wm_uart.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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���ã����Dz������ǹ̶������
  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 (intr_src & UIS_RX_FIFO_TIMEOUT)
  547. {
  548. port->rx_callback(0, (void*)((int)port->priv_data*10));
  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 (intr_src & UIS_RX_FIFO_TIMEOUT)
  646. {
  647. port->rx_callback(0, (void*)((int)port->priv_data*10));
  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. u32 intr_src;
  670. u32 rx_fifocnt;
  671. u32 fifos;
  672. u32 rxlen = 0;
  673. u8 ch;
  674. csi_kernel_intrpt_enter();
  675. intr_src = port->regs->UR_INTS;
  676. if (intr_src & UIS_OVERRUN)
  677. {
  678. port->regs->UR_INTS |= UIS_OVERRUN;
  679. if(port->tx_dma_on)
  680. {
  681. tls_reg_write32((int)&port->regs->UR_DMAC, (tls_reg_read32((int)&port->regs->UR_DMAC) & ~0x01));
  682. tls_reg_write32((int)&port->regs->UR_DMAC, (tls_reg_read32((int)&port->regs->UR_DMAC) | 0x01));
  683. }
  684. }
  685. if ((intr_src & UART_RX_INT_FLAG) && (0 == (port->regs->UR_INTM & UIS_RX_FIFO)))
  686. {
  687. rx_fifocnt = (port->regs->UR_FIFOS >> 6) & 0x3F;
  688. while (rx_fifocnt-- > 0)
  689. {
  690. ch = (u8) port->regs->UR_RXW;
  691. if (intr_src & UART_RX_ERR_INT_FLAG)
  692. {
  693. port->regs->UR_INTS |= UART_RX_ERR_INT_FLAG;
  694. continue; /* not insert to buffer */
  695. }
  696. if (CIRC_SPACE(recv->head, recv->tail, TLS_UART_RX_BUF_SIZE) <= 2)
  697. {
  698. if (TLS_UART_FLOW_CTRL_HARDWARE == port->fcStatus)
  699. {
  700. tls_set_uart_rx_status(port->uart_no, TLS_UART_RX_DISABLE);
  701. rx_fifocnt = 0; // �����Ӳ�����أ��رս��գ������һ���ַ��Ž�����buffer��
  702. }
  703. else
  704. break;
  705. }
  706. recv->buf[recv->head] = ch;
  707. recv->head = (recv->head + 1) & (TLS_UART_RX_BUF_SIZE - 1);
  708. rxlen++;
  709. }
  710. if(port->rx_callback != NULL && rxlen)
  711. {
  712. port->rx_callback(rxlen, port->priv_data);
  713. }
  714. }
  715. if (intr_src & UART_TX_INT_FLAG)
  716. {
  717. tls_uart_tx_chars(port);
  718. }
  719. if (intr_src & UIS_CTS_CHNG)
  720. {
  721. fifos = port->regs->UR_FIFOS;
  722. uart_handle_cts_change(port, fifos & UFS_CST_STS);
  723. }
  724. if (intr_src & UIS_RX_FIFO_TIMEOUT)
  725. {
  726. port->rx_callback(0, (void*)((int)port->priv_data*10));
  727. }
  728. port->regs->UR_INTS = intr_src;
  729. csi_kernel_intrpt_exit();
  730. }
  731. /**
  732. * @brief This function is used to initial uart port.
  733. *
  734. * @param[in] uart_no: is the uart number.
  735. * - \ref TLS_UART_0 TLS_UART_1 TLS_UART_2 TLS_UART_3 TLS_UART_4 TLS_UART5
  736. * @param[in] opts: is the uart setting options,if this param is NULL,this function will use the default options.
  737. * @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.
  738. *
  739. * @retval
  740. * - \ref WM_SUCCESS
  741. * - \ref WM_FAILED
  742. *
  743. * @note When the system is initialized, the function has been called, so users can not call the function.
  744. */
  745. int tls_uart_port_init(u16 uart_no, tls_uart_options_t * opts, u8 modeChoose)
  746. {
  747. struct tls_uart_port *port;
  748. int ret;
  749. char *bufrx; // ,*buftx
  750. tls_uart_options_t opt;
  751. if (TLS_UART_MAX <= uart_no)
  752. {
  753. return WM_FAILED;
  754. }
  755. switch( uart_no )
  756. {
  757. case TLS_UART_0:
  758. case TLS_UART_1:
  759. tls_irq_disable((UART0_IRQn+uart_no));
  760. break;
  761. case TLS_UART_2:
  762. case TLS_UART_3:
  763. case TLS_UART_4:
  764. case TLS_UART_5:
  765. tls_irq_disable(UART24_IRQn);
  766. break;
  767. }
  768. UartRegInit(uart_no);
  769. if (uart_port[uart_no].recv.buf)
  770. {
  771. tls_mem_free((void *)uart_port[uart_no].recv.buf);
  772. uart_port[uart_no].recv.buf = NULL;
  773. }
  774. memset(&uart_port[uart_no], 0, sizeof(struct tls_uart_port));
  775. port = &uart_port[uart_no];
  776. port->regs = (TLS_UART_REGS_T *)(HR_UART0_BASE_ADDR + uart_no*STEP_SIZE);
  777. if( uart_no==TLS_UART_2 )
  778. {
  779. (modeChoose == 1)?(port->regs->UR_LC |= (1 << 24)):(port->regs->UR_LC &= ~(0x1000000));
  780. }
  781. port->uart_no = uart_no;
  782. if (NULL == opts)
  783. {
  784. opt.baudrate = UART_BAUDRATE_B115200;
  785. opt.charlength = TLS_UART_CHSIZE_8BIT;
  786. opt.flow_ctrl = TLS_UART_FLOW_CTRL_NONE;
  787. opt.paritytype = TLS_UART_PMODE_DISABLED;
  788. opt.stopbits = TLS_UART_ONE_STOPBITS;
  789. ret = tls_uart_config(port, &opt);
  790. }
  791. else
  792. {
  793. ret = tls_uart_config(port, opts);
  794. }
  795. if (ret != WM_SUCCESS)
  796. return WM_FAILED;
  797. port->rxstatus = TLS_UART_RX_ENABLE;
  798. switch( uart_no )
  799. {
  800. case TLS_UART_0:
  801. case TLS_UART_1:
  802. port->uart_irq_no = (UART0_IRQn+uart_no);
  803. break;
  804. case TLS_UART_2:
  805. case TLS_UART_3:
  806. case TLS_UART_4:
  807. case TLS_UART_5:
  808. port->uart_irq_no = UART24_IRQn;
  809. break;
  810. }
  811. if (port->recv.buf == NULL)
  812. {
  813. bufrx = tls_mem_alloc(TLS_UART_RX_BUF_SIZE);
  814. if (!bufrx)
  815. return WM_FAILED;
  816. memset(bufrx, 0, TLS_UART_RX_BUF_SIZE);
  817. port->recv.buf = (u8 *) bufrx;
  818. }
  819. port->recv.head = 0;
  820. port->recv.tail = 0;
  821. port->tx_fifofull = 16;
  822. dl_list_init(&port->tx_msg_pending_list);
  823. dl_list_init(&port->tx_msg_to_be_freed_list);
  824. tls_uart_tx_callback_register(uart_no, tls_uart_free_tx_sent_data);
  825. tls_irq_enable(port->uart_irq_no); /* enable uart interrupt */
  826. return WM_SUCCESS;
  827. }
  828. /**
  829. * @brief This function is used to register uart rx interrupt.
  830. *
  831. * @param[in] uart_no: is the uart numer.
  832. * @param[in] callback: is the uart rx interrupt call back function.
  833. *
  834. * @retval
  835. *
  836. * @note This function should be called after the fucntion tls_uart_port_init() or it won't work.
  837. */
  838. void tls_uart_rx_callback_register(u16 uart_no, s16(*rx_callback) (u16 len, void* user_data), void *priv_data)
  839. {
  840. uart_port[uart_no].rx_callback = rx_callback;
  841. uart_port[uart_no].priv_data = priv_data;
  842. }
  843. void tls_uart_rx_byte_callback_flag(u16 uart_no, u8 flag)
  844. {
  845. uart_rx_byte_cb_flag[uart_no] = flag;
  846. }
  847. /**
  848. * @brief This function is used to register uart tx interrupt.
  849. *
  850. * @param[in] uart_no: is the uart numer.
  851. * @param[in] callback: is the uart tx interrupt call back function.
  852. *
  853. * @retval
  854. */
  855. void tls_uart_tx_callback_register(u16 uart_no, s16(*tx_callback) (struct tls_uart_port *port))
  856. {
  857. uart_port[uart_no].tx_callback = tx_callback;
  858. }
  859. void tls_uart_tx_sent_callback_register(u16 uart_no, s16(*tx_callback) (struct tls_uart_port *port))
  860. {
  861. uart_port[uart_no].tx_sent_callback = tx_callback;
  862. }
  863. int tls_uart_try_read(u16 uart_no, int32_t read_size)
  864. {
  865. int data_cnt = 0;
  866. struct tls_uart_port *port = NULL;
  867. struct tls_uart_circ_buf *recv;
  868. port = &uart_port[uart_no];
  869. recv = &port->recv;
  870. data_cnt = CIRC_CNT(recv->head, recv->tail, TLS_UART_RX_BUF_SIZE);
  871. if(data_cnt >= read_size)
  872. {
  873. return read_size;
  874. }else
  875. {
  876. return 0;
  877. }
  878. }
  879. /**
  880. * @brief This function is used to copy circular buffer data to user buffer.
  881. * @param[in] uart_no: is the uart numer.
  882. * @param[in] buf: is the user buffer.
  883. * @param[in] readsize: is the user read size.
  884. * @retval
  885. */
  886. int tls_uart_read(u16 uart_no, u8 * buf, u16 readsize)
  887. {
  888. int data_cnt, buflen, bufcopylen;
  889. struct tls_uart_port *port = NULL;
  890. struct tls_uart_circ_buf *recv;
  891. if (NULL == buf || readsize < 1)
  892. {
  893. return WM_FAILED;
  894. }
  895. port = &uart_port[uart_no];
  896. recv = &port->recv;
  897. data_cnt = CIRC_CNT(recv->head, recv->tail, TLS_UART_RX_BUF_SIZE);
  898. (data_cnt >= readsize)?(buflen = readsize):(buflen = data_cnt);
  899. if ((recv->tail + buflen) > TLS_UART_RX_BUF_SIZE)
  900. {
  901. bufcopylen = (TLS_UART_RX_BUF_SIZE - recv->tail);
  902. MEMCPY(buf, (void *)(recv->buf + recv->tail), bufcopylen);
  903. MEMCPY(buf + bufcopylen, (void *)recv->buf, buflen - bufcopylen);
  904. }
  905. else
  906. {
  907. MEMCPY(buf, (void *)(recv->buf + recv->tail), buflen);
  908. }
  909. recv->tail = (recv->tail + buflen) & (TLS_UART_RX_BUF_SIZE - 1);
  910. return buflen;
  911. }
  912. /**
  913. * @brief This function is used to transfer data throuth DMA.
  914. *
  915. * @param[in] buf is a buf for saving user data
  916. * @param[in] writesize is the user data length
  917. * @param[in] cmpl_callback function point,when the transfer is completed, the function will be called.
  918. *
  919. * @retval WM_SUCCESS success
  920. * @retval WM_FAILED failed
  921. *
  922. * @note Only uart1 support DMA transfer.
  923. */
  924. int tls_uart_dma_write(char *buf, u16 writesize, void (*cmpl_callback) (void *p), u16 uart_no)
  925. {
  926. unsigned char dmaCh = 0;
  927. struct tls_dma_descriptor DmaDesc;
  928. struct tls_uart_port *port = &uart_port[uart_no];
  929. if (NULL == buf || writesize < 1 || writesize >= 4096)
  930. {
  931. TLS_DBGPRT_ERR("param err\n");
  932. return WM_FAILED;
  933. }
  934. if (port->tx_dma_on)
  935. {
  936. TLS_DBGPRT_ERR("transmiting,wait\n");
  937. return WM_FAILED;
  938. }
  939. tls_reg_write32(HR_DMA_CHNL_SEL, uart_no);
  940. /* Request DMA Channel */
  941. dmaCh = tls_dma_request(2, TLS_DMA_FLAGS_CHANNEL_SEL(TLS_DMA_SEL_UART_TX) | TLS_DMA_FLAGS_HARD_MODE);
  942. if (dmaCh == 0xFF)
  943. {
  944. TLS_DBGPRT_ERR("dma request err\n");
  945. return WM_FAILED;
  946. }
  947. tls_reg_write32((int)&port->regs->UR_DMAC, (tls_reg_read32((int)&port->regs->UR_DMAC) & ~0x01));
  948. tls_dma_irq_register(dmaCh, cmpl_callback, (void *)(u32)uart_no, TLS_DMA_IRQ_TRANSFER_DONE);
  949. DmaDesc.src_addr = (int) buf;
  950. DmaDesc.dest_addr = (int)&port->regs->UR_TXW;
  951. DmaDesc.dma_ctrl = TLS_DMA_DESC_CTRL_SRC_ADD_INC | TLS_DMA_DESC_CTRL_DATA_SIZE_BYTE | (writesize << 7);
  952. DmaDesc.valid = TLS_DMA_DESC_VALID;
  953. DmaDesc.next = NULL;
  954. tls_dma_start(dmaCh, &DmaDesc, 0);
  955. /* Enable uart TX DMA */
  956. port->tx_dma_on = TRUE;
  957. tls_reg_write32((int)&port->regs->UR_DMAC, (tls_reg_read32((int)&port->regs->UR_DMAC) | 0x01));
  958. tls_reg_write32(HR_DMA_INT_MASK, (tls_reg_read32(HR_DMA_INT_MASK) & ~(0x01 << 5)));
  959. /* enable dma interrupt */
  960. tls_irq_enable(DMA_Channel2_IRQn);
  961. return WM_SUCCESS;
  962. }
  963. /**
  964. * @brief This function is used to transfer data asynchronous.
  965. *
  966. * @param[in] uart_no is the uart number
  967. * @param[in] buf is a buf for saving user data.
  968. * @param[in] writesize is the data length
  969. *
  970. * @retval WM_SUCCESS success
  971. * @retval WM_FAILED failed
  972. *
  973. * @note The function only start transmission, fill buffer in the callback function.
  974. */
  975. int tls_uart_write_async(u16 uart_no, char *buf, u16 writesize)
  976. {
  977. struct tls_uart_port *port = NULL;
  978. int ret;
  979. if (NULL == buf || writesize < 1)
  980. {
  981. TLS_DBGPRT_ERR("param err\n");
  982. return WM_FAILED;
  983. }
  984. port = &uart_port[uart_no];
  985. ret = tls_uart_fill_buf(port, buf, writesize);
  986. if (0 == ret)
  987. {
  988. tls_uart_tx_chars_start(port);
  989. }
  990. return ret;
  991. }
  992. /**
  993. * @brief get the data length has been transmitted.
  994. *
  995. * @param[in] uart_no is the uart number
  996. *
  997. * @retval the length has been transmitted
  998. *
  999. */
  1000. int tls_uart_tx_length(u16 uart_no)
  1001. {
  1002. struct tls_uart_port *port = &uart_port[uart_no];
  1003. return port->icount.tx;
  1004. }
  1005. /**
  1006. * @brief This function is used to transfer data synchronous.
  1007. *
  1008. * @param[in] uart_no is the uart number
  1009. * @param[in] buf is a buf for saving user data.
  1010. * @param[in] writesize is the data length
  1011. *
  1012. * @retval WM_SUCCESS success
  1013. * @retval WM_FAILED failed
  1014. *
  1015. * @note The function only start transmission, fill buffer in the callback function.
  1016. */
  1017. int tls_uart_write(u16 uart_no, char *buf, u16 writesize)
  1018. {
  1019. return tls_uart_write_async(uart_no, buf, writesize);
  1020. }
  1021. /**
  1022. * @brief This function is used to set uart parity.
  1023. *
  1024. * @param[in] paritytype is a parity type defined in TLS_UART_PMODE_T
  1025. *
  1026. * @retval WM_SUCCESS success
  1027. * @retval WM_FAILED failed
  1028. *
  1029. */
  1030. int tls_uart_set_parity(u16 uart_no, TLS_UART_PMODE_T paritytype)
  1031. {
  1032. return tls_uart_set_parity_inside(&uart_port[uart_no], paritytype);
  1033. }
  1034. /**
  1035. * @brief This function is used to set uart baudrate.
  1036. *
  1037. * @param[in] uart_no is the uart number
  1038. * @param[in] baudrate is the baudrate user want used,the unit is HZ.
  1039. *
  1040. * @retval WM_SUCCESS success
  1041. * @retval WM_FAILED failed
  1042. *
  1043. */
  1044. int tls_uart_set_baud_rate(u16 uart_no, u32 baudrate)
  1045. {
  1046. return tls_uart_set_baud_rate_inside(&uart_port[uart_no], baudrate);
  1047. }
  1048. /**
  1049. * @brief This function is used to set uart stop bits.
  1050. *
  1051. * @param[in] uart_no is the uart number
  1052. * @param[in] stopbits is a stop bit type defined in TLS_UART_STOPBITS_T.
  1053. *
  1054. * @retval WM_SUCCESS success
  1055. * @retval WM_FAILED failed
  1056. *
  1057. */
  1058. int tls_uart_set_stop_bits(u16 uart_no, TLS_UART_STOPBITS_T stopbits)
  1059. {
  1060. return tls_uart_set_stop_bits_inside(&uart_port[uart_no], stopbits);
  1061. }
  1062. int tls_uart_dma_off(u16 uart_no)
  1063. {
  1064. uart_port[uart_no].tx_dma_on = FALSE;
  1065. return WM_SUCCESS;
  1066. }
  1067. #endif
  1068. //TLS_CONFIG_UART