NetBurner 3.4.0f
PDF Version


 
Loading...
Searching...
No Matches
nbrtos.h
Go to the documentation of this file.
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
16#ifndef _NBRTOS_H
17#define _NBRTOS_H
18
19// NB Definitions
20#include <predef.h>
21
22// NB Constants
23#include <constants.h>
24
25// NB Libs
26#include <basictypes.h>
27#include <nbrtoscpu.h>
28#include <predef.h>
29
30/***********************************************************
31 * NBRTOS.H
32 * SYSTEM DECLARATIONS
33 ***********************************************************
34 */
35#define OS_LO_PRIO 63 /*IDLE task priority */
36
43#define OS_STAT_RDY 0x00
44#define OS_STAT_MBOX 0x01
45#define OS_STAT_SEM 0x02
46#define OS_STAT_Q 0x04
47#define OS_STAT_FIFO 0x08
48#define OS_STAT_CRIT 0x10
49#define OS_STAT_DELAY 0x20
50#define OS_STAT_RES4 0x40
51#define OS_STAT_RES5 0x80
59#define OS_NO_ERR 0
60#define OS_TIMEOUT 10
61#define OS_MBOX_FULL 20
62#define OS_Q_FULL 30
63#define OS_Q_EXISTS 31
64#define OS_PRIO_EXIST 40
65#define OS_PRIO_INVALID 41
66#define OS_SEM_ERR 50
67#define OS_SEM_OVF 51
68#define OS_CRIT_ERR 60
69#define OS_NO_MORE_TCB 70
72#define WAIT_FOREVER 0
73
74typedef volatile uint32_t tick_t;
75
77// GLOBAL VARIABLES
78//
79extern vuint32_t Secs; // Number of seconds since system start
80extern volatile tick_t TimeTick; // Number of time ticks since system start
81
82// Is test_time later than now (TimeTick)
83inline bool IsTickLater(uint32_t test_time)
84{
85 return ((int)(TimeTick - test_time) < 0);
86}
87
88// Is test_time NoworEarlier than TimeTick
89inline bool IsTickNowOrEarlier(uint32_t test_time)
90{
91 return ((int)(TimeTick - test_time) >= 0);
92}
93
94// Compare two timetick values
95inline bool Is2ndTickEarlier(uint32_t t1, uint32_t t2)
96{
97 return (((int)(t1 - t2)) > 0);
98}
99
100// Compare two timetick values
101inline bool Is2ndTickNowOrEarlier(uint32_t t1, uint32_t t2)
102{
103 return (((int)(t1 - t2)) >= 0);
104}
105
106class TickTimeout;
107struct RawTickTimeout_t
108{
109 tick_t expiration;
110
111 inline bool expired() const { return expiration ? (((int)(expiration - TimeTick)) <= 0) : false; }
112 inline bool expired() volatile { return expiration ? (((int)(expiration - TimeTick)) <= 0) : false; }
113 inline operator bool() const { return !expired(); }
114 const RawTickTimeout_t &operator=(const TickTimeout &rhs);
115 volatile RawTickTimeout_t &operator=(const TickTimeout &rhs) volatile;
116
117 inline bool operator<(const RawTickTimeout_t &later)
118 {
119 if (!expiration)
120 return false;
121 if (!later.expiration)
122 return true;
123 return (((int)(expiration - later.expiration)) <= 0);
124 }
125
126 inline bool operator<(tick_t later)
127 {
128 if (!expiration)
129 return false;
130 return (((int)(expiration - later)) <= 0);
131 }
132
133 inline tick_t operator-(const tick_t &tick) { return expiration - tick; }
134 inline tick_t operator-(const tick_t &tick) const { return expiration - tick; }
135 inline tick_t operator-(const tick_t &tick) volatile { return expiration - tick; }
136};
137
138inline bool operator==(const RawTickTimeout_t &lhs, const int &rhs)
139{
140 return lhs.expiration == (tick_t)rhs;
141}
142
143inline bool operator==(const volatile RawTickTimeout_t &lhs, const int &rhs)
144{
145 return lhs.expiration == (tick_t)rhs;
146}
147
154{
155 RawTickTimeout_t raw;
156
157 void set(uint32_t timeout)
158 {
159 if (!timeout) { raw.expiration = 0; }
160 else
161 {
162 raw.expiration = TimeTick + (timeout & 0x7FFFFFFF);
163 // A 1 tick delay extension is introduced on TimeTick overflow
164 // in order to allow for infinite delays to be indicated with an
165 // expiration of zero
166 if (timeout && !raw.expiration) { raw.expiration = 1; }
167 }
168 }
169
170 public:
171 class uint32_nonboolean_t
172 {
173 uint32_t value;
174
175 public:
176 uint32_nonboolean_t(uint32_t val) : value(val) {}
177 inline explicit operator bool() { return (bool)value; }
178 inline operator uint32_t() { return value; }
179 };
180
181 explicit TickTimeout() { set(0); }
182
188 TickTimeout(uint32_t timeout) { set(timeout); }
189 TickTimeout(uint16_t timeout) { set(timeout); }
190 TickTimeout(int timeout) { set(timeout); }
191
192
198 inline uint32_t val() const
199 {
200 if (!raw.expiration) { return raw.expiration; }
201 int ret = raw.expiration - TimeTick;
202 // Prevent passing an infinite or otherwise bogus timeout in a tick race
203 return (ret > 0) ? ret : 1;
204 }
205
212 inline bool expired() const { return raw.expired(); }
213
225 inline operator bool() const { return !expired(); }
226
227 inline operator uint32_t() const { return val(); }
228
229 inline operator uint16_t() const
230 {
231 uint32_t ret = val();
232 return ret > 0xFFFF ? 0xFFFE : ret;
233 }
234
235 inline TickTimeout &operator=(const TickTimeout &rhs)
236 {
237 raw.expiration = rhs.raw.expiration;
238 return *this;
239 }
240 inline TickTimeout &operator=(uint32_t val)
241 {
242 set(val);
243 return *this;
244 }
245 inline bool operator<(TickTimeout later)
246 {
247 return raw < later.raw;
248 }
249 inline bool operator<(tick_t later)
250 {
251 return raw < later;
252 }
253
259 inline void SetUntil(uint32_t when) {raw.expiration = when; }
260
261 friend void OSTimeWaitUntil(uint32_t systemTickValue);
262
263 friend class RawTickTimeout_t;
264};
265
266inline const RawTickTimeout_t &RawTickTimeout_t::operator=(const TickTimeout &rhs)
267{
268 expiration = rhs.raw.expiration;
269 return *this;
270}
271
272inline volatile RawTickTimeout_t &RawTickTimeout_t::operator=(const TickTimeout &rhs) volatile
273{
274 expiration = rhs.raw.expiration;
275 return *this;
276}
277
278// The following class holds a list of tasks
279
280class task_bit_list
281{
282 public:
283 volatile uint32_t OSTbl[TASK_TABLE_SIZE];
284
285 // task_bit_list();
286 void Init() volatile;
287 void Copy(volatile task_bit_list &rhs)
288 {
289 for (int i = 0; i < TASK_TABLE_SIZE; i++)
290 {
291 OSTbl[i] = rhs.OSTbl[i];
292 }
293 }
294
295 // The following functions are all guaranteed to be atomic
296 void set(int set_num) volatile;
297 void clr(int clr_num) volatile;
298
299 // The following functions return 0 if no bits are set.
300 uint32_t gethigh() volatile;
301 uint32_t get_high_and_clear() volatile;
302
303 inline bool isSet(int num) volatile const { return (OSTbl[num / 32] & (0x80000000 >> (num % 32))); }
304};
305
306class OS_TCB;
307
308// The common element of all the task objects
309class OS_TASK_DLY_OBJ
310{
311 task_bit_list tasks_waiting;
312
313 public:
314 OS_TASK_DLY_OBJ();
315 void Init();
316
317 // Returns true if woken up, returns false if timed out
318 bool Wait_when(uint8_t StatReason, TickTimeout &timeout);
319
320 inline bool Wait(uint8_t StatReason, uint32_t to_count)
321 {
322 TickTimeout to_when(to_count);
323 return Wait_when(StatReason, to_when);
324 }
325
326 // This releases the highest priority task waiting on this object.
327 void MakeHighTaskWaitingReady(uint8_t StatReason);
328 friend class OS_TCB;
329} __attribute__((packed));
330
331// class OS_TCB;//forward
332
333class OS_TCB : public cpu_tcb
334{
335 public:
336 uint8_t OSTCBStat; // Holds the current status of the TCB
337 uint8_t OSTCBResult; // Basically holds the timeout or not flag when woken.
338 uint8_t OSTCBPrio; // Index to prio table.... not sure if we need to keep this.
339 uint8_t pad; // Make 32 bit aligned.
340
341 RawTickTimeout_t OSTCBDly_when; // When to release timeout the task, 0= never.
342
343 const char *pOSTCBName;
344 OS_TCB *OSTCBNext;
345 OS_TCB *OSTCBPrev;
346
347#ifdef NBRTOS_PRIO_PROMOTION
348 // These pointers are for handling Priority Promotion when OS_CRITs create
349 // an inversion situation
350 volatile OS_TCB *pPromotedTo;
351 volatile OS_TCB *pDisplacedBy;
352 OS_TASK_DLY_OBJ *pWaiting;
353 uint32_t displacedByOrigPrio;
354
355 void PromoteToCurPrio() volatile;
356 void Demote() volatile;
357#endif
358
359 static volatile OS_TCB *GetCur();
360
361#ifdef NBRTOS_TIME
362 unsigned long switchTimeTick;
363 unsigned long switchTimeFraction;
364 unsigned long runningTime;
365 unsigned long runningTimeFraction;
366#endif
367 // OS_TCB(); //Zero everything
368 void Init();
369
370 // Set up TCB assuming that the STACK has already been setup and properly initalized.
371 bool Init(uint8_t prio, void *pActualTop, void *pstk, long *pbot, const char *name);
372};
373
374/* Forward Declaration */
375struct OS_CRIT;
376
382struct OS_SEM : public OS_TASK_DLY_OBJ
383{
384 volatile uint32_t OSSemCnt;
385 volatile uint32_t OSSemUsed;
386
387 private:
388 bool Claim();
389
390 public:
398 inline OS_SEM(int32_t cnt = 0) : OS_TASK_DLY_OBJ() { Init(cnt); }
399
409 uint8_t Init(int32_t cnt = 0);
410
420 uint8_t Post();
421
431 inline uint8_t Pend(uint32_t timeoutTicks = WAIT_FOREVER){TickTimeout tt(timeoutTicks); return Pend(tt);};
432
442 inline uint8_t PendUntil(uint32_t timeout_time){TickTimeout tt(0); tt.SetUntil(timeout_time); return Pend(tt);};
443
453 uint8_t Pend(TickTimeout &t);
454
464 uint8_t PendNoWait();
465
475 inline uint32_t Avail() { uint32_t v; USER_ENTER_CRITICAL(); v=OSSemCnt-OSSemUsed; USER_EXIT_CRITICAL(); return v;};
476
477} __attribute__((packed));
478
493struct OS_MBOX : public OS_TASK_DLY_OBJ
494{
495 void *OSMboxMsg;
496 bool OSMboxDataAvail;
497
498 bool Claim(void *&Result);
499
500 public:
506 inline OS_MBOX() : OS_TASK_DLY_OBJ() { Init(); }
507
515 inline OS_MBOX(void *msg) : OS_TASK_DLY_OBJ() { Init(msg); }
516
526 uint8_t Init(void *msg = NULL);
527
538 uint8_t Post(void *msg);
539
552 inline void *Pend(uint32_t timeoutTicks, uint8_t &result){TickTimeout tt(timeoutTicks); return Pend(tt,result);};
553
566 void *Pend(TickTimeout &t, uint8_t &result);
567
578 inline void *Pend(uint32_t timeoutTicks = WAIT_FOREVER)
579 {
580 uint8_t unused;
581 return Pend(timeoutTicks, unused);
582 };
583
596 inline void *PendUntil(uint32_t timeoutTime, uint8_t &result){TickTimeout tt(0); tt.SetUntil(timeoutTime); return Pend(tt,result);};
597
609 void *PendNoWait(uint8_t &result);
610
619 inline void *PendNoWait()
620 {
621 uint8_t unused;
622 return PendNoWait(unused);
623 };
624};
625
626
627template<typename T>
628class TEMPL_MBOX
629{
630 protected:
631 OS_MBOX m_mbox;
632
633 public:
634 TEMPL_MBOX(const T *msg) : m_mbox((void *)msg) {}
635 inline uint8_t Init(const T *msg) { return m_mbox.Init((void *)msg); }
636 inline uint8_t Post(const T *msg) { return m_mbox.Post((void *)msg); }
637
638 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) { return static_cast<T *>(m_mbox.Pend(timeoutTicks, result)); };
639
640 inline T *PendNoWait(uint8_t &result) { return static_cast<T *>(m_mbox.PendNoWait(result)); };
641
642 inline T *Pend(uint32_t timeoutTicks = WAIT_FOREVER) { return static_cast<T *>(m_mbox.Pend(timeoutTicks)); };
643
644 inline T *PendNoWait() { return static_cast<T *>(m_mbox.PendNoWait()); };
645};
646
647
668struct OS_Q : public OS_TASK_DLY_OBJ
669{
670 void **OSQStart;
671 void **OSQEnd;
672 void **OSQIn;
673 void **OSQOut;
674 uint8_t OSQSize;
675 uint8_t OSQEntries;
676
677 bool Claim(void *&Result);
678
679 public:
695 inline OS_Q(void **pQueueStorage, uint8_t size) : OS_TASK_DLY_OBJ() { Init(pQueueStorage, size); }
696
705 uint8_t Init(void **pQueueStorage, uint8_t size);
706
717 uint8_t Post(void *pItem);
718
729 uint8_t PostFirst(void *pItem);
730
743 uint8_t PostUnique(void *pItem);
744
757 uint8_t PostUniqueFirst(void *msg);
758
771 inline void *Pend(uint32_t timeoutTicks, uint8_t &result){TickTimeout tt(timeoutTicks); return Pend(tt,result);};
772
785 void *Pend(TickTimeout &t, uint8_t &result);
786
797 inline void *Pend(uint32_t timeoutTicks = WAIT_FOREVER)
798 {
799 uint8_t unused;
800 return Pend(timeoutTicks, unused);
801 };
802
815 inline void *PendUntil(uint32_t timeoutTime, uint8_t &result){TickTimeout tt(0); tt.SetUntil(timeoutTime); return Pend(tt,result);};
816
828 void *PendNoWait(uint8_t &result);
829
838 inline void *PendNoWait()
839 {
840 uint8_t unused;
841 return PendNoWait(unused);
842 };
843};
844
845template<typename T>
846struct TEMPL_Q
847{
848 protected:
849 OS_Q m_q;
850
851 public:
852 TEMPL_Q() {}
853 TEMPL_Q(T **pQueueStorage, uint8_t size)
854 : m_q((void**)pQueueStorage,size) { }
855 uint8_t Init(T **pQueueStorage, uint8_t size) { return m_q.Init((void **)pQueueStorage, size); }
856 uint8_t Post(T *item) { return m_q.Post((void *)item); }
857 uint8_t PostFirst(T *item) { return m_q.PostFirst((void *)item); };
858 uint8_t PostUnique(T *item) { return m_q.PostUnique((void *)item); };
859 uint8_t PostUniqueFirst(T *item) { return m_q.PostUniqueFirst((void *)item); };
860
861 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) { return static_cast<T *>(m_q.Pend(timeoutTicks, result)); };
862
863 inline T *Pend(uint32_t timeoutTicks = WAIT_FOREVER) { return static_cast<T *>(m_q.Pend(timeoutTicks)); };
864
865 inline T *PendNoWait() { return static_cast<T *>(m_q.PendNoWait()); };
866
867 inline T *PendNoWait(uint8_t &result) { return static_cast<T *>(m_q.PendNoWait(result)); };
868};
869
876typedef struct os_fifo_el
877{
883 union
884 {
886 puint8_t pAsBytePtr;
887 };
889
899struct OS_FIFO : public OS_TASK_DLY_OBJ
900{
901 OS_FIFO_EL *pHead;
902 OS_FIFO_EL *pTail;
903
904 bool Claim(volatile OS_FIFO_EL *&pToRet);
905
906 public:
912 inline OS_FIFO() : OS_TASK_DLY_OBJ() { Init(); }
913
921 uint8_t Init();
922
934 uint8_t Post(OS_FIFO_EL *pToPost);
935
947 uint8_t PostFirst(OS_FIFO_EL *pToPost);
948
961 inline OS_FIFO_EL *Pend(uint32_t timeoutTicks, uint8_t &result){TickTimeout tt(timeoutTicks); return Pend(tt,result);};
962
975 OS_FIFO_EL *Pend(TickTimeout &t, uint8_t &result);
976
987 inline OS_FIFO_EL *Pend(uint32_t timeoutTicks = WAIT_FOREVER)
988 {
989 uint8_t unused;
990 return Pend(timeoutTicks, unused);
991 };
992
1005 inline OS_FIFO_EL *PendUntil(uint32_t timeoutTime, uint8_t &result){TickTimeout tt(0); tt.SetUntil(timeoutTime); return Pend(tt,result);};
1006
1018 OS_FIFO_EL *PendNoWait(uint8_t &result);
1019
1020
1030 {
1031 uint8_t unused;
1032 return PendNoWait(unused);
1033 };
1034};
1035
1036
1037
1038template<typename T>
1039struct TEMPL_FIFO
1040{
1041 protected:
1042 OS_FIFO m_fifo;
1043
1044 public:
1045 TEMPL_FIFO() { m_fifo.Init(); }
1046 uint8_t Init() { return m_fifo.Init(); }
1047 uint8_t Post(T *item) { return m_fifo.Post((OS_FIFO_EL *)item); }
1048 uint8_t PostFirst(T *item) { return m_fifo.PostFirst((OS_FIFO_EL *)item); };
1049
1050 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) { return static_cast<T *>(m_fifo.Pend(timeoutTicks, result)); };
1051
1052 inline T *Pend(uint32_t timeoutTicks = WAIT_FOREVER) { return static_cast<T *>(m_fifo.Pend(timeoutTicks)); };
1053
1054 inline T *PendNoWait() { return static_cast<T *>(m_fifo.PendNoWait()); };
1055
1056 inline T *PendNoWait(uint8_t &result) { return static_cast<T *>(m_fifo.PendNoWait(result)); };
1057
1058 inline OS_FIFO *GetRawFIFO() { return &m_fifo; }
1059};
1060
1061/*
1062 * Critical Section DATA STRUCTURES
1063 *
1064 * Added by PTB 5/09/99
1065 * Modified by DEC 3/21/16
1066 */
1067
1068class BufferCriticalLock;
1069class fifo_buffer_storage;
1070
1076struct OS_CRIT : public OS_TASK_DLY_OBJ
1077{
1078 OS_TCB *OSCritOwnerTCB;
1079 uint32_t OSCritDepthCount;
1080
1081 bool Claim();
1082
1083 public:
1089 OS_CRIT() { Init(); }
1090
1098 uint8_t Init();
1099
1115 uint8_t LockAndEnter(uint32_t timeoutTicks = WAIT_FOREVER);
1116
1131 uint8_t Enter(TickTimeout &t);
1132
1147 inline uint8_t Enter(uint32_t timeoutTicks = WAIT_FOREVER) {TickTimeout tt(timeoutTicks); return Enter(tt);};
1148
1160 uint8_t EnterNoWait();
1161
1173 uint8_t Leave();
1174
1186
1187 friend class BufferCriticalLock;
1188 friend class fifo_buffer_storage;
1189
1195 bool UsedFromISR() { return OSCritOwnerTCB == (OS_TCB *)0xFFFFFFFF; }
1196
1204 void SetUseFromISR(bool enableFromISR)
1205 {
1206 if (enableFromISR) { OSCritOwnerTCB = (OS_TCB *)0xFFFFFFFF; }
1207 else if (UsedFromISR())
1208 {
1209 OSCritOwnerTCB = NULL;
1210 }
1211 }
1212
1216 bool OwnedByCurTask();
1217
1223 uint32_t CurDepth() { return OSCritDepthCount; }
1224
1228 friend void ForceReboot(bool fromIRQ);
1229} __attribute__((packed));
1230
1231
1232
1233struct OS_FLAGS_WAIT;
1234
1246{
1247 protected:
1248 vuint32_t m_current_flags;
1249 void *m_pWaitinglist;
1250 void TestFlags();
1251 void AddOFW(OS_FLAGS_WAIT *ofw);
1252 void RemoveOFW(OS_FLAGS_WAIT *ofw);
1253
1254 public:
1261
1267 void Init();
1268
1276 void Set(uint32_t bits_to_set);
1277
1285 void Clear(uint32_t bits_to_clr);
1286
1287
1295 void Write(uint32_t bits_to_force);
1296
1304 uint32_t State();
1305
1320 uint8_t PendAny(uint32_t bit_mask, uint16_t timeout = WAIT_FOREVER){TickTimeout tt(timeout); return PendAny(bit_mask,tt);}
1321
1336 uint8_t PendAny(uint32_t bit_mask, TickTimeout & timeout);
1337
1338
1350 uint8_t PendAnyUntil(uint32_t bit_mask, uint32_t end_time){TickTimeout tt(0); tt.SetUntil(end_time); return PendAny(bit_mask,tt);}
1351
1352
1362 uint8_t PendAnyNoWait(uint32_t bit_mask);
1363
1377 uint8_t PendAll(uint32_t bit_mask, uint16_t timeout = WAIT_FOREVER){TickTimeout tt(timeout); return PendAll(bit_mask,tt);}
1378
1392 uint8_t PendAll(uint32_t bit_mask,TickTimeout & timeout);
1393
1405 uint8_t PendAllUntil(uint32_t bit_mask, uint32_t end_time){TickTimeout tt(0); tt.SetUntil(end_time); return PendAll(bit_mask,tt);}
1406
1407
1418 uint8_t PendAllNoWait(uint32_t bit_mask);
1419
1420};
1421
1422
1423/* Create and initialize an OS flags object
1424This function must be called before you use an OS_FLAGS object.
1425*/
1426[[deprecated]] inline void OSFlagCreate(OS_FLAGS *pf)
1427{
1428 pf->Init();
1429};
1430
1441[[deprecated]] inline void OSFlagSet(OS_FLAGS *flags, uint32_t bits_to_set)
1442{
1443 flags->Set(bits_to_set);
1444};
1445
1456[[deprecated]] inline void OSFlagClear(OS_FLAGS *flags, uint32_t bits_to_clr)
1457{
1458 flags->Clear(bits_to_clr);
1459};
1460
1475[[deprecated]] inline uint8_t OSFlagPendAny(OS_FLAGS *flags, uint32_t bit_mask, uint16_t timeout)
1476{
1477 return flags->PendAny(bit_mask, timeout);
1478};
1479
1493[[deprecated]] inline uint8_t OSFlagPendAnyNoWait(OS_FLAGS *flags, uint32_t bit_mask)
1494{
1495 return flags->PendAnyNoWait(bit_mask);
1496};
1497
1512[[deprecated]] inline uint8_t OSFlagPendAll(OS_FLAGS *flags, uint32_t bit_mask, uint16_t timeout)
1513{
1514 return flags->PendAll(bit_mask, timeout);
1515};
1516
1530[[deprecated]] inline uint8_t OSFlagPendAllNoWait(OS_FLAGS *flags, uint32_t bit_mask)
1531{
1532 return flags->PendAllNoWait(bit_mask);
1533};
1534
1546[[deprecated]] inline uint32_t OSFlagState(OS_FLAGS *flags)
1547{
1548 return flags->State();
1549};
1550
1551/*
1552 ***********************************************************
1553 * NBRTOS GLOBAL VARIABLES
1554 ***********************************************************
1555 */
1556// Pointers to each of the OS_TCB structure sorted by priority
1557extern volatile OS_TCB *OSTCBPrioTbl[OS_MAX_PRIOS];
1558
1559// taks bits for what tasks are ready to run
1560extern volatile task_bit_list OSTaskReadyList;
1561#ifdef NBRTOS_PRIO_PROMOTION
1562extern volatile task_bit_list OSInUsePrioList FAST_SYS_VAR;
1563extern volatile task_bit_list OSActivePrioList FAST_SYS_VAR;
1564#endif
1565
1566extern OS_TCB OSTCBTbl[OS_MAX_TASKS]; // All the possible TCB's
1567
1568extern OS_TCB *pOSActiveTCBList; // Linked list of activ TCB's
1569
1570// One of the following two variables wsill go away....
1571extern volatile uint32_t nPrioOfCurTask; // Current task priority number
1572extern volatile uint32_t nPrioOfHighReady; // highest task ready to run
1573extern volatile OS_TCB *OSTCBCur;
1574extern volatile OS_TCB *OSTCBHighRdy;
1575
1576extern OS_TCB *pOSTCBFreeList; // List of unused TCB's
1577
1578extern volatile uint32_t OSIntNesting;
1579extern volatile uint32_t OSLockNesting;
1580extern volatile uint32_t OSISRLevel32;
1581
1582extern volatile bool OSRunning;
1583
1584// So non-recompilable files can reference the right struct size
1585extern unsigned long OSTcbStructSize;
1586
1587#ifdef NBRTOS_TASK_LOG
1588extern void (*pTaskLogger)(uint8_t nextPrio);
1589#endif
1590/*
1591Removed
1592 extern volatile BOOLEAN OSShowTasksOnLeds;
1593*/
1594
1595/*
1596***********************************************************
1597* NBRTOS FUNCTION PROTOTYPES
1598***********************************************************
1599*/
1600void OSInit(uint8_t maxtasks);
1601void OSStart(void);
1602void OSCreateIdleTask();
1603
1632uint8_t OSTaskCreatewName(void (*task)(void *dptr), // Function to call
1633 void *data, // Data to pass as a parameter
1634 void *pstktop, // Stack top
1635 void *pstkbot, // Stack bottom
1636 uint8_t prio, // current priority
1637 const char *name // task name
1638);
1639
1650#define OSSimpleTaskCreatewName(x, p, n) \
1651 { \
1652 static uint32_t func_##x_Stk[USER_TASK_STK_SIZE] __attribute__((aligned(4))); \
1653 OSTaskCreatewName(x, NULL, (void *)&func_##x_Stk[USER_TASK_STK_SIZE], (void *)func_##x_Stk, p, n); \
1654 }
1655
1656#define OSSimpleTaskCreatewNameSRAM(x, p, n) \
1657 { \
1658 static uint32_t func_##x_Stk[USER_TASK_STK_SIZE] __attribute__((aligned(4))) FAST_USER_STK; \
1659 OSTaskCreatewName(x, NULL, (void *)&func_##x_Stk[USER_TASK_STK_SIZE], (void *)func_##x_Stk, p, n); \
1660 }
1661
1662/* Helper macro*/
1663#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)
1664
1680#define OSSimpleTaskCreateLambda(p,n,f) LambdaTask2(p,n,[]( void * pv)f,__COUNTER__)
1681
1682
1702void OSTimeWaitUntil(uint32_t systemTickValue);
1703
1716inline void OSTimeDly(uint32_t to_count)
1717{
1718 uint32_t to_when = to_count + TimeTick;
1719 if (!to_when) to_when++;
1720 OSTimeWaitUntil(to_when);
1721};
1722
1723// void OSIntEnter( void );
1724
1725extern "C"
1726{
1727 void OSIntExit(void);
1728 void OSCtxSw(void);
1729 void OSTickISR(void);
1730 void OSStartHighRdy(void);
1731 void OSSetupVBR(void);
1732 void OSSched(void);
1733 void OSTimeTick(void);
1734
1745 void OSTaskDelete(void);
1746}
1747
1748OS_TCB *OSTCBGetFree(void);
1749
1768uint8_t OSChangePrio(uint32_t newp);
1769
1776void OSSetName(const char *cp);
1777
1791void OSLock(void);
1792
1800void OSUnlock(void);
1801
1816[[deprecated]] inline uint8_t OSSemInit(OS_SEM *psem, long value)
1817{
1818 return (psem != nullptr) ? psem->Init(value) : OS_CRIT_ERR;
1819}
1820
1834[[deprecated]] inline uint8_t OSSemPost(OS_SEM *psem)
1835{
1836 return psem->Post();
1837}
1838
1853[[deprecated]] inline uint8_t OSSemPend(OS_SEM *psem, uint16_t timeout)
1854{
1855 return psem->Pend(timeout);
1856}
1857
1870[[deprecated]] inline uint8_t OSSemPendNoWait(OS_SEM *psem)
1871{
1872 return psem->PendNoWait();
1873}
1874
1888[[deprecated]] inline uint8_t OSMboxInit(OS_MBOX *pmbox, void *msg)
1889{
1890 return (pmbox != nullptr) ? pmbox->Init(msg) : OS_CRIT_ERR;
1891}
1892
1906[[deprecated]] inline uint8_t OSMboxPost(OS_MBOX *pmbox, void *msg)
1907{
1908 return pmbox->Post(msg);
1909}
1910
1922[[deprecated]] inline void *OSMboxPend(OS_MBOX *pmbox, uint16_t timeout, uint8_t *err)
1923{
1924 return pmbox->Pend(timeout, *err);
1925}
1926
1937[[deprecated]] inline void *OSMboxPendNoWait(OS_MBOX *pmbox, uint8_t *err)
1938{
1939 return pmbox->PendNoWait(*err);
1940}
1941
1956[[deprecated]] inline uint8_t OSQInit(OS_Q *pq, void **start, uint8_t size)
1957{
1958 return (pq != nullptr) ? pq->Init(start, size) : OS_CRIT_ERR;
1959}
1960
1974[[deprecated]] inline uint8_t OSQPost(OS_Q *pq, void *msg)
1975{
1976 return pq->Post(msg);
1977}
1978
1992[[deprecated]] inline uint8_t OSQPostFirst(OS_Q *pq, void *msg)
1993{
1994 return pq->PostFirst(msg);
1995}
1996
2012[[deprecated]] inline uint8_t OSQPostUnique(OS_Q *pq, void *msg)
2013{
2014 return pq->PostUnique(msg);
2015}
2016
2032[[deprecated]] inline uint8_t OSQPostUniqueFirst(OS_Q *pq, void *msg)
2033{
2034 return pq->PostUniqueFirst(msg);
2035}
2036
2048[[deprecated]] inline void *OSQPend(OS_Q *pq, uint16_t timeout, uint8_t *err)
2049{
2050 return pq->Pend(timeout, *err);
2051}
2052
2063[[deprecated]] inline void *OSQPendNoWait(OS_Q *pq, uint8_t *err)
2064{
2065 return pq->PendNoWait(*err);
2066}
2067
2080[[deprecated]] inline uint8_t OSFifoInit(OS_FIFO *pFifo)
2081{
2082 return (pFifo != nullptr) ? pFifo->Init() : OS_CRIT_ERR;
2083}
2084
2097[[deprecated]] inline uint8_t OSFifoPost(OS_FIFO *pFifo, OS_FIFO_EL *pToPost)
2098{
2099 return pFifo->Post(pToPost);
2100}
2113[[deprecated]] inline uint8_t OSFifoPostFirst(OS_FIFO *pFifo, OS_FIFO_EL *pToPost)
2114{
2115 return pFifo->PostFirst(pToPost);
2116};
2117
2128[[deprecated]] inline OS_FIFO_EL *OSFifoPend(OS_FIFO *pFifo, uint16_t timeout)
2129{
2130 return pFifo->Pend(timeout);
2131};
2132
2142[[deprecated]] inline OS_FIFO_EL *OSFifoPendNoWait(OS_FIFO *pFifo)
2143{
2144 return pFifo->PendNoWait();
2145 ;
2146}
2147
2159[[deprecated]] inline uint8_t OSCritInit(OS_CRIT *pCrit)
2160{
2161 return pCrit->Init();
2162}
2163[[deprecated]] inline uint8_t OSCritLockAndEnter(OS_CRIT *pCrit, uint16_t timeout)
2164{
2165 return pCrit->LockAndEnter(timeout);
2166}
2167
2181[[deprecated]] inline uint8_t OSCritEnter(OS_CRIT *pCrit, uint16_t timeout)
2182{
2183 return pCrit->Enter(timeout);
2184}
2185
2198[[deprecated]] inline uint8_t OSCritEnterNoWait(OS_CRIT *pCrit)
2199{
2200 return pCrit->EnterNoWait();
2201}
2202
2215[[deprecated]] inline uint8_t OSCritLeave(OS_CRIT *pCrit)
2216{
2217 return pCrit->Leave();
2218}
2219[[deprecated]] inline uint8_t OSCritLeaveAndUnlock(OS_CRIT *pCrit)
2220{
2221 return pCrit->LeaveAndUnlock();
2222}
2223
2227uint8_t OSTaskID(void);
2228
2232const char *OSTaskName();
2233
2234void OSChangeTaskWhen(uint16_t task_prio, uint32_t to_when);
2235
2246inline void OSChangeTaskDly(uint16_t task_prio, uint32_t to_count)
2247{
2248 uint32_t to_when = to_count + TimeTick;
2249 if (!to_when) to_when++;
2250 OSChangeTaskWhen(task_prio, to_when);
2251}
2252
2256void OSDumpStack(void);
2257
2258#if (defined NBRTOS_STACKOVERFLOW) || (defined NBRTOS_STACKUNDERFLOW)
2259void EnableOSStackProtector();
2260extern "C" void OSStackProtectCtxSw(); // ASM task switcher
2261extern "C" void OSStackProtectIntCtxSw(); // ASM task switcher
2262extern "C" void OSStackProtector(); // extern because must be called from ASM
2263#endif
2264
2265#ifdef NBRTOS_STACKCHECK
2275
2284void OSDumpTasks(void);
2285
2294void OSStartTaskDumper(uint8_t prio, uint32_t reportInterval);
2295#endif
2296
2297#ifdef NBRTOS_TASKLIST
2303void ShowTaskList(void);
2304#endif
2305
2306#ifdef NBRTOS_TIME
2307uint32_t GetCurrentTaskTime(uint32_t *const TotalTicks);
2308void ShowTaskTimes(void);
2309void ClearTaskTimes(void);
2310#endif
2311
2324{
2325 public:
2330
2335} __attribute__((packed));
2336
2347{
2348 OS_CRIT *pcrit;
2349
2350 public:
2358 {
2359 pcrit = &ocrit;
2360 ocrit.Enter(0);
2361 };
2362
2371 OSCriticalSectionObj(OS_CRIT &ocrit, bool NoWait, TickTimeout &timeout)
2372 {
2373 pcrit = &ocrit;
2374 if (NoWait)
2375 ocrit.EnterNoWait();
2376 else
2377 ocrit.Enter(timeout);
2378 };
2379
2385} __attribute__((packed));
2386
2398{
2399 OS_CRIT *pcrit;
2400
2401 public:
2408 OSLockAndCritObj(OS_CRIT &ocrit) : pcrit(&ocrit) { pcrit->LockAndEnter(0); }
2409
2415};
2416
2429{
2430 OS_CRIT *pcrit;
2431
2432 public:
2439 OSSpinCrit(OS_CRIT &ocrit) : pcrit(&ocrit)
2440 {
2441 while (pcrit->EnterNoWait() == OS_TIMEOUT) {}
2442 }
2443
2448 ~OSSpinCrit() { pcrit->Leave(); }
2449};
2450
2451
2456{
2457 public:
2458 USERCritObj() { USER_ENTER_CRITICAL(); }
2459 ~USERCritObj() { USER_EXIT_CRITICAL(); }
2460};
2461
2462
2463
2471{
2472 return OSCritOwnerTCB == OSTCBCur;
2473}
2474
2487{
2488 static NBRtosInitObj * pHead;
2489 static bool bAlreadInited;
2490 NBRtosInitObj *pNext;
2491
2492 protected:
2493 inline bool WasInitDone() {return bAlreadInited; }
2494 NBRtosInitObj();
2496
2497 public:
2501 virtual void Notify()=0;
2502 static void InitWholeSet(); //Used internally
2503};
2504
2505
2506#endif
2507
2508
2509
2510
A simple class to derive from if you are creating tasks that are constructed at global scope and need...
Definition: nbrtos.h:2487
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:2347
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:2371
OSCriticalSectionObj(OS_CRIT &ocrit)
Initialize the OSCriticalSectionObj object, and then call Enter() on the OS_CRIT object that is passe...
Definition: nbrtos.h:2357
~OSCriticalSectionObj()
Destructs the OSCriticalSectionObj object, and call Leave() on the OS_CRIT object that was passed int...
Definition: nbrtos.h:2384
A simple wrapper class that helps utilize OS_CRIT objects to lock tasks and enter critical sections m...
Definition: nbrtos.h:2398
~OSLockAndCritObj()
Call LeaveAndUnlock() on the OSCriticalSectionObj object, then destruct.
Definition: nbrtos.h:2414
OSLockAndCritObj(OS_CRIT &ocrit)
Initialize the OSCriticalSectionObj object, and then call LockAndEnter() on the OS_CRIT object that i...
Definition: nbrtos.h:2408
A simple wrapper class that helps use OS locks effectively.
Definition: nbrtos.h:2324
OSLockObj()
Initialize the OSLockObj and calls OSLock().
Definition: nbrtos.h:2329
~OSLockObj()
Destructs the OSLockObj and calls OSUnlock().
Definition: nbrtos.h:2334
A simple wrapper class that uses an OS_CRIT object to try and claim a critical section,...
Definition: nbrtos.h:2429
~OSSpinCrit()
Call Leave() on the OS_CRIT object, and then destruct/.
Definition: nbrtos.h:2448
OSSpinCrit(OS_CRIT &ocrit)
Initialize the OSSpinCrit object, and then call EnterNoWait() repeatedly on the OS_CRIT object that i...
Definition: nbrtos.h:2439
TickTimeout objects are used to facilitate sequential function calls with timeout parameters that nee...
Definition: nbrtos.h:154
bool expired() const
Determine whether the timeout duration has elapsed.
Definition: nbrtos.h:212
TickTimeout(uint32_t timeout)
Create and initialize the Timeout.
Definition: nbrtos.h:188
void SetUntil(uint32_t when)
Set the TimeTick value to expire.
Definition: nbrtos.h:259
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:198
User critial section object class.
Definition: nbrtos.h:2456
NetBurner System Constants.
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:2246
uint8_t OSCritInit(OS_CRIT *pCrit)
This function initializes the critical section.
Definition: nbrtos.h:2159
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:1992
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:1816
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:1512
uint8_t OSMboxPost(OS_MBOX *pmbox, void *msg)
This function posts a message to a Mail box.
Definition: nbrtos.h:1906
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:1922
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:2012
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:2181
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:1475
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:2198
uint8_t OSCritLeave(OS_CRIT *pCrit)
This function releases the critical section.
Definition: nbrtos.h:2215
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:2032
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:2113
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:2097
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:1441
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:2128
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:1493
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:1974
uint8_t OSSemPendNoWait(OS_SEM *psem)
OSSemPendNoWait() is identical to OSSemPend(), but it does not wait.
Definition: nbrtos.h:1870
uint8_t OSFifoInit(OS_FIFO *pFifo)
Initialize a FIFO, which is used to pass structures from one task to another.
Definition: nbrtos.h:2080
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:1546
#define WAIT_FOREVER
Parameter macro used for timeout parameters that have a 0 value and wait forever.
Definition: nbrtos.h:72
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:1853
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:1456
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:1956
void * OSMboxPendNoWait(OS_MBOX *pmbox, uint8_t *err)
OSMboxPendNoWait() is identical to OSMboxPend(), but it does not wait.
Definition: nbrtos.h:1937
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:1530
bool OwnedByCurTask()
Check if critical section owned by the current task.
Definition: nbrtos.h:2470
void * OSQPendNoWait(OS_Q *pq, uint8_t *err)
OSQPendNoWait() is identical to the OSQPend() function but it does not wait.
Definition: nbrtos.h:2063
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:1716
OS_FIFO_EL * OSFifoPendNoWait(OS_FIFO *pFifo)
This function is identical to the OSFifoPen() function, but it does not wait.
Definition: nbrtos.h:2142
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:2048
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:1834
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:1888
#define OS_TIMEOUT
Timeout.
Definition: nbrtos.h:60
#define OS_CRIT_ERR
Critical section error.
Definition: nbrtos.h:68
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition: nbrtos.h:1077
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:1195
void SetUseFromISR(bool enableFromISR)
Set critical section UsedFromISR flag.
Definition: nbrtos.h:1204
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:1089
uint8_t Enter(uint32_t timeoutTicks=WAIT_FOREVER)
Request to Enter/Claim the critical section, with a time out parameter.
Definition: nbrtos.h:1147
uint32_t CurDepth()
Returns the critical section depth count.
Definition: nbrtos.h:1223
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:900
OS_FIFO()
Create and initialize a FIFO object.
Definition: nbrtos.h:912
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:987
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:1005
OS_FIFO_EL * PendNoWait()
Attempts to pend a structure to the FIFO, but does not wait.
Definition: nbrtos.h:1029
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:961
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:1246
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:1405
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:1320
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:1377
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:1350
Mailboxes single value storage locations used to communicate between tasks.
Definition: nbrtos.h:494
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:596
void * PendNoWait()
Checks if a message is available in the mailbox and returns immediately.
Definition: nbrtos.h:619
OS_MBOX()
Create and initialize a mailbox object with no defalut message.
Definition: nbrtos.h:506
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:515
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:578
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:552
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:669
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:838
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:815
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:771
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:695
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:797
Semaphores are used to control access to shared resources or or to communicate between tasks in a mul...
Definition: nbrtos.h:383
uint8_t Pend(uint32_t timeoutTicks=WAIT_FOREVER)
Wait timeout ticks for the value of the semaphore to be non zero.
Definition: nbrtos.h:431
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:398
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:475
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:442
OS_FIFO element definition.
Definition: nbrtos.h:877
puint8_t pAsBytePtr
Next OS_FIFO element data byte pointer.
Definition: nbrtos.h:886
struct os_fifo_el * pNextFifo_El
Pointer to next OS_FIFO element.
Definition: nbrtos.h:885