1 /******************************************************************************
2 * Filename: flash.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.
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38
39 //*****************************************************************************
40 //
41 //! \addtogroup system_control_group
42 //! @{
43 //! \addtogroup flash_api
44 //! @{
45 //
46 //*****************************************************************************
47
48 #ifndef __FLASH_H__
49 #define __FLASH_H__
50
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inc/hw_types.h>
65 #include <inc/hw_flash.h>
66 #include <inc/hw_memmap.h>
67 #include <inc/hw_ints.h>
68 #include <inc/hw_aon_sysctl.h>
69 #include <inc/hw_fcfg1.h>
70 #include <driverlib/interrupt.h>
71 #include <driverlib/debug.h>
72
73 //*****************************************************************************
74 //
75 // Support for DriverLib in ROM:
76 // This section renames all functions that are not "static inline", so that
77 // calling these functions will default to implementation in flash. At the end
78 // of this file a second renaming will change the defaults to implementation in
79 // ROM for available functions.
80 //
81 // To force use of the implementation in flash, e.g. for debugging:
82 // - Globally: Define DRIVERLIB_NOROM at project level
83 // - Per function: Use prefix "NOROM_" when calling the function
84 //
85 //*****************************************************************************
86 #if !defined(DOXYGEN)
87 #define FlashPowerModeSet NOROM_FlashPowerModeSet
88 #define FlashPowerModeGet NOROM_FlashPowerModeGet
89 #define FlashProtectionSet NOROM_FlashProtectionSet
90 #define FlashProtectionGet NOROM_FlashProtectionGet
91 #define FlashProtectionSave NOROM_FlashProtectionSave
92 #define FlashSectorErase NOROM_FlashSectorErase
93 #define FlashProgram NOROM_FlashProgram
94 #define FlashEfuseReadRow NOROM_FlashEfuseReadRow
95 #define FlashDisableSectorsForWrite NOROM_FlashDisableSectorsForWrite
96 #endif
97
98 //*****************************************************************************
99 //
100 // Values that can be returned from the API functions
101 //
102 //*****************************************************************************
103 #define FAPI_STATUS_SUCCESS 0x00000000 // Function completed successfully
104 #define FAPI_STATUS_FSM_BUSY 0x00000001 // FSM is Busy
105 #define FAPI_STATUS_FSM_READY 0x00000002 // FSM is Ready
106 #define FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH \
107 0x00000003 // Incorrect parameter value
108 #define FAPI_STATUS_FSM_ERROR 0x00000004 // Operation failed
109
110 //*****************************************************************************
111 //
112 // Values passed to FlashIntEnable(), FlashIntDisable() and FlashIntClear() and
113 // returned from FlashIntStatus().
114 //
115 //*****************************************************************************
116 #define FLASH_INT_FSM_DONE 0x00400000 // FSM Done Interrupt Mask
117 #define FLASH_INT_RV 0x00010000 // Read Verify error Interrupt Mask
118
119 //*****************************************************************************
120 //
121 // Values passed to FlashSetPowerMode() and returned from FlashGetPowerMode().
122 //
123 //*****************************************************************************
124 #define FLASH_PWR_ACTIVE_MODE 0x00000000
125 #define FLASH_PWR_OFF_MODE 0x00000001
126 #define FLASH_PWR_DEEP_STDBY_MODE \
127 0x00000002
128
129 //*****************************************************************************
130 //
131 // Values passed to FlashSetProtection() and returned from FlashGetProtection().
132 //
133 //*****************************************************************************
134 #define FLASH_NO_PROTECT 0x00000000 // Sector not protected
135 #define FLASH_WRITE_PROTECT 0x00000001 // Sector erase and program
136 // protected
137
138 //*****************************************************************************
139 //
140 // Define used by the flash programming and erase functions
141 //
142 //*****************************************************************************
143 #define ADDR_OFFSET (0x1F800000 - FLASHMEM_BASE)
144
145 //*****************************************************************************
146 //
147 // Define used for access to factory configuration area.
148 //
149 //*****************************************************************************
150 #define FCFG1_OFFSET 0x1000
151
152 //*****************************************************************************
153 //
154 // Define for the clock frequencey input to the flash module in number of MHz
155 //
156 //*****************************************************************************
157 #define FLASH_MODULE_CLK_FREQ 48
158
159 //*****************************************************************************
160 //
161 //! \brief Defined values for Flash State Machine commands
162 //
163 //*****************************************************************************
164 typedef enum
165 {
166 FAPI_PROGRAM_DATA = 0x0002, //!< Program data.
167 FAPI_ERASE_SECTOR = 0x0006, //!< Erase sector.
168 FAPI_ERASE_BANK = 0x0008, //!< Erase bank.
169 FAPI_VALIDATE_SECTOR = 0x000E, //!< Validate sector.
170 FAPI_CLEAR_STATUS = 0x0010, //!< Clear status.
171 FAPI_PROGRAM_RESUME = 0x0014, //!< Program resume.
172 FAPI_ERASE_RESUME = 0x0016, //!< Erase resume.
173 FAPI_CLEAR_MORE = 0x0018, //!< Clear more.
174 FAPI_PROGRAM_SECTOR = 0x0020, //!< Program sector.
175 FAPI_ERASE_OTP = 0x0030 //!< Erase OTP.
176 } tFlashStateCommandsType;
177
178 //*****************************************************************************
179 //
180 // Defines for values written to the FLASH_O_FSM_WR_ENA register
181 //
182 //*****************************************************************************
183 #define FSM_REG_WRT_ENABLE 5
184 #define FSM_REG_WRT_DISABLE 2
185
186 //*****************************************************************************
187 //
188 // Defines for the bank power mode field the FLASH_O_FBFALLBACK register
189 //
190 //*****************************************************************************
191 #define FBFALLBACK_SLEEP 0
192 #define FBFALLBACK_DEEP_STDBY 1
193 #define FBFALLBACK_ACTIVE 3
194
195 //*****************************************************************************
196 //
197 // Defines for the bank grace periode and pump grace periode
198 //
199 //*****************************************************************************
200 #define FLASH_BAGP 0x14
201 #define FLASH_PAGP 0x14
202
203 //*****************************************************************************
204 //
205 // Defines used by the FlashProgramPattern() function
206 //
207 //*****************************************************************************
208 #define PATTERN_BITS 0x20 // No of bits in data pattern to program
209
210 //*****************************************************************************
211 //
212 // Defines for the FW flag bits in the FLASH_O_FWFLAG register
213 //
214 //*****************************************************************************
215 #define FW_WRT_TRIMMED 0x00000001
216
217 //*****************************************************************************
218 //
219 // Defines used by the flash programming functions
220 //
221 //*****************************************************************************
222 typedef volatile uint8_t tFwpWriteByte;
223 #define FWPWRITE_BYTE_ADDRESS ((tFwpWriteByte *)((FLASH_BASE + FLASH_O_FWPWRITE0)))
224
225 //*****************************************************************************
226 //
227 // Define for efuse instruction
228 //
229 //*****************************************************************************
230 #define DUMPWORD_INSTR 0x04
231
232 //*****************************************************************************
233 //
234 // Define for FSM command execution
235 //
236 //*****************************************************************************
237 #define FLASH_CMD_EXEC 0x15
238
239 //*****************************************************************************
240 //
241 // Defines for accesses to the customer configuration area in flash top sector
242 //
243 //*****************************************************************************
244 #define CCFG_OFFSET_SECURITY 0x00000FD8
245 #define CCFG_OFFSET_SECT_PROT 0x00000FF0
246 #define CCFG_SIZE_SECURITY 0x00000014
247 #define CCFG_SIZE_SECT_PROT 0x00000004
248
249 //*****************************************************************************
250 //
251 //! \brief Get size of a flash sector in number of bytes.
252 //!
253 //! This function will return the size of a flash sector in number of bytes.
254 //!
255 //! \return Returns size of a flash sector in number of bytes.
256 //
257 //*****************************************************************************
258 __STATIC_INLINE uint32_t
FlashSectorSizeGet(void)259 FlashSectorSizeGet(void)
260 {
261 uint32_t ui32SectorSizeInKbyte;
262
263 ui32SectorSizeInKbyte = (HWREG(FLASH_BASE + FLASH_O_FCFG_B0_SSIZE0) &
264 FLASH_FCFG_B0_SSIZE0_B0_SECT_SIZE_M) >>
265 FLASH_FCFG_B0_SSIZE0_B0_SECT_SIZE_S;
266
267 //
268 // Return flash sector size in number of bytes.
269 //
270 return(ui32SectorSizeInKbyte * 1024);
271 }
272
273 //*****************************************************************************
274 //
275 //! \brief Get the size of the flash.
276 //!
277 //! This function returns the size of the flash main bank in number of bytes.
278 //!
279 //! \return Returns the flash size in number of bytes.
280 //
281 //*****************************************************************************
282 __STATIC_INLINE uint32_t
FlashSizeGet(void)283 FlashSizeGet(void)
284 {
285 uint32_t ui32NoOfSectors;
286
287 //
288 // Get number of flash sectors
289 //
290 ui32NoOfSectors = (HWREG(FLASH_BASE + FLASH_O_FLASH_SIZE) &
291 FLASH_FLASH_SIZE_SECTORS_M) >>
292 FLASH_FLASH_SIZE_SECTORS_S;
293
294 //
295 // Return flash size in number of bytes
296 //
297 return(ui32NoOfSectors * FlashSectorSizeGet());
298 }
299
300 //*****************************************************************************
301 //
302 //! \brief Set power mode.
303 //!
304 //! This function will set the specified power mode.
305 //!
306 //! Any access to the bank causes a reload of the specified bank grace periode
307 //! input value into the bank down counter. After the last access to the
308 //! flash bank, the down counter delays from 0 to 255 prescaled HCLK clock
309 //! cycles before putting the bank into one of the fallback power modes as
310 //! determined by \c ui32PowerMode. This value must be greater than 1 when the
311 //! fallback mode is not \ref FLASH_PWR_ACTIVE_MODE.
312 //!
313 //! Note: The prescaled clock used for the down counter is a clock divided by
314 //! 16 from input HCLK. The \c ui32BankGracePeriode parameter is ignored if
315 //! \c ui32PowerMode is equal to \ref FLASH_PWR_ACTIVE_MODE.
316 //! Any access to flash memory causes the pump grace periode down counter to
317 //! reload with value of \c ui32PumpGracePeriode. After the bank has gone to sleep,
318 //! the down counter delays this number of prescaled HCLK clock cycles before
319 //! entering one of the charge pump fallback power modes as determined by
320 //! \c ui32PowerMode. The prescaled clock used for the pump grace periode down
321 //! counter is a clock divided by 16 from input HCLK. This parameter is ignored
322 //! if \c ui32PowerMode is equal to \ref FLASH_PWR_ACTIVE_MODE.
323 //!
324 //! Changing the power mode of the flash module must be a part within a
325 //! device power mode transition requiring configuration of multiple modules.
326 //! Refer to documents describing the device power modes.
327 //!
328 //! \param ui32PowerMode is the wanted power mode.
329 //! The defined flash power modes are:
330 //! - \ref FLASH_PWR_ACTIVE_MODE
331 //! - \ref FLASH_PWR_OFF_MODE
332 //! - \ref FLASH_PWR_DEEP_STDBY_MODE
333 //! \param ui32BankGracePeriode is the starting count value for the bank grace
334 //! periode down counter.
335 //! \param ui32PumpGracePeriode is the starting count value for the pump grace
336 //! periode down counter.
337 //!
338 //! \return None
339 //
340 //*****************************************************************************
341 extern void FlashPowerModeSet(uint32_t ui32PowerMode,
342 uint32_t ui32BankGracePeriode,
343 uint32_t ui32PumpGracePeriode);
344
345 //*****************************************************************************
346 //
347 //! \brief Get current configured power mode.
348 //!
349 //! This function will return the current configured power mode.
350 //!
351 //! \return Returns the current configured power mode.
352 //! The defined power modes are:
353 //! - \ref FLASH_PWR_ACTIVE_MODE
354 //! - \ref FLASH_PWR_OFF_MODE
355 //! - \ref FLASH_PWR_DEEP_STDBY_MODE
356 //
357 //*****************************************************************************
358 extern uint32_t FlashPowerModeGet(void);
359
360 //*****************************************************************************
361 //
362 //! \brief Set sector protection.
363 //!
364 //! This function will set the specified protection on specified flash bank
365 //! sector. A sector can either have no protection or have write protection
366 //! which guards for both program and erase of that sector.
367 //! Sector protection can only be changed from \ref FLASH_NO_PROTECT to
368 //! \ref FLASH_WRITE_PROTECT! After write protecting a sector this sector can
369 //! only be set back to unprotected by a device reset.
370 //!
371 //! \param ui32SectorAddress is the start address of the sector to protect.
372 //! \param ui32ProtectMode is the enumerated sector protection mode.
373 //! - \ref FLASH_NO_PROTECT
374 //! - \ref FLASH_WRITE_PROTECT
375 //!
376 //! \return None
377 //
378 //*****************************************************************************
379 extern void FlashProtectionSet(uint32_t ui32SectorAddress,
380 uint32_t ui32ProtectMode);
381
382 //*****************************************************************************
383 //
384 //! \brief Get sector protection.
385 //!
386 //! This return the protection mode for the specified flash bank sector.
387 //!
388 //! \param ui32SectorAddress is the start address of the desired sector.
389 //!
390 //! \return Returns the sector protection:
391 //! - \ref FLASH_NO_PROTECT
392 //! - \ref FLASH_WRITE_PROTECT
393 //
394 //*****************************************************************************
395 extern uint32_t FlashProtectionGet(uint32_t ui32SectorAddress);
396
397 //*****************************************************************************
398 //
399 //! \brief Save sector protection to make it permanent.
400 //!
401 //! This function will save the current protection mode for the specified
402 //! flash bank sector.
403 //!
404 //! This function must only be executed from ROM or SRAM.
405 //!
406 //! \note A write protected sector will become permanent write
407 //! protected!! A device reset will not change the write protection!
408 //!
409 //! \param ui32SectorAddress is the start address of the sector to be protected.
410 //!
411 //! \return Returns the status of the sector protection:
412 //! - \ref FAPI_STATUS_SUCCESS : Success.
413 //! - \ref FAPI_STATUS_FSM_ERROR : An erase error is encountered.
414 //
415 //*****************************************************************************
416 extern uint32_t FlashProtectionSave(uint32_t ui32SectorAddress);
417
418 //*****************************************************************************
419 //
420 //! \brief Checks if the Flash state machine has detected an error.
421 //!
422 //! This function returns the status of the Flash State Machine indicating if
423 //! an error is detected or not. Primary use is to check if an Erase or
424 //! Program operation has failed.
425 //!
426 //! \note Please note that code can not execute in flash while any part of the flash
427 //! is being programmed or erased. This function must be called from ROM or
428 //! SRAM while any part of the flash is being programmed or erased.
429 //!
430 //! \return Returns status of Flash state machine:
431 //! - \ref FAPI_STATUS_FSM_ERROR
432 //! - \ref FAPI_STATUS_SUCCESS
433 //
434 //*****************************************************************************
435 __STATIC_INLINE uint32_t
FlashCheckFsmForError(void)436 FlashCheckFsmForError(void)
437 {
438 if(HWREG(FLASH_BASE + FLASH_O_FMSTAT) & FLASH_FMSTAT_CSTAT)
439 {
440 return(FAPI_STATUS_FSM_ERROR);
441 }
442 else
443 {
444 return(FAPI_STATUS_SUCCESS);
445 }
446 }
447
448 //*****************************************************************************
449 //
450 //! \brief Checks if the Flash state machine is ready.
451 //!
452 //! This function returns the status of the Flash State Machine indicating if
453 //! it is ready to accept a new command or not. Primary use is to check if an
454 //! Erase or Program operation has finished.
455 //!
456 //! \note Please note that code can not execute in flash while any part of the flash
457 //! is being programmed or erased. This function must be called from ROM or
458 //! SRAMh while any part of the flash is being programmed or erased.
459 //!
460 //! \return Returns readiness status of Flash state machine:
461 //! - \ref FAPI_STATUS_FSM_READY
462 //! - \ref FAPI_STATUS_FSM_BUSY
463 //
464 //*****************************************************************************
465 __STATIC_INLINE uint32_t
FlashCheckFsmForReady(void)466 FlashCheckFsmForReady(void)
467 {
468 if(HWREG(FLASH_BASE + FLASH_O_STAT) & FLASH_STAT_BUSY)
469 {
470 return(FAPI_STATUS_FSM_BUSY);
471 }
472 else
473 {
474 return(FAPI_STATUS_FSM_READY);
475 }
476 }
477
478 //*****************************************************************************
479 //
480 //! \brief Registers an interrupt handler for the flash interrupt.
481 //!
482 //! This function does the actual registering of the interrupt handler. This
483 //! function enables the global interrupt in the interrupt controller; specific
484 //! FLASH interrupts must be enabled via \ref FlashIntEnable(). It is the interrupt
485 //! handler's responsibility to clear the interrupt source.
486 //!
487 //! \param pfnHandler is a pointer to the function to be called when the flash
488 //! interrupt occurs.
489 //!
490 //! \return None
491 //!
492 //! \sa \ref IntRegister() for important information about registering interrupt
493 //! handlers.
494 //
495 //*****************************************************************************
496 __STATIC_INLINE void
FlashIntRegister(void (* pfnHandler)(void))497 FlashIntRegister(void (*pfnHandler)(void))
498 {
499 //
500 // Register the interrupt handler.
501 //
502 IntRegister(INT_FLASH, pfnHandler);
503
504 //
505 // Enable the flash interrupt.
506 //
507 IntEnable(INT_FLASH);
508 }
509
510 //*****************************************************************************
511 //
512 //! \brief Unregisters the interrupt handler for the flash interrupt.
513 //!
514 //! This function does the actual unregistering of the interrupt handler. It
515 //! clears the handler to be called when a FLASH interrupt occurs. This
516 //! function also masks off the interrupt in the interrupt controller so that
517 //! the interrupt handler no longer is called.
518 //!
519 //! \return None
520 //!
521 //! \sa \ref IntRegister() for important information about registering interrupt
522 //! handlers.
523 //
524 //*****************************************************************************
525 __STATIC_INLINE void
FlashIntUnregister(void)526 FlashIntUnregister(void)
527 {
528 //
529 // Disable the interrupts.
530 //
531 IntDisable(INT_FLASH);
532
533 //
534 // Unregister the interrupt handler.
535 //
536 IntUnregister(INT_FLASH);
537 }
538
539 //*****************************************************************************
540 //
541 //! \brief Enables flash controller interrupt sources.
542 //!
543 //! This function enables the flash controller interrupt sources.
544 //!
545 //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
546 //! The parameter is the bitwise OR of any of the following:
547 //! - \ref FLASH_INT_FSM_DONE : FSM Done interrupt.
548 //! - \ref FLASH_INT_RV : Read verify error interrupt.
549 //!
550 //! \return None
551 //
552 //*****************************************************************************
553 __STATIC_INLINE void
FlashIntEnable(uint32_t ui32IntFlags)554 FlashIntEnable(uint32_t ui32IntFlags)
555 {
556 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
557 HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) |= ui32IntFlags;
558 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
559 }
560
561 //*****************************************************************************
562 //
563 //! \brief Disables individual flash controller interrupt sources.
564 //!
565 //! This function disables the flash controller interrupt sources.
566 //!
567 //! \param ui32IntFlags is the bit mask of the interrupt sources to be disabled.
568 //! The parameter is the bitwise OR of any of the following:
569 //! - \ref FLASH_INT_FSM_DONE : FSM Done interrupt.
570 //! - \ref FLASH_INT_RV : Read verify error interrupt.
571 //!
572 //! \return None
573 //
574 //*****************************************************************************
575 __STATIC_INLINE void
FlashIntDisable(uint32_t ui32IntFlags)576 FlashIntDisable(uint32_t ui32IntFlags)
577 {
578 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
579 HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) &= ~ui32IntFlags;
580 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
581 }
582
583 //*****************************************************************************
584 //
585 //! \brief Gets the current interrupt status.
586 //!
587 //! This function returns the interrupt status for the Flash.
588 //!
589 //! \return Returns the current interrupt status as values described in
590 //! \ref FlashIntEnable().
591 //
592 //*****************************************************************************
593 __STATIC_INLINE uint32_t
FlashIntStatus(void)594 FlashIntStatus(void)
595 {
596 uint32_t ui32IntFlags;
597
598 ui32IntFlags = 0;
599
600 //
601 // Check if FSM_DONE interrupt status is set.
602 //
603 if(HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) & FLASH_FEDACSTAT_FSM_DONE)
604 {
605 ui32IntFlags = FLASH_INT_FSM_DONE;
606 }
607
608 //
609 // Check if RVF_INT interrupt status is set.
610 //
611 if(HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) & FLASH_FEDACSTAT_RVF_INT)
612 {
613 ui32IntFlags |= FLASH_INT_RV;
614 }
615
616 return(ui32IntFlags);
617 }
618
619 //*****************************************************************************
620 //
621 //! \brief Clears flash controller interrupt source.
622 //!
623 //! The flash controller interrupt source is cleared, so that it no longer
624 //! asserts. This must be done in the interrupt handler to keep it from being
625 //! called again immediately upon exit.
626 //!
627 //! \note Due to write buffers and synchronizers in the system it may take several
628 //! clock cycles from a register write clearing an event in a module and until the
629 //! event is actually cleared in the NVIC of the system CPU. It is recommended to
630 //! clear the event source early in the interrupt service routine (ISR) to allow
631 //! the event clear to propagate to the NVIC before returning from the ISR.
632 //! At the same time, an early event clear allows new events of the same type to be
633 //! pended instead of ignored if the event is cleared later in the ISR.
634 //! It is the responsibility of the programmer to make sure that enough time has passed
635 //! before returning from the ISR to avoid false re-triggering of the cleared event.
636 //! A simple, although not necessarily optimal, way of clearing an event before
637 //! returning from the ISR is:
638 //! -# Write to clear event (interrupt source). (buffered write)
639 //! -# Dummy read from the event source module. (making sure the write has propagated)
640 //! -# Wait two system CPU clock cycles (user code or two NOPs). (allowing cleared event to propagate through any synchronizers)
641 //!
642 //! \param ui32IntFlags is the bit mask of the interrupt sources to be cleared.
643 //! Can be any of:
644 //! - \ref FLASH_INT_FSM_DONE
645 //! - \ref FLASH_INT_RV
646 //!
647 //! \return None
648 //
649 //*****************************************************************************
650 __STATIC_INLINE void
FlashIntClear(uint32_t ui32IntFlags)651 FlashIntClear(uint32_t ui32IntFlags)
652 {
653 uint32_t ui32TempVal;
654
655 ui32TempVal = 0;
656
657 if(ui32IntFlags & FLASH_INT_FSM_DONE)
658 {
659 ui32TempVal = FLASH_FEDACSTAT_FSM_DONE;
660 }
661
662 if(ui32IntFlags & FLASH_INT_RV)
663 {
664 ui32TempVal |= FLASH_FEDACSTAT_RVF_INT;
665 }
666
667 //
668 // Clear the flash interrupt source.
669 //
670 HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) = ui32TempVal;
671 }
672
673 //*****************************************************************************
674 //
675 //! \brief Erase a flash sector.
676 //!
677 //! This function will erase the specified flash sector. The function will
678 //! not return until the flash sector has been erased or an error condition
679 //! occurred. If flash top sector is erased the function will program the
680 //! the device security data bytes with default values. The device security
681 //! data located in the customer configuration area of the flash top sector,
682 //! must have valid values at all times. These values affect the configuration
683 //! of the device during boot.
684 //!
685 //! \note Please note that code can not execute in flash while any part of the flash
686 //! is being programmed or erased. This function must only be executed from ROM
687 //! or SRAM.
688 //!
689 //! \param ui32SectorAddress is the starting address in flash of the sector to be
690 //! erased.
691 //!
692 //! \return Returns the status of the sector erase:
693 //! - \ref FAPI_STATUS_SUCCESS : Success.
694 //! - \ref FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH : Invalid argument.
695 //! - \ref FAPI_STATUS_FSM_ERROR : A programming error is encountered.
696 //
697 //*****************************************************************************
698 extern uint32_t FlashSectorErase(uint32_t ui32SectorAddress);
699
700
701 //*****************************************************************************
702 //
703 //! \brief Programs unprotected main bank flash sectors.
704 //!
705 //! This function will program a sequence of bytes into the on-chip flash.
706 //! Programming each location consists of the result of an AND operation
707 //! of the new data and the existing data; in other words bits that contain
708 //! 1 can remain 1 or be changed to 0, but bits that are 0 cannot be changed
709 //! to 1. Therefore, a byte can be programmed multiple times as long as these
710 //! rules are followed; if a program operation attempts to change a 0 bit to
711 //! a 1 bit, that bit will not have its value changed.
712 //!
713 //! This function will not return until the data has been programmed or an
714 //! programming error has occurred.
715 //!
716 //! \note Please note that code can not execute in flash while any part of the flash
717 //! is being programmed or erased. This function must only be executed from ROM
718 //! or SRAM.
719 //!
720 //! The \c pui8DataBuffer pointer can not point to flash.
721 //!
722 //! \param pui8DataBuffer is a pointer to the data to be programmed.
723 //! \param ui32Address is the starting address in flash to be programmed.
724 //! \param ui32Count is the number of bytes to be programmed.
725 //!
726 //! \return Returns status of the flash programming:
727 //! - \ref FAPI_STATUS_SUCCESS : Success.
728 //! - \ref FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH : Too many bytes were requested.
729 //! - \ref FAPI_STATUS_FSM_ERROR : A programming error is encountered.
730 //
731 //*****************************************************************************
732 extern uint32_t FlashProgram(uint8_t *pui8DataBuffer,
733 uint32_t ui32Address, uint32_t ui32Count);
734
735 //*****************************************************************************
736 //
737 //! \brief Reads efuse data from specified row.
738 //!
739 //! This function will read one efuse row.
740 //! It is assumed that any previous efuse operation has finished.
741 //!
742 //! \param pui32EfuseData is pointer to variable to be updated with efuse data.
743 //! \param ui32RowAddress is the efuse row number to be read. First row is row
744 //! number 0.
745 //!
746 //! \return Returns the status of the efuse read operation.
747 //! - \c false : OK status.
748 //! - \c true : Error status
749 //
750 //*****************************************************************************
751 extern bool FlashEfuseReadRow(uint32_t *pui32EfuseData,
752 uint32_t ui32RowAddress);
753
754 //*****************************************************************************
755 //
756 //! \brief Disables all sectors for erase and programming on the active bank.
757 //!
758 //! This function disables all sectors for erase and programming on the active
759 //! bank and enables the Idle Reading Power reduction mode if no low power
760 //! mode is configured. Furthermore, an additional level of protection from
761 //! erase is enabled.
762 //!
763 //! \note Please note that code can not execute in flash while any part of the flash
764 //! is being programmed or erased.
765 //!
766 //! \return None
767 //
768 //*****************************************************************************
769 extern void FlashDisableSectorsForWrite(void);
770
771
772 //*****************************************************************************
773 //
774 // Support for DriverLib in ROM:
775 // Redirect to implementation in ROM when available.
776 //
777 //*****************************************************************************
778 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
779 #include <driverlib/rom.h>
780 #ifdef ROM_FlashPowerModeSet
781 #undef FlashPowerModeSet
782 #define FlashPowerModeSet ROM_FlashPowerModeSet
783 #endif
784 #ifdef ROM_FlashPowerModeGet
785 #undef FlashPowerModeGet
786 #define FlashPowerModeGet ROM_FlashPowerModeGet
787 #endif
788 #ifdef ROM_FlashProtectionSet
789 #undef FlashProtectionSet
790 #define FlashProtectionSet ROM_FlashProtectionSet
791 #endif
792 #ifdef ROM_FlashProtectionGet
793 #undef FlashProtectionGet
794 #define FlashProtectionGet ROM_FlashProtectionGet
795 #endif
796 #ifdef ROM_FlashProtectionSave
797 #undef FlashProtectionSave
798 #define FlashProtectionSave ROM_FlashProtectionSave
799 #endif
800 #ifdef ROM_FlashSectorErase
801 #undef FlashSectorErase
802 #define FlashSectorErase ROM_FlashSectorErase
803 #endif
804 #ifdef ROM_FlashProgram
805 #undef FlashProgram
806 #define FlashProgram ROM_FlashProgram
807 #endif
808 #ifdef ROM_FlashEfuseReadRow
809 #undef FlashEfuseReadRow
810 #define FlashEfuseReadRow ROM_FlashEfuseReadRow
811 #endif
812 #ifdef ROM_FlashDisableSectorsForWrite
813 #undef FlashDisableSectorsForWrite
814 #define FlashDisableSectorsForWrite ROM_FlashDisableSectorsForWrite
815 #endif
816 #endif
817
818 //*****************************************************************************
819 //
820 // Mark the end of the C bindings section for C++ compilers.
821 //
822 //*****************************************************************************
823 #ifdef __cplusplus
824 }
825 #endif
826
827 #endif // __FLASH_H__
828
829 //*****************************************************************************
830 //
831 //! Close the Doxygen group.
832 //! @}
833 //! @}
834 //
835 //*****************************************************************************
836