NetBurner 3.5.0
PDF Version
 
nbrtos.h
Go to the documentation of this file.
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
17#ifndef _NBRTOS_H
18#define _NBRTOS_H
19
20// NB Definitions
21#include <predef.h>
22
23// NB Constants
24#include <constants.h>
25
26// NB Libs
27#include <basictypes.h>
28#include <nbrtoscpu.h>
29#include <predef.h>
30
31/***********************************************************
32 * NBRTOS.H
33 * SYSTEM DECLARATIONS
34 ***********************************************************
35 */
36#define OS_LO_PRIO 63 /*IDLE task priority */
37
45#define OS_STAT_RDY 0x00
46#define OS_STAT_MBOX 0x01
47#define OS_STAT_SEM 0x02
48#define OS_STAT_Q 0x04
49#define OS_STAT_FIFO 0x08
50#define OS_STAT_CRIT 0x10
51#define OS_STAT_DELAY 0x20
52#define OS_STAT_RES4 0x40
53#define OS_STAT_RES5 0x80
62#define OS_NO_ERR 0
63#define OS_TIMEOUT 10
64#define OS_MBOX_FULL 20
65#define OS_Q_FULL 30
66#define OS_Q_EXISTS 31
67#define OS_PRIO_EXIST 40
68#define OS_PRIO_INVALID 41
69#define OS_SEM_ERR 50
70#define OS_SEM_OVF 51
71#define OS_CRIT_ERR 60
72#define OS_NO_MORE_TCB 70
75#define WAIT_FOREVER 0
76
77typedef volatile uint32_t tick_t;
78
80// GLOBAL VARIABLES
81//
82extern vuint32_t Secs; // Number of seconds since system start
83extern volatile tick_t TimeTick; // Number of time ticks since system start
84
85// Is test_time later than now (TimeTick)
86inline bool IsTickLater(uint32_t test_time)
87{
88 return ((int)(TimeTick - test_time) < 0);
89}
90
91// Is test_time NoworEarlier than TimeTick
92inline bool IsTickNowOrEarlier(uint32_t test_time)
93{
94 return ((int)(TimeTick - test_time) >= 0);
95}
96
97// Compare two timetick values
98inline bool Is2ndTickEarlier(uint32_t t1, uint32_t t2)
99{
100 return (((int)(t1 - t2)) > 0);
101}
102
103// Compare two timetick values
104inline bool Is2ndTickNowOrEarlier(uint32_t t1, uint32_t t2)
105{
106 return (((int)(t1 - t2)) >= 0);
107}
108
109class TickTimeout;
110struct RawTickTimeout_t
111{
112 tick_t expiration;
113
114 inline bool expired() const { return expiration ? (((int)(expiration - TimeTick)) <= 0) : false; }
115 inline bool expired() volatile { return expiration ? (((int)(expiration - TimeTick)) <= 0) : false; }
116 inline operator bool() const { return !expired(); }
117 const RawTickTimeout_t &operator=(const TickTimeout &rhs);
118 volatile RawTickTimeout_t &operator=(const TickTimeout &rhs) volatile;
119
120 inline bool operator<(const RawTickTimeout_t &later)
121 {
122 if (!expiration)
123 return false;
124 if (!later.expiration)
125 return true;
126 return (((int)(expiration - later.expiration)) <= 0);
127 }
128
129 inline bool operator<(tick_t later)
130 {
131 if (!expiration)
132 return false;
133 return (((int)(expiration - later)) <= 0);
134 }
135
136 inline tick_t operator-(const tick_t &tick) { return expiration - tick; }
137 inline tick_t operator-(const tick_t &tick) const { return expiration - tick; }
138 inline tick_t operator-(const tick_t &tick) volatile { return expiration - tick; }
139};
140
141inline bool operator==(const RawTickTimeout_t &lhs, const int &rhs)
142{
143 return lhs.expiration == (tick_t)rhs;
144}
145
146inline bool operator==(const volatile RawTickTimeout_t &lhs, const int &rhs)
147{
148 return lhs.expiration == (tick_t)rhs;
149}
150
157{
158 RawTickTimeout_t raw;
159
160 void set(uint32_t timeout)
161 {
162 if (!timeout) { raw.expiration = 0; }
163 else
164 {
165 raw.expiration = TimeTick + (timeout & 0x7FFFFFFF);
166 // A 1 tick delay extension is introduced on TimeTick overflow
167 // in order to allow for infinite delays to be indicated with an
168 // expiration of zero
169 if (timeout && !raw.expiration) { raw.expiration = 1; }
170 }
171 }
172
173 public:
174 class uint32_nonboolean_t
175 {
176 uint32_t value;
177
178 public:
179 uint32_nonboolean_t(uint32_t val) : value(val) {}
180 inline explicit operator bool() { return (bool)value; }
181 inline operator uint32_t() { return value; }
182 };
183
184 explicit TickTimeout() { set(0); }
185
191 TickTimeout(uint32_t timeout) { set(timeout); }
192 TickTimeout(uint16_t timeout) { set(timeout); }
193 TickTimeout(int timeout) { set(timeout); }
194
195
201 inline uint32_t val() const
202 {
203 if (!raw.expiration) { return raw.expiration; }
204 int ret = raw.expiration - TimeTick;
205 // Prevent passing an infinite or otherwise bogus timeout in a tick race
206 return (ret > 0) ? ret : 1;
207 }
208
215 inline bool expired() const { return raw.expired(); }
216
228 inline operator bool() const { return !expired(); }
229
230 inline operator uint32_t() const { return val(); }
231
232 inline operator uint16_t() const
233 {
234 uint32_t ret = val();
235 return ret > 0xFFFF ? 0xFFFE : ret;
236 }
237
238 inline TickTimeout &operator=(const TickTimeout &rhs)
239 {
240 raw.expiration = rhs.raw.expiration;
241 return *this;
242 }
243 inline TickTimeout &operator=(uint32_t val)
244 {
245 set(val);
246 return *this;
247 }
248 inline bool operator<(TickTimeout later)
249 {
250 return raw < later.raw;
251 }
252 inline bool operator<(tick_t later)
253 {
254 return raw < later;
255 }
256
262 inline void SetUntil(uint32_t when) {raw.expiration = when; }
263
264 friend void OSTimeWaitUntil(uint32_t systemTickValue);
265
266 friend class RawTickTimeout_t;
267};
268
269inline const RawTickTimeout_t &RawTickTimeout_t::operator=(const TickTimeout &rhs)
270{
271 expiration = rhs.raw.expiration;
272 return *this;
273}
274
275inline volatile RawTickTimeout_t &RawTickTimeout_t::operator=(const TickTimeout &rhs) volatile
276{
277 expiration = rhs.raw.expiration;
278 return *this;
279}
280
281// The following class holds a list of tasks
282
283class task_bit_list
284{
285 public:
286 volatile uint32_t OSTbl[TASK_TABLE_SIZE];
287
288 // task_bit_list();
289 void Init() volatile;
290 void Copy(volatile task_bit_list &rhs)
291 {
292 for (int i = 0; i < TASK_TABLE_SIZE; i++)
293 {
294 OSTbl[i] = rhs.OSTbl[i];
295 }
296 }
297
298 // The following functions are all guaranteed to be atomic
299 void set(int set_num) volatile;
300 void clr(int clr_num) volatile;
301
302 // The following functions return 0 if no bits are set.
303 uint32_t gethigh() volatile;
304 uint32_t get_high_and_clear() volatile;
305
306 inline bool isSet(int num) volatile const { return (OSTbl[num / 32] & (0x80000000 >> (num % 32))); }
307};
308
309class OS_TCB;
310
311// The common element of all the task objects
312class OS_TASK_DLY_OBJ
313{
314 task_bit_list tasks_waiting;
315
316 public:
317 OS_TASK_DLY_OBJ();
318 void Init();
319
320 // Returns true if woken up, returns false if timed out
321 bool Wait_when(uint8_t StatReason, TickTimeout &timeout);
322
323 inline bool Wait(uint8_t StatReason, uint32_t to_count)
324 {
325 TickTimeout to_when(to_count);
326 return Wait_when(StatReason, to_when);
327 }
328
329 // This releases the highest priority task waiting on this object.
330 void MakeHighTaskWaitingReady(uint8_t StatReason);
331 friend class OS_TCB;
332} __attribute__((packed));
333
334// class OS_TCB;//forward
335
336class OS_TCB : public cpu_tcb
337{
338 public:
339 uint8_t OSTCBStat; // Holds the current status of the TCB
340 uint8_t OSTCBResult; // Basically holds the timeout or not flag when woken.
341 uint8_t OSTCBPrio; // Index to prio table.... not sure if we need to keep this.
342 uint8_t pad; // Make 32 bit aligned.
343
344 RawTickTimeout_t OSTCBDly_when; // When to release timeout the task, 0= never.
345
346 const char *pOSTCBName;
347 OS_TCB *OSTCBNext;
348 OS_TCB *OSTCBPrev;
349
350#ifdef NBRTOS_PRIO_PROMOTION
351 // These pointers are for handling Priority Promotion when OS_CRITs create
352 // an inversion situation
353 volatile OS_TCB *pPromotedTo;
354 volatile OS_TCB *pDisplacedBy;
355 OS_TASK_DLY_OBJ *pWaiting;
356 uint32_t displacedByOrigPrio;
357
358 void PromoteToCurPrio() volatile;
359 void Demote() volatile;
360#endif
361
362 static volatile OS_TCB *GetCur();
363
364#ifdef NBRTOS_TIME
365 unsigned long switchTimeTick;
366 unsigned long switchTimeFraction;
367 unsigned long runningTime;
368 unsigned long runningTimeFraction;
369#endif
370 // OS_TCB(); //Zero everything
371 void Init();
372
373 // Set up TCB assuming that the STACK has already been setup and properly initalized.
374 bool Init(uint8_t prio, void *pActualTop, void *pstk, long *pbot, const char *name);
375};
376
377/* Forward Declaration */
378struct OS_CRIT;
379
385struct OS_SEM : public OS_TASK_DLY_OBJ
386{
387 volatile uint32_t OSSemCnt;
388 volatile uint32_t OSSemUsed;
389
390 private:
391 bool Claim();
392
393 public:
401 inline OS_SEM(int32_t cnt = 0) : OS_TASK_DLY_OBJ() { Init(cnt); }
402
412 uint8_t Init(int32_t cnt = 0);
413
423 uint8_t Post();
424
434 inline uint8_t Pend(uint32_t timeoutTicks = WAIT_FOREVER){TickTimeout tt(timeoutTicks); return Pend(tt);};
435
445 inline uint8_t PendUntil(uint32_t timeout_time){TickTimeout tt(0); tt.SetUntil(timeout_time); return Pend(tt);};
446
456 uint8_t Pend(TickTimeout &t);
457
467 uint8_t PendNoWait();
468
478 inline uint32_t Avail() { uint32_t v; USER_ENTER_CRITICAL(); v=OSSemCnt-OSSemUsed; USER_EXIT_CRITICAL(); return v;};
479
480} __attribute__((packed));
481
496struct OS_MBOX : public OS_TASK_DLY_OBJ
497{
498 void *OSMboxMsg;
499 bool OSMboxDataAvail;
500
501 bool Claim(void *&Result);
502
503 public:
509 inline OS_MBOX() : OS_TASK_DLY_OBJ() { Init(); }
510
518 inline OS_MBOX(void *msg) : OS_TASK_DLY_OBJ() { Init(msg); }
519
529 uint8_t Init(void *msg = NULL);
530
541 uint8_t Post(void *msg);
542
555 inline void *Pend(uint32_t timeoutTicks, uint8_t &result){TickTimeout tt(timeoutTicks); return Pend(tt,result);};
556
569 void *Pend(TickTimeout &t, uint8_t &result);
570
581 inline void *Pend(uint32_t timeoutTicks = WAIT_FOREVER)
582 {
583 uint8_t unused;
584 return Pend(timeoutTicks, unused);
585 };
586
599 inline void *PendUntil(uint32_t timeoutTime, uint8_t &result){TickTimeout tt(0); tt.SetUntil(timeoutTime); return Pend(tt,result);};
600
612 void *PendNoWait(uint8_t &result);
613
622 inline void *PendNoWait()
623 {
624 uint8_t unused;
625 return PendNoWait(unused);
626 };
627};
628
629
630template<typename T>
631class TEMPL_MBOX
632{
633 protected:
634 OS_MBOX m_mbox;
635
636 public:
637 TEMPL_MBOX(const T *msg) : m_mbox((void *)msg) {}
638 inline uint8_t Init(const T *msg) { return m_mbox.Init((void *)msg); }
639 inline uint8_t Post(const T *msg) { return m_mbox.Post((void *)msg); }
640
641 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) { return static_cast<T *>(m_mbox.Pend(timeoutTicks, result)); };
642
643 inline T *PendNoWait(uint8_t &result) { return static_cast<T *>(m_mbox.PendNoWait(result)); };
644
645 inline T *Pend(uint32_t timeoutTicks = WAIT_FOREVER) { return static_cast<T *>(m_mbox.Pend(timeoutTicks)); };
646
647 inline T *PendNoWait() { return static_cast<T *>(m_mbox.PendNoWait()); };
648};
649
650
671struct OS_Q : public OS_TASK_DLY_OBJ
672{
673 void **OSQStart;
674 void **OSQEnd;
675 void **OSQIn;
676 void **OSQOut;
677 uint8_t OSQSize;
678 uint8_t OSQEntries;
679
680 bool Claim(void *&Result);
681
682 public:
698 inline OS_Q(void **pQueueStorage, uint8_t size) : OS_TASK_DLY_OBJ() { Init(pQueueStorage, size); }
699
708 uint8_t Init(void **pQueueStorage, uint8_t size);
709
720 uint8_t Post(void *pItem);
721
732 uint8_t PostFirst(void *pItem);
733
746 uint8_t PostUnique(void *pItem);
747
760 uint8_t PostUniqueFirst(void *msg);
761
774 inline void *Pend(uint32_t timeoutTicks, uint8_t &result){TickTimeout tt(timeoutTicks); return Pend(tt,result);};
775
788 void *Pend(TickTimeout &t, uint8_t &result);
789
800 inline void *Pend(uint32_t timeoutTicks = WAIT_FOREVER)
801 {
802 uint8_t unused;
803 return Pend(timeoutTicks, unused);
804 };
805
818 inline void *PendUntil(uint32_t timeoutTime, uint8_t &result){TickTimeout tt(0); tt.SetUntil(timeoutTime); return Pend(tt,result);};
819
831 void *PendNoWait(uint8_t &result);
832
841 inline void *PendNoWait()
842 {
843 uint8_t unused;
844 return PendNoWait(unused);
845 };
846};
847
852template<typename T>
854{
855 protected:
856 OS_Q m_q;
857
858 public:
859 TEMPL_Q() {}
860 TEMPL_Q(T **pQueueStorage, uint8_t size)
861 : m_q((void**)pQueueStorage,size) { }
862 uint8_t Init(T **pQueueStorage, uint8_t size) { return m_q.Init((void **)pQueueStorage, size); }
863 uint8_t Post(T *item) { return m_q.Post((void *)item); }
864 uint8_t PostFirst(T *item) { return m_q.PostFirst((void *)item); };
865 uint8_t PostUnique(T *item) { return m_q.PostUnique((void *)item); };
866 uint8_t PostUniqueFirst(T *item) { return m_q.PostUniqueFirst((void *)item); };
867
868 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) { return static_cast<T *>(m_q.Pend(timeoutTicks, result)); };
869
870 inline T *Pend(uint32_t timeoutTicks = WAIT_FOREVER) { return static_cast<T *>(m_q.Pend(timeoutTicks)); };
871
872 inline T *PendNoWait() { return static_cast<T *>(m_q.PendNoWait()); };
873
874 inline T *PendNoWait(uint8_t &result) { return static_cast<T *>(m_q.PendNoWait(result)); };
875};
876
883typedef struct os_fifo_el
884{
890 union
891 {
893 puint8_t pAsBytePtr;
894 };
896
906struct OS_FIFO : public OS_TASK_DLY_OBJ
907{
908 OS_FIFO_EL *pHead;
909 OS_FIFO_EL *pTail;
910
911 bool Claim(volatile OS_FIFO_EL *&pToRet);
912
913 public:
919 inline OS_FIFO() : OS_TASK_DLY_OBJ() { Init(); }
920
928 uint8_t Init();
929
941 uint8_t Post(OS_FIFO_EL *pToPost);
942
954 uint8_t PostFirst(OS_FIFO_EL *pToPost);
955
968 inline OS_FIFO_EL *Pend(uint32_t timeoutTicks, uint8_t &result){TickTimeout tt(timeoutTicks); return Pend(tt,result);};
969
982 OS_FIFO_EL *Pend(TickTimeout &t, uint8_t &result);
983
994 inline OS_FIFO_EL *Pend(uint32_t timeoutTicks = WAIT_FOREVER)
995 {
996 uint8_t unused;
997 return Pend(timeoutTicks, unused);
998 };
999
1012 inline OS_FIFO_EL *PendUntil(uint32_t timeoutTime, uint8_t &result){TickTimeout tt(0); tt.SetUntil(timeoutTime); return Pend(tt,result);};
1013
1025 OS_FIFO_EL *PendNoWait(uint8_t &result);
1026
1027
1037 {
1038 uint8_t unused;
1039 return PendNoWait(unused);
1040 };
1041};
1042
1043
1044
1045template<typename T>
1046struct TEMPL_FIFO
1047{
1048 protected:
1049 OS_FIFO m_fifo;
1050
1051 public:
1052 TEMPL_FIFO() { m_fifo.Init(); }
1053 uint8_t Init() { return m_fifo.Init(); }
1054 uint8_t Post(T *item) { return m_fifo.Post((OS_FIFO_EL *)item); }
1055 uint8_t PostFirst(T *item) { return m_fifo.PostFirst((OS_FIFO_EL *)item); };
1056
1057 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) { return static_cast<T *>(m_fifo.Pend(timeoutTicks, result)); };
1058
1059 inline T *Pend(uint32_t timeoutTicks = WAIT_FOREVER) { return static_cast<T *>(m_fifo.Pend(timeoutTicks)); };
1060
1061 inline T *PendNoWait() { return static_cast<T *>(m_fifo.PendNoWait()); };
1062
1063 inline T *PendNoWait(uint8_t &result) { return static_cast<T *>(m_fifo.PendNoWait(result)); };
1064
1065 inline OS_FIFO *GetRawFIFO() { return &m_fifo; }
1066};
1067
1068/*
1069 * Critical Section DATA STRUCTURES
1070 *
1071 * Added by PTB 5/09/99
1072 * Modified by DEC 3/21/16
1073 */
1074
1075class BufferCriticalLock;
1076class fifo_buffer_storage;
1077
1083struct OS_CRIT : public OS_TASK_DLY_OBJ
1084{
1085 OS_TCB *OSCritOwnerTCB;
1086 uint32_t OSCritDepthCount;
1087
1088 bool Claim();
1089 OS_TCB *GetOwner() { return (OS_TCB*)(((uint32_t)OSCritOwnerTCB)&~0x1ul); }
1090 void SetOwner(OS_TCB *newOwner)
1091 {
1092 OSCritOwnerTCB =
1093 (OS_TCB*) (((uint32_t)newOwner) | (((uint32_t)OSCritOwnerTCB)&0x1));
1094 }
1095
1096 public:
1102 OS_CRIT() { Init(); }
1103
1111 uint8_t Init();
1112
1128 uint8_t LockAndEnter(uint32_t timeoutTicks = WAIT_FOREVER);
1129
1144 uint8_t Enter(TickTimeout &t);
1145
1160 inline uint8_t Enter(uint32_t timeoutTicks = WAIT_FOREVER) {TickTimeout tt(timeoutTicks); return Enter(tt);};
1161
1173 uint8_t EnterNoWait();
1174
1186 uint8_t Leave();
1187
1199
1200 friend class BufferCriticalLock;
1201 friend class fifo_buffer_storage;
1202
1208 bool UsedFromISR() { return (((uint32_t)OSCritOwnerTCB)&0x1ul); }
1209
1217 void SetUseFromISR(bool enableFromISR)
1218 {
1219 if (enableFromISR)
1220 {
1221 OSCritOwnerTCB = (OS_TCB*)(((uint32_t)OSCritOwnerTCB)|0x1ul);
1222 }
1223 else
1224 {
1225 OSCritOwnerTCB = (OS_TCB*)(((uint32_t)OSCritOwnerTCB)&~0x1ul);
1226 }
1227 }
1228
1232 bool OwnedByCurTask();
1233
1239 uint32_t CurDepth() { return OSCritDepthCount; }
1240
1244 friend void ForceReboot(bool fromIRQ);
1245} __attribute__((packed));
1246
1247
1248
1249struct OS_FLAGS_WAIT;
1250
1262{
1263 protected:
1264 vuint32_t m_current_flags;
1265 void *m_pWaitinglist;
1266 void TestFlags();
1267 void AddOFW(OS_FLAGS_WAIT *ofw);
1268 void RemoveOFW(OS_FLAGS_WAIT *ofw);
1269
1270 public:
1277
1283 void Init();
1284
1292 void Set(uint32_t bits_to_set);
1293
1301 void Clear(uint32_t bits_to_clr);
1302
1303
1311 void Write(uint32_t bits_to_force);
1312
1320 uint32_t State();
1321
1336 uint8_t PendAny(uint32_t bit_mask, uint16_t timeout = WAIT_FOREVER){TickTimeout tt(timeout); return PendAny(bit_mask,tt);}
1337
1352 uint8_t PendAny(uint32_t bit_mask, TickTimeout & timeout);
1353
1354
1366 uint8_t PendAnyUntil(uint32_t bit_mask, uint32_t end_time){TickTimeout tt(0); tt.SetUntil(end_time); return PendAny(bit_mask,tt);}
1367
1368
1378 uint8_t PendAnyNoWait(uint32_t bit_mask);
1379
1393 uint8_t PendAll(uint32_t bit_mask, uint16_t timeout = WAIT_FOREVER){TickTimeout tt(timeout); return PendAll(bit_mask,tt);}
1394
1408 uint8_t PendAll(uint32_t bit_mask,TickTimeout & timeout);
1409
1421 uint8_t PendAllUntil(uint32_t bit_mask, uint32_t end_time){TickTimeout tt(0); tt.SetUntil(end_time); return PendAll(bit_mask,tt);}
1422
1423
1434 uint8_t PendAllNoWait(uint32_t bit_mask);
1435
1436};
1437
1438
1439/* Create and initialize an OS flags object
1440This function must be called before you use an OS_FLAGS object.
1441*/
1442[[deprecated]] inline void OSFlagCreate(OS_FLAGS *pf)
1443{
1444 pf->Init();
1445};
1446
1457[[deprecated]] inline void OSFlagSet(OS_FLAGS *flags, uint32_t bits_to_set)
1458{
1459 flags->Set(bits_to_set);
1460};
1461
1472[[deprecated]] inline void OSFlagClear(OS_FLAGS *flags, uint32_t bits_to_clr)
1473{
1474 flags->Clear(bits_to_clr);
1475};
1476
1491[[deprecated]] inline uint8_t OSFlagPendAny(OS_FLAGS *flags, uint32_t bit_mask, uint16_t timeout)
1492{
1493 return flags->PendAny(bit_mask, timeout);
1494};
1495
1509[[deprecated]] inline uint8_t OSFlagPendAnyNoWait(OS_FLAGS *flags, uint32_t bit_mask)
1510{
1511 return flags->PendAnyNoWait(bit_mask);
1512};
1513
1528[[deprecated]] inline uint8_t OSFlagPendAll(OS_FLAGS *flags, uint32_t bit_mask, uint16_t timeout)
1529{
1530 return flags->PendAll(bit_mask, timeout);
1531};
1532
1546[[deprecated]] inline uint8_t OSFlagPendAllNoWait(OS_FLAGS *flags, uint32_t bit_mask)
1547{
1548 return flags->PendAllNoWait(bit_mask);
1549};
1550
1562[[deprecated]] inline uint32_t OSFlagState(OS_FLAGS *flags)
1563{
1564 return flags->State();
1565};
1566
1567/*
1568 ***********************************************************
1569 * NBRTOS GLOBAL VARIABLES
1570 ***********************************************************
1571 */
1572// Pointers to each of the OS_TCB structure sorted by priority
1573extern volatile OS_TCB *OSTCBPrioTbl[OS_MAX_PRIOS];
1574
1575// taks bits for what tasks are ready to run
1576extern volatile task_bit_list OSTaskReadyList;
1577#ifdef NBRTOS_PRIO_PROMOTION
1578extern volatile task_bit_list OSInUsePrioList FAST_SYS_VAR;
1579extern volatile task_bit_list OSActivePrioList FAST_SYS_VAR;
1580#endif
1581
1582extern OS_TCB OSTCBTbl[OS_MAX_TASKS]; // All the possible TCB's
1583
1584extern OS_TCB *pOSActiveTCBList; // Linked list of activ TCB's
1585
1586// One of the following two variables wsill go away....
1587extern volatile uint32_t nPrioOfCurTask; // Current task priority number
1588extern volatile uint32_t nPrioOfHighReady; // highest task ready to run
1589extern volatile OS_TCB *OSTCBCur;
1590extern volatile OS_TCB *OSTCBHighRdy;
1591
1592extern OS_TCB *pOSTCBFreeList; // List of unused TCB's
1593
1594extern volatile uint32_t OSIntNesting;
1595extern volatile uint32_t OSLockNesting;
1596extern volatile uint32_t OSISRLevel32;
1597
1598extern volatile bool OSRunning;
1599
1600// So non-recompilable files can reference the right struct size
1601extern unsigned long OSTcbStructSize;
1602
1603#ifdef NBRTOS_TASK_LOG
1604extern void (*pTaskLogger)(uint8_t nextPrio);
1605#endif
1606/*
1607Removed
1608 extern volatile BOOLEAN OSShowTasksOnLeds;
1609*/
1610
1611/*
1612***********************************************************
1613* NBRTOS FUNCTION PROTOTYPES
1614***********************************************************
1615*/
1616void OSInit(uint8_t maxtasks);
1617void OSStart(void);
1618void OSCreateIdleTask();
1619
1648uint8_t OSTaskCreatewName(void (*task)(void *dptr), // Function to call
1649 void *data, // Data to pass as a parameter
1650 void *pstktop, // Stack top
1651 void *pstkbot, // Stack bottom
1652 uint8_t prio, // current priority
1653 const char *name // task name
1654);
1655
1666#define OSSimpleTaskCreatewName(x, p, n) \
1667 { \
1668 static uint32_t func_##x_Stk[USER_TASK_STK_SIZE] __attribute__((aligned(4))); \
1669 OSTaskCreatewName(x, NULL, (void *)&func_##x_Stk[USER_TASK_STK_SIZE], (void *)func_##x_Stk, p, n); \
1670 }
1672#define OSSimpleTaskCreatewNameSRAM(x, p, n) \
1673 { \
1674 static uint32_t func_##x_Stk[USER_TASK_STK_SIZE] __attribute__((aligned(4))) FAST_USER_STK; \
1675 OSTaskCreatewName(x, NULL, (void *)&func_##x_Stk[USER_TASK_STK_SIZE], (void *)func_##x_Stk, p, n); \
1676 }
1677
1678/* Helper macro*/
1679#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)
1680
1696#define OSSimpleTaskCreateLambda(p,n,f) LambdaTask2(p,n,[]( void * pv)f,__COUNTER__)
1697
1698
1718void OSTimeWaitUntil(uint32_t systemTickValue);
1719
1732inline void OSTimeDly(uint32_t to_count)
1733{
1734 uint32_t to_when = to_count + TimeTick;
1735 if (!to_when) to_when++;
1736 OSTimeWaitUntil(to_when);
1737};
1738
1739// void OSIntEnter( void );
1740
1741extern "C"
1742{
1743 void OSIntExit(void);
1744 void OSCtxSw(void);
1745 void OSTickISR(void);
1746 void OSStartHighRdy(void);
1747 void OSSetupVBR(void);
1748 void OSSched(void);
1749 void OSTimeTick(void);
1750
1761 void OSTaskDelete(void);
1762}
1763
1764OS_TCB *OSTCBGetFree(void);
1765
1784uint8_t OSChangePrio(uint32_t newp);
1785
1792void OSSetName(const char *cp);
1793
1807void OSLock(void);
1808
1816void OSUnlock(void);
1817
1832[[deprecated]] inline uint8_t OSSemInit(OS_SEM *psem, long value)
1833{
1834 return (psem != nullptr) ? psem->Init(value) : OS_CRIT_ERR;
1835}
1836
1850[[deprecated]] inline uint8_t OSSemPost(OS_SEM *psem)
1851{
1852 return psem->Post();
1853}
1854
1869[[deprecated]] inline uint8_t OSSemPend(OS_SEM *psem, uint16_t timeout)
1870{
1871 return psem->Pend(timeout);
1872}
1873
1886[[deprecated]] inline uint8_t OSSemPendNoWait(OS_SEM *psem)
1887{
1888 return psem->PendNoWait();
1889}
1890
1904[[deprecated]] inline uint8_t OSMboxInit(OS_MBOX *pmbox, void *msg)
1905{
1906 return (pmbox != nullptr) ? pmbox->Init(msg) : OS_CRIT_ERR;
1907}
1908
1922[[deprecated]] inline uint8_t OSMboxPost(OS_MBOX *pmbox, void *msg)
1923{
1924 return pmbox->Post(msg);
1925}
1926
1938[[deprecated]] inline void *OSMboxPend(OS_MBOX *pmbox, uint16_t timeout, uint8_t *err)
1939{
1940 return pmbox->Pend(timeout, *err);
1941}
1942
1953[[deprecated]] inline void *OSMboxPendNoWait(OS_MBOX *pmbox, uint8_t *err)
1954{
1955 return pmbox->PendNoWait(*err);
1956}
1957
1972[[deprecated]] inline uint8_t OSQInit(OS_Q *pq, void **start, uint8_t size)
1973{
1974 return (pq != nullptr) ? pq->Init(start, size) : OS_CRIT_ERR;
1975}
1976
1990[[deprecated]] inline uint8_t OSQPost(OS_Q *pq, void *msg)
1991{
1992 return pq->Post(msg);
1993}
1994
2008[[deprecated]] inline uint8_t OSQPostFirst(OS_Q *pq, void *msg)
2009{
2010 return pq->PostFirst(msg);
2011}
2012
2028[[deprecated]] inline uint8_t OSQPostUnique(OS_Q *pq, void *msg)
2029{
2030 return pq->PostUnique(msg);
2031}
2032
2048[[deprecated]] inline uint8_t OSQPostUniqueFirst(OS_Q *pq, void *msg)
2049{
2050 return pq->PostUniqueFirst(msg);
2051}
2052
2064[[deprecated]] inline void *OSQPend(OS_Q *pq, uint16_t timeout, uint8_t *err)
2065{
2066 return pq->Pend(timeout, *err);
2067}
2068
2079[[deprecated]] inline void *OSQPendNoWait(OS_Q *pq, uint8_t *err)
2080{
2081 return pq->PendNoWait(*err);
2082}
2083
2096[[deprecated]] inline uint8_t OSFifoInit(OS_FIFO *pFifo)
2097{
2098 return (pFifo != nullptr) ? pFifo->Init() : OS_CRIT_ERR;
2099}
2100
2113[[deprecated]] inline uint8_t OSFifoPost(OS_FIFO *pFifo, OS_FIFO_EL *pToPost)
2114{
2115 return pFifo->Post(pToPost);
2116}
2129[[deprecated]] inline uint8_t OSFifoPostFirst(OS_FIFO *pFifo, OS_FIFO_EL *pToPost)
2130{
2131 return pFifo->PostFirst(pToPost);
2132};
2133
2144[[deprecated]] inline OS_FIFO_EL *OSFifoPend(OS_FIFO *pFifo, uint16_t timeout)
2145{
2146 return pFifo->Pend(timeout);
2147};
2148
2158[[deprecated]] inline OS_FIFO_EL *OSFifoPendNoWait(OS_FIFO *pFifo)
2159{
2160 return pFifo->PendNoWait();
2161 ;
2162}
2163
2175[[deprecated]] inline uint8_t OSCritInit(OS_CRIT *pCrit)
2176{
2177 return pCrit->Init();
2178}
2179[[deprecated]] inline uint8_t OSCritLockAndEnter(OS_CRIT *pCrit, uint16_t timeout)
2180{
2181 return pCrit->LockAndEnter(timeout);
2182}
2183
2197[[deprecated]] inline uint8_t OSCritEnter(OS_CRIT *pCrit, uint16_t timeout)
2198{
2199 return pCrit->Enter(timeout);
2200}
2201
2214[[deprecated]] inline uint8_t OSCritEnterNoWait(OS_CRIT *pCrit)
2215{
2216 return pCrit->EnterNoWait();
2217}
2218
2231[[deprecated]] inline uint8_t OSCritLeave(OS_CRIT *pCrit)
2232{
2233 return pCrit->Leave();
2234}
2235[[deprecated]] inline uint8_t OSCritLeaveAndUnlock(OS_CRIT *pCrit)
2236{
2237 return pCrit->LeaveAndUnlock();
2238}
2239
2243uint8_t OSTaskID(void);
2244
2248const char *OSTaskName();
2249
2250void OSChangeTaskWhen(uint16_t task_prio, uint32_t to_when);
2251
2262inline void OSChangeTaskDly(uint16_t task_prio, uint32_t to_count)
2263{
2264 uint32_t to_when = to_count + TimeTick;
2265 if (!to_when) to_when++;
2266 OSChangeTaskWhen(task_prio, to_when);
2267}
2268
2272void OSDumpStack(void);
2273
2274#if (defined NBRTOS_STACKOVERFLOW) || (defined NBRTOS_STACKUNDERFLOW)
2275void EnableOSStackProtector();
2276extern "C" void OSStackProtectCtxSw(); // ASM task switcher
2277extern "C" void OSStackProtectIntCtxSw(); // ASM task switcher
2278extern "C" void OSStackProtector(); // extern because must be called from ASM
2279#endif
2280
2281#ifdef NBRTOS_STACKCHECK
2291
2300void OSDumpTasks(void);
2301
2310void OSStartTaskDumper(uint8_t prio, uint32_t reportInterval);
2311#endif
2312
2313#ifdef NBRTOS_TASKLIST
2319void ShowTaskList(void);
2320#endif
2321
2322#ifdef NBRTOS_TIME
2323uint32_t GetCurrentTaskTime(uint32_t *const TotalTicks);
2324void ShowTaskTimes(void);
2325void ClearTaskTimes(void);
2326#endif
2327
2340{
2341 public:
2346
2351} __attribute__((packed));
2352
2363{
2364 OS_CRIT *pcrit;
2365
2366 public:
2374 {
2375 pcrit = &ocrit;
2376 ocrit.Enter(0);
2377 };
2378
2387 OSCriticalSectionObj(OS_CRIT &ocrit, bool NoWait, TickTimeout &timeout)
2388 {
2389 pcrit = &ocrit;
2390 if (NoWait)
2391 ocrit.EnterNoWait();
2392 else
2393 ocrit.Enter(timeout);
2394 };
2395
2401} __attribute__((packed));
2402
2414{
2415 OS_CRIT *pcrit;
2416
2417 public:
2424 OSLockAndCritObj(OS_CRIT &ocrit) : pcrit(&ocrit) { pcrit->LockAndEnter(0); }
2425
2431};
2432
2445{
2446 OS_CRIT *pcrit;
2447
2448 public:
2455 OSSpinCrit(OS_CRIT &ocrit) : pcrit(&ocrit)
2456 {
2457 while (pcrit->EnterNoWait() == OS_TIMEOUT) {}
2458 }
2459
2464 ~OSSpinCrit() { pcrit->Leave(); }
2465};
2466
2467
2472{
2473 public:
2474 USERCritObj() { USER_ENTER_CRITICAL(); }
2475 ~USERCritObj() { USER_EXIT_CRITICAL(); }
2476};
2477
2478
2479
2487{
2488 return OSCritOwnerTCB == OSTCBCur;
2489}
2490
2503{
2504 static NBRtosInitObj * pHead;
2505 static bool bAlreadInited;
2506 NBRtosInitObj *pNext;
2507
2508 protected:
2509 inline bool WasInitDone() {return bAlreadInited; }
2510 NBRtosInitObj();
2512
2513 public:
2517 virtual void Notify()=0;
2518 static void InitWholeSet(); //Used internally
2519};
2520
2521
2522#endif
2523
2524
2525
2526
A simple class to derive from if you are creating tasks that are constructed at global scope and need...
Definition nbrtos.h:2503
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:2363
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:2387
OSCriticalSectionObj(OS_CRIT &ocrit)
Initialize the OSCriticalSectionObj object, and then call Enter() on the OS_CRIT object that is passe...
Definition nbrtos.h:2373
~OSCriticalSectionObj()
Destructs the OSCriticalSectionObj object, and call Leave() on the OS_CRIT object that was passed int...
Definition nbrtos.h:2400
A simple wrapper class that helps utilize OS_CRIT objects to lock tasks and enter critical sections m...
Definition nbrtos.h:2414
~OSLockAndCritObj()
Call LeaveAndUnlock() on the OSCriticalSectionObj object, then destruct.
Definition nbrtos.h:2430
OSLockAndCritObj(OS_CRIT &ocrit)
Initialize the OSCriticalSectionObj object, and then call LockAndEnter() on the OS_CRIT object that i...
Definition nbrtos.h:2424
A simple wrapper class that helps use OS locks effectively.
Definition nbrtos.h:2340
OSLockObj()
Initialize the OSLockObj and calls OSLock().
Definition nbrtos.h:2345
~OSLockObj()
Destructs the OSLockObj and calls OSUnlock().
Definition nbrtos.h:2350
A simple wrapper class that uses an OS_CRIT object to try and claim a critical section,...
Definition nbrtos.h:2445
~OSSpinCrit()
Call Leave() on the OS_CRIT object, and then destruct/.
Definition nbrtos.h:2464
OSSpinCrit(OS_CRIT &ocrit)
Initialize the OSSpinCrit object, and then call EnterNoWait() repeatedly on the OS_CRIT object that i...
Definition nbrtos.h:2455
TickTimeout objects are used to facilitate sequential function calls with timeout parameters that nee...
Definition nbrtos.h:157
bool expired() const
Determine whether the timeout duration has elapsed.
Definition nbrtos.h:215
TickTimeout(uint32_t timeout)
Create and initialize the Timeout.
Definition nbrtos.h:191
void SetUntil(uint32_t when)
Set the TimeTick value to expire.
Definition nbrtos.h:262
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:201
User critial section object class.
Definition nbrtos.h:2472
#define OS_MAX_TASKS
Max number of system tasks.
Definition nbrtos/include/constants.h:67
#define OS_MAX_PRIOS
Maximum number of system priorities.
Definition nbrtos/include/constants.h:69
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:2262
uint8_t OSCritInit(OS_CRIT *pCrit)
This function initializes the critical section.
Definition nbrtos.h:2175
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:2008
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:1832
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:1528
uint8_t OSMboxPost(OS_MBOX *pmbox, void *msg)
This function posts a message to a Mail box.
Definition nbrtos.h:1922
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:1938
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:2028
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:2197
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:1491
void OSTaskDelete(void)
This function deletes the current calling task, but we do not recommend the use of this function beca...
uint8_t OSCritEnterNoWait(OS_CRIT *pCrit)
This function tries to enter or claim the critical section.
Definition nbrtos.h:2214
uint8_t OSCritLeave(OS_CRIT *pCrit)
This function releases the critical section.
Definition nbrtos.h:2231
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:2048
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:2129
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:2113
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:1457
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:2144
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:1509
uint8_t OSTaskCreatewName(void(*task)(void *dptr), void *data, void *pstktop, void *pstkbot, uint8_t prio, const char *name)
Create a new task.
uint8_t OSQPost(OS_Q *pq, void *msg)
This function posts a message to a Queue.
Definition nbrtos.h:1990
uint8_t OSSemPendNoWait(OS_SEM *psem)
OSSemPendNoWait() is identical to OSSemPend(), but it does not wait.
Definition nbrtos.h:1886
uint8_t OSFifoInit(OS_FIFO *pFifo)
Initialize a FIFO, which is used to pass structures from one task to another.
Definition nbrtos.h:2096
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:1562
#define WAIT_FOREVER
Parameter macro used for timeout parameters that have a 0 value and wait forever.
Definition nbrtos.h:75
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:1869
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:1472
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:1972
void * OSMboxPendNoWait(OS_MBOX *pmbox, uint8_t *err)
OSMboxPendNoWait() is identical to OSMboxPend(), but it does not wait.
Definition nbrtos.h:1953
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:1546
bool OwnedByCurTask()
Check if critical section owned by the current task.
Definition nbrtos.h:2486
void * OSQPendNoWait(OS_Q *pq, uint8_t *err)
OSQPendNoWait() is identical to the OSQPend() function but it does not wait.
Definition nbrtos.h:2079
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:1732
OS_FIFO_EL * OSFifoPendNoWait(OS_FIFO *pFifo)
This function is identical to the OSFifoPen() function, but it does not wait.
Definition nbrtos.h:2158
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:2064
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:1850
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:1904
#define OS_TIMEOUT
Timeout.
Definition nbrtos.h:63
#define OS_CRIT_ERR
Critical section error.
Definition nbrtos.h:71
NetBurner System Constants.
#define FAST_SYS_VAR
Definition nbrtos/include/constants.h:278
#define TASK_TABLE_SIZE
Definition nbrtos/include/constants.h:205
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition nbrtos.h:1084
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:1208
void SetUseFromISR(bool enableFromISR)
Set critical section UsedFromISR flag.
Definition nbrtos.h:1217
friend void ForceReboot(bool fromIRQ)
Forces the system hardware to perform a soft reset.
OS_CRIT()
Create and initialize an OS_CRIT object.
Definition nbrtos.h:1102
uint8_t Enter(uint32_t timeoutTicks=WAIT_FOREVER)
Request to Enter/Claim the critical section, with a time out parameter.
Definition nbrtos.h:1160
uint32_t CurDepth()
Returns the critical section depth count.
Definition nbrtos.h:1239
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.
Definition nbrtos.h:907
OS_FIFO()
Create and initialize a FIFO object.
Definition nbrtos.h:919
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:994
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:1012
OS_FIFO_EL * PendNoWait()
Attempts to pend a structure to the FIFO, but does not wait.
Definition nbrtos.h:1036
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:968
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:1262
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:1421
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:1336
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:1393
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:1366
Mailboxes single value storage locations used to communicate between tasks.
Definition nbrtos.h:497
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:599
void * PendNoWait()
Checks if a message is available in the mailbox and returns immediately.
Definition nbrtos.h:622
OS_MBOX()
Create and initialize a mailbox object with no defalut message.
Definition nbrtos.h:509
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:518
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:581
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:555
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:672
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:841
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:818
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:774
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:698
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:800
Semaphores are used to control access to shared resources or or to communicate between tasks in a mul...
Definition nbrtos.h:386
uint8_t Pend(uint32_t timeoutTicks=WAIT_FOREVER)
Wait timeout ticks for the value of the semaphore to be non zero.
Definition nbrtos.h:434
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:401
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:478
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:445
A convenience wrapper around OS_Q.
Definition nbrtos.h:854
OS_FIFO element definition.
Definition nbrtos.h:884
puint8_t pAsBytePtr
Next OS_FIFO element data byte pointer.
Definition nbrtos.h:893
struct os_fifo_el * pNextFifo_El
Pointer to next OS_FIFO element.
Definition nbrtos.h:892