I am implementing an RF chip driver that communicates over SPI. I need to implement a user space call-back function to be invoked when an interrupt is received. I know how to register an interrupt hander in a kernel module but what is the proper method of notifying the user space application?
Callback from kernel space to user space
Hello, maybe you could take a look on how FUSE works ( http://fuse.sourceforge.net/ ) - it is a system which allows to create file system drivers in user space.
Hi, Use SIGNAL method in order to notify from the kernel module to user pace program. Before seding signal the kernel module need the process ID of the user space program. In the kernel module: struct siginfo sinfo; /* signal information */ pid_t pid; /* user program process id */ struct task_struct *task; /* init */ memset(&sinfo, 0, sizeof(struct siginfo)); sinfo.si_signo = SIGIO; // Config the signals sinfo.si_code = SI_USER; // Config SI_QUERE std or SI_KERNEL for RTC pid = your_user_space_PID; task = find_task_by_vpid (pid); if(task == NULL) { printk ("Cannot find pid from user program\r\n"); return; } /* send SIGIO to the user program */ send_sig_info (SIGIO, &sinfo, task); /* Send signal to user program */ In user program : void signal_handler (int signum) { if (signum == SIGIO) printf ("SIGIO\r\n"); return; } struct sigaction action; memset (&action, 0, sizeof (action)); /* clean variable */ action.sa_handler = signal_handler; /* specify signal handler */ action.sa_flags = 0; /* operation flags setting */ sigaction (SIGIO, &action, NULL); /* attach action with SIGIO */
Write fasync moduule in your driver and make your application ready for SIGIO signal.Once any data comes to your ISR just send the SIGIO signal to your application and from your application the registered signal handler will do whatever the work you have assigned to this.