Skip to content

Commit

Permalink
updated kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
rajszym committed Apr 16, 2018
1 parent 70b2ba0 commit 75bc08b
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 80 deletions.
1 change: 1 addition & 0 deletions StateOS/README
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Features:
- removed direct semaphore (use signal instead)
- updated const qualifiers
- changed syntax of box_init function
- updated kernel
---------
5.7
- updated memory pool object
Expand Down
16 changes: 8 additions & 8 deletions StateOS/cmsis-rtos/cmsis_os2.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@file StateOS: cmsis_os2.c
@author Rajmund Szymanski
@date 15.04.2018
@date 16.04.2018
@brief CMSIS-RTOS2 API implementation for StateOS.
******************************************************************************
Expand Down Expand Up @@ -256,9 +256,9 @@ osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAtt
sys_lock();

tsk_init(&thread->tsk, (attr == NULL) ? osPriorityNormal : attr->priority, thread_handler, stack_mem, stack_size);
if (attr->cb_mem == NULL || attr->cb_size == 0U) thread->tsk.res = thread;
if (attr->cb_mem == NULL || attr->cb_size == 0U) thread->tsk.obj.res = thread;
else
if (attr->stack_mem == NULL || attr->stack_size == 0U) thread->tsk.res = stack_mem;
if (attr->stack_mem == NULL || attr->stack_size == 0U) thread->tsk.obj.res = stack_mem;
thread->tsk.join = (flags & osThreadJoinable) ? JOINABLE : DETACHED;
flg_init(&thread->flg);
thread->flags = flags;
Expand Down Expand Up @@ -467,10 +467,10 @@ uint32_t osThreadGetCount (void)

count++;

for (tsk = IDLE.next; tsk != &IDLE; tsk = tsk->next)
for (tsk = IDLE.obj.next; tsk != &IDLE; tsk = tsk->obj.next)
count++;

for (tmr = WAIT.next; tmr != &WAIT; tmr = tmr->next)
for (tmr = WAIT.obj.next; tmr != &WAIT; tmr = tmr->obj.next)
if (tmr->id == ID_DELAYED)
count++;

Expand All @@ -492,10 +492,10 @@ uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items)

thread_array[count++] = &IDLE;

for (tsk = IDLE.next; (tsk != &IDLE) && (count < array_items); tsk = tsk->next)
for (tsk = IDLE.obj.next; (tsk != &IDLE) && (count < array_items); tsk = tsk->obj.next)
thread_array[count++] = tsk;

for (tmr = WAIT.next; (tmr != &WAIT) && (count < array_items); tmr = tmr->next)
for (tmr = WAIT.obj.next; (tmr != &WAIT) && (count < array_items); tmr = tmr->obj.next)
if (tmr->id == ID_DELAYED)
thread_array[count++] = tmr;

Expand Down Expand Up @@ -622,7 +622,7 @@ osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument,
sys_lock();

