From 2e6facf66ee3d6aa37f2fb41096b1763261506a7 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sat, 7 Dec 2019 17:17:21 +0100 Subject: eos evtq flags refactor; net buf flags refator for all modules --- code/fe310/eos/eos.c | 4 ++ code/fe310/eos/eos.h | 4 +- code/fe310/eos/event.c | 4 ++ code/fe310/eos/event.h | 1 + code/fe310/eos/evt_def.h | 3 +- code/fe310/eos/i2s.c | 29 +++++----- code/fe310/eos/i2s.h | 4 +- code/fe310/eos/irq_def.h | 4 +- code/fe310/eos/msgq.c | 2 +- code/fe310/eos/net.c | 128 +++++++++++++++++++++++--------------------- code/fe310/eos/net.h | 3 ++ code/fe310/eos/sock.c | 45 +++++++--------- code/fe310/eos/sock.h | 6 +-- code/fe310/eos/spi.c | 35 ++++++------ code/fe310/eos/spi.h | 3 +- code/fe310/eos/timer.c | 44 ++++++++------- code/fe310/eos/timer.h | 3 +- code/fe310/eos/trap_entry.S | 2 +- code/fe310/eos/wifi.c | 43 ++++++--------- code/fe310/eos/wifi.h | 6 +-- 20 files changed, 191 insertions(+), 182 deletions(-) (limited to 'code') diff --git a/code/fe310/eos/eos.c b/code/fe310/eos/eos.c index a0bf4c9..bb231d1 100644 --- a/code/fe310/eos/eos.c +++ b/code/fe310/eos/eos.c @@ -2,9 +2,11 @@ #include "interrupt.h" #include "timer.h" #include "i2s.h" +#include "uart.h" #include "spi.h" #include "net.h" #include "wifi.h" +#include "cell.h" #include "sock.h" #include "eve.h" @@ -15,9 +17,11 @@ void eos_init(void) { eos_intr_init(); eos_timer_init(); eos_i2s_init(); + eos_uart_init(); eos_spi_init(); eos_net_init(); eos_wifi_init(); + eos_cell_init(); eos_sock_init(); eos_spi_dev_start(EOS_SPI_DEV_DISP); eos_eve_init(); diff --git a/code/fe310/eos/eos.h b/code/fe310/eos/eos.h index f1d7907..08bd10b 100644 --- a/code/fe310/eos/eos.h +++ b/code/fe310/eos/eos.h @@ -1,7 +1,7 @@ #define EOS_OK 0 #define EOS_ERR -1 -#define EOS_ERR_Q_FULL -10 -#define EOS_ERR_Q_EMPTY -11 +#define EOS_ERR_FULL -10 +#define EOS_ERR_EMPTY -11 #define EOS_ERR_NET -20 void eos_init(void); diff --git a/code/fe310/eos/event.c b/code/fe310/eos/event.c index 9371ca7..ed313fb 100644 --- a/code/fe310/eos/event.c +++ b/code/fe310/eos/event.c @@ -32,6 +32,10 @@ int eos_evtq_push(unsigned char type, unsigned char *buffer, uint16_t len) { 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); diff --git a/code/fe310/eos/event.h b/code/fe310/eos/event.h index 8a16dfd..6beb263 100644 --- a/code/fe310/eos/event.h +++ b/code/fe310/eos/event.h @@ -6,6 +6,7 @@ typedef void (*eos_evt_fptr_t) (unsigned char, unsigned char *, uint16_t); void eos_evtq_init(void); int eos_evtq_push(unsigned char type, unsigned char *buffer, uint16_t len); +int eos_evtq_push_isr(unsigned char type, unsigned char *buffer, uint16_t len); 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); diff --git a/code/fe310/eos/evt_def.h b/code/fe310/eos/evt_def.h index 529ee72..0cd63bb 100644 --- a/code/fe310/eos/evt_def.h +++ b/code/fe310/eos/evt_def.h @@ -2,7 +2,8 @@ #define EOS_EVT_AUDIO 0x20 #define EOS_EVT_NET 0x30 #define EOS_EVT_SPI 0x40 -#define EOS_EVT_USER 0x50 +#define EOS_EVT_UART 0x50 +#define EOS_EVT_USER 0x60 #define EOS_EVT_MAX_EVT 8 #define EOS_EVT_MASK 0xF0 diff --git a/code/fe310/eos/i2s.c b/code/fe310/eos/i2s.c index d71a31d..4702bc3 100644 --- a/code/fe310/eos/i2s.c +++ b/code/fe310/eos/i2s.c @@ -33,8 +33,8 @@ uint32_t _eos_i2s_spk_wm = 0; uint32_t _eos_i2s_mic_evt_enable = 0; uint32_t _eos_i2s_spk_evt_enable = 0; -static eos_i2s_fptr_t spk_evt_handler = NULL; -static eos_i2s_fptr_t mic_evt_handler = NULL; +static eos_i2s_fptr_t i2s_spk_handler = NULL; +static eos_i2s_fptr_t i2s_mic_handler = NULL; static void _abuf_init(EOSABuf *buf, uint8_t *array, uint16_t size) { buf->idx_r = 0; @@ -44,7 +44,7 @@ static void _abuf_init(EOSABuf *buf, uint8_t *array, uint16_t size) { } static int _abuf_push8(EOSABuf *buf, uint8_t sample) { - if ((uint16_t)(buf->idx_w - buf->idx_r) == buf->size) return EOS_ERR_Q_FULL; + if ((uint16_t)(buf->idx_w - buf->idx_r) == buf->size) return EOS_ERR_FULL; buf->array[EOS_ABUF_IDX_MASK(buf->idx_w, buf->size)] = sample; buf->idx_w++; @@ -52,7 +52,7 @@ static int _abuf_push8(EOSABuf *buf, uint8_t sample) { } static int _abuf_push16(EOSABuf *buf, uint16_t sample) { - if ((uint16_t)(buf->idx_w - buf->idx_r) == buf->size) return EOS_ERR_Q_FULL; + if ((uint16_t)(buf->idx_w - buf->idx_r) == buf->size) return EOS_ERR_FULL; buf->array[EOS_ABUF_IDX_MASK(buf->idx_w, buf->size)] = sample >> 8; buf->array[EOS_ABUF_IDX_MASK(buf->idx_w + 1, buf->size)] = sample & 0xFF; @@ -62,7 +62,7 @@ static int _abuf_push16(EOSABuf *buf, uint16_t sample) { static int _abuf_pop8(EOSABuf *buf, uint8_t *sample) { if (buf->idx_r == buf->idx_w) { - return EOS_ERR_Q_EMPTY; + return EOS_ERR_EMPTY; } else { *sample = buf->array[EOS_ABUF_IDX_MASK(buf->idx_r, buf->size)]; buf->idx_r++; @@ -72,7 +72,7 @@ static int _abuf_pop8(EOSABuf *buf, uint8_t *sample) { static int _abuf_pop16(EOSABuf *buf, uint16_t *sample) { if (buf->idx_r == buf->idx_w) { - return EOS_ERR_Q_EMPTY; + return EOS_ERR_EMPTY; } else { *sample = buf->array[EOS_ABUF_IDX_MASK(buf->idx_r, buf->size)] << 8; *sample |= buf->array[EOS_ABUF_IDX_MASK(buf->idx_r + 1, buf->size)]; @@ -94,13 +94,13 @@ static uint16_t _abuf_len(EOSABuf *buf) { static void i2s_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) { switch(type & ~EOS_EVT_MASK) { case I2S_ETYPE_MIC: - if (mic_evt_handler) mic_evt_handler(type); + if (i2s_mic_handler) i2s_mic_handler(type); clear_csr(mstatus, MSTATUS_MIE); _eos_i2s_mic_evt_enable = 1; set_csr(mstatus, MSTATUS_MIE); break; case I2S_ETYPE_SPK: - if (spk_evt_handler) spk_evt_handler(type); + if (i2s_spk_handler) i2s_spk_handler(type); clear_csr(mstatus, MSTATUS_MIE); _eos_i2s_spk_evt_enable = 1; set_csr(mstatus, MSTATUS_MIE); @@ -115,7 +115,6 @@ 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_NET_FLAG_BACQ); GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK); GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK); @@ -249,10 +248,12 @@ void eos_i2s_mic_init(uint8_t *mic_arr, uint16_t mic_arr_size) { set_csr(mstatus, MSTATUS_MIE); } -void eos_i2s_mic_set_handler(eos_i2s_fptr_t wm_handler) { +void eos_i2s_mic_set_handler(eos_i2s_fptr_t wm_handler, uint8_t flags) { clear_csr(mstatus, MSTATUS_MIE); - mic_evt_handler = wm_handler; + i2s_mic_handler = wm_handler; set_csr(mstatus, MSTATUS_MIE); + + if (flags) eos_evtq_set_flags(EOS_EVT_AUDIO | I2S_ETYPE_MIC, flags); } void eos_i2s_mic_set_wm(uint16_t wm) { @@ -308,10 +309,12 @@ void eos_i2s_spk_init(uint8_t *spk_arr, uint16_t spk_arr_size) { set_csr(mstatus, MSTATUS_MIE); } -void eos_i2s_spk_set_handler(eos_i2s_fptr_t wm_handler) { +void eos_i2s_spk_set_handler(eos_i2s_fptr_t wm_handler, uint8_t flags) { clear_csr(mstatus, MSTATUS_MIE); - spk_evt_handler = wm_handler; + i2s_spk_handler = wm_handler; set_csr(mstatus, MSTATUS_MIE); + + if (flags) eos_evtq_set_flags(EOS_EVT_AUDIO | I2S_ETYPE_SPK, flags); } void eos_i2s_spk_set_wm(uint16_t wm) { diff --git a/code/fe310/eos/i2s.h b/code/fe310/eos/i2s.h index 8ae7d98..af91dd3 100644 --- a/code/fe310/eos/i2s.h +++ b/code/fe310/eos/i2s.h @@ -16,14 +16,14 @@ void eos_i2s_init(void); void eos_i2s_start(uint32_t sample_rate, unsigned char fmt); void eos_i2s_stop(void); void eos_i2s_mic_init(uint8_t *mic_arr, uint16_t mic_arr_size); -void eos_i2s_mic_set_handler(eos_i2s_fptr_t wm_handler); +void eos_i2s_mic_set_handler(eos_i2s_fptr_t wm_handler, uint8_t flags); void eos_i2s_mic_set_wm(uint16_t wm); uint16_t eos_i2s_mic_len(void); uint16_t eos_i2s_mic_read(uint8_t *sample, uint16_t ssize); int eos_i2s_mic_pop8(uint8_t *sample); int eos_i2s_mic_pop16(uint16_t *sample); void eos_i2s_spk_init(uint8_t *mic_arr, uint16_t mic_arr_size); -void eos_i2s_spk_set_handler(eos_i2s_fptr_t wm_handler); +void eos_i2s_spk_set_handler(eos_i2s_fptr_t wm_handler, uint8_t flags); void eos_i2s_spk_set_wm(uint16_t wm); uint16_t eos_i2s_spk_len(void); uint16_t eos_i2s_spk_write(uint8_t *sample, uint16_t ssize); diff --git a/code/fe310/eos/irq_def.h b/code/fe310/eos/irq_def.h index 4584b01..b6a9dbb 100644 --- a/code/fe310/eos/irq_def.h +++ b/code/fe310/eos/irq_def.h @@ -4,4 +4,6 @@ #define IRQ_PRIORITY_SPI_XCHG 5 #define IRQ_PRIORITY_NET_CTS 4 -#define IRQ_PRIORITY_NET_RTS 4 \ No newline at end of file +#define IRQ_PRIORITY_NET_RTS 4 + +#define IRQ_PRIORITY_UART 1 \ No newline at end of file diff --git a/code/fe310/eos/msgq.c b/code/fe310/eos/msgq.c index d0fe405..35e0d15 100644 --- a/code/fe310/eos/msgq.c +++ b/code/fe310/eos/msgq.c @@ -20,7 +20,7 @@ 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) { - if ((uint8_t)(msgq->idx_w - msgq->idx_r) == msgq->size) return EOS_ERR_Q_FULL; + if ((uint8_t)(msgq->idx_w - msgq->idx_r) == msgq->size) return EOS_ERR_FULL; uint8_t idx = EOS_MSGQ_IDX_MASK(msgq->idx_w, msgq->size); msgq->array[idx].type = type; diff --git a/code/fe310/eos/net.c b/code/fe310/eos/net.c index 319a3f5..f3a82b8 100644 --- a/code/fe310/eos/net.c +++ b/code/fe310/eos/net.c @@ -44,7 +44,6 @@ static eos_evt_fptr_t evt_handler[EOS_NET_MAX_MTYPE]; static uint16_t evt_handler_flags_buf_free = 0; static uint16_t evt_handler_flags_buf_acq = 0; -extern EOSMsgQ _eos_event_q; extern uint32_t _eos_spi_state_len; extern uint32_t _eos_spi_state_idx_tx; extern uint32_t _eos_spi_state_idx_rx; @@ -106,7 +105,39 @@ static void net_xchg_start(unsigned char type, unsigned char *buffer, uint16_t l SPI1_REG(SPI_REG_IE) = SPI_IP_RXWM; } -static void net_xchg_handler(void) { +static int net_xchg_next(unsigned char *_buffer) { + unsigned char type; + unsigned char *buffer = NULL; + uint16_t len; + + eos_msgq_pop(&net_send_q, &type, &buffer, &len); + if (type) { + net_xchg_start(type, buffer, len); + } else if (net_state_flags & NET_STATE_FLAG_RTS) { + if (_buffer == NULL) _buffer = net_bufq_pop(); + if (_buffer) { + net_xchg_start(0, _buffer, 0); + return 0; + } + } + return 1; +} + +void eos_net_xchg_done(void) { + SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_AUTO; + if (net_state_type) { + int r = eos_evtq_push_isr(EOS_EVT_NET | net_state_type, _eos_spi_state_buf, net_state_len_rx); + if (r) net_bufq_push(_eos_spi_state_buf); + } else if (((net_state_flags & NET_STATE_FLAG_ONEW) || net_state_next_cnt) && (net_state_next_buf == NULL)) { + net_state_next_buf = _eos_spi_state_buf; + net_state_flags &= ~NET_STATE_FLAG_ONEW; + } else { + net_bufq_push(_eos_spi_state_buf); + } + net_state_flags &= ~NET_STATE_FLAG_XCHG; +} + +static void net_handler_xchg(void) { volatile uint32_t r1, r2; if (net_state_flags & NET_STATE_FLAG_RST) { @@ -155,38 +186,6 @@ static void net_xchg_handler(void) { eos_spi_xchg_handler(); } -static int net_xchg_next(unsigned char *_buffer) { - unsigned char type; - unsigned char *buffer = NULL; - uint16_t len; - - eos_msgq_pop(&net_send_q, &type, &buffer, &len); - if (type) { - net_xchg_start(type, buffer, len); - } else if (net_state_flags & NET_STATE_FLAG_RTS) { - if (_buffer == NULL) _buffer = net_bufq_pop(); - if (_buffer) { - net_xchg_start(0, _buffer, 0); - return 0; - } - } - return 1; -} - -void eos_net_xchg_done(void) { - SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_AUTO; - if (net_state_type) { - int r = eos_msgq_push(&_eos_event_q, EOS_EVT_NET | net_state_type, _eos_spi_state_buf, net_state_len_rx); - if (r) net_bufq_push(_eos_spi_state_buf); - } else if (((net_state_flags & NET_STATE_FLAG_ONEW) || net_state_next_cnt) && (net_state_next_buf == NULL)) { - net_state_next_buf = _eos_spi_state_buf; - net_state_flags &= ~NET_STATE_FLAG_ONEW; - } else { - net_bufq_push(_eos_spi_state_buf); - } - net_state_flags &= ~NET_STATE_FLAG_XCHG; -} - static void net_handler_cts(void) { GPIO_REG(GPIO_RISE_IP) = (1 << NET_PIN_CTS); net_state_flags |= NET_STATE_FLAG_CTS; @@ -210,37 +209,13 @@ static void net_handler_rts(void) { static void net_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) { unsigned char idx = (type & ~EOS_EVT_MASK) - 1; - 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 (idx >= EOS_NET_MAX_MTYPE) { eos_evtq_bad_handler(type, buffer, len); eos_net_free(buffer, 0); return; } - if (buf_free) { - eos_net_free(buffer, buf_acq); - buffer = NULL; - len = 0; - } - - evt_handler[idx](type, buffer, len); - - if (buf_free && buf_acq) eos_net_release(); -} - -void eos_net_set_handler(unsigned char mtype, eos_evt_fptr_t handler, uint8_t flags) { - if (mtype && (mtype <= EOS_NET_MAX_MTYPE)) { - mtype--; - } else { - return; - } - if (flags) { - uint16_t flag = (uint16_t)1 << mtype; - 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; + _eos_net_handle(type, buffer, len, idx, evt_handler, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq); } void eos_net_init(void) { @@ -272,7 +247,7 @@ void eos_net_init(void) { } void eos_net_start(void) { - eos_intr_set_handler(INT_SPI1_BASE, net_xchg_handler); + eos_intr_set_handler(INT_SPI1_BASE, net_handler_xchg); SPI1_REG(SPI_REG_SCKDIV) = SPI_DIV_NET; SPI1_REG(SPI_REG_CSID) = SPI_CS_IDX_NET; @@ -298,6 +273,39 @@ void eos_net_stop(void) { } } +void _eos_net_handle(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char idx, eos_evt_fptr_t handlers[], uint16_t *flags_buf_free, uint16_t *flags_buf_acq) { + uint16_t buf_free = ((uint16_t)1 << idx) & *flags_buf_free; + uint16_t buf_acq = ((uint16_t)1 << idx) & *flags_buf_acq; + + if (buf_free) { + eos_net_free(buffer, buf_acq); + buffer = NULL; + len = 0; + } + + handlers[idx](type, buffer, len); + + if (buf_free && buf_acq) eos_net_release(); +} + +void _eos_net_set_handler(unsigned char idx, eos_evt_fptr_t handler, eos_evt_fptr_t handlers[], uint16_t flags, uint16_t *flags_buf_free, uint16_t *flags_buf_acq) { + if (flags) { + uint16_t flag = (uint16_t)1 << idx; + if (flags & EOS_NET_FLAG_BFREE) *flags_buf_free |= flag; + if (flags & EOS_NET_FLAG_BACQ) *flags_buf_acq |= flag; + } + handlers[idx] = handler; +} + +void eos_net_set_handler(unsigned char mtype, eos_evt_fptr_t handler, uint8_t flags) { + if (mtype && (mtype <= EOS_NET_MAX_MTYPE)) { + mtype--; + } else { + return; + } + _eos_net_set_handler(mtype, handler, evt_handler, flags, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq); +} + int _eos_net_acquire(unsigned char reserved) { int ret = 0; diff --git a/code/fe310/eos/net.h b/code/fe310/eos/net.h index 127942c..e0fdbf9 100644 --- a/code/fe310/eos/net.h +++ b/code/fe310/eos/net.h @@ -19,7 +19,10 @@ void eos_net_xchg_done(void); void eos_net_init(void); void eos_net_start(void); void eos_net_stop(void); +void _eos_net_handle(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char idx, eos_evt_fptr_t handlers[], uint16_t *flags_buf_free, uint16_t *flags_buf_acq); +void _eos_net_set_handler(unsigned char idx, eos_evt_fptr_t handler, eos_evt_fptr_t handlers[], uint16_t flags, uint16_t *flags_buf_free, uint16_t *flags_buf_acq); void eos_net_set_handler(unsigned char type, eos_evt_fptr_t handler, uint8_t flags); + int _eos_net_acquire(unsigned char reserved); void eos_net_acquire(void); void eos_net_release(void); diff --git a/code/fe310/eos/sock.c b/code/fe310/eos/sock.c index 2c6ba5d..077c93d 100644 --- a/code/fe310/eos/sock.c +++ b/code/fe310/eos/sock.c @@ -8,9 +8,9 @@ #include "sock.h" -static eos_sock_fptr_t sock_handler[EOS_SOCK_MAX_SOCK]; -static uint16_t sock_handler_flags_buf_free = 0; -static uint16_t sock_handler_flags_buf_acq = 0; +static eos_evt_fptr_t evt_handler[EOS_SOCK_MAX_SOCK]; +static uint16_t evt_handler_flags_buf_free = 0; +static uint16_t evt_handler_flags_buf_acq = 0; static void sock_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) { if ((buffer == NULL) || (len < 2)) { @@ -28,24 +28,28 @@ static void sock_handler_evt(unsigned char type, unsigned char *buffer, uint16_t eos_net_free(buffer, 0); return; } - uint16_t buf_free = ((uint16_t)1 << sock) & sock_handler_flags_buf_free; - uint16_t buf_acq = ((uint16_t)1 << sock) & sock_handler_flags_buf_acq; - if (buf_free) { - eos_net_free(buffer, buf_acq); - buffer = NULL; - len = 0; - } - - sock_handler[sock](buffer, len); - - if (buf_free && buf_acq) eos_net_release(); + _eos_net_handle(type, buffer, len, sock, evt_handler, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq); } } void eos_sock_init(void) { + int i; + + for (i=0; i +#include "event.h" #define EOS_SOCK_MTYPE_PKT 0 #define EOS_SOCK_MTYPE_OPEN_DGRAM 1 @@ -15,11 +16,10 @@ typedef struct EOSNetAddr { uint16_t port; } EOSNetAddr; -typedef void (*eos_sock_fptr_t) (unsigned char *, uint16_t); - void eos_sock_init(void); +void eos_sock_set_handler(int sock, eos_evt_fptr_t handler, uint8_t flags); + int eos_sock_open_udp(void); void eos_sock_close(int sock); int eos_sock_sendto(int sock, unsigned char *buffer, uint16_t size, unsigned char more, EOSNetAddr *addr); void eos_sock_getfrom(unsigned char *buffer, EOSNetAddr *addr); -void eos_sock_set_handler(int sock, eos_sock_fptr_t handler, uint8_t flags); diff --git a/code/fe310/eos/spi.c b/code/fe310/eos/spi.c index 56ef318..d752bfb 100644 --- a/code/fe310/eos/spi.c +++ b/code/fe310/eos/spi.c @@ -18,8 +18,6 @@ #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) #define SPI_IOF_MASK (((uint32_t)1 << IOF_SPI1_SCK) | ((uint32_t)1 << IOF_SPI1_MOSI) | ((uint32_t)1 << IOF_SPI1_MISO)) | ((uint32_t)1 << IOF_SPI1_SS0) | ((uint32_t)1 << IOF_SPI1_SS2) | ((uint32_t)1 << IOF_SPI1_SS3) -extern EOSMsgQ _eos_event_q; - static uint8_t spi_dev; static uint8_t spi_dev_cs_pin; static uint8_t spi_state_flags; @@ -60,6 +58,14 @@ static void spi_xchg_wait(void) { } void eos_spi_init(void) { + int i; + + for (i=0; i= EOS_WIFI_MAX_MTYPE) { + return; + } + _eos_net_set_handler(mtype, handler, evt_handler, flags, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq); +} + void eos_wifi_connect(const char *ssid, const char *pass) { int ssid_len = strlen(ssid); int pass_len = strlen(pass); @@ -61,16 +63,3 @@ void eos_wifi_disconnect(void) { buffer[0] = EOS_WIFI_MTYPE_DISCONNECT; eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0); } - -void eos_wifi_set_handler(int mtype, eos_wifi_fptr_t handler, uint8_t flags) { - if (mtype >= EOS_WIFI_MAX_MTYPE) { - return; - } - - if (flags) { - uint16_t flag = (uint16_t)1 << mtype; - 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; -} diff --git a/code/fe310/eos/wifi.h b/code/fe310/eos/wifi.h index d46d25b..3587d1d 100644 --- a/code/fe310/eos/wifi.h +++ b/code/fe310/eos/wifi.h @@ -1,4 +1,5 @@ #include +#include "event.h" #define EOS_WIFI_MTYPE_SCAN 0 #define EOS_WIFI_MTYPE_CONNECT 1 @@ -6,9 +7,8 @@ #define EOS_WIFI_MAX_MTYPE 3 -typedef void (*eos_wifi_fptr_t) (unsigned char *, uint16_t); - void eos_wifi_init(void); +void eos_wifi_set_handler(int mtype, eos_evt_fptr_t handler, uint8_t flags); + void eos_wifi_connect(const char *ssid, const char *pass); void eos_wifi_disconnect(void); -void eos_wifi_set_handler(int mtype, eos_wifi_fptr_t handler, uint8_t flags); \ No newline at end of file -- cgit v1.2.3