diff --git a/StateOS/README b/StateOS/README index c7170b8c..bc10b6cd 100644 --- a/StateOS/README +++ b/StateOS/README @@ -35,6 +35,7 @@ Features: - added sys_alloc and sys_free procedures - updated cmsis-rtos and nasa-osal - added changes in some definitions +- rebuilded kernel --------- 4.3 - rebuilded internal preprocessor definitions diff --git a/StateOS/kernel/ARMCC/oscore.c b/StateOS/kernel/ARMCC/oscore.c index b5af1ddc..7da06e7f 100644 --- a/StateOS/kernel/ARMCC/oscore.c +++ b/StateOS/kernel/ARMCC/oscore.c @@ -2,7 +2,7 @@ @file StateOS: oscore.c @author Rajmund Szymanski - @date 21.12.2016 + @date 25.01.2017 @brief StateOS port file for ARM Cotrex-M uC. ****************************************************************************** @@ -122,10 +122,12 @@ priv_ctx_exit __asm void core_tsk_flip( void *sp ) { PRESERVE8 - IMPORT core_tsk_break + IMPORT core_ctx_switch + IMPORT core_tsk_start mov sp, r0 - bl core_tsk_break + bl core_ctx_switch + bl core_tsk_start ALIGN } diff --git a/StateOS/kernel/CLANG/oscore.c b/StateOS/kernel/CLANG/oscore.c index c3db8ec4..e516ef17 100644 --- a/StateOS/kernel/CLANG/oscore.c +++ b/StateOS/kernel/CLANG/oscore.c @@ -2,7 +2,7 @@ @file StateOS: oscore.c @author Rajmund Szymanski - @date 21.12.2016 + @date 25.01.2017 @brief StateOS port file for ARM Cotrex-M uC. ****************************************************************************** @@ -121,12 +121,13 @@ void PendSV_Handler( void ) /* -------------------------------------------------------------------------- */ __attribute__((naked)) -void core_tsk_flip() +void core_tsk_flip(/*void *sp*/) { __asm volatile ( " mov sp, r0 \n" -" bl core_tsk_break \n" +" bl core_ctx_switch \n" +" bl core_tsk_start \n" ::: "memory" ); diff --git a/StateOS/kernel/CSMCC/oscore.c b/StateOS/kernel/CSMCC/oscore.c index 15562027..bb092a53 100644 --- a/StateOS/kernel/CSMCC/oscore.c +++ b/StateOS/kernel/CSMCC/oscore.c @@ -2,7 +2,7 @@ @file StateOS: oscore.c @author Rajmund Szymanski - @date 21.12.2016 + @date 25.01.2017 @brief StateOS port file for ARM Cotrex-M uC. ****************************************************************************** @@ -36,7 +36,6 @@ void PendSV_Handler( void ) { #asm - xref _core_tsk_handler #if __CORTEX_M < 3 @@ -123,11 +122,12 @@ priv_ctx_exit void core_tsk_flip( void *sp ) { #asm - - xref _core_tsk_break + xref _core_ctx_switch + xref _core_tsk_start mov sp, r0 - bl _core_tsk_break + bl _core_ctx_switch + bl _core_tsk_start #endasm } diff --git a/StateOS/kernel/GNUCC/oscore.c b/StateOS/kernel/GNUCC/oscore.c index 67f4dfae..62e87148 100644 --- a/StateOS/kernel/GNUCC/oscore.c +++ b/StateOS/kernel/GNUCC/oscore.c @@ -2,7 +2,7 @@ @file StateOS: oscore.c @author Rajmund Szymanski - @date 21.12.2016 + @date 25.01.2017 @brief StateOS port file for ARM Cotrex-M uC. ****************************************************************************** @@ -126,7 +126,8 @@ void core_tsk_flip( void *sp ) __asm volatile ( " mov sp, %[sp] \n" -" bl core_tsk_break \n" +" bl core_ctx_switch \n" +" bl core_tsk_start \n" :: [sp]"r"(sp) : "memory" diff --git a/StateOS/kernel/osbase.h b/StateOS/kernel/osbase.h index 63ebc231..66ffabac 100644 --- a/StateOS/kernel/osbase.h +++ b/StateOS/kernel/osbase.h @@ -2,7 +2,7 @@ @file StateOS: osbase.h @author Rajmund Szymanski - @date 13.01.2017 + @date 25.01.2017 @brief This file contains basic definitions for StateOS. ****************************************************************************** @@ -126,22 +126,11 @@ typedef struct __sys typedef struct __ctx { - unsigned r4; // context saved by the software - unsigned r5; - unsigned r6; - unsigned r7; - unsigned r8; - unsigned r9; - unsigned r10; - unsigned r11; - unsigned exc; // EXC_RETURN - - unsigned r0; // context saved by the hardware - unsigned r1; - unsigned r2; - unsigned r3; - void * ip; - fun_t * lr; + // context saved by the software + unsigned h[8]; // r4-r11 + unsigned lr; // EXC_RETURN + // context saved by the hardware + unsigned l[6]; // r0-r3,ip,lr fun_t * pc; unsigned psr; @@ -149,6 +138,27 @@ typedef struct __ctx /* -------------------------------------------------------------------------- */ +#define _CTX_INIT( pc ) { { 0 }, 0xFFFFFFFD, { 0 }, pc, 0x01000000 } + +__STATIC_INLINE +void port_ctx_init( ctx_t *ctx, fun_t *pc ) +{ + ctx->lr = 0xFFFFFFFD; // EXC_RETURN: return from psp + ctx->pc = pc; + ctx->psr = 0x01000000; +} + +/* -------------------------------------------------------------------------- */ + +// procedure inside ISR? +__STATIC_INLINE +unsigned port_isr_inside( void ) +{ + return __get_IPSR(); +} + +/* -------------------------------------------------------------------------- */ + #ifdef __cplusplus } #endif diff --git a/StateOS/kernel/oskernel.c b/StateOS/kernel/oskernel.c index 4e23c814..0dbead0b 100644 --- a/StateOS/kernel/oskernel.c +++ b/StateOS/kernel/oskernel.c @@ -2,7 +2,7 @@ @file StateOS: oskernel.c @author Rajmund Szymanski - @date 22.01.2017 + @date 26.01.2017 @brief This file provides set of variables and functions for StateOS. ****************************************************************************** @@ -49,8 +49,8 @@ static struct { stk_t STK[ASIZE(OS_STACK_SIZE)]; } MAIN_STACK; #endif static union { stk_t STK[ASIZE(OS_STACK_SIZE)]; - struct { char stk[ASIZE(OS_STACK_SIZE)*sizeof(stk_t)-sizeof(ctx_t)]; ctx_t ctx; } CTX; } IDLE_STACK = - { .CTX={ .ctx={ .exc=0xFFFFFFFD, .lr=core_tsk_break, .pc=priv_tsk_idle, .psr=0x01000000 } } }; + struct { char stk[sizeof(stk_t[ASIZE(OS_STACK_SIZE)])-sizeof(ctx_t)]; ctx_t ctx; } CTX; } IDLE_STACK = + { .CTX = { .ctx = _CTX_INIT(core_tsk_start) } }; #define IDLE_TOP &IDLE_STACK+1 #define IDLE_SP &IDLE_STACK.CTX.ctx @@ -129,6 +129,17 @@ void core_tsk_remove( tsk_t *tsk ) /* -------------------------------------------------------------------------- */ +void core_ctx_init( tsk_t *tsk ) +{ + ctx_t *ctx = (ctx_t *)tsk->top - 1; + + port_ctx_init(ctx, core_tsk_start); + + tsk->sp = ctx; +} + +/* -------------------------------------------------------------------------- */ + void core_ctx_switch( void ) { tsk_t *cur = IDLE.obj.next; @@ -139,13 +150,13 @@ void core_ctx_switch( void ) /* -------------------------------------------------------------------------- */ -void core_tsk_break( void ) +void core_tsk_start( void ) { for (;;) { - core_ctx_switch(); port_clr_lock(); - System.cur->state(); + Current->state(); + core_ctx_switch(); } } @@ -297,20 +308,6 @@ void core_tsk_prio( tsk_t *tsk, unsigned prio ) /* -------------------------------------------------------------------------- */ -void core_ctx_init( tsk_t *tsk ) -{ - ctx_t *ctx = (ctx_t *)tsk->top - 1; - - ctx->psr = 0x01000000; - ctx->pc = tsk->state; - ctx->lr = core_tsk_break; - ctx->exc = 0xFFFFFFFD; // EXC_RETURN: return from psp - - tsk->sp = ctx; -} - -/* -------------------------------------------------------------------------- */ - void *core_tsk_handler( void *sp ) { tsk_t *cur, *nxt; diff --git a/StateOS/kernel/oskernel.h b/StateOS/kernel/oskernel.h index 16f8281b..1ece5152 100644 --- a/StateOS/kernel/oskernel.h +++ b/StateOS/kernel/oskernel.h @@ -2,7 +2,7 @@ @file StateOS: oskernel.h @author Rajmund Szymanski - @date 24.01.2017 + @date 25.01.2017 @brief This file defines set of kernel functions for StateOS. ****************************************************************************** @@ -52,9 +52,16 @@ void port_sys_init( void ); /* -------------------------------------------------------------------------- */ +// init task 'tsk' for context switch +void core_ctx_init( tsk_t *tsk ); + // save status of current process and force yield system control to the next void core_ctx_switch( void ); +// start current process +__NO_RETURN +void core_tsk_start( void ); + // reset context switch indicator __STATIC_INLINE void core_ctx_reset( void ) @@ -91,10 +98,6 @@ void core_tmr_handler( void ); __NO_RETURN void core_tsk_flip( void *sp ); -// abort and reset current process and force yield system control to the next -__NO_RETURN -void core_tsk_break( void ); - // add task 'tsk' to tasks READY queue with id ID_READY // force context switch if priority of task 'tsk' is greater then priority of current task and kernel works in preemptive mode void core_tsk_insert( tsk_t *tsk ); @@ -152,10 +155,6 @@ void core_all_wakeup( void *obj, unsigned event ); // force context switch if new priority of task 'tsk' is greater then priority of current task and kernel works in preemptive mode void core_tsk_prio( tsk_t *tsk, unsigned prio ); -// init task 'tsk' stack -// prepare stack the starting task for context switch -void core_ctx_init( tsk_t *tsk ); - // tasks queue handler procedure // save stack pointer 'sp' of the current task // reset context switch timer counter @@ -164,15 +163,6 @@ void *core_tsk_handler( void *sp ); /* -------------------------------------------------------------------------- */ -// procedure inside ISR? -__STATIC_INLINE -unsigned port_isr_inside( void ) -{ - return __get_IPSR(); -} - -/* -------------------------------------------------------------------------- */ - #ifdef __cplusplus } #endif