17#include <basictypes.h>
31#define OS_LO_PRIO (OS_MAX_PRIOS-1)
40#define OS_STAT_RDY 0x00
41#define OS_STAT_MBOX 0x01
42#define OS_STAT_SEM 0x02
44#define OS_STAT_FIFO 0x08
45#define OS_STAT_CRIT 0x10
46#define OS_STAT_DELAY 0x20
47#define OS_STAT_JOIN 0x40
48#define OS_STAT_RES4 0x40
49#define OS_STAT_RES5 0x80
60#define OS_MBOX_FULL 20
63#define OS_PRIO_EXIST 40
64#define OS_PRIO_INVALID 41
68#define OS_NO_MORE_TCB 70
78#define OS_TFLAG_IN_USE 0x80
83typedef volatile uint32_t tick_t;
88extern volatile tick_t TimeTick;
91inline bool IsTickLater(uint32_t test_time)
93 return ((
int)(TimeTick - test_time) < 0);
97inline bool IsTickNowOrEarlier(uint32_t test_time)
99 return ((
int)(TimeTick - test_time) >= 0);
103inline bool Is2ndTickEarlier(uint32_t t1, uint32_t t2)
105 return (((
int)(t1 - t2)) > 0);
109inline bool Is2ndTickNowOrEarlier(uint32_t t1, uint32_t t2)
111 return (((
int)(t1 - t2)) >= 0);
115struct RawTickTimeout_t
117 tick_t expiration = 0;
119 inline bool expired()
const {
return expiration ? (((int)(expiration - TimeTick)) <= 0) : false; }
120 inline bool expired()
volatile {
return expiration ? (((int)(expiration - TimeTick)) <= 0) : false; }
121 inline operator bool()
const {
return !expired(); }
122 const RawTickTimeout_t &operator=(
const TickTimeout &rhs);
123 volatile RawTickTimeout_t &operator=(
const TickTimeout &rhs)
volatile;
125 inline bool operator<(
const RawTickTimeout_t &later)
129 if (!later.expiration)
131 return (((
int)(expiration - later.expiration)) <= 0);
134 inline bool operator<(tick_t later)
138 return (((
int)(expiration - later)) <= 0);
141 inline tick_t operator-(
const tick_t &tick) {
return expiration - tick; }
142 inline tick_t operator-(
const tick_t &tick)
const {
return expiration - tick; }
143 inline tick_t operator-(
const tick_t &tick)
volatile {
return expiration - tick; }
146inline bool operator==(
const RawTickTimeout_t &lhs,
const int &rhs)
148 return lhs.expiration == (tick_t)rhs;
151inline bool operator==(
const volatile RawTickTimeout_t &lhs,
const int &rhs)
153 return lhs.expiration == (tick_t)rhs;
163 RawTickTimeout_t raw;
165 void set(uint32_t timeout)
167 if (!timeout) { raw.expiration = 0; }
170 raw.expiration = TimeTick + (timeout & 0x7FFFFFFF);
174 if (timeout && !raw.expiration) { raw.expiration = 1; }
179 class uint32_nonboolean_t
184 uint32_nonboolean_t(uint32_t
val) : value(
val) {}
185 inline explicit operator bool() {
return (
bool)value; }
186 inline operator uint32_t() {
return value; }
206 inline uint32_t
val()
const
208 if (!raw.expiration) {
return raw.expiration; }
209 int ret = raw.expiration - TimeTick;
211 return (ret > 0) ? ret : 1;
220 inline bool expired()
const {
return raw.expired(); }
233 inline operator bool()
const {
return !
expired(); }
235 inline operator uint32_t()
const {
return val(); }
237 inline operator uint16_t()
const
239 uint32_t ret =
val();
240 return ret > 0xFFFF ? 0xFFFE : ret;
245 raw.expiration = rhs.raw.expiration;
255 return raw < later.raw;
257 inline bool operator<(tick_t later)
265 raw.expiration += (
val & 0x7FFFFFFF);
269 if (
val && !raw.expiration) { raw.expiration = 1; }
279 inline void SetUntil(uint32_t when) {raw.expiration = when; }
283 friend class RawTickTimeout_t;
286inline const RawTickTimeout_t &RawTickTimeout_t::operator=(
const TickTimeout &rhs)
288 expiration = rhs.raw.expiration;
292inline volatile RawTickTimeout_t &RawTickTimeout_t::operator=(
const TickTimeout &rhs)
volatile
294 expiration = rhs.raw.expiration;
303 volatile uint32_t OSTbl[TASK_TABLE_SIZE];
306 void Init()
volatile;
307 void Copy(
volatile task_bit_list &rhs)
309 for (
int i = 0; i < TASK_TABLE_SIZE; i++)
311 OSTbl[i] = rhs.OSTbl[i];
316 void set(
int set_num)
volatile;
317 void clr(
int clr_num)
volatile;
320 uint32_t gethigh()
volatile;
321 uint32_t get_high_and_clear()
volatile;
323 inline bool isSet(
int num)
volatile const {
return (OSTbl[num / 32] & (0x80000000 >> (num % 32))); }
331 task_bit_list tasks_waiting;
338 bool Wait_when(uint8_t StatReason,
TickTimeout &timeout);
340 inline bool Wait(uint8_t StatReason, uint32_t to_count)
343 return Wait_when(StatReason, to_when);
347 void MakeHighTaskWaitingReady(uint8_t StatReason);
348 void MakeTaskWaitingReady(uint8_t taskPrio, uint8_t StatReason);
349 void MakeAllWaitingReady(uint8_t StatReason);
353} __attribute__((packed));
357class OS_TCB :
public cpu_tcb
365 RawTickTimeout_t OSTCBDly_when;
367 const char *pOSTCBName;
371#ifdef NBRTOS_PRIO_PROMOTION
374 volatile OS_TCB *pPromotedTo;
375 volatile OS_TCB *pDisplacedBy;
376 OS_TASK_DLY_OBJ *pWaiting;
377 uint32_t displacedByOrigPrio;
379 void PromoteToCurPrio()
volatile;
380 void Demote()
volatile;
383 static volatile OS_TCB *GetCur();
386 unsigned long switchTimeTick;
387 unsigned long switchTimeFraction;
388 unsigned long runningTime;
389 unsigned long runningTimeFraction;
395 bool Init(uint8_t prio,
void *pActualTop,
void *pstk,
long *pbot,
const char *name);
408 volatile uint32_t OSSemCnt;
409 volatile uint32_t OSSemUsed;
422 inline OS_SEM(int32_t cnt = 0) : OS_TASK_DLY_OBJ() {
Init(cnt); }
499 inline uint32_t
Avail() { uint32_t v; USER_ENTER_CRITICAL(); v=OSSemCnt-OSSemUsed; USER_EXIT_CRITICAL();
return v;};
501} __attribute__((packed));
520 bool OSMboxDataAvail;
522 bool Claim(
void *&Result);
550 uint8_t
Init(
void *msg = NULL);
576 inline void *
Pend(uint32_t timeoutTicks, uint8_t &result){
TickTimeout tt(timeoutTicks);
return Pend(tt,result);};
605 return Pend(timeoutTicks, unused);
658 TEMPL_MBOX(
const T *msg) : m_mbox((void *)msg) {}
659 inline uint8_t Init(
const T *msg) {
return m_mbox.
Init((
void *)msg); }
660 inline uint8_t Post(
const T *msg) {
return m_mbox.
Post((
void *)msg); }
662 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) {
return static_cast<T *
>(m_mbox.
Pend(timeoutTicks, result)); };
664 inline T *PendNoWait(uint8_t &result) {
return static_cast<T *
>(m_mbox.
PendNoWait(result)); };
666 inline T *Pend(uint32_t timeoutTicks =
WAIT_FOREVER) {
return static_cast<T *
>(m_mbox.
Pend(timeoutTicks)); };
668 inline T *PendNoWait() {
return static_cast<T *
>(m_mbox.
PendNoWait()); };
692struct OS_Q :
public OS_TASK_DLY_OBJ
701 bool Claim(
void *&Result);
719 inline OS_Q(
void **pQueueStorage, uint8_t size) : OS_TASK_DLY_OBJ() {
Init(pQueueStorage, size); }
729 uint8_t
Init(
void **pQueueStorage, uint8_t size);
795 inline void *
Pend(uint32_t timeoutTicks, uint8_t &result){
TickTimeout tt(timeoutTicks);
return Pend(tt,result);};
824 return Pend(timeoutTicks, unused);
881 TEMPL_Q(T **pQueueStorage, uint8_t size)
882 : m_q((
void**)pQueueStorage,size) { }
883 uint8_t Init(T **pQueueStorage, uint8_t size) {
return m_q.
Init((
void **)pQueueStorage, size); }
884 uint8_t Post(T *item) {
return m_q.
Post((
void *)item); }
885 uint8_t PostFirst(T *item) {
return m_q.
PostFirst((
void *)item); };
886 uint8_t PostUnique(T *item) {
return m_q.
PostUnique((
void *)item); };
887 uint8_t PostUniqueFirst(T *item) {
return m_q.
PostUniqueFirst((
void *)item); };
889 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) {
return static_cast<T *
>(m_q.
Pend(timeoutTicks, result)); };
891 inline T *Pend(uint32_t timeoutTicks =
WAIT_FOREVER) {
return static_cast<T *
>(m_q.
Pend(timeoutTicks)); };
893 inline T *PendNoWait() {
return static_cast<T *
>(m_q.
PendNoWait()); };
895 inline T *PendNoWait(uint8_t &result) {
return static_cast<T *
>(m_q.
PendNoWait(result)); };
1018 return Pend(timeoutTicks, unused);
1073 TEMPL_FIFO() { m_fifo.
Init(); }
1074 uint8_t Init() {
return m_fifo.
Init(); }
1075 uint8_t Post(T *item) {
return m_fifo.
Post((
OS_FIFO_EL *)item); }
1078 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) {
return static_cast<T *
>(m_fifo.
Pend(timeoutTicks, result)); };
1080 inline T *Pend(uint32_t timeoutTicks =
WAIT_FOREVER) {
return static_cast<T *
>(m_fifo.
Pend(timeoutTicks)); };
1082 inline T *PendNoWait() {
return static_cast<T *
>(m_fifo.
PendNoWait()); };
1084 inline T *PendNoWait(uint8_t &result) {
return static_cast<T *
>(m_fifo.
PendNoWait(result)); };
1086 inline OS_FIFO *GetRawFIFO() {
return &m_fifo; }
1096class BufferCriticalLock;
1107 OS_TCB *OSCritOwnerTCB;
1108 uint32_t OSCritDepthCount;
1111 OS_TCB *GetOwner() {
return (OS_TCB*)(((uint32_t)OSCritOwnerTCB)&~0x1ul); }
1112 void SetOwner(OS_TCB *newOwner)
1115 (OS_TCB*) (((uint32_t)newOwner) | (((uint32_t)OSCritOwnerTCB)&0x1));
1222 friend class BufferCriticalLock;
1224 friend class OS_RRCB;
1244 OSCritOwnerTCB = (OS_TCB*)(((uint32_t)OSCritOwnerTCB)|0x1ul);
1248 OSCritOwnerTCB = (OS_TCB*)(((uint32_t)OSCritOwnerTCB)&~0x1ul);
1268} __attribute__((packed));
1272struct OS_FLAGS_WAIT;
1287 vuint32_t m_current_flags;
1288 void *m_pWaitinglist;
1290 void AddOFW(OS_FLAGS_WAIT *ofw);
1291 void RemoveOFW(OS_FLAGS_WAIT *ofw);
1315 void Set(uint32_t bits_to_set);
1465[[deprecated]]
inline void OSFlagCreate(
OS_FLAGS *pf)
1482 flags->
Set(bits_to_set);
1497 flags->
Clear(bits_to_clr);
1516 return flags->
PendAny(bit_mask, timeout);
1553 return flags->
PendAll(bit_mask, timeout);
1587 return flags->
State();
1599extern volatile task_bit_list OSTaskReadyList;
1600#ifdef NBRTOS_PRIO_PROMOTION
1601extern volatile task_bit_list OSInUsePrioList FAST_SYS_VAR;
1602extern volatile task_bit_list OSActivePrioList FAST_SYS_VAR;
1607extern OS_TCB *pOSActiveTCBList;
1610extern volatile uint32_t nPrioOfCurTask;
1611extern volatile uint32_t nPrioOfHighReady;
1612extern volatile OS_TCB *OSTCBCur;
1613extern volatile OS_TCB *OSTCBHighRdy;
1615extern OS_TCB *pOSTCBFreeList;
1617extern volatile uint32_t OSIntNesting;
1618extern volatile uint32_t OSLockNesting;
1619extern volatile uint32_t OSISRLevel32;
1621extern volatile bool OSRunning;
1624extern unsigned long OSTcbStructSize;
1626#ifdef NBRTOS_TASK_LOG
1627extern void (*pTaskLogger)(uint8_t nextPrio);
1639void OSInit(uint8_t maxtasks);
1641void OSCreateIdleTask();
1721 OS_TCB **pRetHandle = NULL
1763#define OSSimpleTaskCreatewName(x, p, n) \
1765 static uint32_t func_##x##_Stk[USER_TASK_STK_SIZE] __attribute__((aligned(4))); \
1766 return OSTaskCreatewName(x, NULL, (void *)&func_##x##_Stk[USER_TASK_STK_SIZE], (void *)func_##x##_Stk, p, n); \
1785#define OSSimpleTaskCreatewNameSRAM(x, p, n) \
1787 static uint32_t func_##x##_Stk[USER_TASK_STK_SIZE] __attribute__((aligned(4))) FAST_USER_STK; \
1788 return OSTaskCreatewName(x, NULL, (void *)&func_##x##_Stk[USER_TASK_STK_SIZE], (void *)func_##x##_Stk, p, n); \
1793#define LambdaTask2(p,n,f,vn) static uint32_t func_##vn_Stk[USER_TASK_STK_SIZE] __attribute__((aligned(4)));OSTaskCreatewName(f, NULL, (void *)&func_##vn_Stk[USER_TASK_STK_SIZE], (void *)func_##vn_Stk, p, n)
1810#define OSSimpleTaskCreateLambda(p,n,f) LambdaTask2(p,n,[]( void * pv)f,__COUNTER__)
1848 uint32_t to_when = to_count + TimeTick;
1849 if (!to_when) to_when++;
1857 void OSIntExit(
void);
1859 void OSTickISR(
void);
1860 void OSStartHighRdy(
void);
1861 void OSSetupVBR(
void);
1863 void OSTimeTick(
void);
1878OS_TCB *OSTCBGetFree(
void);
1966 return psem->
Post();
1985 return psem->
Pend(timeout);
2038 return pmbox->
Post(msg);
2054 return pmbox->
Pend(timeout, *err);
2086[[deprecated]]
inline uint8_t
OSQInit(
OS_Q *pq,
void **start, uint8_t size)
2106 return pq->
Post(msg);
2178[[deprecated]]
inline void *
OSQPend(
OS_Q *pq, uint16_t timeout, uint8_t *err)
2180 return pq->
Pend(timeout, *err);
2229 return pFifo->
Post(pToPost);
2260 return pFifo->
Pend(timeout);
2291 return pCrit->
Init();
2293[[deprecated]]
inline uint8_t OSCritLockAndEnter(
OS_CRIT *pCrit, uint16_t timeout)
2313 return pCrit->
Enter(timeout);
2347 return pCrit->
Leave();
2349[[deprecated]]
inline uint8_t OSCritLeaveAndUnlock(
OS_CRIT *pCrit)
2388void OSChangeTaskWhen(uint16_t task_prio, uint32_t to_when);
2402 uint32_t to_when = to_count + TimeTick;
2403 if (!to_when) to_when++;
2404 OSChangeTaskWhen(task_prio, to_when);
2435#if (defined NBRTOS_STACKOVERFLOW) || (defined NBRTOS_STACKUNDERFLOW)
2436void EnableOSStackProtector();
2437extern "C" void OSStackProtectCtxSw();
2438extern "C" void OSStackProtectIntCtxSw();
2439extern "C" void OSStackProtector();
2442#ifdef NBRTOS_STACKCHECK
2474#ifdef NBRTOS_TASKLIST
2484uint32_t GetCurrentTaskTime(uint32_t *
const TotalTicks);
2485void ShowTaskTimes(
void);
2486void ClearTaskTimes(
void);
2512} __attribute__((packed));
2554 ocrit.
Enter(timeout);
2562} __attribute__((packed));
2649 return OSCritOwnerTCB == OSTCBCur;
2666 static bool bAlreadInited;
2670 inline bool WasInitDone() {
return bAlreadInited; }
2679 static void InitWholeSet();
A simple class to derive from if you are creating tasks that are constructed at global scope and need...
Definition nbrtos.h:2664
virtual void Notify()=0
This will be called when the RTOS has been setup in initalization.
A simple wrapper class that helps utilize OS_CRIT objects more effectively.
Definition nbrtos.h:2524
OSCriticalSectionObj(OS_CRIT &ocrit, bool NoWait, TickTimeout &timeout)
Initialize the OSCriticalSectionObj object, and then call Enter() on the OS_CRIT object that is passe...
Definition nbrtos.h:2548
OSCriticalSectionObj(OS_CRIT &ocrit)
Initialize the OSCriticalSectionObj object, and then call Enter() on the OS_CRIT object that is passe...
Definition nbrtos.h:2534
~OSCriticalSectionObj()
Destructs the OSCriticalSectionObj object, and call Leave() on the OS_CRIT object that was passed int...
Definition nbrtos.h:2561
A simple wrapper class that helps utilize OS_CRIT objects to lock tasks and enter critical sections m...
Definition nbrtos.h:2575
~OSLockAndCritObj()
Call LeaveAndUnlock() on the OSCriticalSectionObj object, then destruct.
Definition nbrtos.h:2591
OSLockAndCritObj(OS_CRIT &ocrit)
Initialize the OSCriticalSectionObj object, and then call LockAndEnter() on the OS_CRIT object that i...
Definition nbrtos.h:2585
A simple wrapper class that helps use OS locks effectively.
Definition nbrtos.h:2501
OSLockObj()
Initialize the OSLockObj and calls OSLock().
Definition nbrtos.h:2506
~OSLockObj()
Destructs the OSLockObj and calls OSUnlock().
Definition nbrtos.h:2511
A simple wrapper class that uses an OS_CRIT object to try and claim a critical section,...
Definition nbrtos.h:2606
~OSSpinCrit()
Call Leave() on the OS_CRIT object, and then destruct/.
Definition nbrtos.h:2625
OSSpinCrit(OS_CRIT &ocrit)
Initialize the OSSpinCrit object, and then call EnterNoWait() repeatedly on the OS_CRIT object that i...
Definition nbrtos.h:2616
TickTimeout objects are used to facilitate sequential function calls with timeout parameters that nee...
Definition nbrtos.h:162
bool expired() const
Determine whether the timeout duration has elapsed.
Definition nbrtos.h:220
TickTimeout(uint32_t timeout)
Create and initialize the Timeout.
Definition nbrtos.h:196
void SetUntil(uint32_t when)
Set the TimeTick value to expire.
Definition nbrtos.h:279
friend void OSTimeWaitUntil(uint32_t systemTickValue)
Delay the task until the specified value of the system timer tick. The number of system ticks per sec...
uint32_t val() const
Get the timeout duration to be passed to a function utilizing timeout ticks.
Definition nbrtos.h:206
User critial section object class.
Definition nbrtos.h:2633
FIFO buffer storage using linked pool buffers.
Definition buffers.h:443
#define OS_MAX_TASKS
Max number of system tasks.
Definition constants.h:97
#define OS_MAX_PRIOS
Maximum number of system priorities (NBRTOS limit: 256)
Definition constants.h:101
void OSUnlock(void)
This function unlocks the OS.
void OSChangeTaskDly(uint16_t task_prio, uint32_t to_count)
This function allows the User to modify the timeout delay for a task that is waiting.
Definition nbrtos.h:2400
uint8_t OSCritInit(OS_CRIT *pCrit)
This function initializes the critical section.
Definition nbrtos.h:2289
struct os_fifo_el OS_FIFO_EL
OS_FIFO element definition.
uint8_t OSChangePrio(uint32_t newp)
Set the priority of the calling task.
uint8_t OSQPostFirst(OS_Q *pq, void *msg)
This function posts a message like OSQPost, but posts the message at the head of the queue.
Definition nbrtos.h:2122
void OSSetName(const char *cp)
Set the name of the calling task.
void OSDumpTasks(void)
Dump the state and call stack for every task to stdout. This function is useful for debugging.
uint8_t OSSemInit(OS_SEM *psem, long value)
Initializes a semaphore.
Definition nbrtos.h:1946
int OSGetNextPrio(OSNextPrio where=OSNextPrio::Below, int startingPrio=-1)
Get the next available task priority suitable to create a new task with.
uint8_t OSFlagPendAll(OS_FLAGS *flags, uint32_t bit_mask, uint16_t timeout)
This function waits a number of time ticks specified by timeout until all the flags indicated by bit_...
Definition nbrtos.h:1551
OSNextPrio
What to consider as the 'next' priority when looking for an available priority for task creation.
Definition nbrtos.h:2365
uint8_t OSMboxPost(OS_MBOX *pmbox, void *msg)
This function posts a message to a Mail box.
Definition nbrtos.h:2036
void * OSMboxPend(OS_MBOX *pmbox, uint16_t timeout, uint8_t *err)
Wait timeout ticks for some other task to post to the Mailbox.
Definition nbrtos.h:2052
uint8_t OSQPostUnique(OS_Q *pq, void *msg)
This function posts a message like OSQPost, but only if the message isn't already in the queue The fu...
Definition nbrtos.h:2142
void OSStartTaskDumper(uint8_t prio, uint32_t reportInterval)
This function creates a task that calls OSDumpTasks() at the specified system time tick interval....
uint8_t OSCritEnter(OS_CRIT *pCrit, uint16_t timeout)
This function tries to enter or claim the critical section.
Definition nbrtos.h:2311
uint8_t OSFlagPendAny(OS_FLAGS *flags, uint32_t bit_mask, uint16_t timeout)
This function waits a number of time ticks specified by timeout until any of the flags indicated by b...
Definition nbrtos.h:1514
void OSTaskDelete(void)
This function deletes the current calling task, but we do not recommend the use of this function beca...
uint8_t OSTaskCreatewName(void(*task)(void *dptr), void *data, void *pstktop, void *pstkbot, uint8_t prio, const char *name, OS_TCB **pRetHandle=NULL)
Create a new task.
uint8_t OSCritEnterNoWait(OS_CRIT *pCrit)
This function tries to enter or claim the critical section.
Definition nbrtos.h:2328
uint8_t OSCritLeave(OS_CRIT *pCrit)
This function releases the critical section.
Definition nbrtos.h:2345
uint8_t OSQPostUniqueFirst(OS_Q *pq, void *msg)
This function posts a message like OSQPostFirst, but only if the message isn't already in the queue T...
Definition nbrtos.h:2162
uint8_t OSFifoPostFirst(OS_FIFO *pFifo, OS_FIFO_EL *pToPost)
This function is identical to OSFifoPost(), but the element posted is put at the beginning of the FIF...
Definition nbrtos.h:2243
void ShowTaskList(void)
This functions dumps the current RTOS task states to stdio.
uint8_t OSFifoPost(OS_FIFO *pFifo, OS_FIFO_EL *pToPost)
This function posts to a FIFO.
Definition nbrtos.h:2227
void OSFlagSet(OS_FLAGS *flags, uint32_t bits_to_set)
This function sets the corresponding bits asserted in bits_to_set of an OS_FLAGS object pointed to by...
Definition nbrtos.h:1480
uint8_t OSTaskID(void)
Returns the current task's priority.
OS_FIFO_EL * OSFifoPend(OS_FIFO *pFifo, uint16_t timeout)
This function pends on a FIFO.
Definition nbrtos.h:2258
uint8_t OSFlagPendAnyNoWait(OS_FLAGS *flags, uint32_t bit_mask)
This function immediately checks to see if any of the flag bits indicated by bit_mask are set; it doe...
Definition nbrtos.h:1532
uint8_t OSQPost(OS_Q *pq, void *msg)
This function posts a message to a Queue.
Definition nbrtos.h:2104
uint8_t OSSemPendNoWait(OS_SEM *psem)
OSSemPendNoWait() is identical to OSSemPend(), but it does not wait.
Definition nbrtos.h:2000
uint8_t OSFifoInit(OS_FIFO *pFifo)
Initialize a FIFO, which is used to pass structures from one task to another.
Definition nbrtos.h:2210
void OSTimeWaitUntil(uint32_t systemTickValue)
Delay the task until the specified value of the system timer tick. The number of system ticks per sec...
void OSDumpTCBStacks(void)
This function dumps information about the UCOS stacks and tasks to stdout. This function is useful fo...
void OSLock(void)
Calling the OSLock function will prevent the OS from changing tasks.
const char * OSTaskName()
Returns the current task's name.
uint32_t OSFlagState(OS_FLAGS *flags)
This function returns the current values of the flags stored in the OS_FLAGS object structure.
Definition nbrtos.h:1585
#define WAIT_FOREVER
Parameter macro used for timeout parameters that have a 0 value and wait forever.
Definition nbrtos.h:81
uint8_t OSSemPend(OS_SEM *psem, uint16_t timeout)
Wait timeout ticks for the value of the semaphore to be non zero. Note: A timeout value of 0 (zero) w...
Definition nbrtos.h:1983
void OSFlagClear(OS_FLAGS *flags, uint32_t bits_to_clr)
This function clears the bits asserted in bits_to_clr of an OS_FLAGS object pointed to by *flags....
Definition nbrtos.h:1495
uint8_t OSQInit(OS_Q *pq, void **start, uint8_t size)
A queue functions as a fixed size FIFO for communication between tasks. This function initializes an ...
Definition nbrtos.h:2086
void * OSMboxPendNoWait(OS_MBOX *pmbox, uint8_t *err)
OSMboxPendNoWait() is identical to OSMboxPend(), but it does not wait.
Definition nbrtos.h:2067
uint8_t OSFlagPendAllNoWait(OS_FLAGS *flags, uint32_t bit_mask)
This function immediately checks to see if all the flag bits indicated by bit_mask are set; it does n...
Definition nbrtos.h:1569
uint8_t OSTaskJoin(OS_TCB *pTask, uint32_t timeoutDly=0)
Wait for a task to finish.
bool OwnedByCurTask()
Check if critical section owned by the current task.
Definition nbrtos.h:2647
OS_TCB * OSGetTaskBlock(uint16_t task_prio)
Get a pointer to the task control block structure for a given registered task priority.
void * OSQPendNoWait(OS_Q *pq, uint8_t *err)
OSQPendNoWait() is identical to the OSQPend() function but it does not wait.
Definition nbrtos.h:2193
void OSTimeDly(uint32_t to_count)
Delay the task until the specified value of the system timer ticks. The number of system ticks per se...
Definition nbrtos.h:1846
OS_FIFO_EL * OSFifoPendNoWait(OS_FIFO *pFifo)
This function is identical to the OSFifoPen() function, but it does not wait.
Definition nbrtos.h:2272
void * OSQPend(OS_Q *pq, uint16_t timeout, uint8_t *err)
Wait timeout ticks for another task to post to the queue.
Definition nbrtos.h:2178
uint8_t OSSemPost(OS_SEM *psem)
Increases the value of the semaphore by one. Note: If any higher priority tasks were waiting on the s...
Definition nbrtos.h:1964
void OSDumpStack(void)
Dump the task stack to the stdout.
uint8_t OSMboxInit(OS_MBOX *pmbox, void *msg)
This function is used to initialize an OS_MBOX structure.
Definition nbrtos.h:2018
@ Next
Highest priority that is lower than the current task, OSTaskID()->OS_LO_PRIO.
@ Above
Lowest priority that is higher than the current task, OSTaskID()->0.
@ Maximum
Highest priority currently unused, 0->OS_LO_PRIO.
@ Minimum
Lowest priority currently unused, OS_LO_PRIO->0.
@ Below
Highest priority that is lower than the current task, OSTaskID()->OS_LO_PRIO.
#define OS_TIMEOUT
Timeout.
Definition nbrtos.h:59
#define OS_CRIT_ERR
Critical section error.
Definition nbrtos.h:67
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition nbrtos.h:1106
uint8_t LockAndEnter(uint32_t timeoutTicks=WAIT_FOREVER)
Locks the current task to prevent task switching and claims the critical section.
uint8_t LeaveAndUnlock()
Leave/release the critical section and unlock the task.
uint8_t Init()
Initialize an OS_CRIT object to its default state.
uint8_t Enter(TickTimeout &t)
Request to Enter/Claim the critical section.
bool UsedFromISR()
Check if critical section UsedFromISR flag is set.
Definition nbrtos.h:1231
friend void ForceReboot(bool fromIRQ)
Forces the system hardware to perform a soft reset.
void SetUseFromISR(bool enableFromISR)
Set critical section UsedFromISR flag.
Definition nbrtos.h:1240
OS_CRIT()
Create and initialize an OS_CRIT object.
Definition nbrtos.h:1124
uint8_t Enter(uint32_t timeoutTicks=WAIT_FOREVER)
Request to Enter/Claim the critical section, with a time out parameter.
Definition nbrtos.h:1182
uint32_t CurDepth()
Returns the critical section depth count.
Definition nbrtos.h:1262
uint8_t EnterNoWait()
Request to Enter/Claim the critical section. Does not wait if a critical section is not available.
uint8_t Leave()
Release the critical section.
OS_FIFO()
Create and initialize a FIFO object.
Definition nbrtos.h:940
uint8_t Init()
Sets the FIFO object to its initial state.
OS_FIFO_EL * PendNoWait(uint8_t &result)
Attempts to pend a structure to the FIFO, but does not wait.
uint8_t PostFirst(OS_FIFO_EL *pToPost)
Post a message to the head of the FIFO.
OS_FIFO_EL * Pend(uint32_t timeoutTicks=WAIT_FOREVER)
Pend on a FIFO for the specified number of system TimeTicks.
Definition nbrtos.h:1015
OS_FIFO_EL * Pend(TickTimeout &t, uint8_t &result)
Wait the specified number of TickTimeout ticks for some other task to post to the FIFO.
OS_FIFO_EL * PendUntil(uint32_t timeoutTime, uint8_t &result)
Wait the specified TimeTicks value for some other task to post to the FIFO.
Definition nbrtos.h:1033
OS_FIFO_EL * PendNoWait()
Attempts to pend a structure to the FIFO, but does not wait.
Definition nbrtos.h:1057
OS_FIFO_EL * Pend(uint32_t timeoutTicks, uint8_t &result)
Wait the specified number of time ticks for some other task to post to the FIFO.
Definition nbrtos.h:989
uint8_t Post(OS_FIFO_EL *pToPost)
Post a message to the next available location in the FIFO.
OSFlags enables a function or task to pend on multiple flags or events.
Definition nbrtos.h:1285
uint8_t PendAll(uint32_t bit_mask, TickTimeout &timeout)
Wait the specified number of TickTimeout time ticks until all the specified flags are set.
uint8_t PendAnyNoWait(uint32_t bit_mask)
Check for the specified flags and return immediately.
void Write(uint32_t bits_to_force)
Set the flag bits to match the specified value.
void Init()
Initialize an OS_FLAG object to its default value.
OS_FLAGS()
Create and initialize an OS_FLAG object.
uint8_t PendAllUntil(uint32_t bit_mask, uint32_t end_time)
Wait until the specified system TimeTicks value for all of the flags in the bit mask to be set.
Definition nbrtos.h:1444
uint8_t PendAny(uint32_t bit_mask, uint16_t timeout=WAIT_FOREVER)
Wait the specified number of system TimeTicks for any of the flags in the bit mask to be set.
Definition nbrtos.h:1359
uint32_t State()
Returns the current values of the flags stored in the OS_FLAGS object.
void Set(uint32_t bits_to_set)
Sets the specified flag bits.
uint8_t PendAll(uint32_t bit_mask, uint16_t timeout=WAIT_FOREVER)
Wait the specified number of system time ticks until all the specified flags are set.
Definition nbrtos.h:1416
uint8_t PendAllNoWait(uint32_t bit_mask)
Wait the specified number of system time ticks until all the specified flags are set.
void Clear(uint32_t bits_to_clr)
Clear the specified flag bits.
uint8_t PendAny(uint32_t bit_mask, TickTimeout &timeout)
Wait the specified number of TickTimeout time ticks for any of the flags in the bit mask to be set.
uint8_t PendAnyUntil(uint32_t bit_mask, uint32_t end_time)
Wait until the specified system TimeTicks value for any of the flags in the bit mask to be set.
Definition nbrtos.h:1389
Mailboxes single value storage locations used to communicate between tasks.
Definition nbrtos.h:518
void * PendUntil(uint32_t timeoutTime, uint8_t &result)
Wait the specified number of TimeTicks for some other task to post to the mailbox.
Definition nbrtos.h:620
void * PendNoWait()
Checks if a message is available in the mailbox and returns immediately.
Definition nbrtos.h:643
OS_MBOX()
Create and initialize a mailbox object with no defalut message.
Definition nbrtos.h:530
uint8_t Init(void *msg=NULL)
Sets the mailbox object to its initial state.
uint8_t Post(void *msg)
Post a message to the mailbox.
OS_MBOX(void *msg)
Create and initialize a mailbox object with the specified message.
Definition nbrtos.h:539
void * Pend(uint32_t timeoutTicks=WAIT_FOREVER)
Wait the specified number of time ticks for some other task to post to the mailbox.
Definition nbrtos.h:602
void * Pend(uint32_t timeoutTicks, uint8_t &result)
Wait the specified number of time ticks for some other task to post to the mailbox.
Definition nbrtos.h:576
void * PendNoWait(uint8_t &result)
Checks if a message is available in the mailbox and returns immediately.
void * Pend(TickTimeout &t, uint8_t &result)
Wait the specified number of TickTimeout ticks for some other task to post to the mailbox.
A message queue is an object that enables tasks and interrupt service routines to pend and post point...
Definition nbrtos.h:693
uint8_t PostFirst(void *pItem)
Post a message to the head of the queue.
void * PendNoWait()
Checks if a message is available in the queue and returns immediately.
Definition nbrtos.h:862
void * PendUntil(uint32_t timeoutTime, uint8_t &result)
Wait the specified TimeTicks value for some other task to post to the queue.
Definition nbrtos.h:839
uint8_t PostUnique(void *pItem)
Post the specified message to the next available location in the queue, but only if the message is un...
uint8_t Post(void *pItem)
Post a message to the next available location in the queue.
void * Pend(uint32_t timeoutTicks, uint8_t &result)
Wait the specified number of time ticks for some other task to post to the queue.
Definition nbrtos.h:795
void * Pend(TickTimeout &t, uint8_t &result)
Wait the specified number of TickTimeout ticks for some other task to post to the queue.
void * PendNoWait(uint8_t &result)
Checks if a message is available in the queue and returns immediately.
OS_Q(void **pQueueStorage, uint8_t size)
Create and initialize a queue object.
Definition nbrtos.h:719
uint8_t PostUniqueFirst(void *msg)
Post the specified message to the first location in the queue, but only if the message is unique and ...
uint8_t Init(void **pQueueStorage, uint8_t size)
Set the queue object to its initial state.
void * Pend(uint32_t timeoutTicks=WAIT_FOREVER)
Wait the specified number of time ticks for some other task to post to the queue.
Definition nbrtos.h:821
Semaphores are used to control access to shared resources or or to communicate between tasks in a mul...
Definition nbrtos.h:407
uint8_t Pend(uint32_t timeoutTicks=WAIT_FOREVER)
Wait timeout ticks for the value of the semaphore to be non zero.
Definition nbrtos.h:455
uint8_t Init(int32_t cnt=0)
Initialize the semaphore object count value.
OS_SEM(int32_t cnt=0)
Create and initialize a semaphore.
Definition nbrtos.h:422
uint8_t Pend(TickTimeout &t)
Wait for the specified number of system time ticks for a task to post to the semaphore.
uint8_t PendNoWait()
Pend on a semaphore with no waiting period.
uint32_t Avail()
Returns the number of semaphore counts availble.
Definition nbrtos.h:499
uint8_t Post()
Posts to the semaphore, increasing it's value by 1.
uint8_t PendUntil(uint32_t timeout_time)
Wait until the specified timeout time for a task to post to the semaphore.
Definition nbrtos.h:466
A convenience wrapper around OS_Q.
Definition nbrtos.h:875
OS_FIFO element definition.
Definition nbrtos.h:905
puint8_t pAsBytePtr
Next OS_FIFO element data byte pointer.
Definition nbrtos.h:914
struct os_fifo_el * pNextFifo_El
Pointer to next OS_FIFO element.
Definition nbrtos.h:913