apm32f10x_smc.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*!
  2. * @file apm32f10x_smc.h
  3. *
  4. * @brief This file contains all the functions prototypes for the SMC firmware library
  5. *
  6. * @version V1.0.4
  7. *
  8. * @date 2022-12-01
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2020-2022 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be useful and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32F10X_SMC_H
  27. #define __APM32F10X_SMC_H
  28. /* Includes */
  29. #include "apm32f10x.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /** @addtogroup APM32F10x_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup SMC_Driver SMC Driver
  37. @{
  38. */
  39. /** @defgroup SMC_Enumerations Enumerations
  40. @{
  41. */
  42. /**
  43. * @brief SMC NORSRAM_Bank
  44. */
  45. typedef enum
  46. {
  47. SMC_BANK1_NORSRAM_1 = 0x00000000,
  48. SMC_BANK1_NORSRAM_2 = 0x00000002,
  49. SMC_BANK1_NORSRAM_3 = 0x00000004,
  50. SMC_BANK1_NORSRAM_4 = 0x00000006
  51. } SMC_BANK1_NORSRAM_T;
  52. /**
  53. * @brief SMC NAND and PC Card Bank
  54. */
  55. typedef enum
  56. {
  57. SMC_BANK2_NAND = 0x00000010,
  58. SMC_BANK3_NAND = 0x00000100,
  59. SMC_BANK4_PCCARD = 0x00001000
  60. } SMC_BANK_NAND_T;
  61. /**
  62. * @brief SMC_Data_Address_Bus_Multiplexing
  63. */
  64. typedef enum
  65. {
  66. SMC_DATA_ADDRESS_MUX_DISABLE = 0x00000000,
  67. SMC_DATA_ADDRESS_MUX_ENABLE = 0x00000002
  68. } SMC_DATA_ADDRESS_MUX_T;
  69. /**
  70. * @brief SMC_Memory_Type
  71. */
  72. typedef enum
  73. {
  74. SMC_MEMORY_TYPE_SRAM = 0x00000000,
  75. SMC_MEMORY_TYPE_PSRAM = 0x00000004,
  76. SMC_MEMORY_TYPE_NOR = 0x00000008
  77. } SMC_MEMORY_TYPE_T;
  78. /**
  79. * @brief SMC_Data_Width
  80. */
  81. typedef enum
  82. {
  83. SMC_MEMORY_DATA_WIDTH_8BIT = 0x00000000,
  84. SMC_MEMORY_DATA_WIDTH_16BIT = 0x00000010
  85. } SMC_MEMORY_DATA_WIDTH_T;
  86. /**
  87. * @brief SMC_Burst_Access_Mode
  88. */
  89. typedef enum
  90. {
  91. SMC_BURST_ACCESS_MODE_DISABLE = 0x00000000,
  92. SMC_BURST_ACCESS_MODE_ENABLE = 0x00000100
  93. } SMC_BURST_ACCESS_MODE_T;
  94. /**
  95. * @brief SMC_AsynchronousWait
  96. */
  97. typedef enum
  98. {
  99. SMC_ASYNCHRONOUS_WAIT_DISABLE = 0x00000000,
  100. SMC_ASYNCHRONOUS_WAIT_ENABLE = 0x00008000
  101. } SMC_ASYNCHRONOUS_WAIT_T;
  102. /**
  103. * @brief SMC_Wait_Signal_Polarity
  104. */
  105. typedef enum
  106. {
  107. SMC_WAIT_SIGNAL_POLARITY_LOW = 0x00000000,
  108. SMC_WAIT_SIGNAL_POLARITY_HIGH = 0x00000200
  109. } SMC_WAIT_SIGNAL_POLARITY_T;
  110. /**
  111. * @brief SMC_Wrap_Mode
  112. */
  113. typedef enum
  114. {
  115. SMC_WRAP_MODE_DISABLE = 0x00000000,
  116. SMC_WRAP_MODE_ENABLE = 0x00000400
  117. } SMC_WRAP_MODE_T;
  118. /**
  119. * @brief SMC_Wait_Timing
  120. */
  121. typedef enum
  122. {
  123. SMC_WAIT_SIGNAL_ACTIVE_BEFORE_WAIT = 0x00000000,
  124. SMC_WAIT_SIGNAL_ACTIVE_DURING_WAIT = 0x00000800
  125. } SMC_WAIT_SIGNAL_ACTIVE_T;
  126. /**
  127. * @brief SMC_Write_Operation
  128. */
  129. typedef enum
  130. {
  131. SMC_WRITE_OPERATION_DISABLE = 0x00000000,
  132. SMC_WRITE_OPERATION_ENABLE = 0x00001000
  133. } SMC_WRITE_OPERATION_T;
  134. /**
  135. * @brief SMC_Wait_Signal
  136. */
  137. typedef enum
  138. {
  139. SMC_WAITE_SIGNAL_DISABLE = 0x00000000,
  140. SMC_WAITE_SIGNAL_ENABLE = 0x00002000
  141. } SMC_WAITE_SIGNAL_T;
  142. /**
  143. * @brief SMC_Extended_Mode
  144. */
  145. typedef enum
  146. {
  147. SMC_EXTENDEN_MODE_DISABLE = 0x00000000,
  148. SMC_EXTENDEN_MODE_ENABLE = 0x00004000
  149. } SMC_EXTENDEN_MODE_T;
  150. /**
  151. * @brief SMC_Write_Burst
  152. */
  153. typedef enum
  154. {
  155. SMC_WRITE_BURST_DISABLE = 0x00000000,
  156. SMC_WRITE_BURST_ENABLE = 0x00080000
  157. } SMC_WRITE_BURST_T;
  158. /**
  159. * @brief SMC_WAIT_FEATURE
  160. */
  161. typedef enum
  162. {
  163. SMC_WAIT_FEATURE_DISABLE = 0x00000000,
  164. SMC_WAIT_FEATURE_ENABLE = 0x00000002
  165. } SMC_WAIT_FEATURE_T;
  166. /**
  167. * @brief SMC_ECC
  168. */
  169. typedef enum
  170. {
  171. SMC_ECC_DISABLE = 0x00000000,
  172. SMC_ECC_ENABLE = 0x00000040
  173. } SMC_ECC_T;
  174. /**
  175. * @brief SMC_ECC_Page_Size
  176. */
  177. typedef enum
  178. {
  179. SMC_ECC_PAGE_SIZE_BYTE_256 = 0x00000000,
  180. SMC_ECC_PAGE_SIZE_BYTE_512 = 0x00020000,
  181. SMC_ECC_PAGE_SIZE_BYTE_1024 = 0x00040000,
  182. SMC_ECC_PAGE_SIZE_BYTE_2048 = 0x00060000,
  183. SMC_ECC_PAGE_SIZE_BYTE_4096 = 0x00080000,
  184. SMC_ECC_PAGE_SIZE_BYTE_8192 = 0x000A0000
  185. } SMC_ECC_PAGE_SIZE_BYTE_T;
  186. /**
  187. * @brief SMC_Access_Mode
  188. */
  189. typedef enum
  190. {
  191. SMC_ACCESS_MODE_A = 0x00000000,
  192. SMC_ACCESS_MODE_B = 0x10000000,
  193. SMC_ACCESS_MODE_C = 0x20000000,
  194. SMC_ACCESS_MODE_D = 0x30000000
  195. } SMC_ACCESS_MODE_T;
  196. /**
  197. * @brief SMC_Interrupt_sources
  198. */
  199. typedef enum
  200. {
  201. SMC_INT_EDGE_RISING = 0x00000008,
  202. SMC_INT_LEVEL_HIGH = 0x00000010,
  203. SMC_INT_EDGE_FALLING = 0x00000020
  204. } SMC_INT_T;
  205. /**
  206. * @brief SMC_Flags
  207. */
  208. typedef enum
  209. {
  210. SMC_FLAG_EDGE_RISING = 0x00000001,
  211. SMC_FLAG_LEVEL_HIGH = 0x00000002,
  212. SMC_FLAG_EDGE_FALLING = 0x00000004,
  213. SMC_FLAG_FIFO_EMPTY = 0x00000040
  214. } SMC_FLAG_T;
  215. /**@} end of group SMC_Enumerations */
  216. /** @defgroup SMC_Structures Structures
  217. @{
  218. */
  219. /**
  220. * @brief Timing parameters for NOR/SRAM Banks
  221. */
  222. typedef struct
  223. {
  224. uint32_t addressSetupTime;
  225. uint32_t addressHodeTime;
  226. uint32_t dataSetupTime;
  227. uint32_t busTurnaroundTime;
  228. uint32_t clockDivision;
  229. uint32_t dataLatency;
  230. SMC_ACCESS_MODE_T accessMode;
  231. } SMC_NORSRAMTimingConfig_T;
  232. /**
  233. * @brief SMC NOR/SRAM Configure structure
  234. */
  235. typedef struct
  236. {
  237. SMC_BANK1_NORSRAM_T bank;
  238. SMC_DATA_ADDRESS_MUX_T dataAddressMux;
  239. SMC_MEMORY_TYPE_T memoryType;
  240. SMC_MEMORY_DATA_WIDTH_T memoryDataWidth;
  241. SMC_BURST_ACCESS_MODE_T burstAcceesMode;
  242. SMC_ASYNCHRONOUS_WAIT_T asynchronousWait;
  243. SMC_WAIT_SIGNAL_POLARITY_T waitSignalPolarity;
  244. SMC_WRAP_MODE_T wrapMode;
  245. SMC_WAIT_SIGNAL_ACTIVE_T waitSignalActive;
  246. SMC_WRITE_OPERATION_T writeOperation;
  247. SMC_WAITE_SIGNAL_T waiteSignal;
  248. SMC_EXTENDEN_MODE_T extendedMode;
  249. SMC_WRITE_BURST_T writeBurst;
  250. SMC_NORSRAMTimingConfig_T* readWriteTimingStruct;
  251. SMC_NORSRAMTimingConfig_T* writeTimingStruct;
  252. } SMC_NORSRAMConfig_T;
  253. /**
  254. * @brief Timing parameters for NAND and PCCARD Banks
  255. */
  256. typedef struct
  257. {
  258. uint32_t setupTime;
  259. uint32_t waitSetupTime;
  260. uint32_t holdSetupTime;
  261. uint32_t HiZSetupTime;
  262. } SMC_NAND_PCCARDTimingConfig_T;
  263. /**
  264. * @brief SMC NAND Configure structure
  265. */
  266. typedef struct
  267. {
  268. SMC_BANK_NAND_T bank;
  269. SMC_WAIT_FEATURE_T waitFeature;
  270. SMC_MEMORY_DATA_WIDTH_T memoryDataWidth;
  271. SMC_ECC_T ECC;
  272. SMC_ECC_PAGE_SIZE_BYTE_T ECCPageSize;
  273. uint32_t TCLRSetupTime;
  274. uint32_t TARSetupTime;
  275. SMC_NAND_PCCARDTimingConfig_T* commonSpaceTimingStruct;
  276. SMC_NAND_PCCARDTimingConfig_T* attributeSpaceTimingStruct;
  277. } SMC_NANDConfig_T;
  278. /**
  279. * @brief SMC PCCARD Configure structure
  280. */
  281. typedef struct
  282. {
  283. SMC_WAIT_FEATURE_T waitFeature;
  284. uint32_t TCLRSetupTime;
  285. uint32_t TARSetupTime;
  286. SMC_NAND_PCCARDTimingConfig_T* commonSpaceTimingStruct;
  287. SMC_NAND_PCCARDTimingConfig_T* attributeSpaceTimingStruct;
  288. SMC_NAND_PCCARDTimingConfig_T* IOSpaceTimingStruct;
  289. } SMC_PCCARDConfig_T;
  290. /**@} end of group SMC_Structures */
  291. /** @defgroup SMC_Functions Functions
  292. @{
  293. */
  294. /* SMC reset */
  295. void SMC_ResetNORSRAM(SMC_BANK1_NORSRAM_T bank);
  296. void SMC_ResetNAND(SMC_BANK_NAND_T bank);
  297. void SMC_ResetPCCard(void);
  298. /* SMC Configuration */
  299. void SMC_ConfigNORSRAM(SMC_NORSRAMConfig_T* smcNORSRAMConfig);
  300. void SMC_ConfigNAND(SMC_NANDConfig_T* smcNANDConfig);
  301. void SMC_ConfigPCCard(SMC_PCCARDConfig_T* smcPCCardConfig);
  302. void SMC_ConfigNORSRAMStructInit(SMC_NORSRAMConfig_T* smcNORSRAMConfig);
  303. void SMC_ConfigNANDStructInit(SMC_NANDConfig_T* smcNANDConfig);
  304. void SMC_ConfigPCCardStructInit(SMC_PCCARDConfig_T* smcPCCardConfig);
  305. /* SMC bank control */
  306. void SMC_EnableNORSRAM(SMC_BANK1_NORSRAM_T bank);
  307. void SMC_DisableNORSRAM(SMC_BANK1_NORSRAM_T bank);
  308. void SMC_EnableNAND(SMC_BANK_NAND_T bank);
  309. void SMC_DisableNAND(SMC_BANK_NAND_T bank);
  310. void SMC_EnablePCCARD(void);
  311. void SMC_DisablePCCARD(void);
  312. void SMC_EnableNANDECC(SMC_BANK_NAND_T bank);
  313. void SMC_DisableNANDECC(SMC_BANK_NAND_T bank);
  314. uint32_t SMC_ReadECC(SMC_BANK_NAND_T bank);
  315. /* Interrupt and flag */
  316. void SMC_EnableInterrupt(SMC_BANK_NAND_T bank, uint32_t interrupt);
  317. void SMC_DisableInterrupt(SMC_BANK_NAND_T bank, uint32_t interrupt);
  318. uint8_t SMC_ReadStatusFlag(SMC_BANK_NAND_T bank, SMC_FLAG_T flag);
  319. void SMC_ClearStatusFlag(SMC_BANK_NAND_T bank, uint32_t flag);
  320. uint8_t SMC_ReadIntFlag(SMC_BANK_NAND_T bank, SMC_INT_T flag);
  321. void SMC_ClearIntFlag(SMC_BANK_NAND_T bank, uint32_t flag);
  322. /**@} end of group SMC_Functions */
  323. /**@} end of group SMC_Driver */
  324. /**@} end of group APM32F10x_StdPeriphDriver */
  325. #ifdef __cplusplus
  326. }
  327. #endif
  328. #endif /* __APM32F10X_SMC_H */