From 22a79e03a60bed3df7ba24015564c4b48bb811cb Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sun, 24 Nov 2019 18:25:18 +0100 Subject: fixed evt msg get; cleanup --- code/fe310/eos/Makefile | 14 ++++---------- code/fe310/eos/ecp.c | 21 --------------------- code/fe310/eos/ecp.h | 3 --- code/fe310/eos/event.c | 19 +++++++++++++++---- code/fe310/eos/i2s.c | 6 +++++- code/fe310/eos/interrupt.c | 16 +++++----------- code/fe310/eos/sock.c | 7 +++++++ code/fe310/eos/timer.c | 4 ---- code/fe310/eos/trap_entry.S | 2 +- 9 files changed, 37 insertions(+), 55 deletions(-) delete mode 100644 code/fe310/eos/ecp.c delete mode 100644 code/fe310/eos/ecp.h (limited to 'code/fe310/eos') diff --git a/code/fe310/eos/Makefile b/code/fe310/eos/Makefile index b7f401c..cb91b59 100644 --- a/code/fe310/eos/Makefile +++ b/code/fe310/eos/Makefile @@ -1,13 +1,8 @@ -include ../../ecp/Makefile.fe310 +include ../common.mk -FE310_HOME = /opt/my/freedom-e-sdk +CFLAGS += -I../include -I../drivers -CC = $(FE310_HOME)/work/build/riscv-gnu-toolchain/riscv64-unknown-elf/prefix/bin/riscv64-unknown-elf-gcc -AR = $(FE310_HOME)/work/build/riscv-gnu-toolchain/riscv64-unknown-elf/prefix/bin/riscv64-unknown-elf-ar - -CFLAGS = $(CFLAGS_PL) -I../.. - -obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o i2s.o spi.o net.o sock.o ecp.o +obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o i2s.o spi.o net.o sock.o %.o: %.c %.h @@ -17,7 +12,6 @@ obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o i2s.o spi.o net.o so $(CC) $(CFLAGS) -c $< all: $(obj) - $(AR) rcs libeos.a $(obj) clean: - rm -f *.o *.a \ No newline at end of file + rm -f *.o \ No newline at end of file diff --git a/code/fe310/eos/ecp.c b/code/fe310/eos/ecp.c deleted file mode 100644 index f151d1b..0000000 --- a/code/fe310/eos/ecp.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -#include "encoding.h" -#include "platform.h" - -#include "ecp.h" - -int ecp_init(ECPContext *ctx) { - int rv; - - rv = ecp_ctx_create_vconn(ctx); - if (rv) return rv; - - return ECP_OK; -} diff --git a/code/fe310/eos/ecp.h b/code/fe310/eos/ecp.h deleted file mode 100644 index 3dd9b72..0000000 --- a/code/fe310/eos/ecp.h +++ /dev/null @@ -1,3 +0,0 @@ -struct ECPContext; - -int ecp_init(struct ECPContext *ctx); diff --git a/code/fe310/eos/event.c b/code/fe310/eos/event.c index 0335df1..3c3ceb9 100644 --- a/code/fe310/eos/event.c +++ b/code/fe310/eos/event.c @@ -99,9 +99,21 @@ void eos_evtq_get(unsigned char type, unsigned char *selector, uint16_t sel_len, clear_csr(mstatus, MSTATUS_MIE); rv = eos_msgq_get(&_eos_event_q, type, selector, sel_len, buffer, len); if (!rv) { - asm volatile ("wfi"); + unsigned char _type; + unsigned char *_buffer; + uint16_t _len; + + eos_msgq_pop(&_eos_event_q, &_type, &_buffer, &_len); + if (_type) { + set_csr(mstatus, MSTATUS_MIE); + evtq_handler(_type, _buffer, _len); + } else { + asm volatile ("wfi"); + set_csr(mstatus, MSTATUS_MIE); + } + } else { + set_csr(mstatus, MSTATUS_MIE); } - set_csr(mstatus, MSTATUS_MIE); } } @@ -117,11 +129,10 @@ void eos_evtq_loop(void) { if (type) { set_csr(mstatus, MSTATUS_MIE); evtq_handler(type, buffer, len); - clear_csr(mstatus, MSTATUS_MIE); } else { if (!evt_busy) asm volatile ("wfi"); + set_csr(mstatus, MSTATUS_MIE); } - set_csr(mstatus, MSTATUS_MIE); } } diff --git a/code/fe310/eos/i2s.c b/code/fe310/eos/i2s.c index 3d3e007..3cc0619 100644 --- a/code/fe310/eos/i2s.c +++ b/code/fe310/eos/i2s.c @@ -3,6 +3,7 @@ #include "encoding.h" #include "platform.h" +#include "prci_driver.h" #include "eos.h" #include "interrupt.h" @@ -117,7 +118,10 @@ void eos_i2s_init(void) { } void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) { - uint32_t ck_period = (get_cpu_freq() / (sample_rate * 64)) & ~I2S_PWM_SCALE_CK_MASK;; + // Ignore the first run (for icache reasons) + uint32_t cpu_freq = PRCI_measure_mcycle_freq(3000, RTC_FREQ); + cpu_freq = PRCI_measure_mcycle_freq(3000, RTC_FREQ); + uint32_t ck_period = (cpu_freq / (sample_rate * 64)) & ~I2S_PWM_SCALE_CK_MASK;; GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK); GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK); diff --git a/code/fe310/eos/interrupt.c b/code/fe310/eos/interrupt.c index 0172fb8..cb513a0 100644 --- a/code/fe310/eos/interrupt.c +++ b/code/fe310/eos/interrupt.c @@ -4,7 +4,7 @@ #include "encoding.h" #include "platform.h" -#include "plic/plic_driver.h" +#include "plic_driver.h" #include "interrupt.h" @@ -15,8 +15,8 @@ static plic_instance_t plic; static eos_intr_fptr_t ext_interrupt_handler[PLIC_NUM_INTERRUPTS]; uintptr_t eos_intr_handle(uintptr_t int_num) { - if ((int_num >=1) && (int_num < PLIC_NUM_INTERRUPTS) && (ext_interrupt_handler[int_num])) { - ext_interrupt_handler[int_num](); + if ((int_num >=1) && (int_num <= PLIC_NUM_INTERRUPTS) && (ext_interrupt_handler[int_num-1])) { + ext_interrupt_handler[int_num-1](); } else { write(1, "error\n", 6); exit(int_num); @@ -24,12 +24,6 @@ uintptr_t eos_intr_handle(uintptr_t int_num) { return int_num; } -void handle_m_ext_interrupt(void) { - plic_source int_num = PLIC_claim_interrupt(&plic); - eos_intr_handle(int_num); - PLIC_complete_interrupt(&plic, int_num); -} - void eos_intr_init(void) { for (int i = 0; i < PLIC_NUM_INTERRUPTS; i++){ ext_interrupt_handler[i] = NULL; @@ -51,13 +45,13 @@ void eos_intr_init(void) { } void eos_intr_set(uint8_t int_num, uint8_t priority, eos_intr_fptr_t handler) { - ext_interrupt_handler[int_num] = handler; + ext_interrupt_handler[int_num-1] = handler; PLIC_set_priority(&plic, int_num, priority); PLIC_enable_interrupt(&plic, int_num); } void eos_intr_set_handler(uint8_t int_num, eos_intr_fptr_t handler) { - ext_interrupt_handler[int_num] = handler; + ext_interrupt_handler[int_num-1] = handler; } void eos_intr_set_priority(uint8_t int_num, uint8_t priority) { diff --git a/code/fe310/eos/sock.c b/code/fe310/eos/sock.c index b217b43..ab0fc59 100644 --- a/code/fe310/eos/sock.c +++ b/code/fe310/eos/sock.c @@ -13,6 +13,12 @@ static uint16_t sock_handler_flags_buf_free = 0; static uint16_t sock_handler_flags_buf_acq = 0; static void sock_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) { + if ((buffer == NULL) || (len < 2)) { + eos_evtq_bad_handler(type, buffer, len); + eos_net_free(buffer, 0); + return; + } + if (buffer[0] == EOS_SOCK_MTYPE_PKT) { uint8_t sock = buffer[1]; if (sock && (sock <= EOS_SOCK_MAX_SOCK)) { @@ -59,6 +65,7 @@ int eos_sock_open_udp(void) { sock = buffer[1]; eos_net_free(buffer, 1); + if (sock == 0) return EOS_ERR_NET; return sock; } diff --git a/code/fe310/eos/timer.c b/code/fe310/eos/timer.c index 6589c06..ed6aac4 100644 --- a/code/fe310/eos/timer.c +++ b/code/fe310/eos/timer.c @@ -48,10 +48,6 @@ void eos_timer_handle(void) { if (*mtimecmp == 0) clear_csr(mie, MIP_MTIP); } -void handle_m_time_interrupt(void) { - return eos_timer_handle(); -} - void eos_timer_init(void) { int i; uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP); diff --git a/code/fe310/eos/trap_entry.S b/code/fe310/eos/trap_entry.S index efa61ec..b7d0d7f 100644 --- a/code/fe310/eos/trap_entry.S +++ b/code/fe310/eos/trap_entry.S @@ -47,7 +47,7 @@ .section .data.entry - .align 2 + .align 4 .global eos_trap_entry eos_trap_entry: -- cgit v1.2.3