#include "gpio.h" #include #include #include #include #include // Function for User to write to the Kernel ioctl_set(int fd, char* buf) { int ret_val; // The ioctl command goes to the switch statement in gpio.c ret_val = ioctl(fd, IOC_SET, buf); if (ret_val < 0) { printf("ioctl_set failed:%d\n", ret_val); exit(-1); } } // Function for User to read from the Kernel ioctl_get(int fd) { int ret_val; char buf[100]; // The ioctl command goes to the switch statement in gpio.c ret_val = ioctl(fd, IOC_GET, buf); if (ret_val < 0) { printf("ioctl_get failed:%d\n", ret_val); exit(-1); } } // Function to toggle the pin ioctl_toggle(int fd) { int ret_val; char buf[100]; // The ioctl command goes to the switch statement in gpio.c ret_val = ioctl(fd, IOC_TOGGLE, buf); if (ret_val < 0) { printf("ioctl_toggle failed:%d\n", ret_val); exit(-1); } } main() { char *buf = "test\n"; int fd; /* Make sure to 'mknod /dev/gpio c 60 0' Where c is for char device 60 is major number 0 is minor number may also need to 'chmod 666 /dev/gpio' or 'chmod 664 /dev/gpio' */ fd = open("/dev/gpio", O_RDWR | O_SYNC); if (fd < 0) { printf("Can't open device file\n"); exit(-1); } // calls the Toggle function above ioctl_toggle(fd); close(fd); }