📄 gpio_test.c
字号:
/* * John zsh * mailzang.bokee.com * */#include <stdio.h> #include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/ioctl.h>#include <unistd.h>#define DEVICE_GPIODRIV "/dev/gpio_2440"#include "gpio_2440.h"int main(void){ int fd; int val=-1; int c; if((fd=open(DEVICE_GPIODRIV,O_RDWR | O_NONBLOCK))<0) { perror("open failed !! :can not open device"); exit(1); } while(1) {#ifdef AT91RM9200_GPIO_ZSH printf("gpio_9200 select:\n"); printf("0-get 1-set/clr 2-GPC14Low 3-GPC14High 4-GPC15Low 5-GPC15High 6-exit\n"); scanf("%d", &c); if(c==0) { // GET test int t; ioctl(fd,IOSET, GPC14); ioctl(fd,IOGET, (unsigned long)(&t)); printf("%x \n",t); usleep(100000); ioctl(fd,IOCLR, GPC14); ioctl(fd,IOGET, (unsigned long)(&t)); printf("%x \n",t); } else if (c==1) { // SET & CLR test for(;;) { ioctl(fd, IOSET, GPC14); usleep(100000); ioctl(fd, IOCLR, GPC14); usleep(100000); ioctl(fd, IOSET, GPC15); usleep(100000); ioctl(fd, IOCLR, GPC15); usleep(100000); } } else if(c==2){ ioctl(fd, IOCLR, GPC14); } else if(c==3){ ioctl(fd, IOSET, GPC14); } else if(c==4){ ioctl(fd, IOCLR, GPC15); } else if(c==5){ ioctl(fd, IOSET, GPC15); } else if (c==6) { close(fd); exit(0); }#endif#ifdef S3C2440_GPIO_ZSHprintf("gpio_2440 select:\n");printf("0-get 1-set/clr 2-GPF4Low 3-GPF4High 4-GPF5Low 5-GPF5High 6-GPF6Low 7-GPF6High 8-GPF7Low 9-GPF7High 10-exit\n"); scanf("%d", &c); if(c==0) { // GET test int t; ioctl(fd,IOSET, GPF4); ioctl(fd,IOGET, (unsigned long)(&t)); printf("%x \n",t); usleep(100000); ioctl(fd,IOCLR, GPF4); ioctl(fd,IOGET, (unsigned long)(&t)); printf("%x \n",t); } else if (c==1) { // SET & CLR test for(;;) { ioctl(fd, IOSET, GPF4); usleep(100000); ioctl(fd, IOCLR, GPF4); usleep(100000); ioctl(fd, IOSET, GPF5); usleep(100000); ioctl(fd, IOCLR, GPF5); usleep(100000); ioctl(fd, IOSET, GPF6); usleep(100000); ioctl(fd, IOCLR, GPF6); usleep(100000); ioctl(fd, IOSET, GPF7); usleep(100000); ioctl(fd, IOCLR, GPF7); usleep(100000); } } else if(c==2){ ioctl(fd, IOCLR, GPF4); } else if(c==3){ ioctl(fd, IOSET, GPF4); } else if(c==4){ ioctl(fd, IOCLR, GPF5); } else if(c==5){ ioctl(fd, IOSET, GPF5); } else if(c==6){ ioctl(fd, IOCLR, GPF6); } else if(c==7){ ioctl(fd, IOSET, GPF6); } else if(c==8){ ioctl(fd, IOCLR, GPF7); } else if(c==9){ ioctl(fd, IOSET, GPF7); } else if (c==10) { close(fd); exit(0); }#endif } close(fd); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -