Files

70 lines
1.9 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "system/includes.h"
#include "asm/uart_dev.h"
#include "system/event.h"
#if 1
static uart_bus_t *uart_bus0;
static u8 uart_cbuf0[256] __attribute__((aligned(4)));
static u8 uart_rxbuf0[256] __attribute__((aligned(4)));
extern void usr_uart_data_recieve(u8* data,u16 len);
void usr_uart_send_cmd(u8* data,u16 len)
{
//if(uart_bus0)uart_bus0->write(data,len);
}
static void uart_u_task0(void *arg)
{
int ret;
u32 uart_rxcnt0 = 0;
printf("uart_u_task start\n");
while (1) {
//uart_bus0->read()在尚未收到串口数据时会pend信号量,挂起task,直到UART_RX_PND或UART_RX_OT_PND中断发生,post信号量,唤醒task
uart_rxcnt0 = uart_bus0->read(uart_rxbuf0, sizeof(uart_rxbuf0), 0);
if (uart_rxcnt0)
{
//printf("uart_rx = ");
//printf_buf(uart_rxbuf,uart_rxcnt0);
//usr_uart_send_cmd(uart_rxbuf,uart_rxcnt0);
usr_uart_data_recieve(uart_rxbuf0,uart_rxcnt0);
}
}
}
static void uart_isr_hook0(void *arg, u32 status)
{
//当CONFIG_UARTx_ENABLE_TX_DMAx = 0, 1)为1时,不要在中断里面调用ubus->write(),因为中断不能pend信号量
if (status == UT_RX) {
// printf("uart_rx_isr\n");
}
if (status == UT_RX_OT) {
// printf("uart_rx_ot_isr\n");
}
}
void uart_dev_main_init0()
{
struct uart_platform_data_t u_arg = {0};
u_arg.tx_pin = IO_PORTB_06;
u_arg.rx_pin = IO_PORTB_07;
u_arg.rx_cbuf = uart_cbuf0;
u_arg.rx_cbuf_size = 256;
u_arg.frame_length = 256;
u_arg.rx_timeout = 100;
u_arg.isr_cbfun = uart_isr_hook0;
u_arg.baud = 9600;
u_arg.is_9bit = 0;
uart_bus0 = uart_dev_open(&u_arg);
if (uart_bus0 != NULL)
{
printf("uart_dev_open2() success\n");
os_task_create(uart_u_task0, (void *)uart_bus0, 31, 2048, 0, "uart_cmd_task");
}
// usr_uart_send_cmd(' ',1);
}
#endif