summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/event.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/eos/event.c')
-rw-r--r--fw/fe310/eos/event.c105
1 files changed, 27 insertions, 78 deletions
diff --git a/fw/fe310/eos/event.c b/fw/fe310/eos/event.c
index b21e5ea..1af51da 100644
--- a/fw/fe310/eos/event.c
+++ b/fw/fe310/eos/event.c
@@ -7,7 +7,7 @@
#include "eos.h"
#include "log.h"
-#include "msgq.h"
+
#include "event.h"
EOSMsgQ _eos_event_q;
@@ -17,13 +17,13 @@ static eos_evt_handler_t evt_handler[EOS_EVT_MAX];
static eos_evt_handler_global_t evt_handler_global;
static eos_evt_loopf_t evt_loop_f;
-static void evtq_handler(unsigned char type, unsigned char *buffer, uint16_t len, uint8_t _idx) {
+static void evtq_handler(unsigned char type, EOSMessage *msg, uint16_t len, uint8_t _idx) {
unsigned char idx = (type & EOS_EVT_MASK) >> 4;
if (idx && (idx <= EOS_EVT_MAX)) {
- evt_handler[idx - 1](type, buffer, len);
+ evt_handler[idx - 1](type, msg, len);
} else {
- eos_evtq_bad_handler(type, buffer, len);
+ eos_evtq_bad_handler(type, msg, len);
}
}
@@ -49,102 +49,52 @@ int eos_evtq_len(void) {
return rv;
}
-int eos_evtq_push(unsigned char type, unsigned char *buffer, uint16_t len) {
+int eos_evtq_push(unsigned char type, EOSMessage *msg, uint16_t len) {
int rv;
clear_csr(mstatus, MSTATUS_MIE);
- rv = eos_msgq_push(&_eos_event_q, type, buffer, len);
+ rv = eos_msgq_push(&_eos_event_q, type, msg, len);
set_csr(mstatus, MSTATUS_MIE);
return rv;
}
-int eos_evtq_push_widx(unsigned char type, unsigned char *buffer, uint16_t len, uint8_t *idx) {
+int eos_evtq_push_widx(unsigned char type, EOSMessage *msg, uint16_t len, uint8_t *idx) {
int rv;
clear_csr(mstatus, MSTATUS_MIE);
- rv = eos_msgq_push_widx(&_eos_event_q, type, buffer, len, idx);
+ rv = eos_msgq_push_widx(&_eos_event_q, type, msg, len, idx);
set_csr(mstatus, MSTATUS_MIE);
return rv;
}
-int eos_evtq_push_isr(unsigned char type, unsigned char *buffer, uint16_t len) {
- return eos_msgq_push(&_eos_event_q, type, buffer, len);
-}
-
-int eos_evtq_push_widx_isr(unsigned char type, unsigned char *buffer, uint16_t len, uint8_t *idx) {
- return eos_msgq_push_widx(&_eos_event_q, type, buffer, len, idx);
+int eos_evtq_push_isr(unsigned char type, EOSMessage *msg, uint16_t len) {
+ return eos_msgq_push(&_eos_event_q, type, msg, 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, type, buffer, len);
- set_csr(mstatus, MSTATUS_MIE);
+int eos_evtq_push_widx_isr(unsigned char type, EOSMessage *msg, uint16_t len, uint8_t *idx) {
+ return eos_msgq_push_widx(&_eos_event_q, type, msg, len, idx);
}
-void eos_evtq_pop_widx(unsigned char *type, unsigned char **buffer, uint16_t *len, uint8_t *idx) {
+void eos_evtq_pop(unsigned char *type, EOSMessage *msg, uint16_t *len) {
clear_csr(mstatus, MSTATUS_MIE);
- eos_msgq_pop_widx(&_eos_event_q, type, buffer, len, idx);
+ eos_msgq_pop(&_eos_event_q, type, msg, len);
set_csr(mstatus, MSTATUS_MIE);
}
-void eos_evtq_pop_isr(unsigned char *type, unsigned char **buffer, uint16_t *len) {
- eos_msgq_pop(&_eos_event_q, type, buffer, len);
-}
-
-void eos_evtq_pop_widx_isr(unsigned char *type, unsigned char **buffer, uint16_t *len, uint8_t *idx) {
- eos_msgq_pop_widx(&_eos_event_q, type, buffer, len, idx);
-}
-
-int eos_evtq_get(unsigned char type, unsigned char **buffer, uint16_t *len) {
- int rv = 0;
-
+void eos_evtq_pop_widx(unsigned char *type, EOSMessage *msg, uint16_t *len, uint8_t *idx) {
clear_csr(mstatus, MSTATUS_MIE);
- rv = eos_msgq_find(&_eos_event_q, type, NULL, 0, buffer, len);
+ eos_msgq_pop_widx(&_eos_event_q, type, msg, len, idx);
set_csr(mstatus, MSTATUS_MIE);
-
- return rv;
}
-int eos_evtq_find(unsigned char type, unsigned char *selector, uint16_t sel_len, unsigned char **buffer, uint16_t *len) {
- int rv = 0;
-
- clear_csr(mstatus, MSTATUS_MIE);
- rv = eos_msgq_find(&_eos_event_q, type, selector, sel_len, buffer, len);
- set_csr(mstatus, MSTATUS_MIE);
-
- return rv;
+void eos_evtq_pop_isr(unsigned char *type, EOSMessage *msg, uint16_t *len) {
+ eos_msgq_pop(&_eos_event_q, type, msg, len);
}
-int 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_find(&_eos_event_q, type, selector, sel_len, buffer, len);
- if (rv && (rv != EOS_ERR_NOTFOUND)) {
- set_csr(mstatus, MSTATUS_MIE);
- return rv;
- }
- if (rv) {
- unsigned char _type;
- unsigned char *_buffer;
- uint16_t _len;
- uint8_t idx;
-
- eos_msgq_pop_widx(&_eos_event_q, &_type, &_buffer, &_len, &idx);
- if (_type) {
- set_csr(mstatus, MSTATUS_MIE);
- evt_handler_global(_type, _buffer, _len, idx);
- } else {
- asm volatile ("wfi");
- set_csr(mstatus, MSTATUS_MIE);
- }
- } else {
- set_csr(mstatus, MSTATUS_MIE);
- }
- }
+void eos_evtq_pop_widx_isr(unsigned char *type, EOSMessage *msg, uint16_t *len, uint8_t *idx) {
+ eos_msgq_pop_widx(&_eos_event_q, type, msg, len, idx);
}
void eos_evtq_flush(void) {
@@ -155,15 +105,15 @@ void eos_evtq_flush(void) {
void eos_evtq_flush_isr(void) {
unsigned char type;
- unsigned char *buffer;
+ EOSMessage msg;
uint16_t len;
uint8_t idx;
do {
- eos_msgq_pop_widx(&_eos_event_q, &type, &buffer, &len, &idx);
+ eos_msgq_pop_widx(&_eos_event_q, &type, &msg, &len, &idx);
if (type) {
set_csr(mstatus, MSTATUS_MIE);
- evt_handler_global(type, buffer, len, idx);
+ evt_handler_global(type, &msg, len, idx);
clear_csr(mstatus, MSTATUS_MIE);
}
} while (type);
@@ -180,15 +130,15 @@ void eos_evtq_loop(void) {
void eos_evtq_exec(void) {
unsigned char type;
- unsigned char *buffer;
+ EOSMessage msg;
uint16_t len;
uint8_t idx;
clear_csr(mstatus, MSTATUS_MIE);
- eos_msgq_pop_widx(&_eos_event_q, &type, &buffer, &len, &idx);
+ eos_msgq_pop_widx(&_eos_event_q, &type, &msg, &len, &idx);
if (type) {
set_csr(mstatus, MSTATUS_MIE);
- evt_handler_global(type, buffer, len, idx);
+ evt_handler_global(type, &msg, len, idx);
} else {
asm volatile ("wfi");
set_csr(mstatus, MSTATUS_MIE);
@@ -199,8 +149,7 @@ void eos_evtq_set_loopf(eos_evt_loopf_t loop_f) {
evt_loop_f = loop_f;
}
-
-void eos_evtq_bad_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
+void eos_evtq_bad_handler(unsigned char type, EOSMessage *msg, uint16_t len) {
EOS_LOG(EOS_LOG_ERR, "EVT BAD HANDLER:0x%.2X\n", type);
}