This code is from project: Raspberry pi interrupt to signal conversion, kernel to user space
wait_for_signal.c
#include <stdlib.h> #include <stdio.h> #include <signal.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h> #define SIGNAL_TO_WATCH 34 #define DEVICE_PATH "/dev/m_gpioSignal" /****************************************************************************/ /* Function which will write program pid to device secified by path, */ /****************************************************************************/ void reloadKernelHandler() { int devHandle = -1; char buff[10] = { 0 }; if ( (devHandle = open(DEVICE_PATH, O_WRONLY)) == -1) { perror("open"); return; } sprintf(buff, "%d\n", getpid()); if (write(devHandle, buff, strlen(buff)) == -1) perror("write"); close(devHandle); return; } /****************************************************************************/ /* Function triggered by signal */ /****************************************************************************/ static void run_function(int sig, siginfo_t *siginfo, void *c) { printf ("Got signal\n"); usleep(100); // reenable interrupt in kernel, and once again write own pid reloadKernelHandler(); } /****************************************************************************/ /* Main. */ /****************************************************************************/ int main(int argc, char *argv[]) { struct sigaction act = { 0 }; act.sa_sigaction = &run_function; act.sa_flags = SA_SIGINFO; // attach own function to signal if (sigaction(SIGNAL_TO_WATCH, &act, NULL) < 0) { perror ("error"); return 1; } // enable kernel interrupt and send own pid to kernel reloadKernelHandler(); // loop while(1); return 0; }
if iam using camera for the application what iam did?signal implemention means?iam new to this word..
ReplyDeleteif ( (devHandle = open(DEVICE_PATH, O_WRONLY)) == -1)
DEVICE PATH means for camera is located in the /dev/video0..So iam giving this path...is it ryt?is any other changes iam did?Please give me some suggestions regarding camera application..
Thanks&Regards,
K.Arungopal
Hi,
DeleteThis code has nothing to do with camera, it only fetch signal in users space.
In this app, function run_function is executed, when you press button connected to GPIO.
You have to implement your own code that reads frame.
Take a look on this post http://forums-web2.gentoo.org/viewtopic-t-836218-start-0.html
The v4l2 API: http://linuxtv.org/downloads/v4l-dvb-apis/
Regards,
Igor.
And here you have examples:
Deletehttp://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html
http://linuxtv.org/downloads/v4l-dvb-apis/v4l2grab-example.html
Rgs.