#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <asm/hardware.h> #include <asm-arm/arch-s3c2410/gpio.h> #include <fcntl.h> #include <pthread.h>
#define msleep(x) usleep(x*1000)
int gpf_fd;
void *thread1(void *arg) { while(1) { ioctl(gpf_fd, GPIO_SET_PIN, 4); msleep(250); ioctl(gpf_fd, GPIO_CLR_PIN, 4); msleep(250); } }
void *thread2(void *arg) { while(1) { ioctl(gpf_fd, GPIO_SET_PIN, 5); msleep(500); ioctl(gpf_fd, GPIO_CLR_PIN, 5); msleep(500); } }
void *thread3(void *arg) { while(1) { ioctl(gpf_fd, GPIO_SET_PIN, 6); sleep(1); ioctl(gpf_fd, GPIO_CLR_PIN, 6); sleep(1); } }
int main(void) { pthread_t tid1, tid2, tid3; void *tret;
if((gpf_fd = open("/dev/gpf/0", O_RDWR)) < 0) { perror("open error!"); exit(1); }
if(ioctl(gpf_fd, GPIO_SET_MULTI_PIN_OUT, 0xF0) != 0) { perror("set error!"); exit(1); }
pthread_create(&tid1, NULL, thread1, NULL); msleep(1); pthread_create(&tid2, NULL, thread2, NULL); msleep(1); pthread_create(&tid3, NULL, thread3, NULL); msleep(1); while(1) { ioctl(gpf_fd, GPIO_SET_PIN, 7); msleep(1500); ioctl(gpf_fd, GPIO_CLR_PIN, 7); msleep(1500); }
// pthread_join(tid1, &tret);
// pthread_join(tid2, &tret);
}
驱动的编译:
arm-linux-gcc -c s3c2410-gpf.c -o s3c2410-gpf.o -I /home/skyily/tools/kernel/include/
|