wm_uart.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  1. /**
  2. * @file wm_uart.c
  3. *
  4. * @brief uart Driver Module
  5. *
  6. * @author dave
  7. *
  8. * Copyright (c) 2015 Winner Microelectronics Co., Ltd.
  9. */
  10. #include <string.h>
  11. #include "wm_regs.h"
  12. #include "wm_uart.h"
  13. #include "wm_debug.h"
  14. #include "wm_irq.h"
  15. #include "wm_config.h"
  16. #include "wm_mem.h"
  17. #include "wm_dma.h"
  18. #include "wm_cpu.h"
  19. #if TLS_CONFIG_UART
  20. #define RX_CACHE_LIMIT 128
  21. #define STEP_SIZE (HR_UART1_BASE_ADDR - HR_UART0_BASE_ADDR)
  22. extern void tls_irq_priority(u8 vec_no, u32 prio);
  23. void tls_uart_tx_callback_register(u16 uart_no, s16(*tx_callback) (struct tls_uart_port *port));
  24. const u32 baud_rates[] = { 2000000, 1500000, 1250000, 1000000, 921600, 460800,
  25. 230400, 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1800, 1200, 600 };
  26. struct tls_uart_port uart_port[TLS_UART_MAX];
  27. static u8 uart_rx_byte_cb_flag[TLS_UART_MAX] = {0};
  28. static void tls_uart_tx_enable(struct tls_uart_port *port)
  29. {
  30. u32 ucon;
  31. ucon = port->regs->UR_LC;
  32. ucon |= ULCON_TX_EN;
  33. port->regs->UR_LC = ucon;
  34. }
  35. /**
  36. * @brief This function is used to continue transfer data.
  37. * @param[in] port: is the uart port.
  38. * @retval
  39. */
  40. static void tls_uart_tx_chars(struct tls_uart_port *port)
  41. {
  42. struct dl_list *pending_list = &port->tx_msg_pending_list;
  43. tls_uart_tx_msg_t *tx_msg = NULL;
  44. int tx_count;
  45. u32 cpu_sr;
  46. /* send some chars */
  47. tx_count = 32;
  48. cpu_sr = tls_os_set_critical();
  49. if (!dl_list_empty(pending_list))
  50. {
  51. tx_msg = dl_list_first(pending_list, tls_uart_tx_msg_t, list);
  52. while (tx_count-- > 0 && tx_msg->offset < tx_msg->buflen)
  53. {
  54. /* 检查tx fifo是否已满 */
  55. if ((port->regs->UR_FIFOS & UFS_TX_FIFO_CNT_MASK) == port->tx_fifofull)
  56. {
  57. break;
  58. }
  59. port->regs->UR_TXW = tx_msg->buf[tx_msg->offset];
  60. tx_msg->offset++;
  61. port->icount.tx++;
  62. }
  63. if (tx_msg->offset >= tx_msg->buflen)
  64. {
  65. dl_list_del(&tx_msg->list);
  66. dl_list_add_tail(&port->tx_msg_to_be_freed_list, &tx_msg->list);
  67. tls_os_release_critical(cpu_sr);
  68. if (port->tx_sent_callback)
  69. port->tx_sent_callback(port);
  70. if (port->tx_callback)
  71. port->tx_callback(port);
  72. }else{
  73. tls_os_release_critical(cpu_sr);
  74. }
  75. }
  76. else{
  77. tls_os_release_critical(cpu_sr);
  78. }
  79. }
  80. static void UartRegInit(int uart_no)
  81. {
  82. u32 bd;
  83. u32 apbclk;
  84. tls_sys_clk sysclk;
  85. tls_sys_clk_get(&sysclk);
  86. apbclk = sysclk.apbclk * 1000000;
  87. if (TLS_UART_0 == uart_no)
  88. {
  89. bd = (apbclk / (16 * 115200) - 1) | (((apbclk % (115200 * 16)) * 16 / (115200 * 16)) << 16);
  90. tls_reg_write32(HR_UART0_BAUD_RATE_CTRL, bd);
  91. /* Line control register : Normal,No parity,1 stop,8 bits, only use tx */
  92. tls_reg_write32(HR_UART0_LINE_CTRL, ULCON_WL8 | ULCON_TX_EN);
  93. /* disable auto flow control */
  94. tls_reg_write32(HR_UART0_FLOW_CTRL, 0);
  95. /* disable dma */
  96. tls_reg_write32(HR_UART0_DMA_CTRL, 0);
  97. /* one byte tx */
  98. tls_reg_write32(HR_UART0_FIFO_CTRL, 0);
  99. /* disable interrupt */
  100. tls_reg_write32(HR_UART0_INT_MASK, 0xFF);
  101. }
  102. else
  103. {
  104. /* 4 byte tx, 8 bytes rx */
  105. tls_reg_write32(HR_UART0_FIFO_CTRL + uart_no*STEP_SIZE, (0x01 << 2) | (0x02 << 4));
  106. /* enable rx timeout, disable rx dma, disable tx dma */
  107. tls_reg_write32(HR_UART0_DMA_CTRL + uart_no*STEP_SIZE, (8 << 3) | (1 << 2));
  108. /* enable rx/timeout interrupt */
  109. tls_reg_write32(HR_UART0_INT_MASK + uart_no*STEP_SIZE, ~(3 << 2));
  110. }
  111. }
  112. int tls_uart_check_baudrate(u32 baudrate)
  113. {
  114. int i;
  115. for (i = 0; i < sizeof(baud_rates) / sizeof(u32); i++)
  116. {
  117. if (baudrate == baud_rates[i])
  118. return 1;
  119. }
  120. /* not found match baudrate */
  121. return -1;
  122. }
  123. u32 tls_uart_get_baud_rate(struct tls_uart_port * port)
  124. {
  125. if ((port != NULL) && (port->regs != NULL))
  126. return port->opts.baudrate;
  127. else
  128. return 0;
  129. }
  130. static int tls_uart_set_baud_rate_inside(struct tls_uart_port *port, u32 baudrate)
  131. {
  132. int index;
  133. u32 value;
  134. u32 apbclk;
  135. tls_sys_clk sysclk;
  136. // index = tls_uart_check_baudrate(baudrate);
  137. // if (index < 0)
  138. // {
  139. // return WM_FAILED;
  140. // }
  141. tls_sys_clk_get(&sysclk);
  142. apbclk = sysclk.apbclk * 1000000;
  143. value = (apbclk / (16 * baudrate) - 1) |
  144. (((apbclk % (baudrate * 16)) * 16 / (baudrate * 16)) << 16);
  145. port->regs->UR_BD = value;
  146. port->opts.baudrate = baudrate;
  147. return WM_SUCCESS;
  148. }
  149. static int tls_uart_set_parity_inside(struct tls_uart_port *port, TLS_UART_PMODE_T paritytype)
  150. {
  151. if (port == NULL)
  152. return WM_FAILED;
  153. port->opts.paritytype = paritytype;
  154. if (paritytype == TLS_UART_PMODE_DISABLED)
  155. port->regs->UR_LC &= ~ULCON_PMD_EN;
  156. else if (paritytype == TLS_UART_PMODE_EVEN)
  157. {
  158. port->regs->UR_LC &= ~ULCON_PMD_MASK;
  159. port->regs->UR_LC |= ULCON_PMD_EVEN;
  160. }
  161. else if (paritytype == TLS_UART_PMODE_ODD)
  162. {
  163. port->regs->UR_LC &= ~ULCON_PMD_MASK;
  164. port->regs->UR_LC |= ULCON_PMD_ODD;
  165. }
  166. else
  167. return WM_FAILED;
  168. return WM_SUCCESS;
  169. }
  170. #if 0
  171. static TLS_UART_PMODE_T tls_uart_get_parity(struct tls_uart_port * port)
  172. {
  173. return port->opts.paritytype;
  174. }
  175. #endif
  176. static int tls_uart_set_data_bits(struct tls_uart_port *port, TLS_UART_CHSIZE_T charlength)
  177. {
  178. if (!port)
  179. return WM_FAILED;
  180. port->opts.charlength = charlength;
  181. port->regs->UR_LC &= ~ULCON_WL_MASK;
  182. if (charlength == TLS_UART_CHSIZE_5BIT)
  183. port->regs->UR_LC |= ULCON_WL5;
  184. else if (charlength == TLS_UART_CHSIZE_6BIT)
  185. port->regs->UR_LC |= ULCON_WL6;
  186. else if (charlength == TLS_UART_CHSIZE_7BIT)
  187. port->regs->UR_LC |= ULCON_WL7;
  188. else if (charlength == TLS_UART_CHSIZE_8BIT)
  189. port->regs->UR_LC |= ULCON_WL8;
  190. else
  191. return WM_FAILED;
  192. return WM_SUCCESS;
  193. }
  194. #if 0
  195. static TLS_UART_CHSIZE_T tls_uart_get_data_bits(struct tls_uart_port * port)
  196. {
  197. return port->opts.charlength;
  198. }
  199. #endif
  200. static int tls_uart_set_stop_bits_inside(struct tls_uart_port *port, TLS_UART_STOPBITS_T stopbits)
  201. {
  202. if (!port)
  203. return WM_FAILED;
  204. port->opts.stopbits = stopbits;
  205. if (stopbits == TLS_UART_TWO_STOPBITS)
  206. port->regs->UR_LC |= ULCON_STOP_2;
  207. else
  208. port->regs->UR_LC &= ~ULCON_STOP_2;
  209. return WM_SUCCESS;
  210. }
  211. #if 0
  212. static TLS_UART_STOPBITS_T tls_uart_get_stop_bits(struct tls_uart_port * port)
  213. {
  214. return port->opts.stopbits;
  215. }
  216. #endif
  217. static TLS_UART_STATUS_T tls_uart_set_flow_ctrl(struct tls_uart_port * port, TLS_UART_FLOW_CTRL_MODE_T flow_ctrl)
  218. {
  219. TLS_UART_STATUS_T status = TLS_UART_STATUS_OK;
  220. if (!port)
  221. return TLS_UART_STATUS_ERROR;
  222. // port->opts.flow_ctrl = flow_ctrl;
  223. // //不能在这里修改,为了配合透传和AT指令,软件会自己修改flowctrl配置,但是参数还是固定不变的
  224. //printf("\nport %d flow ctrl==%d\n",port->uart_no,flow_ctrl);
  225. switch (flow_ctrl)
  226. {
  227. case TLS_UART_FLOW_CTRL_NONE:
  228. port->regs->UR_FC = 0;
  229. break;
  230. case TLS_UART_FLOW_CTRL_HARDWARE:
  231. if (TLS_UART_FLOW_CTRL_HARDWARE == port->opts.flow_ctrl)
  232. {
  233. port->regs->UR_FC = (1UL << 0) | (6UL << 2);
  234. }
  235. break;
  236. default:
  237. return TLS_UART_STATUS_ERROR;
  238. }
  239. return status;
  240. }
  241. void tls_uart_set_fc_status(int uart_no, TLS_UART_FLOW_CTRL_MODE_T status)
  242. {
  243. struct tls_uart_port *port;
  244. port = &uart_port[uart_no];
  245. port->fcStatus = status;
  246. tls_uart_set_flow_ctrl(port, status);
  247. if (TLS_UART_FLOW_CTRL_HARDWARE == port->opts.flow_ctrl && 0 == status && port->hw_stopped) // 准备关闭流控时,发现tx已经停止,需要再打开tx
  248. {
  249. tls_uart_tx_enable(port);
  250. tls_uart_tx_chars(port);
  251. port->hw_stopped = 0;
  252. }
  253. }
  254. void tls_uart_rx_disable(struct tls_uart_port *port)
  255. {
  256. u32 ucon;
  257. ucon = port->regs->UR_LC;
  258. ucon &= ~ULCON_RX_EN;
  259. port->regs->UR_LC = ucon;
  260. }
  261. void tls_uart_rx_enable(struct tls_uart_port *port)
  262. {
  263. port->regs->UR_LC |= ULCON_RX_EN;
  264. }
  265. static void tls_uart_tx_disable(struct tls_uart_port *port)
  266. {
  267. u32 ucon;
  268. ucon = port->regs->UR_LC;
  269. ucon &= ~ULCON_TX_EN;
  270. port->regs->UR_LC = ucon;
  271. }
  272. static int tls_uart_config(struct tls_uart_port *port, struct tls_uart_options *opts)
  273. {
  274. if (NULL == port || NULL == opts)
  275. return WM_FAILED;
  276. tls_uart_set_baud_rate_inside(port, opts->baudrate);
  277. tls_uart_set_parity_inside(port, opts->paritytype);
  278. tls_uart_set_data_bits(port, opts->charlength);
  279. tls_uart_set_stop_bits_inside(port, opts->stopbits);
  280. port->opts.flow_ctrl = opts->flow_ctrl;
  281. tls_uart_set_flow_ctrl(port, opts->flow_ctrl);
  282. {
  283. /* clear interrupt */
  284. port->regs->UR_INTS = 0xFFFFFFFF;
  285. /* enable interupt */
  286. port->regs->UR_INTM = 0x0;
  287. port->regs->UR_DMAC = (4UL << UDMA_RX_FIFO_TIMEOUT_SHIFT) | UDMA_RX_FIFO_TIMEOUT;
  288. }
  289. /* config FIFO control */
  290. port->regs->UR_FIFOC = UFC_TX_FIFO_LVL_16_BYTE | UFC_RX_FIFO_LVL_16_BYTE |
  291. UFC_TX_FIFO_RESET | UFC_RX_FIFO_RESET;
  292. port->regs->UR_LC &= ~(ULCON_TX_EN | ULCON_RX_EN);
  293. port->regs->UR_LC |= ULCON_RX_EN | ULCON_TX_EN;
  294. return WM_SUCCESS;
  295. }
  296. /**
  297. * @brief handle a change of clear-to-send state
  298. * @param[in] port: uart_port structure for the open port
  299. * @param[in] status: new clear to send status, nonzero if active
  300. */
  301. static void uart_handle_cts_change(struct tls_uart_port *port, unsigned int status)
  302. {
  303. if (((1 == port->fcStatus)
  304. && (port->opts.flow_ctrl == TLS_UART_FLOW_CTRL_HARDWARE))
  305. && (port->uart_no == TLS_UART_1))
  306. {
  307. if (port->hw_stopped)
  308. {
  309. if (status)
  310. {
  311. port->hw_stopped = 0;
  312. tls_uart_tx_enable(port);
  313. tls_uart_tx_chars(port);
  314. }
  315. }
  316. else
  317. {
  318. if (!status)
  319. {
  320. port->hw_stopped = 1;
  321. tls_uart_tx_disable(port);
  322. }
  323. }
  324. }
  325. }
  326. static void uart_tx_finish_callback(void *arg)
  327. {
  328. if (arg)
  329. {
  330. tls_mem_free(arg);
  331. }
  332. }
  333. int tls_uart_tx_remain_len(struct tls_uart_port *port)
  334. {
  335. tls_uart_tx_msg_t *tx_msg = NULL;
  336. u16 buf_len = 0;
  337. u32 cpu_sr;
  338. cpu_sr = tls_os_set_critical();
  339. dl_list_for_each(tx_msg, &port->tx_msg_pending_list, tls_uart_tx_msg_t, list)
  340. {
  341. buf_len += tx_msg->buflen;
  342. }
  343. tls_os_release_critical(cpu_sr);
  344. return TLS_UART_TX_BUF_SIZE - buf_len;
  345. }
  346. /**
  347. * @brief This function is used to fill tx buffer.
  348. * @param[in] port: is the uart port.
  349. * @param[in] buf: is the user buffer.
  350. * @param[in] count: is the user data length
  351. * @retval
  352. */
  353. int tls_uart_fill_buf(struct tls_uart_port *port, char *buf, u32 count)
  354. {
  355. tls_uart_tx_msg_t *uart_tx_msg;
  356. int ret = 0;
  357. u32 cpu_sr;
  358. uart_tx_msg = tls_mem_alloc(sizeof(tls_uart_tx_msg_t));
  359. if (uart_tx_msg == NULL)
  360. {
  361. TLS_DBGPRT_ERR("mem err\n");
  362. return -1;
  363. }
  364. dl_list_init(&uart_tx_msg->list);
  365. uart_tx_msg->buf = tls_mem_alloc(count);
  366. if (uart_tx_msg->buf == NULL)
  367. {
  368. tls_mem_free(uart_tx_msg);
  369. TLS_DBGPRT_ERR("mem err 1 count=%d\n", count);
  370. return -1;
  371. }
  372. memcpy(uart_tx_msg->buf, buf, count);
  373. uart_tx_msg->buflen = count;
  374. uart_tx_msg->offset = 0;
  375. uart_tx_msg->finish_callback = uart_tx_finish_callback;
  376. uart_tx_msg->callback_arg = uart_tx_msg->buf;
  377. cpu_sr = tls_os_set_critical();
  378. dl_list_add_tail(&port->tx_msg_pending_list, &uart_tx_msg->list);
  379. tls_os_release_critical(cpu_sr);
  380. return ret;
  381. }
  382. /**
  383. * @brief free the data buffer has been transmitted.
  384. * @param[in] port: is the uart port.
  385. * @retval
  386. */
  387. s16 tls_uart_free_tx_sent_data(struct tls_uart_port *port)
  388. {
  389. tls_uart_tx_msg_t *tx_msg = NULL;
  390. u32 cpu_sr = tls_os_set_critical();
  391. while (!dl_list_empty(&port->tx_msg_to_be_freed_list))
  392. {
  393. tx_msg = dl_list_first(&port->tx_msg_to_be_freed_list, tls_uart_tx_msg_t, list);
  394. dl_list_del(&tx_msg->list);
  395. tls_os_release_critical(cpu_sr);
  396. if (tx_msg->buf != NULL)
  397. {
  398. if (tx_msg->finish_callback)
  399. tx_msg->finish_callback(tx_msg->callback_arg);
  400. tls_mem_free(tx_msg);
  401. }
  402. cpu_sr = tls_os_set_critical();
  403. }
  404. tls_os_release_critical(cpu_sr);
  405. return 0;
  406. }
  407. /**
  408. * @brief This function is used to start transfer data.
  409. * @param[in] port: is the uart port.
  410. * @retval
  411. */
  412. void tls_uart_tx_chars_start(struct tls_uart_port *port)
  413. {
  414. struct dl_list *pending_list = &port->tx_msg_pending_list;
  415. tls_uart_tx_msg_t *tx_msg = NULL;
  416. int tx_count;
  417. u32 cpu_sr;
  418. /* send some chars */
  419. tx_count = 32;
  420. cpu_sr = tls_os_set_critical();
  421. if (!dl_list_empty(pending_list))
  422. {
  423. tx_msg = dl_list_first(pending_list, tls_uart_tx_msg_t, list);
  424. while (tx_count-- > 0 && tx_msg->offset < tx_msg->buflen)
  425. {
  426. /* 检查tx fifo是否已满 */
  427. if ((port->regs->UR_FIFOS & UFS_TX_FIFO_CNT_MASK) ==
  428. port->tx_fifofull)
  429. {
  430. break;
  431. }
  432. port->regs->UR_TXW = tx_msg->buf[tx_msg->offset];
  433. tx_msg->offset++;
  434. port->icount.tx++;
  435. }
  436. if (tx_msg->offset >= tx_msg->buflen)
  437. {
  438. dl_list_del(&tx_msg->list);
  439. dl_list_add_tail(&port->tx_msg_to_be_freed_list, &tx_msg->list);
  440. tls_os_release_critical(cpu_sr);
  441. if (port->tx_sent_callback)
  442. port->tx_sent_callback(port);
  443. if (port->tx_callback)
  444. port->tx_callback(port);
  445. }else{
  446. tls_os_release_critical(cpu_sr);
  447. }
  448. }else{
  449. tls_os_release_critical(cpu_sr);
  450. }
  451. }
  452. void tls_set_uart_rx_status(int uart_no, int status)
  453. {
  454. u32 cpu_sr;
  455. struct tls_uart_port *port;
  456. if (TLS_UART_1 == uart_no)
  457. {
  458. port = &uart_port[1];
  459. if ((TLS_UART_RX_DISABLE == port->rxstatus
  460. && TLS_UART_RX_DISABLE == status)
  461. || (TLS_UART_RX_ENABLE == port->rxstatus
  462. && TLS_UART_RX_ENABLE == status))
  463. return;
  464. if (TLS_UART_RX_DISABLE == status)
  465. {
  466. if ((TLS_UART_FLOW_CTRL_HARDWARE == port->opts.flow_ctrl)
  467. && (TLS_UART_FLOW_CTRL_HARDWARE == port->fcStatus))
  468. {
  469. cpu_sr = tls_os_set_critical();
  470. // 锟斤拷rxfifo trigger level interrupt锟斤拷overrun error
  471. port->regs->UR_INTM |= ((0x1 << 2) | (0x01 << 8));
  472. port->rxstatus = TLS_UART_RX_DISABLE;
  473. tls_os_release_critical(cpu_sr);
  474. }
  475. }
  476. else
  477. {
  478. cpu_sr = tls_os_set_critical();
  479. uart_port[1].regs->UR_INTM &= ~((0x1 << 2) | (0x01 << 8));
  480. port->rxstatus = TLS_UART_RX_ENABLE;
  481. tls_os_release_critical(cpu_sr);
  482. }
  483. }
  484. }
  485. ATTRIBUTE_ISR void UART0_IRQHandler(void)
  486. {
  487. struct tls_uart_port *port = &uart_port[0];
  488. struct tls_uart_circ_buf *recv = &port->recv;
  489. u8 rx_byte_cb_flag = uart_rx_byte_cb_flag[0];
  490. u32 intr_src;
  491. u32 rx_fifocnt;
  492. u32 fifos;
  493. u8 ch;
  494. u32 rxlen = 0;
  495. csi_kernel_intrpt_enter();
  496. /* check interrupt status */
  497. intr_src = port->regs->UR_INTS;
  498. port->regs->UR_INTS = intr_src;
  499. if ((intr_src & UART_RX_INT_FLAG) && (0 == (port->regs->UR_INTM & UIS_RX_FIFO)))
  500. {
  501. rx_fifocnt = (port->regs->UR_FIFOS >> 6) & 0x3F;
  502. while (rx_fifocnt-- > 0)
  503. {
  504. ch = (u8) port->regs->UR_RXW;
  505. if (intr_src & UART_RX_ERR_INT_FLAG)
  506. {
  507. port->regs->UR_INTS |= UART_RX_ERR_INT_FLAG;
  508. TLS_DBGPRT_INFO("\nrx err=%x,c=%d,ch=%x\n", intr_src, rx_fifocnt, ch);
  509. /* not insert to buffer */
  510. continue;
  511. }
  512. if (CIRC_SPACE(recv->head, recv->tail, TLS_UART_RX_BUF_SIZE) <= 2)
  513. {
  514. TLS_DBGPRT_INFO("\nrx buf overrun int_src=%x\n", intr_src);
  515. if (TLS_UART_FLOW_CTRL_HARDWARE == port->fcStatus)
  516. {
  517. tls_set_uart_rx_status(port->uart_no, TLS_UART_RX_DISABLE);
  518. rx_fifocnt = 0; // 如果有硬件流控,关闭接收,把最后一个字符放进环形buffer中
  519. }
  520. else
  521. break;
  522. }
  523. /* insert the character into the buffer */
  524. recv->buf[recv->head] = ch;
  525. recv->head = (recv->head + 1) & (TLS_UART_RX_BUF_SIZE - 1);
  526. rxlen++;
  527. if(port->rx_callback != NULL && rx_byte_cb_flag)
  528. {
  529. port->rx_callback(1, port->priv_data);
  530. }
  531. }
  532. if (port->rx_callback != NULL && !rx_byte_cb_flag)
  533. {
  534. port->rx_callback(rxlen, port->priv_data);
  535. }
  536. }
  537. if (intr_src & UART_TX_INT_FLAG)
  538. {
  539. tls_uart_tx_chars(port);
  540. }
  541. if (intr_src & UIS_CTS_CHNG)
  542. {
  543. fifos = port->regs->UR_FIFOS;
  544. uart_handle_cts_change(port, fifos & UFS_CST_STS);
  545. }
  546. if (port->rx_callback != NULL && intr_src & UIS_RX_FIFO_TIMEOUT)
  547. {
  548. port->rx_callback(0, (void*)((int)port->priv_data+100));
  549. }
  550. csi_kernel_intrpt_exit();
  551. }
  552. void tls_uart_push(int index, u8* data, int length)
  553. {
  554. int i = 0;
  555. struct tls_uart_port *port = &uart_port[1];
  556. struct tls_uart_circ_buf *recv = &port->recv;
  557. while(i<length)
  558. {
  559. recv->buf[recv->head] = data[i];
  560. recv->head = (recv->head + 1) & (TLS_UART_RX_BUF_SIZE - 1);
  561. i++;
  562. }
  563. }
  564. ATTRIBUTE_ISR void UART1_IRQHandler(void)
  565. {
  566. struct tls_uart_port *port = &uart_port[1];
  567. struct tls_uart_circ_buf *recv = &port->recv;
  568. u8 rx_byte_cb_flag = uart_rx_byte_cb_flag[1];
  569. u32 intr_src;
  570. u32 rx_fifocnt;
  571. u32 fifos;
  572. u8 ch = 0;
  573. u8 escapefifocnt = 0;
  574. u32 rxlen = 0;
  575. csi_kernel_intrpt_enter();
  576. intr_src = port->regs->UR_INTS;
  577. port->regs->UR_INTS = intr_src;
  578. if (intr_src & UIS_OVERRUN)
  579. {
  580. port->regs->UR_INTS |= UIS_OVERRUN;
  581. if(port->tx_dma_on)
  582. {
  583. tls_reg_write32((int)&port->regs->UR_DMAC, (tls_reg_read32((int)&port->regs->UR_DMAC) & ~0x01));
  584. tls_reg_write32((int)&port->regs->UR_DMAC, (tls_reg_read32((int)&port->regs->UR_DMAC) | 0x01));
  585. }
  586. }
  587. if ((intr_src & UART_RX_INT_FLAG) && (0 == (port->regs->UR_INTM & UIS_RX_FIFO)))
  588. {
  589. rx_fifocnt = (port->regs->UR_FIFOS >> 6) & 0x3F;
  590. escapefifocnt = rx_fifocnt;
  591. port->plus_char_cnt = 0;
  592. rxlen = rx_fifocnt;
  593. if (CIRC_SPACE(recv->head, recv->tail, TLS_UART_RX_BUF_SIZE) <= RX_CACHE_LIMIT)
  594. {
  595. recv->tail = (recv->tail + RX_CACHE_LIMIT) & (TLS_UART_RX_BUF_SIZE - 1);
  596. }
  597. while (rx_fifocnt-- > 0)
  598. {
  599. ch = (u8) port->regs->UR_RXW;
  600. if (intr_src & UART_RX_ERR_INT_FLAG)
  601. {
  602. port->regs->UR_INTS |= UART_RX_ERR_INT_FLAG;
  603. TLS_DBGPRT_INFO("\nrx err=%x,c=%d,ch=%x\n", intr_src, rx_fifocnt, ch);
  604. continue;
  605. }
  606. recv->buf[recv->head] = ch;
  607. recv->head = (recv->head + 1) & (TLS_UART_RX_BUF_SIZE - 1);
  608. }
  609. if( escapefifocnt==3 && ch=='+')
  610. {
  611. switch(recv->head-1)
  612. {
  613. case 0:
  614. if(recv->buf[TLS_UART_RX_BUF_SIZE-1]=='+' && recv->buf[TLS_UART_RX_BUF_SIZE-2]=='+')
  615. port->plus_char_cnt = 3;
  616. break;
  617. case 1:
  618. if(recv->buf[0]=='+' && recv->buf[TLS_UART_RX_BUF_SIZE-1]=='+')
  619. port->plus_char_cnt = 3;
  620. break;
  621. default:
  622. if(recv->buf[recv->head-2]=='+' && recv->buf[recv->head-3]=='+')
  623. port->plus_char_cnt = 3;
  624. break;
  625. }
  626. if(port->rx_callback != NULL && rx_byte_cb_flag)
  627. {
  628. port->rx_callback(1, port->priv_data);
  629. }
  630. }
  631. if (port->rx_callback!=NULL && !rx_byte_cb_flag)
  632. {
  633. port->rx_callback(rxlen, port->priv_data);
  634. }
  635. }
  636. if (intr_src & UART_TX_INT_FLAG)
  637. {
  638. tls_uart_tx_chars(port);
  639. }
  640. if (intr_src & UIS_CTS_CHNG)
  641. {
  642. fifos = port->regs->UR_FIFOS;
  643. uart_handle_cts_change(port, fifos & UFS_CST_STS);
  644. }
  645. if (port->rx_callback != NULL && intr_src & UIS_RX_FIFO_TIMEOUT)
  646. {
  647. port->rx_callback(0, (void*)((int)port->priv_data+100));
  648. }
  649. csi_kernel_intrpt_exit();
  650. }
  651. static int findOutIntUart(void)
  652. {
  653. int i;
  654. u32 regValue;
  655. for( i=TLS_UART_2; i< TLS_UART_MAX; i++ )
  656. {
  657. regValue = tls_reg_read32(HR_UART0_INT_SRC + i*STEP_SIZE);
  658. regValue &= 0x1FF;
  659. if( regValue )
  660. break;
  661. }
  662. return i;
  663. }
  664. ATTRIBUTE_ISR void UART2_4_IRQHandler(void)
  665. {
  666. int intUartNum = findOutIntUart();
  667. struct tls_uart_port *port = &uart_port[intUartNum];
  668. struct tls_uart_circ_buf *recv = &port->recv;
  669. u8 rx_byte_cb_flag = uart_rx_byte_cb_flag[intUartNum];
  670. u32 intr_src;
  671. u32 rx_fifocnt;
  672. u32 fifos;
  673. u8 escapefifocnt = 0;
  674. u32 rxlen = 0;
  675. u8 ch = 0;
  676. csi_kernel_intrpt_enter();
  677. intr_src = port->regs->UR_INTS;
  678. if (intr_src & UIS_OVERRUN)
  679. {
  680. port->regs->UR_INTS |= UIS_OVERRUN;
  681. if(port->tx_dma_on)
  682. {
  683. tls_reg_write32((int)&port->regs->UR_DMAC, (tls_reg_read32((int)&port->regs->UR_DMAC) & ~0x01));
  684. tls_reg_write32((int)&port->regs->UR_DMAC, (tls_reg_read32((int)&port->regs->UR_DMAC) | 0x01));
  685. }
  686. }
  687. if ((intr_src & UART_RX_INT_FLAG) && (0 == (port->regs->UR_INTM & UIS_RX_FIFO)))
  688. {
  689. rx_fifocnt = (port->regs->UR_FIFOS >> 6) & 0x3F;
  690. escapefifocnt = rx_fifocnt;
  691. port->plus_char_cnt = 0;
  692. rxlen = rx_fifocnt;
  693. if (CIRC_SPACE(recv->head, recv->tail, TLS_UART_RX_BUF_SIZE) <= RX_CACHE_LIMIT)
  694. {
  695. recv->tail = (recv->tail + RX_CACHE_LIMIT) & (TLS_UART_RX_BUF_SIZE - 1);
  696. }
  697. while (rx_fifocnt-- > 0)
  698. {
  699. ch = (u8) port->regs->UR_RXW;
  700. if (intr_src & UART_RX_ERR_INT_FLAG)
  701. {
  702. port->regs->UR_INTS |= UART_RX_ERR_INT_FLAG;
  703. //TLS_DBGPRT_INFO("\nrx err=%x,c=%d,ch=%x\n", intr_src, rx_fifocnt, ch);
  704. continue;
  705. }
  706. recv->buf[recv->head] = ch;
  707. recv->head = (recv->head + 1) & (TLS_UART_RX_BUF_SIZE - 1);
  708. }
  709. if( escapefifocnt==3 && ch=='+')
  710. {
  711. switch(recv->head-1)
  712. {
  713. case 0:
  714. if(recv->buf[TLS_UART_RX_BUF_SIZE-1]=='+' && recv->buf[TLS_UART_RX_BUF_SIZE-2]=='+')
  715. port->plus_char_cnt = 3;
  716. break;
  717. case 1:
  718. if(recv->buf[0]=='+' && recv->buf[TLS_UART_RX_BUF_SIZE-1]=='+')
  719. port->plus_char_cnt = 3;
  720. break;
  721. default:
  722. if(recv->buf[recv->head-2]=='+' && recv->buf[recv->head-3]=='+')
  723. port->plus_char_cnt = 3;
  724. break;
  725. }
  726. if(port->rx_callback != NULL && rx_byte_cb_flag)
  727. {
  728. port->rx_callback(1, port->priv_data);
  729. }
  730. }
  731. if (port->rx_callback!=NULL && !rx_byte_cb_flag)
  732. {
  733. port->rx_callback(rxlen, port->priv_data);
  734. }
  735. }
  736. if (intr_src & UART_TX_INT_FLAG)
  737. {
  738. tls_uart_tx_chars(port);
  739. }
  740. if (intr_src & UIS_CTS_CHNG)
  741. {
  742. fifos = port->regs->UR_FIFOS;
  743. uart_handle_cts_change(port, fifos & UFS_CST_STS);
  744. }
  745. if (port->rx_callback != NULL && intr_src & UIS_RX_FIFO_TIMEOUT)
  746. {
  747. port->rx_callback(0, (void*)((int)port->priv_data+100));
  748. }
  749. port->regs->UR_INTS = intr_src;
  750. csi_kernel_intrpt_exit();
  751. }
  752. /**
  753. * @brief This function is used to initial uart port.
  754. *
  755. * @param[in] uart_no: is the uart number.
  756. * - \ref TLS_UART_0 TLS_UART_1 TLS_UART_2 TLS_UART_3 TLS_UART_4 TLS_UART5
  757. * @param[in] opts: is the uart setting options,if this param is NULL,this function will use the default options.
  758. * @param[in] modeChoose:; choose uart2 mode or 7816 mode when uart_no is TLS_UART_2, 0 for uart2 mode and 1 for 7816 mode.
  759. *
  760. * @retval
  761. * - \ref WM_SUCCESS
  762. * - \ref WM_FAILED
  763. *
  764. * @note When the system is initialized, the function has been called, so users can not call the function.
  765. */
  766. int tls_uart_port_init(u16 uart_no, tls_uart_options_t * opts, u8 modeChoose)
  767. {
  768. struct tls_uart_port *port;
  769. int ret;
  770. char *bufrx; // ,*buftx
  771. tls_uart_options_t opt;
  772. if (TLS_UART_MAX <= uart_no)
  773. {
  774. return WM_FAILED;
  775. }
  776. switch( uart_no )
  777. {
  778. case TLS_UART_0:
  779. case TLS_UART_1:
  780. tls_irq_disable((UART0_IRQn+uart_no));
  781. break;
  782. case TLS_UART_2:
  783. case TLS_UART_3:
  784. case TLS_UART_4:
  785. case TLS_UART_5:
  786. tls_irq_disable(UART24_IRQn);
  787. break;
  788. }
  789. UartRegInit(uart_no);
  790. if (uart_port[uart_no].recv.buf)
  791. {
  792. tls_mem_free((void *)uart_port[uart_no].recv.buf);
  793. uart_port[uart_no].recv.buf = NULL;
  794. }
  795. memset(&uart_port[uart_no], 0, sizeof(struct tls_uart_port));
  796. port = &uart_port[uart_no];
  797. port->regs = (TLS_UART_REGS_T *)(HR_UART0_BASE_ADDR + uart_no*STEP_SIZE);
  798. if( uart_no==TLS_UART_2 )
  799. {
  800. (modeChoose == 1)?(port->regs->UR_LC |= (1 << 24)):(port->regs->UR_LC &= ~(0x1000000));
  801. }
  802. port->uart_no = uart_no;
  803. if (NULL == opts)
  804. {
  805. opt.baudrate = UART_BAUDRATE_B115200;
  806. opt.charlength = TLS_UART_CHSIZE_8BIT;
  807. opt.flow_ctrl = TLS_UART_FLOW_CTRL_NONE;
  808. opt.paritytype = TLS_UART_PMODE_DISABLED;
  809. opt.stopbits = TLS_UART_ONE_STOPBITS;
  810. ret = tls_uart_config(port, &opt);
  811. }
  812. else
  813. {
  814. ret = tls_uart_config(port, opts);
  815. }
  816. if (ret != WM_SUCCESS)
  817. return WM_FAILED;
  818. port->rxstatus = TLS_UART_RX_ENABLE;
  819. switch( uart_no )
  820. {
  821. case TLS_UART_0:
  822. case TLS_UART_1:
  823. port->uart_irq_no = (UART0_IRQn+uart_no);
  824. break;
  825. case TLS_UART_2:
  826. case TLS_UART_3:
  827. case TLS_UART_4:
  828. case TLS_UART_5:
  829. port->uart_irq_no = UART24_IRQn;
  830. break;
  831. }
  832. if (port->recv.buf == NULL)
  833. {
  834. bufrx = tls_mem_alloc(TLS_UART_RX_BUF_SIZE);
  835. if (!bufrx)
  836. return WM_FAILED;
  837. memset(bufrx, 0, TLS_UART_RX_BUF_SIZE);
  838. port->recv.buf = (u8 *) bufrx;
  839. }
  840. port->recv.head = 0;
  841. port->recv.tail = 0;
  842. port->tx_fifofull = 16;
  843. dl_list_init(&port->tx_msg_pending_list);
  844. dl_list_init(&port->tx_msg_to_be_freed_list);
  845. tls_uart_tx_callback_register(uart_no, tls_uart_free_tx_sent_data);
  846. tls_irq_enable(port->uart_irq_no); /* enable uart interrupt */
  847. return WM_SUCCESS;
  848. }
  849. /**
  850. * @brief This function is used to register uart rx interrupt.
  851. *
  852. * @param[in] uart_no: is the uart numer.
  853. * @param[in] callback: is the uart rx interrupt call back function.
  854. *
  855. * @retval
  856. *
  857. * @note This function should be called after the fucntion tls_uart_port_init() or it won't work.
  858. */
  859. void tls_uart_rx_callback_register(u16 uart_no, s16(*rx_callback) (u16 len, void* user_data), void *priv_data)
  860. {
  861. uart_port[uart_no].rx_callback = rx_callback;
  862. uart_port[uart_no].priv_data = priv_data;
  863. }
  864. void tls_uart_rx_byte_callback_flag(u16 uart_no, u8 flag)
  865. {
  866. uart_rx_byte_cb_flag[uart_no] = flag;
  867. }
  868. /**
  869. * @brief This function is used to register uart tx interrupt.
  870. *
  871. * @param[in] uart_no: is the uart numer.
  872. * @param[in] callback: is the uart tx interrupt call back function.
  873. *
  874. * @retval
  875. */
  876. void tls_uart_tx_callback_register(u16 uart_no, s16(*tx_callback) (struct tls_uart_port *port))
  877. {
  878. uart_port[uart_no].tx_callback = tx_callback;
  879. }
  880. void tls_uart_tx_sent_callback_register(u16 uart_no, s16(*tx_callback) (struct tls_uart_port *port))
  881. {
  882. uart_port[uart_no].tx_sent_callback = tx_callback;
  883. }
  884. int tls_uart_try_read(u16 uart_no, int32_t read_size)
  885. {
  886. int data_cnt = 0;
  887. struct tls_uart_port *port = NULL;
  888. struct tls_uart_circ_buf *recv;
  889. port = &uart_port[uart_no];
  890. recv = &port->recv;
  891. data_cnt = CIRC_CNT(recv->head, recv->tail, TLS_UART_RX_BUF_SIZE);
  892. if(data_cnt >= read_size)
  893. {
  894. return read_size;
  895. }else
  896. {
  897. return 0;
  898. }
  899. }
  900. /**
  901. * @brief This function is used to copy circular buffer data to user buffer.
  902. * @param[in] uart_no: is the uart numer.
  903. * @param[in] buf: is the user buffer.
  904. * @param[in] readsize: is the user read size.
  905. * @retval
  906. */
  907. int tls_uart_read(u16 uart_no, u8 * buf, u16 readsize)
  908. {
  909. int data_cnt, buflen, bufcopylen;
  910. struct tls_uart_port *port = NULL;
  911. struct tls_uart_circ_buf *recv;
  912. if (NULL == buf || readsize < 1)
  913. {
  914. return WM_FAILED;
  915. }
  916. port = &uart_port[uart_no];
  917. recv = &port->recv;
  918. data_cnt = CIRC_CNT(recv->head, recv->tail, TLS_UART_RX_BUF_SIZE);
  919. (data_cnt >= readsize)?(buflen = readsize):(buflen = data_cnt);
  920. if ((recv->tail + buflen) > TLS_UART_RX_BUF_SIZE)
  921. {
  922. bufcopylen = (TLS_UART_RX_BUF_SIZE - recv->tail);
  923. MEMCPY(buf, (void *)(recv->buf + recv->tail), bufcopylen);
  924. MEMCPY(buf + bufcopylen, (void *)recv->buf, buflen - bufcopylen);
  925. }
  926. else
  927. {
  928. MEMCPY(buf, (void *)(recv->buf + recv->tail), buflen);
  929. }
  930. recv->tail = (recv->tail + buflen) & (TLS_UART_RX_BUF_SIZE - 1);
  931. return buflen;
  932. }
  933. /**
  934. * @brief This function is used to transfer data throuth DMA.
  935. *
  936. * @param[in] buf is a buf for saving user data
  937. * @param[in] writesize is the user data length
  938. * @param[in] cmpl_callback function point,when the transfer is completed, the function will be called.
  939. *
  940. * @retval WM_SUCCESS success
  941. * @retval WM_FAILED failed
  942. *
  943. * @note Only uart1 support DMA transfer.
  944. */
  945. int tls_uart_dma_write(char *buf, u16 writesize, void (*cmpl_callback) (void *p), u16 uart_no)
  946. {
  947. unsigned char dmaCh = 0;
  948. struct tls_dma_descriptor DmaDesc;
  949. struct tls_uart_port *port = &uart_port[uart_no];
  950. if (NULL == buf || writesize < 1 || writesize >= 4096)
  951. {
  952. TLS_DBGPRT_ERR("param err\n");
  953. return WM_FAILED;
  954. }
  955. if (port->tx_dma_on)
  956. {
  957. TLS_DBGPRT_ERR("transmiting,wait\n");
  958. return WM_FAILED;
  959. }
  960. tls_reg_write32(HR_DMA_CHNL_SEL, uart_no);
  961. /* Request DMA Channel */
  962. dmaCh = tls_dma_request(2, TLS_DMA_FLAGS_CHANNEL_SEL(TLS_DMA_SEL_UART_TX) | TLS_DMA_FLAGS_HARD_MODE);
  963. if (dmaCh == 0xFF)
  964. {
  965. TLS_DBGPRT_ERR("dma request err\n");
  966. return WM_FAILED;
  967. }
  968. tls_reg_write32((int)&port->regs->UR_DMAC, (tls_reg_read32((int)&port->regs->UR_DMAC) & ~0x01));
  969. tls_dma_irq_register(dmaCh, cmpl_callback, (void *)(u32)uart_no, TLS_DMA_IRQ_TRANSFER_DONE);
  970. DmaDesc.src_addr = (int) buf;
  971. DmaDesc.dest_addr = (int)&port->regs->UR_TXW;
  972. DmaDesc.dma_ctrl = TLS_DMA_DESC_CTRL_SRC_ADD_INC | TLS_DMA_DESC_CTRL_DATA_SIZE_BYTE | (writesize << 7);
  973. DmaDesc.valid = TLS_DMA_DESC_VALID;
  974. DmaDesc.next = NULL;
  975. tls_dma_start(dmaCh, &DmaDesc, 0);
  976. /* Enable uart TX DMA */
  977. port->tx_dma_on = TRUE;
  978. tls_reg_write32((int)&port->regs->UR_DMAC, (tls_reg_read32((int)&port->regs->UR_DMAC) | 0x01));
  979. tls_reg_write32(HR_DMA_INT_MASK, (tls_reg_read32(HR_DMA_INT_MASK) & ~(0x01 << 5)));
  980. /* enable dma interrupt */
  981. tls_irq_enable(DMA_Channel2_IRQn);
  982. return WM_SUCCESS;
  983. }
  984. /**
  985. * @brief This function is used to transfer data asynchronous.
  986. *
  987. * @param[in] uart_no is the uart number
  988. * @param[in] buf is a buf for saving user data.
  989. * @param[in] writesize is the data length
  990. *
  991. * @retval WM_SUCCESS success
  992. * @retval WM_FAILED failed
  993. *
  994. * @note The function only start transmission, fill buffer in the callback function.
  995. */
  996. int tls_uart_write_async(u16 uart_no, char *buf, u16 writesize)
  997. {
  998. struct tls_uart_port *port = NULL;
  999. int ret;
  1000. if (NULL == buf || writesize < 1)
  1001. {
  1002. TLS_DBGPRT_ERR("param err\n");
  1003. return WM_FAILED;
  1004. }
  1005. port = &uart_port[uart_no];
  1006. ret = tls_uart_fill_buf(port, buf, writesize);
  1007. if (0 == ret)
  1008. {
  1009. tls_uart_tx_chars_start(port);
  1010. }
  1011. return ret;
  1012. }
  1013. /**
  1014. * @brief get the data length has been transmitted.
  1015. *
  1016. * @param[in] uart_no is the uart number
  1017. *
  1018. * @retval the length has been transmitted
  1019. *
  1020. */
  1021. int tls_uart_tx_length(u16 uart_no)
  1022. {
  1023. struct tls_uart_port *port = &uart_port[uart_no];
  1024. return port->icount.tx;
  1025. }
  1026. /**
  1027. * @brief This function is used to transfer data synchronous.
  1028. *
  1029. * @param[in] uart_no is the uart number
  1030. * @param[in] buf is a buf for saving user data.
  1031. * @param[in] writesize is the data length
  1032. *
  1033. * @retval WM_SUCCESS success
  1034. * @retval WM_FAILED failed
  1035. *
  1036. * @note The function only start transmission, fill buffer in the callback function.
  1037. */
  1038. int tls_uart_write(u16 uart_no, char *buf, u16 writesize)
  1039. {
  1040. return tls_uart_write_async(uart_no, buf, writesize);
  1041. }
  1042. /**
  1043. * @brief This function is used to set uart parity.
  1044. *
  1045. * @param[in] paritytype is a parity type defined in TLS_UART_PMODE_T
  1046. *
  1047. * @retval WM_SUCCESS success
  1048. * @retval WM_FAILED failed
  1049. *
  1050. */
  1051. int tls_uart_set_parity(u16 uart_no, TLS_UART_PMODE_T paritytype)
  1052. {
  1053. return tls_uart_set_parity_inside(&uart_port[uart_no], paritytype);
  1054. }
  1055. /**
  1056. * @brief This function is used to set uart baudrate.
  1057. *
  1058. * @param[in] uart_no is the uart number
  1059. * @param[in] baudrate is the baudrate user want used,the unit is HZ.
  1060. *
  1061. * @retval WM_SUCCESS success
  1062. * @retval WM_FAILED failed
  1063. *
  1064. */
  1065. int tls_uart_set_baud_rate(u16 uart_no, u32 baudrate)
  1066. {
  1067. return tls_uart_set_baud_rate_inside(&uart_port[uart_no], baudrate);
  1068. }
  1069. /**
  1070. * @brief This function is used to set uart stop bits.
  1071. *
  1072. * @param[in] uart_no is the uart number
  1073. * @param[in] stopbits is a stop bit type defined in TLS_UART_STOPBITS_T.
  1074. *
  1075. * @retval WM_SUCCESS success
  1076. * @retval WM_FAILED failed
  1077. *
  1078. */
  1079. int tls_uart_set_stop_bits(u16 uart_no, TLS_UART_STOPBITS_T stopbits)
  1080. {
  1081. return tls_uart_set_stop_bits_inside(&uart_port[uart_no], stopbits);
  1082. }
  1083. int tls_uart_dma_off(u16 uart_no)
  1084. {
  1085. uart_port[uart_no].tx_dma_on = FALSE;
  1086. return WM_SUCCESS;
  1087. }
  1088. #endif
  1089. //TLS_CONFIG_UART