summaryrefslogtreecommitdiff
path: root/code/fe310/eos/net.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2019-10-15 18:11:40 +0200
committerUros Majstorovic <majstor@majstor.org>2019-10-15 18:11:40 +0200
commitedec491d59697a635ddce7a19a870dd3e8d2f3ed (patch)
tree8b5c00103609eabe9fdc89169c825f544aca41d5 /code/fe310/eos/net.c
parent850ce8bb7a447e1d2500d5dac0b0003bb4412c37 (diff)
event handler flags per evt subtype
timer has evt subtypes i2s refactor i2s has spk event i2s fixed intr handler audio buf push msgq fixed get message
Diffstat (limited to 'code/fe310/eos/net.c')
-rw-r--r--code/fe310/eos/net.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/code/fe310/eos/net.c b/code/fe310/eos/net.c
index 0cbe9f6..b8a5056 100644
--- a/code/fe310/eos/net.c
+++ b/code/fe310/eos/net.c
@@ -217,32 +217,38 @@ static void net_handler_rts(void) {
}
static void net_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
- if ((type & ~EOS_EVT_MASK) > EOS_NET_MAX_MTYPE) {
+ unsigned char idx = (type & ~EOS_EVT_MASK) - 1;
+ uint16_t buf_free = ((uint16_t)1 << idx) & evt_handler_flags_buf_free;
+ uint16_t buf_acq = ((uint16_t)1 << idx) & evt_handler_flags_buf_acq;
+
+ if (idx >= EOS_NET_MAX_MTYPE) {
eos_evtq_bad_handler(type, buffer, len);
- } else {
- unsigned char idx = (type & ~EOS_EVT_MASK) - 1;
- uint16_t buf_free = ((uint16_t)1 << idx) & evt_handler_flags_buf_free;
- uint16_t buf_acq = ((uint16_t)1 << idx) & evt_handler_flags_buf_acq;
-
- if (buf_free) {
- eos_net_free(buffer, buf_acq);
- buffer = NULL;
- len = 0;
- }
+ eos_net_free(buffer, 0);
+ return;
+ }
+ if (buf_free) {
+ eos_net_free(buffer, buf_acq);
+ buffer = NULL;
+ len = 0;
+ }
- evt_handler[idx](type, buffer, len);
+ evt_handler[idx](type, buffer, len);
- if (buf_free && buf_acq) eos_net_release();
- }
+ if (buf_free && buf_acq) eos_net_release();
}
-void eos_net_set_handler(unsigned char type, eos_evt_fptr_t handler, uint8_t flags) {
+void eos_net_set_handler(unsigned char mtype, eos_evt_fptr_t handler, uint8_t flags) {
+ if (mtype && (mtype <= EOS_NET_MAX_MTYPE)) {
+ mtype--;
+ } else {
+ return;
+ }
if (flags) {
- uint16_t flag = (uint16_t)1 << ((type & ~EOS_EVT_MASK) - 1);
+ uint16_t flag = (uint16_t)1 << mtype;
if (flags & EOS_NET_FLAG_BUF_FREE) evt_handler_flags_buf_free |= flag;
if (flags & EOS_NET_FLAG_BUF_ACQ) evt_handler_flags_buf_acq |= flag;
}
- evt_handler[(type & ~EOS_EVT_MASK) - 1] = handler;
+ evt_handler[mtype] = handler;
}
void eos_net_init(void) {
@@ -275,7 +281,7 @@ void eos_net_init(void) {
for (i=0; i<EOS_NET_MAX_MTYPE; i++) {
evt_handler[i] = eos_evtq_bad_handler;
}
- eos_evtq_set_handler(EOS_EVT_NET, net_handler_evt, 0);
+ eos_evtq_set_handler(EOS_EVT_NET, net_handler_evt);
}
void eos_net_start(uint32_t sckdiv) {