From 37a18889be8efa08c9e054014ca7058768b51a61 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Fri, 30 Aug 2019 13:38:17 +0200 Subject: event flags cleanup; added user event type --- code/fe310/eos/ecp.c | 2 +- code/fe310/eos/eos.c | 2 +- code/fe310/eos/event.c | 27 ++++++++++++++------------- code/fe310/eos/event.h | 4 +--- code/fe310/eos/evt_def.h | 17 +++++++++-------- code/fe310/eos/i2s.c | 2 +- code/fe310/eos/net.c | 35 +++++++++++++++++++---------------- code/fe310/eos/net.h | 2 +- code/fe310/eos/net_def.h | 5 ++++- 9 files changed, 51 insertions(+), 45 deletions(-) diff --git a/code/fe310/eos/ecp.c b/code/fe310/eos/ecp.c index 06a3fc3..9297ccd 100644 --- a/code/fe310/eos/ecp.c +++ b/code/fe310/eos/ecp.c @@ -59,7 +59,7 @@ int ecp_init(ECPContext *ctx) { rv = ecp_ctx_create_vconn(ctx); if (rv) return rv; - eos_evtq_set_handler(EOS_EVT_TIMER, timer_handler, EOS_EVT_FLAG_WRAP); + eos_evtq_set_handler(EOS_EVT_TIMER, timer_handler, EOS_EVT_FLAG_NET_BUF_ACQ); eos_net_set_handler(EOS_NET_CMD_PKT, packet_handler, 0); return ECP_OK; } diff --git a/code/fe310/eos/eos.c b/code/fe310/eos/eos.c index 163edfa..3ad3b68 100644 --- a/code/fe310/eos/eos.c +++ b/code/fe310/eos/eos.c @@ -13,5 +13,5 @@ void eos_init(void) { } void eos_start(void) { - eos_net_start(9); + eos_net_start(15); } \ No newline at end of file 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; -} diff --git a/code/fe310/eos/event.h b/code/fe310/eos/event.h index 2dee419..8215d2b 100644 --- a/code/fe310/eos/event.h +++ b/code/fe310/eos/event.h @@ -8,7 +8,5 @@ void eos_evtq_init(void); int eos_evtq_push(unsigned char cmd, unsigned char *buffer, uint16_t len); void eos_evtq_pop(unsigned char *cmd, unsigned char **buffer, uint16_t *len); void eos_evtq_bad_handler(unsigned char cmd, unsigned char *buffer, uint16_t len); -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); -void eos_evtq_handle(unsigned char cmd, unsigned char *buffer, uint16_t len); -void eos_evtq_loop(void); void eos_evtq_set_handler(unsigned char cmd, eos_evt_fptr_t handler, uint8_t flags); +void eos_evtq_loop(void); diff --git a/code/fe310/eos/evt_def.h b/code/fe310/eos/evt_def.h index e07b23c..a011638 100644 --- a/code/fe310/eos/evt_def.h +++ b/code/fe310/eos/evt_def.h @@ -1,11 +1,12 @@ -#define EOS_EVT_FLAG_WRAP 0x1 +#define EOS_EVT_FLAG_NET_BUF_ACQ 0x1 -#define EOS_EVT_NET 0x10 -#define EOS_EVT_TIMER 0x20 -#define EOS_EVT_AUDIO 0x30 -#define EOS_EVT_UI 0x40 +#define EOS_EVT_NET 0x10 +#define EOS_EVT_TIMER 0x20 +#define EOS_EVT_AUDIO 0x30 +#define EOS_EVT_UI 0x40 +#define EOS_EVT_USER 0x80 -#define EOS_EVT_MASK 0xF0 +#define EOS_EVT_MASK 0xF0 -#define EOS_EVT_MAX_EVT 4 -#define EOS_EVT_SIZE_Q 4 +#define EOS_EVT_MAX_EVT 8 +#define EOS_EVT_SIZE_Q 4 diff --git a/code/fe310/eos/i2s.c b/code/fe310/eos/i2s.c index 7d8baf4..d6e924b 100644 --- a/code/fe310/eos/i2s.c +++ b/code/fe310/eos/i2s.c @@ -154,7 +154,7 @@ void eos_i2s_init(uint32_t sample_rate) { for (i=0; i