summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/cell.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 /fw/fe310/eos/cell.c
parent5cd610a07468137066ea4daa5176c3e7045113b0 (diff)
code -> fw
Diffstat (limited to 'fw/fe310/eos/cell.c')
-rw-r--r--fw/fe310/eos/cell.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/fw/fe310/eos/cell.c b/fw/fe310/eos/cell.c
new file mode 100644
index 0000000..2421f4b
--- /dev/null
+++ b/fw/fe310/eos/cell.c
@@ -0,0 +1,48 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "eos.h"
+#include "event.h"
+#include "net.h"
+
+#include "cell.h"
+
+static eos_evt_handler_t evt_handler[EOS_CELL_MAX_MTYPE];
+
+static void cell_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
+ if ((buffer == NULL) || (len < 1)) {
+ eos_net_bad_handler(type, buffer, len);
+ return;
+ }
+ unsigned char mtype = buffer[0];
+ unsigned char idx = (mtype & EOS_CELL_MTYPE_MASK) >> 4;
+
+ if (idx < EOS_CELL_MAX_MTYPE) {
+ evt_handler[idx](type, buffer, len);
+ } else {
+ eos_net_bad_handler(type, buffer, len);
+ }
+}
+
+static void cell_handle_rdy(unsigned char type, unsigned char *buffer, uint16_t len) {
+ // Do nothing
+ eos_net_free(buffer, 0);
+}
+
+void eos_cell_init(void) {
+ int i;
+
+ for (i=0; i<EOS_CELL_MAX_MTYPE; i++) {
+ evt_handler[i] = eos_net_bad_handler;
+ }
+ eos_net_set_handler(EOS_NET_MTYPE_CELL, cell_handle_evt);
+ eos_cell_set_handler(EOS_CELL_MTYPE_READY, cell_handle_rdy);
+}
+
+void eos_cell_set_handler(unsigned char mtype, eos_evt_handler_t handler) {
+ unsigned char idx = (mtype & EOS_CELL_MTYPE_MASK) >> 4;
+
+ if (handler == NULL) handler = eos_net_bad_handler;
+ if (idx < EOS_CELL_MAX_MTYPE) evt_handler[idx] = handler;
+}