From c286437474becda19c255efa3ede6beb0f2292d9 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sun, 4 Sep 2022 18:18:59 +0200 Subject: moved critical functions to itim --- fw/fe310/eos/dev/net.c | 28 +++++++++++++++++++++++++--- fw/fe310/eos/event.c | 8 ++++++++ fw/fe310/eos/msgq.c | 6 ++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/fw/fe310/eos/dev/net.c b/fw/fe310/eos/dev/net.c index 6114485..3811368 100644 --- a/fw/fe310/eos/dev/net.c +++ b/fw/fe310/eos/dev/net.c @@ -34,7 +34,7 @@ static EOSBufQ net_buf_q; static unsigned char *net_bufq_array[EOS_NET_SIZE_BUFQ]; -static unsigned char net_bufq_buffer[EOS_NET_SIZE_BUFQ][EOS_NET_SIZE_BUF]; +static unsigned char net_bufq_buffer[EOS_NET_SIZE_BUFQ][EOS_NET_SIZE_BUF] __attribute__((section (".itim2"))); static EOSMsgQ net_send_q; static EOSMsgItem net_sndq_array[EOS_NET_SIZE_BUFQ]; @@ -91,6 +91,7 @@ static void net_xchg_wake(void) { SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_AUTO; } +__attribute__ ((section (".itim"))) static void net_xchg_reset(void) { volatile uint32_t x = 0; net_state_flags &= ~NET_STATE_FLAG_CTS; @@ -103,6 +104,7 @@ static void net_xchg_reset(void) { SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_AUTO; } +__attribute__ ((section (".itim"))) static void net_xchg_start(unsigned char type, unsigned char *buffer, uint16_t len) { net_state_flags &= ~NET_STATE_FLAG_CTS; net_state_flags |= (NET_STATE_FLAG_INIT | NET_STATE_FLAG_XCHG); @@ -123,6 +125,7 @@ static void net_xchg_start(unsigned char type, unsigned char *buffer, uint16_t l SPI1_REG(SPI_REG_IE) = SPI_IP_RXWM; } +__attribute__ ((section (".itim"))) static int net_xchg_next(unsigned char *_buffer) { unsigned char type; unsigned char *buffer = NULL; @@ -145,6 +148,7 @@ static int net_xchg_next(unsigned char *_buffer) { return ret; } +__attribute__ ((section (".itim"))) static void net_handle_xchg(void) { if (net_state_flags & NET_STATE_FLAG_INIT) { volatile uint32_t r1, r2, r3; @@ -203,6 +207,7 @@ static void net_handle_xchg(void) { } } +// __attribute__ ((section (".itim"))) static void net_handle_cts(void) { GPIO_REG(GPIO_RISE_IP) = (1 << NET_PIN_CTS); net_state_flags |= NET_STATE_FLAG_CTS; @@ -212,6 +217,7 @@ static void net_handle_cts(void) { } } +__attribute__ ((section (".itim"))) static void net_handle_rts(void) { uint32_t rts_offset = (1 << NET_PIN_RTS); @@ -227,6 +233,7 @@ static void net_handle_rts(void) { } } +__attribute__ ((section (".itim"))) static void net_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) { unsigned char idx = (type & ~EOS_EVT_MASK) - 1; @@ -237,6 +244,7 @@ static void net_handle_evt(unsigned char type, unsigned char *buffer, uint16_t l } } +__attribute__ ((section (".itim"))) static int net_acquire(unsigned char reserved) { int ret = 0; @@ -253,7 +261,9 @@ static int net_acquire(unsigned char reserved) { } } else { clear_csr(mstatus, MSTATUS_MIE); - if (net_state_next_buf == NULL) net_state_next_buf = eos_bufq_pop(&net_buf_q); + if (net_state_next_buf == NULL) { + net_state_next_buf = eos_bufq_pop(&net_buf_q); + } ret = (net_state_next_buf != NULL); if (!ret) net_state_next_cnt++; set_csr(mstatus, MSTATUS_MIE); @@ -261,6 +271,7 @@ static int net_acquire(unsigned char reserved) { return ret; } +__attribute__ ((section (".itim"))) static void evt_handler_wrapper(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char idx, uint16_t flag) { int ok; @@ -275,6 +286,7 @@ static void evt_handler_wrapper(unsigned char type, unsigned char *buffer, uint1 } } +__attribute__ ((section (".itim"))) static void evt_handler(unsigned char type, unsigned char *buffer, uint16_t len) { unsigned char idx = (type & EOS_EVT_MASK) >> 4; @@ -464,11 +476,13 @@ void eos_net_acquire_for_evt(unsigned char type, char acq) { } } +__attribute__ ((section (".itim"))) void eos_net_acquire(void) { unsigned char acq = net_acquire(0); if (!acq) net_acquire(1); } +__attribute__ ((section (".itim"))) void eos_net_release(void) { clear_csr(mstatus, MSTATUS_MIE); if (!net_state_next_cnt && net_state_next_buf) { @@ -478,6 +492,7 @@ void eos_net_release(void) { set_csr(mstatus, MSTATUS_MIE); } +__attribute__ ((section (".itim"))) unsigned char *eos_net_alloc(void) { unsigned char *ret = NULL; @@ -495,6 +510,7 @@ unsigned char *eos_net_alloc(void) { return ret; } +__attribute__ ((section (".itim"))) void eos_net_free(unsigned char *buffer, unsigned char more) { uint8_t do_release = 1; @@ -512,6 +528,7 @@ void eos_net_free(unsigned char *buffer, unsigned char more) { set_csr(mstatus, MSTATUS_MIE); } +__attribute__ ((section (".itim"))) static int net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len, unsigned char flags) { int rv = EOS_OK; int _sync = 0; @@ -577,8 +594,13 @@ int eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len) { return net_xchg(&type, buffer, &len, (EOS_NET_FLAG_ONEW | EOS_NET_FLAG_SYNC)); } +__attribute__ ((section (".itim"))) int eos_net_send_async(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char more) { - return net_xchg(&type, buffer, &len, more ? EOS_NET_FLAG_ONEW : 0); + int rv; + + rv = net_xchg(&type, buffer, &len, more ? EOS_NET_FLAG_ONEW : 0); + if (rv) eos_net_free(buffer, more); + return rv; } int _eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char async, unsigned char more) { diff --git a/fw/fe310/eos/event.c b/fw/fe310/eos/event.c index f76384a..9f9a119 100644 --- a/fw/fe310/eos/event.c +++ b/fw/fe310/eos/event.c @@ -15,6 +15,7 @@ static EOSMsgItem event_q_array[EOS_EVT_SIZE_Q]; static eos_evt_handler_t evt_handler[EOS_EVT_MAX_EVT + 1]; +__attribute__ ((section (".itim"))) static void evtq_handler(unsigned char type, unsigned char *buffer, uint16_t len) { unsigned char idx = (type & EOS_EVT_MASK) >> 4; @@ -37,6 +38,7 @@ int eos_evtq_init(uint8_t wakeup_cause) { return EOS_OK; } +__attribute__ ((section (".itim"))) 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); @@ -44,16 +46,19 @@ int eos_evtq_push(unsigned char type, unsigned char *buffer, uint16_t len) { return ret; } +__attribute__ ((section (".itim"))) int eos_evtq_push_isr(unsigned char type, unsigned char *buffer, uint16_t len) { return eos_msgq_push(&_eos_event_q, type, buffer, len); } +__attribute__ ((section (".itim"))) 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); } +__attribute__ ((section (".itim"))) void eos_evtq_pop_isr(unsigned char *type, unsigned char **buffer, uint16_t *len) { eos_msgq_pop(&_eos_event_q, type, buffer, len); } @@ -120,6 +125,7 @@ void eos_evtq_flush_isr(void) { } while (type); } +__attribute__ ((section (".itim"))) void eos_evtq_loop(void) { int foo = 1; @@ -128,6 +134,7 @@ void eos_evtq_loop(void) { } } +__attribute__ ((section (".itim"))) void eos_evtq_exec(void) { unsigned char type; unsigned char *buffer; @@ -156,6 +163,7 @@ void eos_evtq_set_handler(unsigned char type, eos_evt_handler_t handler) { if (idx <= EOS_EVT_MAX_EVT) evt_handler[idx] = handler; } +__attribute__ ((section (".itim"))) eos_evt_handler_t eos_evtq_get_handler(unsigned char type) { unsigned char idx = (type & EOS_EVT_MASK) >> 4; diff --git a/fw/fe310/eos/msgq.c b/fw/fe310/eos/msgq.c index a483a58..1462ebe 100644 --- a/fw/fe310/eos/msgq.c +++ b/fw/fe310/eos/msgq.c @@ -17,6 +17,7 @@ void eos_msgq_init(EOSMsgQ *msgq, EOSMsgItem *array, uint8_t size) { msgq->array = array; } +__attribute__ ((section (".itim"))) 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_FULL; @@ -28,6 +29,7 @@ int eos_msgq_push(EOSMsgQ *msgq, unsigned char type, unsigned char *buffer, uint return EOS_OK; } +__attribute__ ((section (".itim"))) void eos_msgq_pop(EOSMsgQ *msgq, unsigned char *type, unsigned char **buffer, uint16_t *len) { if (msgq->idx_r == msgq->idx_w) { *type = 0; @@ -93,6 +95,7 @@ int eos_msgq_find(EOSMsgQ *msgq, unsigned char type, unsigned char *selector, ui return 0; } +__attribute__ ((section (".itim"))) uint8_t eos_msgq_len(EOSMsgQ *msgq) { return (uint8_t)(msgq->idx_w - msgq->idx_r); } @@ -104,6 +107,7 @@ void eos_bufq_init(EOSBufQ *bufq, unsigned char **array, uint8_t size) { bufq->array = array; } +__attribute__ ((section (".itim"))) int eos_bufq_push(EOSBufQ *bufq, unsigned char *buffer) { if ((uint8_t)(bufq->idx_w - bufq->idx_r) == bufq->size) return EOS_ERR_FULL; @@ -111,12 +115,14 @@ int eos_bufq_push(EOSBufQ *bufq, unsigned char *buffer) { return EOS_OK; } +__attribute__ ((section (".itim"))) unsigned char *eos_bufq_pop(EOSBufQ *bufq) { if (bufq->idx_r == bufq->idx_w) return NULL; return bufq->array[IDX_MASK(bufq->idx_r++, bufq->size)]; } +__attribute__ ((section (".itim"))) uint8_t eos_bufq_len(EOSBufQ *bufq) { return (uint8_t)(bufq->idx_w - bufq->idx_r); } -- cgit v1.2.3