iLLD_TC27xC  1.0
IfxFlash.h
Go to the documentation of this file.
1 /**
2  * \file IfxFlash.h
3  * \brief FLASH basic functionality
4  * \ingroup IfxLld_Flash
5  *
6  * \version iLLD_0_1_0_10
7  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8  *
9  *
10  * IMPORTANT NOTICE
11  *
12  *
13  * Infineon Technologies AG (Infineon) is supplying this file for use
14  * exclusively with Infineon's microcontroller products. This file can be freely
15  * distributed within development tools that are supporting such microcontroller
16  * products.
17  *
18  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23  *
24  *
25  * \defgroup IfxLld_Flash FLASH
26  * \ingroup IfxLld
27  * \defgroup IfxLld_Flash_Std Standard Driver
28  * \ingroup IfxLld_Flash
29  * \defgroup IfxLld_Flash_Std_Enumerations Enumerations
30  * \ingroup IfxLld_Flash_Std
31  * \defgroup IfxLld_Flash_Std_CommandSequence CommandSequence Functions
32  * \ingroup IfxLld_Flash_Std
33  * \defgroup IfxLld_Flash_Std_ErrorTracking Error Tracking Functions
34  * \ingroup IfxLld_Flash_Std
35  */
36 
37 #ifndef IFXFLAS_H
38 #define IFXFLAS_H 1
39 
40 /******************************************************************************/
41 /*----------------------------------Includes----------------------------------*/
42 /******************************************************************************/
43 
44 #include "_Impl/IfxFlash_cfg.h"
45 #include "_Reg/IfxFlash_reg.h"
46 
47 /******************************************************************************/
48 /*--------------------------------Enumerations--------------------------------*/
49 /******************************************************************************/
50 
51 /** \addtogroup IfxLld_Flash_Std_Enumerations
52  * \{ */
53 /** \brief enumeration for Flash Error tracking
54  */
55 typedef enum
56 {
57  IfxFlash_ErrorTracking_none = 0, /**< \brief Error tracking disabled */
58  IfxFlash_ErrorTracking_correctedSingleBitError = 1, /**< \brief corrected single bit errors */
59  IfxFlash_ErrorTracking_correctedDoubleBitError = 2, /**< \brief Corrected double-bit errors */
60  IfxFlash_ErrorTracking_correctedSingleOrDoubleBitError = 3, /**< \brief Corrected single-bit and double-bit errors */
61  IfxFlash_ErrorTracking_uncorrectableMultiBitError = 4 /**< \brief Detected uncorrectable errors */
63 
64 /** \brief Corrected/UnCorrected Bits Address Buffer Port Id
65  */
66 typedef enum
67 {
68  IfxFlash_PortId_PortId_0 = 0, /**< \brief Port Id 0 */
69  IfxFlash_PortId_PortId_1 = 1, /**< \brief Port Id 1 */
71 
72 /** \} */
73 
74 /******************************************************************************/
75 /*-----------------------------Data Structures--------------------------------*/
76 /******************************************************************************/
77 
78 /** \brief Error tracking address structure
79  */
80 typedef struct
81 {
82  uint32 address; /**< \brief Flash address for error tracking */
83  IfxFlash_ErrorTracking errorType; /**< \brief Error type */
85 
86 /** \addtogroup IfxLld_Flash_Std_CommandSequence
87  * \{ */
88 
89 /******************************************************************************/
90 /*-------------------------Global Function Prototypes-------------------------*/
91 /******************************************************************************/
92 
93 /** \brief Performs the "Clear Status" sequence
94  * \param flash selects the flash (PMU) module
95  * \return None
96  */
98 
99 /** \brief Performs the "Erase Verify" sequence
100  * \param flash selects the flash (PMU) module
101  * \param ucb selects the user configuration block (0 for UCB0, 1 for UCB1, 5 for UCB_HSMC)
102  * \param password password pointer to an array of 8 words
103  * \return None
104  */
106 
107 /** \brief Performs the sequence for entering program page mode
108  * \param pageAddr pageAddr specifies the page being written - the command sequence will be varied accordingly
109  * \return 0 on success, != 0 if invalid or not available page is selected
110  *
111  * Usage Example:
112  * \code
113  *
114  * unsigned int pageAddr = IFXFLASH_DFLASH_START + page*IFXFLASH_DFLASH_PAGE_LENGTH;
115  *
116  * // enter page mode
117  * IfxFlash_enterPageMode(pageAddr);
118  *
119  * \endcode
120  *
121  */
123 
124 /** \brief Performs the erase sequence for n sectors in program or data flash
125  * \param sectorAddr sector address
126  * \param numSector the no.of sectors to be erased
127  * \return None
128  *
129  * Usage Example:
130  * \code
131  *
132  * // erase the first and second data flash
133  * IfxFlash_eraseMultiplePhysicalSectors(IFXFLASH_DFLASH_START,2);
134  *
135  * \endcode
136  *
137  */
139 
140 /** \brief Performs the erase sequence for n sectors in program or data flash
141  * \param sectorAddr sector address
142  * \param numSector the no.of sectors to be erased
143  * \return None
144  *
145  * Usage Example:
146  * \code
147  *
148  * // erase logical sectors of program flash
149  * IfxFlash_eraseMultipleSectors(pFlashTableLog[sector].start,2);
150  *
151  * \endcode
152  *
153  */
154 IFX_EXTERN void IfxFlash_eraseMultipleSectors(uint32 sectorAddr, uint32 numSector);
155 
156 /** \brief Performs the erase sequence for a physical sector in program or data flash
157  * \param sectorAddr sector address
158  * \return None
159  *
160  * Usage Example:
161  * \code
162  *
163  * // erase the first data flash
164  * IfxFlash_erasePhysicalSector(IFXFLASH_DFLASH_START);
165  *
166  *
167  * \endcode
168  *
169  */
171 
172 /** \brief Performs the erase sequence for a sector in program or data flash.
173  * \param sectorAddr sector address
174  * \return None
175  *
176  * Usage Example:
177  * \code
178  *
179  *
180  * // erase all sectors of program flash
181  * for(sector=0; sector<IFXFLASH_PFLASH_NO_OF_LOG_SECTORS; ++sector) {
182  * // get address from predefined table
183  * unsigned int sector_addr = pFlashTableLog[sector].start;
184  * // erase sector
185  * IfxFlash_eraseSector(sector_addr);
186  * }
187  *
188  *
189  * \endcode
190  *
191  */
192 IFX_EXTERN void IfxFlash_eraseSector(uint32 sectorAddr);
193 
194 /** \brief Performs the "Erase Verify" sequence for multiple sectors
195  * \param sectorAddr sector address which should be verified
196  * \param numSector no.of sectors to be operated on
197  * \return None
198  */
199 IFX_EXTERN void IfxFlash_eraseVerifyMultipleSectors(uint32 sectorAddr, uint32 numSector);
200 
201 /** \brief Performs the "Erase Verify" sequence
202  * \param sectorAddr sector address which should be verified
203  * \return None
204  */
206 
207 /** \brief performs a load page sequence with a single 64bit access
208  * \param pageAddr pageAddr start address of page which should be programmed
209  * \param wordL Lower Address word
210  * \param wordU Upper address word
211  * \return None
212  *
213  * Usage Example:
214  * \code
215  *
216  * // load 64bit into assembly buffer of program flash
217  * IfxFlash_loadPage(IFXFLASH_PFLASH_START, 0x55555555, 0xaaaaaaaa);
218  *
219  * // load 64bit into assembly buffer of data flash
220  * IfxFlash_loadPage(0XAF000000, 0x55555555, 0xaaaaaaaa);
221  * \endcode
222  *
223  */
224 IFX_EXTERN void IfxFlash_loadPage(uint32 pageAddr, uint32 wordL, uint32 wordU);
225 
226 /** \brief performs a load page sequence with two 32bit accesses
227  * \param pageAddr pageAddr start address of page which should be programmed
228  * \param wordL Lower Address word
229  * \param wordU Upper Address word
230  * \return None
231  *
232  * Usage Example:
233  * \code
234  *
235  * // load 2*32bit into assembly buffer of program flash
236  * IfxFlash_loadPage2X32(IFXFLASH_PFLASH_START, 0x55555555, 0xaaaaaaaa);
237  *
238  * // load 2*32bit into assembly buffer of data flash
239  * IfxFlash_loadPage2X32(0XAF000000, 0x55555555, 0xaaaaaaaa);
240  * \endcode
241  *
242  */
243 IFX_EXTERN void IfxFlash_loadPage2X32(uint32 pageAddr, uint32 wordL, uint32 wordU);
244 
245 /** \brief reset to read mode
246  * \param flash flash selects the flash (PMU) module
247  * \return None
248  *
249  * Usage Example:
250  * \code
251  *
252  * // reset to read mode
253  * IfxFlash_resetToRead(0);
254  *
255  * \endcode
256  *
257  */
259 
260 /** \brief Performs the "Resume Protection" sequence
261  * \param flash selects the flash (PMU) module
262  * \return None
263  */
265 
266 /** \brief Performs the "Suspend Resume" sequence for multiple sectors
267  * \param sectorAddr sector address
268  * \param numSector the no.of sectors to be operated on
269  * \return None
270  */
272 
273 /** \brief Performs the "Suspend Resume" sequence
274  * \param sectorAddr sector address which should be resumed
275  * \return None
276  */
278 
279 /** \brief Polls the selected status flag in flash status register until it turns to 0
280  * \param flash selects the flash (PMU) module
281  * \param flashType selects the flash type
282  * \return 0 on success, != 0 if invalid or not available page is selected
283  *
284  * Usage Example:
285  * \code
286  *
287  * // wait until data flash 0 is unbusy
288  * IfxFlash_waitUnbusy(0, IfxFlash_FlashType_D0);
289  *
290  * \endcode
291  *
292  */
294 
295 /** \brief Performs the "Write Burst" sequence, similar to write page but performs a burst transfer instead of page.Make sure the appropriate amount of data is loaded using load page command
296  * \param pageAddr start address of page which should be programmed
297  * \return None
298  *
299  * Usage Example:
300  * \code
301  *
302  * // program the second page of the first sector of the Program Flash
303  * IfxFlash_writeBurst(0xa0000100);
304  *
305  * \endcode
306  *
307  */
308 IFX_EXTERN void IfxFlash_writeBurst(uint32 pageAddr);
309 
310 /** \brief Performs the "Write Page" sequence
311  * \param pageAddr start address of page which should be programmed
312  * \return None
313  *
314  * Usage Example:
315  * \code
316  *
317  * // program the second page of the first sector of the Program Flash
318  * IfxFlash_writePage(0xa0000100);
319  *
320  * \endcode
321  *
322  */
323 IFX_EXTERN void IfxFlash_writePage(uint32 pageAddr);
324 
325 /** \brief Performs the "Write Page Once" sequence, similar to write page but performs a program verify after writing.
326  * \param pageAddr start address of page which should be programmed
327  * \return None
328  *
329  * Usage Example:
330  * \code
331  *
332  * // program the second page of the first sector of the Program Flash
333  * IfxFlash_writePageOnce(0xa0000100);
334  *
335  * \endcode
336  *
337  */
339 
340 /** \} */
341 
342 /** \addtogroup IfxLld_Flash_Std_ErrorTracking
343  * \{ */
344 
345 /******************************************************************************/
346 /*-------------------------Global Function Prototypes-------------------------*/
347 /******************************************************************************/
348 
349 /** \brief Clear the Correctable errors in Corrected Bits Address Buffer Configuration Port x (CBABCFGx) register
350  * \param portId Corrected Bits Address Buffer Port Id
351  * \return None
352  */
354 
355 /** \brief Select the uncorrectable errors in UnCorrectable Bits Address Buffer Configuration Port x (UBABCFGx) register
356  * \param portId UnCorrected Bits Address Buffer Port Id
357  * \return None
358  */
360 
361 /** \brief Disable the Correctable errors in Corrected Bits Address Buffer Configuration Port x (CBABCFGx) register
362  * \param portId Corrected Bits Address Buffer Port Id
363  * \param disable Disable/enable the error tracking
364  * \return None
365  */
367 
368 /** \brief Clear the uncorrectable errors in UnCorrectable Bits Address Buffer Configuration Port x (UBABCFGx) register
369  * \param portId UnCorrected Bits Address Buffer Port Id
370  * \param disable Disable/enable the error tracking
371  * \return None
372  */
374 
375 /** \brief Returns the tracked correctable error addresses, error types and number of errors which are stored in the CBAB registers.
376  * \param portId Corrected Bits Address Buffer Port Id
377  * \param trackedFlashAdresses tracked flash addresses for correctable errors
378  * \return numErrors
379  *
380  * Example usage to print out tracked errors :
381  *
382  * \code
383  * {
384  * IfxFlash_ErrorTracking_Address trackedAddresses[IFX_FLASH_ERROR_TRACKING_MAX_CORRECTABLE_ERRORS];
385  * IfxFlash_portId portId = 0;
386  * uint8 numTrackedAddresses = IfxFlash_getTrackedCorrectableErrors(portId, trackedAddresses);
387  *
388  * for(int i=0; i<numTrackedAddresses; ++i) {
389  * printf("%d: A:0x%04x Error Type:%d \n",
390  * i,
391  * trackedAddresses[i].address,
392  * trackedAddresses[i].errorType);
393  * }
394  * }
395  * \endcode
396  *
397  */
399 
400 /** \brief Returns the tracked uncorrectable error addresses, error types and number of errors which are stored in the UBAB registers.
401  * \param portId UnCorrected Bits Address Buffer Port Id
402  * \param trackedFlashAdresses tracked flash addresses for uncorrectable errors
403  * \return numErrors
404  *
405  * Example usage to print out tracked errors :
406  *
407  * \code
408  * {
409  * IfxFlash_ErrorTracking_Address trackedAddresses[IFX_FLASH_ERROR_TRACKING_MAX_UNCORRECTABLE_ERRORS];
410  * IfxFlash_portId portId = 0;
411  * uint8 numTrackedAddresses = IfxFlash_getTrackedUnCorrectableErrors(portId, trackedAddresses);
412  *
413  * for(int i=0; i<numTrackedAddresses; ++i) {
414  * printf("%d: A:0x%04x Error Type:%d \n",
415  * i,
416  * trackedAddresses[i].address,
417  * trackedAddresses[i].errorType);
418  * }
419  * }
420  * \endcode
421  *
422  */
424 
425 /** \brief Enables error tracking for correctable flash errors
426  * \param portId Corrected Bits Address Buffer Port Id
427  * \param errorTracking Error Tracking to be selected
428  * \return None
429  *
430  * Usage example: how to enable error tracking for two flash ports:
431  * \code
432  * // enable error tracking
433  * {
434  * uint16 password = IfxScuWdt_getCpuWatchdogPassword();
435  * IfxScuWdt_clearCpuEndinit(password);
436  *
437  * // PFlash0
438  * IfxFlash_selectCorrectableErrorTracking(IfxFlash_PortId_PortId_0, IfxFlash_ErrorTracking_correctedSingleOrDoubleBitError);
439  * IfxFlash_selectUncorrectableErrorTracking(IfxFlash_PortId_PortId_0, IfxFlash_ErrorTracking_uncorrectableMultiBitError);
440  *
441  * // PFlash1
442  * IfxFlash_selectCorrectableErrorTracking(IfxFlash_PortId_PortId_1, IfxFlash_ErrorTracking_correctedSingleOrDoubleBitError);
443  * IfxFlash_selectUncorrectableErrorTracking(IfxFlash_PortId_PortId_1, IfxFlash_ErrorTracking_uncorrectableMultiBitError);
444  *
445  * IfxScuWdt_setCpuEndinit(password);
446  * }
447  * \endcode
448  *
449  */
451 
452 /** \brief Enables error tracking for uncorrectable flash errors
453  * \param portId UnCorrected Bits Address Buffer Port Id
454  * \param errorTracking Error Tracking to be selected
455  * \return None
456  *
457  * Usage example: see \ref IfxFlash_selectCorrectableErrorTracking
458  *
459  */
461 
462 /** \} */
463 
464 #endif /* IFXFLAS_H */