diff options
author | Uros Majstorovic <majstor@majstor.org> | 2019-10-16 00:02:41 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2019-10-16 00:02:41 +0200 |
commit | fae5fce8ffecdcb6a041435adb7254d720884de3 (patch) | |
tree | d40fd15a00144471642d3638fd553c6bfd537754 /code/fe310/eos/event.c | |
parent | 86957adfc5e2177010db896581763b4cba07273e (diff) |
envent q added eos_evtq_wait
Diffstat (limited to 'code/fe310/eos/event.c')
-rw-r--r-- | code/fe310/eos/event.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/code/fe310/eos/event.c b/code/fe310/eos/event.c index 9e3fb90..25a4feb 100644 --- a/code/fe310/eos/event.c +++ b/code/fe310/eos/event.c @@ -16,6 +16,8 @@ static eos_evt_fptr_t evt_handler[EOS_EVT_MAX_EVT]; static uint16_t evt_handler_wrapper_acq[EOS_EVT_MAX_EVT]; static uint16_t evt_handler_flags_buf_acq[EOS_EVT_MAX_EVT]; +static volatile char evt_busy = 0; + void eos_evtq_init(void) { int i; @@ -86,6 +88,23 @@ void eos_evtq_set_flags(unsigned char type, uint8_t flags) { if ((idx < EOS_EVT_MAX_EVT) && (flags & EOS_EVT_FLAG_NET_BUF_ACQ)) evt_handler_flags_buf_acq[idx] |= flag; } +void eos_evtq_set_busy(char busy) { + evt_busy = busy; +} + +void eos_evtq_wait(unsigned char type, unsigned char *selector, uint16_t sel_len, unsigned char **buffer, uint16_t *len) { + int rv = 0; + + while(!rv) { + clear_csr(mstatus, MSTATUS_MIE); + rv = eos_msgq_get(&_eos_event_q, type, selector, sel_len, buffer, len); + if (!rv) { + asm volatile ("wfi"); + } + set_csr(mstatus, MSTATUS_MIE); + } +} + void eos_evtq_loop(void) { unsigned char type; unsigned char *buffer; @@ -100,7 +119,7 @@ void eos_evtq_loop(void) { evtq_handler(type, buffer, len); clear_csr(mstatus, MSTATUS_MIE); } else { - // asm volatile ("wfi"); + if (!evt_busy) asm volatile ("wfi"); } set_csr(mstatus, MSTATUS_MIE); } |