The three important data structures of the linux character device driver are
struct file
struct inode
strude file_operations
where struct file represents a The open file, struct inode, is used to record the physical information of the file. So for the time being, you can ignore it.
strude file_operations is a collection of function pointers. The following is a description of the GPIO driver and application examples:
The first part is the driver:
//------------------- OPEN ------------------------ssize_t SIMPLE_GPIO_open (struct Inode * inode , struct file * file){ #ifdef OURS_GPIO_DEBUG printk ("SIMPLE_GPIO_open [ --kernel--]\ "); #endif return 0;}
//------ ------------- RELEASE/CLOSE ---------------ssize_t SIMPLE_GPIO_release (struct inode * inode , struct file * file){ #ifdef OURS_GPIO_DEBUG printk ( "SIMPLE_GPIO_release [ --kernel--]\ "); #endif
return 0;}
//--------------- ----------------------------------struct file_operations gpio_fops ={
.open= SIMPLE_GPIO_open, .read= SIMPLE_GPIO_read, .write= SIMPLE_GPIO_write, .ioctl= SIMPLE_GPIO_ioctl, .release= SIMPLE_GPIO_release, };
Defined as struct file_operations in gpio_fops , for example .open = SIMPLE_GPIO_open, which defines the open function of the application to actually call the SIMPLE_GPIO_open function.
Look at the ssize_t defined in the driver SIMPLE_GPIO_open (struct inode * inode, struct file * file)
where the parameter is another The two data structures are ignored here. (Do not write parameters or anything)
Review the call in the application
#define DEVICE_NAME "/dev/gpio"
int main(void){ int fd ; int ret; char *i;
printf("\ start gpio_led_driver test\ \ ");
fd = open(DEVICE_NAME, O_RDWR); printf("fd = %d\ ",fd);
if (fd == -1) { printf("open device %s error\ ",DEVICE_NAME); }
The open function argument of the application call is open(DEVICE_NAME, O_RDWR);
where #define DEVICE_NAME "/dev/gpio" , O_RDWR means to open and write
In the driver, the xxxopen function can be written according to the book, the parameters can be completely ignored (the function body can write the content, I don't know what to do)
The open function parameter of the application According to the parameters written in the linux application book,
busybox is a Linux command box that integrates many of the tools and commands that compress Linux.
Webalizer is a commonly used web log analysis script under Linux, of course, for nginx. I am curious
The network is often dropped. Many technicians think that the router is unstable. The ac
Do you know what a Linux system is? Some users dont know much about Linux. Linux is a free and free
Linux hard links and soft links deep understanding
Su: /bin/bash: Permission denied
Linux using soft links to solve the problem of directory transfer
The best solution for hard disk partitioning under Linux
Centos5.8 iptables management basic tutorial
How to set Sysctl.conf to improve Linux performance (the most complete sysctl.conf excellent
Self-made Linux Pinyin Wubi input method
Arm+linux startup process into the kernel
Linux displays the Chinese character file name on the FAT partition
Windows server2008 64-bit how to set the same administrator multi-ip remote login
Win7 system running game prompt application initialization 0xc00000ba failure reason and solution
Win7 notebook keyboard failure is also useless how to solve?
What if Win8.1 rasman.dll is missing and the program cannot run?
Win7 system can not set the Aero theme how to do
What software can I use to open GHO files?
DNS server settings detailed steps teaching
Linux study notes - SSH password-free login
Combined shortcut keys in Windows 7
God skills! How to use Windows's own software to convert pictures to Word