CC13xx Driver Library
flashsafe.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: flashsafe.h
3 * Revised: 2015-09-21 15:19:36 +0200 (Mon, 21 Sep 2015)
4 * Revision: 44629
5 *
6 * Description: Defines and prototypes for the Flash driver in
7 * Thread safe mode.
8 *
9 * Copyright (c) 2015, Texas Instruments Incorporated
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
15 * 1) Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 *
18 * 2) Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 *
22 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
23 * be used to endorse or promote products derived from this software without
24 * specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 *
38 ******************************************************************************/
39 
40 //*****************************************************************************
41 //
46 //
47 //*****************************************************************************
48 
49 #ifndef __FLASHSAFE_H__
50 #define __FLASHSAFE_H__
51 
52 //*****************************************************************************
53 //
54 // If building with a C++ compiler, make all of the definitions in this header
55 // have a C binding.
56 //
57 //*****************************************************************************
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 #include <stdbool.h>
64 #include <stdint.h>
65 #include <inc/hw_types.h>
66 #include <inc/hw_flash.h>
67 #include <inc/hw_memmap.h>
68 #include <inc/hw_ints.h>
69 #include <inc/hw_fcfg1.h>
70 #include <driverlib/interrupt.h>
71 #include <driverlib/debug.h>
72 #include <driverlib/flash.h>
73 #include <driverlib/rom.h>
74 #include <driverlib/smph.h>
75 
76 //*****************************************************************************
77 //
78 // Support for DriverLib in ROM:
79 // This section renames all functions that are not "static inline", so that
80 // calling these functions will default to implementation in flash. At the end
81 // of this file a second renaming will change the defaults to implementation in
82 // ROM for available functions.
83 //
84 // To force use of the implementation in flash, e.g. for debugging:
85 // - Globally: Define DRIVERLIB_NOROM at project level
86 // - Per function: Use prefix "NOROM_" when calling the function
87 //
88 //*****************************************************************************
89 #if !defined(DOXYGEN)
90  #define FlashsafeSizeGet NOROM_FlashsafeSizeGet
91  #define FlashsafeSectorSizeGet NOROM_FlashsafeSectorSizeGet
92  #define FlashsafePowerModeSet NOROM_FlashsafePowerModeSet
93  #define FlashsafePowerModeGet NOROM_FlashsafePowerModeGet
94  #define FlashsafeProtectionSet NOROM_FlashsafeProtectionSet
95  #define FlashsafeProtectionGet NOROM_FlashsafeProtectionGet
96  #define FlashsafeProtectionSave NOROM_FlashsafeProtectionSave
97  #define FlashsafeCheckFsmForError NOROM_FlashsafeCheckFsmForError
98  #define FlashsafeCheckFsmForReady NOROM_FlashsafeCheckFsmForReady
99  #define FlashsafeIntRegister NOROM_FlashsafeIntRegister
100  #define FlashsafeIntUnregister NOROM_FlashsafeIntUnregister
101  #define FlashsafeIntEnable NOROM_FlashsafeIntEnable
102  #define FlashsafeIntDisable NOROM_FlashsafeIntDisable
103  #define FlashsafeIntStatus NOROM_FlashsafeIntStatus
104  #define FlashsafeIntClear NOROM_FlashsafeIntClear
105  #define FlashsafeSectorErase NOROM_FlashsafeSectorErase
106  #define FlashsafeProgram NOROM_FlashsafeProgram
107  #define FlashsafeDisableSectorsForWrite NOROM_FlashsafeDisableSectorsForWrite
108 #endif
109 
110 //*****************************************************************************
111 //
112 // Values that can be returned from the API functions
113 //
114 //*****************************************************************************
115 
116 #define FLASHSAFE_ACCESS_DENIED 0x000000ff
117 #define FLASHSAFE_ACCESS_OK 0x000000ee
118 #define SMPH_ALLOC_FLASH 1
119 
120 //*****************************************************************************
121 //
122 // Values that can be returned from the API functions
123 //
124 //*****************************************************************************
125 #define FAPI_STATUS_SUCCESS 0x00000000 // Function completed successfully
126 #define FAPI_STATUS_FSM_BUSY 0x00000001 // FSM is Busy
127 #define FAPI_STATUS_FSM_READY 0x00000002 // FSM is Ready
128 #define FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH \
129  0x00000003 // Incorrect parameter value
130 #define FAPI_STATUS_FSM_ERROR 0x00000004 // Operation failed
131 
132 //*****************************************************************************
133 //
134 // Values passed to FlashsafeIntEnable(), FlashsafeIntDisable() and FlashsafeIntClear() and
135 // returned from FlashsafeIntStatus().
136 //
137 //*****************************************************************************
138 #define FLASH_INT_FSM_DONE 0x00400000 // FSM Done Interrupt Mask
139 #define FLASH_INT_RV 0x00010000 // Read Verify error Interrupt Mask
140 
141 //*****************************************************************************
142 //
143 // Values passed to FlashsafeSetPowerMode() and returned from FlashsafeGetPowerMode().
144 //
145 //*****************************************************************************
146 #define FLASH_PWR_ACTIVE_MODE 0x00000000
147 #define FLASH_PWR_OFF_MODE 0x00000001
148 #define FLASH_PWR_DEEP_STDBY_MODE \
149  0x00000002
150 
151 //*****************************************************************************
152 //
153 // Values passed to FlashsafeSetProtection() and returned from FlashsafeGetProtection().
154 //
155 //*****************************************************************************
156 #define FLASH_NO_PROTECT 0x00000000 // Sector not protected
157 #define FLASH_WRITE_PROTECT 0x00000001 // Sector erase and program
158  // protected
159 
160 //*****************************************************************************
161 //
162 // Defines for values written to the FLASH_O_FSM_WR_ENA register
163 //
164 //*****************************************************************************
165 #define FSM_REG_WRT_ENABLE 5
166 #define FSM_REG_WRT_DISABLE 2
167 
168 //*****************************************************************************
169 //
173 //
174 //*****************************************************************************
175 __STATIC_INLINE bool
177 {
179 }
180 
181 //*****************************************************************************
182 //
186 //
187 //*****************************************************************************
188 __STATIC_INLINE void
190 {
192 }
193 
194 //*****************************************************************************
195 //
201 //
202 //*****************************************************************************
203 extern uint32_t FlashsafeSizeGet(void);
204 
205 //*****************************************************************************
206 //
212 //
213 //*****************************************************************************
214 extern uint32_t FlashsafeSectorSizeGet(void);
215 
216 //*****************************************************************************
217 //
263 //
264 //*****************************************************************************
265 extern uint32_t FlashsafePowerModeSet(uint32_t ui32PowerMode,
266  uint32_t ui32BankGracePeriode,
267  uint32_t ui32PumpGracePeriode);
268 
269 //*****************************************************************************
270 //
280 //
281 //*****************************************************************************
282 extern uint32_t FlashsafePowerModeGet(void);
283 
284 //*****************************************************************************
285 //
306 //
307 //*****************************************************************************
308 extern uint32_t FlashsafeProtectionSet(uint32_t ui32SectorAddress,
309  uint32_t ui32ProtectMode);
310 
311 //*****************************************************************************
312 //
324 //
325 //*****************************************************************************
326 extern uint32_t FlashsafeProtectionGet(uint32_t ui32SectorAddress);
327 
328 //*****************************************************************************
329 //
345 //
346 //*****************************************************************************
347 extern uint32_t FlashsafeProtectionSave(uint32_t ui32SectorAddress);
348 
349 //*****************************************************************************
350 //
360 //
361 //*****************************************************************************
362 extern uint32_t FlashsafeCheckFsmForError(void);
363 
364 //*****************************************************************************
365 //
375 //
376 //*****************************************************************************
377 extern uint32_t FlashsafeCheckFsmForReady(void);
378 
379 //*****************************************************************************
380 //
397 //
398 //*****************************************************************************
399 extern uint32_t FlashsafeIntRegister(void (*pfnHandler)(void));
400 
401 //*****************************************************************************
402 //
416 //
417 //*****************************************************************************
418 extern uint32_t FlashsafeIntUnregister(void);
419 
420 //*****************************************************************************
421 //
434 //
435 //*****************************************************************************
436 extern uint32_t FlashsafeIntEnable(uint32_t ui32IntFlags);
437 
438 //*****************************************************************************
439 //
452 //
453 //*****************************************************************************
454 extern uint32_t FlashsafeIntDisable(uint32_t ui32IntFlags);
455 
456 //*****************************************************************************
457 //
465 //
466 //*****************************************************************************
467 extern uint32_t FlashsafeIntStatus(void);
468 
469 //*****************************************************************************
470 //
500 //
501 //*****************************************************************************
502 extern uint32_t FlashsafeIntClear(uint32_t ui32IntFlags);
503 
504 //*****************************************************************************
505 //
527 //
528 //*****************************************************************************
529 extern uint32_t FlashsafeSectorErase(uint32_t ui32SectorAddress);
530 
531 //*****************************************************************************
532 //
560 //
561 //*****************************************************************************
562 extern uint32_t FlashsafeProgram(uint8_t *pui8DataBuffer, uint32_t ui32Address,
563  uint32_t ui32Count);
564 
565 //*****************************************************************************
566 //
577 //
578 //*****************************************************************************
579 extern uint32_t FlashsafeDisableSectorsForWrite(void);
580 
581 //*****************************************************************************
582 //
583 // Support for DriverLib in ROM:
584 // Redirect to implementation in ROM when available.
585 //
586 //*****************************************************************************
587 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
588  #include <driverlib/rom.h>
589  #ifdef ROM_FlashsafeSizeGet
590  #undef FlashsafeSizeGet
591  #define FlashsafeSizeGet ROM_FlashsafeSizeGet
592  #endif
593  #ifdef ROM_FlashsafeSectorSizeGet
594  #undef FlashsafeSectorSizeGet
595  #define FlashsafeSectorSizeGet ROM_FlashsafeSectorSizeGet
596  #endif
597  #ifdef ROM_FlashsafePowerModeSet
598  #undef FlashsafePowerModeSet
599  #define FlashsafePowerModeSet ROM_FlashsafePowerModeSet
600  #endif
601  #ifdef ROM_FlashsafePowerModeGet
602  #undef FlashsafePowerModeGet
603  #define FlashsafePowerModeGet ROM_FlashsafePowerModeGet
604  #endif
605  #ifdef ROM_FlashsafeProtectionSet
606  #undef FlashsafeProtectionSet
607  #define FlashsafeProtectionSet ROM_FlashsafeProtectionSet
608  #endif
609  #ifdef ROM_FlashsafeProtectionGet
610  #undef FlashsafeProtectionGet
611  #define FlashsafeProtectionGet ROM_FlashsafeProtectionGet
612  #endif
613  #ifdef ROM_FlashsafeProtectionSave
614  #undef FlashsafeProtectionSave
615  #define FlashsafeProtectionSave ROM_FlashsafeProtectionSave
616  #endif
617  #ifdef ROM_FlashsafeCheckFsmForError
618  #undef FlashsafeCheckFsmForError
619  #define FlashsafeCheckFsmForError ROM_FlashsafeCheckFsmForError
620  #endif
621  #ifdef ROM_FlashsafeCheckFsmForReady
622  #undef FlashsafeCheckFsmForReady
623  #define FlashsafeCheckFsmForReady ROM_FlashsafeCheckFsmForReady
624  #endif
625  #ifdef ROM_FlashsafeIntRegister
626  #undef FlashsafeIntRegister
627  #define FlashsafeIntRegister ROM_FlashsafeIntRegister
628  #endif
629  #ifdef ROM_FlashsafeIntUnregister
630  #undef FlashsafeIntUnregister
631  #define FlashsafeIntUnregister ROM_FlashsafeIntUnregister
632  #endif
633  #ifdef ROM_FlashsafeIntEnable
634  #undef FlashsafeIntEnable
635  #define FlashsafeIntEnable ROM_FlashsafeIntEnable
636  #endif
637  #ifdef ROM_FlashsafeIntDisable
638  #undef FlashsafeIntDisable
639  #define FlashsafeIntDisable ROM_FlashsafeIntDisable
640  #endif
641  #ifdef ROM_FlashsafeIntStatus
642  #undef FlashsafeIntStatus
643  #define FlashsafeIntStatus ROM_FlashsafeIntStatus
644  #endif
645  #ifdef ROM_FlashsafeIntClear
646  #undef FlashsafeIntClear
647  #define FlashsafeIntClear ROM_FlashsafeIntClear
648  #endif
649  #ifdef ROM_FlashsafeSectorErase
650  #undef FlashsafeSectorErase
651  #define FlashsafeSectorErase ROM_FlashsafeSectorErase
652  #endif
653  #ifdef ROM_FlashsafeProgram
654  #undef FlashsafeProgram
655  #define FlashsafeProgram ROM_FlashsafeProgram
656  #endif
657  #ifdef ROM_FlashsafeDisableSectorsForWrite
658  #undef FlashsafeDisableSectorsForWrite
659  #define FlashsafeDisableSectorsForWrite ROM_FlashsafeDisableSectorsForWrite
660  #endif
661 #endif
662 
663 //*****************************************************************************
664 //
665 // Mark the end of the C bindings section for C++ compilers.
666 //
667 //*****************************************************************************
668 #ifdef __cplusplus
669 }
670 #endif
671 
672 #endif // __FLASHSAFE_H__
673 
674 //*****************************************************************************
675 //
679 //
680 //*****************************************************************************
uint32_t FlashsafeSectorSizeGet(void)
Get size of a flash sector in no of bytes.
Definition: flashsafe.c:104
uint32_t FlashsafeSectorErase(uint32_t ui32SectorAddress)
Erase a flash sector.
Definition: flashsafe.c:403
uint32_t FlashsafeIntEnable(uint32_t ui32IntFlags)
Enables flash controller interrupt sources.
Definition: flashsafe.c:333
static bool FlashsafeSMPHTryAcquire(void)
Aquire the flash semaphore.
Definition: flashsafe.h:176
uint32_t FlashsafeCheckFsmForError(void)
Checks if the Flashsafe state machine has detected an error.
Definition: flashsafe.c:243
uint32_t FlashsafePowerModeGet(void)
Get current configured power mode.
Definition: flashsafe.c:144
uint32_t FlashsafeProgram(uint8_t *pui8DataBuffer, uint32_t ui32Address, uint32_t ui32Count)
Programs unprotected main bank flash sectors.
Definition: flashsafe.c:431
uint32_t FlashsafeIntClear(uint32_t ui32IntFlags)
Clears flash controller interrupt source.
Definition: flashsafe.c:385
#define SMPH_ALLOC_FLASH
Definition: flashsafe.h:118
uint32_t FlashsafeIntDisable(uint32_t ui32IntFlags)
Disables individual flash controller interrupt sources.
Definition: flashsafe.c:354
uint32_t FlashsafeCheckFsmForReady(void)
Checks if the Flash state machine is ready.
Definition: flashsafe.c:261
static void SMPHRelease(uint32_t ui32Semaphore)
Release a semaphore.
Definition: smph.h:244
static bool SMPHTryAcquire(uint32_t ui32Semaphore)
Try to Acquire a semaphore.
Definition: smph.h:176
uint32_t FlashsafeProtectionSet(uint32_t ui32SectorAddress, uint32_t ui32ProtectMode)
Set sector protection.
Definition: flashsafe.c:164
uint32_t FlashsafePowerModeSet(uint32_t ui32PowerMode, uint32_t ui32BankGracePeriode, uint32_t ui32PumpGracePeriode)
Set power mode.
Definition: flashsafe.c:115
uint32_t FlashsafeDisableSectorsForWrite(void)
Disables all sectors for erase and programming on the active bank.
Definition: flashsafe.c:457
uint32_t FlashsafeProtectionGet(uint32_t ui32SectorAddress)
Get sector protection.
Definition: flashsafe.c:189
uint32_t FlashsafeProtectionSave(uint32_t ui32SectorAddress)
Save sector protection to make it permanent.
Definition: flashsafe.c:216
uint32_t FlashsafeIntStatus(void)
Gets the current interrupt status.
Definition: flashsafe.c:374
uint32_t FlashsafeSizeGet(void)
Get the size of the flash.
Definition: flashsafe.c:93
static void FlashsafeSMPHRelease(void)
Release the flash semaphore.
Definition: flashsafe.h:189
uint32_t FlashsafeIntUnregister(void)
Unregisters the interrupt handler for the flash interrupt.
Definition: flashsafe.c:306
uint32_t FlashsafeIntRegister(void(*pfnHandler)(void))
Registers an interrupt handler for the flash interrupt.
Definition: flashsafe.c:279