Contiki 2.5
flash.h
Go to the documentation of this file.
1 /** @file hal/micro/cortexm3/flash.h
2  * @brief Header for flash for APIs
3  *
4  * <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
5  */
6 
7 /** @addtogroup flash
8  * @brief Definition and description of public flash manipulation routines.
9  *
10  * @note
11  * During an erase or a write the flash is not available,
12  * which means code will not be executable from flash. These routines still
13  * execute from flash, though, since the bus architecture can support doing so.
14  * <b>Additonally, this also means all interrupts will be disabled.</b>
15  *
16  * <b>Hardware documentation indicates 40us for a write and 21ms for an erase.</b>
17  *
18  * See flash.h for source code.
19  *@{
20  */
21 
22 #ifndef __FLASH_H__
23 #define __FLASH_H__
24 
25 #include "memmap.h"
26 
27 
28 /** @brief Tells the calling code if a Flash Erase operation is active.
29  *
30  * This state is import to know because Flash Erasing is ATOMIC for 21ms
31  * and could disrupt interrupt latency. But if an ISR can know that it wasn't
32  * serviced immediately due to Flash Erasing, then the ISR has the opportunity
33  * to correct in whatever manner it needs to.
34  *
35  * @return A boolean flag: TRUE if Flash Erase is active, FALSE otherwise.
36  */
37 boolean halFlashEraseIsActive(void);
38 
39 #ifndef DOXYGEN_SHOULD_SKIP_THIS
40 
41 //[[ The following eraseType definitions must match the FIB erase types! ]]
42 /**
43  * @brief Assign numerical value to the type of erasure requested.
44  */
45 #define MFB_MASS_ERASE 0x01
46 #define MFB_PAGE_ERASE 0x02
47 #define CIB_ERASE 0x03
48 
49 /** @brief Erases a section of flash back to all 0xFFFF.
50  *
51  * @param eraseType Choose one of the three types of erasures to perform.
52  * - MFB_MASS_ERASE (0x01) Erase the entire main flash block.
53  * - MFB_PAGE_ERASE (0x02) Erase one hardware page in the main flash block
54  * chosen by the \c address parameter.
55  * - CIB_ERASE (0x03) Erase the entire customer information block.
56  *
57  * @param address This parameter is only effectual when a MFB_PAGE_ERASE is
58  * being performed. The hardware page encapsulating the address given in this
59  * parameter will be erased. A hardware page size depends on the chip
60  *
61  * @return An ::StStatus value indicating the success or failure of the
62  * command:
63  * - ST_ERR_FATAL if the \c eraseType is not valid
64  * - ST_ERR_FLASH_ERASE_FAIL if erasing failed due to write protection
65  * - ST_ERR_FLASH_VERIFY_FAILED if erase verification failed
66  * - ST_SUCCESS if erasure completed and verified properly
67  */
68 StStatus halInternalFlashErase(int8u eraseType, int32u address);
69 
70 /** @brief Writes a block of words to flash. A page is erased
71  * to 0xFFFF at every address. Only two writes can be performed to the same
72  * address between erasures and this is enforced by the flash interface
73  * controller. If the value already in the address being written to is 0xFFFF,
74  * any value can be written. If the value is not 0xFFFF and not 0x0000, only
75  * 0x0000 can be written. If the value is 0x0000, nothing can be written.
76  *
77  * \b NOTE: This function can NOT write the option bytes and will throw an
78  * error if that is attempted.
79  *
80  * @param address The starting address of where the programming will occur.
81  * This parameter MUST be half-word aligned since all programming operations
82  * are half-words. Also, the address parameter is NOT a pointer. This
83  * routines will cast the address to a pointer for the actual hardware access.
84  *
85  * @param data A pointer to a buffer containing the 16bit (half-words) to
86  * be written.
87  *
88  * @param length The number of 16bit (half-words) contained in the data buffer
89  * to be written to flash.
90  *
91  * @return An ::StStatus value indicating the success or failure of the
92  * command:
93  * - ST_ERR_FLASH_PROG_FAIL if the address is not half-word aligned, the
94  * address is inside the option bytes, write protection is enabled, or the
95  * address is being written to more than twice between erasures.
96  * - ST_ERR_FLASH_VERIFY_FAILED if write verification failed
97  * - ST_SUCCESS if writing completed and verified properly
98  */
99 StStatus halInternalFlashWrite(int32u address, int16u * data, int32u length);
100 
101 /** @brief Writes an option byte to the customer information block. Only
102  * two writes can be performed to the same address between erasures and this
103  * is enforced by the flash interface controller.
104  *
105  * @param byte The option byte number, 0 though 7, to be programmed.
106  *
107  * @param data The 8 bit value to be programmed into the option byte. The
108  * hardware is responsible for calculating the compliment and programming
109  * the full 16bit option byte space.
110  *
111  * @return An ::StStatus value indicating the success or failure of the
112  * command:
113  * - ST_ERR_FLASH_PROG_FAIL if the byte chosen is greater than 7, write
114  * protection is enabled, or the byte is being written to more than twice
115  * between erasures.
116  * - ST_ERR_FLASH_VERIFY_FAILED if write verification failed
117  * - ST_SUCCESS if writing completed and verified properly
118  */
119 StStatus halInternalCibOptionByteWrite(int8u byte, int8u data);
120 
121 #endif //DOXYGEN_SHOULD_SKIP_THIS
122 
123 #endif //__FLASH_H__
124 
125 /** @} END addtogroup */
126