gpio_testing.c

来自「嵌入式ARM-LINUX中断编程」· C语言 代码 · 共 42 行

C
42
字号
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/ioctl.h>

int main()
{
	int fd,i,nwrite,nread;
	char *buf = "hello\n";
	char read_buf[6] = {0};
	fd=open("/dev/fs",O_RDWR);
	if (fd<=0)
	{
		perror("open");
		exit(1);
	}
	else
		printf("open success\n");
	
	nwrite = write(fd,buf,6);
	if (nwrite<0)
	{
		perror("write");
		exit(1);
	}
	
	nread = read(fd,read_buf,strlen(buf));
	if (nread<0)
	{
		perror("read");
		exit(1);
	}
	else
		printf("read is %s\n",read_buf);
	close(fd);
	exit(0);
}

⌨️ 快捷键说明

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