⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.cpp

📁 XMODEM 是一种适合在两个计算机之间进行文件传输的简单协议。嵌入式系统调试环境经常利用此协议或其变体
💻 CPP
字号:

#include <vxWorks.h>
#include <ioLib.h>
#include <string.h>
#include <taskLib.h >
#include <selectLib.h>
#include "uart.h"

int sfd = 0;

void Uart_Init()
{
	sfd =  open("/tyCo/1", O_RDWR, 0);

	ioctl(sfd, FIOBAUDRATE, 115200);
	ioctl(sfd, FIOSETOPTIONS, OPT_RAW);
	ioctl(sfd, FIOFLUSH, 0);
}

void Uart_Exit()
{
	ioctl(sfd, FIOFLUSH, 0);
	ioctl(sfd, FIOSETOPTIONS, OPT_TERMINAL);
	close(sfd);
}

/*
 * int Uart_GetKey(char *data);
 * Uart_GetKey is a non-pend function by reading /dev/tyCo/1 with ioctl
 * Return -1 while nothing in buffer;
 * Return 0 while data is update.
 */
int Uart_GetKey(char *data)
{
	int ret, count = 0;

	ret = ioctl(sfd, FIONREAD, (int)&count);
	if (ret!=ERROR && count>0)
	{
		ret = read(sfd, data, 1);
		if (ret == 1)
			return 0;
	}
	return -1;
}

/*
 * int Uart_SendKey(char data);
 * Return -1 while error occur;
 * Return 0 while data is write to /dev/tyCo/1.
 */
int Uart_SendKey(char data)
{
	int ret = write(sfd, &data, 1);
	if (ret == 1)
		return 0;
	return -1;
}

/*
 * A simple function for timer.
 */
void idler()
{
	fd_set readList;
	struct timeval timeOut;

	FD_ZERO(&readList);
	FD_SET(sfd, &readList);
	timeOut.tv_sec = 1;
	timeOut.tv_usec = 0;

	int ret = select(0, &readList, 0, 0, &timeOut);
	// if (!ret) timeout...
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -