summaryrefslogtreecommitdiff
path: root/code/fe310/eos
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2019-12-06 20:04:08 +0100
committerUros Majstorovic <majstor@majstor.org>2019-12-06 20:04:08 +0100
commit0bcbb62eb408e6fcbfe78fbc2756dfb1b9ae6a37 (patch)
tree8517595e723686fd8954f0640c5fc40c36e88a67 /code/fe310/eos
parentbc37c471fbb233a2a17119091b10f7adf8045a95 (diff)
net refactor: alloc reverted to take void arg; EOS_NET_FLAGs renamed
Diffstat (limited to 'code/fe310/eos')
-rw-r--r--code/fe310/eos/event.c4
-rw-r--r--code/fe310/eos/evt_def.h2
-rw-r--r--code/fe310/eos/i2s.c3
-rw-r--r--code/fe310/eos/net.c18
-rw-r--r--code/fe310/eos/net.h23
-rw-r--r--code/fe310/eos/sock.c8
-rw-r--r--code/fe310/eos/wifi.c8
7 files changed, 33 insertions, 33 deletions
diff --git a/code/fe310/eos/event.c b/code/fe310/eos/event.c
index cc9c5de..9371ca7 100644
--- a/code/fe310/eos/event.c
+++ b/code/fe310/eos/event.c
@@ -47,7 +47,7 @@ static void evtq_handler_wrapper(unsigned char type, unsigned char *buffer, uint
uint16_t flag = (uint16_t)1 << ((type & ~EOS_EVT_MASK) - 1);
int ok;
- ok = eos_net_acquire(evt_handler_wrapper_acq[idx] & flag);
+ ok = _eos_net_acquire(evt_handler_wrapper_acq[idx] & flag);
if (ok) {
evt_handler[idx](type, buffer, len);
eos_net_release();
@@ -83,7 +83,7 @@ void eos_evtq_set_flags(unsigned char type, uint8_t flags) {
unsigned char idx = ((type & EOS_EVT_MASK) >> 4) - 1;
uint16_t flag = type & ~EOS_EVT_MASK ? (uint16_t)1 << ((type & ~EOS_EVT_MASK) - 1) : 0xFFFF;
- if ((idx < EOS_EVT_MAX_EVT) && (flags & EOS_EVT_FLAG_NET_BUF_ACQ)) evt_handler_flags_buf_acq[idx] |= flag;
+ if ((idx < EOS_EVT_MAX_EVT) && (flags & EOS_NET_FLAG_BACQ)) evt_handler_flags_buf_acq[idx] |= flag;
}
void eos_evtq_get(unsigned char type, unsigned char *selector, uint16_t sel_len, unsigned char **buffer, uint16_t *len) {
diff --git a/code/fe310/eos/evt_def.h b/code/fe310/eos/evt_def.h
index ee08d7d..529ee72 100644
--- a/code/fe310/eos/evt_def.h
+++ b/code/fe310/eos/evt_def.h
@@ -1,5 +1,3 @@
-#define EOS_EVT_FLAG_NET_BUF_ACQ 0x1
-
#define EOS_EVT_TIMER 0x10
#define EOS_EVT_AUDIO 0x20
#define EOS_EVT_NET 0x30
diff --git a/code/fe310/eos/i2s.c b/code/fe310/eos/i2s.c
index 4c36d55..d71a31d 100644
--- a/code/fe310/eos/i2s.c
+++ b/code/fe310/eos/i2s.c
@@ -8,6 +8,7 @@
#include "eos.h"
#include "interrupt.h"
#include "event.h"
+#include "net.h"
#include "i2s.h"
#include "i2s_def.h"
@@ -114,7 +115,7 @@ extern void _eos_i2s_start_pwm(void);
void eos_i2s_init(void) {
eos_evtq_set_handler(EOS_EVT_AUDIO, i2s_handler_evt);
- eos_evtq_set_flags(EOS_EVT_AUDIO | I2S_ETYPE_MIC, EOS_EVT_FLAG_NET_BUF_ACQ);
+ eos_evtq_set_flags(EOS_EVT_AUDIO | I2S_ETYPE_MIC, EOS_NET_FLAG_BACQ);
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK);
diff --git a/code/fe310/eos/net.c b/code/fe310/eos/net.c
index 9f19b4b..319a3f5 100644
--- a/code/fe310/eos/net.c
+++ b/code/fe310/eos/net.c
@@ -237,8 +237,8 @@ void eos_net_set_handler(unsigned char mtype, eos_evt_fptr_t handler, uint8_t fl
}
if (flags) {
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;
+ if (flags & EOS_NET_FLAG_BFREE) evt_handler_flags_buf_free |= flag;
+ if (flags & EOS_NET_FLAG_BACQ) evt_handler_flags_buf_acq |= flag;
}
evt_handler[mtype] = handler;
}
@@ -298,7 +298,7 @@ void eos_net_stop(void) {
}
}
-int eos_net_acquire(unsigned char reserved) {
+int _eos_net_acquire(unsigned char reserved) {
int ret = 0;
if (reserved) {
@@ -322,6 +322,11 @@ int eos_net_acquire(unsigned char reserved) {
return ret;
}
+void eos_net_acquire(void) {
+ unsigned char acq = _eos_net_acquire(0);
+ if (!acq) _eos_net_acquire(1);
+}
+
void eos_net_release(void) {
clear_csr(mstatus, MSTATUS_MIE);
if (!net_state_next_cnt && net_state_next_buf) {
@@ -331,14 +336,9 @@ void eos_net_release(void) {
set_csr(mstatus, MSTATUS_MIE);
}
-unsigned char *eos_net_alloc(unsigned char acquired) {
+unsigned char *eos_net_alloc(void) {
unsigned char *ret = NULL;
- if (!acquired) {
- unsigned char acq = eos_net_acquire(0);
- if (!acq) eos_net_acquire(1);
- }
-
clear_csr(mstatus, MSTATUS_MIE);
ret = net_state_next_buf;
net_state_next_buf = NULL;
diff --git a/code/fe310/eos/net.h b/code/fe310/eos/net.h
index a68cd77..127942c 100644
--- a/code/fe310/eos/net.h
+++ b/code/fe310/eos/net.h
@@ -1,18 +1,18 @@
#include <stdint.h>
#include "event.h"
-#define EOS_NET_FLAG_BUF_FREE 0x1
-#define EOS_NET_FLAG_BUF_ACQ 0x2
+#define EOS_NET_FLAG_BACQ 0x1
+#define EOS_NET_FLAG_BFREE 0x2
-#define EOS_NET_MTYPE_SOCK 1
-#define EOS_NET_MTYPE_AUDIO 2
+#define EOS_NET_MTYPE_SOCK 1
+#define EOS_NET_MTYPE_AUDIO 2
-#define EOS_NET_MTYPE_WIFI 5
-#define EOS_NET_MTYPE_CELL 6
-#define EOS_NET_MTYPE_SIP 7
-#define EOS_NET_MTYPE_APP 8
+#define EOS_NET_MTYPE_WIFI 5
+#define EOS_NET_MTYPE_CELL 6
+#define EOS_NET_MTYPE_SIP 7
+#define EOS_NET_MTYPE_APP 8
-#define EOS_NET_MAX_MTYPE 8
+#define EOS_NET_MAX_MTYPE 8
void eos_net_xchg_done(void);
@@ -20,8 +20,9 @@ void eos_net_init(void);
void eos_net_start(void);
void eos_net_stop(void);
void eos_net_set_handler(unsigned char type, eos_evt_fptr_t handler, uint8_t flags);
-int eos_net_acquire(unsigned char reserved);
+int _eos_net_acquire(unsigned char reserved);
+void eos_net_acquire(void);
void eos_net_release(void);
-unsigned char *eos_net_alloc(unsigned char acquired);
+unsigned char *eos_net_alloc(void);
void eos_net_free(unsigned char *buffer, unsigned char more);
int eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char more);
diff --git a/code/fe310/eos/sock.c b/code/fe310/eos/sock.c
index b690dc4..2c6ba5d 100644
--- a/code/fe310/eos/sock.c
+++ b/code/fe310/eos/sock.c
@@ -48,7 +48,7 @@ void eos_sock_init(void) {
int eos_sock_open_udp(void) {
unsigned char type = EOS_SOCK_MTYPE_OPEN_DGRAM;
- unsigned char *buffer = eos_net_alloc(1);
+ unsigned char *buffer = eos_net_alloc();
uint16_t buf_size;
int rv, sock;
@@ -70,7 +70,7 @@ int eos_sock_open_udp(void) {
}
void eos_sock_close(int sock) {
- unsigned char *buffer = eos_net_alloc(1);
+ unsigned char *buffer = eos_net_alloc();
buffer[0] = EOS_SOCK_MTYPE_CLOSE;
buffer[1] = sock;
eos_net_send(EOS_NET_MTYPE_SOCK, buffer, 2, 1);
@@ -100,8 +100,8 @@ void eos_sock_set_handler(int sock, eos_sock_fptr_t handler, uint8_t flags) {
}
if (flags) {
uint16_t flag = (uint16_t)1 << sock;
- if (flags & EOS_NET_FLAG_BUF_FREE) sock_handler_flags_buf_free |= flag;
- if (flags & EOS_NET_FLAG_BUF_ACQ) sock_handler_flags_buf_acq |= flag;
+ if (flags & EOS_NET_FLAG_BFREE) sock_handler_flags_buf_free |= flag;
+ if (flags & EOS_NET_FLAG_BACQ) sock_handler_flags_buf_acq |= flag;
}
sock_handler[sock] = handler;
}
diff --git a/code/fe310/eos/wifi.c b/code/fe310/eos/wifi.c
index 95fec7d..67682aa 100644
--- a/code/fe310/eos/wifi.c
+++ b/code/fe310/eos/wifi.c
@@ -46,7 +46,7 @@ void eos_wifi_init(void) {
void eos_wifi_connect(const char *ssid, const char *pass) {
int ssid_len = strlen(ssid);
int pass_len = strlen(pass);
- unsigned char *buffer = eos_net_alloc(0);
+ unsigned char *buffer = eos_net_alloc();
buffer[0] = EOS_WIFI_MTYPE_CONNECT;
strcpy(buffer+1, ssid);
@@ -57,7 +57,7 @@ void eos_wifi_connect(const char *ssid, const char *pass) {
}
void eos_wifi_disconnect(void) {
- unsigned char *buffer = eos_net_alloc(0);
+ unsigned char *buffer = eos_net_alloc();
buffer[0] = EOS_WIFI_MTYPE_DISCONNECT;
eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0);
}
@@ -69,8 +69,8 @@ void eos_wifi_set_handler(int mtype, eos_wifi_fptr_t handler, uint8_t flags) {
if (flags) {
uint16_t flag = (uint16_t)1 << mtype;
- if (flags & EOS_NET_FLAG_BUF_FREE) wifi_handler_flags_buf_free |= flag;
- if (flags & EOS_NET_FLAG_BUF_ACQ) wifi_handler_flags_buf_acq |= flag;
+ if (flags & EOS_NET_FLAG_BFREE) wifi_handler_flags_buf_free |= flag;
+ if (flags & EOS_NET_FLAG_BACQ) wifi_handler_flags_buf_acq |= flag;
}
wifi_handler[mtype] = handler;
}