Skip to content

Commit

Permalink
added box_push, msg_push and job_push functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajmund Szymanski committed Apr 9, 2018
1 parent f7a76df commit 57739e8
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 13 deletions.
1 change: 1 addition & 0 deletions StateOS/README
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Features:
- updated list object
- updated examples
- updated kernel
- added box_push, msg_push and job_push functions
---------
5.6
- changed license to MIT
Expand Down
27 changes: 26 additions & 1 deletion StateOS/kernel/inc/os_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: os_box.h
@author Rajmund Szymanski
@date 24.01.2018
@date 09.04.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -448,6 +448,29 @@ unsigned box_give( box_t *box, const void *data ) { return box_sendFor(box, data
__STATIC_INLINE
unsigned box_giveISR( box_t *box, const void *data ) { return box_sendFor(box, data, IMMEDIATE); }

/******************************************************************************
*
* Name : box_push
* ISR alias : box_pushISR
*
* Description : transfer mailbox data to the mailbox queue object,
* remove the oldest mailbox data if the mailbox queue object is full
*
* Parameters
* box : pointer to mailbox queue object
* data : pointer to mailbox data
*
* Return : none
*
* Note : may be used both in thread and handler mode
*
******************************************************************************/

void box_push( box_t *box, const void *data );

__STATIC_INLINE
void box_pushISR( box_t *box, const void *data ) { box_push(box, data); }

#ifdef __cplusplus
}
#endif
Expand Down Expand Up @@ -488,6 +511,8 @@ struct baseMailBoxQueue : public __box
unsigned send ( const void *_data ) { return box_send (this, _data); }
unsigned give ( const void *_data ) { return box_give (this, _data); }
unsigned giveISR ( const void *_data ) { return box_giveISR (this, _data); }
void push ( const void *_data ) { box_push (this, _data); }
void pushISR ( const void *_data ) { box_pushISR (this, _data); }
};

/******************************************************************************
Expand Down
29 changes: 28 additions & 1 deletion StateOS/kernel/inc/os_job.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: os_job.h
@author Rajmund Szymanski
@date 24.01.2018
@date 09.04.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -432,6 +432,29 @@ unsigned job_give( job_t *job, fun_t *fun ) { return job_sendFor(job, fun, IMMED
__STATIC_INLINE
unsigned job_giveISR( job_t *job, fun_t *fun ) { return job_sendFor(job, fun, IMMEDIATE); }

/******************************************************************************
*
* Name : job_push
* ISR alias : job_pushISR
*
* Description : transfer job data to the job queue object,
* remove the oldest job data if the job queue object is full
*
* Parameters
* job : pointer to job queue object
* fun : pointer to job procedure
*
* Return : none
*
* Note : may be used both in thread and handler mode
*
******************************************************************************/

void job_push( job_t *job, fun_t *fun );

__STATIC_INLINE
void job_pushISR( job_t *job, fun_t *fun ) { job_push(job, fun); }

#ifdef __cplusplus
}
#endif
Expand Down Expand Up @@ -472,6 +495,8 @@ struct baseJobQueue : public __box
unsigned send ( FUN_t _fun ) { unsigned event = box_send (this, &_fun); return event; }
unsigned give ( FUN_t _fun ) { unsigned event = box_give (this, &_fun); return event; }
unsigned giveISR ( FUN_t _fun ) { unsigned event = box_giveISR (this, &_fun); return event; }
void push ( FUN_t _fun ) { box_push (this, &_fun); }
void pushISR ( FUN_t _fun ) { box_pushISR (this, &_fun); }
};

#else
Expand All @@ -492,6 +517,8 @@ struct baseJobQueue : public __job
unsigned send ( FUN_t _fun ) { return job_send (this, _fun); }
unsigned give ( FUN_t _fun ) { return job_give (this, _fun); }
unsigned giveISR ( FUN_t _fun ) { return job_giveISR (this, _fun); }
void push ( FUN_t _fun ) { job_push (this, _fun); }
void pushISR ( FUN_t _fun ) { job_pushISR (this, _fun); }
};

#endif
Expand Down
27 changes: 26 additions & 1 deletion StateOS/kernel/inc/os_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: os_msg.h
@author Rajmund Szymanski
@date 24.01.2018
@date 09.04.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -440,6 +440,29 @@ unsigned msg_give( msg_t *msg, unsigned data ) { return msg_sendFor(msg, data, I
__STATIC_INLINE
unsigned msg_giveISR( msg_t *msg, unsigned data ) { return msg_sendFor(msg, data, IMMEDIATE); }

/******************************************************************************
*
* Name : msg_push
* ISR alias : msg_pushISR
*
* Description : transfer message data to the message queue object,
* remove the oldest message data if the message queue object is full
*
* Parameters
* msg : pointer to message queue object
* data : message data
*
* Return : none
*
* Note : may be used both in thread and handler mode
*
******************************************************************************/

void msg_push( msg_t *msg, unsigned data );

__STATIC_INLINE
void msg_pushISR( msg_t *msg, unsigned data ) { msg_push(msg, data); }

#ifdef __cplusplus
}
#endif
Expand Down Expand Up @@ -479,6 +502,8 @@ struct baseMessageQueue : public __msg
unsigned send ( unsigned _data ) { return msg_send (this, _data); }
unsigned give ( unsigned _data ) { return msg_give (this, _data); }
unsigned giveISR ( unsigned _data ) { return msg_giveISR (this, _data); }
void push ( unsigned _data ) { msg_push (this, _data); }
void pushISR ( unsigned _data ) { msg_pushISR (this, _data); }
};

