Skip to content

Commit

Permalink
Merge pull request #156 from TrampolineRTOS/g4mh_serial
Browse files Browse the repository at this point in the history
G4mh add serial/printf support and fix a context switch issue
  • Loading branch information
RICCIARDI-Adrien authored Dec 1, 2023
2 parents 7cd2d87 + 33c9a3b commit 88860b1
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 15 deletions.
17 changes: 17 additions & 0 deletions examples/rh850/serial/build.sh
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions examples/rh850/serial/serial.c
Original file line number Diff line number Diff line change
@@ -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);
}
59 changes: 59 additions & 0 deletions examples/rh850/serial/serial.oil
Original file line number Diff line number Diff line change
@@ -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;
};
};
};

8 changes: 7 additions & 1 deletion goil/templates/config/rh850/g4mh/config.oil
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ CPU renesas {
NEEDS = net_can_renesas_spider_driver;
PATH = "net/can";
};

LIBRARY serial {
GLOBAL = TRUE;
PATH = "drivers/serial/renesas";
};
};

IMPLEMENTATION renesas {
OS {
BOOLEAN [
TRUE {
ENUM [
can
can,
serial
] LIBRARY[];
},
FALSE
Expand Down
8 changes: 7 additions & 1 deletion libraries/drivers/serial/renesas/spider_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 10 additions & 11 deletions machines/rh850/tpl_irq_handler.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions machines/rh850/tpl_machine_renesas.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}

0 comments on commit 88860b1

Please sign in to comment.