2022-06-14 19:43:20 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
|
|
|
|
* Change Logs:
|
|
|
|
|
* Date Author Notes
|
|
|
|
|
* 2022-06-14 fize the first version
|
|
|
|
|
*/
|
|
|
|
|
#include "user_uart.h"
|
|
|
|
|
|
|
|
|
|
//dev <20>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//size <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>С<EFBFBD><D0A1><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//still in ISR func,so can only use ulog at asynchronous mode.
|
|
|
|
|
static rt_err_t uart3_rx_complete(rt_device_t dev, rt_size_t size)
|
|
|
|
|
{
|
2022-06-22 09:23:36 +08:00
|
|
|
|
uart3_simpack.rx_num = size;
|
2022-06-14 19:43:20 +08:00
|
|
|
|
rt_sem_release(&uart3_simpack.rx_sem);
|
|
|
|
|
return RT_EOK;
|
|
|
|
|
}
|
2022-06-22 09:23:36 +08:00
|
|
|
|
static rt_err_t uart6_rx_complete(rt_device_t dev, rt_size_t size)
|
|
|
|
|
{
|
|
|
|
|
uart6_simpack.rx_num = size;
|
|
|
|
|
rt_sem_release(&uart6_simpack.rx_sem);
|
|
|
|
|
return RT_EOK;
|
|
|
|
|
}
|
2022-06-14 19:43:20 +08:00
|
|
|
|
|
|
|
|
|
rt_device_t uart3_init(void)
|
|
|
|
|
{
|
|
|
|
|
struct serial_configure config;
|
|
|
|
|
|
2022-06-22 09:23:36 +08:00
|
|
|
|
serial3 = rt_device_find(USER_UART3_NAME);
|
2022-06-14 19:43:20 +08:00
|
|
|
|
if (serial3 == RT_NULL)
|
|
|
|
|
{
|
2022-06-22 09:23:36 +08:00
|
|
|
|
LOG_E("could not find device: %s", USER_UART3_NAME);
|
2022-06-14 19:43:20 +08:00
|
|
|
|
return RT_NULL;
|
|
|
|
|
}
|
2022-06-22 09:23:36 +08:00
|
|
|
|
config.baud_rate = BAUD_RATE_460800; //<2F>IJ<DEB8><C4B2><EFBFBD><EFBFBD><EFBFBD>Ϊ 460800
|
2022-06-14 19:43:20 +08:00
|
|
|
|
config.data_bits = DATA_BITS_8; //<2F><><EFBFBD><EFBFBD>λ 8
|
|
|
|
|
config.stop_bits = STOP_BITS_1; //ֹͣλ 1
|
2022-06-30 15:28:02 +08:00
|
|
|
|
config.bufsz = 8000; //<2F>Ļ<DEB8><C4BB><EFBFBD><EFBFBD><EFBFBD> buff size Ϊ 2048
|
2022-06-14 19:43:20 +08:00
|
|
|
|
config.parity = PARITY_NONE; //<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
|
|
|
|
|
rt_device_control(serial3, RT_DEVICE_CTRL_CONFIG, &config);
|
2022-06-22 09:23:36 +08:00
|
|
|
|
if (rt_device_set_rx_indicate(serial3, uart3_rx_complete) != RT_EOK)
|
2022-06-14 19:43:20 +08:00
|
|
|
|
{
|
2022-06-22 09:23:36 +08:00
|
|
|
|
LOG_E("could not set %s 's rx callback func", USER_UART3_NAME);
|
2022-06-14 19:43:20 +08:00
|
|
|
|
return RT_NULL;
|
|
|
|
|
}
|
|
|
|
|
//do not ust dma for rx and tx at same time
|
2022-06-22 09:23:36 +08:00
|
|
|
|
if (rt_device_open(serial3, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_DMA_RX | RT_DEVICE_OFLAG_RDWR))
|
2022-06-14 19:43:20 +08:00
|
|
|
|
{
|
2022-06-22 09:23:36 +08:00
|
|
|
|
LOG_E("could not open device: %s", USER_UART3_NAME);
|
2022-06-14 19:43:20 +08:00
|
|
|
|
return RT_NULL;
|
|
|
|
|
}
|
|
|
|
|
rt_sem_init(&uart3_simpack.rx_sem, "rx3_sem", 0, RT_IPC_FLAG_PRIO);
|
|
|
|
|
return serial3;
|
|
|
|
|
}
|
2022-06-22 09:23:36 +08:00
|
|
|
|
rt_device_t uart6_init(void)
|
|
|
|
|
{
|
|
|
|
|
struct serial_configure config;
|
|
|
|
|
serial6 = rt_device_find(USER_UART6_NAME);
|
|
|
|
|
if (serial6 == RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
LOG_E("could not find device: %s", USER_UART6_NAME);
|
|
|
|
|
return RT_NULL;
|
|
|
|
|
}
|
2022-06-30 15:28:02 +08:00
|
|
|
|
config.baud_rate = BAUD_RATE_115200; //<2F>IJ<DEB8><C4B2><EFBFBD><EFBFBD><EFBFBD>Ϊ 460800
|
2022-06-22 09:23:36 +08:00
|
|
|
|
config.data_bits = DATA_BITS_8; //<2F><><EFBFBD><EFBFBD>λ 8
|
|
|
|
|
config.stop_bits = STOP_BITS_1; //ֹͣλ 1
|
2022-06-30 15:28:02 +08:00
|
|
|
|
config.bufsz = 8000; //<2F>Ļ<DEB8><C4BB><EFBFBD><EFBFBD><EFBFBD> buff size Ϊ 2048
|
2022-06-22 09:23:36 +08:00
|
|
|
|
config.parity = PARITY_NONE; //<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
|
|
|
|
|
rt_device_control(serial6, RT_DEVICE_CTRL_CONFIG, &config);
|
|
|
|
|
if (rt_device_set_rx_indicate(serial6, uart6_rx_complete) != RT_EOK)
|
|
|
|
|
{
|
|
|
|
|
LOG_E("could not set %s 's rx callback func", USER_UART6_NAME);
|
|
|
|
|
return RT_NULL;
|
|
|
|
|
}
|
|
|
|
|
//do not ust dma for rx and tx at same time
|
|
|
|
|
if (rt_device_open(serial6, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_DMA_RX | RT_DEVICE_OFLAG_RDWR))
|
|
|
|
|
{
|
|
|
|
|
LOG_E("could not open device: %s", USER_UART6_NAME);
|
|
|
|
|
return RT_NULL;
|
|
|
|
|
}
|
|
|
|
|
rt_sem_init(&uart6_simpack.rx_sem, "rx6_sem", 0, RT_IPC_FLAG_PRIO);
|
|
|
|
|
return serial6;
|
|
|
|
|
}
|
2022-06-14 19:43:20 +08:00
|
|
|
|
|