资源简介
主要是使用POLLIN中断去读取串口数据,这是我认为和stm32最近似的一种串口中断

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include “serial.hpp“
/****************************************************************
* Constants
****************************************************************/
#define SYSFS_GPIO_DIR “/sys/class/gpio“
#define POLL_TIMEOUT (3 * 1000) /* 3 seconds */
#define MAX_BUF 64
/****************************************************************
* gpio_export
****************************************************************/
int gpio_export(unsigned int gpio)
{
int fd len;
char buf[MAX_BUF];
fd = open(SYSFS_GPIO_DIR “/export“ O_WRONLY);
if (fd < 0) {
perror(“gpio/export“);
return fd;
}
len = snprintf(buf sizeof(buf) “%d“ gpio);
write(fd buf len);
close(fd);
return 0;
}
/****************************************************************
* gpio_unexport
****************************************************************/
int gpio_unexport(unsigned int gpio)
{
int fd len;
char buf[MAX_BUF];
fd = open(SYSFS_GPIO_DIR “/unexport“ O_WRONLY);
if (fd < 0) {
perror(“gpio/export“);
return fd;
}
len = snprintf(buf sizeof(buf) “%d“ gpio);
write(fd buf len);
close(fd);
return 0;
}
/****************************************************************
* gpio_set_dir
****************************************************************/
int gpio_set_dir(unsigned int gpio unsigned int out_flag)
{
int fd len;
char buf[MAX_BUF];
len = snprintf(buf sizeof(buf) SYSFS_GPIO_DIR “/gpio%d/direction“ gpio);
fd = open(buf O_WRONLY);
if (fd < 0) {
perror(“gpio/direction“);
return fd;
}
if (out_flag)
write(fd “out“ 4);
else
write(fd “in“ 3);
close(fd);
return 0;
}
/****************************************************************
* gpio_set_value
****************************************************************/
int gpio_set_value(unsigned int gpio unsigned int value)
{
int fd len;
char buf[MAX_BUF];
len = snprintf(buf sizeof(buf) SYSFS_GPIO_DIR “/gpio%d/value“ gpio);
fd = open(buf O_WRONLY);
if (fd < 0) {
perror(“gpio/set-value“);
return fd;
}
if (value)
write(fd “1“ 2);
else
write(fd “0“ 2);
close(fd);
return 0;
}
/****************************************************************
* gpio_get_value
****************************************************************/
int gpio_get_value(unsigned int gpio unsigned int *value)
{
int fd len;
char buf[MAX_BUF];
char ch;
len = snprintf(buf sizeof(buf) SYSFS_GPIO_DIR “/gpio%d/value“ gpio);
fd = open(buf O_RDONLY);
if (fd < 0) {
perror(“gpio/get-value“);
return fd;
}
read(fd &ch 1);
if (ch != ‘0‘) {
*value = 1;
} else {
*value = 0;
}
close(fd);
return 0;
}
/*************************************************************
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5454 2019-04-28 23:41 try_serial_interrupt\gpio_test.cpp
文件 20936 2019-04-28 23:40 try_serial_interrupt\main
文件 1480 2019-04-28 23:41 try_serial_interrupt\main.cpp
文件 316 2019-04-28 23:41 try_serial_interrupt\main.hpp
文件 5585 2019-04-28 23:41 try_serial_interrupt\serial.cpp
文件 1599 2019-04-28 23:41 try_serial_interrupt\serial.hpp
目录 0 2019-04-28 23:42 try_serial_interrupt\
相关资源
- Verilog FPGA UART串口控制器
- 串口虚拟工具Configure Virtual Serial Por
- Jetson-TX2多声卡实现同时录音与播放
- USB-Serial-Controller_虚拟串口.rar
- free-serial-port-monitor_(串口监控调试)
- Prolific usb-to-serial comm port 驱动 for wi
- USBserialport
- USB Serial Port win7 64/32 驱动后缀丢失,
- MIPI Alliance Specification for Camera Serial
- High-speed serial IO made simple 中文版
- 把SerialPort通讯类封装成的DLL
- DS18B20_Serial_println.ino
- Serial Attached SCSI - 2.1 (SAS-2.1)
- 虚拟串口破解版 VirtualSerialPortDriver8
- Virtual Serial Port Driver 6 9 注册 破解版
- Virtual Serial Port Driver.zip
- CSerialPort类使用
- JetsonTX1_TX2说明文档
- PL2303 串口 Windows 10 驱动 + 工具
- serial for mac(全功能串行终端管理软件
- Virtual Serial Port Driver虚拟串口
- Serial to Ethernet Connector 5.0.7.376 破解版
- SerialChart一款可以实时输出串口数据并
- Configure Virtual Serial Port Driver 破解版
- 虚拟串口 Virtual Serial Port Driver 官方原
- Serial to Ethernet Connector 7.1 Build (7.1.
- VSPD虚拟串口破解版Virtual Serial Port D
- SATA 3.2规范文档
- MIPI Alliance Specification for Camera Serial
- 虚拟串口工具9.0 中文版 (支持win10)
评论
共有 条评论