drv_eflash.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /******************************************************************************
  17. * @file drv_eflash.h
  18. * @brief header file for eflash driver
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. #ifndef _CSI_EFLASH_H_
  23. #define _CSI_EFLASH_H_
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include <stdint.h>
  28. #include <drv_common.h>
  29. /// definition for eflash handle.
  30. typedef void *eflash_handle_t;
  31. /**
  32. \brief Flash information
  33. */
  34. typedef struct {
  35. uint32_t start; ///< Chip Start address
  36. uint32_t end; ///< Chip End address (start+size-1)
  37. uint32_t sector_count; ///< Number of sectors
  38. uint32_t sector_size; ///< Uniform sector size in bytes (0=sector_info used)
  39. uint32_t page_size; ///< Optimal programming page size in bytes
  40. uint32_t program_unit; ///< Smallest programmable unit in bytes
  41. uint8_t erased_value; ///< Contents of erased memory (usually 0xFF)
  42. } eflash_info;
  43. /**
  44. \brief Flash Status
  45. */
  46. typedef struct {
  47. uint32_t busy : 1; ///< Flash busy flag
  48. uint32_t error : 1; ///< Read/Program/Erase error flag (cleared on start of next operation)
  49. } eflash_status_t;
  50. /****** EFLASH Event *****/
  51. typedef enum {
  52. EFLASH_EVENT_READY = 0, ///< Flash Ready
  53. EFLASH_EVENT_ERROR , ///< Read/Program/Erase Error
  54. } eflash_event_e;
  55. typedef void (*eflash_event_cb_t)(eflash_event_e event); ///< Pointer to \ref eflash_event_cb_t : EFLASH Event call back.
  56. /**
  57. \brief Flash Driver Capabilities.
  58. */
  59. typedef struct {
  60. uint32_t event_ready : 1; ///< Signal Flash Ready event
  61. uint32_t data_width : 2; ///< Data width: 0=8-bit, 1=16-bit, 2=32-bit
  62. uint32_t erase_chip : 1; ///< Supports EraseChip operation
  63. } eflash_capabilities_t;
  64. // Function documentation
  65. /**
  66. \brief get eflash handle count.
  67. \return eflash handle count
  68. */
  69. int32_t csi_eflash_get_instance_count(void);
  70. /**
  71. \brief Initialize EFLASH Interface. 1. Initializes the resources needed for the EFLASH interface 2.registers event callback function
  72. \param[in] idx must not exceed return value of csi_eflash_get_instance_count()
  73. \param[in] cb_event Pointer to \ref eflash_event_cb_t
  74. \return pointer to eflash handle
  75. */
  76. eflash_handle_t csi_eflash_initialize(int32_t idx, eflash_event_cb_t cb_event);
  77. /**
  78. \brief De-initialize EFLASH Interface. stops operation and releases the software resources used by the interface
  79. \param[in] handle eflash handle to operate.
  80. \return error code
  81. */
  82. int32_t csi_eflash_uninitialize(eflash_handle_t handle);
  83. /**
  84. \brief Get driver capabilities.
  85. \param[in] handle eflash handle to operate.
  86. \return \ref eflash_capabilities_t
  87. */
  88. eflash_capabilities_t csi_eflash_get_capabilities(eflash_handle_t handle);
  89. /**
  90. \brief Read data from Flash.
  91. \param[in] handle eflash handle to operate.
  92. \param[in] addr Data address.
  93. \param[out] data Pointer to a buffer storing the data read from Flash.
  94. \param[in] cnt Number of data items to read.
  95. \return number of data items read or error code
  96. */
  97. int32_t csi_eflash_read(eflash_handle_t handle, uint32_t addr, void *data, uint32_t cnt);
  98. /**
  99. \brief Program data to Flash.
  100. \param[in] handle eflash handle to operate.
  101. \param[in] addr Data address.
  102. \param[in] data Pointer to a buffer containing the data to be programmed to Flash..
  103. \param[in] cnt Number of data items to program.
  104. \return number of data items programmed or error code
  105. */
  106. int32_t csi_eflash_program(eflash_handle_t handle, uint32_t addr, const void *data, uint32_t cnt);
  107. /**
  108. \brief Erase Flash Sector.
  109. \param[in] handle eflash handle to operate.
  110. \param[in] addr Sector address
  111. \return error code
  112. */
  113. int32_t csi_eflash_erase_sector(eflash_handle_t handle, uint32_t addr);
  114. /**
  115. \brief Erase complete Flash.
  116. \param[in] handle eflash handle to operate.
  117. \return error code
  118. */
  119. int32_t csi_eflash_erase_chip(eflash_handle_t handle);
  120. /**
  121. \brief Get Flash information.
  122. \param[in] handle eflash handle to operate.
  123. \return Pointer to Flash information \ref eflash_info
  124. */
  125. eflash_info *csi_eflash_get_info(eflash_handle_t handle);
  126. /**
  127. \brief Get EFLASH status.
  128. \param[in] handle eflash handle to operate.
  129. \return EFLASH status \ref eflash_status_t
  130. */
  131. eflash_status_t csi_eflash_get_status(eflash_handle_t handle);
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif /* _CSI_EFLASH_H_ */