Skip to content

Commit

Permalink
cleaning OSEK code
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalandi committed Oct 5, 2024
1 parent 1dfdbfb commit 9b3a80a
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 84 deletions.
4 changes: 2 additions & 2 deletions Code/Appli/OsGenCfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ OS_CONFIG_BEGIN
OS_INTERRUPT_CAT2_DEF(Undefined, 0, NOT_NESTED) /* SVCall */
OS_INTERRUPT_CAT2_DEF(Undefined, 0, NOT_NESTED) /* Reserved */
OS_INTERRUPT_CAT2_DEF(Undefined, 0, NOT_NESTED) /* Reserved */
OS_INTERRUPT_CAT1_DEF(OsDispatchHandler, 4, NESTED) /* OsDispatchHandler */
OS_INTERRUPT_CAT2_DEF(SysTickTimer, 4, NOT_NESTED) /* OsCat2IsrWrapper */
OS_INTERRUPT_CAT1_DEF(osDispatchHandler, 4, NESTED) /* osDispatchHandler */
OS_INTERRUPT_CAT2_DEF(SysTickTimer, 4, NOT_NESTED) /* osCat2IsrWrapper */
#endif
OS_INTERRUPT_CAT2_DEF(Undefined, 0, NOT_NESTED) /* TIMER0_IRQ_0_IRQn */
OS_INTERRUPT_CAT2_DEF(Undefined, 0, NOT_NESTED) /* TIMER0_IRQ_1_IRQn */
Expand Down
28 changes: 16 additions & 12 deletions Code/OSEK/HwPlatform/ARM/OsAsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@
#ifndef __OS_ASM_H__
#define __OS_ASM_H__

void OsDispatch(void);
void OsCat2IsrIrqWrapper(void);
void OsStartNewTask(uint32 StackFramePtr, pFunc TaskFuncPtr);
void OsGetCurrentSP(uint32* CurrentSpPtr);
void OsGetPSR(uint32* CurrentPsr);
void OsSetSysCtrlReg(uint32 CtrlRegValue);
void OsGetSysCtrlReg(uint32* CtrlRegValue);
void OsSetSysBasepriReg(uint32 BasepriRegValue);
void OsGetSysBasepriReg(uint32* BasepriRegValue);
uint32 OsHwGetInterruptPrioBits(void);
uint32 OsGetSysPrimaskReg(void);
uint32 OsHwSearchForHighPrio(void);
#include <stdint.h>

void osDispatchHandler(void);
void osCat2IsrWrapper(void);
void osStartNewTask(uint32_t StackFramePtr, pFunc TaskFuncPtr);
void osGetCurrentSP(uint32_t* CurrentSpPtr);
void OsGetPSR(uint32_t* CurrentPsr);
void OsSetSysCtrlReg(uint32_t CtrlRegValue);
void OsGetSysCtrlReg(uint32_t* CtrlRegValue);
void OsSetSysBasepriReg(uint32_t BasepriRegValue);
void OsGetSysBasepriReg(uint32_t* BasepriRegValue);

uint32_t OsGetSysPrimaskReg(void);
uint32_t OsHwGetInterruptPrioBits(void);
uint32_t osHwSearchForHighPrio(void);

#endif
34 changes: 17 additions & 17 deletions Code/OSEK/HwPlatform/ARM/OsAsm.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.syntax unified

//-----------------------------------------------------------------------------------------------------------------
// \brief OsDispatchHandler
// \brief void osDispatchHandler(void)
//
// \descr Context switcher
//
Expand All @@ -28,11 +28,11 @@
.thumb_func
.section ".text"
.align 4
.globl OsDispatchHandler
.type OsDispatchHandler, % function
.globl osDispatchHandler
.type osDispatchHandler, % function
.extern osDispatcher

OsDispatchHandler:
osDispatchHandler:

cpsid i
push {r4 - r11, lr}
Expand All @@ -51,7 +51,7 @@ OsDispatchHandler:
bx lr

