summaryrefslogtreecommitdiff
path: root/code/fe310/eos
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2019-08-30 13:38:17 +0200
committerUros Majstorovic <majstor@majstor.org>2019-08-30 13:38:17 +0200
commit37a18889be8efa08c9e054014ca7058768b51a61 (patch)
tree717f965d550394b3ef473c1184e5a05391a53a48 /code/fe310/eos
parent0fdc7ebc120b99bef9338630e954e773acf15018 (diff)
event flags cleanup; added user event type
Diffstat (limited to 'code/fe310/eos')
-rw-r--r--code/fe310/eos/ecp.c2
-rw-r--r--code/fe310/eos/eos.c2
-rw-r--r--code/fe310/eos/event.c27
-rw-r--r--code/fe310/eos/event.h4
-rw-r--r--code/fe310/eos/evt_def.h17
-rw-r--r--code/fe310/eos/i2s.c2
-rw-r--r--code/fe310/eos/net.c35
-rw-r--r--code/fe310/eos/net.h2
-rw-r--r--code/fe310/eos/net_def.h5
9 files changed, 51 insertions, 45 deletions
diff --git a/code/fe310/eos/ecp.c b/code/fe310/eos/ecp.c
index 06a3fc3..9297ccd 100644
--- a/code/fe310/eos/ecp.c
+++ b/code/fe310/eos/ecp.c
@@ -59,7 +59,7 @@ int ecp_init(ECPContext *ctx) {
rv = ecp_ctx_create_vconn(ctx);
if (rv) return rv;
- eos_evtq_set_handler(EOS_EVT_TIMER, timer_handler, EOS_EVT_FLAG_WRAP);
+ eos_evtq_set_handler(EOS_EVT_TIMER, timer_handler, EOS_EVT_FLAG_NET_BUF_ACQ);
eos_net_set_handler(EOS_NET_CMD_PKT, packet_handler, 0);
return ECP_OK;
}
diff --git a/code/fe310/eos/eos.c b/code/fe310/eos/eos.c
index 163edfa..3ad3b68 100644
--- a/code/fe310/eos/eos.c
+++ b/code/fe310/eos/eos.c
@@ -13,5 +13,5 @@ void eos_init(void) {
}
void eos_start(void) {
- eos_net_start(9);
+ eos_net_start(15);
} \ No newline at end of file
diff --git a/code/fe310/eos/event.c b/code/fe310/eos/event.c
index f7ee4ef..1cffb26 100644
--- a/code/fe310/eos/event.c
+++ b/code/fe310/eos/event.c
@@ -14,7 +14,7 @@ static EOSMsgItem event_q_array[EOS_EVT_SIZE_Q];
static eos_evt_fptr_t evt_handler[EOS_EVT_MAX_EVT];
static uint16_t evt_handler_wrapper_acq = 0;
-static uint16_t evt_handler_wrapper_en = 0;
+static uint16_t evt_handler_flags_buf_acq = 0;
void eos_evtq_init(void) {
int i;
@@ -42,7 +42,7 @@ void eos_evtq_bad_handler(unsigned char cmd, unsigned char *buffer, uint16_t len
write(1, "error\n", 6);
}
-void eos_evtq_handler_wrapper(unsigned char cmd, unsigned char *buffer, uint16_t len, uint16_t *flags_acq, uint16_t flag, eos_evt_fptr_t f) {
+static void evtq_handler_wrapper(unsigned char cmd, unsigned char *buffer, uint16_t len, uint16_t *flags_acq, uint16_t flag, eos_evt_fptr_t f) {
int ok = eos_net_acquire(*flags_acq & flag);
if (ok) {
f(cmd, buffer, len);
@@ -54,20 +54,28 @@ void eos_evtq_handler_wrapper(unsigned char cmd, unsigned char *buffer, uint16_t
}
}
-void eos_evtq_handle(unsigned char cmd, unsigned char *buffer, uint16_t len) {
+static void evtq_handler(unsigned char cmd, unsigned char *buffer, uint16_t len) {
if (((cmd & EOS_EVT_MASK) >> 4) > EOS_EVT_MAX_EVT) {
eos_evtq_bad_handler(cmd, buffer, len);
} else {
unsigned char idx = ((cmd & EOS_EVT_MASK) >> 4) - 1;
uint16_t flag = (uint16_t)1 << idx;
- if (flag & evt_handler_wrapper_en) {
- eos_evtq_handler_wrapper(cmd, buffer, len, &evt_handler_wrapper_acq, flag, evt_handler[idx]);
+ if (flag & evt_handler_flags_buf_acq) {
+ evtq_handler_wrapper(cmd, buffer, len, &evt_handler_wrapper_acq, flag, evt_handler[idx]);
} else {
evt_handler[idx](cmd, buffer, len);
}
}
}
+void eos_evtq_set_handler(unsigned char cmd, eos_evt_fptr_t handler, uint8_t flags) {
+ if (flags) {
+ uint16_t flag = (uint16_t)1 << (((cmd & EOS_EVT_MASK) >> 4) - 1);
+ if (flags & EOS_EVT_FLAG_NET_BUF_ACQ) evt_handler_flags_buf_acq |= flag;
+ }
+ evt_handler[((cmd & EOS_EVT_MASK) >> 4) - 1] = handler;
+}
+
void eos_evtq_loop(void) {
unsigned char cmd;
unsigned char *buffer;
@@ -79,7 +87,7 @@ void eos_evtq_loop(void) {
eos_msgq_pop(&_eos_event_q, &cmd, &buffer, &len);
if (cmd) {
set_csr(mstatus, MSTATUS_MIE);
- eos_evtq_handle(cmd, buffer, len);
+ evtq_handler(cmd, buffer, len);
clear_csr(mstatus, MSTATUS_MIE);
} else {
asm volatile ("wfi");
@@ -88,11 +96,4 @@ void eos_evtq_loop(void) {
}
}
-void eos_evtq_set_handler(unsigned char cmd, eos_evt_fptr_t handler, uint8_t flags) {
- if (flags & EOS_EVT_FLAG_WRAP) {
- uint16_t flag = (uint16_t)1 << (((cmd & EOS_EVT_MASK) >> 4) - 1);
- evt_handler_wrapper_en |= flag;
- }
- evt_handler[((cmd & EOS_EVT_MASK) >> 4) - 1] = handler;
-}
diff --git a/code/fe310/eos/event.h b/code/fe310/eos/event.h
index 2dee419..8215d2b 100644
--- a/code/fe310/eos/event.h
+++ b/code/fe310/eos/event.h
@@ -8,7 +8,5 @@ void eos_evtq_init(void);
int eos_evtq_push(unsigned char cmd, unsigned char *buffer, uint16_t len);
void eos_evtq_pop(unsigned char *cmd, unsigned char **buffer, uint16_t *len);
void eos_evtq_bad_handler(unsigned char cmd, unsigned char *buffer, uint16_t len);
-void eos_evtq_handler_wrapper(unsigned char cmd, unsigned char *buffer, uint16_t len, uint16_t *flags_acq, uint16_t flag, eos_evt_fptr_t f);
-void eos_evtq_handle(unsigned char cmd, unsigned char *buffer, uint16_t len);
-void eos_evtq_loop(void);
void eos_evtq_set_handler(unsigned char cmd, eos_evt_fptr_t handler, uint8_t flags);
+void eos_evtq_loop(void);
diff --git a/code/fe310/eos/evt_def.h b/code/fe310/eos/evt_def.h
index e07b23c..a011638 100644
--- a/code/fe310/eos/evt_def.h
+++ b/code/fe310/eos/evt_def.h
@@ -1,11 +1,12 @@
-#define EOS_EVT_FLAG_WRAP 0x1
+#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_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_MASK 0xF0
+#define EOS_EVT_MASK 0xF0
-#define EOS_EVT_MAX_EVT 4
-#define EOS_EVT_SIZE_Q 4
+#define EOS_EVT_MAX_EVT 8
+#define EOS_EVT_SIZE_Q 4
diff --git a/code/fe310/eos/i2s.c b/code/fe310/eos/i2s.c
index 7d8baf4..d6e924b 100644
--- a/code/fe310/eos/i2s.c
+++ b/code/fe310/eos/i2s.c
@@ -154,7 +154,7 @@ void eos_i2s_init(uint32_t sample_rate) {
for (i=0; i<I2S_MAX_HANDLER; i++) {
evt_handler[i] = eos_evtq_bad_handler;
}
- eos_evtq_set_handler(EOS_EVT_AUDIO, audio_handler, EOS_EVT_FLAG_WRAP);
+ eos_evtq_set_handler(EOS_EVT_AUDIO, audio_handler, EOS_EVT_FLAG_NET_BUF_ACQ);
}
extern void _eos_set_pwm(void);
diff --git a/code/fe310/eos/net.c b/code/fe310/eos/net.c
index 7ef1745..32b293a 100644
--- a/code/fe310/eos/net.c
+++ b/code/fe310/eos/net.c
@@ -38,7 +38,8 @@ uint8_t _eos_spi_state_next_cnt = 0;
unsigned char *_eos_spi_state_next_buf = NULL;
static eos_evt_fptr_t evt_handler[EOS_NET_MAX_CMD];
-static uint16_t evt_handler_wrapper_en = 0;
+static uint16_t evt_handler_flags_buf_free = 0;
+static uint16_t evt_handler_flags_buf_acq = 0;
static int spi_bufq_push(unsigned char *buffer) {
_eos_spi_buf_q.array[SPI_BUFQ_IDX_MASK(_eos_spi_buf_q.idx_w++)] = buffer;
@@ -53,6 +54,7 @@ static unsigned char *spi_bufq_pop(void) {
static void spi_xchg_reset(void) {
_eos_spi_state_flags &= ~SPI_FLAG_CTS;
_eos_spi_state_flags |= SPI_FLAG_RST;
+
// before starting a transaction, set SPI peripheral to desired mode
SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_HOLD;
@@ -211,20 +213,29 @@ static void net_handler(unsigned char cmd, unsigned char *buffer, uint16_t len)
eos_evtq_bad_handler(cmd, buffer, len);
} else {
unsigned char idx = (cmd & ~EOS_EVT_MASK) - 1;
- uint16_t wrap = ((uint16_t)1 << idx) & evt_handler_wrapper_en;
+ 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 (wrap) {
- eos_net_free(buffer, 1);
+ if (buf_free) {
+ eos_net_free(buffer, buf_acq);
buffer = NULL;
len = 0;
}
evt_handler[idx](cmd, buffer, len);
- if (wrap) eos_net_release();
+ if (buf_free && buf_acq) eos_net_release();
}
}
+void eos_net_set_handler(unsigned char cmd, eos_evt_fptr_t handler, uint8_t flags) {
+ if (flags) {
+ uint16_t flag = (uint16_t)1 << ((cmd & ~EOS_EVT_MASK) - 1);
+ 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[(cmd & ~EOS_EVT_MASK) - 1] = handler;
+}
void eos_net_init(void) {
int i;
@@ -304,14 +315,6 @@ void eos_net_stop(void) {
}
}
-void eos_net_set_handler(unsigned char cmd, eos_evt_fptr_t handler, uint8_t flags) {
- if (flags & EOS_EVT_FLAG_WRAP) {
- uint16_t flag = (uint16_t)1 << ((cmd & ~EOS_EVT_MASK) - 1);
- evt_handler_wrapper_en |= flag;
- }
- evt_handler[(cmd & ~EOS_EVT_MASK) - 1] = handler;
-}
-
int eos_net_acquire(unsigned char reserved) {
int ret = 0;
@@ -366,12 +369,12 @@ unsigned char *eos_net_alloc(void) {
return ret;
}
-int eos_net_free(unsigned char *buffer, unsigned char reserve) {
+int eos_net_free(unsigned char *buffer, unsigned char more) {
int rv = EOS_OK;
uint8_t do_release = 1;
clear_csr(mstatus, MSTATUS_MIE);
- if ((reserve || _eos_spi_state_next_cnt) && (_eos_spi_state_next_buf == NULL)) {
+ if ((more || _eos_spi_state_next_cnt) && (_eos_spi_state_next_buf == NULL)) {
_eos_spi_state_next_buf = buffer;
} else {
if ((_eos_spi_state_flags & SPI_FLAG_RDY) && (_eos_spi_state_flags & SPI_FLAG_CTS)) do_release = spi_xchg_next(buffer);
@@ -389,7 +392,7 @@ int eos_net_send(unsigned char cmd, unsigned char *buffer, uint16_t len) {
if ((_eos_spi_state_flags & SPI_FLAG_RDY) && (_eos_spi_state_flags & SPI_FLAG_CTS)) {
spi_xchg_start(cmd, buffer, len);
} else {
- rv = eos_msgq_push(&_eos_spi_send_q, cmd, buffer, len);
+ rv = eos_msgq_push(&_eos_spi_send_q, EOS_EVT_NET | cmd, buffer, len);
}
set_csr(mstatus, MSTATUS_MIE);
diff --git a/code/fe310/eos/net.h b/code/fe310/eos/net.h
index 8c15efa..d09cd96 100644
--- a/code/fe310/eos/net.h
+++ b/code/fe310/eos/net.h
@@ -10,5 +10,5 @@ void eos_net_set_handler(unsigned char cmd, eos_evt_fptr_t handler, uint8_t flag
int eos_net_acquire(unsigned char reserved);
int eos_net_release(void);
unsigned char *eos_net_alloc(void);
-int eos_net_free(unsigned char *buffer, unsigned char reserve_next);
+int eos_net_free(unsigned char *buffer, unsigned char more);
int eos_net_send(unsigned char cmd, unsigned char *buffer, uint16_t len);
diff --git a/code/fe310/eos/net_def.h b/code/fe310/eos/net_def.h
index 18e9417..a7766f2 100644
--- a/code/fe310/eos/net_def.h
+++ b/code/fe310/eos/net_def.h
@@ -1,3 +1,6 @@
+#define EOS_NET_FLAG_BUF_FREE 0x1
+#define EOS_NET_FLAG_BUF_ACQ 0x2
+
#define EOS_NET_CMD_FLAG_ONEW 0x10
#define EOS_NET_CMD_CONNECT 1
@@ -5,4 +8,4 @@
#define EOS_NET_CMD_SCAN 3
#define EOS_NET_CMD_PKT 4
-#define EOS_NET_MAX_CMD 4
+#define EOS_NET_MAX_CMD 8