drv_usart.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044
  1. /*
  2. * Copyright (C) 2022-2024, Xiaohua Semiconductor Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-04-28 CDT first version
  9. * 2023-10-09 CDT support HC32F448
  10. * 2024-04-15 CDT support HC32F472
  11. * 2025-07-16 CDT Support HC32F334
  12. */
  13. /*******************************************************************************
  14. * Include files
  15. ******************************************************************************/
  16. #include <rtdevice.h>
  17. #include <rthw.h>
  18. #ifdef RT_USING_SERIAL
  19. #if defined (BSP_USING_UART1) || defined (BSP_USING_UART2) || defined (BSP_USING_UART3) || \
  20. defined (BSP_USING_UART4) || defined (BSP_USING_UART5) || defined (BSP_USING_UART6) || \
  21. defined (BSP_USING_UART7) || defined (BSP_USING_UART8) || defined (BSP_USING_UART9) || \
  22. defined (BSP_USING_UART10)
  23. #include "drv_usart.h"
  24. #include "board_config.h"
  25. /*******************************************************************************
  26. * Local type definitions ('typedef')
  27. ******************************************************************************/
  28. /*******************************************************************************
  29. * Local pre-processor symbols/macros ('#define')
  30. ******************************************************************************/
  31. #define DMA_CH_REG(reg_base, ch) \
  32. (*(volatile uint32_t *)((uint32_t)(&(reg_base)) + ((ch) * 0x40UL)))
  33. #define DMA_TRANS_SET_CNT(unit, ch) \
  34. (READ_REG32(DMA_CH_REG((unit)->DTCTL0,(ch))) >> DMA_DTCTL_CNT_POS)
  35. #define DMA_TRANS_CNT(unit, ch) \
  36. (READ_REG32(DMA_CH_REG((unit)->MONDTCTL0, (ch))) >> DMA_DTCTL_CNT_POS)
  37. #define UART_BAUDRATE_ERR_MAX (0.025F)
  38. #if defined (HC32F460)
  39. #define FCG_USART_CLK FCG_Fcg1PeriphClockCmd
  40. #elif defined (HC32F4A0) || defined (HC32F448) || defined (HC32F472) || defined (HC32F4A8) || defined (HC32F334)
  41. #define FCG_USART_CLK FCG_Fcg3PeriphClockCmd
  42. #endif
  43. #define FCG_TMR0_CLK FCG_Fcg2PeriphClockCmd
  44. #define FCG_DMA_CLK FCG_Fcg0PeriphClockCmd
  45. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F472)
  46. #define USART_MAX_CLK_DIV USART_CLK_DIV64
  47. #elif defined (HC32F448) || defined (HC32F4A8) || defined (HC32F334)
  48. #define USART_MAX_CLK_DIV USART_CLK_DIV1024
  49. #endif
  50. /*******************************************************************************
  51. * Global variable definitions (declared in header file with 'extern')
  52. ******************************************************************************/
  53. extern rt_err_t rt_hw_board_uart_init(CM_USART_TypeDef *USARTx);
  54. /*******************************************************************************
  55. * Local function prototypes ('static')
  56. ******************************************************************************/
  57. #ifdef RT_SERIAL_USING_DMA
  58. static void hc32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag);
  59. #endif
  60. /*******************************************************************************
  61. * Local variable definitions ('static')
  62. ******************************************************************************/
  63. enum
  64. {
  65. #ifdef BSP_USING_UART1
  66. UART1_INDEX,
  67. #endif
  68. #ifdef BSP_USING_UART2
  69. UART2_INDEX,
  70. #endif
  71. #ifdef BSP_USING_UART3
  72. UART3_INDEX,
  73. #endif
  74. #ifdef BSP_USING_UART4
  75. UART4_INDEX,
  76. #endif
  77. #ifdef BSP_USING_UART5
  78. UART5_INDEX,
  79. #endif
  80. #ifdef BSP_USING_UART6
  81. UART6_INDEX,
  82. #endif
  83. #ifdef BSP_USING_UART7
  84. UART7_INDEX,
  85. #endif
  86. #ifdef BSP_USING_UART8
  87. UART8_INDEX,
  88. #endif
  89. #ifdef BSP_USING_UART9
  90. UART9_INDEX,
  91. #endif
  92. #ifdef BSP_USING_UART10
  93. UART10_INDEX,
  94. #endif
  95. };
  96. static struct hc32_uart_config uart_config[] =
  97. {
  98. #ifdef BSP_USING_UART1
  99. UART1_CONFIG,
  100. #endif
  101. #ifdef BSP_USING_UART2
  102. UART2_CONFIG,
  103. #endif
  104. #ifdef BSP_USING_UART3
  105. UART3_CONFIG,
  106. #endif
  107. #ifdef BSP_USING_UART4
  108. UART4_CONFIG,
  109. #endif
  110. #ifdef BSP_USING_UART5
  111. UART5_CONFIG,
  112. #endif
  113. #ifdef BSP_USING_UART6
  114. UART6_CONFIG,
  115. #endif
  116. #ifdef BSP_USING_UART7
  117. UART7_CONFIG,
  118. #endif
  119. #ifdef BSP_USING_UART8
  120. UART8_CONFIG,
  121. #endif
  122. #ifdef BSP_USING_UART9
  123. UART9_CONFIG,
  124. #endif
  125. #ifdef BSP_USING_UART10
  126. UART10_CONFIG,
  127. #endif
  128. };
  129. static struct hc32_uart uart_obj[sizeof(uart_config) / sizeof(uart_config[0])] = {0};
  130. /*******************************************************************************
  131. * Function implementation - global ('extern') and local ('static')
  132. ******************************************************************************/
  133. static rt_err_t hc32_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
  134. {
  135. struct hc32_uart *uart;
  136. stc_usart_uart_init_t uart_init;
  137. RT_ASSERT(RT_NULL != cfg);
  138. RT_ASSERT(RT_NULL != serial);
  139. uart = rt_container_of(serial, struct hc32_uart, serial);
  140. USART_UART_StructInit(&uart_init);
  141. uart_init.u32OverSampleBit = USART_OVER_SAMPLE_8BIT;
  142. uart_init.u32Baudrate = cfg->baud_rate;
  143. uart_init.u32ClockSrc = USART_CLK_SRC_INTERNCLK;
  144. #if defined (HC32F4A0)
  145. if ((CM_USART1 == uart->config->Instance) || (CM_USART2 == uart->config->Instance) || \
  146. (CM_USART6 == uart->config->Instance) || (CM_USART7 == uart->config->Instance))
  147. #elif defined (HC32F460) || defined (HC32F334)
  148. if ((CM_USART1 == uart->config->Instance) || (CM_USART2 == uart->config->Instance) || \
  149. (CM_USART3 == uart->config->Instance) || (CM_USART4 == uart->config->Instance))
  150. #elif defined (HC32F448) || defined (HC32F472)
  151. if ((CM_USART1 == uart->config->Instance) || (CM_USART2 == uart->config->Instance) || \
  152. (CM_USART4 == uart->config->Instance) || (CM_USART5 == uart->config->Instance))
  153. #endif
  154. {
  155. uart_init.u32CKOutput = USART_CK_OUTPUT_ENABLE;
  156. }
  157. switch (cfg->data_bits)
  158. {
  159. case DATA_BITS_8:
  160. uart_init.u32DataWidth = USART_DATA_WIDTH_8BIT;
  161. break;
  162. case DATA_BITS_9:
  163. uart_init.u32DataWidth = USART_DATA_WIDTH_9BIT;
  164. break;
  165. default:
  166. uart_init.u32DataWidth = USART_DATA_WIDTH_8BIT;
  167. break;
  168. }
  169. switch (cfg->stop_bits)
  170. {
  171. case STOP_BITS_1:
  172. uart_init.u32StopBit = USART_STOPBIT_1BIT;
  173. break;
  174. case STOP_BITS_2:
  175. uart_init.u32StopBit = USART_STOPBIT_2BIT;
  176. break;
  177. default:
  178. uart_init.u32StopBit = USART_STOPBIT_1BIT;
  179. break;
  180. }
  181. switch (cfg->parity)
  182. {
  183. case PARITY_NONE:
  184. uart_init.u32Parity = USART_PARITY_NONE;
  185. break;
  186. case PARITY_EVEN:
  187. uart_init.u32Parity = USART_PARITY_EVEN;
  188. break;
  189. case PARITY_ODD:
  190. uart_init.u32Parity = USART_PARITY_ODD;
  191. break;
  192. default:
  193. uart_init.u32Parity = USART_PARITY_NONE;
  194. break;
  195. }
  196. if (BIT_ORDER_LSB == cfg->bit_order)
  197. {
  198. uart_init.u32FirstBit = USART_FIRST_BIT_LSB;
  199. }
  200. else
  201. {
  202. uart_init.u32FirstBit = USART_FIRST_BIT_MSB;
  203. }
  204. #if defined (HC32F4A0) || defined (HC32F448) || defined (HC32F472) || defined (HC32F4A8) || defined (HC32F334)
  205. switch (cfg->flowcontrol)
  206. {
  207. case RT_SERIAL_FLOWCONTROL_NONE:
  208. uart_init.u32HWFlowControl = USART_HW_FLOWCTRL_NONE;
  209. break;
  210. case RT_SERIAL_FLOWCONTROL_CTSRTS:
  211. uart_init.u32HWFlowControl = USART_HW_FLOWCTRL_RTS_CTS;
  212. break;
  213. default:
  214. uart_init.u32HWFlowControl = USART_HW_FLOWCTRL_NONE;
  215. break;
  216. }
  217. #endif
  218. #ifdef RT_SERIAL_USING_DMA
  219. if (!(serial->parent.open_flag & RT_DEVICE_OFLAG_OPEN))
  220. {
  221. uart->dma_rx_remaining_cnt = (serial->config.bufsz <= 1UL) ? serial->config.bufsz : serial->config.bufsz / 2;
  222. }
  223. #endif
  224. /* Enable USART clock */
  225. FCG_USART_CLK(uart->config->clock, ENABLE);
  226. if (RT_EOK != rt_hw_board_uart_init(uart->config->Instance))
  227. {
  228. return -RT_ERROR;
  229. }
  230. /* Configure UART */
  231. uint32_t u32Div;
  232. float32_t f32Error;
  233. int32_t i32Ret = LL_ERR;
  234. USART_DeInit(uart->config->Instance);
  235. USART_UART_Init(uart->config->Instance, &uart_init, NULL);
  236. for (u32Div = 0UL; u32Div <= USART_MAX_CLK_DIV; u32Div++)
  237. {
  238. #if defined (HC32F448) || defined (HC32F4A8) || defined (HC32F334)
  239. if (u32Div == (USART_CLK_DIV64 + 1U))
  240. {
  241. u32Div = USART_CLK_DIV128;
  242. }
  243. #endif
  244. USART_SetClockDiv(uart->config->Instance, u32Div);
  245. if ((LL_OK == USART_SetBaudrate(uart->config->Instance, uart_init.u32Baudrate, &f32Error)) &&
  246. ((-UART_BAUDRATE_ERR_MAX <= f32Error) && (f32Error <= UART_BAUDRATE_ERR_MAX)))
  247. {
  248. i32Ret = LL_OK;
  249. break;
  250. }
  251. }
  252. if (i32Ret != LL_OK)
  253. {
  254. return -RT_ERROR;
  255. }
  256. /* Enable error interrupt */
  257. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  258. NVIC_EnableIRQ(uart->config->rxerr_irq.irq_config.irq_num);
  259. #elif defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  260. INTC_IntSrcCmd(uart->config->tx_int_src, ENABLE);
  261. INTC_IntSrcCmd(uart->config->rx_int_src, DISABLE);
  262. INTC_IntSrcCmd(uart->config->rxerr_int_src, ENABLE);
  263. NVIC_EnableIRQ(uart->config->irq_num);
  264. #endif
  265. USART_FuncCmd(uart->config->Instance, USART_TX | USART_RX | USART_INT_RX, ENABLE);
  266. return RT_EOK;
  267. }
  268. static rt_err_t hc32_control(struct rt_serial_device *serial, int cmd, void *arg)
  269. {
  270. struct hc32_uart *uart;
  271. rt_ubase_t ctrl_arg = (rt_ubase_t)arg;
  272. RT_ASSERT(RT_NULL != serial);
  273. uart = rt_container_of(serial, struct hc32_uart, serial);
  274. RT_ASSERT(RT_NULL != uart->config->Instance);
  275. switch (cmd)
  276. {
  277. /* Disable interrupt */
  278. case RT_DEVICE_CTRL_CLR_INT:
  279. if (RT_DEVICE_FLAG_INT_RX == ctrl_arg)
  280. {
  281. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  282. NVIC_DisableIRQ(uart->config->rx_irq.irq_config.irq_num);
  283. INTC_IrqSignOut(uart->config->rx_irq.irq_config.irq_num);
  284. #elif defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  285. INTC_IntSrcCmd(uart->config->rx_int_src, DISABLE);
  286. #endif
  287. }
  288. else if (RT_DEVICE_FLAG_INT_TX == ctrl_arg)
  289. {
  290. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  291. NVIC_DisableIRQ(uart->config->tx_irq.irq_config.irq_num);
  292. USART_FuncCmd(uart->config->Instance, USART_INT_TX_EMPTY, DISABLE);
  293. INTC_IrqSignOut(uart->config->tx_irq.irq_config.irq_num);
  294. #elif defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  295. USART_FuncCmd(uart->config->Instance, USART_INT_TX_EMPTY, DISABLE);
  296. #endif
  297. }
  298. #ifdef RT_SERIAL_USING_DMA
  299. else if (RT_DEVICE_FLAG_DMA_RX == ctrl_arg)
  300. {
  301. NVIC_DisableIRQ(uart->config->dma_rx->irq_config.irq_num);
  302. }
  303. else if (RT_DEVICE_FLAG_DMA_TX == ctrl_arg)
  304. {
  305. USART_FuncCmd(uart->config->Instance, USART_INT_TX_CPLT, DISABLE);
  306. NVIC_DisableIRQ(uart->config->dma_tx->irq_config.irq_num);
  307. }
  308. #endif
  309. break;
  310. /* Enable interrupt */
  311. case RT_DEVICE_CTRL_SET_INT:
  312. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  313. if (RT_DEVICE_FLAG_INT_RX == ctrl_arg)
  314. {
  315. hc32_install_irq_handler(&uart->config->rx_irq.irq_config, uart->config->rx_irq.irq_callback, RT_TRUE);
  316. USART_FuncCmd(uart->config->Instance, USART_INT_RX, ENABLE);
  317. }
  318. else if (RT_DEVICE_FLAG_INT_TX == ctrl_arg)
  319. {
  320. INTC_IrqSignOut(uart->config->tx_irq.irq_config.irq_num);
  321. hc32_install_irq_handler(&uart->config->tx_irq.irq_config, uart->config->tx_irq.irq_callback, RT_TRUE);
  322. USART_FuncCmd(uart->config->Instance, USART_TX, DISABLE);
  323. USART_FuncCmd(uart->config->Instance, USART_TX | USART_INT_TX_EMPTY, ENABLE);
  324. }
  325. #elif defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  326. /* NVIC config */
  327. if (RT_DEVICE_FLAG_INT_RX == ctrl_arg)
  328. {
  329. /* intsrc enable */
  330. INTC_IntSrcCmd(uart->config->rx_int_src, ENABLE);
  331. USART_FuncCmd(uart->config->Instance, USART_INT_RX, ENABLE);
  332. }
  333. else if (RT_DEVICE_FLAG_INT_TX == ctrl_arg)
  334. {
  335. USART_FuncCmd(uart->config->Instance, USART_TX | USART_INT_TX_EMPTY, ENABLE);
  336. }
  337. #endif
  338. break;
  339. #ifdef RT_SERIAL_USING_DMA
  340. case RT_DEVICE_CTRL_CONFIG:
  341. hc32_dma_config(serial, ctrl_arg);
  342. break;
  343. #endif
  344. case RT_DEVICE_CTRL_CLOSE:
  345. USART_DeInit(uart->config->Instance);
  346. break;
  347. }
  348. return RT_EOK;
  349. }
  350. static int hc32_putc(struct rt_serial_device *serial, char c)
  351. {
  352. struct hc32_uart *uart;
  353. RT_ASSERT(RT_NULL != serial);
  354. uart = rt_container_of(serial, struct hc32_uart, serial);
  355. RT_ASSERT(RT_NULL != uart->config->Instance);
  356. if (serial->parent.open_flag & RT_DEVICE_FLAG_INT_TX)
  357. {
  358. if (USART_GetStatus(uart->config->Instance, USART_FLAG_TX_EMPTY) != SET)
  359. {
  360. return -1;
  361. }
  362. }
  363. else
  364. {
  365. /* Polling mode. */
  366. while (USART_GetStatus(uart->config->Instance, USART_FLAG_TX_EMPTY) != SET);
  367. }
  368. USART_WriteData(uart->config->Instance, c);
  369. return 1;
  370. }
  371. static int hc32_getc(struct rt_serial_device *serial)
  372. {
  373. int ch = -1;
  374. struct hc32_uart *uart;
  375. RT_ASSERT(RT_NULL != serial);
  376. uart = rt_container_of(serial, struct hc32_uart, serial);
  377. RT_ASSERT(RT_NULL != uart->config->Instance);
  378. if (SET == USART_GetStatus(uart->config->Instance, USART_FLAG_RX_FULL))
  379. {
  380. ch = (rt_uint8_t)USART_ReadData(uart->config->Instance);
  381. }
  382. return ch;
  383. }
  384. static rt_ssize_t hc32_dma_transmit(struct rt_serial_device *serial,
  385. rt_uint8_t *buf,
  386. rt_size_t size,
  387. int direction)
  388. {
  389. #ifdef RT_SERIAL_USING_DMA
  390. struct hc32_uart *uart;
  391. struct dma_config *uart_dma;
  392. RT_ASSERT(RT_NULL != serial);
  393. RT_ASSERT(RT_NULL != buf);
  394. if (0 == size)
  395. {
  396. return 0;
  397. }
  398. uart = rt_container_of(serial, struct hc32_uart, serial);
  399. if (RT_SERIAL_DMA_TX == direction)
  400. {
  401. uart_dma = uart->config->dma_tx;
  402. if (RESET == USART_GetStatus(uart->config->Instance, USART_FLAG_TX_CPLT))
  403. {
  404. RT_ASSERT(0);
  405. }
  406. DMA_SetSrcAddr(uart_dma->Instance, uart_dma->channel, (uint32_t)buf);
  407. DMA_SetTransCount(uart_dma->Instance, uart_dma->channel, size);
  408. DMA_ChCmd(uart_dma->Instance, uart_dma->channel, ENABLE);
  409. USART_FuncCmd(uart->config->Instance, USART_TX, ENABLE);
  410. USART_FuncCmd(uart->config->Instance, USART_INT_TX_CPLT, ENABLE);
  411. return size;
  412. }
  413. #endif
  414. return 0;
  415. }
  416. static void hc32_uart_rx_irq_handler(struct hc32_uart *uart)
  417. {
  418. RT_ASSERT(RT_NULL != uart);
  419. rt_hw_serial_isr(&uart->serial, RT_SERIAL_EVENT_RX_IND);
  420. }
  421. static void hc32_uart_tx_irq_handler(struct hc32_uart *uart)
  422. {
  423. RT_ASSERT(RT_NULL != uart);
  424. if (uart->serial.parent.open_flag & RT_DEVICE_FLAG_INT_TX)
  425. {
  426. rt_hw_serial_isr(&uart->serial, RT_SERIAL_EVENT_TX_DONE);
  427. }
  428. }
  429. static void hc32_uart_rxerr_irq_handler(struct hc32_uart *uart)
  430. {
  431. RT_ASSERT(RT_NULL != uart);
  432. RT_ASSERT(RT_NULL != uart->config->Instance);
  433. if (SET == USART_GetStatus(uart->config->Instance, (USART_FLAG_OVERRUN | USART_FLAG_PARITY_ERR | USART_FLAG_FRAME_ERR)))
  434. {
  435. USART_ReadData(uart->config->Instance);
  436. }
  437. USART_ClearStatus(uart->config->Instance, (USART_FLAG_PARITY_ERR | USART_FLAG_FRAME_ERR | USART_FLAG_OVERRUN));
  438. }
  439. #ifdef RT_SERIAL_USING_DMA
  440. static void hc32_uart_rx_timeout(struct rt_serial_device *serial)
  441. {
  442. struct hc32_uart *uart;
  443. CM_TMR0_TypeDef *TMR0_Instance;
  444. uint8_t ch;
  445. uint32_t rtb;
  446. uint32_t alpha;
  447. uint32_t ckdiv;
  448. uint32_t cmp_val;
  449. stc_tmr0_init_t stcTmr0Init;
  450. RT_ASSERT(RT_NULL != serial);
  451. uart = rt_container_of(serial, struct hc32_uart, serial);
  452. RT_ASSERT(RT_NULL != uart->config->Instance);
  453. TMR0_Instance = uart->config->rx_timeout->TMR0_Instance;
  454. ch = uart->config->rx_timeout->channel;
  455. rtb = uart->config->rx_timeout->timeout_bits;
  456. #if defined (HC32F460) || defined (HC32F334)
  457. if ((CM_USART1 == uart->config->Instance) || (CM_USART3 == uart->config->Instance))
  458. {
  459. RT_ASSERT(TMR0_CH_A == ch);
  460. }
  461. else if ((CM_USART2 == uart->config->Instance) || (CM_USART4 == uart->config->Instance))
  462. {
  463. RT_ASSERT(TMR0_CH_B == ch);
  464. }
  465. #elif defined (HC32F4A0)
  466. if ((CM_USART1 == uart->config->Instance) || (CM_USART6 == uart->config->Instance))
  467. {
  468. RT_ASSERT(TMR0_CH_A == ch);
  469. }
  470. else if ((CM_USART2 == uart->config->Instance) || (CM_USART7 == uart->config->Instance))
  471. {
  472. RT_ASSERT(TMR0_CH_B == ch);
  473. }
  474. #elif defined (HC32F448) || defined (HC32F472)
  475. if ((CM_USART1 == uart->config->Instance) || (CM_USART4 == uart->config->Instance))
  476. {
  477. RT_ASSERT(TMR0_CH_A == ch);
  478. }
  479. else if ((CM_USART2 == uart->config->Instance) || (CM_USART5 == uart->config->Instance))
  480. {
  481. RT_ASSERT(TMR0_CH_B == ch);
  482. }
  483. #elif defined (HC32F4A8)
  484. if ((CM_USART1 == uart->config->Instance) || (CM_USART3 == uart->config->Instance) || (CM_USART5 == uart->config->Instance) ||
  485. (CM_USART6 == uart->config->Instance) || (CM_USART9 == uart->config->Instance))
  486. {
  487. RT_ASSERT(TMR0_CH_A == ch);
  488. }
  489. else if ((CM_USART2 == uart->config->Instance) || (CM_USART4 == uart->config->Instance) || (CM_USART7 == uart->config->Instance) ||
  490. (CM_USART8 == uart->config->Instance) || (CM_USART10 == uart->config->Instance))
  491. {
  492. RT_ASSERT(TMR0_CH_B == ch);
  493. }
  494. #endif
  495. #if defined (HC32F4A8)
  496. if ((CM_TMR0_4 == uart->config->rx_timeout->TMR0_Instance) || (CM_TMR0_5 == uart->config->rx_timeout->TMR0_Instance))
  497. {
  498. FCG_Fcg3PeriphClockCmd(uart->config->rx_timeout->clock, ENABLE);
  499. }
  500. else
  501. {
  502. FCG_TMR0_CLK(uart->config->rx_timeout->clock, ENABLE);
  503. }
  504. #elif defined (HC32F460) || defined (HC32F4A0) || defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  505. FCG_TMR0_CLK(uart->config->rx_timeout->clock, ENABLE);
  506. #endif
  507. /* TIMER0 basetimer function initialize */
  508. TMR0_SetCountValue(TMR0_Instance, ch, 0U);
  509. TMR0_StructInit(&stcTmr0Init);
  510. stcTmr0Init.u32ClockDiv = TMR0_CLK_DIV1;
  511. stcTmr0Init.u32ClockSrc = TMR0_CLK_SRC_XTAL32;
  512. if (TMR0_CLK_DIV1 == stcTmr0Init.u32ClockDiv)
  513. {
  514. alpha = 7UL;
  515. }
  516. else if (TMR0_CLK_DIV2 == stcTmr0Init.u32ClockDiv)
  517. {
  518. alpha = 5UL;
  519. }
  520. else if ((TMR0_CLK_DIV4 == stcTmr0Init.u32ClockDiv) || \
  521. (TMR0_CLK_DIV8 == stcTmr0Init.u32ClockDiv) || \
  522. (TMR0_CLK_DIV16 == stcTmr0Init.u32ClockDiv))
  523. {
  524. alpha = 3UL;
  525. }
  526. else
  527. {
  528. alpha = 2UL;
  529. }
  530. /* TMR0_CMPA<B>R calculation formula: CMPA<B>R = (RTB / (2 ^ CKDIVA<B>)) - alpha */
  531. ckdiv = 1UL << (stcTmr0Init.u32ClockDiv >> TMR0_BCONR_CKDIVA_POS);
  532. cmp_val = ((rtb + ckdiv - 1UL) / ckdiv) - alpha;
  533. DDL_ASSERT(cmp_val <= 0xFFFFUL);
  534. stcTmr0Init.u16CompareValue = (uint16_t)(cmp_val);
  535. TMR0_Init(TMR0_Instance, ch, &stcTmr0Init);
  536. TMR0_HWStartCondCmd(TMR0_Instance, ch, ENABLE);
  537. TMR0_HWClearCondCmd(TMR0_Instance, ch, ENABLE);
  538. /* Clear compare flag */
  539. TMR0_ClearStatus(TMR0_Instance, (uint32_t)(0x1UL << (ch * TMR0_STFLR_CMFB_POS)));
  540. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  541. NVIC_EnableIRQ(uart->config->rx_timeout->irq_config.irq_num);
  542. #endif
  543. USART_ClearStatus(uart->config->Instance, USART_FLAG_RX_TIMEOUT);
  544. USART_FuncCmd(uart->config->Instance, (USART_RX_TIMEOUT | USART_INT_RX_TIMEOUT), ENABLE);
  545. }
  546. static void hc32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag)
  547. {
  548. rt_uint32_t trans_count = (serial->config.bufsz <= 1UL) ? serial->config.bufsz : serial->config.bufsz / 2UL;
  549. struct hc32_uart *uart;
  550. stc_dma_init_t dma_init;
  551. struct dma_config *uart_dma;
  552. RT_ASSERT(RT_NULL != serial);
  553. RT_ASSERT(RT_NULL == ((serial->config.bufsz) & ((RT_ALIGN_SIZE) - 1)));
  554. uart = rt_container_of(serial, struct hc32_uart, serial);
  555. RT_ASSERT(RT_NULL != uart->config->Instance);
  556. if (RT_DEVICE_FLAG_DMA_RX == flag)
  557. {
  558. stc_dma_llp_init_t llp_init;
  559. struct rt_serial_rx_fifo *rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
  560. RT_ASSERT(RT_NULL != uart->config->rx_timeout->TMR0_Instance);
  561. RT_ASSERT(RT_NULL != uart->config->dma_rx->Instance);
  562. RT_ASSERT(RT_NULL != rx_fifo);
  563. #if defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  564. INTC_IntSrcCmd(uart->config->rx_int_src, DISABLE);
  565. #endif
  566. uart_dma = uart->config->dma_rx;
  567. /* Initialization uart rx timeout for DMA */
  568. hc32_uart_rx_timeout(serial);
  569. /* Enable DMA clock */
  570. FCG_DMA_CLK(uart_dma->clock, ENABLE);
  571. DMA_ChCmd(uart_dma->Instance, uart_dma->channel, DISABLE);
  572. /* Initialize DMA */
  573. DMA_StructInit(&dma_init);
  574. dma_init.u32IntEn = DMA_INT_ENABLE;
  575. dma_init.u32SrcAddr = (uint32_t)(&uart->config->Instance->RDR);
  576. dma_init.u32DestAddr = (uint32_t)rx_fifo->buffer;
  577. dma_init.u32DataWidth = DMA_DATAWIDTH_8BIT;
  578. dma_init.u32BlockSize = 1UL;
  579. dma_init.u32TransCount = trans_count;
  580. dma_init.u32SrcAddrInc = DMA_SRC_ADDR_FIX;
  581. dma_init.u32DestAddrInc = DMA_DEST_ADDR_INC;
  582. DMA_Init(uart_dma->Instance, uart_dma->channel, &dma_init);
  583. /* Initialize LLP */
  584. llp_init.u32State = DMA_LLP_ENABLE;
  585. llp_init.u32Mode = DMA_LLP_WAIT;
  586. llp_init.u32Addr = (uint32_t)&uart->config->llp_desc;
  587. DMA_LlpInit(uart_dma->Instance, uart_dma->channel, &llp_init);
  588. /* Configure LLP descriptor */
  589. uart->config->llp_desc[0U].SARx = dma_init.u32SrcAddr;
  590. uart->config->llp_desc[0U].DARx = dma_init.u32DestAddr + ((serial->config.bufsz <= 1U) ? 0U : dma_init.u32TransCount);
  591. uart->config->llp_desc[0U].DTCTLx = (((serial->config.bufsz <= 1U) ? dma_init.u32TransCount : (serial->config.bufsz - dma_init.u32TransCount)) << DMA_DTCTL_CNT_POS) | \
  592. (dma_init.u32BlockSize << DMA_DTCTL_BLKSIZE_POS);
  593. uart->config->llp_desc[0U].LLPx = (serial->config.bufsz <= 1U) ? (uint32_t)&uart->config->llp_desc[0U] : (uint32_t)&uart->config->llp_desc[1U];
  594. uart->config->llp_desc[0U].CHCTLx = (dma_init.u32SrcAddrInc | dma_init.u32DestAddrInc | dma_init.u32DataWidth | \
  595. llp_init.u32State | llp_init.u32Mode | dma_init.u32IntEn);
  596. if (serial->config.bufsz > 1UL)
  597. {
  598. uart->config->llp_desc[1U].SARx = dma_init.u32SrcAddr;
  599. uart->config->llp_desc[1U].DARx = dma_init.u32DestAddr;
  600. uart->config->llp_desc[1U].DTCTLx = (dma_init.u32TransCount << DMA_DTCTL_CNT_POS) | (dma_init.u32BlockSize << DMA_DTCTL_BLKSIZE_POS);
  601. uart->config->llp_desc[1U].LLPx = (uint32_t)&uart->config->llp_desc[0U];
  602. uart->config->llp_desc[1U].CHCTLx = (dma_init.u32SrcAddrInc | dma_init.u32DestAddrInc | dma_init.u32DataWidth | \
  603. llp_init.u32State | llp_init.u32Mode | dma_init.u32IntEn);
  604. }
  605. /* Enable DMA interrupt */
  606. NVIC_EnableIRQ(uart->config->dma_rx->irq_config.irq_num);
  607. /* Enable DMA module */
  608. DMA_Cmd(uart_dma->Instance, ENABLE);
  609. AOS_SetTriggerEventSrc(uart_dma->trigger_select, uart_dma->trigger_event);
  610. DMA_ChCmd(uart_dma->Instance, uart_dma->channel, ENABLE);
  611. }
  612. else if (RT_DEVICE_FLAG_DMA_TX == flag)
  613. {
  614. RT_ASSERT(RT_NULL != uart->config->dma_tx->Instance);
  615. uart_dma = uart->config->dma_tx;
  616. /* Enable DMA clock */
  617. FCG_DMA_CLK(uart_dma->clock, ENABLE);
  618. DMA_ChCmd(uart_dma->Instance, uart_dma->channel, DISABLE);
  619. /* Initialize DMA */
  620. DMA_StructInit(&dma_init);
  621. dma_init.u32IntEn = DMA_INT_DISABLE;
  622. dma_init.u32SrcAddr = 0UL;
  623. dma_init.u32DestAddr = (uint32_t)(&uart->config->Instance->TDR);
  624. dma_init.u32DataWidth = DMA_DATAWIDTH_8BIT;
  625. dma_init.u32BlockSize = 1UL;
  626. dma_init.u32TransCount = 0UL;
  627. dma_init.u32SrcAddrInc = DMA_SRC_ADDR_INC;
  628. dma_init.u32DestAddrInc = DMA_DEST_ADDR_FIX;
  629. DMA_Init(uart_dma->Instance, uart_dma->channel, &dma_init);
  630. /* Enable DMA module */
  631. DMA_Cmd(uart_dma->Instance, ENABLE);
  632. AOS_SetTriggerEventSrc(uart_dma->trigger_select, uart_dma->trigger_event);
  633. USART_FuncCmd(uart->config->Instance, (USART_TX | USART_INT_TX_EMPTY | USART_INT_TX_CPLT), DISABLE);
  634. NVIC_EnableIRQ(uart->config->tc_irq->irq_config.irq_num);
  635. }
  636. }
  637. #if defined (BSP_UART1_RX_USING_DMA) || defined (BSP_UART2_RX_USING_DMA) || defined (BSP_UART3_RX_USING_DMA) || \
  638. defined (BSP_UART4_RX_USING_DMA) || defined (BSP_UART5_RX_USING_DMA) || defined (BSP_UART6_RX_USING_DMA) || \
  639. defined (BSP_UART7_RX_USING_DMA) || defined (BSP_UART8_RX_USING_DMA) || defined (BSP_UART9_RX_USING_DMA) || \
  640. defined (BSP_UART10_RX_USING_DMA)
  641. static void hc32_uart_dma_rx_irq_handler(struct hc32_uart *uart)
  642. {
  643. rt_base_t level;
  644. rt_size_t recv_len;
  645. struct rt_serial_device *serial;
  646. RT_ASSERT(RT_NULL != uart);
  647. RT_ASSERT(RT_NULL != uart->config->Instance);
  648. serial = &uart->serial;
  649. RT_ASSERT(RT_NULL != serial);
  650. level = rt_hw_interrupt_disable();
  651. recv_len = uart->dma_rx_remaining_cnt;
  652. uart->dma_rx_remaining_cnt = DMA_TRANS_SET_CNT(uart->config->dma_rx->Instance, uart->config->dma_rx->channel);
  653. if (recv_len)
  654. {
  655. rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_DMADONE | (recv_len << 8));
  656. }
  657. rt_hw_interrupt_enable(level);
  658. }
  659. static void hc32_uart_rxto_irq_handler(struct hc32_uart *uart)
  660. {
  661. rt_base_t level;
  662. rt_size_t dma_set_cnt, cnt;
  663. rt_size_t recv_len;
  664. struct rt_serial_device *serial;
  665. serial = &uart->serial;
  666. RT_ASSERT(serial != RT_NULL);
  667. cnt = DMA_TRANS_CNT(uart->config->dma_rx->Instance, uart->config->dma_rx->channel);
  668. dma_set_cnt = DMA_TRANS_SET_CNT(uart->config->dma_rx->Instance, uart->config->dma_rx->channel);
  669. level = rt_hw_interrupt_disable();
  670. if (cnt <= uart->dma_rx_remaining_cnt)
  671. {
  672. recv_len = uart->dma_rx_remaining_cnt - cnt;
  673. }
  674. else
  675. {
  676. recv_len = uart->dma_rx_remaining_cnt + dma_set_cnt - cnt;
  677. }
  678. if (recv_len)
  679. {
  680. uart->dma_rx_remaining_cnt = cnt;
  681. rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_DMADONE | (recv_len << 8));
  682. }
  683. rt_hw_interrupt_enable(level);
  684. TMR0_Stop(uart->config->rx_timeout->TMR0_Instance, uart->config->rx_timeout->channel);
  685. USART_ClearStatus(uart->config->Instance, USART_FLAG_RX_TIMEOUT);
  686. }
  687. #endif
  688. #if defined (BSP_UART1_TX_USING_DMA) || defined (BSP_UART2_TX_USING_DMA) || defined (BSP_UART3_TX_USING_DMA) || \
  689. defined (BSP_UART4_TX_USING_DMA) || defined (BSP_UART5_TX_USING_DMA) || defined (BSP_UART6_TX_USING_DMA) || \
  690. defined (BSP_UART7_TX_USING_DMA) || defined (BSP_UART8_TX_USING_DMA) || defined (BSP_UART9_TX_USING_DMA) || \
  691. defined (BSP_UART10_TX_USING_DMA)
  692. static void hc32_uart_tc_irq_handler(struct hc32_uart *uart)
  693. {
  694. RT_ASSERT(uart != RT_NULL);
  695. DMA_ClearTransCompleteStatus(uart->config->dma_tx->Instance, (DMA_FLAG_TC_CH0 | DMA_FLAG_BTC_CH0) << uart->config->dma_tx->channel);
  696. USART_FuncCmd(uart->config->Instance, (USART_TX | USART_INT_TX_CPLT), DISABLE);
  697. if (uart->serial.parent.open_flag & RT_DEVICE_FLAG_DMA_TX)
  698. {
  699. rt_hw_serial_isr(&uart->serial, RT_SERIAL_EVENT_TX_DMADONE);
  700. }
  701. }
  702. #endif
  703. #endif
  704. #if defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  705. static void hc32_usart_handler(struct hc32_uart *uart)
  706. {
  707. RT_ASSERT(RT_NULL != uart);
  708. #if defined (RT_SERIAL_USING_DMA)
  709. if ((SET == USART_GetStatus(uart->config->Instance, USART_FLAG_RX_TIMEOUT)) && \
  710. (ENABLE == USART_GetFuncState(uart->config->Instance, USART_RX_TIMEOUT)) && \
  711. (ENABLE == INTC_GetIntSrcState(uart->config->rxto_int_src)))
  712. {
  713. #if defined (BSP_UART1_RX_USING_DMA) || defined (BSP_UART2_RX_USING_DMA) || defined (BSP_UART3_RX_USING_DMA) || \
  714. defined (BSP_UART4_RX_USING_DMA) || defined (BSP_UART5_RX_USING_DMA)
  715. hc32_uart_rxto_irq_handler(uart);
  716. #endif
  717. }
  718. #endif
  719. if ((SET == USART_GetStatus(uart->config->Instance, USART_FLAG_RX_FULL)) && \
  720. (ENABLE == USART_GetFuncState(uart->config->Instance, USART_INT_RX)) && \
  721. (ENABLE == INTC_GetIntSrcState(uart->config->rx_int_src)))
  722. {
  723. hc32_uart_rx_irq_handler(uart);
  724. }
  725. if ((SET == USART_GetStatus(uart->config->Instance, USART_FLAG_TX_EMPTY)) && \
  726. (ENABLE == USART_GetFuncState(uart->config->Instance, USART_INT_TX_EMPTY)) && \
  727. (ENABLE == INTC_GetIntSrcState(uart->config->tx_int_src)))
  728. {
  729. hc32_uart_tx_irq_handler(uart);
  730. }
  731. if ((SET == USART_GetStatus(uart->config->Instance, (USART_FLAG_OVERRUN | \
  732. USART_FLAG_FRAME_ERR | USART_FLAG_PARITY_ERR))) && \
  733. (ENABLE == USART_GetFuncState(uart->config->Instance, USART_INT_RX)) && \
  734. (ENABLE == INTC_GetIntSrcState(uart->config->rxerr_int_src)))
  735. {
  736. hc32_uart_rxerr_irq_handler(uart);
  737. }
  738. }
  739. #endif
  740. #if defined (BSP_USING_UART1)
  741. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  742. static void hc32_uart1_rx_irq_handler(void)
  743. {
  744. /* enter interrupt */
  745. rt_interrupt_enter();
  746. hc32_uart_rx_irq_handler(&uart_obj[UART1_INDEX]);
  747. /* leave interrupt */
  748. rt_interrupt_leave();
  749. }
  750. static void hc32_uart1_tx_irq_handler(void)
  751. {
  752. /* enter interrupt */
  753. rt_interrupt_enter();
  754. hc32_uart_tx_irq_handler(&uart_obj[UART1_INDEX]);
  755. /* leave interrupt */
  756. rt_interrupt_leave();
  757. }
  758. static void hc32_uart1_rxerr_irq_handler(void)
  759. {
  760. /* enter interrupt */
  761. rt_interrupt_enter();
  762. hc32_uart_rxerr_irq_handler(&uart_obj[UART1_INDEX]);
  763. /* leave interrupt */
  764. rt_interrupt_leave();
  765. }
  766. #endif
  767. #if defined (RT_SERIAL_USING_DMA)
  768. #if defined (BSP_UART1_TX_USING_DMA)
  769. static void hc32_uart1_tc_irq_handler(void)
  770. {
  771. /* enter interrupt */
  772. rt_interrupt_enter();
  773. hc32_uart_tc_irq_handler(&uart_obj[UART1_INDEX]);
  774. /* leave interrupt */
  775. rt_interrupt_leave();
  776. }
  777. #if defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  778. void USART1_TxComplete_Handler(void)
  779. {
  780. hc32_uart1_tc_irq_handler();
  781. }
  782. #endif
  783. #endif /* BSP_UART1_TX_USING_DMA */
  784. #if defined (BSP_UART1_RX_USING_DMA)
  785. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  786. static void hc32_uart1_rxto_irq_handler(void)
  787. {
  788. /* enter interrupt */
  789. rt_interrupt_enter();
  790. hc32_uart_rxto_irq_handler(&uart_obj[UART1_INDEX]);
  791. /* leave interrupt */
  792. rt_interrupt_leave();
  793. }
  794. #endif
  795. static void hc32_uart1_dma_rx_irq_handler(void)
  796. {
  797. /* enter interrupt */
  798. rt_interrupt_enter();
  799. hc32_uart_dma_rx_irq_handler(&uart_obj[UART1_INDEX]);
  800. /* leave interrupt */
  801. rt_interrupt_leave();
  802. }
  803. #endif /* BSP_UART1_RX_USING_DMA */
  804. #endif /* RT_SERIAL_USING_DMA */
  805. #if defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  806. void USART1_Handler(void)
  807. {
  808. /* enter interrupt */
  809. rt_interrupt_enter();
  810. hc32_usart_handler(&uart_obj[UART1_INDEX]);
  811. /* leave interrupt */
  812. rt_interrupt_leave();
  813. }
  814. #endif
  815. #endif /* BSP_USING_UART1 */
  816. #if defined (BSP_USING_UART2)
  817. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  818. static void hc32_uart2_rx_irq_handler(void)
  819. {
  820. /* enter interrupt */
  821. rt_interrupt_enter();
  822. hc32_uart_rx_irq_handler(&uart_obj[UART2_INDEX]);
  823. /* leave interrupt */
  824. rt_interrupt_leave();
  825. }
  826. static void hc32_uart2_tx_irq_handler(void)
  827. {
  828. /* enter interrupt */
  829. rt_interrupt_enter();
  830. hc32_uart_tx_irq_handler(&uart_obj[UART2_INDEX]);
  831. /* leave interrupt */
  832. rt_interrupt_leave();
  833. }
  834. static void hc32_uart2_rxerr_irq_handler(void)
  835. {
  836. /* enter interrupt */
  837. rt_interrupt_enter();
  838. hc32_uart_rxerr_irq_handler(&uart_obj[UART2_INDEX]);
  839. /* leave interrupt */
  840. rt_interrupt_leave();
  841. }
  842. #endif
  843. #if defined (RT_SERIAL_USING_DMA)
  844. #if defined (BSP_UART2_TX_USING_DMA)
  845. static void hc32_uart2_tc_irq_handler(void)
  846. {
  847. /* enter interrupt */
  848. rt_interrupt_enter();
  849. hc32_uart_tc_irq_handler(&uart_obj[UART2_INDEX]);
  850. /* leave interrupt */
  851. rt_interrupt_leave();
  852. }
  853. #if defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  854. void USART2_TxComplete_Handler(void)
  855. {
  856. hc32_uart2_tc_irq_handler();
  857. }
  858. #endif
  859. #endif /* BSP_UART2_TX_USING_DMA */
  860. #if defined (BSP_UART2_RX_USING_DMA)
  861. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  862. static void hc32_uart2_rxto_irq_handler(void)
  863. {
  864. /* enter interrupt */
  865. rt_interrupt_enter();
  866. hc32_uart_rxto_irq_handler(&uart_obj[UART2_INDEX]);
  867. /* leave interrupt */
  868. rt_interrupt_leave();
  869. }
  870. #endif
  871. static void hc32_uart2_dma_rx_irq_handler(void)
  872. {
  873. /* enter interrupt */
  874. rt_interrupt_enter();
  875. hc32_uart_dma_rx_irq_handler(&uart_obj[UART2_INDEX]);
  876. /* leave interrupt */
  877. rt_interrupt_leave();
  878. }
  879. #endif /* BSP_UART2_RX_USING_DMA */
  880. #endif /* RT_SERIAL_USING_DMA */
  881. #if defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  882. void USART2_Handler(void)
  883. {
  884. /* enter interrupt */
  885. rt_interrupt_enter();
  886. hc32_usart_handler(&uart_obj[UART2_INDEX]);
  887. /* leave interrupt */
  888. rt_interrupt_leave();
  889. }
  890. #endif
  891. #endif /* BSP_USING_UART2 */
  892. #if defined (BSP_USING_UART3)
  893. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  894. static void hc32_uart3_rx_irq_handler(void)
  895. {
  896. /* enter interrupt */
  897. rt_interrupt_enter();
  898. hc32_uart_rx_irq_handler(&uart_obj[UART3_INDEX]);
  899. /* leave interrupt */
  900. rt_interrupt_leave();
  901. }
  902. static void hc32_uart3_tx_irq_handler(void)
  903. {
  904. /* enter interrupt */
  905. rt_interrupt_enter();
  906. hc32_uart_tx_irq_handler(&uart_obj[UART3_INDEX]);
  907. /* leave interrupt */
  908. rt_interrupt_leave();
  909. }
  910. static void hc32_uart3_rxerr_irq_handler(void)
  911. {
  912. /* enter interrupt */
  913. rt_interrupt_enter();
  914. hc32_uart_rxerr_irq_handler(&uart_obj[UART3_INDEX]);
  915. /* leave interrupt */
  916. rt_interrupt_leave();
  917. }
  918. #if defined (RT_SERIAL_USING_DMA)
  919. #if defined (BSP_UART3_TX_USING_DMA)
  920. static void hc32_uart3_tc_irq_handler(void)
  921. {
  922. /* enter interrupt */
  923. rt_interrupt_enter();
  924. hc32_uart_tc_irq_handler(&uart_obj[UART3_INDEX]);
  925. /* leave interrupt */
  926. rt_interrupt_leave();
  927. }
  928. #endif /* BSP_UART3_TX_USING_DMA */
  929. #if defined (BSP_UART3_RX_USING_DMA)
  930. static void hc32_uart3_rxto_irq_handler(void)
  931. {
  932. /* enter interrupt */
  933. rt_interrupt_enter();
  934. hc32_uart_rxto_irq_handler(&uart_obj[UART3_INDEX]);
  935. /* leave interrupt */
  936. rt_interrupt_leave();
  937. }
  938. static void hc32_uart3_dma_rx_irq_handler(void)
  939. {
  940. /* enter interrupt */
  941. rt_interrupt_enter();
  942. hc32_uart_dma_rx_irq_handler(&uart_obj[UART3_INDEX]);
  943. /* leave interrupt */
  944. rt_interrupt_leave();
  945. }
  946. #endif /* BSP_UART3_RX_USING_DMA */
  947. #endif /* RT_SERIAL_USING_DMA */
  948. #endif /* HC32F460, HC32F4A0, HC32F4A8 */
  949. #if defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  950. void USART3_Handler(void)
  951. {
  952. /* enter interrupt */
  953. rt_interrupt_enter();
  954. hc32_usart_handler(&uart_obj[UART3_INDEX]);
  955. /* leave interrupt */
  956. rt_interrupt_leave();
  957. }
  958. #endif
  959. #endif /* BSP_USING_UART3 */
  960. #if defined (BSP_USING_UART4)
  961. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  962. static void hc32_uart4_rx_irq_handler(void)
  963. {
  964. /* enter interrupt */
  965. rt_interrupt_enter();
  966. hc32_uart_rx_irq_handler(&uart_obj[UART4_INDEX]);
  967. /* leave interrupt */
  968. rt_interrupt_leave();
  969. }
  970. static void hc32_uart4_tx_irq_handler(void)
  971. {
  972. /* enter interrupt */
  973. rt_interrupt_enter();
  974. hc32_uart_tx_irq_handler(&uart_obj[UART4_INDEX]);
  975. /* leave interrupt */
  976. rt_interrupt_leave();
  977. }
  978. static void hc32_uart4_rxerr_irq_handler(void)
  979. {
  980. /* enter interrupt */
  981. rt_interrupt_enter();
  982. hc32_uart_rxerr_irq_handler(&uart_obj[UART4_INDEX]);
  983. /* leave interrupt */
  984. rt_interrupt_leave();
  985. }
  986. #endif
  987. #if defined (RT_SERIAL_USING_DMA)
  988. #if defined (BSP_UART4_TX_USING_DMA)
  989. static void hc32_uart4_tc_irq_handler(void)
  990. {
  991. /* enter interrupt */
  992. rt_interrupt_enter();
  993. hc32_uart_tc_irq_handler(&uart_obj[UART4_INDEX]);
  994. /* leave interrupt */
  995. rt_interrupt_leave();
  996. }
  997. #if defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  998. void USART4_TxComplete_Handler(void)
  999. {
  1000. hc32_uart4_tc_irq_handler();
  1001. }
  1002. #endif
  1003. #endif /* BSP_UART4_TX_USING_DMA */
  1004. #if defined (BSP_UART4_RX_USING_DMA)
  1005. #if defined (HC32F460) || defined (HC32F4A8)
  1006. static void hc32_uart4_rxto_irq_handler(void)
  1007. {
  1008. /* enter interrupt */
  1009. rt_interrupt_enter();
  1010. hc32_uart_rxto_irq_handler(&uart_obj[UART4_INDEX]);
  1011. /* leave interrupt */
  1012. rt_interrupt_leave();
  1013. }
  1014. #endif
  1015. static void hc32_uart4_dma_rx_irq_handler(void)
  1016. {
  1017. /* enter interrupt */
  1018. rt_interrupt_enter();
  1019. hc32_uart_dma_rx_irq_handler(&uart_obj[UART4_INDEX]);
  1020. /* leave interrupt */
  1021. rt_interrupt_leave();
  1022. }
  1023. #endif /* BSP_UART4_RX_USING_DMA */
  1024. #endif /* RT_SERIAL_USING_DMA */
  1025. #if defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  1026. void USART4_Handler(void)
  1027. {
  1028. /* enter interrupt */
  1029. rt_interrupt_enter();
  1030. hc32_usart_handler(&uart_obj[UART4_INDEX]);
  1031. /* leave interrupt */
  1032. rt_interrupt_leave();
  1033. }
  1034. #endif
  1035. #endif /* BSP_USING_UART4 */
  1036. #if defined (BSP_USING_UART5)
  1037. #if defined (HC32F4A0) || defined (HC32F4A8)
  1038. static void hc32_uart5_rx_irq_handler(void)
  1039. {
  1040. /* enter interrupt */
  1041. rt_interrupt_enter();
  1042. hc32_uart_rx_irq_handler(&uart_obj[UART5_INDEX]);
  1043. /* leave interrupt */
  1044. rt_interrupt_leave();
  1045. }
  1046. static void hc32_uart5_tx_irq_handler(void)
  1047. {
  1048. /* enter interrupt */
  1049. rt_interrupt_enter();
  1050. hc32_uart_tx_irq_handler(&uart_obj[UART5_INDEX]);
  1051. /* leave interrupt */
  1052. rt_interrupt_leave();
  1053. }
  1054. static void hc32_uart5_rxerr_irq_handler(void)
  1055. {
  1056. /* enter interrupt */
  1057. rt_interrupt_enter();
  1058. hc32_uart_rxerr_irq_handler(&uart_obj[UART5_INDEX]);
  1059. /* leave interrupt */
  1060. rt_interrupt_leave();
  1061. }
  1062. #endif
  1063. #if defined (RT_SERIAL_USING_DMA)
  1064. #if defined (BSP_UART5_TX_USING_DMA)
  1065. static void hc32_uart5_tc_irq_handler(void)
  1066. {
  1067. /* enter interrupt */
  1068. rt_interrupt_enter();
  1069. hc32_uart_tc_irq_handler(&uart_obj[UART5_INDEX]);
  1070. /* leave interrupt */
  1071. rt_interrupt_leave();
  1072. }
  1073. #if defined (HC32F448) || defined (HC32F472)
  1074. void USART5_TxComplete_Handler(void)
  1075. {
  1076. hc32_uart5_tc_irq_handler();
  1077. }
  1078. #endif
  1079. #endif /* BSP_UART5_TX_USING_DMA */
  1080. #if defined (BSP_UART5_RX_USING_DMA)
  1081. #if defined (HC32F4A8)
  1082. static void hc32_uart5_rxto_irq_handler(void)
  1083. {
  1084. /* enter interrupt */
  1085. rt_interrupt_enter();
  1086. hc32_uart_rxto_irq_handler(&uart_obj[UART5_INDEX]);
  1087. /* leave interrupt */
  1088. rt_interrupt_leave();
  1089. }
  1090. #endif
  1091. static void hc32_uart5_dma_rx_irq_handler(void)
  1092. {
  1093. /* enter interrupt */
  1094. rt_interrupt_enter();
  1095. hc32_uart_dma_rx_irq_handler(&uart_obj[UART5_INDEX]);
  1096. /* leave interrupt */
  1097. rt_interrupt_leave();
  1098. }
  1099. #endif /* BSP_UART5_RX_USING_DMA */
  1100. #endif /* RT_SERIAL_USING_DMA */
  1101. #if defined (HC32F448) || defined (HC32F472)
  1102. void USART5_Handler(void)
  1103. {
  1104. /* enter interrupt */
  1105. rt_interrupt_enter();
  1106. hc32_usart_handler(&uart_obj[UART5_INDEX]);
  1107. /* leave interrupt */
  1108. rt_interrupt_leave();
  1109. }
  1110. #endif
  1111. #endif /* BSP_USING_UART5 */
  1112. #if defined (BSP_USING_UART6)
  1113. #if defined (HC32F4A0) || defined (HC32F4A8)
  1114. static void hc32_uart6_rx_irq_handler(void)
  1115. {
  1116. /* enter interrupt */
  1117. rt_interrupt_enter();
  1118. hc32_uart_rx_irq_handler(&uart_obj[UART6_INDEX]);
  1119. /* leave interrupt */
  1120. rt_interrupt_leave();
  1121. }
  1122. static void hc32_uart6_tx_irq_handler(void)
  1123. {
  1124. /* enter interrupt */
  1125. rt_interrupt_enter();
  1126. hc32_uart_tx_irq_handler(&uart_obj[UART6_INDEX]);
  1127. /* leave interrupt */
  1128. rt_interrupt_leave();
  1129. }
  1130. static void hc32_uart6_rxerr_irq_handler(void)
  1131. {
  1132. /* enter interrupt */
  1133. rt_interrupt_enter();
  1134. hc32_uart_rxerr_irq_handler(&uart_obj[UART6_INDEX]);
  1135. /* leave interrupt */
  1136. rt_interrupt_leave();
  1137. }
  1138. #if defined (RT_SERIAL_USING_DMA)
  1139. #if defined (BSP_UART6_TX_USING_DMA)
  1140. static void hc32_uart6_tc_irq_handler(void)
  1141. {
  1142. /* enter interrupt */
  1143. rt_interrupt_enter();
  1144. hc32_uart_tc_irq_handler(&uart_obj[UART6_INDEX]);
  1145. /* leave interrupt */
  1146. rt_interrupt_leave();
  1147. }
  1148. #endif /* BSP_UART6_TX_USING_DMA */
  1149. #if defined (BSP_UART6_RX_USING_DMA)
  1150. static void hc32_uart6_rxto_irq_handler(void)
  1151. {
  1152. /* enter interrupt */
  1153. rt_interrupt_enter();
  1154. hc32_uart_rxto_irq_handler(&uart_obj[UART6_INDEX]);
  1155. /* leave interrupt */
  1156. rt_interrupt_leave();
  1157. }
  1158. static void hc32_uart6_dma_rx_irq_handler(void)
  1159. {
  1160. /* enter interrupt */
  1161. rt_interrupt_enter();
  1162. hc32_uart_dma_rx_irq_handler(&uart_obj[UART6_INDEX]);
  1163. /* leave interrupt */
  1164. rt_interrupt_leave();
  1165. }
  1166. #endif /* BSP_UART6_RX_USING_DMA */
  1167. #endif /* RT_SERIAL_USING_DMA */
  1168. #endif /* HC32F4A0, HC32F4A8 */
  1169. #if defined (HC32F448) || defined (HC32F472)
  1170. void USART6_Handler(void)
  1171. {
  1172. /* enter interrupt */
  1173. rt_interrupt_enter();
  1174. hc32_usart_handler(&uart_obj[UART6_INDEX]);
  1175. /* leave interrupt */
  1176. rt_interrupt_leave();
  1177. }
  1178. #endif
  1179. #endif /* BSP_USING_UART6 */
  1180. #if defined (BSP_USING_UART7)
  1181. static void hc32_uart7_rx_irq_handler(void)
  1182. {
  1183. /* enter interrupt */
  1184. rt_interrupt_enter();
  1185. hc32_uart_rx_irq_handler(&uart_obj[UART7_INDEX]);
  1186. /* leave interrupt */
  1187. rt_interrupt_leave();
  1188. }
  1189. static void hc32_uart7_tx_irq_handler(void)
  1190. {
  1191. /* enter interrupt */
  1192. rt_interrupt_enter();
  1193. hc32_uart_tx_irq_handler(&uart_obj[UART7_INDEX]);
  1194. /* leave interrupt */
  1195. rt_interrupt_leave();
  1196. }
  1197. static void hc32_uart7_rxerr_irq_handler(void)
  1198. {
  1199. /* enter interrupt */
  1200. rt_interrupt_enter();
  1201. hc32_uart_rxerr_irq_handler(&uart_obj[UART7_INDEX]);
  1202. /* leave interrupt */
  1203. rt_interrupt_leave();
  1204. }
  1205. #if defined (RT_SERIAL_USING_DMA)
  1206. #if defined (BSP_UART7_TX_USING_DMA)
  1207. static void hc32_uart7_tc_irq_handler(void)
  1208. {
  1209. /* enter interrupt */
  1210. rt_interrupt_enter();
  1211. hc32_uart_tc_irq_handler(&uart_obj[UART7_INDEX]);
  1212. /* leave interrupt */
  1213. rt_interrupt_leave();
  1214. }
  1215. #endif /* BSP_UART7_TX_USING_DMA */
  1216. #if defined (BSP_UART7_RX_USING_DMA)
  1217. static void hc32_uart7_rxto_irq_handler(void)
  1218. {
  1219. /* enter interrupt */
  1220. rt_interrupt_enter();
  1221. hc32_uart_rxto_irq_handler(&uart_obj[UART7_INDEX]);
  1222. /* leave interrupt */
  1223. rt_interrupt_leave();
  1224. }
  1225. static void hc32_uart7_dma_rx_irq_handler(void)
  1226. {
  1227. /* enter interrupt */
  1228. rt_interrupt_enter();
  1229. hc32_uart_dma_rx_irq_handler(&uart_obj[UART7_INDEX]);
  1230. /* leave interrupt */
  1231. rt_interrupt_leave();
  1232. }
  1233. #endif /* BSP_UART7_RX_USING_DMA */
  1234. #endif /* RT_SERIAL_USING_DMA */
  1235. #endif /* BSP_USING_UART7 */
  1236. #if defined (BSP_USING_UART8)
  1237. static void hc32_uart8_rx_irq_handler(void)
  1238. {
  1239. /* enter interrupt */
  1240. rt_interrupt_enter();
  1241. hc32_uart_rx_irq_handler(&uart_obj[UART8_INDEX]);
  1242. /* leave interrupt */
  1243. rt_interrupt_leave();
  1244. }
  1245. static void hc32_uart8_tx_irq_handler(void)
  1246. {
  1247. /* enter interrupt */
  1248. rt_interrupt_enter();
  1249. hc32_uart_tx_irq_handler(&uart_obj[UART8_INDEX]);
  1250. /* leave interrupt */
  1251. rt_interrupt_leave();
  1252. }
  1253. static void hc32_uart8_rxerr_irq_handler(void)
  1254. {
  1255. /* enter interrupt */
  1256. rt_interrupt_enter();
  1257. hc32_uart_rxerr_irq_handler(&uart_obj[UART8_INDEX]);
  1258. /* leave interrupt */
  1259. rt_interrupt_leave();
  1260. }
  1261. #if defined (RT_SERIAL_USING_DMA)
  1262. #if defined (BSP_UART8_TX_USING_DMA)
  1263. static void hc32_uart8_tc_irq_handler(void)
  1264. {
  1265. /* enter interrupt */
  1266. rt_interrupt_enter();
  1267. hc32_uart_tc_irq_handler(&uart_obj[UART8_INDEX]);
  1268. /* leave interrupt */
  1269. rt_interrupt_leave();
  1270. }
  1271. #endif /* BSP_UART8_TX_USING_DMA */
  1272. #if defined (BSP_UART8_RX_USING_DMA)
  1273. static void hc32_uart8_rxto_irq_handler(void)
  1274. {
  1275. /* enter interrupt */
  1276. rt_interrupt_enter();
  1277. hc32_uart_rxto_irq_handler(&uart_obj[UART8_INDEX]);
  1278. /* leave interrupt */
  1279. rt_interrupt_leave();
  1280. }
  1281. static void hc32_uart8_dma_rx_irq_handler(void)
  1282. {
  1283. /* enter interrupt */
  1284. rt_interrupt_enter();
  1285. hc32_uart_dma_rx_irq_handler(&uart_obj[UART8_INDEX]);
  1286. /* leave interrupt */
  1287. rt_interrupt_leave();
  1288. }
  1289. #endif /* BSP_UART8_RX_USING_DMA */
  1290. #endif /* RT_SERIAL_USING_DMA */
  1291. #endif /* BSP_USING_UART8 */
  1292. #if defined (BSP_USING_UART9)
  1293. static void hc32_uart9_rx_irq_handler(void)
  1294. {
  1295. /* enter interrupt */
  1296. rt_interrupt_enter();
  1297. hc32_uart_rx_irq_handler(&uart_obj[UART9_INDEX]);
  1298. /* leave interrupt */
  1299. rt_interrupt_leave();
  1300. }
  1301. static void hc32_uart9_tx_irq_handler(void)
  1302. {
  1303. /* enter interrupt */
  1304. rt_interrupt_enter();
  1305. hc32_uart_tx_irq_handler(&uart_obj[UART9_INDEX]);
  1306. /* leave interrupt */
  1307. rt_interrupt_leave();
  1308. }
  1309. static void hc32_uart9_rxerr_irq_handler(void)
  1310. {
  1311. /* enter interrupt */
  1312. rt_interrupt_enter();
  1313. hc32_uart_rxerr_irq_handler(&uart_obj[UART9_INDEX]);
  1314. /* leave interrupt */
  1315. rt_interrupt_leave();
  1316. }
  1317. #if defined (RT_SERIAL_USING_DMA)
  1318. #if defined (BSP_UART9_TX_USING_DMA)
  1319. static void hc32_uart9_tc_irq_handler(void)
  1320. {
  1321. /* enter interrupt */
  1322. rt_interrupt_enter();
  1323. hc32_uart_tc_irq_handler(&uart_obj[UART9_INDEX]);
  1324. /* leave interrupt */
  1325. rt_interrupt_leave();
  1326. }
  1327. #endif /* BSP_UART9_TX_USING_DMA */
  1328. #if defined (BSP_UART9_RX_USING_DMA)
  1329. static void hc32_uart9_rxto_irq_handler(void)
  1330. {
  1331. /* enter interrupt */
  1332. rt_interrupt_enter();
  1333. hc32_uart_rxto_irq_handler(&uart_obj[UART9_INDEX]);
  1334. /* leave interrupt */
  1335. rt_interrupt_leave();
  1336. }
  1337. static void hc32_uart9_dma_rx_irq_handler(void)
  1338. {
  1339. /* enter interrupt */
  1340. rt_interrupt_enter();
  1341. hc32_uart_dma_rx_irq_handler(&uart_obj[UART9_INDEX]);
  1342. /* leave interrupt */
  1343. rt_interrupt_leave();
  1344. }
  1345. #endif /* BSP_UART9_RX_USING_DMA */
  1346. #endif /* RT_SERIAL_USING_DMA */
  1347. #endif /* BSP_USING_UART9 */
  1348. #if defined (BSP_USING_UART10)
  1349. static void hc32_uart10_rx_irq_handler(void)
  1350. {
  1351. /* enter interrupt */
  1352. rt_interrupt_enter();
  1353. hc32_uart_rx_irq_handler(&uart_obj[UART10_INDEX]);
  1354. /* leave interrupt */
  1355. rt_interrupt_leave();
  1356. }
  1357. static void hc32_uart10_tx_irq_handler(void)
  1358. {
  1359. /* enter interrupt */
  1360. rt_interrupt_enter();
  1361. hc32_uart_tx_irq_handler(&uart_obj[UART10_INDEX]);
  1362. /* leave interrupt */
  1363. rt_interrupt_leave();
  1364. }
  1365. static void hc32_uart10_rxerr_irq_handler(void)
  1366. {
  1367. /* enter interrupt */
  1368. rt_interrupt_enter();
  1369. hc32_uart_rxerr_irq_handler(&uart_obj[UART10_INDEX]);
  1370. /* leave interrupt */
  1371. rt_interrupt_leave();
  1372. }
  1373. #if defined (RT_SERIAL_USING_DMA)
  1374. #if defined (BSP_UART10_TX_USING_DMA)
  1375. static void hc32_uart10_tc_irq_handler(void)
  1376. {
  1377. /* enter interrupt */
  1378. rt_interrupt_enter();
  1379. hc32_uart_tc_irq_handler(&uart_obj[UART10_INDEX]);
  1380. /* leave interrupt */
  1381. rt_interrupt_leave();
  1382. }
  1383. #endif /* BSP_UART10_TX_USING_DMA */
  1384. #if defined (BSP_UART10_RX_USING_DMA)
  1385. static void hc32_uart10_rxto_irq_handler(void)
  1386. {
  1387. /* enter interrupt */
  1388. rt_interrupt_enter();
  1389. hc32_uart_rxto_irq_handler(&uart_obj[UART10_INDEX]);
  1390. /* leave interrupt */
  1391. rt_interrupt_leave();
  1392. }
  1393. static void hc32_uart10_dma_rx_irq_handler(void)
  1394. {
  1395. /* enter interrupt */
  1396. rt_interrupt_enter();
  1397. hc32_uart_dma_rx_irq_handler(&uart_obj[UART10_INDEX]);
  1398. /* leave interrupt */
  1399. rt_interrupt_leave();
  1400. }
  1401. #endif /* BSP_UART10_RX_USING_DMA */
  1402. #endif /* RT_SERIAL_USING_DMA */
  1403. #endif /* BSP_USING_UART10 */
  1404. /**
  1405. * @brief This function gets dma witch uart used infomation include unit,
  1406. * channel, interrupt etc.
  1407. * @param None
  1408. * @retval None
  1409. */
  1410. static void hc32_uart_get_dma_info(void)
  1411. {
  1412. #ifdef BSP_USING_UART1
  1413. uart_obj[UART1_INDEX].uart_dma_flag = 0;
  1414. #ifdef BSP_UART1_RX_USING_DMA
  1415. uart_obj[UART1_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
  1416. static struct dma_config uart1_dma_rx = UART1_DMA_RX_CONFIG;
  1417. static struct hc32_uart_rxto uart1_rx_timeout = UART1_RXTO_CONFIG;
  1418. uart1_dma_rx.irq_callback = hc32_uart1_dma_rx_irq_handler;
  1419. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  1420. uart1_rx_timeout.irq_callback = hc32_uart1_rxto_irq_handler;
  1421. #endif
  1422. uart_config[UART1_INDEX].rx_timeout = &uart1_rx_timeout;
  1423. uart_config[UART1_INDEX].dma_rx = &uart1_dma_rx;
  1424. #endif
  1425. #ifdef BSP_UART1_TX_USING_DMA
  1426. uart_obj[UART1_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
  1427. static struct dma_config uart1_dma_tx = UART1_DMA_TX_CONFIG;
  1428. uart_config[UART1_INDEX].dma_tx = &uart1_dma_tx;
  1429. static struct hc32_uart_irq_config uart1_tc_irq = UART1_TX_CPLT_CONFIG;
  1430. uart1_tc_irq.irq_callback = hc32_uart1_tc_irq_handler;
  1431. uart_config[UART1_INDEX].tc_irq = &uart1_tc_irq;
  1432. #endif
  1433. #endif
  1434. #ifdef BSP_USING_UART2
  1435. uart_obj[UART2_INDEX].uart_dma_flag = 0;
  1436. #ifdef BSP_UART2_RX_USING_DMA
  1437. uart_obj[UART2_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
  1438. static struct dma_config uart2_dma_rx = UART2_DMA_RX_CONFIG;
  1439. static struct hc32_uart_rxto uart2_rx_timeout = UART2_RXTO_CONFIG;
  1440. uart2_dma_rx.irq_callback = hc32_uart2_dma_rx_irq_handler;
  1441. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  1442. uart2_rx_timeout.irq_callback = hc32_uart2_rxto_irq_handler;
  1443. #endif
  1444. uart_config[UART2_INDEX].rx_timeout = &uart2_rx_timeout;
  1445. uart_config[UART2_INDEX].dma_rx = &uart2_dma_rx;
  1446. #endif
  1447. #ifdef BSP_UART2_TX_USING_DMA
  1448. uart_obj[UART2_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
  1449. static struct dma_config uart2_dma_tx = UART2_DMA_TX_CONFIG;
  1450. uart_config[UART2_INDEX].dma_tx = &uart2_dma_tx;
  1451. static struct hc32_uart_irq_config uart2_tc_irq = UART2_TX_CPLT_CONFIG;
  1452. uart2_tc_irq.irq_callback = hc32_uart2_tc_irq_handler;
  1453. uart_config[UART2_INDEX].tc_irq = &uart2_tc_irq;
  1454. #endif
  1455. #endif
  1456. #ifdef BSP_USING_UART3
  1457. uart_obj[UART3_INDEX].uart_dma_flag = 0;
  1458. #ifdef BSP_UART3_RX_USING_DMA
  1459. uart_obj[UART3_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
  1460. static struct dma_config uart3_dma_rx = UART3_DMA_RX_CONFIG;
  1461. static struct hc32_uart_rxto uart3_rx_timeout = UART3_RXTO_CONFIG;
  1462. uart3_dma_rx.irq_callback = hc32_uart3_dma_rx_irq_handler;
  1463. uart3_rx_timeout.irq_callback = hc32_uart3_rxto_irq_handler;
  1464. uart_config[UART3_INDEX].rx_timeout = &uart3_rx_timeout;
  1465. uart_config[UART3_INDEX].dma_rx = &uart3_dma_rx;
  1466. #endif
  1467. #ifdef BSP_UART3_TX_USING_DMA
  1468. uart_obj[UART3_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
  1469. static struct dma_config uart3_dma_tx = UART3_DMA_TX_CONFIG;
  1470. uart_config[UART3_INDEX].dma_tx = &uart3_dma_tx;
  1471. static struct hc32_uart_irq_config uart3_tc_irq = UART3_TX_CPLT_CONFIG;
  1472. uart3_tc_irq.irq_callback = hc32_uart3_tc_irq_handler;
  1473. uart_config[UART3_INDEX].tc_irq = &uart3_tc_irq;
  1474. #endif
  1475. #endif
  1476. #ifdef BSP_USING_UART4
  1477. uart_obj[UART4_INDEX].uart_dma_flag = 0;
  1478. #ifdef BSP_UART4_RX_USING_DMA
  1479. uart_obj[UART4_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
  1480. static struct dma_config uart4_dma_rx = UART4_DMA_RX_CONFIG;
  1481. static struct hc32_uart_rxto uart4_rx_timeout = UART4_RXTO_CONFIG;
  1482. uart4_dma_rx.irq_callback = hc32_uart4_dma_rx_irq_handler;
  1483. #if defined (HC32F460) || defined (HC32F4A8)
  1484. uart4_rx_timeout.irq_callback = hc32_uart4_rxto_irq_handler;
  1485. #endif
  1486. uart_config[UART4_INDEX].rx_timeout = &uart4_rx_timeout;
  1487. uart_config[UART4_INDEX].dma_rx = &uart4_dma_rx;
  1488. #endif
  1489. #ifdef BSP_UART4_TX_USING_DMA
  1490. uart_obj[UART4_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
  1491. static struct dma_config uart4_dma_tx = UART4_DMA_TX_CONFIG;
  1492. uart_config[UART4_INDEX].dma_tx = &uart4_dma_tx;
  1493. static struct hc32_uart_irq_config uart4_tc_irq = UART4_TX_CPLT_CONFIG;
  1494. uart4_tc_irq.irq_callback = hc32_uart4_tc_irq_handler;
  1495. uart_config[UART4_INDEX].tc_irq = &uart4_tc_irq;
  1496. #endif
  1497. #endif
  1498. #ifdef BSP_USING_UART5
  1499. uart_obj[UART5_INDEX].uart_dma_flag = 0;
  1500. #ifdef BSP_UART5_RX_USING_DMA
  1501. uart_obj[UART5_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
  1502. static struct dma_config uart5_dma_rx = UART5_DMA_RX_CONFIG;
  1503. static struct hc32_uart_rxto uart5_rx_timeout = UART5_RXTO_CONFIG;
  1504. uart5_dma_rx.irq_callback = hc32_uart5_dma_rx_irq_handler;
  1505. #if defined (HC32F4A8)
  1506. uart5_rx_timeout.irq_callback = hc32_uart5_rxto_irq_handler;
  1507. #endif
  1508. uart_config[UART5_INDEX].rx_timeout = &uart5_rx_timeout;
  1509. uart_config[UART5_INDEX].dma_rx = &uart5_dma_rx;
  1510. #endif
  1511. #ifdef BSP_UART5_TX_USING_DMA
  1512. uart_obj[UART5_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
  1513. static struct dma_config uart5_dma_tx = UART5_DMA_TX_CONFIG;
  1514. uart_config[UART5_INDEX].dma_tx = &uart5_dma_tx;
  1515. static struct hc32_uart_irq_config uart5_tc_irq = UART5_TX_CPLT_CONFIG;
  1516. uart5_tc_irq.irq_callback = hc32_uart5_tc_irq_handler;
  1517. uart_config[UART5_INDEX].tc_irq = &uart5_tc_irq;
  1518. #endif
  1519. #endif
  1520. #ifdef BSP_USING_UART6
  1521. uart_obj[UART6_INDEX].uart_dma_flag = 0;
  1522. #ifdef BSP_UART6_RX_USING_DMA
  1523. uart_obj[UART6_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
  1524. static struct dma_config uart6_dma_rx = UART6_DMA_RX_CONFIG;
  1525. static struct hc32_uart_rxto uart6_rx_timeout = UART6_RXTO_CONFIG;
  1526. uart6_dma_rx.irq_callback = hc32_uart6_dma_rx_irq_handler;
  1527. uart6_rx_timeout.irq_callback = hc32_uart6_rxto_irq_handler;
  1528. uart_config[UART6_INDEX].rx_timeout = &uart6_rx_timeout;
  1529. uart_config[UART6_INDEX].dma_rx = &uart6_dma_rx;
  1530. #endif
  1531. #ifdef BSP_UART6_TX_USING_DMA
  1532. uart_obj[UART6_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
  1533. static struct dma_config uart6_dma_tx = UART6_DMA_TX_CONFIG;
  1534. uart_config[UART6_INDEX].dma_tx = &uart6_dma_tx;
  1535. static struct hc32_uart_irq_config uart6_tc_irq = UART6_TX_CPLT_CONFIG;
  1536. uart6_tc_irq.irq_callback = hc32_uart6_tc_irq_handler;
  1537. uart_config[UART6_INDEX].tc_irq = &uart6_tc_irq;
  1538. #endif
  1539. #endif
  1540. #ifdef BSP_USING_UART7
  1541. uart_obj[UART7_INDEX].uart_dma_flag = 0;
  1542. #ifdef BSP_UART7_RX_USING_DMA
  1543. uart_obj[UART7_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
  1544. static struct dma_config uart7_dma_rx = UART7_DMA_RX_CONFIG;
  1545. static struct hc32_uart_rxto uart7_rx_timeout = UART7_RXTO_CONFIG;
  1546. uart7_dma_rx.irq_callback = hc32_uart7_dma_rx_irq_handler;
  1547. uart7_rx_timeout.irq_callback = hc32_uart7_rxto_irq_handler;
  1548. uart_config[UART7_INDEX].rx_timeout = &uart7_rx_timeout;
  1549. uart_config[UART7_INDEX].dma_rx = &uart7_dma_rx;
  1550. #endif
  1551. #ifdef BSP_UART7_TX_USING_DMA
  1552. uart_obj[UART7_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
  1553. static struct dma_config uart7_dma_tx = UART7_DMA_TX_CONFIG;
  1554. uart_config[UART7_INDEX].dma_tx = &uart7_dma_tx;
  1555. static struct hc32_uart_irq_config uart7_tc_irq = UART7_TX_CPLT_CONFIG;
  1556. uart7_tc_irq.irq_callback = hc32_uart7_tc_irq_handler;
  1557. uart_config[UART7_INDEX].tc_irq = &uart7_tc_irq;
  1558. #endif
  1559. #endif
  1560. #ifdef BSP_USING_UART8
  1561. uart_obj[UART8_INDEX].uart_dma_flag = 0;
  1562. #ifdef BSP_UART8_RX_USING_DMA
  1563. uart_obj[UART8_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
  1564. static struct dma_config uart8_dma_rx = UART8_DMA_RX_CONFIG;
  1565. static struct hc32_uart_rxto uart8_rx_timeout = UART8_RXTO_CONFIG;
  1566. uart8_dma_rx.irq_callback = hc32_uart8_dma_rx_irq_handler;
  1567. uart8_rx_timeout.irq_callback = hc32_uart8_rxto_irq_handler;
  1568. uart_config[UART8_INDEX].rx_timeout = &uart8_rx_timeout;
  1569. uart_config[UART8_INDEX].dma_rx = &uart8_dma_rx;
  1570. #endif
  1571. #ifdef BSP_UART8_TX_USING_DMA
  1572. uart_obj[UART8_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
  1573. static struct dma_config uart8_dma_tx = UART8_DMA_TX_CONFIG;
  1574. uart_config[UART8_INDEX].dma_tx = &uart8_dma_tx;
  1575. static struct hc32_uart_irq_config uart8_tc_irq = UART8_TX_CPLT_CONFIG;
  1576. uart8_tc_irq.irq_callback = hc32_uart8_tc_irq_handler;
  1577. uart_config[UART8_INDEX].tc_irq = &uart8_tc_irq;
  1578. #endif
  1579. #endif
  1580. #ifdef BSP_USING_UART9
  1581. uart_obj[UART9_INDEX].uart_dma_flag = 0;
  1582. #ifdef BSP_UART9_RX_USING_DMA
  1583. uart_obj[UART9_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
  1584. static struct dma_config uart9_dma_rx = UART9_DMA_RX_CONFIG;
  1585. static struct hc32_uart_rxto uart9_rx_timeout = UART9_RXTO_CONFIG;
  1586. uart9_dma_rx.irq_callback = hc32_uart9_dma_rx_irq_handler;
  1587. uart9_rx_timeout.irq_callback = hc32_uart9_rxto_irq_handler;
  1588. uart_config[UART9_INDEX].rx_timeout = &uart9_rx_timeout;
  1589. uart_config[UART9_INDEX].dma_rx = &uart9_dma_rx;
  1590. #endif
  1591. #ifdef BSP_UART9_TX_USING_DMA
  1592. uart_obj[UART9_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
  1593. static struct dma_config uart9_dma_tx = UART9_DMA_TX_CONFIG;
  1594. uart_config[UART9_INDEX].dma_tx = &uart9_dma_tx;
  1595. static struct hc32_uart_irq_config uart9_tc_irq = UART9_TX_CPLT_CONFIG;
  1596. uart9_tc_irq.irq_callback = hc32_uart9_tc_irq_handler;
  1597. uart_config[UART9_INDEX].tc_irq = &uart9_tc_irq;
  1598. #endif
  1599. #endif
  1600. #ifdef BSP_USING_UART10
  1601. uart_obj[UART10_INDEX].uart_dma_flag = 0;
  1602. #ifdef BSP_UART10_RX_USING_DMA
  1603. uart_obj[UART10_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
  1604. static struct dma_config uart10_dma_rx = UART10_DMA_RX_CONFIG;
  1605. static struct hc32_uart_rxto uart10_rx_timeout = UART10_RXTO_CONFIG;
  1606. uart10_dma_rx.irq_callback = hc32_uart10_dma_rx_irq_handler;
  1607. uart10_rx_timeout.irq_callback = hc32_uart10_rxto_irq_handler;
  1608. uart_config[UART10_INDEX].rx_timeout = &uart10_rx_timeout;
  1609. uart_config[UART10_INDEX].dma_rx = &uart10_dma_rx;
  1610. #endif
  1611. #ifdef BSP_UART10_TX_USING_DMA
  1612. uart_obj[UART10_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
  1613. static struct dma_config uart10_dma_tx = UART10_DMA_TX_CONFIG;
  1614. uart_config[UART10_INDEX].dma_tx = &uart10_dma_tx;
  1615. static struct hc32_uart_irq_config uart10_tc_irq = UART10_TX_CPLT_CONFIG;
  1616. uart10_tc_irq.irq_callback = hc32_uart10_tc_irq_handler;
  1617. uart_config[UART10_INDEX].tc_irq = &uart10_tc_irq;
  1618. #endif
  1619. #endif
  1620. }
  1621. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  1622. /**
  1623. * @brief This function gets uart irq handle.
  1624. * @param None
  1625. * @retval None
  1626. */
  1627. static void hc32_get_uart_callback(void)
  1628. {
  1629. #ifdef BSP_USING_UART1
  1630. uart_config[UART1_INDEX].rxerr_irq.irq_callback = hc32_uart1_rxerr_irq_handler;
  1631. uart_config[UART1_INDEX].rx_irq.irq_callback = hc32_uart1_rx_irq_handler;
  1632. uart_config[UART1_INDEX].tx_irq.irq_callback = hc32_uart1_tx_irq_handler;
  1633. #endif
  1634. #ifdef BSP_USING_UART2
  1635. uart_config[UART2_INDEX].rxerr_irq.irq_callback = hc32_uart2_rxerr_irq_handler;
  1636. uart_config[UART2_INDEX].rx_irq.irq_callback = hc32_uart2_rx_irq_handler;
  1637. uart_config[UART2_INDEX].tx_irq.irq_callback = hc32_uart2_tx_irq_handler;
  1638. #endif
  1639. #ifdef BSP_USING_UART3
  1640. uart_config[UART3_INDEX].rxerr_irq.irq_callback = hc32_uart3_rxerr_irq_handler;
  1641. uart_config[UART3_INDEX].rx_irq.irq_callback = hc32_uart3_rx_irq_handler;
  1642. uart_config[UART3_INDEX].tx_irq.irq_callback = hc32_uart3_tx_irq_handler;
  1643. #endif
  1644. #ifdef BSP_USING_UART4
  1645. uart_config[UART4_INDEX].rxerr_irq.irq_callback = hc32_uart4_rxerr_irq_handler;
  1646. uart_config[UART4_INDEX].rx_irq.irq_callback = hc32_uart4_rx_irq_handler;
  1647. uart_config[UART4_INDEX].tx_irq.irq_callback = hc32_uart4_tx_irq_handler;
  1648. #endif
  1649. #ifdef BSP_USING_UART5
  1650. uart_config[UART5_INDEX].rxerr_irq.irq_callback = hc32_uart5_rxerr_irq_handler;
  1651. uart_config[UART5_INDEX].rx_irq.irq_callback = hc32_uart5_rx_irq_handler;
  1652. uart_config[UART5_INDEX].tx_irq.irq_callback = hc32_uart5_tx_irq_handler;
  1653. #endif
  1654. #ifdef BSP_USING_UART6
  1655. uart_config[UART6_INDEX].rxerr_irq.irq_callback = hc32_uart6_rxerr_irq_handler;
  1656. uart_config[UART6_INDEX].rx_irq.irq_callback = hc32_uart6_rx_irq_handler;
  1657. uart_config[UART6_INDEX].tx_irq.irq_callback = hc32_uart6_tx_irq_handler;
  1658. #endif
  1659. #ifdef BSP_USING_UART7
  1660. uart_config[UART7_INDEX].rxerr_irq.irq_callback = hc32_uart7_rxerr_irq_handler;
  1661. uart_config[UART7_INDEX].rx_irq.irq_callback = hc32_uart7_rx_irq_handler;
  1662. uart_config[UART7_INDEX].tx_irq.irq_callback = hc32_uart7_tx_irq_handler;
  1663. #endif
  1664. #ifdef BSP_USING_UART8
  1665. uart_config[UART8_INDEX].rxerr_irq.irq_callback = hc32_uart8_rxerr_irq_handler;
  1666. uart_config[UART8_INDEX].rx_irq.irq_callback = hc32_uart8_rx_irq_handler;
  1667. uart_config[UART8_INDEX].tx_irq.irq_callback = hc32_uart8_tx_irq_handler;
  1668. #endif
  1669. #ifdef BSP_USING_UART9
  1670. uart_config[UART9_INDEX].rxerr_irq.irq_callback = hc32_uart9_rxerr_irq_handler;
  1671. uart_config[UART9_INDEX].rx_irq.irq_callback = hc32_uart9_rx_irq_handler;
  1672. uart_config[UART9_INDEX].tx_irq.irq_callback = hc32_uart9_tx_irq_handler;
  1673. #endif
  1674. #ifdef BSP_USING_UART10
  1675. uart_config[UART10_INDEX].rxerr_irq.irq_callback = hc32_uart10_rxerr_irq_handler;
  1676. uart_config[UART10_INDEX].rx_irq.irq_callback = hc32_uart10_rx_irq_handler;
  1677. uart_config[UART10_INDEX].tx_irq.irq_callback = hc32_uart10_tx_irq_handler;
  1678. #endif
  1679. }
  1680. #endif
  1681. static const struct rt_uart_ops hc32_uart_ops =
  1682. {
  1683. .configure = hc32_configure,
  1684. .control = hc32_control,
  1685. .putc = hc32_putc,
  1686. .getc = hc32_getc,
  1687. .dma_transmit = hc32_dma_transmit
  1688. };
  1689. int rt_hw_usart_init(void)
  1690. {
  1691. rt_err_t result = RT_EOK;
  1692. rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct hc32_uart);
  1693. struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
  1694. hc32_uart_get_dma_info();
  1695. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  1696. hc32_get_uart_callback();
  1697. #endif
  1698. for (int i = 0; i < obj_num; i++)
  1699. {
  1700. /* init UART object */
  1701. uart_obj[i].serial.ops = &hc32_uart_ops;
  1702. uart_obj[i].serial.config = config;
  1703. uart_obj[i].config = &uart_config[i];
  1704. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  1705. /* register the handle */
  1706. hc32_install_irq_handler(&uart_config[i].rxerr_irq.irq_config, uart_config[i].rxerr_irq.irq_callback, RT_FALSE);
  1707. #endif
  1708. #ifdef RT_SERIAL_USING_DMA
  1709. if (uart_obj[i].uart_dma_flag & RT_DEVICE_FLAG_DMA_RX)
  1710. {
  1711. hc32_install_irq_handler(&uart_config[i].dma_rx->irq_config, uart_config[i].dma_rx->irq_callback, RT_FALSE);
  1712. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  1713. hc32_install_irq_handler(&uart_config[i].rx_timeout->irq_config, uart_config[i].rx_timeout->irq_callback, RT_FALSE);
  1714. #endif
  1715. }
  1716. if (uart_obj[i].uart_dma_flag & RT_DEVICE_FLAG_DMA_TX)
  1717. {
  1718. hc32_install_irq_handler(&uart_config[i].tc_irq->irq_config, uart_config[i].tc_irq->irq_callback, RT_FALSE);
  1719. }
  1720. #endif
  1721. /* register UART device */
  1722. result = rt_hw_serial_register(&uart_obj[i].serial,
  1723. uart_obj[i].config->name,
  1724. (RT_DEVICE_FLAG_RDWR |
  1725. RT_DEVICE_FLAG_INT_RX |
  1726. RT_DEVICE_FLAG_INT_TX |
  1727. uart_obj[i].uart_dma_flag),
  1728. &uart_obj[i]);
  1729. RT_ASSERT(result == RT_EOK);
  1730. }
  1731. return result;
  1732. }
  1733. #endif
  1734. #endif /* RT_USING_SERIAL */
  1735. /*******************************************************************************
  1736. * EOF (not truncated)
  1737. ******************************************************************************/