diff options
author | Uros Majstorovic <majstor@majstor.org> | 2019-08-30 13:38:17 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2019-08-30 13:38:17 +0200 |
commit | 37a18889be8efa08c9e054014ca7058768b51a61 (patch) | |
tree | 717f965d550394b3ef473c1184e5a05391a53a48 /code/fe310/eos/event.c | |
parent | 0fdc7ebc120b99bef9338630e954e773acf15018 (diff) |
event flags cleanup; added user event type
Diffstat (limited to 'code/fe310/eos/event.c')
-rw-r--r-- | code/fe310/eos/event.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/code/fe310/eos/event.c b/code/fe310/eos/event.c index f7ee4ef..1cffb26 100644 --- a/code/fe310/eos/event.c +++ b/code/fe310/eos/event.c @@ -14,7 +14,7 @@ static EOSMsgItem event_q_array[EOS_EVT_SIZE_Q]; static eos_evt_fptr_t evt_handler[EOS_EVT_MAX_EVT]; static uint16_t evt_handler_wrapper_acq = 0; -static uint16_t evt_handler_wrapper_en = 0; +static uint16_t evt_handler_flags_buf_acq = 0; void eos_evtq_init(void) { int i; @@ -42,7 +42,7 @@ void eos_evtq_bad_handler(unsigned char cmd, unsigned char *buffer, uint16_t len write(1, "error\n", 6); } -void eos_evtq_handler_wrapper(unsigned char cmd, unsigned char *buffer, uint16_t len, uint16_t *flags_acq, uint16_t flag, eos_evt_fptr_t f) { +static void evtq_handler_wrapper(unsigned char cmd, unsigned char *buffer, uint16_t len, uint16_t *flags_acq, uint16_t flag, eos_evt_fptr_t f) { int ok = eos_net_acquire(*flags_acq & flag); if (ok) { f(cmd, buffer, len); @@ -54,20 +54,28 @@ void eos_evtq_handler_wrapper(unsigned char cmd, unsigned char *buffer, uint16_t } } -void eos_evtq_handle(unsigned char cmd, unsigned char *buffer, uint16_t len) { +static void evtq_handler(unsigned char cmd, unsigned char *buffer, uint16_t len) { if (((cmd & EOS_EVT_MASK) >> 4) > EOS_EVT_MAX_EVT) { eos_evtq_bad_handler(cmd, buffer, len); } else { unsigned char idx = ((cmd & EOS_EVT_MASK) >> 4) - 1; uint16_t flag = (uint16_t)1 << idx; - if (flag & evt_handler_wrapper_en) { - eos_evtq_handler_wrapper(cmd, buffer, len, &evt_handler_wrapper_acq, flag, evt_handler[idx]); + if (flag & evt_handler_flags_buf_acq) { + evtq_handler_wrapper(cmd, buffer, len, &evt_handler_wrapper_acq, flag, evt_handler[idx]); } else { evt_handler[idx](cmd, buffer, len); } } } +void eos_evtq_set_handler(unsigned char cmd, eos_evt_fptr_t handler, uint8_t flags) { + if (flags) { + uint16_t flag = (uint16_t)1 << (((cmd & EOS_EVT_MASK) >> 4) - 1); + if (flags & EOS_EVT_FLAG_NET_BUF_ACQ) evt_handler_flags_buf_acq |= flag; + } + evt_handler[((cmd & EOS_EVT_MASK) >> 4) - 1] = handler; +} + void eos_evtq_loop(void) { unsigned char cmd; unsigned char *buffer; @@ -79,7 +87,7 @@ void eos_evtq_loop(void) { eos_msgq_pop(&_eos_event_q, &cmd, &buffer, &len); if (cmd) { set_csr(mstatus, MSTATUS_MIE); - eos_evtq_handle(cmd, buffer, len); + evtq_handler(cmd, buffer, len); clear_csr(mstatus, MSTATUS_MIE); } else { asm volatile ("wfi"); @@ -88,11 +96,4 @@ void eos_evtq_loop(void) { } } -void eos_evtq_set_handler(unsigned char cmd, eos_evt_fptr_t handler, uint8_t flags) { - if (flags & EOS_EVT_FLAG_WRAP) { - uint16_t flag = (uint16_t)1 << (((cmd & EOS_EVT_MASK) >> 4) - 1); - evt_handler_wrapper_en |= flag; - } - evt_handler[((cmd & EOS_EVT_MASK) >> 4) - 1] = handler; -} |