From 2ba72f11ea2b611e224d490ece7ca84204e96023 Mon Sep 17 00:00:00 2001 From: Florian Sylvestre Date: Mon, 23 Oct 2023 14:33:53 +0200 Subject: [PATCH 1/3] spider: add COM support by using SCIF/HSCIF --- goil/templates/config/rh850/g4mh/config.oil | 8 +++++++- libraries/drivers/serial/renesas/spider_serial.h | 8 +++++++- machines/rh850/tpl_machine_renesas.c | 12 ++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/goil/templates/config/rh850/g4mh/config.oil b/goil/templates/config/rh850/g4mh/config.oil index 00295fb48..662e4420f 100755 --- a/goil/templates/config/rh850/g4mh/config.oil +++ b/goil/templates/config/rh850/g4mh/config.oil @@ -9,6 +9,11 @@ CPU renesas { NEEDS = net_can_renesas_spider_driver; PATH = "net/can"; }; + + LIBRARY serial { + GLOBAL = TRUE; + PATH = "drivers/serial/renesas"; + }; }; IMPLEMENTATION renesas { @@ -16,7 +21,8 @@ IMPLEMENTATION renesas { BOOLEAN [ TRUE { ENUM [ - can + can, + serial ] LIBRARY[]; }, FALSE diff --git a/libraries/drivers/serial/renesas/spider_serial.h b/libraries/drivers/serial/renesas/spider_serial.h index a32563166..08a8c56ec 100644 --- a/libraries/drivers/serial/renesas/spider_serial.h +++ b/libraries/drivers/serial/renesas/spider_serial.h @@ -3,11 +3,17 @@ #include "tpl_os.h" +#if __arm__ /* SCIF3 */ #define SCIF_BASE_ADDR 0xE6C50000 - /* HSCIF0 */ #define HSCIF_BASE_ADDR 0xE6540000 +#else +/* SCIF3 */ +#define SCIF_BASE_ADDR 0xD6C50000 +/* HSCIF0 */ +#define HSCIF_BASE_ADDR 0xD6540000 +#endif /* BRR computing: * HSBRR: Register value = Internal clock / ( Sr * 2^(2*n + 1) * B) * 10^6 -1 diff --git a/machines/rh850/tpl_machine_renesas.c b/machines/rh850/tpl_machine_renesas.c index 349947c95..1bc239f89 100644 --- a/machines/rh850/tpl_machine_renesas.c +++ b/machines/rh850/tpl_machine_renesas.c @@ -2,13 +2,13 @@ #include "tpl_machine.h" #include "tpl_machine_interface.h" #include "tpl_dispatch_table.h" -#include "iodefine.h" //FSY: usefull? +#include "iodefine.h" VAR (tpl_context, OS_VAR) idle_task_context; VAR(tpl_stack_word, OS_VAR) idle_stack[IDLE_STACK_SIZE/sizeof(tpl_stack_word)]; -#define SYSTICK_HZ ((u32) 80000000) /* 80MHz : is it the correct frequency? */ +#define SYSTICK_HZ ((u32) 80000000) /* 80MHz */ #define TICKS_FOR_10MS SYSTICK_HZ / 100 static void stop_systick() @@ -170,9 +170,17 @@ extern u32 _tpl_syscall_table; FUNC(void, OS_CODE) tpl_init_machine(void) { + volatile uint32 val = 0; + /* Initialize Syscall registers */ __ldsr_rh(11, 1, SYSCALL_COUNT); /* SCCFG */ __ldsr_rh(12, 1, (u32) &_tpl_syscall_table); /* SCBP */ init_systick(); + + /* Enable access to the bus */ + MCCR_SELB1.STBY_CTRL.UINT32 = 0x00000001; + do { + val = MCCR_SELB1.STBY_CTRL.UINT32; + } while (val != 0x00000001); } From da75f970ca8cc20b0727c2dc81ebfbbf3c4b7f06 Mon Sep 17 00:00:00 2001 From: Florian Sylvestre Date: Mon, 23 Oct 2023 14:59:32 +0200 Subject: [PATCH 2/3] spider: Add Serial example for g4mh --- examples/rh850/serial/build.sh | 17 +++++++++ examples/rh850/serial/serial.c | 39 +++++++++++++++++++++ examples/rh850/serial/serial.oil | 59 ++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 examples/rh850/serial/build.sh create mode 100755 examples/rh850/serial/serial.c create mode 100755 examples/rh850/serial/serial.oil diff --git a/examples/rh850/serial/build.sh b/examples/rh850/serial/build.sh new file mode 100644 index 000000000..de51daa8b --- /dev/null +++ b/examples/rh850/serial/build.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +#stop on errors +set -e + +if [[ ! -d "_build" ]] +then + mkdir _build +fi + +echo "*** Run Goil ***" +goil --target=rh850/g4mh --templates=../../../goil/templates/ serial.oil +cd _build +echo "*** Run CMake ***" +cmake -G "Unix Makefiles" -D CMAKE_TOOLCHAIN_FILE=../serial/compiler.cmake .. +echo "*** Run Make ***" +make diff --git a/examples/rh850/serial/serial.c b/examples/rh850/serial/serial.c new file mode 100755 index 000000000..1b117811e --- /dev/null +++ b/examples/rh850/serial/serial.c @@ -0,0 +1,39 @@ +#include "tpl_os.h" + +#include "spider_serial.h" +#include "printf.h" + +FUNC(int, OS_APPL_CODE) main(void) +{ + + StartOS(OSDEFAULTAPPMODE); + return 0; +} + +volatile uint32 tmp = 0; + +TASK(serial_rx) +{ + uint8 uart_rx; + + Serial_Init(); + + debug_printf("serial_rx task started\r\n"); + + while(1) + { + if (Serial_Rx(&uart_rx)) + { + /* If received a char, send back the next one */ + Serial_Tx(uart_rx+1); + } + } +} + +TASK(serial_tx) +{ + /* Send next alphabet letter each time*/ + static uint8 uart_char=0; + uart_char = (uart_char+1) % 26; + Serial_Tx('a' + uart_char); +} diff --git a/examples/rh850/serial/serial.oil b/examples/rh850/serial/serial.oil new file mode 100755 index 000000000..79b227cfd --- /dev/null +++ b/examples/rh850/serial/serial.oil @@ -0,0 +1,59 @@ +OIL_VERSION = "4.2"; + +IMPLEMENTATION trampoline { + TASK { + UINT32 STACKSIZE = 2048 ; + } ; + + ISR { + UINT32 STACKSIZE = 2048 ; + } ; +}; + +CPU serial { + OS config { + STATUS = EXTENDED; + + BUILD = TRUE { + TRAMPOLINE_BASE_PATH = "../../../"; + APP_SRC = "serial.c"; + APP_NAME = "serial_exe"; + LDFLAGS="-debug -nocompress -NOOPtimize -memory=high -nologo -SHow=ALL"; + CFLAGS="-DHSCIF_1843200BPS -Xcpu=g4mh -g -g_line -Xfxu=off -Xasm_path=."; + LINKER = "rlink"; + SYSTEM = CMAKE; + + LIBRARY = serial; + }; + SYSTEM_CALL = TRUE; + }; + + APPMODE std {}; + + TASK serial_rx { + PRIORITY = 1; + AUTOSTART = TRUE { APPMODE = std; }; + ACTIVATION = 1; + SCHEDULE = FULL; + }; + + TASK serial_tx { + PRIORITY = 2; + AUTOSTART = FALSE; + ACTIVATION = 1; + SCHEDULE = FULL; + }; + + ALARM serial_serial { + COUNTER = SystemCounter; + ACTION = ACTIVATETASK { + TASK = serial_tx; + }; + AUTOSTART = TRUE { + APPMODE = std; + ALARMTIME = 100; + CYCLETIME = 100; + }; + }; +}; + From 33c9a3b3ac5338a22e6ce9c29ed36032e05b1c5a Mon Sep 17 00:00:00 2001 From: Florian Sylvestre Date: Thu, 30 Nov 2023 17:45:45 +0100 Subject: [PATCH 3/3] G4MH: Fix IRQ context switch on g4mh During the IRQ context switch the SP of the calling task was not correctly updated in the kernel strucutres. Fix the issue an make the code more readable. --- machines/rh850/tpl_irq_handler.asm | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/machines/rh850/tpl_irq_handler.asm b/machines/rh850/tpl_irq_handler.asm index 586b718fa..9e5dc9945 100644 --- a/machines/rh850/tpl_irq_handler.asm +++ b/machines/rh850/tpl_irq_handler.asm @@ -65,11 +65,11 @@ __irq_handler: pushsp r21, r31 ; Save the current context. - mov TPL_KERN_OFFSET_S_RUNNING, r10 - movhi HIGHW1(#_tpl_kern), r10, r11 ; get pointer to the descriptor of the running task - ld.w LOWW(#_tpl_kern)[r11], r10 - - st.w r3, [r10] ; save running task sp + mov #_tpl_kern, r10 + addi TPL_KERN_OFFSET_S_RUNNING, r10, r11 ; get pointer to the descriptor of the running task + ld.w [r11], r10 ; get pointer to the running task context + ld.w [r10], r11 + st.w r3, [r11] ; save running task sp ; Switch back to kernel stack mov r4, r3 @@ -79,12 +79,11 @@ __irq_handler: jarl _tpl_run_elected, r31 ; Update the current context according to SP given by the OS - mov TPL_KERN_OFFSET_S_RUNNING, r10 - movhi HIGHW1(#_tpl_kern), r10, r11 ; Get pointer to the descriptor of the new running task - ld.w LOWW(#_tpl_kern)[r11], r10 - - ld.w [r10], r11 ; Get SP of elected task - ld.w [r11], r3 + mov #_tpl_kern, r10 + addi TPL_KERN_OFFSET_S_RUNNING, r10, r11 ; get pointer to the descriptor of the running task + ld.w [r11], r10 ; Get SP of elected task + ld.w [r10], r11 + ld.w [r11], r3 ; load running task sp ; epilogue popsp r21, r31