at32f403a_407_xmc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /**
  2. **************************************************************************
  3. * @file at32f403a_407_xmc.c
  4. * @brief contains all the functions for the xmc firmware library
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. #include "at32f403a_407_conf.h"
  25. /** @addtogroup AT32F403A_407_periph_driver
  26. * @{
  27. */
  28. /** @defgroup XMC
  29. * @brief XMC driver modules
  30. * @{
  31. */
  32. #ifdef XMC_MODULE_ENABLED
  33. /** @defgroup XMC_private_functions
  34. * @{
  35. */
  36. /**
  37. * @brief xmc nor or sram registers reset
  38. * @param xmc_subbank
  39. * this parameter can be one of the following values:
  40. * - XMC_BANK1_NOR_SRAM1
  41. * - XMC_BANK1_NOR_SRAM4
  42. * @retval none
  43. */
  44. void xmc_nor_sram_reset(xmc_nor_sram_subbank_type xmc_subbank)
  45. {
  46. /* XMC_BANK1_NORSRAM1 */
  47. if(xmc_subbank == XMC_BANK1_NOR_SRAM1)
  48. {
  49. XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1ctrl = 0x000030DB;
  50. }
  51. /* XMC_BANK1_NORSRAM2, XMC_BANK1_NORSRAM3 or XMC_BANK1_NORSRAM4 */
  52. else
  53. {
  54. XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1ctrl = 0x000030D2;
  55. }
  56. XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1tmg = 0x0FFFFFFF;
  57. XMC_BANK1->tmgwr_group[xmc_subbank].bk1tmgwr = 0x0FFFFFFF;
  58. }
  59. /**
  60. * @brief initialize the xmc nor/sram banks according to the specified
  61. * parameters in the xmc_norsraminitstruct.
  62. * @param xmc_norsram_init_struct : pointer to a xmc_norsram_init_type
  63. * structure that contains the configuration information for
  64. * the xmc nor/sram specified banks.
  65. * @retval none
  66. */
  67. void xmc_nor_sram_init(xmc_norsram_init_type* xmc_norsram_init_struct)
  68. {
  69. /* bank1 nor/sram control register configuration */
  70. XMC_BANK1->ctrl_tmg_group[xmc_norsram_init_struct->subbank].bk1ctrl =
  71. (uint32_t)xmc_norsram_init_struct->data_addr_multiplex |
  72. xmc_norsram_init_struct->device |
  73. xmc_norsram_init_struct->bus_type |
  74. xmc_norsram_init_struct->burst_mode_enable |
  75. xmc_norsram_init_struct->asynwait_enable |
  76. xmc_norsram_init_struct->wait_signal_lv |
  77. xmc_norsram_init_struct->wrapped_mode_enable |
  78. xmc_norsram_init_struct->wait_signal_config |
  79. xmc_norsram_init_struct->write_enable |
  80. xmc_norsram_init_struct->wait_signal_enable |
  81. xmc_norsram_init_struct->write_timing_enable |
  82. xmc_norsram_init_struct->write_burst_syn;
  83. /* if nor flash device */
  84. if(xmc_norsram_init_struct->device == XMC_DEVICE_NOR)
  85. {
  86. XMC_BANK1->ctrl_tmg_group[xmc_norsram_init_struct->subbank].bk1ctrl_bit.noren = 0x1;
  87. }
  88. }
  89. /**
  90. * @brief initialize the xmc nor/sram banks according to the specified
  91. * parameters in the xmc_rw_timing_struct and xmc_w_timing_struct.
  92. * @param xmc_rw_timing_struct : pointer to a xmc_norsram_timing_init_type
  93. * structure that contains the configuration information for
  94. * the xmc nor/sram specified banks.
  95. * @param xmc_w_timing_struct : pointer to a xmc_norsram_timing_init_type
  96. * structure that contains the configuration information for
  97. * the xmc nor/sram specified banks.
  98. * @retval none
  99. */
  100. void xmc_nor_sram_timing_config(xmc_norsram_timing_init_type* xmc_rw_timing_struct,
  101. xmc_norsram_timing_init_type* xmc_w_timing_struct)
  102. {
  103. /* bank1 nor/sram timing register configuration */
  104. XMC_BANK1->ctrl_tmg_group[xmc_rw_timing_struct->subbank].bk1tmg =
  105. (uint32_t)xmc_rw_timing_struct->addr_setup_time |
  106. (xmc_rw_timing_struct->addr_hold_time << 4) |
  107. (xmc_rw_timing_struct->data_setup_time << 8) |
  108. (xmc_rw_timing_struct->bus_latency_time <<16) |
  109. (xmc_rw_timing_struct->clk_psc << 20) |
  110. (xmc_rw_timing_struct->data_latency_time << 24) |
  111. xmc_rw_timing_struct->mode;
  112. /* bank1 nor/sram timing register for write configuration, if extended mode is used */
  113. if(xmc_rw_timing_struct->write_timing_enable == XMC_WRITE_TIMING_ENABLE)
  114. {
  115. XMC_BANK1->tmgwr_group[xmc_w_timing_struct->subbank].bk1tmgwr =
  116. (uint32_t)xmc_w_timing_struct->addr_setup_time |
  117. (xmc_w_timing_struct->addr_hold_time << 4) |
  118. (xmc_w_timing_struct->data_setup_time << 8) |
  119. (xmc_w_timing_struct->bus_latency_time << 16) |
  120. (xmc_w_timing_struct->clk_psc << 20) |
  121. (xmc_w_timing_struct->data_latency_time << 24) |
  122. xmc_w_timing_struct->mode;
  123. }
  124. else
  125. {
  126. XMC_BANK1->tmgwr_group[xmc_w_timing_struct->subbank].bk1tmgwr = 0x0FFFFFFF;
  127. }
  128. }
  129. /**
  130. * @brief fill each xmc_nor_sram_init_struct member with its default value.
  131. * @param xmc_nor_sram_init_struct: pointer to a xmc_norsram_init_type
  132. * structure which will be initialized.
  133. * @retval none
  134. */
  135. void xmc_norsram_default_para_init(xmc_norsram_init_type* xmc_nor_sram_init_struct)
  136. {
  137. /* reset nor/sram init structure parameters values */
  138. xmc_nor_sram_init_struct->subbank = XMC_BANK1_NOR_SRAM1;
  139. xmc_nor_sram_init_struct->data_addr_multiplex = XMC_DATA_ADDR_MUX_ENABLE;
  140. xmc_nor_sram_init_struct->device = XMC_DEVICE_SRAM;
  141. xmc_nor_sram_init_struct->bus_type = XMC_BUSTYPE_8_BITS;
  142. xmc_nor_sram_init_struct->burst_mode_enable = XMC_BURST_MODE_DISABLE;
  143. xmc_nor_sram_init_struct->asynwait_enable = XMC_ASYN_WAIT_DISABLE;
  144. xmc_nor_sram_init_struct->wait_signal_lv = XMC_WAIT_SIGNAL_LEVEL_LOW;
  145. xmc_nor_sram_init_struct->wrapped_mode_enable = XMC_WRAPPED_MODE_DISABLE;
  146. xmc_nor_sram_init_struct->wait_signal_config = XMC_WAIT_SIGNAL_SYN_BEFORE;
  147. xmc_nor_sram_init_struct->write_enable = XMC_WRITE_OPERATION_ENABLE;
  148. xmc_nor_sram_init_struct->wait_signal_enable = XMC_WAIT_SIGNAL_ENABLE;
  149. xmc_nor_sram_init_struct->write_timing_enable = XMC_WRITE_TIMING_DISABLE;
  150. xmc_nor_sram_init_struct->write_burst_syn = XMC_WRITE_BURST_SYN_DISABLE;
  151. }
  152. /**
  153. * @brief fill each xmc_rw_timing_struct and xmc_w_timing_struct member with its default value.
  154. * @param xmc_rw_timing_struct: pointer to a xmc_norsram_timing_init_type
  155. * structure which will be initialized.
  156. * @param xmc_w_timing_struct: pointer to a xmc_norsram_timing_init_type
  157. * structure which will be initialized.
  158. * @retval none
  159. */
  160. void xmc_norsram_timing_default_para_init(xmc_norsram_timing_init_type* xmc_rw_timing_struct,
  161. xmc_norsram_timing_init_type* xmc_w_timing_struct)
  162. {
  163. xmc_rw_timing_struct->subbank = XMC_BANK1_NOR_SRAM1;
  164. xmc_rw_timing_struct->write_timing_enable = XMC_WRITE_TIMING_DISABLE;
  165. xmc_rw_timing_struct->addr_setup_time = 0xF;
  166. xmc_rw_timing_struct->addr_hold_time = 0xF;
  167. xmc_rw_timing_struct->data_setup_time = 0xFF;
  168. xmc_rw_timing_struct->bus_latency_time = 0xF;
  169. xmc_rw_timing_struct->clk_psc = 0xF;
  170. xmc_rw_timing_struct->data_latency_time = 0xF;
  171. xmc_rw_timing_struct->mode = XMC_ACCESS_MODE_A;
  172. xmc_w_timing_struct->subbank = XMC_BANK1_NOR_SRAM1;
  173. xmc_w_timing_struct->write_timing_enable = XMC_WRITE_TIMING_DISABLE;
  174. xmc_w_timing_struct->addr_setup_time = 0xF;
  175. xmc_w_timing_struct->addr_hold_time = 0xF;
  176. xmc_w_timing_struct->data_setup_time = 0xFF;
  177. xmc_w_timing_struct->bus_latency_time = 0xF;
  178. xmc_w_timing_struct->clk_psc = 0xF;
  179. xmc_w_timing_struct->data_latency_time = 0xF;
  180. xmc_w_timing_struct->mode = XMC_ACCESS_MODE_A;
  181. }
  182. /**
  183. * @brief enable or disable the specified nor/sram memory bank.
  184. * @param xmc_subbank
  185. * this parameter can be one of the following values:
  186. * - XMC_BANK1_NOR_SRAM1
  187. * - XMC_BANK1_NOR_SRAM4
  188. * @param new_state (TRUE or FALSE)
  189. * @retval none
  190. */
  191. void xmc_nor_sram_enable(xmc_nor_sram_subbank_type xmc_subbank, confirm_state new_state)
  192. {
  193. XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1ctrl_bit.en = new_state;
  194. }
  195. /**
  196. * @brief config the bus turnaround phase.
  197. * @param xmc_sub_bank
  198. * this parameter can be one of the following values:
  199. * - XMC_BANK1_NOR_SRAM1
  200. * - XMC_BANK1_NOR_SRAM4
  201. * @param w2w_timing :write timing
  202. * @param r2r_timing :read timing
  203. * @retval none
  204. */
  205. void xmc_ext_timing_config(volatile xmc_nor_sram_subbank_type xmc_sub_bank, uint16_t w2w_timing, uint16_t r2r_timing)
  206. {
  207. XMC_BANK1->ext_bit[xmc_sub_bank].buslatr2r = r2r_timing;
  208. XMC_BANK1->ext_bit[xmc_sub_bank].buslatw2w = w2w_timing;
  209. }
  210. /**
  211. * @brief xmc nand flash registers reset
  212. * @param xmc_bank
  213. * this parameter can be one of the following values:
  214. * - XMC_BANK2_NAND
  215. * @retval none
  216. */
  217. void xmc_nand_reset(xmc_class_bank_type xmc_bank)
  218. {
  219. /* set the XMC_BANK2_NAND registers to their reset values */
  220. if(xmc_bank == XMC_BANK2_NAND)
  221. {
  222. XMC_BANK2->bk2ctrl = 0x00000018;
  223. XMC_BANK2->bk2is = 0x00000040;
  224. XMC_BANK2->bk2tmgatt = 0xFCFCFCFC;
  225. XMC_BANK2->bk2tmgmem = 0xFCFCFCFC;
  226. }
  227. }
  228. /**
  229. * @brief initialize the xmc nand banks according to the specified
  230. * parameters in the xmc_nandinitstruct.
  231. * @param xmc_nand_init_struct : pointer to a xmc_nand_init_type
  232. * structure that contains the configuration information for the xmc
  233. * nand specified banks.
  234. * @retval none
  235. */
  236. void xmc_nand_init(xmc_nand_init_type* xmc_nand_init_struct)
  237. {
  238. uint32_t tempctrl = 0x0;
  239. /* Set the tempctrl value according to xmc_nand_init_struct parameters */
  240. tempctrl = (uint32_t)xmc_nand_init_struct->wait_enable |
  241. xmc_nand_init_struct->bus_type |
  242. xmc_nand_init_struct->ecc_enable |
  243. xmc_nand_init_struct->ecc_pagesize |
  244. (xmc_nand_init_struct->delay_time_cycle << 9) |
  245. (xmc_nand_init_struct->delay_time_ar << 13) |
  246. 0x00000008;
  247. /* xmc_bank2_nand registers configuration */
  248. if(xmc_nand_init_struct->nand_bank == XMC_BANK2_NAND)
  249. {
  250. XMC_BANK2->bk2ctrl = tempctrl;
  251. }
  252. }
  253. /**
  254. * @brief initialize the xmc nand banks according to the specified
  255. * parameters in the xmc_nandinitstruct.
  256. * @param xmc_regular_spacetiming_struct : pointer to a xmc_nand_timinginit_type
  257. * structure that contains the configuration information for the xmc
  258. * nand specified banks.
  259. * @param xmc_special_spacetiming_struct : pointer to a xmc_nand_timinginit_type
  260. * structure that contains the configuration information for the xmc
  261. * nand specified banks.
  262. * @retval none
  263. */
  264. void xmc_nand_timing_config(xmc_nand_timinginit_type* xmc_regular_spacetiming_struct,
  265. xmc_nand_timinginit_type* xmc_special_spacetiming_struct)
  266. {
  267. uint32_t tempmem = 0x0, tempatt = 0x0;
  268. /* set the tempmem value according to xmc_nand_init_struct parameters */
  269. tempmem = (uint32_t)xmc_regular_spacetiming_struct->mem_setup_time |
  270. (xmc_regular_spacetiming_struct->mem_waite_time << 8) |
  271. (xmc_regular_spacetiming_struct->mem_hold_time << 16) |
  272. (xmc_regular_spacetiming_struct->mem_hiz_time << 24);
  273. /* set the tempatt value according to xmc_nand_init_struct parameters */
  274. tempatt = (uint32_t)xmc_special_spacetiming_struct->mem_setup_time |
  275. (xmc_special_spacetiming_struct->mem_waite_time << 8) |
  276. (xmc_special_spacetiming_struct->mem_hold_time << 16) |
  277. (xmc_special_spacetiming_struct->mem_hiz_time << 24);
  278. /* xmc_bank2_nand registers configuration */
  279. if(xmc_regular_spacetiming_struct->class_bank == XMC_BANK2_NAND)
  280. {
  281. XMC_BANK2->bk2tmgatt = tempatt;
  282. XMC_BANK2->bk2tmgmem = tempmem;
  283. }
  284. }
  285. /**
  286. * @brief fill each xmc_nand_init_struct member with its default value.
  287. * @param xmc_nand_init_struct: pointer to a xmc_nand_init_type
  288. * structure which will be initialized.
  289. * @retval none
  290. */
  291. void xmc_nand_default_para_init(xmc_nand_init_type* xmc_nand_init_struct)
  292. {
  293. /* reset nand init structure parameters values */
  294. xmc_nand_init_struct->nand_bank = XMC_BANK2_NAND;
  295. xmc_nand_init_struct->wait_enable = XMC_WAIT_OPERATION_DISABLE;
  296. xmc_nand_init_struct->bus_type = XMC_BUSTYPE_8_BITS;
  297. xmc_nand_init_struct->ecc_enable = XMC_ECC_OPERATION_DISABLE;
  298. xmc_nand_init_struct->ecc_pagesize = XMC_ECC_PAGESIZE_256_BYTES;
  299. xmc_nand_init_struct->delay_time_cycle = 0x0;
  300. xmc_nand_init_struct->delay_time_ar = 0x0;
  301. }
  302. /**
  303. * @brief fill each xmc_common_spacetiming_struct and xmc_attribute_spacetiming_struct member with its default value.
  304. * @param xmc_common_spacetiming_struct: pointer to a xmc_nand_timinginit_type
  305. * structure which will be initialized.
  306. * @param xmc_special_spacetiming_struct: pointer to a xmc_nand_timinginit_type
  307. * structure which will be initialized.
  308. * @retval none
  309. */
  310. void xmc_nand_timing_default_para_init(xmc_nand_timinginit_type* xmc_regular_spacetiming_struct,
  311. xmc_nand_timinginit_type* xmc_special_spacetiming_struct)
  312. {
  313. xmc_regular_spacetiming_struct->class_bank = XMC_BANK2_NAND;
  314. xmc_regular_spacetiming_struct->mem_hold_time = 0xFC;
  315. xmc_regular_spacetiming_struct->mem_waite_time = 0xFC;
  316. xmc_regular_spacetiming_struct->mem_setup_time = 0xFC;
  317. xmc_regular_spacetiming_struct->mem_hiz_time = 0xFC;
  318. xmc_special_spacetiming_struct->class_bank = XMC_BANK2_NAND;
  319. xmc_special_spacetiming_struct->mem_hold_time = 0xFC;
  320. xmc_special_spacetiming_struct->mem_waite_time = 0xFC;
  321. xmc_special_spacetiming_struct->mem_setup_time = 0xFC;
  322. xmc_special_spacetiming_struct->mem_hiz_time = 0xFC;
  323. }
  324. /**
  325. * @brief enable or disable the specified nand memory bank.
  326. * @param xmc_bank: specifies the xmc bank to be used
  327. * this parameter can be one of the following values:
  328. * - XMC_BANK2_NAND
  329. * @param new_state (TRUE or FALSE)
  330. * @retval none
  331. */
  332. void xmc_nand_enable(xmc_class_bank_type xmc_bank, confirm_state new_state)
  333. {
  334. /* enable or disable the nand bank2 by setting the en bit in the bk2ctrl register */
  335. if(xmc_bank == XMC_BANK2_NAND)
  336. {
  337. XMC_BANK2->bk2ctrl_bit.en = new_state;
  338. }
  339. }
  340. /**
  341. * @brief enable or disable the xmc nand ecc feature.
  342. * @param xmc_bank: specifies the xmc bank to be used
  343. * this parameter can be one of the following values:
  344. * - XMC_BANK2_NAND
  345. * @param new_state (TRUE or FALSE)
  346. * @retval none
  347. */
  348. void xmc_nand_ecc_enable(xmc_class_bank_type xmc_bank, confirm_state new_state)
  349. {
  350. /* enable the selected nand bank2 ecc function by setting the eccen bit in the bk2ctrl register */
  351. if(xmc_bank == XMC_BANK2_NAND)
  352. {
  353. XMC_BANK2->bk2ctrl_bit.eccen = new_state;
  354. }
  355. }
  356. /**
  357. * @brief return the error correction code register value.
  358. * @param xmc_bank: specifies the xmc bank to be used
  359. * this parameter can be one of the following values:
  360. * - XMC_BANK2_NAND
  361. * @retval the error correction code (ecc) value.
  362. */
  363. uint32_t xmc_ecc_get(xmc_class_bank_type xmc_bank)
  364. {
  365. uint32_t eccvaule = 0x0;
  366. /* get the bk2ecc register value */
  367. if(xmc_bank == XMC_BANK2_NAND)
  368. {
  369. eccvaule = XMC_BANK2->bk2ecc;
  370. }
  371. /* return the error correction code value */
  372. return eccvaule;
  373. }
  374. /**
  375. * @brief enable or disable the specified xmc interrupts.
  376. * @param xmc_bank: specifies the xmc bank to be used
  377. * this parameter can be one of the following values:
  378. * - XMC_BANK2_NAND
  379. * @param xmc_int: specifies the xmc interrupt sources to be enabled or disabled.
  380. * this parameter can be any combination of the following values:
  381. * - XMC_INT_RISING_EDGE
  382. * - XMC_INT_LEVEL
  383. * - XMC_INT_FALLING_EDGE
  384. * @param new_state (TRUE or FALSE)
  385. * @retval none
  386. */
  387. void xmc_interrupt_enable(xmc_class_bank_type xmc_bank, xmc_interrupt_sources_type xmc_int, confirm_state new_state)
  388. {
  389. if(new_state != FALSE)
  390. {
  391. /* enable the selected xmc_bank2 interrupts */
  392. if(xmc_bank == XMC_BANK2_NAND)
  393. {
  394. XMC_BANK2->bk2is |= xmc_int;
  395. }
  396. }
  397. else
  398. {
  399. /* disable the selected xmc_bank2 interrupts */
  400. if(xmc_bank == XMC_BANK2_NAND)
  401. {
  402. XMC_BANK2->bk2is &= ~xmc_int;
  403. }
  404. }
  405. }
  406. /**
  407. * @brief check whether the specified xmc flag is set or not.
  408. * @param xmc_bank: specifies the xmc bank to be used
  409. * this parameter can be one of the following values:
  410. * - XMC_BANK2_NAND
  411. * @param xmc_flag: specifies the flag to check.
  412. * this parameter can be any combination of the following values:
  413. * - XMC_RISINGEDGE_FLAG
  414. * - XMC_LEVEL_FLAG
  415. * - XMC_FALLINGEDGE_FLAG
  416. * - XMC_FEMPT_FLAG
  417. * @retval none
  418. */
  419. flag_status xmc_flag_status_get(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_flag)
  420. {
  421. flag_status status = RESET;
  422. uint32_t temp = 0;
  423. if(xmc_bank == XMC_BANK2_NAND)
  424. {
  425. temp = XMC_BANK2->bk2is;
  426. }
  427. /* get the flag status */
  428. if((temp & xmc_flag) == RESET)
  429. {
  430. status = RESET;
  431. }
  432. else
  433. {
  434. status = SET;
  435. }
  436. /* return the flag status */
  437. return status;
  438. }
  439. /**
  440. * @brief check whether the specified xmc interrupt flag is set or not.
  441. * @param xmc_bank: specifies the xmc bank to be used
  442. * this parameter can be one of the following values:
  443. * - XMC_BANK2_NAND
  444. * @param xmc_flag: specifies the flag to check.
  445. * this parameter can be any combination of the following values:
  446. * - XMC_RISINGEDGE_FLAG
  447. * - XMC_LEVEL_FLAG
  448. * - XMC_FALLINGEDGE_FLAG
  449. * @retval none
  450. */
  451. flag_status xmc_interrupt_flag_status_get(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_flag)
  452. {
  453. flag_status status = RESET;
  454. switch(xmc_flag)
  455. {
  456. case XMC_RISINGEDGE_FLAG:
  457. if(XMC_BANK2->bk2is_bit.reien & XMC_BANK2->bk2is_bit.res)
  458. status = SET;
  459. break;
  460. case XMC_LEVEL_FLAG:
  461. if(XMC_BANK2->bk2is_bit.feien & XMC_BANK2->bk2is_bit.fes)
  462. status = SET;
  463. break;
  464. case XMC_FALLINGEDGE_FLAG:
  465. if(XMC_BANK2->bk2is_bit.hlien & XMC_BANK2->bk2is_bit.hls)
  466. status = SET;
  467. break;
  468. default:
  469. break;
  470. }
  471. /* return the flag status */
  472. return status;
  473. }
  474. /**
  475. * @brief clear the xmc's pending flags.
  476. * @param xmc_bank: specifies the xmc bank to be used
  477. * this parameter can be one of the following values:
  478. * - XMC_BANK2_NAND
  479. * @param xmc_flag: specifies the flag to check.
  480. * this parameter can be any combination of the following values:
  481. * - XMC_RISINGEDGE_FLAG
  482. * - XMC_LEVEL_FLAG
  483. * - XMC_FALLINGEDGE_FLAG
  484. * - XMC_FEMPT_FLAG
  485. * @retval none
  486. */
  487. void xmc_flag_clear(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_flag)
  488. {
  489. __IO uint32_t int_state;
  490. if(xmc_bank == XMC_BANK2_NAND)
  491. {
  492. int_state = XMC_BANK2->bk2is & 0x38; /* keep interrupt state */
  493. XMC_BANK2->bk2is = (~(xmc_flag | 0x38) | int_state);
  494. }
  495. }
  496. /**
  497. * @}
  498. */
  499. #endif
  500. /**
  501. * @}
  502. */
  503. /**
  504. * @}
  505. */