fsl_eeprom.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_EEPROM_H_
  31. #define _FSL_EEPROM_H_
  32. #include "fsl_common.h"
  33. /*!
  34. * @addtogroup eeprom
  35. * @{
  36. */
  37. /*******************************************************************************
  38. * Definitions
  39. ******************************************************************************/
  40. /*! @name Driver version */
  41. /*@{*/
  42. /*! @brief EEPROM driver version 2.0.0. */
  43. #define FSL_EEPROM_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  44. /*@}*/
  45. /*! @brief EEPROM automatic program option */
  46. typedef enum _eeprom_auto_program
  47. {
  48. kEEPROM_AutoProgramDisable = 0x0, /*!< Disable auto program */
  49. kEEPROM_AutoProgramWriteWord = 0x1, /*!< Auto program triggered after 1 word is written */
  50. kEEPROM_AutoProgramLastWord = 0x2 /*!< Auto program triggered after last word of a page written */
  51. } eeprom_auto_program_t;
  52. /*! @brief EEPROM interrupt source */
  53. typedef enum _eeprom_interrupt_enable
  54. {
  55. kEEPROM_ProgramFinishInterruptEnable = EEPROM_INTENSET_PROG_SET_EN_MASK, /*!< Interrupt while program finished */
  56. } eeprom_interrupt_enable_t;
  57. /*!
  58. * @brief EEPROM region configuration structure.
  59. */
  60. typedef struct _eeprom_config
  61. {
  62. eeprom_auto_program_t autoProgram; /*!< Automatic program feature. */
  63. uint8_t readWaitPhase1; /*!< EEPROM read waiting phase 1 */
  64. uint8_t readWaitPhase2; /*!< EEPROM read waiting phase 2 */
  65. uint8_t writeWaitPhase1; /*!< EEPROM write waiting phase 1 */
  66. uint8_t writeWaitPhase2; /*!< EEPROM write waiting phase 2 */
  67. uint8_t writeWaitPhase3; /*!< EEPROM write waiting phase 3 */
  68. bool lockTimingParam; /*!< If lock the read and write wait phase settings */
  69. } eeprom_config_t;
  70. /*******************************************************************************
  71. * API
  72. ******************************************************************************/
  73. #if defined(__cplusplus)
  74. extern "C" {
  75. #endif /* _cplusplus */
  76. /*!
  77. * @name Initialization and deinitialization
  78. * @{
  79. */
  80. /*!
  81. * @brief Initializes the EEPROM with the user configuration structure.
  82. *
  83. * This function configures the EEPROM module with the user-defined configuration. This function also sets the
  84. * internal clock frequency to about 155kHz according to the source clock frequency.
  85. *
  86. * @param base EEPROM peripheral base address.
  87. * @param config The pointer to the configuration structure.
  88. * @param sourceClock_Hz EEPROM source clock frequency in Hz.
  89. */
  90. void EEPROM_Init(EEPROM_Type *base, const eeprom_config_t *config, uint32_t sourceClock_Hz);
  91. /*!
  92. * @brief Get EEPROM default configure settings.
  93. *
  94. * @param config EEPROM config structure pointer.
  95. */
  96. void EEPROM_GetDefaultConfig(eeprom_config_t *config);
  97. /*!
  98. * @brief Deinitializes the EEPROM regions.
  99. *
  100. * @param base EEPROM peripheral base address.
  101. */
  102. void EEPROM_Deinit(EEPROM_Type *base);
  103. /* @}*/
  104. /*!
  105. * @name Basic Control Operations
  106. * @{
  107. */
  108. /*!
  109. * @brief Set EEPROM automatic program feature.
  110. *
  111. * EEPROM write always needs a program and erase cycle to write the data into EEPROM. This program and erase cycle can
  112. * be finished automaticlly or manually. If users want to use or disable auto program feature, users can call this API.
  113. *
  114. * @param base EEPROM peripheral base address.
  115. * @param autoProgram EEPROM auto program feature need to set.
  116. */
  117. static inline void EEPROM_SetAutoProgram(EEPROM_Type *base, eeprom_auto_program_t autoProgram)
  118. {
  119. base->AUTOPROG = autoProgram;
  120. }
  121. /*!
  122. * @brief Set EEPROM to in/out power down mode.
  123. *
  124. * This function make EEPROM eneter or out of power mode. Notice that, users shall not put EEPROM into power down mode
  125. * while there is still any pending EEPROM operation. While EEPROM is wakes up from power down mode, any EEPROM
  126. * operation has to be suspended for 100 us.
  127. *
  128. * @param base EEPROM peripheral base address.
  129. * @param enable True means enter to power down mode, false means wake up.
  130. */
  131. static inline void EEPROM_SetPowerDownMode(EEPROM_Type *base, bool enable)
  132. {
  133. base->PWRDWN = enable;
  134. }
  135. /*!
  136. * @brief Enable EEPROM interrupt.
  137. *
  138. * @param base EEPROM peripheral base address.
  139. * @param mask EEPROM interrupt enable mask. It is a logic OR of members the
  140. * enumeration :: eeprom_interrupt_enable_t
  141. */
  142. static inline void EEPROM_EnableInterrupt(EEPROM_Type *base, uint32_t mask)
  143. {
  144. base->INTENSET = mask;
  145. }
  146. /*!
  147. * @brief Disable EEPROM interrupt.
  148. *
  149. * @param base EEPROM peripheral base address.
  150. * @param mask EEPROM interrupt enable mask. It is a logic OR of members the
  151. * enumeration :: eeprom_interrupt_enable_t
  152. */
  153. static inline void EEPROM_DisableInterrupt(EEPROM_Type *base, uint32_t mask)
  154. {
  155. base->INTENCLR = mask;
  156. }
  157. /*!
  158. * @brief Get the status of all interrupt flags for ERPROM.
  159. *
  160. * @param base EEPROM peripheral base address.
  161. * @return EEPROM interrupt flag status
  162. */
  163. static inline uint32_t EEPROM_GetInterruptStatus(EEPROM_Type *base)
  164. {
  165. return base->INTSTAT;
  166. }
  167. /*!
  168. * @brief Get the status of enabled interrupt flags for ERPROM.
  169. *
  170. * @param base EEPROM peripheral base address.
  171. * @return EEPROM enabled interrupt flag status
  172. */
  173. static inline uint32_t EEPROM_GetEnabledInterruptStatus(EEPROM_Type *base)
  174. {
  175. return base->INTEN;
  176. }
  177. /*!
  178. * @brief Set interrupt flags manually.
  179. *
  180. * This API trigger a interrupt manually, users can no need to wait for hardware trigger interrupt. Call this API will
  181. * set the corresponding bit in INSTAT register.
  182. *
  183. * @param base EEPROM peripheral base address.
  184. * @param mask EEPROM interrupt flag need to be set. It is a logic OR of members of
  185. * enumeration:: eeprom_interrupt_enable_t
  186. */
  187. static inline void EEPROM_SetInterruptFlag(EEPROM_Type *base, uint32_t mask)
  188. {
  189. base->INTSTATSET = mask;
  190. }
  191. /*!
  192. * @brief Clear interrupt flags manually.
  193. *
  194. * This API clears interrupt flags manually. Call this API will clear the corresponding bit in INSTAT register.
  195. *
  196. * @param base EEPROM peripheral base address.
  197. * @param mask EEPROM interrupt flag need to be cleared. It is a logic OR of members of
  198. * enumeration:: eeprom_interrupt_enable_t
  199. */
  200. static inline void EEPROM_ClearInterruptFlag(EEPROM_Type *base, uint32_t mask)
  201. {
  202. base->INTSTATCLR = mask;
  203. }
  204. /*!
  205. * @brief Write a word data in address of EEPROM.
  206. *
  207. * Users can write a page or at least a word data into EEPROM address.
  208. *
  209. * @param base EEPROM peripheral base address.
  210. * @param offset Offset from the begining address of EEPROM. This value shall be 4-byte aligned.
  211. * @param data Data need be write.
  212. */
  213. status_t EEPROM_WriteWord(EEPROM_Type *base, uint32_t offset, uint32_t data);
  214. /*!
  215. * @brief Write a page data into EEPROM.
  216. *
  217. * Users can write a page or at least a word data into EEPROM address.
  218. *
  219. * @param base EEPROM peripheral base address.
  220. * @param pageNum Page number to be written.
  221. * @param data Data need be write. This array data size shall equals to the page size.
  222. */
  223. status_t EEPROM_WritePage(EEPROM_Type *base, uint32_t pageNum, uint32_t *data);
  224. /* @} */
  225. #if defined(__cplusplus)
  226. }
  227. #endif
  228. /*! @}*/
  229. #endif /* _FSL_EEPROM_H_ */