Skip to content

Commit

Permalink
rebuilded kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajmund Szymanski committed Jan 26, 2017
1 parent 1bbd024 commit e00e234
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 68 deletions.
1 change: 1 addition & 0 deletions StateOS/README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions StateOS/kernel/ARMCC/oscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
******************************************************************************
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions StateOS/kernel/CLANG/oscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
******************************************************************************
Expand Down Expand Up @@ -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"
);
Expand Down
10 changes: 5 additions & 5 deletions StateOS/kernel/CSMCC/oscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
******************************************************************************
Expand Down Expand Up @@ -36,7 +36,6 @@
void PendSV_Handler( void )
{
#asm

xref _core_tsk_handler

#if __CORTEX_M < 3
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions StateOS/kernel/GNUCC/oscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
******************************************************************************
Expand Down Expand Up @@ -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"
Expand Down
44 changes: 27 additions & 17 deletions StateOS/kernel/osbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
******************************************************************************
Expand Down Expand Up @@ -126,29 +126,39 @@ 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;

} ctx_t;

/* -------------------------------------------------------------------------- */

#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
Expand Down
37 changes: 17 additions & 20 deletions StateOS/kernel/oskernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
******************************************************************************
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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;
Expand Down
26 changes: 8 additions & 18 deletions StateOS/kernel/oskernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
******************************************************************************
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e00e234

Please sign in to comment.