diff options
Diffstat (limited to 'code/fe310/eos/event.c')
-rw-r--r-- | code/fe310/eos/event.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/code/fe310/eos/event.c b/code/fe310/eos/event.c index 2aa4ecf..66b1f4a 100644 --- a/code/fe310/eos/event.c +++ b/code/fe310/eos/event.c @@ -25,69 +25,69 @@ void eos_evtq_init(void) { eos_msgq_init(&_eos_event_q, event_q_array, EOS_EVT_SIZE_Q); } -int eos_evtq_push(unsigned char cmd, unsigned char *buffer, uint16_t len) { +int eos_evtq_push(unsigned char type, unsigned char *buffer, uint16_t len) { clear_csr(mstatus, MSTATUS_MIE); - int ret = eos_msgq_push(&_eos_event_q, cmd, buffer, len); + int ret = eos_msgq_push(&_eos_event_q, type, buffer, len); set_csr(mstatus, MSTATUS_MIE); return ret; } -void eos_evtq_pop(unsigned char *cmd, unsigned char **buffer, uint16_t *len) { +void eos_evtq_pop(unsigned char *type, unsigned char **buffer, uint16_t *len) { clear_csr(mstatus, MSTATUS_MIE); - eos_msgq_pop(&_eos_event_q, cmd, buffer, len); + eos_msgq_pop(&_eos_event_q, type, buffer, len); set_csr(mstatus, MSTATUS_MIE); } -void eos_evtq_bad_handler(unsigned char cmd, unsigned char *buffer, uint16_t len) { +void eos_evtq_bad_handler(unsigned char type, unsigned char *buffer, uint16_t len) { write(1, "error\n", 6); } -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) { +static void evtq_handler_wrapper(unsigned char type, 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); + f(type, buffer, len); eos_net_release(); *flags_acq &= ~flag; } else { *flags_acq |= flag; - eos_evtq_push(cmd, buffer, len); + eos_evtq_push(type, buffer, 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); +static void evtq_handler(unsigned char type, unsigned char *buffer, uint16_t len) { + if (((type & EOS_EVT_MASK) >> 4) > EOS_EVT_MAX_EVT) { + eos_evtq_bad_handler(type, buffer, len); } else { - unsigned char idx = ((cmd & EOS_EVT_MASK) >> 4) - 1; + unsigned char idx = ((type & EOS_EVT_MASK) >> 4) - 1; uint16_t flag = (uint16_t)1 << idx; if (flag & evt_handler_flags_buf_acq) { - evtq_handler_wrapper(cmd, buffer, len, &evt_handler_wrapper_acq, flag, evt_handler[idx]); + evtq_handler_wrapper(type, buffer, len, &evt_handler_wrapper_acq, flag, evt_handler[idx]); } else { - evt_handler[idx](cmd, buffer, len); + evt_handler[idx](type, buffer, len); } } } -void eos_evtq_set_handler(unsigned char cmd, eos_evt_fptr_t handler, uint8_t flags) { +void eos_evtq_set_handler(unsigned char type, eos_evt_fptr_t handler, uint8_t flags) { if (flags) { - uint16_t flag = (uint16_t)1 << (((cmd & EOS_EVT_MASK) >> 4) - 1); + uint16_t flag = (uint16_t)1 << (((type & 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; + evt_handler[((type & EOS_EVT_MASK) >> 4) - 1] = handler; } void eos_evtq_loop(void) { - unsigned char cmd; + unsigned char type; unsigned char *buffer; uint16_t len; int foo = 1; while(foo) { clear_csr(mstatus, MSTATUS_MIE); - eos_msgq_pop(&_eos_event_q, &cmd, &buffer, &len); - if (cmd) { + eos_msgq_pop(&_eos_event_q, &type, &buffer, &len); + if (type) { set_csr(mstatus, MSTATUS_MIE); - evtq_handler(cmd, buffer, len); + evtq_handler(type, buffer, len); clear_csr(mstatus, MSTATUS_MIE); } else { // asm volatile ("wfi"); |