Driver_Flash.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* -----------------------------------------------------------------------------
  2. * Copyright (c) 2013-2014 ARM Ltd.
  3. *
  4. * This software is provided 'as-is', without any express or implied warranty.
  5. * In no event will the authors be held liable for any damages arising from
  6. * the use of this software. Permission is granted to anyone to use this
  7. * software for any purpose, including commercial applications, and to alter
  8. * it and redistribute it freely, subject to the following restrictions:
  9. *
  10. * 1. The origin of this software must not be misrepresented; you must not
  11. * claim that you wrote the original software. If you use this software in
  12. * a product, an acknowledgment in the product documentation would be
  13. * appreciated but is not required.
  14. *
  15. * 2. Altered source versions must be plainly marked as such, and must not be
  16. * misrepresented as being the original software.
  17. *
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. *
  20. *
  21. * $Date: 31. Mar 2014
  22. * $Revision: V2.00
  23. *
  24. * Project: Flash Driver definitions
  25. * -------------------------------------------------------------------------- */
  26. /* History:
  27. * Version 2.00
  28. * Renamed driver NOR -> Flash (more generic)
  29. * Non-blocking operation
  30. * Added Events, Status and Capabilities
  31. * Linked Flash information (GetInfo)
  32. * Version 1.11
  33. * Changed prefix ARM_DRV -> ARM_DRIVER
  34. * Version 1.10
  35. * Namespace prefix ARM_ added
  36. * Version 1.00
  37. * Initial release
  38. */
  39. #ifndef __DRIVER_FLASH_H
  40. #define __DRIVER_FLASH_H
  41. #include "Driver_Common.h"
  42. #define ARM_FLASH_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,00) /* API version */
  43. #define _ARM_Driver_Flash_(n) Driver_Flash##n
  44. #define ARM_Driver_Flash_(n) _ARM_Driver_Flash_(n)
  45. #define ARM_FLASH_SECTOR_INFO(addr,size) { (addr), (addr)+(size)-1 }
  46. /**
  47. \brief Flash Sector information
  48. */
  49. typedef struct _ARM_FLASH_SECTOR {
  50. uint32_t start; ///< Sector Start address
  51. uint32_t end; ///< Sector End address (start+size-1)
  52. } const ARM_FLASH_SECTOR;
  53. /**
  54. \brief Flash information
  55. */
  56. typedef struct _ARM_FLASH_INFO {
  57. ARM_FLASH_SECTOR *sector_info; ///< Sector layout information (NULL=Uniform sectors)
  58. uint32_t sector_count; ///< Number of sectors
  59. uint32_t sector_size; ///< Uniform sector size in bytes (0=sector_info used)
  60. uint32_t page_size; ///< Optimal programming page size in bytes
  61. uint32_t program_unit; ///< Smallest programmable unit in bytes
  62. uint8_t erased_value; ///< Contents of erased memory (usually 0xFF)
  63. } const ARM_FLASH_INFO;
  64. /**
  65. \brief Flash Status
  66. */
  67. typedef struct _ARM_FLASH_STATUS {
  68. uint32_t busy : 1; ///< Flash busy flag
  69. uint32_t error : 1; ///< Read/Program/Erase error flag (cleared on start of next operation)
  70. } ARM_FLASH_STATUS;
  71. /****** Flash Event *****/
  72. #define ARM_FLASH_EVENT_READY (1UL << 0) ///< Flash Ready
  73. #define ARM_FLASH_EVENT_ERROR (1UL << 1) ///< Read/Program/Erase Error
  74. // Function documentation
  75. /**
  76. \fn ARM_DRIVER_VERSION ARM_Flash_GetVersion (void)
  77. \brief Get driver version.
  78. \return \ref ARM_DRIVER_VERSION
  79. */
  80. /**
  81. \fn ARM_FLASH_CAPABILITIES ARM_Flash_GetCapabilities (void)
  82. \brief Get driver capabilities.
  83. \return \ref ARM_FLASH_CAPABILITIES
  84. */
  85. /**
  86. \fn int32_t ARM_Flash_Initialize (ARM_Flash_SignalEvent_t cb_event)
  87. \brief Initialize the Flash Interface.
  88. \param[in] cb_event Pointer to \ref ARM_Flash_SignalEvent
  89. \return \ref execution_status
  90. */
  91. /**
  92. \fn int32_t ARM_Flash_Uninitialize (void)
  93. \brief De-initialize the Flash Interface.
  94. \return \ref execution_status
  95. */
  96. /**
  97. \fn int32_t ARM_Flash_PowerControl (ARM_POWER_STATE state)
  98. \brief Control the Flash interface power.
  99. \param[in] state Power state
  100. \return \ref execution_status
  101. */
  102. /**
  103. \fn int32_t ARM_Flash_ReadData (uint32_t addr, void *data, uint32_t cnt)
  104. \brief Read data from Flash.
  105. \param[in] addr Data address.
  106. \param[out] data Pointer to a buffer storing the data read from Flash.
  107. \param[in] cnt Number of data items to read.
  108. \return number of data items read or \ref execution_status
  109. */
  110. /**
  111. \fn int32_t ARM_Flash_ProgramData (uint32_t addr, const void *data, uint32_t cnt)
  112. \brief Program data to Flash.
  113. \param[in] addr Data address.
  114. \param[in] data Pointer to a buffer containing the data to be programmed to Flash.
  115. \param[in] cnt Number of data items to program.
  116. \return number of data items programmed or \ref execution_status
  117. */
  118. /**
  119. \fn int32_t ARM_Flash_EraseSector (uint32_t addr)
  120. \brief Erase Flash Sector.
  121. \param[in] addr Sector address
  122. \return \ref execution_status
  123. */
  124. /**
  125. \fn int32_t ARM_Flash_EraseChip (void)
  126. \brief Erase complete Flash.
  127. Optional function for faster full chip erase.
  128. \return \ref execution_status
  129. */
  130. /**
  131. \fn ARM_FLASH_STATUS ARM_Flash_GetStatus (void)
  132. \brief Get Flash status.
  133. \return Flash status \ref ARM_FLASH_STATUS
  134. */
  135. /**
  136. \fn ARM_FLASH_INFO * ARM_Flash_GetInfo (void)
  137. \brief Get Flash information.
  138. \return Pointer to Flash information \ref ARM_FLASH_INFO
  139. */
  140. /**
  141. \fn void ARM_Flash_SignalEvent (uint32_t event)
  142. \brief Signal Flash event.
  143. \param[in] event Event notification mask
  144. \return none
  145. */
  146. typedef void (*ARM_Flash_SignalEvent_t) (uint32_t event); ///< Pointer to \ref ARM_Flash_SignalEvent : Signal Flash Event.
  147. /**
  148. \brief Flash Driver Capabilities.
  149. */
  150. typedef struct _ARM_FLASH_CAPABILITIES {
  151. uint32_t event_ready : 1; ///< Signal Flash Ready event
  152. uint32_t data_width : 2; ///< Data width: 0=8-bit, 1=16-bit, 2=32-bit
  153. uint32_t erase_chip : 1; ///< Supports EraseChip operation
  154. } ARM_FLASH_CAPABILITIES;
  155. /**
  156. \brief Access structure of the Flash Driver
  157. */
  158. typedef struct _ARM_DRIVER_FLASH {
  159. ARM_DRIVER_VERSION (*GetVersion) (void); ///< Pointer to \ref ARM_Flash_GetVersion : Get driver version.
  160. ARM_FLASH_CAPABILITIES (*GetCapabilities)(void); ///< Pointer to \ref ARM_Flash_GetCapabilities : Get driver capabilities.
  161. int32_t (*Initialize) (ARM_Flash_SignalEvent_t cb_event); ///< Pointer to \ref ARM_Flash_Initialize : Initialize Flash Interface.
  162. int32_t (*Uninitialize) (void); ///< Pointer to \ref ARM_Flash_Uninitialize : De-initialize Flash Interface.
  163. int32_t (*PowerControl) (ARM_POWER_STATE state); ///< Pointer to \ref ARM_Flash_PowerControl : Control Flash Interface Power.
  164. int32_t (*ReadData) (uint32_t addr, void *data, uint32_t cnt); ///< Pointer to \ref ARM_Flash_ReadData : Read data from Flash.
  165. int32_t (*ProgramData) (uint32_t addr, const void *data, uint32_t cnt); ///< Pointer to \ref ARM_Flash_ProgramData : Program data to Flash.
  166. int32_t (*EraseSector) (uint32_t addr); ///< Pointer to \ref ARM_Flash_EraseSector : Erase Flash Sector.
  167. int32_t (*EraseChip) (void); ///< Pointer to \ref ARM_Flash_EraseChip : Erase complete Flash.
  168. ARM_FLASH_STATUS (*GetStatus) (void); ///< Pointer to \ref ARM_Flash_GetStatus : Get Flash status.
  169. ARM_FLASH_INFO * (*GetInfo) (void); ///< Pointer to \ref ARM_Flash_GetInfo : Get Flash information.
  170. } const ARM_DRIVER_FLASH;
  171. #endif /* __DRIVER_FLASH_H */