tmr_init(&timer->tmr, timer_handler);
if (attr->cb_mem == NULL || attr->cb_size == 0U) timer->tmr.res = timer;
if (attr->cb_mem == NULL || attr->cb_size == 0U) timer->tmr.obj.res = timer;
timer->flags = flags;
timer->name = (attr == NULL) ? NULL : attr->name;
timer->func = func;
Expand Down
15 changes: 6 additions & 9 deletions StateOS/kernel/inc/os_tmr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: os_tmr.h
@author Rajmund Szymanski
@date 13.04.2018
@date 16.04.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -46,11 +46,8 @@ extern "C" {

struct __tmr
{
tsk_t * queue; // next task in the DELAYED queue
void * res; // allocated object's resource
obj_t obj; // object header
unsigned id; // timer's id: ID_STOPPED, ID_DELAYED, ID_TIMER
tmr_t * prev; // previous timer in the READY queue
tmr_t * next; // next timer in the READY queue

fun_t * state; // callback procedure
cnt_t start;
Expand All @@ -74,7 +71,7 @@ struct __tmr
*
******************************************************************************/

#define _TMR_INIT( _state ) { 0, 0, 0, 0, 0, _state, 0, 0, 0 }
#define _TMR_INIT( _state ) { _OBJ_INIT(), 0, _state, 0, 0, 0 }

/******************************************************************************
*
Expand Down Expand Up @@ -305,7 +302,7 @@ struct __tmr
******************************************************************************/

__STATIC_INLINE
tmr_t *tmr_thisISR( void ) { return (tmr_t *) WAIT.next; }
tmr_t *tmr_thisISR( void ) { return (tmr_t *) WAIT.obj.next; }

/******************************************************************************
*
Expand Down Expand Up @@ -693,7 +690,7 @@ struct Timer : public __tmr
bool operator!( void ) { return __tmr::id == ID_STOPPED; }
#if OS_FUNCTIONAL
static
void run_( void ) { ((Timer *) WAIT.next)->fun_(); }
void run_( void ) { ((Timer *) WAIT.obj.next)->fun_(); }
FUN_t fun_;
#endif
};
Expand Down Expand Up @@ -804,7 +801,7 @@ struct startTimerPeriodic : public startTimer
namespace ThisTimer
{
#if OS_FUNCTIONAL
static inline void flipISR ( FUN_t _state ) { ((Timer *) WAIT.next)->fun_ = _state;
static inline void flipISR ( FUN_t _state ) { ((Timer *) WAIT.obj.next)->fun_ = _state;
tmr_flipISR (Timer::run_); }
#else
static inline void flipISR ( FUN_t _state ) { tmr_flipISR (_state); }
Expand Down
11 changes: 4 additions & 7 deletions StateOS/kernel/inc/os_tsk.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: os_tsk.h
@author Rajmund Szymanski
@date 13.04.2018
@date 16.04.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -48,11 +48,8 @@ extern "C" {

struct __tsk
{
tsk_t * queue; // next task in the DELAYED queue
void * res; // allocated object's resource
obj_t obj; // inherited from timer
unsigned id; // task's id: ID_STOPPED, ID_READY, ID_DELAYED, ID_IDLE
tsk_t * prev; // previous task in the READY queue
tsk_t * next; // next task in the READY queue

fun_t * state; // inherited from timer
cnt_t start; // inherited from timer
Expand Down Expand Up @@ -112,10 +109,10 @@ struct __tsk

#if defined(__ARMCC_VERSION) && !defined(__MICROLIB)
#define _TSK_INIT( _prio, _state, _stack, _size ) \
{ 0, 0, 0, 0, 0, _state, 0, 0, 0, 0, 0, _stack+SSIZE(_size), _stack, _prio, _prio, 0, 0, 0, 0, 0, { 0 }, { 0 }, { 0 } }
{ _OBJ_INIT(), 0, _state, 0, 0, 0, 0, 0, _stack+SSIZE(_size), _stack, _prio, _prio, 0, 0, 0, 0, 0, { 0 }, { 0 }, { 0 } }
#else
#define _TSK_INIT( _prio, _state, _stack, _size ) \
{ 0, 0, 0, 0, 0, _state, 0, 0, 0, 0, 0, _stack+SSIZE(_size), _stack, _prio, _prio, 0, 0, 0, 0, 0, { 0 }, { 0 } }
{ _OBJ_INIT(), 0, _state, 0, 0, 0, 0, 0, _stack+SSIZE(_size), _stack, _prio, _prio, 0, 0, 0, 0, 0, { 0 }, { 0 } }
#endif

/******************************************************************************
Expand Down
18 changes: 17 additions & 1 deletion 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 31.03.2018
@date 16.04.2018
@brief This file contains basic definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -85,6 +85,22 @@ struct __que

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

// object (timer, task) header

typedef struct __obj obj_t;

struct __obj
{
tsk_t * queue; // next process in the DELAYED queue
void * res; // allocated object's resource
void * prev; // previous object (timer, task) in the READY queue
void * next; // next object (timer, task) in the READY queue
};

#define _OBJ_INIT() { 0, 0, 0, 0 }

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

// system data

typedef struct __sys sys_t;
Expand Down
Loading

0 comments on commit 75bc08b

Please sign in to comment.