From 69ed847740e3efb5c5ff6319629c93d236150959 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Fri, 23 Sep 2022 20:08:02 +0200 Subject: i2s driver fixed; added uart programming; --- fw/fe310/eos/dev/net.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'fw/fe310/eos/dev/net.c') diff --git a/fw/fe310/eos/dev/net.c b/fw/fe310/eos/dev/net.c index 3811368..11250bc 100644 --- a/fw/fe310/eos/dev/net.c +++ b/fw/fe310/eos/dev/net.c @@ -91,7 +91,6 @@ 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; @@ -104,7 +103,6 @@ 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); @@ -125,7 +123,6 @@ 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; @@ -148,7 +145,6 @@ 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; @@ -207,7 +203,6 @@ 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; @@ -217,7 +212,6 @@ static void net_handle_cts(void) { } } -__attribute__ ((section (".itim"))) static void net_handle_rts(void) { uint32_t rts_offset = (1 << NET_PIN_RTS); @@ -233,7 +227,6 @@ 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; @@ -244,7 +237,6 @@ 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; @@ -271,7 +263,6 @@ 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; @@ -286,7 +277,6 @@ 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; @@ -413,8 +403,7 @@ void eos_net_stop(void) { } int eos_net_sleep(uint32_t timeout) { - volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME); - uint64_t then_ms = timeout + *mtime * 1000 / EOS_TIMER_RTC_FREQ; + uint32_t start; uint8_t done = 0; int rv = EOS_OK; @@ -424,8 +413,9 @@ int eos_net_sleep(uint32_t timeout) { if (rv) return rv; + start = eos_time_get_tick(); do { - if (*mtime * 1000 / EOS_TIMER_RTC_FREQ > then_ms) return EOS_ERR_TIMEOUT; + if (eos_time_delta_ms(start) > timeout) return EOS_ERR_TIMEOUT; clear_csr(mstatus, MSTATUS_MIE); eos_evtq_flush_isr(); done = (eos_msgq_len(&net_send_q) == 0); @@ -438,7 +428,7 @@ int eos_net_sleep(uint32_t timeout) { } while (!done); while (!(GPIO_REG(GPIO_RISE_IP) & (1 << NET_PIN_CTS))) { - if (*mtime * 1000 / EOS_TIMER_RTC_FREQ > then_ms) { + if (eos_time_delta_ms(start) > timeout) { rv = EOS_ERR_TIMEOUT; break; } @@ -476,13 +466,11 @@ 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) { @@ -492,7 +480,6 @@ void eos_net_release(void) { set_csr(mstatus, MSTATUS_MIE); } -__attribute__ ((section (".itim"))) unsigned char *eos_net_alloc(void) { unsigned char *ret = NULL; @@ -510,7 +497,6 @@ 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; @@ -528,7 +514,6 @@ 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; @@ -594,7 +579,6 @@ 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) { int rv; -- cgit v1.2.3