NetBurner 3.5.7
PDF Version
nbrtos.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
5
12#ifndef _NBRTOS_H
13#define _NBRTOS_H
14
15#include <predef.h>
16#include <constants.h>
17#include <basictypes.h>
18#include <nbrtoscpu.h>
19#include <predef.h>
20
31#define OS_LO_PRIO (OS_MAX_PRIOS-1) /* IDLE task priority */
32
40#define OS_STAT_RDY 0x00
41#define OS_STAT_MBOX 0x01
42#define OS_STAT_SEM 0x02
43#define OS_STAT_Q 0x04
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
58#define OS_NO_ERR 0
59#define OS_TIMEOUT 10
60#define OS_MBOX_FULL 20
61#define OS_Q_FULL 30
62#define OS_Q_EXISTS 31
63#define OS_PRIO_EXIST 40
64#define OS_PRIO_INVALID 41
65#define OS_SEM_ERR 50
66#define OS_SEM_OVF 51
67#define OS_CRIT_ERR 60
68#define OS_NO_MORE_TCB 70
69 // nbrtosErrorGroup
70
78#define OS_TFLAG_IN_USE 0x80
79 // nbrtosTaskFlag
80
81#define WAIT_FOREVER 0
82
83typedef volatile uint32_t tick_t;
84
85
86// GLOBAL VARIABLES
87extern vuint32_t Secs; // Number of seconds since system start
88extern volatile tick_t TimeTick; // Number of time ticks since system start
89
90// Is test_time later than now (TimeTick)
91inline bool IsTickLater(uint32_t test_time)
92{
93 return ((int)(TimeTick - test_time) < 0);
94}
95
96// Is test_time NoworEarlier than TimeTick
97inline bool IsTickNowOrEarlier(uint32_t test_time)
98{
99 return ((int)(TimeTick - test_time) >= 0);
100}
101
102// Compare two timetick values
103inline bool Is2ndTickEarlier(uint32_t t1, uint32_t t2)
104{
105 return (((int)(t1 - t2)) > 0);
106}
107
108// Compare two timetick values
109inline bool Is2ndTickNowOrEarlier(uint32_t t1, uint32_t t2)
110{
111 return (((int)(t1 - t2)) >= 0);
112}
113
114class TickTimeout;
115struct RawTickTimeout_t
116{
117 tick_t expiration = 0;
118
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;
124
125 inline bool operator<(const RawTickTimeout_t &later)
126 {
127 if (!expiration)
128 return false;
129 if (!later.expiration)
130 return true;
131 return (((int)(expiration - later.expiration)) <= 0);
132 }
133
134 inline bool operator<(tick_t later)
135 {
136 if (!expiration)
137 return false;
138 return (((int)(expiration - later)) <= 0);
139 }
140
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; }
144};
145
146inline bool operator==(const RawTickTimeout_t &lhs, const int &rhs)
147{
148 return lhs.expiration == (tick_t)rhs;
149}
150
151inline bool operator==(const volatile RawTickTimeout_t &lhs, const int &rhs)
152{
153 return lhs.expiration == (tick_t)rhs;
154}
155
162{
163 RawTickTimeout_t raw;
164
165 void set(uint32_t timeout)
166 {
167 if (!timeout) { raw.expiration = 0; }
168 else
169 {
170 raw.expiration = TimeTick + (timeout & 0x7FFFFFFF);
171 // A 1 tick delay extension is introduced on TimeTick overflow
172 // in order to allow for infinite delays to be indicated with an
173 // expiration of zero
174 if (timeout && !raw.expiration) { raw.expiration = 1; }
175 }
176 }
177
178 public:
179 class uint32_nonboolean_t
180 {
181 uint32_t value;
182
183 public:
184 uint32_nonboolean_t(uint32_t val) : value(val) {}
185 inline explicit operator bool() { return (bool)value; }
186 inline operator uint32_t() { return value; }
187 };
188
189 explicit TickTimeout() { set(0); }
190
196 TickTimeout(uint32_t timeout) { set(timeout); }
197 TickTimeout(uint16_t timeout) { set(timeout); }
198 TickTimeout(int timeout) { set(timeout); }
199
200
206 inline uint32_t val() const
207 {
208 if (!raw.expiration) { return raw.expiration; }
209 int ret = raw.expiration - TimeTick;
210 // Prevent passing an infinite or otherwise bogus timeout in a tick race
211 return (ret > 0) ? ret : 1;
212 }
213
220 inline bool expired() const { return raw.expired(); }
221
233 inline operator bool() const { return !expired(); }
234
235 inline operator uint32_t() const { return val(); }
236
237 inline operator uint16_t() const
238 {
239 uint32_t ret = val();
240 return ret > 0xFFFF ? 0xFFFE : ret;
241 }
242
243 inline TickTimeout &operator=(const TickTimeout &rhs)
244 {
245 raw.expiration = rhs.raw.expiration;
246 return *this;
247 }
248 inline TickTimeout &operator=(uint32_t val)
249 {
250 set(val);
251 return *this;
252 }
253 inline bool operator<(TickTimeout later)
254 {
255 return raw < later.raw;
256 }
257 inline bool operator<(tick_t later)
258 {
259 return raw < later;
260 }
261 inline TickTimeout &operator+=(uint32_t val)
262 {
263 if (raw.expiration)
264 {
265 raw.expiration += (val & 0x7FFFFFFF);
266 // A 1 tick delay extension is introduced on TimeTick overflow
267 // in order to allow for infinite delays to be indicated with an
268 // expiration of zero
269 if (val && !raw.expiration) { raw.expiration = 1; }
270 }
271 return *this;
272 }
273
279 inline void SetUntil(uint32_t when) {raw.expiration = when; }
280
281 friend void OSTimeWaitUntil(uint32_t systemTickValue);
282
283 friend class RawTickTimeout_t;
284};
285
286inline const RawTickTimeout_t &RawTickTimeout_t::operator=(const TickTimeout &rhs)
287{
288 expiration = rhs.raw.expiration;
289 return *this;
290}
291
292inline volatile RawTickTimeout_t &RawTickTimeout_t::operator=(const TickTimeout &rhs) volatile
293{
294 expiration = rhs.raw.expiration;
295 return *this;
296}
297
298// The following class holds a list of tasks
299
300class task_bit_list
301{
302 public:
303 volatile uint32_t OSTbl[TASK_TABLE_SIZE];
304
305 // task_bit_list();
306 void Init() volatile;
307 void Copy(volatile task_bit_list &rhs)
308 {
309 for (int i = 0; i < TASK_TABLE_SIZE; i++)
310 {
311 OSTbl[i] = rhs.OSTbl[i];
312 }
313 }
314
315 // The following functions are all guaranteed to be atomic
316 void set(int set_num) volatile;
317 void clr(int clr_num) volatile;
318
319 // The following functions return 0 if no bits are set.
320 uint32_t gethigh() volatile;
321 uint32_t get_high_and_clear() volatile;
322
323 inline bool isSet(int num) volatile const { return (OSTbl[num / 32] & (0x80000000 >> (num % 32))); }
324};
325
326class OS_TCB;
327
328// The common element of all the task objects
329class OS_TASK_DLY_OBJ
330{
331 task_bit_list tasks_waiting;
332
333 public:
334 OS_TASK_DLY_OBJ();
335 void Init();
336
337 // Returns true if woken up, returns false if timed out
338 bool Wait_when(uint8_t StatReason, TickTimeout &timeout);
339
340 inline bool Wait(uint8_t StatReason, uint32_t to_count)
341 {
342 TickTimeout to_when(to_count);
343 return Wait_when(StatReason, to_when);
344 }
345
346 // This releases the highest priority task waiting on this object.
347 void MakeHighTaskWaitingReady(uint8_t StatReason);
348 void MakeTaskWaitingReady(uint8_t taskPrio, uint8_t StatReason);
349 void MakeAllWaitingReady(uint8_t StatReason);
350
351 friend class OS_TCB;
352
353} __attribute__((packed));
354
355// class OS_TCB;//forward
356
357class OS_TCB : public cpu_tcb
358{
359 public:
360 uint8_t OSTCBStat; // Holds the current status of the TCB
361 uint8_t OSTCBResult; // Basically holds the timeout or not flag when woken.
362 uint8_t OSTCBPrio; // Index to prio table.... not sure if we need to keep this.
363 uint8_t OSTCBFlags; // Make 32 bit aligned.
364
365 RawTickTimeout_t OSTCBDly_when; // When to release timeout the task, 0= never.
366
367 const char *pOSTCBName;
368 OS_TCB *OSTCBNext;
369 OS_TCB *OSTCBPrev;
370
371#ifdef NBRTOS_PRIO_PROMOTION
372 // These pointers are for handling Priority Promotion when OS_CRITs create
373 // an inversion situation
374 volatile OS_TCB *pPromotedTo;
375 volatile OS_TCB *pDisplacedBy;
376 OS_TASK_DLY_OBJ *pWaiting;
377 uint32_t displacedByOrigPrio;
378
379 void PromoteToCurPrio() volatile;
380 void Demote() volatile;
381#endif
382
383 static volatile OS_TCB *GetCur();
384
385#ifdef NBRTOS_TIME
386 unsigned long switchTimeTick;
387 unsigned long switchTimeFraction;
388 unsigned long runningTime;
389 unsigned long runningTimeFraction;
390#endif
391 // OS_TCB(); //Zero everything
392 void Init();
393
394 // Set up TCB assuming that the STACK has already been setup and properly initalized.
395 bool Init(uint8_t prio, void *pActualTop, void *pstk, long *pbot, const char *name);
396};
397
398/* Forward Declaration */
399struct OS_CRIT;
400
406struct OS_SEM : public OS_TASK_DLY_OBJ
407{
408 volatile uint32_t OSSemCnt;
409 volatile uint32_t OSSemUsed;
410
411 private:
412 bool Claim();
413
414 public:
422 inline OS_SEM(int32_t cnt = 0) : OS_TASK_DLY_OBJ() { Init(cnt); }
423
433 uint8_t Init(int32_t cnt = 0);
434
444 uint8_t Post();
445
455 inline uint8_t Pend(uint32_t timeoutTicks = WAIT_FOREVER){TickTimeout tt(timeoutTicks); return Pend(tt);};
456
466 inline uint8_t PendUntil(uint32_t timeout_time){TickTimeout tt(0); tt.SetUntil(timeout_time); return Pend(tt);};
467
477 uint8_t Pend(TickTimeout &t);
478
488 uint8_t PendNoWait();
489
499 inline uint32_t Avail() { uint32_t v; USER_ENTER_CRITICAL(); v=OSSemCnt-OSSemUsed; USER_EXIT_CRITICAL(); return v;};
500
501} __attribute__((packed));
502
517struct OS_MBOX : public OS_TASK_DLY_OBJ
518{
519 void *OSMboxMsg;
520 bool OSMboxDataAvail;
521
522 bool Claim(void *&Result);
523
524 public:
530 inline OS_MBOX() : OS_TASK_DLY_OBJ() { Init(); }
531
539 inline OS_MBOX(void *msg) : OS_TASK_DLY_OBJ() { Init(msg); }
540
550 uint8_t Init(void *msg = NULL);
551
562 uint8_t Post(void *msg);
563
576 inline void *Pend(uint32_t timeoutTicks, uint8_t &result){TickTimeout tt(timeoutTicks); return Pend(tt,result);};
577
590 void *Pend(TickTimeout &t, uint8_t &result);
591
602 inline void *Pend(uint32_t timeoutTicks = WAIT_FOREVER)
603 {
604 uint8_t unused;
605 return Pend(timeoutTicks, unused);
606 };
607
620 inline void *PendUntil(uint32_t timeoutTime, uint8_t &result){TickTimeout tt(0); tt.SetUntil(timeoutTime); return Pend(tt,result);};
621
633 void *PendNoWait(uint8_t &result);
634
643 inline void *PendNoWait()
644 {
645 uint8_t unused;
646 return PendNoWait(unused);
647 };
648};
649
650
651template<typename T>
652class TEMPL_MBOX
653{
654 protected:
655 OS_MBOX m_mbox;
656
657 public:
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); }
661
662 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) { return static_cast<T *>(m_mbox.Pend(timeoutTicks, result)); };
663
664 inline T *PendNoWait(uint8_t &result) { return static_cast<T *>(m_mbox.PendNoWait(result)); };
665
666 inline T *Pend(uint32_t timeoutTicks = WAIT_FOREVER) { return static_cast<T *>(m_mbox.Pend(timeoutTicks)); };
667
668 inline T *PendNoWait() { return static_cast<T *>(m_mbox.PendNoWait()); };
669};
670
671
692struct OS_Q : public OS_TASK_DLY_OBJ
693{
694 void **OSQStart;
695 void **OSQEnd;
696 void **OSQIn;
697 void **OSQOut;
698 uint8_t OSQSize;
699 uint8_t OSQEntries;
700
701 bool Claim(void *&Result);
702
703 public:
719 inline OS_Q(void **pQueueStorage, uint8_t size) : OS_TASK_DLY_OBJ() { Init(pQueueStorage, size); }
720
729 uint8_t Init(void **pQueueStorage, uint8_t size);
730
741 uint8_t Post(void *pItem);
742
753 uint8_t PostFirst(void *pItem);
754
767 uint8_t PostUnique(void *pItem);
768
781 uint8_t PostUniqueFirst(void *msg);
782
795 inline void *Pend(uint32_t timeoutTicks, uint8_t &result){TickTimeout tt(timeoutTicks); return Pend(tt,result);};
796
809 void *Pend(TickTimeout &t, uint8_t &result);
810
821 inline void *Pend(uint32_t timeoutTicks = WAIT_FOREVER)
822 {
823 uint8_t unused;
824 return Pend(timeoutTicks, unused);
825 };
826
839 inline void *PendUntil(uint32_t timeoutTime, uint8_t &result){TickTimeout tt(0); tt.SetUntil(timeoutTime); return Pend(tt,result);};
840
852 void *PendNoWait(uint8_t &result);
853
862 inline void *PendNoWait()
863 {
864 uint8_t unused;
865 return PendNoWait(unused);
866 };
867};
868
873template<typename T>
875{
876 protected:
877 OS_Q m_q;
878
879 public:
880 TEMPL_Q() {}
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); };
888
889 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) { return static_cast<T *>(m_q.Pend(timeoutTicks, result)); };
890
891 inline T *Pend(uint32_t timeoutTicks = WAIT_FOREVER) { return static_cast<T *>(m_q.Pend(timeoutTicks)); };
892
893 inline T *PendNoWait() { return static_cast<T *>(m_q.PendNoWait()); };
894
895 inline T *PendNoWait(uint8_t &result) { return static_cast<T *>(m_q.PendNoWait(result)); };
896};
897
904typedef struct os_fifo_el
905{
911 union
912 {
914 puint8_t pAsBytePtr;
915 };
917
927struct OS_FIFO : public OS_TASK_DLY_OBJ
928{
929 OS_FIFO_EL *pHead;
930 OS_FIFO_EL *pTail;
931
932 bool Claim(volatile OS_FIFO_EL *&pToRet);
933
934 public:
940 inline OS_FIFO() : OS_TASK_DLY_OBJ() { Init(); }
941
949 uint8_t Init();
950
962 uint8_t Post(OS_FIFO_EL *pToPost);
963
975 uint8_t PostFirst(OS_FIFO_EL *pToPost);
976
989 inline OS_FIFO_EL *Pend(uint32_t timeoutTicks, uint8_t &result){TickTimeout tt(timeoutTicks); return Pend(tt,result);};
990
1003 OS_FIFO_EL *Pend(TickTimeout &t, uint8_t &result);
1004
1015 inline OS_FIFO_EL *Pend(uint32_t timeoutTicks = WAIT_FOREVER)
1016 {
1017 uint8_t unused;
1018 return Pend(timeoutTicks, unused);
1019 };
1020
1033 inline OS_FIFO_EL *PendUntil(uint32_t timeoutTime, uint8_t &result){TickTimeout tt(0); tt.SetUntil(timeoutTime); return Pend(tt,result);};
1034
1046 OS_FIFO_EL *PendNoWait(uint8_t &result);
1047
1048
1058 {
1059 uint8_t unused;
1060 return PendNoWait(unused);
1061 };
1062};
1063
1064
1065
1066template<typename T>
1067struct TEMPL_FIFO
1068{
1069 protected:
1070 OS_FIFO m_fifo;
1071
1072 public:
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); }
1076 uint8_t PostFirst(T *item) { return m_fifo.PostFirst((OS_FIFO_EL *)item); };
1077
1078 inline T *Pend(uint32_t timeoutTicks, uint8_t &result) { return static_cast<T *>(m_fifo.Pend(timeoutTicks, result)); };
1079
1080 inline T *Pend(uint32_t timeoutTicks = WAIT_FOREVER) { return static_cast<T *>(m_fifo.Pend(timeoutTicks)); };
1081
1082 inline T *PendNoWait() { return static_cast<T *>(m_fifo.PendNoWait()); };
1083
1084 inline T *PendNoWait(uint8_t &result) { return static_cast<T *>(m_fifo.PendNoWait(result)); };
1085
1086 inline OS_FIFO *GetRawFIFO() { return &m_fifo; }
1087};
1088
1089/*
1090 * Critical Section DATA STRUCTURES
1091 *
1092 * Added by PTB 5/09/99
1093 * Modified by DEC 3/21/16
1094 */
1095
1096class BufferCriticalLock;
1098class OS_RRCB;
1099
1105struct OS_CRIT : public OS_TASK_DLY_OBJ
1106{
1107 OS_TCB *OSCritOwnerTCB;
1108 uint32_t OSCritDepthCount;
1109
1110 bool Claim();
1111 OS_TCB *GetOwner() { return (OS_TCB*)(((uint32_t)OSCritOwnerTCB)&~0x1ul); }
1112 void SetOwner(OS_TCB *newOwner)
1113 {
1114 OSCritOwnerTCB =
1115 (OS_TCB*) (((uint32_t)newOwner) | (((uint32_t)OSCritOwnerTCB)&0x1));
1116 }
1117
1118 public:
1124 OS_CRIT() { Init(); }
1125
1133 uint8_t Init();
1134
1150 uint8_t LockAndEnter(uint32_t timeoutTicks = WAIT_FOREVER);
1151
1166 uint8_t Enter(TickTimeout &t);
1167
1182 inline uint8_t Enter(uint32_t timeoutTicks = WAIT_FOREVER) {TickTimeout tt(timeoutTicks); return Enter(tt);};
1183
1195 uint8_t EnterNoWait();
1196
1208 uint8_t Leave();
1209
1221
1222 friend class BufferCriticalLock;
1223 friend class fifo_buffer_storage;
1224 friend class OS_RRCB;
1225
1231 bool UsedFromISR() { return (((uint32_t)OSCritOwnerTCB)&0x1ul); }
1232
1240 void SetUseFromISR(bool enableFromISR)
1241 {
1242 if (enableFromISR)
1243 {
1244 OSCritOwnerTCB = (OS_TCB*)(((uint32_t)OSCritOwnerTCB)|0x1ul);
1245 }
1246 else
1247 {
1248 OSCritOwnerTCB = (OS_TCB*)(((uint32_t)OSCritOwnerTCB)&~0x1ul);
1249 }
1250 }
1251
1255 bool OwnedByCurTask();
1256
1262 uint32_t CurDepth() { return OSCritDepthCount; }
1263
1267 friend void ForceReboot(bool fromIRQ);
1268} __attribute__((packed));
1269
1270
1271
1272struct OS_FLAGS_WAIT;
1273
1285{
1286 protected:
1287 vuint32_t m_current_flags;
1288 void *m_pWaitinglist;
1289 void TestFlags();
1290 void AddOFW(OS_FLAGS_WAIT *ofw);
1291 void RemoveOFW(OS_FLAGS_WAIT *ofw);
1292
1293 public:
1300
1306 void Init();
1307
1315 void Set(uint32_t bits_to_set);
1316
1324 void Clear(uint32_t bits_to_clr);
1325
1326
1334 void Write(uint32_t bits_to_force);
1335
1343 uint32_t State();
1344
1359 uint8_t PendAny(uint32_t bit_mask, uint16_t timeout = WAIT_FOREVER){TickTimeout tt(timeout); return PendAny(bit_mask,tt);}
1360
1375 uint8_t PendAny(uint32_t bit_mask, TickTimeout & timeout);
1376
1377
1389 uint8_t PendAnyUntil(uint32_t bit_mask, uint32_t end_time){TickTimeout tt(0); tt.SetUntil(end_time); return PendAny(bit_mask,tt);}
1390
1391
1401 uint8_t PendAnyNoWait(uint32_t bit_mask);
1402
1416 uint8_t PendAll(uint32_t bit_mask, uint16_t timeout = WAIT_FOREVER){TickTimeout tt(timeout); return PendAll(bit_mask,tt);}
1417
1431 uint8_t PendAll(uint32_t bit_mask,TickTimeout & timeout);
1432
1444 uint8_t PendAllUntil(uint32_t bit_mask, uint32_t end_time){TickTimeout tt(0); tt.SetUntil(end_time); return PendAll(bit_mask,tt);}
1445
1446
1457 uint8_t PendAllNoWait(uint32_t bit_mask);
1458
1459};
1460
1461
1462/* Create and initialize an OS flags object
1463This function must be called before you use an OS_FLAGS object.
1464*/
1465[[deprecated]] inline void OSFlagCreate(OS_FLAGS *pf)
1466{
1467 pf->Init();
1468};
1469
1480[[deprecated]] inline void OSFlagSet(OS_FLAGS *flags, uint32_t bits_to_set)
1481{
1482 flags->Set(bits_to_set);
1483};
1484
1495[[deprecated]] inline void OSFlagClear(OS_FLAGS *flags, uint32_t bits_to_clr)
1496{
1497 flags->Clear(bits_to_clr);
1498};
1499
1514[[deprecated]] inline uint8_t OSFlagPendAny(OS_FLAGS *flags, uint32_t bit_mask, uint16_t timeout)
1515{
1516 return flags->PendAny(bit_mask, timeout);
1517};
1518
1532[[deprecated]] inline uint8_t OSFlagPendAnyNoWait(OS_FLAGS *flags, uint32_t bit_mask)
1533{
1534 return flags->PendAnyNoWait(bit_mask);
1535};
1536
1551[[deprecated]] inline uint8_t OSFlagPendAll(OS_FLAGS *flags, uint32_t bit_mask, uint16_t timeout)
1552{
1553 return flags->PendAll(bit_mask, timeout);
1554};
1555
1569[[deprecated]] inline uint8_t OSFlagPendAllNoWait(OS_FLAGS *flags, uint32_t bit_mask)
1570{
1571 return flags->PendAllNoWait(bit_mask);
1572};
1573
1585[[deprecated]] inline uint32_t OSFlagState(OS_FLAGS *flags)
1586{
1587 return flags->State();
1588};
1589
1590/*
1591 ***********************************************************
1592 * NBRTOS GLOBAL VARIABLES
1593 ***********************************************************
1594 */
1595// Pointers to each of the OS_TCB structure sorted by priority
1596extern volatile OS_TCB *OSTCBPrioTbl[OS_MAX_PRIOS];
1597
1598// taks bits for what tasks are ready to run
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;
1603#endif
1604
1605extern OS_TCB OSTCBTbl[OS_MAX_TASKS]; // All the possible TCB's
1606
1607extern OS_TCB *pOSActiveTCBList; // Linked list of activ TCB's
1608
1609// One of the following two variables wsill go away....
1610extern volatile uint32_t nPrioOfCurTask; // Current task priority number
1611extern volatile uint32_t nPrioOfHighReady; // highest task ready to run
1612extern volatile OS_TCB *OSTCBCur;
1613extern volatile OS_TCB *OSTCBHighRdy;
1614
1615extern OS_TCB *pOSTCBFreeList; // List of unused TCB's
1616
1617extern volatile uint32_t OSIntNesting;
1618extern volatile uint32_t OSLockNesting;
1619extern volatile uint32_t OSISRLevel32;
1620
1621extern volatile bool OSRunning;
1622
1623// So non-recompilable files can reference the right struct size
1624extern unsigned long OSTcbStructSize;
1625
1626#ifdef NBRTOS_TASK_LOG
1627extern void (*pTaskLogger)(uint8_t nextPrio);
1628#endif
1629/*
1630Removed
1631 extern volatile BOOLEAN OSShowTasksOnLeds;
1632*/
1633
1634/*
1635***********************************************************
1636* NBRTOS FUNCTION PROTOTYPES
1637***********************************************************
1638*/
1639void OSInit(uint8_t maxtasks);
1640void OSStart(void);
1641void OSCreateIdleTask();
1642
1715uint8_t OSTaskCreatewName(void (*task)(void *dptr), // Function to call
1716 void *data, // Data to pass as a parameter
1717 void *pstktop, // Stack top
1718 void *pstkbot, // Stack bottom
1719 uint8_t prio, // current priority
1720 const char *name, // task name
1721 OS_TCB **pRetHandle = NULL // ReturnPointer to task handle
1722);
1723
1763#define OSSimpleTaskCreatewName(x, p, n) \
1764 [&]() { \
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); \
1767 }()
1768
1785#define OSSimpleTaskCreatewNameSRAM(x, p, n) \
1786 [&]() { \
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); \
1789 }()
1790
1791
1792/* Helper macro*/
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)
1794
1810#define OSSimpleTaskCreateLambda(p,n,f) LambdaTask2(p,n,[]( void * pv)f,__COUNTER__)
1811
1812
1832void OSTimeWaitUntil(uint32_t systemTickValue);
1833
1846inline void OSTimeDly(uint32_t to_count)
1847{
1848 uint32_t to_when = to_count + TimeTick;
1849 if (!to_when) to_when++;
1850 OSTimeWaitUntil(to_when);
1851};
1852
1853// void OSIntEnter( void );
1854
1855extern "C"
1856{
1857 void OSIntExit(void);
1858 void OSCtxSw(void);
1859 void OSTickISR(void);
1860 void OSStartHighRdy(void);
1861 void OSSetupVBR(void);
1862 void OSSched(void);
1863 void OSTimeTick(void);
1864
1875 void OSTaskDelete(void);
1876}
1877
1878OS_TCB *OSTCBGetFree(void);
1879
1898uint8_t OSChangePrio(uint32_t newp);
1899
1906void OSSetName(const char *cp);
1907
1921void OSLock(void);
1922
1930void OSUnlock(void);
1931
1946[[deprecated]] inline uint8_t OSSemInit(OS_SEM *psem, long value)
1947{
1948 return (psem != nullptr) ? psem->Init(value) : OS_CRIT_ERR;
1949}
1950
1964[[deprecated]] inline uint8_t OSSemPost(OS_SEM *psem)
1965{
1966 return psem->Post();
1967}
1968
1983[[deprecated]] inline uint8_t OSSemPend(OS_SEM *psem, uint16_t timeout)
1984{
1985 return psem->Pend(timeout);
1986}
1987
2000[[deprecated]] inline uint8_t OSSemPendNoWait(OS_SEM *psem)
2001{
2002 return psem->PendNoWait();
2003}
2004
2018[[deprecated]] inline uint8_t OSMboxInit(OS_MBOX *pmbox, void *msg)
2019{
2020 return (pmbox != nullptr) ? pmbox->Init(msg) : OS_CRIT_ERR;
2021}
2022
2036[[deprecated]] inline uint8_t OSMboxPost(OS_MBOX *pmbox, void *msg)
2037{
2038 return pmbox->Post(msg);
2039}
2040
2052[[deprecated]] inline void *OSMboxPend(OS_MBOX *pmbox, uint16_t timeout, uint8_t *err)
2053{
2054 return pmbox->Pend(timeout, *err);
2055}
2056
2067[[deprecated]] inline void *OSMboxPendNoWait(OS_MBOX *pmbox, uint8_t *err)
2068{
2069 return pmbox->PendNoWait(*err);
2070}
2071
2086[[deprecated]] inline uint8_t OSQInit(OS_Q *pq, void **start, uint8_t size)
2087{
2088 return (pq != nullptr) ? pq->Init(start, size) : OS_CRIT_ERR;
2089}
2090
2104[[deprecated]] inline uint8_t OSQPost(OS_Q *pq, void *msg)
2105{
2106 return pq->Post(msg);
2107}
2108
2122[[deprecated]] inline uint8_t OSQPostFirst(OS_Q *pq, void *msg)
2123{
2124 return pq->PostFirst(msg);
2125}
2126
2142[[deprecated]] inline uint8_t OSQPostUnique(OS_Q *pq, void *msg)
2143{
2144 return pq->PostUnique(msg);
2145}
2146
2162[[deprecated]] inline uint8_t OSQPostUniqueFirst(OS_Q *pq, void *msg)
2163{
2164 return pq->PostUniqueFirst(msg);
2165}
2166
2178[[deprecated]] inline void *OSQPend(OS_Q *pq, uint16_t timeout, uint8_t *err)
2179{
2180 return pq->Pend(timeout, *err);
2181}
2182
2193[[deprecated]] inline void *OSQPendNoWait(OS_Q *pq, uint8_t *err)
2194{
2195 return pq->PendNoWait(*err);
2196}
2197
2210[[deprecated]] inline uint8_t OSFifoInit(OS_FIFO *pFifo)
2211{
2212 return (pFifo != nullptr) ? pFifo->Init() : OS_CRIT_ERR;
2213}
2214
2227[[deprecated]] inline uint8_t OSFifoPost(OS_FIFO *pFifo, OS_FIFO_EL *pToPost)
2228{
2229 return pFifo->Post(pToPost);
2230}
2243[[deprecated]] inline uint8_t OSFifoPostFirst(OS_FIFO *pFifo, OS_FIFO_EL *pToPost)
2244{
2245 return pFifo->PostFirst(pToPost);
2246};
2247
2258[[deprecated]] inline OS_FIFO_EL *OSFifoPend(OS_FIFO *pFifo, uint16_t timeout)
2259{
2260 return pFifo->Pend(timeout);
2261};
2262
2272[[deprecated]] inline OS_FIFO_EL *OSFifoPendNoWait(OS_FIFO *pFifo)
2273{
2274 return pFifo->PendNoWait();
2275 ;
2276}
2277
2289[[deprecated]] inline uint8_t OSCritInit(OS_CRIT *pCrit)
2290{
2291 return pCrit->Init();
2292}
2293[[deprecated]] inline uint8_t OSCritLockAndEnter(OS_CRIT *pCrit, uint16_t timeout)
2294{
2295 return pCrit->LockAndEnter(timeout);
2296}
2297
2311[[deprecated]] inline uint8_t OSCritEnter(OS_CRIT *pCrit, uint16_t timeout)
2312{
2313 return pCrit->Enter(timeout);
2314}
2315
2328[[deprecated]] inline uint8_t OSCritEnterNoWait(OS_CRIT *pCrit)
2329{
2330 return pCrit->EnterNoWait();
2331}
2332
2345[[deprecated]] inline uint8_t OSCritLeave(OS_CRIT *pCrit)
2346{
2347 return pCrit->Leave();
2348}
2349[[deprecated]] inline uint8_t OSCritLeaveAndUnlock(OS_CRIT *pCrit)
2350{
2351 return pCrit->LeaveAndUnlock();
2352}
2353
2359uint8_t OSTaskID(void);
2360
2365enum class OSNextPrio {
2366 Maximum = -2,
2367 Above = -1,
2368 Below = 0,
2369 Next = Below,
2370 Minimum = 1
2371};
2372
2381int OSGetNextPrio(OSNextPrio where=OSNextPrio::Below, int startingPrio = -1);
2382
2386const char *OSTaskName();
2387
2388void OSChangeTaskWhen(uint16_t task_prio, uint32_t to_when);
2389
2400inline void OSChangeTaskDly(uint16_t task_prio, uint32_t to_count)
2401{
2402 uint32_t to_when = to_count + TimeTick;
2403 if (!to_when) to_when++;
2404 OSChangeTaskWhen(task_prio, to_when);
2405}
2406
2415OS_TCB * OSGetTaskBlock(uint16_t task_prio);
2416
2428uint8_t OSTaskJoin(OS_TCB *pTask, uint32_t timeoutDly = 0);
2429
2433void OSDumpStack(void);
2434
2435#if (defined NBRTOS_STACKOVERFLOW) || (defined NBRTOS_STACKUNDERFLOW)
2436void EnableOSStackProtector();
2437extern "C" void OSStackProtectCtxSw(); // ASM task switcher
2438extern "C" void OSStackProtectIntCtxSw(); // ASM task switcher
2439extern "C" void OSStackProtector(); // extern because must be called from ASM
2440#endif
2441
2442#ifdef NBRTOS_STACKCHECK
2452
2461void OSDumpTasks(void);
2462
2471void OSStartTaskDumper(uint8_t prio, uint32_t reportInterval);
2472#endif
2473
2474#ifdef NBRTOS_TASKLIST
2480void ShowTaskList(void);
2481#endif
2482
2483#ifdef NBRTOS_TIME
2484uint32_t GetCurrentTaskTime(uint32_t *const TotalTicks);
2485void ShowTaskTimes(void);
2486void ClearTaskTimes(void);
2487#endif
2488
2501{
2502 public:
2507
2512} __attribute__((packed));
2513
2524{
2525 OS_CRIT *pcrit;
2526
2527 public:
2535 {
2536 pcrit = &ocrit;
2537 ocrit.Enter(0);
2538 };
2539
2548 OSCriticalSectionObj(OS_CRIT &ocrit, bool NoWait, TickTimeout &timeout)
2549 {
2550 pcrit = &ocrit;
2551 if (NoWait)
2552 ocrit.EnterNoWait();
2553 else
2554 ocrit.Enter(timeout);
2555 };
2556
2562} __attribute__((packed));
2563
2575{
2576 OS_CRIT *pcrit;
2577
2578 public:
2585 OSLockAndCritObj(OS_CRIT &ocrit) : pcrit(&ocrit) { pcrit->LockAndEnter(0); }
2586
2592};
2593
2606{
2607 OS_CRIT *pcrit;
2608
2609 public:
2616 OSSpinCrit(OS_CRIT &ocrit) : pcrit(&ocrit)
2617 {
2618 while (pcrit->EnterNoWait() == OS_TIMEOUT) {}
2619 }
2620
2625 ~OSSpinCrit() { pcrit->Leave(); }
2626};
2627
2628
2633{
2634 public:
2635 USERCritObj() { USER_ENTER_CRITICAL(); }
2636 ~USERCritObj() { USER_EXIT_CRITICAL(); }
2637};
2638
2639
2640
2648{
2649 return OSCritOwnerTCB == OSTCBCur;
2650}
2651
2664{
2665 static NBRtosInitObj * pHead;
2666 static bool bAlreadInited;
2667 NBRtosInitObj *pNext;
2668
2669 protected:
2670 inline bool WasInitDone() {return bAlreadInited; }
2671 NBRtosInitObj();
2673
2674 public:
2678 virtual void Notify()=0;
2679 static void InitWholeSet(); //Used internally
2680};
2681
2682
2683#endif
2684
2685
2686
2687
2688 // groupNBRTOS
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.
Definition nbrtos.h:928
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