diff --git a/StateOS/kernel/inc/oseventqueue.h b/StateOS/kernel/inc/oseventqueue.h index ea2e90f7..e683a89e 100644 --- a/StateOS/kernel/inc/oseventqueue.h +++ b/StateOS/kernel/inc/oseventqueue.h @@ -56,10 +56,17 @@ struct __evq unsigned head; // first element to read from data buffer unsigned tail; // first element to write into data buffer unsigned*data; // data buffer - - unsigned :0; }; +#ifdef __cplusplus +} +template +struct evq_T { evq_t evq; unsigned buf[limit_]; }; +extern "C" { +#else +struct evq_T { evq_t evq; unsigned buf[]; }; +#endif + /****************************************************************************** * * Name : _EVQ_INIT @@ -508,7 +515,7 @@ struct EventQueueT : public __evq static EventQueueT *create( void ) { - static_assert(sizeof(__evq) + limit_ * sizeof(unsigned) == sizeof(EventQueueT), "unexpected error!"); + static_assert(sizeof(evq_T) == sizeof(EventQueueT), "unexpected error!"); return reinterpret_cast *>(evq_create(limit_)); } diff --git a/StateOS/kernel/inc/osjobqueue.h b/StateOS/kernel/inc/osjobqueue.h index bf86e4ac..820c24e4 100644 --- a/StateOS/kernel/inc/osjobqueue.h +++ b/StateOS/kernel/inc/osjobqueue.h @@ -57,10 +57,17 @@ struct __job unsigned head; // first element to read from data buffer unsigned tail; // first element to write into data buffer fun_t ** data; // data buffer - - intptr_t :0; }; +#ifdef __cplusplus +} +template +struct job_T { job_t job; fun_t *buf[limit_]; }; +extern "C" { +#else +struct job_T { job_t job; fun_t *buf[]; }; +#endif + /****************************************************************************** * * Name : _JOB_INIT @@ -507,7 +514,7 @@ struct JobQueueT : public __box static JobQueueT *create( void ) { - static_assert(sizeof(__box) + limit_ * sizeof(FUN_t) == sizeof(JobQueueT), "unexpected error!"); + static_assert(sizeof(box_T) == sizeof(JobQueueT), "unexpected error!"); return reinterpret_cast *>(box_create(limit_, sizeof(FUN_t))); } @@ -549,7 +556,7 @@ struct JobQueueT : public __job static JobQueueT *create( void ) { - static_assert(sizeof(__job) + limit_ * sizeof(FUN_t) == sizeof(JobQueueT), "unexpected error!"); + static_assert(sizeof(job_T) == sizeof(JobQueueT), "unexpected error!"); return reinterpret_cast *>(job_create(limit_)); } diff --git a/StateOS/kernel/inc/osmailboxqueue.h b/StateOS/kernel/inc/osmailboxqueue.h index a2466311..c72550bb 100644 --- a/StateOS/kernel/inc/osmailboxqueue.h +++ b/StateOS/kernel/inc/osmailboxqueue.h @@ -57,10 +57,17 @@ struct __box unsigned head; // first element to read from data buffer unsigned tail; // first element to write into data buffer char * data; // data buffer - - char :0; }; +#ifdef __cplusplus +} +template +struct box_T { box_t box; char buf[limit_ * size_]; }; +extern "C" { +#else +struct box_T { box_t box; char buf[]; }; +#endif + /****************************************************************************** * * Name : _BOX_INIT @@ -556,7 +563,7 @@ struct MailBoxQueueT : public __box static MailBoxQueueT *create( void ) { - static_assert(sizeof(__box) + limit_ * size_ == sizeof(MailBoxQueueT), "unexpected error!"); + static_assert(sizeof(box_T) == sizeof(MailBoxQueueT), "unexpected error!"); return reinterpret_cast *>(box_create(limit_, size_)); } @@ -607,7 +614,7 @@ struct MailBoxQueueTT : public MailBoxQueueT static MailBoxQueueTT *create( void ) { - static_assert(sizeof(__box) + limit_ * sizeof(T) == sizeof(MailBoxQueueTT), "unexpected error!"); + static_assert(sizeof(box_T) == sizeof(MailBoxQueueTT), "unexpected error!"); return reinterpret_cast *>(box_create(limit_, sizeof(T))); } diff --git a/StateOS/kernel/inc/osmemorypool.h b/StateOS/kernel/inc/osmemorypool.h index d8991235..917eb1e7 100644 --- a/StateOS/kernel/inc/osmemorypool.h +++ b/StateOS/kernel/inc/osmemorypool.h @@ -59,10 +59,17 @@ struct __mem unsigned limit; // size of a memory pool (max number of objects) unsigned size; // size of memory object (in sizeof(que_t) units) que_t * data; // pointer to memory pool buffer - - intptr_t :0; }; +#ifdef __cplusplus +} +template +struct mem_T { mem_t mem; que_t buf[limit_ * (1 + MEM_SIZE(size_))]; }; +extern "C" { +#else +struct mem_T { mem_t mem; que_t buf[]; }; +#endif + /****************************************************************************** * * Name : _MEM_INIT @@ -442,7 +449,7 @@ struct MemoryPoolT : public __mem static MemoryPoolT *create( void ) { - static_assert(sizeof(__mem) + limit_ * (1 + MEM_SIZE(size_)) * sizeof(que_t) == sizeof(MemoryPoolT), "unexpected error!"); + static_assert(sizeof(mem_T) == sizeof(MemoryPoolT), "unexpected error!"); return reinterpret_cast *>(mem_create(limit_, size_)); } @@ -482,7 +489,7 @@ struct MemoryPoolTT : public MemoryPoolT static MemoryPoolTT *create( void ) { - static_assert(sizeof(__mem) + limit_ * (1 + MEM_SIZE(sizeof(T))) * sizeof(que_t) == sizeof(MemoryPoolTT), "unexpected error!"); + static_assert(sizeof(mem_T) == sizeof(MemoryPoolTT), "unexpected error!"); return reinterpret_cast *>(mem_create(limit_, sizeof(T))); } diff --git a/StateOS/kernel/inc/osmessagebuffer.h b/StateOS/kernel/inc/osmessagebuffer.h index 6029ac96..5c6ad16a 100644 --- a/StateOS/kernel/inc/osmessagebuffer.h +++ b/StateOS/kernel/inc/osmessagebuffer.h @@ -56,10 +56,17 @@ struct __msg unsigned head; // inherited from stream buffer unsigned tail; // inherited from stream buffer char * data; // inherited from stream buffer - - char :0; }; +#ifdef __cplusplus +} +template +struct msg_T { msg_t msg; char buf[limit_]; }; +extern "C" { +#else +struct msg_T { msg_t msg; char buf[]; }; +#endif + /****************************************************************************** * * Name : _MSG_INIT @@ -623,7 +630,7 @@ struct MessageBufferT : public __msg static MessageBufferT *create( void ) { - static_assert(sizeof(__msg) + limit_ == sizeof(MessageBufferT), "unexpected error!"); + static_assert(sizeof(msg_T) == sizeof(MessageBufferT), "unexpected error!"); return reinterpret_cast *>(msg_create(limit_)); } @@ -676,7 +683,7 @@ struct MessageBufferTT : public MessageBufferT *create( void ) { - static_assert(sizeof(__msg) + limit_ * (sizeof(unsigned) + sizeof(T)) == sizeof(MessageBufferTT), "unexpected error!"); + static_assert(sizeof(msg_T) == sizeof(MessageBufferTT), "unexpected error!"); return reinterpret_cast *>(msg_create(limit_ * (sizeof(unsigned) + sizeof(T)))); } diff --git a/StateOS/kernel/inc/osstreambuffer.h b/StateOS/kernel/inc/osstreambuffer.h index bcbfc73f..df912ed3 100644 --- a/StateOS/kernel/inc/osstreambuffer.h +++ b/StateOS/kernel/inc/osstreambuffer.h @@ -56,10 +56,17 @@ struct __stm unsigned head; // first element to read from data buffer unsigned tail; // first element to write into data buffer char * data; // data buffer - - char :0; }; +#ifdef __cplusplus +} +template +struct stm_T { stm_t stm; char buf[limit_]; }; +extern "C" { +#else +struct stm_T { stm_t stm; char buf[]; }; +#endif + /****************************************************************************** * * Name : _STM_INIT @@ -598,7 +605,7 @@ struct StreamBufferT : public __stm static StreamBufferT *create( void ) { - static_assert(sizeof(__stm) + limit_ == sizeof(StreamBufferT), "unexpected error!"); + static_assert(sizeof(stm_T) == sizeof(StreamBufferT), "unexpected error!"); return reinterpret_cast *>(stm_create(limit_)); } @@ -649,7 +656,7 @@ struct StreamBufferTT : public StreamBufferT static StreamBufferTT *create( void ) { - static_assert(sizeof(__stm) + limit_ * sizeof(T) == sizeof(StreamBufferTT), "unexpected error!"); + static_assert(sizeof(stm_T) == sizeof(StreamBufferTT), "unexpected error!"); return reinterpret_cast *>(stm_create(limit_ * sizeof(T))); } diff --git a/StateOS/kernel/inc/ostask.h b/StateOS/kernel/inc/ostask.h index 51eb96bb..7e263037 100644 --- a/StateOS/kernel/inc/ostask.h +++ b/StateOS/kernel/inc/ostask.h @@ -180,9 +180,17 @@ struct __tsk #else #define _TSK_EXTRA #endif - stk_t :0; }; +#ifdef __cplusplus +} +template +struct tsk_T { tsk_t tsk; stk_t buf[STK_SIZE(limit_)]; }; +extern "C" { +#else +struct tsk_T { tsk_t tsk; stk_t buf[]; }; +#endif + /****************************************************************************** * * Name : _TSK_INIT @@ -1317,7 +1325,7 @@ struct TaskT : public baseTask { CriticalSection cs; TaskT *tsk; - static_assert(sizeof(__tsk) + STK_SIZE(size_) * sizeof(stk_t) == sizeof(TaskT), "unexpected error!"); + static_assert(sizeof(tsk_T) == sizeof(TaskT), "unexpected error!"); #if OS_FUNCTIONAL tsk = reinterpret_cast *>(wrk_create(_prio, baseTask::fun_, size_)); tsk->__tsk::fun = _state; @@ -1332,7 +1340,7 @@ struct TaskT : public baseTask { CriticalSection cs; TaskT *tsk; - static_assert(sizeof(__tsk) + STK_SIZE(size_) * sizeof(stk_t) == sizeof(TaskT), "unexpected error!"); + static_assert(sizeof(tsk_T) == sizeof(TaskT), "unexpected error!"); #if OS_FUNCTIONAL tsk = reinterpret_cast *>(wrk_detached(_prio, baseTask::fun_, size_)); tsk->__tsk::fun = _state; diff --git a/StateOS/kernel/src/oseventqueue.c b/StateOS/kernel/src/oseventqueue.c index 207eb350..4a6ca179 100644 --- a/StateOS/kernel/src/oseventqueue.c +++ b/StateOS/kernel/src/oseventqueue.c @@ -2,7 +2,7 @@ @file StateOS: oseventqueue.c @author Rajmund Szymanski - @date 17.11.2018 + @date 19.11.2018 @brief This file provides set of functions for StateOS. ****************************************************************************** @@ -59,6 +59,8 @@ void evq_init( evq_t *evq, unsigned *data, unsigned bufsize ) evq_t *evq_create( unsigned limit ) /* -------------------------------------------------------------------------- */ { + struct + evq_T * tmp; evq_t * evq; unsigned bufsize; @@ -68,9 +70,10 @@ evq_t *evq_create( unsigned limit ) sys_lock(); { bufsize = limit * sizeof(unsigned); - evq = sys_alloc(sizeof(evq_t) + bufsize); - evq_init(evq, (void *)(evq + 1), bufsize); - evq->obj.res = evq; + tmp = sys_alloc(sizeof(struct evq_T) + bufsize); + evq = &tmp->evq; + evq_init(evq, tmp->buf, bufsize); + evq->obj.res = tmp; } sys_unlock(); diff --git a/StateOS/kernel/src/osjobqueue.c b/StateOS/kernel/src/osjobqueue.c index 74bbd054..147243c9 100644 --- a/StateOS/kernel/src/osjobqueue.c +++ b/StateOS/kernel/src/osjobqueue.c @@ -2,7 +2,7 @@ @file StateOS: osjobqueue.c @author Rajmund Szymanski - @date 17.11.2018 + @date 19.11.2018 @brief This file provides set of functions for StateOS. ****************************************************************************** @@ -59,6 +59,8 @@ void job_init( job_t *job, fun_t **data, unsigned bufsize ) job_t *job_create( unsigned limit ) /* -------------------------------------------------------------------------- */ { + struct + job_T * tmp; job_t * job; unsigned bufsize; @@ -68,9 +70,10 @@ job_t *job_create( unsigned limit ) sys_lock(); { bufsize = limit * sizeof(fun_t *); - job = sys_alloc(sizeof(job_t) + bufsize); - job_init(job, (void *)(job + 1), bufsize); - job->obj.res = job; + tmp = sys_alloc(sizeof(struct job_T) + bufsize); + job = &tmp->job; + job_init(job, tmp->buf, bufsize); + job->obj.res = tmp; } sys_unlock(); diff --git a/StateOS/kernel/src/osmailboxqueue.c b/StateOS/kernel/src/osmailboxqueue.c index f44cd39d..a9d43c1f 100644 --- a/StateOS/kernel/src/osmailboxqueue.c +++ b/StateOS/kernel/src/osmailboxqueue.c @@ -2,7 +2,7 @@ @file StateOS: osmailboxqueue.c @author Rajmund Szymanski - @date 17.11.2018 + @date 19.11.2018 @brief This file provides set of functions for StateOS. ****************************************************************************** @@ -61,6 +61,8 @@ void box_init( box_t *box, unsigned size, void *data, unsigned bufsize ) box_t *box_create( unsigned limit, unsigned size ) /* -------------------------------------------------------------------------- */ { + struct + box_T * tmp; box_t * box; unsigned bufsize; @@ -71,9 +73,10 @@ box_t *box_create( unsigned limit, unsigned size ) sys_lock(); { bufsize = limit * size; - box = sys_alloc(sizeof(box_t) + bufsize); - box_init(box, size, (void *)(box + 1), bufsize); - box->obj.res = box; + tmp = sys_alloc(sizeof(struct box_T) + bufsize); + box = &tmp->box; + box_init(box, size, tmp->buf, bufsize); + box->obj.res = tmp; } sys_unlock(); diff --git a/StateOS/kernel/src/osmemorypool.c b/StateOS/kernel/src/osmemorypool.c index cef0e8b8..d233c512 100644 --- a/StateOS/kernel/src/osmemorypool.c +++ b/StateOS/kernel/src/osmemorypool.c @@ -2,7 +2,7 @@ @file StateOS: osmemorypool.c @author Rajmund Szymanski - @date 17.11.2018 + @date 19.11.2018 @brief This file provides set of functions for StateOS. ****************************************************************************** @@ -87,6 +87,8 @@ void mem_init( mem_t *mem, unsigned size, que_t *data, unsigned bufsize ) mem_t *mem_create( unsigned limit, unsigned size ) /* -------------------------------------------------------------------------- */ { + struct + mem_T * tmp; mem_t * mem; unsigned bufsize; @@ -97,9 +99,10 @@ mem_t *mem_create( unsigned limit, unsigned size ) sys_lock(); { bufsize = limit * (1 + MEM_SIZE(size)) * sizeof(que_t); - mem = sys_alloc(sizeof(mem_t) + bufsize); - mem_init(mem, size, (void *)(mem + 1), bufsize); - mem->lst.obj.res = mem; + tmp = sys_alloc(sizeof(struct mem_T) + bufsize); + mem = &tmp->mem; + mem_init(mem, size, tmp->buf, bufsize); + mem->lst.obj.res = tmp; } sys_unlock(); diff --git a/StateOS/kernel/src/osmessagebuffer.c b/StateOS/kernel/src/osmessagebuffer.c index 95fa9bf5..6adc8a2a 100644 --- a/StateOS/kernel/src/osmessagebuffer.c +++ b/StateOS/kernel/src/osmessagebuffer.c @@ -2,7 +2,7 @@ @file StateOS: osmessagebuffer.c @author Rajmund Szymanski - @date 17.11.2018 + @date 19.11.2018 @brief This file provides set of functions for StateOS. ****************************************************************************** @@ -59,6 +59,8 @@ void msg_init( msg_t *msg, void *data, unsigned bufsize ) msg_t *msg_create( unsigned limit ) /* -------------------------------------------------------------------------- */ { + struct + msg_T * tmp; msg_t * msg; unsigned bufsize; @@ -68,9 +70,10 @@ msg_t *msg_create( unsigned limit ) sys_lock(); { bufsize = limit; - msg = sys_alloc(sizeof(msg_t) + bufsize); - msg_init(msg, (void *)(msg + 1), bufsize); - msg->obj.res = msg; + tmp = sys_alloc(sizeof(struct msg_T) + bufsize); + msg = &tmp->msg; + msg_init(msg, tmp->buf, bufsize); + msg->obj.res = tmp; } sys_unlock(); diff --git a/StateOS/kernel/src/osstreambuffer.c b/StateOS/kernel/src/osstreambuffer.c index 413120ca..b4157991 100644 --- a/StateOS/kernel/src/osstreambuffer.c +++ b/StateOS/kernel/src/osstreambuffer.c @@ -2,7 +2,7 @@ @file StateOS: osstreambuffer.c @author Rajmund Szymanski - @date 17.11.2018 + @date 19.11.2018 @brief This file provides set of functions for StateOS. ****************************************************************************** @@ -59,6 +59,8 @@ void stm_init( stm_t *stm, void *data, unsigned bufsize ) stm_t *stm_create( unsigned limit ) /* -------------------------------------------------------------------------- */ { + struct + stm_T * tmp; stm_t * stm; unsigned bufsize; @@ -68,9 +70,10 @@ stm_t *stm_create( unsigned limit ) sys_lock(); { bufsize = limit; - stm = sys_alloc(sizeof(stm_t) + bufsize); - stm_init(stm, (void *)(stm + 1), bufsize); - stm->obj.res = stm; + tmp = sys_alloc(sizeof(struct stm_T) + bufsize); + stm = &tmp->stm; + stm_init(stm, tmp->buf, bufsize); + stm->obj.res = tmp; } sys_unlock(); diff --git a/StateOS/kernel/src/ostask.c b/StateOS/kernel/src/ostask.c index 7987e288..4a63256b 100644 --- a/StateOS/kernel/src/ostask.c +++ b/StateOS/kernel/src/ostask.c @@ -2,7 +2,7 @@ @file StateOS: ostask.c @author Rajmund Szymanski - @date 17.11.2018 + @date 19.11.2018 @brief This file provides set of functions for StateOS. ****************************************************************************** @@ -66,6 +66,8 @@ void tsk_init( tsk_t *tsk, unsigned prio, fun_t *state, stk_t *stack, unsigned s tsk_t *wrk_create( unsigned prio, fun_t *state, unsigned size ) /* -------------------------------------------------------------------------- */ { + struct + tsk_T * tmp; tsk_t * tsk; unsigned bufsize; @@ -76,9 +78,10 @@ tsk_t *wrk_create( unsigned prio, fun_t *state, unsigned size ) sys_lock(); { bufsize = STK_SIZE(size) * sizeof(stk_t); - tsk = sys_alloc(sizeof(tsk_t) + bufsize); - tsk_init(tsk, prio, state, (void *)(tsk + 1), bufsize); - tsk->hdr.obj.res = tsk; + tmp = sys_alloc(sizeof(struct tsk_T) + bufsize); + tsk = &tmp->tsk; + tsk_init(tsk, prio, state, tmp->buf, bufsize); + tsk->hdr.obj.res = tmp; } sys_unlock();