hc32f460_efm.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*****************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. * opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file hc32f460_efm.h
  11. **
  12. ** A detailed description is available at
  13. ** @link EfmGroup EFM description @endlink
  14. **
  15. ** - 2018-10-29 CDT First version for Device Driver Library of EFM.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_EFM_H__
  19. #define __HC32F460_EFM_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_EFM_ENABLE == DDL_ON)
  26. /* C binding of definitions if building with C++ compiler */
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. *******************************************************************************
  33. ** \defgroup EfmGroup Embedded Flash Management unit(EFM)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /**
  41. *******************************************************************************
  42. ** \brief The flash status.
  43. **
  44. ******************************************************************************/
  45. typedef enum en_efm_flash_status
  46. {
  47. FlashReady = 1u, ///< The flash ready flag.
  48. FlashRWErr = 2u, ///< The flash read/write error flag.
  49. FlashEOP = 3u, ///< The flash end of operation flag.
  50. FlashPgMissMatch = 4u, ///< The flash program miss match flag.
  51. FlashPgSizeErr = 5u, ///< The flash program size error flag.
  52. FlashPgareaPErr = 6u, ///< The flash program protect area error flag.
  53. FlashWRPErr = 7u, ///< The flash write protect error flag.
  54. }en_efm_flash_status_t;
  55. /**
  56. *******************************************************************************
  57. ** \brief The flash read mode.
  58. **
  59. ******************************************************************************/
  60. typedef enum en_efm_read_md
  61. {
  62. NormalRead = 0u, ///< The flash normal read mode.
  63. UltraPowerRead = 1u, ///< The flash ultra power read mode.
  64. }en_efm_read_md_t;
  65. /**
  66. *******************************************************************************
  67. ** \brief The flash interrupt select.
  68. **
  69. ******************************************************************************/
  70. typedef enum en_efm_int_sel
  71. {
  72. PgmErsErrInt = 0u, ///< The flash program / erase error interrupt.
  73. EndPgmInt = 1u, ///< The flash end of program interrupt.
  74. ColErrInt = 2u, ///< The flash read collided error interrupt.
  75. }en_efm_int_sel_t;
  76. /**
  77. *******************************************************************************
  78. ** \brief The bus state while flash program & erase.
  79. **
  80. ******************************************************************************/
  81. typedef enum en_efm_bus_sta
  82. {
  83. BusBusy = 0u, ///< The bus busy while flash program & erase.
  84. BusRelease = 1u, ///< The bus release while flash program & erase.
  85. }en_efm_bus_sta_t;
  86. /**
  87. *******************************************************************************
  88. ** \brief Structure of windows protect address.
  89. **
  90. ** \note None.
  91. **
  92. ******************************************************************************/
  93. typedef struct stc_efm_win_protect_addr
  94. {
  95. uint32_t StartAddr; ///< The protect start address.
  96. uint32_t EndAddr; ///< The protect end address.
  97. }stc_efm_win_protect_addr_t;
  98. /**
  99. *******************************************************************************
  100. ** \brief Structure of unique ID.
  101. **
  102. ** \note None.
  103. **
  104. ******************************************************************************/
  105. typedef struct stc_efm_unique_id
  106. {
  107. uint32_t uniqueID1; ///< unique ID 1.
  108. uint32_t uniqueID2; ///< unique ID 2.
  109. uint32_t uniqueID3; ///< unique ID 3.
  110. }stc_efm_unique_id_t;
  111. /*******************************************************************************
  112. * Global pre-processor symbols/macros ('#define')
  113. ******************************************************************************/
  114. /* Flach latency cycle (0~15) */
  115. #define EFM_LATENCY_0 (0ul)
  116. #define EFM_LATENCY_1 (1ul)
  117. #define EFM_LATENCY_2 (2ul)
  118. #define EFM_LATENCY_3 (3ul)
  119. #define EFM_LATENCY_4 (4ul)
  120. #define EFM_LATENCY_5 (5ul)
  121. #define EFM_LATENCY_6 (6ul)
  122. #define EFM_LATENCY_7 (7ul)
  123. #define EFM_LATENCY_8 (8ul)
  124. #define EFM_LATENCY_9 (9ul)
  125. #define EFM_LATENCY_10 (10ul)
  126. #define EFM_LATENCY_11 (11ul)
  127. #define EFM_LATENCY_12 (12ul)
  128. #define EFM_LATENCY_13 (13ul)
  129. #define EFM_LATENCY_14 (14ul)
  130. #define EFM_LATENCY_15 (15ul)
  131. /* Flash flag */
  132. #define EFM_FLAG_WRPERR (0x00000001ul)
  133. #define EFM_FLAG_PEPRTERR (0x00000002ul)
  134. #define EFM_FLAG_PGSZERR (0x00000004ul)
  135. #define EFM_FLAG_PGMISMTCH (0x00000008ul)
  136. #define EFM_FLAG_EOP (0x00000010ul)
  137. #define EFM_FLAG_COLERR (0x00000020ul)
  138. #define EFM_FLAG_RDY (0x00000100ul)
  139. /* Flash operate mode */
  140. #define EFM_MODE_READONLY (0ul)
  141. #define EFM_MODE_SINGLEPROGRAM (1ul)
  142. #define EFM_MODE_SINGLEPROGRAMRB (2ul)
  143. #define EFM_MODE_SEQUENCEPROGRAM (3ul)
  144. #define EFM_MODE_SECTORERASE (4ul)
  145. #define EFM_MODE_CHIPERASE (5ul)
  146. /*******************************************************************************
  147. * Global variable definitions ('extern')
  148. ******************************************************************************/
  149. /*******************************************************************************
  150. * Global function prototypes (definition in C source)
  151. ******************************************************************************/
  152. void EFM_Unlock(void);
  153. void EFM_Lock(void);
  154. void EFM_FlashCmd(en_functional_state_t enNewState);
  155. void EFM_SetLatency(uint32_t u32Latency);
  156. void EFM_InstructionCacheCmd(en_functional_state_t enNewState);
  157. void EFM_DataCacheRstCmd(en_functional_state_t enNewState);
  158. void EFM_SetReadMode(en_efm_read_md_t enReadMD);
  159. void EFM_ErasePgmCmd(en_functional_state_t enNewState);
  160. en_result_t EFM_SetErasePgmMode(uint32_t u32Mode);
  161. void EFM_InterruptCmd(en_efm_int_sel_t enInt, en_functional_state_t enNewState);
  162. en_flag_status_t EFM_GetFlagStatus(uint32_t u32flag);
  163. en_flag_status_t EFM_GetSwitchStatus(void);
  164. void EFM_ClearFlag(uint32_t u32flag);
  165. en_efm_flash_status_t EFM_GetStatus(void);
  166. void EFM_SetBusState(en_efm_bus_sta_t enState);
  167. void EFM_SetWinProtectAddr(stc_efm_win_protect_addr_t stcAddr);
  168. en_result_t EFM_SingleProgram(uint32_t u32Addr, uint32_t u32Data);
  169. en_result_t EFM_SingleProgramRB(uint32_t u32Addr, uint32_t u32Data);
  170. en_result_t EFM_SequenceProgram(uint32_t u32Addr, uint32_t u32Len, void *pBuf);
  171. en_result_t EFM_SectorErase(uint32_t u32Addr);
  172. en_result_t EFM_MassErase(uint32_t u32Addr);
  173. en_result_t EFM_OtpLock(uint32_t u32Addr);
  174. stc_efm_unique_id_t EFM_ReadUID(void);
  175. //@} // EfmGroup
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179. #endif /* DDL_EFM_ENABLE */
  180. #endif /* __HC32F460_EFM_H__ */
  181. /*******************************************************************************
  182. * EOF (not truncated)
  183. ******************************************************************************/