Driver_Flash.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (c) 2013-2020 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * $Date: 24. January 2020
  19. * $Revision: V2.3
  20. *
  21. * Project: Flash Driver definitions
  22. */
  23. /* History:
  24. * Version 2.3
  25. * Removed volatile from ARM_FLASH_STATUS
  26. * Version 2.2
  27. * Padding bytes added to ARM_FLASH_INFO
  28. * Version 2.1
  29. * ARM_FLASH_STATUS made volatile
  30. * Version 2.0
  31. * Renamed driver NOR -> Flash (more generic)
  32. * Non-blocking operation
  33. * Added Events, Status and Capabilities
  34. * Linked Flash information (GetInfo)
  35. * Version 1.11
  36. * Changed prefix ARM_DRV -> ARM_DRIVER
  37. * Version 1.10
  38. * Namespace prefix ARM_ added
  39. * Version 1.00
  40. * Initial release
  41. */
  42. #ifndef DRIVER_FLASH_H_
  43. #define DRIVER_FLASH_H_
  44. #ifdef __cplusplus
  45. extern "C"
  46. {
  47. #endif
  48. #include "Driver_Common.h"
  49. #define ARM_FLASH_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,3) /* API version */
  50. #define _ARM_Driver_Flash_(n) Driver_Flash##n
  51. #define ARM_Driver_Flash_(n) _ARM_Driver_Flash_(n)
  52. #define ARM_FLASH_SECTOR_INFO(addr,size) { (addr), (addr)+(size)-1 }
  53. /**
  54. \brief Flash Sector information
  55. */
  56. typedef struct _ARM_FLASH_SECTOR {
  57. uint32_t start; ///< Sector Start address
  58. uint32_t end; ///< Sector End address (start+size-1)
  59. } const ARM_FLASH_SECTOR;
  60. /**
  61. \brief Flash information
  62. */
  63. typedef struct _ARM_FLASH_INFO {
  64. ARM_FLASH_SECTOR *sector_info; ///< Sector layout information (NULL=Uniform sectors)
  65. uint32_t sector_count; ///< Number of sectors
  66. uint32_t sector_size; ///< Uniform sector size in bytes (0=sector_info used)
  67. uint32_t page_size; ///< Optimal programming page size in bytes
  68. uint32_t program_unit; ///< Smallest programmable unit in bytes
  69. uint8_t erased_value; ///< Contents of erased memory (usually 0xFF)
  70. uint8_t reserved[3]; ///< Reserved (must be zero)
  71. } const ARM_FLASH_INFO;
  72. /**
  73. \brief Flash Status
  74. */
  75. typedef struct _ARM_FLASH_STATUS {
  76. uint32_t busy : 1; ///< Flash busy flag
  77. uint32_t error : 1; ///< Read/Program/Erase error flag (cleared on start of next operation)
  78. uint32_t reserved : 30;
  79. } ARM_FLASH_STATUS;
  80. /****** Flash Event *****/
  81. #define ARM_FLASH_EVENT_READY (1UL << 0) ///< Flash Ready
  82. #define ARM_FLASH_EVENT_ERROR (1UL << 1) ///< Read/Program/Erase Error
  83. // Function documentation
  84. /**
  85. \fn ARM_DRIVER_VERSION ARM_Flash_GetVersion (void)
  86. \brief Get driver version.
  87. \return \ref ARM_DRIVER_VERSION
  88. */
  89. /**
  90. \fn ARM_FLASH_CAPABILITIES ARM_Flash_GetCapabilities (void)
  91. \brief Get driver capabilities.
  92. \return \ref ARM_FLASH_CAPABILITIES
  93. */
  94. /**
  95. \fn int32_t ARM_Flash_Initialize (ARM_Flash_SignalEvent_t cb_event)
  96. \brief Initialize the Flash Interface.
  97. \param[in] cb_event Pointer to \ref ARM_Flash_SignalEvent
  98. \return \ref execution_status
  99. */
  100. /**
  101. \fn int32_t ARM_Flash_Uninitialize (void)
  102. \brief De-initialize the Flash Interface.
  103. \return \ref execution_status
  104. */
  105. /**
  106. \fn int32_t ARM_Flash_PowerControl (ARM_POWER_STATE state)
  107. \brief Control the Flash interface power.
  108. \param[in] state Power state
  109. \return \ref execution_status
  110. */
  111. /**
  112. \fn int32_t ARM_Flash_ReadData (uint32_t addr, void *data, uint32_t cnt)
  113. \brief Read data from Flash.
  114. \param[in] addr Data address.
  115. \param[out] data Pointer to a buffer storing the data read from Flash.
  116. \param[in] cnt Number of data items to read.
  117. \return number of data items read or \ref execution_status
  118. */
  119. /**
  120. \fn int32_t ARM_Flash_ProgramData (uint32_t addr, const void *data, uint32_t cnt)
  121. \brief Program data to Flash.
  122. \param[in] addr Data address.
  123. \param[in] data Pointer to a buffer containing the data to be programmed to Flash.
  124. \param[in] cnt Number of data items to program.
  125. \return number of data items programmed or \ref execution_status
  126. */
  127. /**
  128. \fn int32_t ARM_Flash_EraseSector (uint32_t addr)
  129. \brief Erase Flash Sector.
  130. \param[in] addr Sector address
  131. \return \ref execution_status
  132. */
  133. /**
  134. \fn int32_t ARM_Flash_EraseChip (void)
  135. \brief Erase complete Flash.
  136. Optional function for faster full chip erase.
  137. \return \ref execution_status
  138. */
  139. /**
  140. \fn ARM_FLASH_STATUS ARM_Flash_GetStatus (void)
  141. \brief Get Flash status.
  142. \return Flash status \ref ARM_FLASH_STATUS
  143. */
  144. /**
  145. \fn ARM_FLASH_INFO * ARM_Flash_GetInfo (void)
  146. \brief Get Flash information.
  147. \return Pointer to Flash information \ref ARM_FLASH_INFO
  148. */
  149. /**
  150. \fn void ARM_Flash_SignalEvent (uint32_t event)
  151. \brief Signal Flash event.
  152. \param[in] event Event notification mask
  153. \return none
  154. */
  155. typedef void (*ARM_Flash_SignalEvent_t) (uint32_t event); ///< Pointer to \ref ARM_Flash_SignalEvent : Signal Flash Event.
  156. /**
  157. \brief Flash Driver Capabilities.
  158. */
  159. typedef struct _ARM_FLASH_CAPABILITIES {
  160. uint32_t event_ready : 1; ///< Signal Flash Ready event
  161. uint32_t data_width : 2; ///< Data width: 0=8-bit, 1=16-bit, 2=32-bit
  162. uint32_t erase_chip : 1; ///< Supports EraseChip operation
  163. uint32_t reserved : 28; ///< Reserved (must be zero)
  164. } ARM_FLASH_CAPABILITIES;
  165. /**
  166. \brief Access structure of the Flash Driver
  167. */
  168. typedef struct _ARM_DRIVER_FLASH {
  169. ARM_DRIVER_VERSION (*GetVersion) (void); ///< Pointer to \ref ARM_Flash_GetVersion : Get driver version.
  170. ARM_FLASH_CAPABILITIES (*GetCapabilities)(void); ///< Pointer to \ref ARM_Flash_GetCapabilities : Get driver capabilities.
  171. int32_t (*Initialize) (ARM_Flash_SignalEvent_t cb_event); ///< Pointer to \ref ARM_Flash_Initialize : Initialize Flash Interface.
  172. int32_t (*Uninitialize) (void); ///< Pointer to \ref ARM_Flash_Uninitialize : De-initialize Flash Interface.
  173. int32_t (*PowerControl) (ARM_POWER_STATE state); ///< Pointer to \ref ARM_Flash_PowerControl : Control Flash Interface Power.
  174. int32_t (*ReadData) (uint32_t addr, void *data, uint32_t cnt); ///< Pointer to \ref ARM_Flash_ReadData : Read data from Flash.
  175. int32_t (*ProgramData) (uint32_t addr, const void *data, uint32_t cnt); ///< Pointer to \ref ARM_Flash_ProgramData : Program data to Flash.
  176. int32_t (*EraseSector) (uint32_t addr); ///< Pointer to \ref ARM_Flash_EraseSector : Erase Flash Sector.
  177. int32_t (*EraseChip) (void); ///< Pointer to \ref ARM_Flash_EraseChip : Erase complete Flash.
  178. ARM_FLASH_STATUS (*GetStatus) (void); ///< Pointer to \ref ARM_Flash_GetStatus : Get Flash status.
  179. ARM_FLASH_INFO * (*GetInfo) (void); ///< Pointer to \ref ARM_Flash_GetInfo : Get Flash information.
  180. } const ARM_DRIVER_FLASH;
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif /* DRIVER_FLASH_H_ */