/******************************************************************************
Expand Down
42 changes: 34 additions & 8 deletions StateOS/kernel/src/os_box.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: os_box.c
@author Rajmund Szymanski
@date 24.01.2018
@date 09.04.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -110,7 +110,7 @@ void priv_box_get( box_t *box, void *data )
/* -------------------------------------------------------------------------- */
{
unsigned i;
char*buf = box->data + box->size * box->first;
char * buf = box->data + box->size * box->first;

for (i = 0; i < box->size; i++) ((char*)data)[i] = buf[i];

Expand All @@ -120,11 +120,11 @@ void priv_box_get( box_t *box, void *data )

/* -------------------------------------------------------------------------- */
static
void priv_box_put( box_t *box, void *data )
void priv_box_put( box_t *box, const void *data )
/* -------------------------------------------------------------------------- */
{
unsigned i;
char*buf = box->data + box->size * box->next;
char * buf = box->data + box->size * box->next;

for (i = 0; i < box->size; i++) buf[i] = ((char*)data)[i];

Expand Down Expand Up @@ -185,7 +185,7 @@ unsigned box_waitFor( box_t *box, void *data, cnt_t delay )

/* -------------------------------------------------------------------------- */
static
unsigned priv_box_send( box_t *box, void *data, cnt_t time, unsigned(*wait)(void*,cnt_t) )
unsigned priv_box_send( box_t *box, const void *data, cnt_t time, unsigned(*wait)(void*,cnt_t) )
/* -------------------------------------------------------------------------- */
{
tsk_t * tsk;
Expand All @@ -198,7 +198,7 @@ unsigned priv_box_send( box_t *box, void *data, cnt_t time, unsigned(*wait)(void

if (box->count >= box->limit)
{
System.cur->tmp.data = data;
System.cur->tmp.data = (void*)data;

event = wait(box, time);
}
Expand All @@ -222,7 +222,7 @@ unsigned box_sendUntil( box_t *box, const void *data, cnt_t time )
{
assert(!port_isr_inside());

return priv_box_send(box, (void*)data, time, core_tsk_waitUntil);
return priv_box_send(box, data, time, core_tsk_waitUntil);
}

/* -------------------------------------------------------------------------- */
Expand All @@ -231,7 +231,33 @@ unsigned box_sendFor( box_t *box, const void *data, cnt_t delay )
{
assert(!port_isr_inside() || !delay);

return priv_box_send(box, (void*)data, delay, core_tsk_waitFor);
return priv_box_send(box, data, delay, core_tsk_waitFor);
}

/* -------------------------------------------------------------------------- */
void box_push( box_t *box, const void *data )
/* -------------------------------------------------------------------------- */
{
tsk_t *tsk;

assert(box);
assert(data);

port_sys_lock();

while (box->count >= box->limit)
{
box->first = (box->first + 1) % box->limit;
box->count--;
}

priv_box_put(box, data);

tsk = core_one_wakeup(box, E_SUCCESS);

if (tsk) priv_box_get(box, tsk->tmp.data);

port_sys_unlock();
}

/* -------------------------------------------------------------------------- */
28 changes: 27 additions & 1 deletion StateOS/kernel/src/os_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: os_job.c
@author Rajmund Szymanski
@date 24.01.2018
@date 09.04.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -227,3 +227,29 @@ unsigned job_sendFor( job_t *job, fun_t *fun, cnt_t delay )
}

/* -------------------------------------------------------------------------- */
void job_push( job_t *job, fun_t *fun )
/* -------------------------------------------------------------------------- */
{
tsk_t *tsk;

assert(job);
assert(fun);

port_sys_lock();

while (job->count >= job->limit)
{
job->first = (job->first + 1) % job->limit;
job->count--;
}

priv_job_put(job, fun);

tsk = core_one_wakeup(job, E_SUCCESS);

if (tsk) priv_job_get(job, &tsk->tmp.fun);

port_sys_unlock();
}

/* -------------------------------------------------------------------------- */
27 changes: 26 additions & 1 deletion StateOS/kernel/src/os_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: os_msg.c
@author Rajmund Szymanski
@date 24.01.2018
@date 09.04.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -225,3 +225,28 @@ unsigned msg_sendFor( msg_t *msg, unsigned data, cnt_t delay )
}

/* -------------------------------------------------------------------------- */
void msg_push( msg_t *msg, unsigned data )
/* -------------------------------------------------------------------------- */
{
tsk_t *tsk;

assert(msg);

port_sys_lock();

while (msg->count >= msg->limit)
{
msg->first = (msg->first + 1) % msg->limit;
msg->count--;
}

priv_msg_put(msg, data);

tsk = core_one_wakeup(msg, E_SUCCESS);

if (tsk) priv_msg_get(msg, tsk->tmp.data);

port_sys_unlock();
}

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

0 comments on commit 57739e8

Please sign in to comment.