// ----------------------------------------------------------------------------------------------------------------
// \brief OsCat2IsrWrapper
// \brief void osCat2IsrWrapper(void)
//
// \descr Wrapper for all category 2 interrupts
//
Expand All @@ -62,16 +62,16 @@ OsDispatchHandler:
.thumb_func
.section ".text"
.align 4
.globl OsCat2IsrWrapper
.type OsCat2IsrWrapper, % function
.globl osCat2IsrWrapper
.type osCat2IsrWrapper, % function
.extern osStoreStackPointer
.extern osRunCat2Isr
.extern osGetSavedStackPointer
.extern osIntCallDispatch
.extern osIncNestingDepthLevel
.extern osDecNestingDepthLevel

OsCat2IsrWrapper:
osCat2IsrWrapper:

cpsid i
push {r4 - r11, lr}
Expand All @@ -95,7 +95,7 @@ OsCat2IsrWrapper:
bx lr

//------------------------------------------------------------------------------------------------------------------
/// \brief OsStartNewTask (OsStartNewTask(uint32 StackFramePtr, pFunc TaskFuncPtr))
/// \brief void osStartNewTask(uint32 StackFramePtr, pFunc TaskFuncPtr)
///
/// \descr This function start an OSEK Task for the 1st execution
///
Expand All @@ -106,11 +106,11 @@ OsCat2IsrWrapper:
.thumb_func
.section ".text"
.align 4
.globl OsStartNewTask
.type OsStartNewTask, % function
.globl osStartNewTask
.type osStartNewTask, % function
.extern osErrTaskExitWithoutTerminate

OsStartNewTask:
osStartNewTask:
mov sp,r0
movw r0, #0
movt r0, #0x0100
Expand All @@ -131,7 +131,7 @@ OsStartNewTask:
bx r0

//-----------------------------------------------------------------------------------------------------------------
// \brief OsGetCurrentSP : void OsGetCurrentSP(unsigned int* CurrentSpPtr)
// \brief osGetCurrentSP : void osGetCurrentSP(unsigned int* CurrentSpPtr)
//
// \descr Get the current stack pointer register value
//
Expand All @@ -142,10 +142,10 @@ OsStartNewTask:
.thumb_func
.section ".text"
.align 4
.globl OsGetCurrentSP
.type OsGetCurrentSP, % function
.globl osGetCurrentSP
.type osGetCurrentSP, % function

OsGetCurrentSP:
osGetCurrentSP:

str r13,[r0]
dsb
Expand Down Expand Up @@ -175,7 +175,7 @@ OsGetPSR:
bx lr

//-----------------------------------------------------------------------------------------------------------------
// \brief OsSetSysCtrlReg : void OsSetSysCtrlReg(unsigned int CtrlRegValue)
// \brief OsSetSysCtrlReg : void OsSetSysCtrlReg(uint32 CtrlRegValue)
//
// \descr set the system CONTROL register
//
Expand Down
6 changes: 3 additions & 3 deletions Code/OSEK/HwPlatform/ARM/OsHwSchedPrio.s
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
.thumb_func
.section ".text"
.align 4
.globl OsHwSearchForHighPrio
.type OsHwSearchForHighPrio, %function
.globl osHwSearchForHighPrio
.type osHwSearchForHighPrio, %function
.extern OsSchedPrioTypeSize
.extern OsHwSchedPrioReg

.equ osNoReadyTaskWasFound, 0xA0A0F5F5UL

OsHwSearchForHighPrio:
osHwSearchForHighPrio:
push {r4-r7,lr}
ldr r0,=OsSchedPrioTypeSize
ldr r7, [r0]
Expand Down
14 changes: 9 additions & 5 deletions Code/OSEK/HwPlatform/RISC-V/OsAsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
#ifndef __OS_ASM_H__
#define __OS_ASM_H__

#include <stdint.h>

#ifndef PFUNC_TYPEDEF
#define PFUNC_TYPEDEF
typedef void (*pFunc)(void);
#endif

void OsDispatchHandler(void);
void OsCat2IsrIrqWrapper(void);
void OsStartNewTask(uint32 StackFramePtr, pFunc TaskFuncPtr);
void OsGetCurrentSP(uint32* CurrentSpPtr);
uint32 OsHwSearchForHighPrio(void);
void osDispatchHandler(void);
void osCat2IsrWrapper(void);
void osStartNewTask(uint32_t StackFramePtr, pFunc TaskFuncPtr);
void osSetIntVectTableAddress(uint32_t address);

uint32_t osGetCurrentSP(void);
uint32_t osHwSearchForHighPrio(void);

