mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-26 15:03:53 +01:00
cpu/native: async_read: add native_async_read_add_int_handler()
fcntl(fd, F_SETOWN, getpid()); doesn't seem to work on Linux to get generate a signal when an event on the GPIO fd occurs. So fall back to the same method as on OS X and call poll() in a child process.
This commit is contained in:
parent
a274ea45fc
commit
47e2885f80
@ -31,9 +31,7 @@ static int _next_index;
|
||||
static struct pollfd _fds[ASYNC_READ_NUMOF];
|
||||
static async_read_t pollers[ASYNC_READ_NUMOF];
|
||||
|
||||
#ifdef __MACH__
|
||||
static void _sigio_child(int fd);
|
||||
#endif
|
||||
|
||||
static void _async_io_isr(void) {
|
||||
if (real_poll(_fds, _next_index, 0) > 0) {
|
||||
@ -104,7 +102,17 @@ void native_async_read_add_handler(int fd, void *arg, native_async_read_callback
|
||||
_next_index++;
|
||||
}
|
||||
|
||||
#ifdef __MACH__
|
||||
void native_async_read_add_int_handler(int fd, void *arg, native_async_read_callback_t handler) {
|
||||
if (_next_index >= ASYNC_READ_NUMOF) {
|
||||
err(EXIT_FAILURE, "native_async_read_add_int_handler(): too many callbacks");
|
||||
}
|
||||
|
||||
_add_handler(fd, arg, handler);
|
||||
|
||||
_sigio_child(_next_index);
|
||||
_next_index++;
|
||||
}
|
||||
|
||||
static void _sigio_child(int index)
|
||||
{
|
||||
struct pollfd fds = _fds[index];
|
||||
@ -148,5 +156,4 @@ static void _sigio_child(int index)
|
||||
sigwait(&sigmask, &sig);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
@ -80,6 +80,16 @@ void native_async_read_continue(int fd);
|
||||
*/
|
||||
void native_async_read_add_handler(int fd, void *arg, native_async_read_callback_t handler);
|
||||
|
||||
/**
|
||||
* @brief start monitoring of file descriptor as interrupt
|
||||
*
|
||||
* @param[in] fd The file descriptor to monitor
|
||||
* @param[in] arg Pointer to be passed as arguments to the callback
|
||||
* @param[in] handler The callback function to be called when the file
|
||||
* descriptor is ready to read.
|
||||
*/
|
||||
void native_async_read_add_int_handler(int fd, void *arg, native_async_read_callback_t handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user