| |
| |
| |
| |
| |
| |
| |
|
|
| #include "apb_uart.h" |
|
|
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| void apb_uart_init(ApbUART* uart, uint32_t base_addr){ |
| uart->hardware = (ApbUARTHd*)base_addr; |
| uart->itr_en = 0x00; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| int apb_uart_send_byte(ApbUART* uart, uint8_t byte){ |
| uint32_t fifo_cs = uart->hardware->fifo_cs; |
| |
| if(fifo_cs & 0x01){ |
| return -1; |
| }else{ |
| fifo_cs &= (~0x3FC); |
| fifo_cs |= ((uint32_t)byte) << 2; |
| uart->hardware->fifo_cs = fifo_cs; |
| |
| uart->hardware->fifo_cs = (fifo_cs | 0x02); |
| uart->hardware->fifo_cs = (fifo_cs & (~0x02)); |
| |
| return 0; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| int apb_uart_rev_byte(ApbUART* uart, uint8_t* byte){ |
| uint32_t fifo_cs = uart->hardware->fifo_cs; |
| |
| if(fifo_cs & 0x400){ |
| return -1; |
| }else{ |
| uart->hardware->fifo_cs = (fifo_cs | 0x800); |
| uart->hardware->fifo_cs = (fifo_cs & (~0x800)); |
| |
| fifo_cs = uart->hardware->fifo_cs; |
| *byte = (fifo_cs >> 12) & 0xFF; |
| |
| return 0; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void apb_uart_enable_itr(ApbUART* uart, uint8_t itr_mask, const ApbUartItrThConfig* config){ |
| uart->hardware->itr_status_en = 0x00000001 | (itr_mask << 1); |
| uart->itr_en = itr_mask; |
| |
| uart->hardware->tx_itr_th = |
| ((uint32_t)(config->tx_bytes_n_th - 1)) | (((uint32_t)(config->tx_idle_th - 2)) << 16); |
| uart->hardware->rx_itr_th = |
| ((uint32_t)(config->rx_bytes_n_th - 1)) | (((uint32_t)(config->rx_idle_th - 2)) << 16); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| void apb_uart_disable_itr(ApbUART* uart){ |
| uart->hardware->itr_status_en = 0x00000000; |
| uart->itr_en = 0x00; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| uint8_t apb_uart_get_itr_status(ApbUART* uart){ |
| uint32_t itr_status_en = uart->hardware->itr_status_en; |
| |
| return (uint8_t)(itr_status_en >> 17) & 0x1F; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| void apb_uart_clear_itr_flag(ApbUART* uart){ |
| uart->hardware->itr_status_en = 0x00000001 | (uart->itr_en << 1); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void uart_printf(ApbUART* uart, char *fmt, ...){ |
| unsigned char UsartPrintfBuf[296]; |
| va_list ap; |
| unsigned char* pStr = UsartPrintfBuf; |
| |
| va_start(ap, fmt); |
| vsnprintf((char *)UsartPrintfBuf, sizeof(UsartPrintfBuf), (const char *)fmt, ap); |
| va_end(ap); |
| |
| while(*pStr != 0){ |
| while (!apb_uart_send_byte(uart, *pStr)); |
| |
| pStr++; |
| } |
| } |
|
|