summaryrefslogtreecommitdiff
path: root/code/fe310
diff options
context:
space:
mode:
Diffstat (limited to 'code/fe310')
-rw-r--r--code/fe310/eos/event.c21
-rw-r--r--code/fe310/eos/event.h2
-rw-r--r--code/fe310/eos/evt_def.h12
-rw-r--r--code/fe310/eos/msgq.c9
-rw-r--r--code/fe310/eos/msgq.h2
5 files changed, 34 insertions, 12 deletions
diff --git a/code/fe310/eos/event.c b/code/fe310/eos/event.c
index 9e3fb90..25a4feb 100644
--- a/code/fe310/eos/event.c
+++ b/code/fe310/eos/event.c
@@ -16,6 +16,8 @@ static eos_evt_fptr_t evt_handler[EOS_EVT_MAX_EVT];
static uint16_t evt_handler_wrapper_acq[EOS_EVT_MAX_EVT];
static uint16_t evt_handler_flags_buf_acq[EOS_EVT_MAX_EVT];
+static volatile char evt_busy = 0;
+
void eos_evtq_init(void) {
int i;
@@ -86,6 +88,23 @@ void eos_evtq_set_flags(unsigned char type, uint8_t flags) {
if ((idx < EOS_EVT_MAX_EVT) && (flags & EOS_EVT_FLAG_NET_BUF_ACQ)) evt_handler_flags_buf_acq[idx] |= flag;
}
+void eos_evtq_set_busy(char busy) {
+ evt_busy = busy;
+}
+
+void 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_get(&_eos_event_q, type, selector, sel_len, buffer, len);
+ if (!rv) {
+ asm volatile ("wfi");
+ }
+ set_csr(mstatus, MSTATUS_MIE);
+ }
+}
+
void eos_evtq_loop(void) {
unsigned char type;
unsigned char *buffer;
@@ -100,7 +119,7 @@ void eos_evtq_loop(void) {
evtq_handler(type, buffer, len);
clear_csr(mstatus, MSTATUS_MIE);
} else {
- // asm volatile ("wfi");
+ if (!evt_busy) asm volatile ("wfi");
}
set_csr(mstatus, MSTATUS_MIE);
}
diff --git a/code/fe310/eos/event.h b/code/fe310/eos/event.h
index a9a98ef..3d9692d 100644
--- a/code/fe310/eos/event.h
+++ b/code/fe310/eos/event.h
@@ -10,4 +10,6 @@ void eos_evtq_pop(unsigned char *type, unsigned char **buffer, uint16_t *len);
void eos_evtq_bad_handler(unsigned char type, unsigned char *buffer, uint16_t len);
void eos_evtq_set_handler(unsigned char type, eos_evt_fptr_t handler);
void eos_evtq_set_flags(unsigned char type, uint8_t flags);
+void eos_evtq_wait(unsigned char type, unsigned char *selector, uint16_t sel_len, unsigned char **buffer, uint16_t *len);
void eos_evtq_loop(void);
+
diff --git a/code/fe310/eos/evt_def.h b/code/fe310/eos/evt_def.h
index a011638..ee08d7d 100644
--- a/code/fe310/eos/evt_def.h
+++ b/code/fe310/eos/evt_def.h
@@ -1,12 +1,12 @@
#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_USER 0x80
+#define EOS_EVT_TIMER 0x10
+#define EOS_EVT_AUDIO 0x20
+#define EOS_EVT_NET 0x30
+#define EOS_EVT_SPI 0x40
+#define EOS_EVT_USER 0x50
+#define EOS_EVT_MAX_EVT 8
#define EOS_EVT_MASK 0xF0
-#define EOS_EVT_MAX_EVT 8
#define EOS_EVT_SIZE_Q 4
diff --git a/code/fe310/eos/msgq.c b/code/fe310/eos/msgq.c
index 0c5d8f1..98ec4aa 100644
--- a/code/fe310/eos/msgq.c
+++ b/code/fe310/eos/msgq.c
@@ -42,13 +42,13 @@ void eos_msgq_pop(EOSMsgQ *msgq, unsigned char *type, unsigned char **buffer, ui
}
}
-void eos_msgq_get(EOSMsgQ *msgq, unsigned char type, unsigned char *selector, uint16_t sel_len, unsigned char **buffer, uint16_t *len) {
+int eos_msgq_get(EOSMsgQ *msgq, unsigned char type, unsigned char *selector, uint16_t sel_len, unsigned char **buffer, uint16_t *len) {
uint8_t i, j, idx;
if (msgq->idx_r == msgq->idx_w) {
*buffer = NULL;
*len = 0;
- return;
+ return 0;
}
idx = EOS_MSGQ_IDX_MASK(msgq->idx_r, msgq->size);
@@ -57,7 +57,7 @@ void eos_msgq_get(EOSMsgQ *msgq, unsigned char type, unsigned char *selector, ui
*len = msgq->array[idx].len;
if ((selector == NULL) || (sel_len == 0) || ((sel_len <= *len) && (memcmp(selector, *buffer, sel_len) == 0))) {
msgq->idx_r++;
- return;
+ return 1;
}
}
for (i = msgq->idx_r + 1; EOS_MSGQ_IDX_LT(i, msgq->idx_w); i++) {
@@ -70,11 +70,12 @@ void eos_msgq_get(EOSMsgQ *msgq, unsigned char type, unsigned char *selector, ui
msgq->array[EOS_MSGQ_IDX_MASK(j - 1, msgq->size)] = msgq->array[EOS_MSGQ_IDX_MASK(j, msgq->size)];
}
msgq->idx_w--;
- return;
+ return 1;
}
}
}
*buffer = NULL;
*len = 0;
+ return 0;
}
diff --git a/code/fe310/eos/msgq.h b/code/fe310/eos/msgq.h
index a280357..aea4273 100644
--- a/code/fe310/eos/msgq.h
+++ b/code/fe310/eos/msgq.h
@@ -16,4 +16,4 @@ typedef struct EOSMsgQ {
void eos_msgq_init(EOSMsgQ *msgq, EOSMsgItem *array, uint8_t size);
int eos_msgq_push(EOSMsgQ *msgq, unsigned char type, unsigned char *buffer, uint16_t len);
void eos_msgq_pop(EOSMsgQ *msgq, unsigned char *type, unsigned char **buffer, uint16_t *len);
-void eos_msgq_get(EOSMsgQ *msgq, unsigned char type, unsigned char *selector, uint16_t sel_len, unsigned char **buffer, uint16_t *len); \ No newline at end of file
+int eos_msgq_get(EOSMsgQ *msgq, unsigned char type, unsigned char *selector, uint16_t sel_len, unsigned char **buffer, uint16_t *len); \ No newline at end of file