avr-fw-modules/core/src/event_wait.c

49 lines
661 B
C
Executable File

#include <hwo/events.h>
#include <sys/atomic.h>
#include <hwo/systick.h>
#include <hwo/threads.h>
#include <stdlib.h>
/*! \brief .
*
*/
EVENT* event_wait(uint32_t maxwait)
{
list_t *l;
EVENT* e;
event_cleanup();
do
{
ATOMIC
l = list_fetch_first( &_ev_head );
if (l) {
e = list_entry(l,EVENT,list);
if (e->flags & EV_FLAG_AUTOFREE)
_ev_cleanup = e;
if (e->event == EV_SYS_TIMER){
if (e->ptr){
void (*h)(void) = e->ptr;
h();
return NULL;
};
};
return e;
};
if (!maxwait)
return NULL;
eventWaiter = current_thread();
wait_ms( maxwait );
eventWaiter = NULL;
} while (1);
};