CC26xx Driver Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
flashsafe.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: flashsafe.h
3 * Revised: 2015-01-05 16:57:31 +0100 (ma, 05 jan 2015)
4 * Revision: 42287
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 //
44 //
45 //*****************************************************************************
46 
47 #ifndef __FLASHSAFE_H__
48 #define __FLASHSAFE_H__
49 
50 //*****************************************************************************
51 //
52 // If building with a C++ compiler, make all of the definitions in this header
53 // have a C binding.
54 //
55 //*****************************************************************************
56 #ifdef __cplusplus
57 extern "C"
58 {
59 #endif
60 
61 #include <stdbool.h>
62 #include <stdint.h>
63 #include <inc/hw_types.h>
64 #include <inc/hw_flash.h>
65 #include <inc/hw_memmap.h>
66 #include <inc/hw_ints.h>
67 #include <inc/hw_fcfg1.h>
68 #include <driverlib/interrupt.h>
69 #include <driverlib/debug.h>
70 #include <driverlib/flash.h>
71 #include <driverlib/rom.h>
72 #include <driverlib/smph.h>
73 
74 //*****************************************************************************
75 //
76 // Support for DriverLib in ROM:
77 // This section renames all functions that are not "static inline", so that
78 // calling these functions will default to implementation in flash. At the end
79 // of this file a second renaming will change the defaults to implementation in
80 // ROM for available functions.
81 //
82 // To force use of the implementation in flash, e.g. for debugging:
83 // - Globally: Define DRIVERLIB_NOROM at project level
84 // - Per function: Use prefix "NOROM_" when calling the function
85 //
86 // Do not define DRIVERLIB_GENERATE_ROM!
87 //
88 //*****************************************************************************
89 #ifndef DRIVERLIB_GENERATE_ROM
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 FlashsafeProgramNowait NOROM_FlashsafeProgramNowait
108  #define FlashsafeProgramNowaitRelease NOROM_FlashsafeProgramNowaitRelease
109  #define FlashsafeDisableSectorsForWrite NOROM_FlashsafeDisableSectorsForWrite
110 #endif
111 
112 //*****************************************************************************
113 //
114 // Values that can be returned from the API functions
115 //
116 //*****************************************************************************
117 
118 #define FLASHSAFE_ACCESS_DENIED 0x000000ff
119 #define FLASHSAFE_ACCESS_OK 0x000000ee
120 #define SMPH_ALLOC_FLASH 1
121 
122 //*****************************************************************************
123 //
124 // Values that can be returned from the API functions
125 //
126 //*****************************************************************************
127 #define FAPI_STATUS_SUCCESS 0x00000000 // Function completed successfully
128 #define FAPI_STATUS_FSM_BUSY 0x00000001 // FSM is Busy
129 #define FAPI_STATUS_FSM_READY 0x00000002 // FSM is Ready
130 #define FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH \
131  0x00000003 // Incorrect parameter value
132 #define FAPI_STATUS_FSM_ERROR 0x00000004 // Operation failed
133 
134 //*****************************************************************************
135 //
136 // Values passed to FlashsafeIntEnable(), FlashsafeIntDisable() and FlashsafeIntClear() and
137 // returned from FlashsafeIntStatus().
138 //
139 //*****************************************************************************
140 #define FLASH_INT_FSM_DONE 0x00400000 // FSM Done Interrupt Mask
141 #define FLASH_INT_RV 0x00010000 // Read Verify error Interrupt Mask
142 
143 //*****************************************************************************
144 //
145 // Values passed to FlashsafeSetPowerMode() and returned from FlashsafeGetPowerMode().
146 //
147 //*****************************************************************************
148 #define FLASH_PWR_ACTIVE_MODE 0x00000000
149 #define FLASH_PWR_OFF_MODE 0x00000001
150 #define FLASH_PWR_DEEP_STDBY_MODE \
151  0x00000002
152 
153 //*****************************************************************************
154 //
155 // Values passed to FlashsafeSetProtection() and returned from FlashsafeGetProtection().
156 //
157 //*****************************************************************************
158 #define FLASH_NO_PROTECT 0x00000000 // Sector not protected
159 #define FLASH_WRITE_PROTECT 0x00000001 // Sector erase and program
160  // protected
161 
162 //*****************************************************************************
163 //
164 // Defines for values written to the FLASH_O_FSM_WR_ENA register
165 //
166 //*****************************************************************************
167 #define FSM_REG_WRT_ENABLE 5
168 #define FSM_REG_WRT_DISABLE 2
169 
170 //*****************************************************************************
171 //
175 //
176 //*****************************************************************************
177 __STATIC_INLINE bool
179 {
181 }
182 
183 //*****************************************************************************
184 //
188 //
189 //*****************************************************************************
190 __STATIC_INLINE void
192 {
194 }
195 
196 //*****************************************************************************
197 //
203 //
204 //*****************************************************************************
205 extern uint32_t FlashsafeSizeGet(void);
206 
207 //*****************************************************************************
208 //
214 //
215 //*****************************************************************************
216 extern uint32_t FlashsafeSectorSizeGet(void);
217 
218 //*****************************************************************************
219 //
265 //
266 //*****************************************************************************
267 extern uint32_t FlashsafePowerModeSet(uint32_t ui32PowerMode,
268  uint32_t ui32BankGracePeriode,
269  uint32_t ui32PumpGracePeriode);
270 
271 //*****************************************************************************
272 //
282 //
283 //*****************************************************************************
284 extern uint32_t FlashsafePowerModeGet(void);
285 
286 //*****************************************************************************
287 //
308 //
309 //*****************************************************************************
310 extern uint32_t FlashsafeProtectionSet(uint32_t ui32SectorAddress,
311  uint32_t ui32ProtectMode);
312 
313 //*****************************************************************************
314 //
326 //
327 //*****************************************************************************
328 extern uint32_t FlashsafeProtectionGet(uint32_t ui32SectorAddress);
329 
330 //*****************************************************************************
331 //
347 //
348 //*****************************************************************************
349 extern uint32_t FlashsafeProtectionSave(uint32_t ui32SectorAddress);
350 
351 //*****************************************************************************
352 //
362 //
363 //*****************************************************************************
364 extern uint32_t FlashsafeCheckFsmForError(void);
365 
366 //*****************************************************************************
367 //
377 //
378 //*****************************************************************************
379 extern uint32_t FlashsafeCheckFsmForReady(void);
380 
381 //*****************************************************************************
382 //
399 //
400 //*****************************************************************************
401 extern uint32_t FlashsafeIntRegister(void (*pfnHandler)(void));
402 
403 //*****************************************************************************
404 //
418 //
419 //*****************************************************************************
420 extern uint32_t FlashsafeIntUnregister(void);
421 
422 //*****************************************************************************
423 //
436 //
437 //*****************************************************************************
438 extern uint32_t FlashsafeIntEnable(uint32_t ui32IntFlags);
439 
440 //*****************************************************************************
441 //
454 //
455 //*****************************************************************************
456 extern uint32_t FlashsafeIntDisable(uint32_t ui32IntFlags);
457 
458 //*****************************************************************************
459 //
467 //
468 //*****************************************************************************
469 extern uint32_t FlashsafeIntStatus(void);
470 
471 //*****************************************************************************
472 //
496 //
497 //*****************************************************************************
498 extern uint32_t FlashsafeIntClear(uint32_t ui32IntFlags);
499 
500 //*****************************************************************************
501 //
523 //
524 //*****************************************************************************
525 extern uint32_t FlashsafeSectorErase(uint32_t ui32SectorAddress);
526 
527 //*****************************************************************************
528 //
556 //
557 //*****************************************************************************
558 extern uint32_t FlashsafeProgram(uint8_t *pui8DataBuffer, uint32_t ui32Address,
559  uint32_t ui32Count);
560 
561 //*****************************************************************************
562 //
573 //
574 //*****************************************************************************
575 extern uint32_t FlashsafeDisableSectorsForWrite(void);
576 
577 //*****************************************************************************
578 //
579 // Support for DriverLib in ROM:
580 // Redirect to implementation in ROM when available.
581 //
582 //*****************************************************************************
583 #ifndef DRIVERLIB_NOROM
584  #include <driverlib/rom.h>
585  #ifdef ROM_FlashsafeSizeGet
586  #undef FlashsafeSizeGet
587  #define FlashsafeSizeGet ROM_FlashsafeSizeGet
588  #endif
589  #ifdef ROM_FlashsafeSectorSizeGet
590  #undef FlashsafeSectorSizeGet
591  #define FlashsafeSectorSizeGet ROM_FlashsafeSectorSizeGet
592  #endif
593  #ifdef ROM_FlashsafePowerModeSet
594  #undef FlashsafePowerModeSet
595  #define FlashsafePowerModeSet ROM_FlashsafePowerModeSet
596  #endif
597  #ifdef ROM_FlashsafePowerModeGet
598  #undef FlashsafePowerModeGet
599  #define FlashsafePowerModeGet ROM_FlashsafePowerModeGet
600  #endif
601  #ifdef ROM_FlashsafeProtectionSet
602  #undef FlashsafeProtectionSet
603  #define FlashsafeProtectionSet ROM_FlashsafeProtectionSet
604  #endif
605  #ifdef ROM_FlashsafeProtectionGet
606  #undef FlashsafeProtectionGet
607  #define FlashsafeProtectionGet ROM_FlashsafeProtectionGet
608  #endif
609  #ifdef ROM_FlashsafeProtectionSave
610  #undef FlashsafeProtectionSave
611  #define FlashsafeProtectionSave ROM_FlashsafeProtectionSave
612  #endif
613  #ifdef ROM_FlashsafeCheckFsmForError
614  #undef FlashsafeCheckFsmForError
615  #define FlashsafeCheckFsmForError ROM_FlashsafeCheckFsmForError
616  #endif
617  #ifdef ROM_FlashsafeCheckFsmForReady
618  #undef FlashsafeCheckFsmForReady
619  #define FlashsafeCheckFsmForReady ROM_FlashsafeCheckFsmForReady
620  #endif
621  #ifdef ROM_FlashsafeIntRegister
622  #undef FlashsafeIntRegister
623  #define FlashsafeIntRegister ROM_FlashsafeIntRegister
624  #endif
625  #ifdef ROM_FlashsafeIntUnregister
626  #undef FlashsafeIntUnregister
627  #define FlashsafeIntUnregister ROM_FlashsafeIntUnregister
628  #endif
629  #ifdef ROM_FlashsafeIntEnable
630  #undef FlashsafeIntEnable
631  #define FlashsafeIntEnable ROM_FlashsafeIntEnable
632  #endif
633  #ifdef ROM_FlashsafeIntDisable
634  #undef FlashsafeIntDisable
635  #define FlashsafeIntDisable ROM_FlashsafeIntDisable
636  #endif
637  #ifdef ROM_FlashsafeIntStatus
638  #undef FlashsafeIntStatus
639  #define FlashsafeIntStatus ROM_FlashsafeIntStatus
640  #endif
641  #ifdef ROM_FlashsafeIntClear
642  #undef FlashsafeIntClear
643  #define FlashsafeIntClear ROM_FlashsafeIntClear
644  #endif
645  #ifdef ROM_FlashsafeSectorErase
646  #undef FlashsafeSectorErase
647  #define FlashsafeSectorErase ROM_FlashsafeSectorErase
648  #endif
649  #ifdef ROM_FlashsafeProgram
650  #undef FlashsafeProgram
651  #define FlashsafeProgram ROM_FlashsafeProgram
652  #endif
653  #ifdef ROM_FlashsafeProgramNowait
654  #undef FlashsafeProgramNowait
655  #define FlashsafeProgramNowait ROM_FlashsafeProgramNowait
656  #endif
657  #ifdef ROM_FlashsafeProgramNowaitRelease
658  #undef FlashsafeProgramNowaitRelease
659  #define FlashsafeProgramNowaitRelease ROM_FlashsafeProgramNowaitRelease
660  #endif
661  #ifdef ROM_FlashsafeDisableSectorsForWrite
662  #undef FlashsafeDisableSectorsForWrite
663  #define FlashsafeDisableSectorsForWrite ROM_FlashsafeDisableSectorsForWrite
664  #endif
665 #endif
666 
667 //*****************************************************************************
668 //
669 // Mark the end of the C bindings section for C++ compilers.
670 //
671 //*****************************************************************************
672 #ifdef __cplusplus
673 }
674 #endif
675 
676 #endif // __FLASHSAFE_H__
677 
678 //*****************************************************************************
679 //
682 //
683 //*****************************************************************************
__STATIC_INLINE bool FlashsafeSMPHTryAcquire(void)
Aquire the flash semaphore.
Definition: flashsafe.h:178
uint32_t FlashsafeSectorSizeGet(void)
Get size of a flash sector in no of bytes.
Definition: flashsafe.c:108
__STATIC_INLINE void FlashsafeSMPHRelease(void)
Release the flash semaphore.
Definition: flashsafe.h:191
uint32_t FlashsafeSectorErase(uint32_t ui32SectorAddress)
Erase a flash sector.
Definition: flashsafe.c:407
uint32_t FlashsafeIntEnable(uint32_t ui32IntFlags)
Enables flash controller interrupt sources.
Definition: flashsafe.c:337
uint32_t FlashsafeCheckFsmForError(void)
Checks if the Flashsafe state machine has detected an error.
Definition: flashsafe.c:247
uint32_t FlashsafePowerModeGet(void)
Get current configured power mode.
Definition: flashsafe.c:148
uint32_t FlashsafeProgram(uint8_t *pui8DataBuffer, uint32_t ui32Address, uint32_t ui32Count)
Programs unprotected main bank flash sectors.
Definition: flashsafe.c:435
uint32_t FlashsafeIntClear(uint32_t ui32IntFlags)
Clears flash controller interrupt source.
Definition: flashsafe.c:389
__STATIC_INLINE void SMPHRelease(uint32_t ui32Semaphore)
Release a semaphore.
Definition: smph.h:244
#define SMPH_ALLOC_FLASH
Definition: flashsafe.h:120
uint32_t FlashsafeIntDisable(uint32_t ui32IntFlags)
Disables individual flash controller interrupt sources.
Definition: flashsafe.c:358
uint32_t FlashsafeCheckFsmForReady(void)
Checks if the Flash state machine is ready.
Definition: flashsafe.c:265
uint32_t FlashsafeProtectionSet(uint32_t ui32SectorAddress, uint32_t ui32ProtectMode)
Set sector protection.
Definition: flashsafe.c:168
uint32_t FlashsafePowerModeSet(uint32_t ui32PowerMode, uint32_t ui32BankGracePeriode, uint32_t ui32PumpGracePeriode)
Set power mode.
Definition: flashsafe.c:119
uint32_t FlashsafeDisableSectorsForWrite(void)
Disables all sectors for erase and programming on the active bank.
Definition: flashsafe.c:461
uint32_t FlashsafeProtectionGet(uint32_t ui32SectorAddress)
Get sector protection.
Definition: flashsafe.c:193
uint32_t FlashsafeProtectionSave(uint32_t ui32SectorAddress)
Save sector protection to make it permanent.
Definition: flashsafe.c:220
uint32_t FlashsafeIntStatus(void)
Gets the current interrupt status.
Definition: flashsafe.c:378
__STATIC_INLINE bool SMPHTryAcquire(uint32_t ui32Semaphore)
Try to Acquire a semaphore.
Definition: smph.h:176
uint32_t FlashsafeSizeGet(void)
Get the size of the flash.
Definition: flashsafe.c:97
uint32_t FlashsafeIntUnregister(void)
Unregisters the interrupt handler for the flash interrupt.
Definition: flashsafe.c:310
uint32_t FlashsafeIntRegister(void(*pfnHandler)(void))
Registers an interrupt handler for the flash interrupt.
Definition: flashsafe.c:283