MSP430 DriverLib for MSP430i2xx Devices  2.10.00.09
 All Data Structures Functions Variables Modules Pages
flashctl.h
1 //*****************************************************************************
2 //
3 // flashctl.h - Driver for the FLASHCTL Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_FLASHCTL_H__
8 #define __MSP430WARE_FLASHCTL_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_FLASH__
13 
14 //*****************************************************************************
15 //
16 // If building with a C++ compiler, make all of the definitions in this header
17 // have a C binding.
18 //
19 //*****************************************************************************
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 //*****************************************************************************
26 //
27 // The following are values that can be passed to the mask parameter for
28 // functions: FlashCtl_getStatus() as well as returned by the
29 // FlashCtl_getStatus() function.
30 //
31 //*****************************************************************************
32 #define FLASHCTL_READY_FOR_NEXT_WRITE WAIT
33 #define FLASHCTL_ACCESS_VIOLATION_INTERRUPT_FLAG ACCVIFG
34 #define FLASHCTL_PASSWORD_WRITTEN_INCORRECTLY KEYV
35 #define FLASHCTL_BUSY BUSY
36 
37 //*****************************************************************************
38 //
39 // The following are values that can be passed to the clockSource parameter for
40 // functions: FlashCtl_setupClock().
41 //
42 //*****************************************************************************
43 #define FLASHCTL_MCLK FSSEL_1
44 #define FLASHCTL_SMCLK FSSEL_2
45 
46 //*****************************************************************************
47 //
48 // Prototypes for the APIs.
49 //
50 //*****************************************************************************
51 
52 //*****************************************************************************
53 //
54 //! \brief Erase a single segment of the flash memory.
55 //!
56 //! For devices like MSP430i204x, if the specified segment is the information
57 //! flash segment, the FLASH_unlockInfo API must be called prior to calling
58 //! this API.
59 //!
60 //! \param flash_ptr is the pointer into the flash segment to be erased
61 //!
62 //! \return None
63 //
64 //*****************************************************************************
65 extern void FlashCtl_eraseSegment(uint8_t *flash_ptr);
66 
67 //*****************************************************************************
68 //
69 //! \brief Erase all flash memory.
70 //!
71 //! This function erases all the flash memory banks. For devices like
72 //! MSP430i204x, this API erases main memory and information flash memory if
73 //! the FLASH_unlockInfo API was previously executed (otherwise the information
74 //! flash is not erased). Also note that erasing information flash memory in
75 //! the MSP430i204x impacts the TLV calibration constants located at the
76 //! information memory.
77 //!
78 //! \param flash_ptr is a pointer into the bank to be erased
79 //!
80 //! \return None
81 //
82 //*****************************************************************************
83 extern void FlashCtl_performMassErase(uint8_t *flash_ptr);
84 
85 //*****************************************************************************
86 //
87 //! \brief Erase check of the flash memory
88 //!
89 //! This function checks bytes in flash memory to make sure that they are in an
90 //! erased state (are set to 0xFF).
91 //!
92 //! \param flash_ptr is the pointer to the starting location of the erase check
93 //! \param numberOfBytes is the number of bytes to be checked
94 //!
95 //! \return STATUS_SUCCESS or STATUS_FAIL
96 //
97 //*****************************************************************************
98 extern bool FlashCtl_performEraseCheck(uint8_t *flash_ptr,
99  uint16_t numberOfBytes);
100 
101 //*****************************************************************************
102 //
103 //! \brief Write data into the flash memory in byte format, pass by reference
104 //!
105 //! This function writes a byte array of size count into flash memory. Assumes
106 //! the flash memory is already erased and unlocked. FlashCtl_eraseSegment can
107 //! be used to erase a segment.
108 //!
109 //! \param data_ptr is the pointer to the data to be written
110 //! \param flash_ptr is the pointer into which to write the data
111 //! \param count number of times to write the value
112 //!
113 //! \return None
114 //
115 //*****************************************************************************
116 extern void FlashCtl_write8(uint8_t *data_ptr,
117  uint8_t *flash_ptr,
118  uint16_t count);
119 
120 //*****************************************************************************
121 //
122 //! \brief Write data into the flash memory in 16-bit word format, pass by
123 //! reference
124 //!
125 //! This function writes a 16-bit word array of size count into flash memory.
126 //! Assumes the flash memory is already erased and unlocked.
127 //! FlashCtl_eraseSegment can be used to erase a segment.
128 //!
129 //! \param data_ptr is the pointer to the data to be written
130 //! \param flash_ptr is the pointer into which to write the data
131 //! \param count number of times to write the value
132 //!
133 //! \return None
134 //
135 //*****************************************************************************
136 extern void FlashCtl_write16(uint16_t *data_ptr,
137  uint16_t *flash_ptr,
138  uint16_t count);
139 
140 //*****************************************************************************
141 //
142 //! \brief Write data into the flash memory in 32-bit word format, pass by
143 //! reference
144 //!
145 //! This function writes a 32-bit array of size count into flash memory.
146 //! Assumes the flash memory is already erased and unlocked.
147 //! FlashCtl_eraseSegment can be used to erase a segment.
148 //!
149 //! \param data_ptr is the pointer to the data to be written
150 //! \param flash_ptr is the pointer into which to write the data
151 //! \param count number of times to write the value
152 //!
153 //! \return None
154 //
155 //*****************************************************************************
156 extern void FlashCtl_write32(uint32_t *data_ptr,
157  uint32_t *flash_ptr,
158  uint16_t count);
159 
160 //*****************************************************************************
161 //
162 //! \brief Write data into the flash memory in 32-bit word format, pass by
163 //! value
164 //!
165 //! This function writes a 32-bit data value into flash memory, count times.
166 //! Assumes the flash memory is already erased and unlocked.
167 //! FlashCtl_eraseSegment can be used to erase a segment.
168 //!
169 //! \param value value to fill memory with
170 //! \param flash_ptr is the pointer into which to write the data
171 //! \param count number of times to write the value
172 //!
173 //! \return None
174 //
175 //*****************************************************************************
176 extern void FlashCtl_fillMemory32(uint32_t value,
177  uint32_t *flash_ptr,
178  uint16_t count);
179 
180 //*****************************************************************************
181 //
182 //! \brief Check FlashCtl status to see if it is currently busy erasing or
183 //! programming
184 //!
185 //! This function checks the status register to determine if the flash memory
186 //! is ready for writing.
187 //!
188 //! \param mask FLASHCTL status to read
189 //! Mask value is the logical OR of any of the following:
190 //! - \b FLASHCTL_READY_FOR_NEXT_WRITE
191 //! - \b FLASHCTL_ACCESS_VIOLATION_INTERRUPT_FLAG
192 //! - \b FLASHCTL_PASSWORD_WRITTEN_INCORRECTLY
193 //! - \b FLASHCTL_BUSY
194 //!
195 //! \return Logical OR of any of the following:
196 //! - \b FlashCtl_READY_FOR_NEXT_WRITE
197 //! - \b FlashCtl_ACCESS_VIOLATION_INTERRUPT_FLAG
198 //! - \b FlashCtl_PASSWORD_WRITTEN_INCORRECTLY
199 //! - \b FlashCtl_BUSY
200 //! \n indicating the status of the FlashCtl
201 //
202 //*****************************************************************************
203 extern uint8_t FlashCtl_getStatus(uint8_t mask);
204 
205 //*****************************************************************************
206 //
207 //! \brief Locks the information flash memory segment
208 //!
209 //! This function is typically called after an erase or write operation on the
210 //! information flash segment is performed by any of the other API functions in
211 //! order to re-lock the information flash segment.
212 //!
213 //!
214 //! \return None
215 //
216 //*****************************************************************************
217 extern void FlashCtl_lockInfo(void);
218 
219 //*****************************************************************************
220 //
221 //! \brief Unlocks the information flash memory segment
222 //!
223 //! This function must be called before an erase or write operation on the
224 //! information flash segment is performed by any of the other API functions.
225 //!
226 //!
227 //! \return None
228 //
229 //*****************************************************************************
230 extern void FlashCtl_unlockInfo(void);
231 
232 //*****************************************************************************
233 //
234 //! \brief Sets up the clock for the flash module
235 //!
236 //! This function sets up the clock for the flash module. This function is
237 //! typically called before any of the other flash API functions are called.
238 //!
239 //! \param clockTargetFreq is the target clock source frequency in Hz.
240 //! \param clockSourceFreq is the clock source frequency in Hz.
241 //! \param clockSource is the clock source type for the flash.
242 //! Valid values are:
243 //! - \b FLASHCTL_MCLK [Default]
244 //! - \b FLASHCTL_SMCLK
245 //!
246 //! \return clock setup result
247 //! \n indicating clock setup succeed or failed
248 //
249 //*****************************************************************************
250 extern uint8_t FlashCtl_setupClock(uint32_t clockTargetFreq,
251  uint32_t clockSourceFreq,
252  uint16_t clockSource);
253 
254 //*****************************************************************************
255 //
256 // Mark the end of the C bindings section for C++ compilers.
257 //
258 //*****************************************************************************
259 #ifdef __cplusplus
260 }
261 #endif
262 
263 #endif
264 #endif // __MSP430WARE_FLASHCTL_H__
void FlashCtl_write16(uint16_t *data_ptr, uint16_t *flash_ptr, uint16_t count)
Write data into the flash memory in 16-bit word format, pass by reference.
Definition: flashctl.c:107
void FlashCtl_unlockInfo(void)
Unlocks the information flash memory segment.
Definition: flashctl.c:238
uint8_t FlashCtl_setupClock(uint32_t clockTargetFreq, uint32_t clockSourceFreq, uint16_t clockSource)
Sets up the clock for the flash module.
Definition: flashctl.c:254
bool FlashCtl_performEraseCheck(uint8_t *flash_ptr, uint16_t numberOfBytes)
Erase check of the flash memory.
Definition: flashctl.c:63
void FlashCtl_eraseSegment(uint8_t *flash_ptr)
Erase a single segment of the flash memory.
Definition: flashctl.c:21
void FlashCtl_write8(uint8_t *data_ptr, uint8_t *flash_ptr, uint16_t count)
Write data into the flash memory in byte format, pass by reference.
Definition: flashctl.c:79
uint8_t FlashCtl_getStatus(uint8_t mask)
Check FlashCtl status to see if it is currently busy erasing or programming.
Definition: flashctl.c:215
void FlashCtl_lockInfo(void)
Locks the information flash memory segment.
Definition: flashctl.c:221
void FlashCtl_fillMemory32(uint32_t value, uint32_t *flash_ptr, uint16_t count)
Write data into the flash memory in 32-bit word format, pass by value.
Definition: flashctl.c:173
void FlashCtl_write32(uint32_t *data_ptr, uint32_t *flash_ptr, uint16_t count)
Write data into the flash memory in 32-bit word format, pass by reference.
Definition: flashctl.c:135
void FlashCtl_performMassErase(uint8_t *flash_ptr)
Erase all flash memory.
Definition: flashctl.c:41

Copyright 2015, Texas Instruments Incorporated