#endif
50 changes: 25 additions & 25 deletions Code/OSEK/HwPlatform/RISC-V/OsAsm.s
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
.endm

/*-----------------------------------------------------------------------------------------------------------------*/
/* \brief OsDispatchHandler */
/* \brief void osDispatchHandler(void) */
/* */
/* \descr Context switcher */
/* */
Expand All @@ -124,14 +124,14 @@
/*-----------------------------------------------------------------------------------------------------------------*/
.section ".text"
.align 4
.globl OsDispatchHandler
.type OsDispatchHandler, % function
.globl osDispatchHandler
.type osDispatchHandler, % function
.extern osDispatcher

.equ SIO_CPUID, 0xd0000000
.equ SIO_RISCV_SOFTIRQ, 0xd00001a0

OsDispatchHandler:
osDispatchHandler:
OsSaveCpuContext
mv a0, sp
la a1, SIO_RISCV_SOFTIRQ
Expand All @@ -147,10 +147,10 @@ OsDispatchHandler:
csrw mcause, zero
mret

.size OsDispatchHandler, .-OsDispatchHandler
.size osDispatchHandler, .-osDispatchHandler

/* ---------------------------------------------------------------------------------------------------------------- */
/* \brief OsCat2IsrWrapper */
/* \brief void osCat2IsrWrapper(void) */
/* */
/* \descr Wrapper for all category 2 interrupts */
/* */
Expand All @@ -160,16 +160,16 @@ OsDispatchHandler:
/* ---------------------------------------------------------------------------------------------------------------- */
.section ".text"
.align 4
.globl OsCat2IsrWrapper
.type OsCat2IsrWrapper, % function
.globl osCat2IsrWrapper
.type osCat2IsrWrapper, % function
.extern osStoreStackPointer
.extern osRunCat2Isr
.extern osGetSavedStackPointer
.extern osIntCallDispatch
.extern osIncNestingDepthLevel
.extern osDecNestingDepthLevel

OsCat2IsrWrapper:
osCat2IsrWrapper:
OsSaveCpuContext
jal osIncNestingDepthLevel
mv a0, sp
Expand All @@ -183,10 +183,10 @@ OsCat2IsrWrapper:
csrw mcause, zero
mret

.size OsCat2IsrWrapper, .-OsCat2IsrWrapper
.size osCat2IsrWrapper, .-osCat2IsrWrapper

/* ------------------------------------------------------------------------------------------------------------------ */
/* / \brief OsStartNewTask (OsStartNewTask(uint32 StackFramePtr, pFunc TaskFuncPtr)) */
/* / \brief void osStartNewTask(uint32 StackFramePtr, pFunc TaskFuncPtr) */
/* / */
/* / \descr This function start an OSEK Task for the 1st execution */
/* / */
Expand All @@ -196,11 +196,11 @@ OsCat2IsrWrapper:
/* ------------------------------------------------------------------------------------------------------------------ */
.section ".text"
.align 4
.globl OsStartNewTask
.type OsStartNewTask, % function
.globl osStartNewTask
.type osStartNewTask, % function
.extern osErrTaskExitWithoutTerminate

OsStartNewTask:
osStartNewTask:
mv sp,a0
csrrw zero, mepc, a1
lw x1, osErrTaskExitWithoutTerminate
Expand Down Expand Up @@ -236,10 +236,10 @@ OsStartNewTask:
csrw mcause, zero
mret

.size OsStartNewTask, .-OsStartNewTask
.size osStartNewTask, .-osStartNewTask

/* ----------------------------------------------------------------------------------------------------------------- */
/* \brief OsGetCurrentSP : void OsGetCurrentSP(unsigned int* CurrentSpPtr) */
/* \brief osGetCurrentSP : uint32 osGetCurrentSP(void) */
/* */
/* \descr Get the current stack pointer register value */
/* */
Expand All @@ -249,18 +249,18 @@ OsStartNewTask:
/* ----------------------------------------------------------------------------------------------------------------- */
.section ".text"
.align 4
.globl OsGetCurrentSP
.type OsGetCurrentSP, % function
.globl osGetCurrentSP
.type osGetCurrentSP, % function

OsGetCurrentSP:
osGetCurrentSP:
mv a0, sp
ret

