From c7d1773e73f8c8195c30fdf0e5143f61a123338e Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Wed, 5 Aug 2020 06:43:12 +0200 Subject: added test prg --- fw/fe310/common.mk | 3 - fw/fe310/test/Makefile | 20 ++++++ fw/fe310/test/modem | Bin 0 -> 134292 bytes fw/fe310/test/modem.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++++ fw/fe310/test/modem.o | Bin 0 -> 7644 bytes 5 files changed, 187 insertions(+), 3 deletions(-) create mode 100644 fw/fe310/test/Makefile create mode 100755 fw/fe310/test/modem create mode 100644 fw/fe310/test/modem.c create mode 100644 fw/fe310/test/modem.o (limited to 'fw') diff --git a/fw/fe310/common.mk b/fw/fe310/common.mk index e468289..9fddf67 100644 --- a/fw/fe310/common.mk +++ b/fw/fe310/common.mk @@ -3,6 +3,3 @@ AR = $(RISCV_HOME)/bin/riscv64-unknown-elf-ar RANLIB = $(RISCV_HOME)/bin/riscv64-unknown-elf-ranlib CFLAGS = -march=rv32imac -mabi=ilp32 -mcmodel=medlow -ffunction-sections -fdata-sections --specs=nano.specs -O3 -LDFLAGS = $(CFLAGS) -L$(FE310_HOME) -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos -Wl,--end-group -T$(FE310_HOME)/bsp/default.lds - -UPARGS = --openocd $(RISCV_OPENOCD_HOME)/bin/openocd --gdb $(RISCV_HOME)/bin/riscv64-unknown-elf-gdb --openocd-config $(FE310_HOME)/bsp/openocd.cfg diff --git a/fw/fe310/test/Makefile b/fw/fe310/test/Makefile new file mode 100644 index 0000000..f6b619c --- /dev/null +++ b/fw/fe310/test/Makefile @@ -0,0 +1,20 @@ +include ../common.mk + +CFLAGS += -I.. -I../bsp/include -I../bsp/drivers +LDFLAGS = $(CFLAGS) -L.. -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos -Wl,--end-group -T../bsp/default.lds + +TARGET = modem + +all: $(TARGET) + +%.o: %.c + $(CC) $(CFLAGS) -c $< + +$(TARGET): $(TARGET).o + $(CC) $< $(LDFLAGS) -o $@ + +clean: + rm -f *.o *.a $(TARGET) + +upload: $(TARGET) + ../bsp/upload --elf ./$(TARGET) --openocd $(RISCV_OPENOCD_HOME)/bin/openocd --gdb $(RISCV_HOME)/bin/riscv64-unknown-elf-gdb --openocd-config ../bsp/openocd.cfg diff --git a/fw/fe310/test/modem b/fw/fe310/test/modem new file mode 100755 index 0000000..e7a3c4a Binary files /dev/null and b/fw/fe310/test/modem differ diff --git a/fw/fe310/test/modem.c b/fw/fe310/test/modem.c new file mode 100644 index 0000000..de6394d --- /dev/null +++ b/fw/fe310/test/modem.c @@ -0,0 +1,167 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ABUF_SIZE 512 +#define MIC_WM 128 + +static uint8_t mic_arr[ABUF_SIZE]; +static uint8_t spk_arr[ABUF_SIZE]; + +static int audio_on = 0; + +static EVEText box; +static EVEKbd kbd; + +static void key_down(void *p, int c) { + int i = 2; + unsigned char *buf = eos_net_alloc(); + + buf[0] = EOS_CELL_MTYPE_UART_DATA; + if (c == '\n') { + buf[1] = '\r'; + buf[2] = '\n'; + i++; + } else { + buf[1] = c; + } + + eos_net_send(EOS_NET_MTYPE_CELL, buf, i, 0); +} + +static void handle_touch(void *p, uint8_t tag0, int touch_idx) { + eve_kbd_touch(&kbd, tag0, touch_idx); + eve_text_touch(&box, tag0, touch_idx); + + eve_cmd_dl(CMD_DLSTART); + eve_cmd_dl(CLEAR_COLOR_RGB(0,0,0)); + eve_cmd_dl(CLEAR(1,1,1)); + eve_text_draw(&box); + eve_kbd_draw(&kbd); + eve_cmd_dl(DISPLAY()); + eve_cmd_dl(CMD_SWAP); + eve_cmd_exec(1); +} + +static void handle_mic(unsigned char type) { + uint16_t size; + unsigned char *buf = eos_net_alloc(); + + buf[0] = EOS_CELL_MTYPE_PCM_DATA; + size = eos_i2s_mic_read(buf+1, MIC_WM); + eos_net_send(EOS_NET_MTYPE_CELL, buf, size+1, 0); +} + +static void handle_uart(unsigned char type) { + int i = 0; + int c = 0; + unsigned char *buf = NULL; + + c = eos_uart_getc(0); + if (c == EOS_ERR_EMPTY) return; + + buf = eos_net_alloc(); + buf[0] = EOS_CELL_MTYPE_UART_DATA; + buf[1] = c; + i = 2; + while ((c = eos_uart_getc(0)) != EOS_ERR_EMPTY) { + buf[i] = c; + i++; + if (i == EOS_NET_SIZE_BUF) break; + } + eos_net_send(EOS_NET_MTYPE_CELL, buf, i, 0); + eos_uart_rxwm_set(0); +} + +static void handle_cell_msg(unsigned char _type, unsigned char *buffer, uint16_t len) { + int i; + unsigned char type = buffer[0]; + + switch (type) { + case EOS_CELL_MTYPE_READY: + buffer[0] = EOS_CELL_MTYPE_UART_TAKE; + eos_net_send(EOS_NET_MTYPE_CELL, buffer, 1, 0); + eos_uart_rxwm_set(0); + printf("\nREADY.\n"); + break; + + case EOS_CELL_MTYPE_UART_DATA: + eos_spi_dev_start(EOS_DEV_DISP); + for (i=1; i