2022-10-21 10:17:49 +08:00
|
|
|
#include "bflb_mtimer.h"
|
|
|
|
#include "bflb_uart.h"
|
|
|
|
#include "board.h"
|
|
|
|
|
2022-11-18 16:26:34 +08:00
|
|
|
struct bflb_device_s *uartx;
|
2022-10-21 10:17:49 +08:00
|
|
|
|
|
|
|
void uart_isr(int irq, void *arg)
|
|
|
|
{
|
2022-11-18 16:26:34 +08:00
|
|
|
uint32_t intstatus = bflb_uart_get_intstatus(uartx);
|
2022-10-21 10:17:49 +08:00
|
|
|
|
|
|
|
if (intstatus & UART_INTSTS_RX_FIFO) {
|
2022-11-29 15:45:02 +08:00
|
|
|
printf("rx fifo\r\n");
|
2022-11-18 16:26:34 +08:00
|
|
|
while (bflb_uart_rxavailable(uartx)) {
|
|
|
|
printf("0x%02x\r\n", bflb_uart_getchar(uartx));
|
2022-10-21 10:17:49 +08:00
|
|
|
}
|
2022-11-18 16:26:34 +08:00
|
|
|
bflb_uart_feature_control(uartx, UART_CMD_SET_RTS_VALUE, 1);
|
2022-10-21 10:17:49 +08:00
|
|
|
}
|
|
|
|
if (intstatus & UART_INTSTS_RTO) {
|
2022-11-29 15:45:02 +08:00
|
|
|
printf("rto\r\n");
|
2022-11-18 16:26:34 +08:00
|
|
|
while (bflb_uart_rxavailable(uartx)) {
|
|
|
|
printf("0x%02x\r\n", bflb_uart_getchar(uartx));
|
2022-10-21 10:17:49 +08:00
|
|
|
}
|
2022-11-29 15:45:02 +08:00
|
|
|
bflb_uart_int_clear(uartx, UART_INTCLR_RTO);
|
2022-10-21 10:17:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
board_init();
|
2022-11-18 16:26:34 +08:00
|
|
|
board_uartx_gpio_init();
|
2022-10-21 10:17:49 +08:00
|
|
|
|
2022-11-18 16:26:34 +08:00
|
|
|
uartx = bflb_device_get_by_name(DEFAULT_TEST_UART);
|
2022-10-21 10:17:49 +08:00
|
|
|
|
|
|
|
struct bflb_uart_config_s cfg;
|
|
|
|
|
|
|
|
cfg.baudrate = 256000;
|
|
|
|
cfg.data_bits = UART_DATA_BITS_8;
|
|
|
|
cfg.stop_bits = UART_STOP_BITS_1;
|
|
|
|
cfg.parity = UART_PARITY_NONE;
|
2022-10-29 13:33:23 +08:00
|
|
|
cfg.flow_ctrl = 0;
|
2022-10-21 10:17:49 +08:00
|
|
|
cfg.tx_fifo_threshold = 7;
|
|
|
|
cfg.rx_fifo_threshold = 7;
|
2022-11-18 16:26:34 +08:00
|
|
|
bflb_uart_init(uartx, &cfg);
|
2022-10-21 10:17:49 +08:00
|
|
|
|
2022-11-18 16:26:34 +08:00
|
|
|
bflb_uart_rxint_mask(uartx, false);
|
|
|
|
bflb_irq_attach(uartx->irq_num, uart_isr, NULL);
|
|
|
|
bflb_irq_enable(uartx->irq_num);
|
2022-10-21 10:17:49 +08:00
|
|
|
|
2022-11-18 16:26:34 +08:00
|
|
|
bflb_uart_feature_control(uartx, UART_CMD_SET_SW_RTS_CONTROL, true);
|
|
|
|
bflb_uart_feature_control(uartx, UART_CMD_SET_RTS_VALUE, 0);
|
2022-10-21 10:17:49 +08:00
|
|
|
while (1) {
|
|
|
|
bflb_mtimer_delay_ms(2000);
|
|
|
|
}
|
|
|
|
}
|