[crisos] GPIO and Interrupt |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/crisos Archives
]
Hi all,
I use the Foxboard (FoxGM) with the alpha firmware for a project at school. Is
there a possibility to monitor the button press (or any GPIO ports/pins
configured as digital input) without polling it?
At the moment I do the following
/** readbuttons **
* \brief monitors one of the two buttons on the FOX Board
*
* \param button bit number of the GPIO pin where the button is connected
* \param timeout amount of seconds to monitor the button
* \return state of button on press or after timeout
*/
int read_buttons(int button, int timeout){
int value=0, start=0;
int retval=0;
int fd=-1;
int t_elapsed, t_rest;
struct timeval T[2];
if ((fd = open("/dev/gpiog", O_RDWR))<0) {
fprintf(stderr, "failed to open /dev/gpiog \n");
return -1;
}
// get initial state
start = button & ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_READBITS));
gettimeofday(&T[0],NULL);
do{ // do until button pressed or timeout occured
value= button & ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_READBITS));
retval = (value == start ) ? 0 : 1;
usleep(100000);
gettimeofday(&T[1],NULL);
t_elapsed = T[1].tv_sec -T[0].tv_sec;
t_rest = timeout-t_elapsed;
}while((t_elapsed < timeout) && (retval == 0));
close(fd);
return retval;
}
Any better solution is highly appreciated!
Thanks a lot and best regards,
Mike
---
CrisOs mailing list
Official multi-language http://www.crisos.org/ mailing list
For unsubscribe send empty mail to: crisos-request@xxxxxxxxxxxxxxxxxxx with subject unsubscribe.