forked from xuos/xiuos
modify linux
This commit is contained in:
parent
814a742260
commit
b9bfce4865
|
@ -58,10 +58,6 @@ static uint32_t _SysTick_Config(uint32_t ticks)
|
|||
* This function will initial your board.
|
||||
*/
|
||||
|
||||
extern RxBuffer2;
|
||||
extern uint16_t UART_ReceiveData(USART_TypeDef* USARTx);
|
||||
extern void UART_SendData(USART_TypeDef* USARTx, uint16_t Data);
|
||||
|
||||
void InitBoardHardware()
|
||||
{
|
||||
_SysTick_Config(SystemCoreClock / TICK_PER_SECOND);
|
||||
|
@ -80,22 +76,4 @@ void InitBoardHardware()
|
|||
|
||||
KPrintf("board init done.\n");
|
||||
KPrintf("start okernel...\n");
|
||||
|
||||
uint16_t ans = 0;
|
||||
uint16_t recv_data = 0;
|
||||
uint16_t send_data = 0;
|
||||
int cnt = 0;
|
||||
while (1) {
|
||||
|
||||
recv_data = UART_ReceiveData(USART3);
|
||||
|
||||
if (recv_data < 58 && recv_data > 47) {
|
||||
ans = recv_data;
|
||||
|
||||
KPrintf("recv data: %d\n", ans - 48);
|
||||
}
|
||||
send_data = ans + 17;
|
||||
KPrintf("send data: %d\n", send_data);
|
||||
UART_SendData(USART3, send_data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
SRC_FILES := connect_uart.c
|
||||
SRC_FILES := connect_uart.c test_uart.c
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int fd;
|
||||
struct termios tty;
|
||||
char buffer[256];
|
||||
|
||||
// 打开串口设备
|
||||
fd = open("/dev/ttySC3", O_RDWR | O_NOCTTY);
|
||||
if (fd == -1) {
|
||||
perror("打开串口失败");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 获取当前串口配置
|
||||
if (tcgetattr(fd, &tty) != 0) {
|
||||
perror("获取串口配置失败");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 设置波特率为9600
|
||||
cfsetispeed(&tty, B9600);
|
||||
cfsetospeed(&tty, B9600);
|
||||
|
||||
// 8位数据位,无校验位,1位停止位
|
||||
tty.c_cflag &= ~PARENB;
|
||||
tty.c_cflag &= ~CSTOPB;
|
||||
tty.c_cflag &= ~CSIZE;
|
||||
tty.c_cflag |= CS8;
|
||||
|
||||
// 非规范模式,禁止软件流控制
|
||||
tty.c_iflag &= ~(IXON | IXOFF | IXANY);
|
||||
tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
|
||||
// 禁止输出回车换行和换行符的映射
|
||||
tty.c_oflag &= ~OPOST;
|
||||
tty.c_oflag &= ~ONLCR;
|
||||
|
||||
// 设置新的串口配置
|
||||
if (tcsetattr(fd, TCSANOW, &tty) != 0) {
|
||||
perror("设置串口配置失败");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 获取待读取数据的字节数
|
||||
int bytes_available;
|
||||
printf("读取中\n");
|
||||
while (1) {
|
||||
int res = ioctl(fd, TIOCINQ, &bytes_available);
|
||||
|
||||
if (res != -1) {
|
||||
if (bytes_available > 0) {
|
||||
// 读取串口数据
|
||||
printf("read\n");
|
||||
int bytes_read = read(fd, buffer, sizeof(buffer));
|
||||
if (bytes_read > 0) {
|
||||
// 在这里处理读取到的数据
|
||||
printf("读取到的数据: %s\n", buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭串口设备
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#include "ch32v30x.h"
|
||||
#include "connect_uart.h"
|
||||
|
||||
extern RxBuffer2;
|
||||
extern uint16_t UART_ReceiveData(USART_TypeDef* USARTx);
|
||||
extern void UART_SendData(USART_TypeDef* USARTx, uint16_t Data);
|
||||
|
||||
void send_rensa()
|
||||
{
|
||||
char* s = "ch uart";
|
||||
while (*s) {
|
||||
UART_SendData(USART3, (uint16_t)*s++);
|
||||
KPrintf("%c", *s);
|
||||
}
|
||||
}
|
||||
|
||||
void recv_rensa()
|
||||
{
|
||||
uint16_t ans = 0;
|
||||
char recv_data = ' ';
|
||||
|
||||
int cnt = 0;
|
||||
while (recv_data != '\n') {
|
||||
recv_data = (char)UART_ReceiveData(USART3);
|
||||
KPrintf("%c", recv_data);
|
||||
}
|
||||
recv_data = ' ';
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
recv_rensa, recv_rensa, test receive renesa);
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
send_rensa, send_rensa, test send renesa);
|
Loading…
Reference in New Issue