.size OsGetCurrentSP, .-OsGetCurrentSP
.size osGetCurrentSP, .-osGetCurrentSP


/* ----------------------------------------------------------------------------------------------------------------- */
/* \brief OsSetIntVectTableAddress : void OsSetIntVectTableAddress(unsigned int* address) */
/* \brief osSetIntVectTableAddress : void osSetIntVectTableAddress(uint32 address) */
/* */
/* \descr */
/* */
Expand All @@ -270,16 +270,16 @@ OsGetCurrentSP:
/* ----------------------------------------------------------------------------------------------------------------- */
.section ".text"
.align 4
.globl OsSetIntVectTableAddress
.type OsSetIntVectTableAddress, % function
.globl osSetIntVectTableAddress
.type osSetIntVectTableAddress, % function

OsSetIntVectTableAddress:
osSetIntVectTableAddress:
/* setup the interrupt vector table */
ori a0, a0, 3
csrw mtvec, a0
ret

.size OsSetIntVectTableAddress, .-OsSetIntVectTableAddress
.size osSetIntVectTableAddress, .-osSetIntVectTableAddress


/*
Expand Down
8 changes: 4 additions & 4 deletions Code/OSEK/HwPlatform/RISC-V/OsHwSchedPrio.s
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

.section ".text", "ax"
.align 4
.globl OsHwSearchForHighPrio
.type OsHwSearchForHighPrio, %function
.globl osHwSearchForHighPrio
.type osHwSearchForHighPrio, %function
.extern OsSchedPrioTypeSize
.extern OsHwSchedPrioReg
.extern __os_sw_clz

.equ osNoReadyTaskWasFound, 0xA0A0F5F5UL

OsHwSearchForHighPrio:
osHwSearchForHighPrio:
addi sp, sp, -4
sw ra, 0(sp)
la a0, OsSchedPrioTypeSize
Expand Down Expand Up @@ -80,7 +80,7 @@ OsHwSearchForHighPrio:
addi sp, sp, 4
ret

.size OsHwSearchForHighPrio, .-OsHwSearchForHighPrio
.size osHwSearchForHighPrio, .-osHwSearchForHighPrio

/*******************************************************************************************
\brief
Expand Down
2 changes: 1 addition & 1 deletion Code/OSEK/OsCore.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ uint32 osDispatcher(uint32 StackPtr)
OCB_Cfg.pTcb[OCB_Cfg.CurrentTaskIdx]->pCurrentStackPointer = NewStackFramePtr;

/* Start the new task */
OsStartNewTask(NewStackFramePtr, NewTaskPtr);
osStartNewTask(NewStackFramePtr, NewTaskPtr);

}
else if(OCB_Cfg.pTcb[OCB_Cfg.CurrentTaskIdx]->TaskStatus == READY)
Expand Down
4 changes: 2 additions & 2 deletions Code/OSEK/OsGenMac.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@

#define OS_INTERRUPT_BEGIN osVectoredIVT:
#define OS_INTERRUPT_CAT1_DEF(IsrFunc,Prio,Type) j IsrFunc
#define OS_INTERRUPT_CAT2_DEF(IsrFunc,Prio,Type) j OsCat2IsrWrapper
#define OS_INTERRUPT_CAT2_DEF(IsrFunc,Prio,Type) j osCat2IsrWrapper
#define OS_INTERRUPT_CATx_DEF(IsrFunc,Prio,Type) j IsrFunc
#define OS_INTERRUPT_END .size osVectoredIVT, .-osVectoredIVT

Expand Down Expand Up @@ -421,7 +421,7 @@

#define OS_INTERRUPT_BEGIN osLookupIVT:
#define OS_INTERRUPT_CAT1_DEF(IsrFunc,Prio,Type) .word IsrFunc
#define OS_INTERRUPT_CAT2_DEF(IsrFunc,Prio,Type) .word OsCat2IsrWrapper
#define OS_INTERRUPT_CAT2_DEF(IsrFunc,Prio,Type) .word osCat2IsrWrapper
#define OS_INTERRUPT_CATx_DEF(IsrFunc,Prio,Type) .word IsrFunc
#define OS_INTERRUPT_END .size osLookupIVT, .-osLookupIVT

Expand Down
Loading

0 comments on commit 9b3a80a

Please sign in to comment.