summaryrefslogtreecommitdiff
path: root/code/fe310/eos/event.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2020-08-05 03:39:22 +0200
committerUros Majstorovic <majstor@majstor.org>2020-08-05 03:39:22 +0200
commitcf7c06297d04bade9cd04c056f9ed510e64dd7bd (patch)
treea3b8cc23574b98e10874b51d33c9fe1bfc012663 /code/fe310/eos/event.c
parent5cd610a07468137066ea4daa5176c3e7045113b0 (diff)
code -> fw
Diffstat (limited to 'code/fe310/eos/event.c')
-rw-r--r--code/fe310/eos/event.c138
1 files changed, 0 insertions, 138 deletions
diff --git a/code/fe310/eos/event.c b/code/fe310/eos/event.c
deleted file mode 100644
index 6953dca..0000000
--- a/code/fe310/eos/event.c
+++ /dev/null
@@ -1,138 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#include "encoding.h"
-#include "platform.h"
-
-#include "msgq.h"
-#include "event.h"
-
-EOSMsgQ _eos_event_q;
-static EOSMsgItem event_q_array[EOS_EVT_SIZE_Q];
-
-static eos_evt_handler_t evt_handler[EOS_EVT_MAX_EVT + 1];
-
-static void evtq_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
- unsigned char idx = (type & EOS_EVT_MASK) >> 4;
-
- if (idx && (idx <= EOS_EVT_MAX_EVT)) {
- evt_handler[idx](type, buffer, len);
- } else {
- eos_evtq_bad_handler(type, buffer, len);
- }
-}
-
-void eos_evtq_init(void) {
- int i;
-
- evt_handler[0] = evtq_handler;
- for (i=0; i<EOS_EVT_MAX_EVT; i++) {
- evt_handler[i + 1] = eos_evtq_bad_handler;
- }
- eos_msgq_init(&_eos_event_q, event_q_array, EOS_EVT_SIZE_Q);
-}
-
-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, type, buffer, len);
- set_csr(mstatus, MSTATUS_MIE);
- return ret;
-}
-
-int eos_evtq_push_isr(unsigned char type, unsigned char *buffer, uint16_t len) {
- return eos_msgq_push(&_eos_event_q, type, buffer, 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);
-}
-
-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_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) {
- unsigned char _type;
- unsigned char *_buffer;
- uint16_t _len;
-
- eos_msgq_pop(&_eos_event_q, &_type, &_buffer, &_len);
- if (_type) {
- set_csr(mstatus, MSTATUS_MIE);
- evt_handler[0](_type, _buffer, _len);
- } else {
- asm volatile ("wfi");
- set_csr(mstatus, MSTATUS_MIE);
- }
- } else {
- set_csr(mstatus, MSTATUS_MIE);
- }
- }
-}
-
-void eos_evtq_flush(void) {
- clear_csr(mstatus, MSTATUS_MIE);
- eos_evtq_flush_isr();
- set_csr(mstatus, MSTATUS_MIE);
-}
-
-void eos_evtq_flush_isr(void) {
- unsigned char type;
- unsigned char *buffer;
- uint16_t len;
-
- do {
- eos_msgq_pop(&_eos_event_q, &type, &buffer, &len);
- if (type) {
- set_csr(mstatus, MSTATUS_MIE);
- evt_handler[0](type, buffer, len);
- clear_csr(mstatus, MSTATUS_MIE);
- }
- } while (type);
-}
-
-void eos_evtq_loop(void) {
- 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, &type, &buffer, &len);
- if (type) {
- set_csr(mstatus, MSTATUS_MIE);
- evt_handler[0](type, buffer, len);
- } else {
- asm volatile ("wfi");
- set_csr(mstatus, MSTATUS_MIE);
- }
- }
-}
-
-void eos_evtq_bad_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
- printf("evt bad handler:0x%x\n", type);
-}
-
-void eos_evtq_set_handler(unsigned char type, eos_evt_handler_t handler) {
- unsigned char idx = (type & EOS_EVT_MASK) >> 4;
-
- if (idx <= EOS_EVT_MAX_EVT) evt_handler[idx] = handler;
-}
-
-eos_evt_handler_t eos_evtq_get_handler(unsigned char type) {
- unsigned char idx = (type & EOS_EVT_MASK) >> 4;
-
- if (idx <= EOS_EVT_MAX_EVT) return evt_handler[idx];
- return NULL;
-}