static void __uart_rx_irq(void *p_arg)
{
uint8_t data;
int ch;
while ((ch = bl_uart_data_recv(AT_UART_NUM)) >= 0) {
data = (uint8_t)ch;
axk_at_data_recv((char *)&data, 1);
}
}
void axk_hal_uart_config(at_uart_t *uart_cfg)
{
int dataBits = UART_DATABITS_8;
int stopBits = UART_STOPBITS_1;
int parity = UART_PARITY_NONE;
int cts_pin = 0xff;
int rts_pin = 0xff;
if (uart_cfg->databits == 5) {
dataBits = UART_DATABITS_5;
} else if (uart_cfg->databits == 6) {
dataBits = UART_DATABITS_6;
} else if (uart_cfg->databits == 7) {
dataBits = UART_DATABITS_7;
} else if (uart_cfg->databits == 9) {
dataBits = UART_DATABITS_8;
}
if (uart_cfg->stopbits == UART_STOP_BITS_1) {
stopBits = UART_STOPBITS_1;
} else if (uart_cfg->stopbits == UART_STOP_BITS_1_5) {
stopBits = UART_STOPBITS_1_5;
} else if (uart_cfg->stopbits == UART_STOP_BITS_2) {
stopBits = UART_STOPBITS_2;
}
vTaskDelay(20 / portTICK_PERIOD_MS);
if (uart_cfg->flowcontrol & AT_UART_FLOWCTRL_RTS) {
rts_pin = 4;
} else if (uart_cfg->flowcontrol & AT_UART_FLOWCTRL_CTS) {
cts_pin = 3;
}
uart_fwctrl = uart_cfg->flowcontrol;
parity = uart_cfg->parity;
bl_uart_init_ex(AT_UART_NUM, GLB_GPIO_PIN_16, GLB_GPIO_PIN_7, cts_pin, rts_pin, uart_cfg->baudrate,
dataBits, stopBits, parity);
bl_uart_int_tx_notify_register(AT_UART_NUM, __uart_tx_irq, NULL);
bl_uart_int_rx_notify_register(AT_UART_NUM, __uart_rx_irq, NULL);
bl_uart_int_enable(AT_UART_NUM);
bl_uart_int_tx_disable(AT_UART_NUM);
} |