flc.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /**
  2. * @file
  3. * @brief Flash Controler driver.
  4. * @details This driver can be used to operate on the embedded flash memory.
  5. */
  6. /* ****************************************************************************
  7. * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a
  10. * copy of this software and associated documentation files (the "Software"),
  11. * to deal in the Software without restriction, including without limitation
  12. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. * and/or sell copies of the Software, and to permit persons to whom the
  14. * Software is furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included
  17. * in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  22. * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
  23. * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. * OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. * Except as contained in this notice, the name of Maxim Integrated
  28. * Products, Inc. shall not be used except as stated in the Maxim Integrated
  29. * Products, Inc. Branding Policy.
  30. *
  31. * The mere transfer of this software does not imply any licenses
  32. * of trade secrets, proprietary technology, copyrights, patents,
  33. * trademarks, maskwork rights, or any other form of intellectual
  34. * property whatsoever. Maxim Integrated Products, Inc. retains all
  35. * ownership rights.
  36. *
  37. * $Date: 2019-06-05 16:53:29 -0500 (Wed, 05 Jun 2019) $
  38. * $Revision: 43696 $
  39. *
  40. *************************************************************************** */
  41. #ifndef _FLC_H_
  42. #define _FLC_H_
  43. /* **** Includes **** */
  44. #include "flc_regs.h"
  45. #include "mxc_sys.h"
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. /**
  50. * @defgroup flc Flash Controller
  51. * @ingroup periphlibs
  52. * @{
  53. */
  54. /***** Definitions *****/
  55. /// Bit mask that can be used to find the starting address of a page in flash
  56. #define MXC_FLASH_PAGE_MASK ~(MXC_FLASH_PAGE_SIZE - 1)
  57. /// Calculate the address of a page in flash from the page number
  58. #define MXC_FLASH_PAGE_ADDR(page) (MXC_FLASH_MEM_BASE + ((unsigned long)page * MXC_FLASH_PAGE_SIZE))
  59. /***** Function Prototypes *****/
  60. /**
  61. * @brief Initializes the flash controller for erase/write operations
  62. * @param sys_cfg Reserved for future use. Use NULL as this parameter's value.
  63. * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful.
  64. */
  65. int FLC_Init(const sys_cfg_flc_t *sys_cfg);
  66. /**
  67. * @brief Checks if Flash controller is busy.
  68. * @details Reading or executing from flash is not possible if flash is busy
  69. * with an erase or write operation.
  70. * @return If non-zero, flash operation is in progress
  71. */
  72. int FLC_Busy(void);
  73. /**
  74. * @brief Erases the entire flash array.
  75. * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful.
  76. */
  77. int FLC_MassErase(void);
  78. /**
  79. * @brief Erases the page of flash at the specified address.
  80. * @param address Any address within the page to erase.
  81. * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful.
  82. */
  83. int FLC_PageErase(uint32_t address);
  84. /**
  85. * @brief Page erase from start to end address.
  86. * @note All data within the selected pages will be erased.
  87. * @param start Any address within the first page to erase.
  88. * @param end Any address within the last page to erase.
  89. * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful.
  90. */
  91. int FLC_Erase(uint32_t start, uint32_t end);
  92. /**
  93. * @brief Erase from start to end address. Restoring any flash page contents outside the given range.
  94. * @param start Starting address to erase, inclusive.
  95. * @param end Ending address to erase, exclusive.
  96. * @param buffer Data buffer to restore data in beginning and ending pages.
  97. * @param length Length of given buffer.
  98. *
  99. * @note Buffer should be appropriate size to store all of the data remaining in the
  100. * first and last pages. length should be greater than or equal to
  101. * (start % MXC_FLASH_PAGE_SIZE) and ((MXC_FLASH_PAGE_SIZE - (end % MXC_FLASH_PAGE_SIZE)) % MXC_FLASH_PAGE_SIZE).
  102. *
  103. * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful.
  104. */
  105. int FLC_BufferErase(uint32_t start, uint32_t end, uint8_t *buffer, unsigned length);
  106. /**
  107. * @brief Writes the specified 32-bit value to flash.
  108. * @param address 32-bit aligned address in flash to write.
  109. * @param data value to be written to flash.
  110. * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
  111. * unsuccessful.
  112. */
  113. int FLC_Write32(uint32_t address, uint32_t data);
  114. /**
  115. * @brief Writes the specified 128-bits of data to flash.
  116. * @param address 128-bit aligned address in flash to write.
  117. * @param data pointer to data to be written to flash.
  118. * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
  119. * unsuccessful.
  120. */
  121. int FLC_Write128(uint32_t address, uint32_t *data);
  122. /**
  123. * @brief Writes data to flash.
  124. * @param address Address in flash to start writing from.
  125. * @param length Number of bytes to be written.
  126. * @param buffer Pointer to data to be written to flash.
  127. * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
  128. * unsuccessful.
  129. */
  130. int FLC_Write(uint32_t address, uint32_t length, uint8_t *buffer);
  131. /**
  132. * @brief Enable flash interrupts
  133. * @param mask Interrupts to enable
  134. * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
  135. * unsuccessful.
  136. */
  137. int FLC_EnableInt(uint32_t mask);
  138. /**
  139. * @brief Disable flash interrupts
  140. * @param mask Interrupts to disable
  141. * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
  142. * unsuccessful.
  143. */
  144. int FLC_DisableInt(uint32_t mask);
  145. /**
  146. * @brief Retrieve flash interrupt flags
  147. * @return Mask of active flags.
  148. */
  149. int FLC_GetFlags(void);
  150. /**
  151. * @brief Clear flash interrupt flags
  152. * @note Provide the bit position to clear, even if the flag is write-0-to-clear
  153. * @param mask Mask of flags to clear
  154. * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
  155. * unsuccessful.
  156. */
  157. int FLC_ClearFlags(uint32_t mask);
  158. /**
  159. * @brief Unlock info block
  160. *
  161. * @return #E_NO_ERROR If function is successful.
  162. */
  163. int FLC_UnlockInfoBlock(void);
  164. /**
  165. * @brief Lock info block
  166. *
  167. * @return #E_NO_ERROR If function is successful.
  168. */
  169. int FLC_LockInfoBlock(void);
  170. /**@} end of group flc */
  171. #ifdef __cplusplus
  172. }
  173. #endif
  174. #endif /* _FLC_H_ */