BRTOS  1.90
Brazilian Real-Time Operating System
 All Data Structures Files Functions Variables Macros
BRTOS.h
Go to the documentation of this file.
1 
9 /*********************************************************************************************************
10 * BRTOS
11 * Brazilian Real-Time Operating System
12 * Acronymous of Basic Real-Time Operating System
13 *
14 *
15 * Open Source RTOS under MIT License
16 *
17 *
18 *
19 * BRTOS Kernel Header
20 *
21 *
22 * Author: Gustavo W. Denardin , Authors: Carlos H. Barriquelo e Gustavo W. Denardin
23 * Revision: 1.0 , Revision: 1.63
24 * Date: 20/03/2009 , Date: 15/12/2010
25 *
26 * Authors: Carlos H. Barriquelo , Authors: Gustavo W. Denardin
27 * Revision: 1.64 , Revision: 1.70
28 * Date: 22/02/2011 , Date: 06/06/2012
29 *
30 * Author: Gustavo W. Denardin , Authors: Gustavo W. Denardin
31 * Revision: 1.75 , Revision: 1.76 , Revision: 1.78
32 * Date: 24/08/2012 , Date: 11/10/2012 , Date: 06/03/2014
33 *
34 * Authors: Gustavo Weber Denardin
35 * Revision: 1.80 , Revision: 1.90
36 * Date: 11/11/2015 , Date: 12/11/2015
37 *
38 * Author: Carlos H. Barriquello
39 * Revision: 1.91
40 * Date: 04/12/2015
41 *
42 * Author: Gustavo Weber Denardin
43 * Revision: 2.00
44 * Date: 18/05/2016
45 *
46 *********************************************************************************************************/
47 
48 #ifndef OS_BRTOS_H
49 #define OS_BRTOS_H
50 
51 #include "OS_types.h"
52 #include "HAL.h"
53 #include "OSTime.h"
54 #include "BRTOSConfig.h"
55 
56 
66 
67 
68 // Brtos version
69 #define BRTOS_VERSION "BRTOS Ver. 2.00"
70 
72 #ifndef FALSE
73 #define FALSE 0
74 #endif
75 
76 #ifndef TRUE
77 #define TRUE 1
78 #endif
79 
80 #ifndef NULL
81 #define NULL (void*)0
82 #endif
83 
84 #ifndef READY_LIST_VAR
85 #define READY_LIST_VAR
86 #endif
87 
88 #define BRTOS_BIG_ENDIAN (0)
89 #define BRTOS_LITTLE_ENDIAN (1)
90 
91 #ifndef BRTOS_TH
92 #define BRTOS_TH OS_CPU_TYPE
93 #endif
94 
95 #if (!defined(ostick_t) && !defined(osdtick_t))
96 #define ostick_t uint16_t
97 #define osdtick_t uint32_t
98 #endif
99 #define sizeof_ostick_t sizeof(ostick_t)
100 
101 
103 #define READY (uint8_t)0
104 #define SUSPENDED (uint8_t)1
105 #define BLOCKED (uint8_t)2
106 #define MUTEX_PRIO (uint8_t)0xFE
107 #define EMPTY_PRIO (uint8_t)0xFF
108 
109 
111 #if (ostick_t == uint64_t)
112 #define MAX_TIMER 0xffffffffffffffffULL
113 #elif (ostick_t == uint32_t)
114 #define MAX_TIMER 0xffffffff
115 #else
116 #define MAX_TIMER 0xffff
117 #endif
118 #define NO_TIMEOUT (ostick_t)(MAX_TIMER - 1)
119 #define EXIT_BY_TIMEOUT (ostick_t)(MAX_TIMER - 2)
120 #define TICK_COUNT_OVERFLOW (ostick_t)(MAX_TIMER - 3)
121 #define TickCountOverFlow TICK_COUNT_OVERFLOW
122 
123 #define OK (uint8_t)0
125 #define NO_MEMORY (uint8_t)1
126 #define STACK_SIZE_TOO_SMALL (uint8_t)2
127 #define END_OF_AVAILABLE_PRIORITIES (uint8_t)3
128 #define BUSY_PRIORITY (uint8_t)4
129 #define INVALID_TIME (uint8_t)5
130 #define TIMEOUT (uint8_t)6
131 #define CANNOT_ASSIGN_IDLE_TASK_PRIO (uint8_t)7
132 #define NOT_VALID_TASK (uint8_t)8
133 #define NO_TASK_DELAY (uint8_t)9
134 #define END_OF_AVAILABLE_TCB (uint8_t)10
135 #define EXIT_BY_NO_ENTRY_AVAILABLE (uint8_t)11
136 #define TASK_WAITING_EVENT (uint8_t)12
137 #define CANNOT_UNINSTALL_IDLE_TASK (uint8_t)13
138 #define EXIT_BY_NO_RESOURCE_AVAILABLE (uint8_t)14
139 
140 
145 
146 
147 // Return defines to events control blocks
148 #define ALLOC_EVENT_OK (uint8_t)0
149 #define NO_AVAILABLE_EVENT (uint8_t)1
150 #define NO_AVAILABLE_MEMORY (uint8_t)2
151 #define INVALID_PARAMETERS (uint8_t)3
152 #define IRQ_PEND_ERR (uint8_t)4
153 #define ERR_SEM_OVF (uint8_t)5
154 #define ERR_MUTEX_OVF (uint8_t)6
155 #define ERR_EVENT_NO_CREATED (uint8_t)7
156 #define NULL_EVENT_POINTER (uint8_t)8
157 #define ERR_EVENT_OWNER (uint8_t)9
158 #define DELETE_EVENT_OK (uint8_t)10
159 #define AVAILABLE_RESOURCE (uint8_t)11
160 #define BUSY_RESOURCE (uint8_t)12
161 #define AVAILABLE_MESSAGE (uint8_t)13
162 #define NO_MESSAGE (uint8_t)14
163 
164 
169 
170 
176 
177 // Enable Queue Structures
178 #define READ_BUFFER_OK 0
179 #define WRITE_BUFFER_OK 0
180 #define BUFFER_UNDERRUN 1
181 #define CLEAN_BUFFER_OK 2
182 #define NO_ENTRY_AVAILABLE 3
183 
184 
189 
190 
192 #define DELAY 0
193 #define SEMAPHORE 1
194 #define MAILBOX 2
195 #define QUEUE 3
196 #define MUTEX 4
197 
198 
199 
201 
202 #if (NUMBER_OF_PRIORITIES > 16)
203  #define configMAX_TASK_INSTALL 32
204  #define configMAX_TASK_PRIORITY 31
205  typedef uint32_t PriorityType;
206 #else
207  #if (NUMBER_OF_PRIORITIES > 8)
208  #define configMAX_TASK_INSTALL 16
209  #define configMAX_TASK_PRIORITY 15
210  typedef uint16_t PriorityType;
211  #else
212  #define configMAX_TASK_INSTALL 8
213  #define configMAX_TASK_PRIORITY 7
214  typedef uint8_t PriorityType;
215  #endif
216 #endif
217 
222 
223 
224 
225 
226 
232 
238 struct Context
239 {
240  const CHAR8 * TaskName;
241  #if SP_SIZE == 32
242  uint32_t StackPoint;
243  uint32_t StackInit;
244  #else
245  uint16_t StackPoint;
246  uint16_t StackInit;
247  #endif
248 #if (BRTOS_DYNAMIC_TASKS_ENABLED == 1)
249  uint16_t StackSize;
250 #endif
251 #if (COMPUTES_TASK_LOAD == 1)
252  uint32_t Runtime;
253 #endif
254  ostick_t TimeToWait;
255  #if (VERBOSE == 1)
256  uint8_t State;
257  uint8_t Blocked;
258  uint8_t SuspendedType;
259  #endif
260  uint8_t Priority;
261  struct Context *Next;
262  struct Context *Previous;
263 };
264 
265 typedef struct Context ContextType;
266 
271 
272 
273 
274 
275 
281 
286 typedef struct {
288  uint8_t OSEventCount;
289  uint8_t OSEventWait;
290 #if (BRTOS_BINARY_SEM_EN == 1)
291  uint8_t Binary;
292 #endif
293  PriorityType OSEventWaitList;
294 } BRTOS_Sem;
295 
300 
301 
302 
303 
304 
310 
315 typedef struct {
317  uint8_t OSEventState;
318  uint8_t OSEventOwner;
319  uint8_t OSMaxPriority;
321  uint8_t OSEventWait;
322  PriorityType OSEventWaitList;
323 } BRTOS_Mutex;
324 
329 
330 
331 
332 
333 
339 
344 typedef struct {
346  uint8_t OSEventWait;
347  uint8_t OSEventState;
348  PriorityType OSEventWaitList;
350 } BRTOS_Mbox;
351 
356 
357 
358 
359 
360 
366 
371 typedef struct {
373  uint8_t OSEventCount;
374  uint8_t OSEventWait;
376  PriorityType OSEventWaitList;
377 } BRTOS_Queue;
378 
383 
384 
385 
386 
392 
397 typedef struct
398 {
399  uint8_t *OSQStart;
400  uint8_t *OSQEnd;
401  uint8_t *OSQIn;
402  uint8_t *OSQOut;
403  uint16_t OSQSize;
404  uint16_t OSQEntries;
405 } OS_QUEUE;
406 
411 
412 
413 
414 
415 
421 
426 typedef struct
427 {
428  uint8_t *OSQStart;
429  uint8_t *OSQEnd;
430  uint8_t *OSQIn;
431  uint8_t *OSQOut;
432  uint16_t OSQTSize;
433  uint16_t OSQLength;
434  uint16_t OSQEntries;
435 } OS_DQUEUE;
436 
441 
442 
443 
444 
445 
451 
456 typedef struct
457 {
458  uint16_t *OSQStart;
459  uint16_t *OSQEnd;
460  uint16_t *OSQIn;
461  uint16_t *OSQOut;
462  uint16_t OSQSize;
463  uint16_t OSQEntries;
464 } OS_QUEUE_16;
465 
470 
471 
472 
473 
479 
484 typedef struct
485 {
486  uint32_t *OSQStart;
487  uint32_t *OSQEnd;
488  uint32_t *OSQIn;
489  uint32_t *OSQOut;
490  uint16_t OSQSize;
491  uint16_t OSQEntries;
492 } OS_QUEUE_32;
493 
498 
499 
500 
501 
502 
508 
509 /*****************************************************************************************/
523 #if (TASK_WITH_PARAMETERS == 1)
524  uint8_t OSInstallTask(void(*FctPtr)(void*),const CHAR8 *TaskName, uint16_t USER_STACKED_BYTES,uint8_t iPriority, void *parameters, OS_CPU_TYPE *TaskHandle);
525  #define InstallTask OSInstallTask
526 #else
527  uint8_t OSInstallTask(void(*FctPtr)(void),const CHAR8 *TaskName, uint16_t USER_STACKED_BYTES,uint8_t iPriority, OS_CPU_TYPE *TaskHandle);
528  #define InstallTask OSInstallTask
529 #endif
530 
531 /*****************************************************************************************/
539 uint8_t OSUninstallTask(BRTOS_TH TaskHandle, OS_CPU_TYPE safety_off);
540 #define UninstallTask OSUninstallTask
541 
542 /*****************************************************************************************/
547 #if (TASK_WITH_PARAMETERS == 1)
548  void Idle(void *parameters);
549 #else
550  void Idle(void);
551 #endif
552 
553 /*****************************************************************************************/
559 #if (TIMER_HOOK_EN == 1)
560 void BRTOS_TimerHook(void);
561 #endif
562 
563 /*****************************************************************************************/
568 #if (IDLE_HOOK_EN == 1)
569 void IdleHook(void);
570 #endif
571 
572 /**************************************************************************/
576 void OS_TICK_HANDLER(void);
577 
578 /*****************************************************************************************/
585 uint8_t BRTOSStart(void);
586 
587 /*****************************************************************************************/
593 BRTOS_TH OSGetCurrentTaskHandle(void);
594 
595 /*****************************************************************************************/
601 BRTOS_TH OSGetTaskPriority(BRTOS_TH task_handle);
602 
603 /*****************************************************************************************/
612 uint8_t OSDelayTask(ostick_t time_wait);
613 #define DelayTask OSDelayTask
614 
615 /*****************************************************************************************/
627 uint8_t OSDelayTaskHMSM(uint8_t hours, uint8_t minutes, uint8_t seconds, uint16_t miliseconds);
628 #define DelayTaskHMSM OSDelayTaskHMSM
629 
630 /*****************************************************************************************/
636 ostick_t OSGetTickCount(void);
637 
638 /*****************************************************************************************/
644 ostick_t OSGetCount(void);
645 
646 /*****************************************************************************************/
651 #if (TICKLESS == 1)
652 void OSIncCounter(ostick_t inc);
653 #else
654 void OSIncCounter(void);
655 #endif
656 
657 /*****************************************************************************************/
663 void PreInstallTasks(void);
664 
665 /*****************************************************************************************/
675 uint8_t OSBlockPriority(uint8_t iPriority);
676 #define BlockPriority OSBlockPriority
677 
678 /*****************************************************************************************/
688 uint8_t OSUnBlockPriority(uint8_t iPriority);
689 #define UnBlockPriority OSUnBlockPriority
690 /*****************************************************************************************/
697 uint8_t OSBlockTask(BRTOS_TH iTaskNumber);
698 #define BlockTask OSBlockTask
699 
700 /*****************************************************************************************/
707 uint8_t OSUnBlockTask(BRTOS_TH iTaskNumber);
708 #define UnBlockTask OSUnBlockTask
709 
710 /*****************************************************************************************/
718 uint8_t OSBlockMultipleTask(uint8_t TaskStart, uint8_t TaskNumber);
719 #define BlockMultipleTask OSBlockMultipleTask
720 
721 /*****************************************************************************************/
729 uint8_t OSUnBlockMultipleTask(uint8_t TaskStart, uint8_t TaskNumber);
730 #define UnBlockMultipleTask OSUnBlockMultipleTask
731 
732 /*********************************************************************************/
736 void BRTOSInit(void);
737 #define BRTOS_Init BRTOSInit
738 
739 /*****************************************************************/
743 uint8_t OSSchedule(void);
744 
745 /*****************************************************************/
751 uint8_t SAScheduler(PriorityType ReadyList);
752 
753 
754 
760 
761 #if (BRTOS_SEM_EN == 1)
762  extern BRTOS_Sem BRTOS_Sem_Table[BRTOS_MAX_SEM];
764 #endif
765 
766 #if (BRTOS_MUTEX_EN == 1)
767  extern BRTOS_Mutex BRTOS_Mutex_Table[BRTOS_MAX_MUTEX];
769 #endif
770 
771 #if (BRTOS_MBOX_EN == 1)
772  extern BRTOS_Mbox BRTOS_Mbox_Table[BRTOS_MAX_MBOX];
774 #endif
775 
776 #if (BRTOS_QUEUE_EN == 1)
777  extern BRTOS_Queue BRTOS_Queue_Table[BRTOS_MAX_QUEUE];
779  extern OS_QUEUE BRTOS_OS_QUEUE_Table[BRTOS_MAX_QUEUE];
780 #endif
781 
782 
783 /*****************************************************************************************/
788 void initEvents(void);
789 
790 
791 #if (BRTOS_SEM_EN == 1)
792 
793  /*****************************************************************************************/
802  uint8_t OSSemCreate (uint8_t cnt, BRTOS_Sem **event);
803 
804 #if (BRTOS_BINARY_SEM_EN == 1)
805  /*****************************************************************************************/
814  uint8_t OSSemBinaryCreate(uint8_t bit, BRTOS_Sem **event);
815 #endif
816 
817  /*****************************************************************************************/
824  uint8_t OSSemDelete (BRTOS_Sem **event);
825 
826  /*****************************************************************************************/
838  uint8_t OSSemPend (BRTOS_Sem *pont_event, ostick_t timeout);
839 
840  /*****************************************************************************************/
848  uint8_t OSSemPost(BRTOS_Sem *pont_event);
849 #endif
850 
851 #if (BRTOS_MUTEX_EN == 1)
852  /*****************************************************************************************/
861  uint8_t OSMutexCreate (BRTOS_Mutex **event, uint8_t HigherPriority);
862 
863  /*****************************************************************************************/
870  uint8_t OSMutexDelete (BRTOS_Mutex **event);
871 
872  /*****************************************************************************************/
883  uint8_t OSMutexAcquire(BRTOS_Mutex *pont_event, ostick_t time_wait);
884 
885  /*****************************************************************************************/
895  uint8_t OSMutexRelease(BRTOS_Mutex *pont_event);
896 #endif
897 
898 #if (BRTOS_MBOX_EN == 1)
899 
900  /*****************************************************************************************/
909  uint8_t OSMboxCreate (BRTOS_Mbox **event, void *message);
910 
911  /*****************************************************************************************/
918  uint8_t OSMboxDelete (BRTOS_Mbox **event);
919 
920  /*****************************************************************************************/
933  uint8_t OSMboxPend (BRTOS_Mbox *pont_event, void **Mail, ostick_t timeout);
934 
935  /*****************************************************************************************/
945  uint8_t OSMboxPost(BRTOS_Mbox *pont_event, void *message);
946 #endif
947 
948 
953 
954 
955 
956 
962 
963 #if (BRTOS_QUEUE_EN == 1)
964 
965  /*****************************************************************************************/
974  uint8_t OSQueueCreate(uint16_t size, BRTOS_Queue **event);
975 
976  /*****************************************************************************************/
984  uint8_t OSWQueue(OS_QUEUE *cqueue,uint8_t data);
985 
986  /*****************************************************************************************/
994  uint8_t OSRQueue(OS_QUEUE *cqueue, uint8_t* pdata);
995 
996  /*****************************************************************************************/
1002  uint8_t OSQueueClean(BRTOS_Queue *pont_event);
1003 
1004  /*****************************************************************************************/
1013  uint8_t OSQueuePend (BRTOS_Queue *pont_event, uint8_t* pdata, ostick_t timeout);
1014 
1015  /*****************************************************************************************/
1025  uint8_t OSQueuePost(BRTOS_Queue *pont_event, uint8_t data);
1026 #endif
1027 
1032 
1033 
1034 
1035 
1041 
1042 #if (BRTOS_QUEUE_16_EN == 1)
1043 
1044  /*****************************************************************************************/
1053  uint8_t OSQueue16Create(OS_QUEUE_16 *cqueue, uint16_t size);
1054 
1055  /*****************************************************************************************/
1063  uint8_t OSWQueue16(OS_QUEUE_16 *cqueue,uint16_t data);
1064 
1065  /*****************************************************************************************/
1072  uint8_t OSRQueue16(OS_QUEUE_16 *cqueue, uint16_t *pdata);
1073 
1074  /*****************************************************************************************/
1080  uint8_t OSCleanQueue16(OS_QUEUE_16 *cqueue);
1081 
1082 #endif
1083 
1088 
1089 
1090 
1091 
1097 
1098 #if (BRTOS_QUEUE_32_EN == 1)
1099 
1100  /*****************************************************************************************/
1109  uint8_t OSQueue32Create(OS_QUEUE_32 *cqueue, uint16_t size);
1110 
1111  /*****************************************************************************************/
1119  uint8_t OSWQueue32(OS_QUEUE_32 *cqueue,uint32_t data);
1120 
1121  /*****************************************************************************************/
1128  uint8_t OSRQueue32(OS_QUEUE_32 *cqueue, uint32_t *pdata);
1129 
1130  /*****************************************************************************************/
1136  uint8_t OSCleanQueue32(OS_QUEUE_32 *cqueue);
1137 
1138 #endif
1139 
1144 
1145 
1146 
1147 
1148 
1149 #if (BRTOS_DYNAMIC_QUEUE_ENABLED == 1)
1150 
1151  /*****************************************************************************************/
1163  uint8_t OSDQueueCreate(uint16_t queue_lenght, OS_CPU_TYPE type_size, BRTOS_Queue **event);
1164 
1165  /*****************************************************************************************/
1172  uint8_t OSDQueueDelete (BRTOS_Queue **event);
1173 
1174  /*****************************************************************************************/
1180  uint8_t OSDQueueClean(BRTOS_Queue *pont_event);
1181 
1182  /*****************************************************************************************/
1193  uint8_t OSDQueuePend (BRTOS_Queue *pont_event, void *pdata, ostick_t time_wait);
1194 
1195  /*****************************************************************************************/
1204  uint8_t OSDQueuePost(BRTOS_Queue *pont_event, void *pdata);
1205 #endif
1206 
1211 
1212 
1213 
1214 
1215 
1221 
1222 extern PriorityType OSReadyList;
1223 extern PriorityType OSBlockedList;
1224 extern const PriorityType PriorityMask[configMAX_TASK_PRIORITY+1];
1225 
1226 extern ContextType *Tail;
1227 extern ContextType *Head;
1228 
1229 extern uint8_t iNesting;
1230 extern volatile uint8_t currentTask;
1231 extern volatile uint8_t SelectedTask;
1232 extern ContextType ContextTask[NUMBER_OF_TASKS + 1];
1233 extern uint16_t iStackAddress;
1234 extern uint8_t NumberOfInstalledTasks;
1235 extern volatile uint32_t OSDuty;
1236 extern uint8_t PriorityVector[configMAX_TASK_INSTALL];
1237 extern volatile uint32_t OSDutyTmp;
1238 
1239 #ifdef TICK_TIMER_32BITS
1240  extern volatile uint32_t LastOSDuty;
1241 #else
1242  extern volatile uint16_t LastOSDuty;
1243 #endif
1244 
1245 #ifdef OS_CPU_TYPE
1246 #if (!BRTOS_DYNAMIC_TASKS_ENABLED)
1247  extern OS_CPU_TYPE STACK[(HEAP_SIZE / sizeof(OS_CPU_TYPE))];
1248 #endif
1249  extern OS_CPU_TYPE QUEUE_STACK[(QUEUE_HEAP_SIZE / sizeof(OS_CPU_TYPE))];
1250 #else
1251  #error("You must define the OS_CPU_TYPE !!!")
1252 #endif
1253 
1254 extern uint32_t TaskAlloc;
1255 extern uint16_t iQueueAddress;
1256 
1257 #if (PROCESSOR == ATMEGA)
1258 #if (!defined __GNUC__)
1259 #define CONST
1260 #else
1261 #define CONST const
1262 #endif
1263 extern PGM_P CONST BRTOSStringTable[] PROGMEM;
1264 #else
1265 #if (PROCESSOR == PIC18)
1266 extern const rom CHAR8 *version;
1267 #else
1268 extern const CHAR8 *version;
1269 #endif
1270 #endif
1271 
1272 #if ((PROCESSOR == ATMEGA) || (PROCESSOR == PIC18))
1273 extern CHAR8 BufferText[32];
1274 #endif
1275 
1276 
1277 extern stack_pointer_t StackAddress;
1278 
1279 
1280 
1285 #if (defined ISR_DEDICATED_STACK && ISR_DEDICATED_STACK == 1)
1286 
1288 #define OS_INT_ENTER() if (!iNesting){OS_SAVE_SP(); OS_RESTORE_ISR_SP(); }; iNesting++;
1289 
1290 #define OS_INT_EXIT() \
1291  CriticalDecNesting(); \
1292  if (!iNesting) \
1293  { \
1294  OS_RESTORE_SP(); \
1295  SelectedTask = OSSchedule(); \
1296  if (currentTask != SelectedTask){ \
1297  OS_SAVE_CONTEXT(); \
1298  OS_SAVE_SP(); \
1299  ContextTask[currentTask].StackPoint = SPvalue; \
1300  currentTask = SelectedTask; \
1301  SPvalue = ContextTask[currentTask].StackPoint; \
1302  OS_RESTORE_SP(); \
1303  OS_RESTORE_CONTEXT(); \
1304  } \
1305  } \
1306 
1307 
1308 #else
1309 
1310 #define OS_INT_ENTER() iNesting++;
1311 
1312 
1313 #if (COMPUTES_TASK_LOAD == 1)
1314 extern void COMPUTE_TASK_LOAD(void);
1315 
1316 #define OS_INT_EXIT() \
1317  CriticalDecNesting(); \
1318  if (!iNesting) \
1319  { \
1320  SelectedTask = OSSchedule(); \
1321  if (currentTask != SelectedTask){ \
1322  COMPUTE_TASK_LOAD(); \
1323  OS_SAVE_CONTEXT(); \
1324  OS_SAVE_SP(); \
1325  ContextTask[currentTask].StackPoint = SPvalue; \
1326  currentTask = SelectedTask; \
1327  SPvalue = ContextTask[currentTask].StackPoint; \
1328  OS_RESTORE_SP(); \
1329  OS_RESTORE_CONTEXT(); \
1330  } \
1331  } \
1332 
1333 #else
1334 #define OS_INT_EXIT() \
1335  CriticalDecNesting(); \
1336  if (!iNesting) \
1337  { \
1338  SelectedTask = OSSchedule(); \
1339  if (currentTask != SelectedTask){ \
1340  OS_SAVE_CONTEXT(); \
1341  OS_SAVE_SP(); \
1342  ContextTask[currentTask].StackPoint = SPvalue; \
1343  currentTask = SelectedTask; \
1344  SPvalue = ContextTask[currentTask].StackPoint; \
1345  OS_RESTORE_SP(); \
1346  OS_RESTORE_CONTEXT(); \
1347  } \
1348  } \
1349 
1350 #endif
1351 #endif
1352 
1357 
1358 
1359 #define RemoveFromDelayList() \
1360  if(Task == Head) \
1361  { \
1362  if(Task == Tail) \
1363  { \
1364  Tail = NULL; \
1365  Head = NULL; \
1366  } \
1367  else \
1368  { \
1369  Head = Task->Next; \
1370  Head->Previous = NULL; \
1371  } \
1372  } \
1373  else \
1374  { \
1375  if(Task == Tail) \
1376  { \
1377  Tail = Task->Previous; \
1378  Tail->Next = NULL; \
1379  } \
1380  else \
1381  { \
1382  Task->Next->Previous = Task->Previous; \
1383  Task->Previous->Next = Task->Next; \
1384  } \
1385  }
1386 
1387 
1388 #define IncludeTaskIntoDelayList() \
1389  if(Tail != NULL) \
1390  { \
1391  /* Insert task into list */ \
1392  Tail->Next = Task; \
1393  Task->Previous = Tail; \
1394  Tail = Task; \
1395  Tail->Next = NULL; \
1396  } \
1397  else{ \
1398  /* Init delay list */ \
1399  Tail = Task; \
1400  Head = Task; \
1401  Task->Next = NULL; \
1402  Task->Previous = NULL; \
1403  }
1404 
1405 
1406 #endif
uint8_t OSEventWait
Counter of waiting Tasks.
Definition: BRTOS.h:321
void OS_TICK_HANDLER(void)
Tick timer interrupt handler routine (Internal kernel function).
Definition: BRTOS.c:563
PGM_P CONST BRTOSStringTable[] PROGMEM
Informs BRTOS version.
Definition: BRTOS.c:77
uint8_t OSEventOwner
Defines mutex owner.
Definition: BRTOS.h:318
uint8_t OSBlockPriority(uint8_t iPriority)
Blocks a specific priority Blocks the task that is associated with the specified priority. The user must be careful when using this function in together with mutexes. This can lead to undesired results due the "cealing priority" property used in the mutex.
Definition: BRTOS.c:722
volatile uint32_t OSDutyTmp
Used to compute the CPU load.
Definition: BRTOS.c:133
#define configMAX_TASK_INSTALL
Task Defines.
Definition: BRTOS.h:212
uint8_t OSEventAllocated
Indicate if the event is allocated or not.
Definition: BRTOS.h:316
uint8_t NumberOfInstalledTasks
Number of Installed tasks at the moment.
Definition: BRTOS.c:114
Definition: BRTOS.h:344
uint8_t OSUnBlockMultipleTask(uint8_t TaskStart, uint8_t TaskNumber)
UnBlocks a set of tasks.
Definition: BRTOS.c:993
PriorityType OSEventWaitList
Task wait list for event to occur.
Definition: BRTOS.h:293
uint8_t OSEventWait
Counter of waiting Tasks.
Definition: BRTOS.h:289
uint16_t OSQSize
Size of the queue - Defined in the create queue function.
Definition: BRTOS.h:403
uint8_t OSEventAllocated
Indicate if the event is allocated or not.
Definition: BRTOS.h:287
volatile uint8_t currentTask
Current task being executed.
Definition: BRTOS.c:115
uint16_t OSQEntries
Size of data inside the queue.
Definition: BRTOS.h:404
uint8_t OSOriginalPriority
Save original priority of Mutex owner task - used to the priority ceiling implementation.
Definition: BRTOS.h:320
uint8_t OSEventState
Mailbox state - Defines if the message is available or not.
Definition: BRTOS.h:347
stack_pointer_t StackAddress
Virtual stack pointer.
Definition: BRTOS.c:108
System Time managment struct declarations and functions prototypes.
uint8_t PriorityVector[configMAX_TASK_INSTALL]
Allocate task priorities.
Definition: BRTOS.c:101
Definition: BRTOS.h:286
uint8_t * OSQIn
Pointer to the next queue entry.
Definition: BRTOS.h:401
void Idle(void)
Idle Task. May be used to implement low power commands.
Definition: BRTOS.c:1059
volatile uint16_t LastOSDuty
Last CPU load computed.
Definition: BRTOS.c:138
ostick_t OSGetCount(void)
Return current tick count. Internal BRTOS function.
Definition: BRTOS.c:357
ContextType ContextTask[NUMBER_OF_TASKS+1]
Definition: BRTOS.c:232
uint8_t OSEventCount
Queue Event Count - This value is increased with a post and decremented with a pend.
Definition: BRTOS.h:373
volatile uint32_t OSDuty
Used to compute the CPU load.
Definition: BRTOS.c:132
uint8_t BRTOSStart(void)
Start the Operating System Scheduler The user must call this function to start the tasks execution...
Definition: BRTOS.c:640
uint8_t OSDelayTaskHMSM(uint8_t hours, uint8_t minutes, uint8_t seconds, uint16_t miliseconds)
Wait for a specified period (in hours, minutes, seconds and miliseconds). A task that calling this fu...
Definition: BRTOS.c:509
uint8_t OSDelayTask(ostick_t time_wait)
Wait for a specified period. A task that calling this function will be suspended for a certain time...
Definition: BRTOS.c:424
void initEvents(void)
Initialize event control blocks.
Definition: BRTOS.c:1548
ostick_t OSGetTickCount(void)
Return current tick count. The user must call this function in order to receive the current tick coun...
Definition: BRTOS.c:333
uint16_t iQueueAddress
Queue heap control.
Definition: BRTOS.c:105
PriorityType OSEventWaitList
Task wait list for event to occur.
Definition: BRTOS.h:376
Definition: BRTOS.h:371
uint8_t * OSQStart
Pointer to the queue start.
Definition: BRTOS.h:399
uint8_t * OSQEnd
Pointer to the queue end.
Definition: BRTOS.h:400
BRTOS_TH OSGetCurrentTaskHandle(void)
Return the handle of the current task. The user must call this function in order to receive the curre...
Definition: BRTOS.c:285
uint8_t OSEventAllocated
Indicate if the event is allocated or not.
Definition: BRTOS.h:345
void * OSEventPointer
Pointer to queue structure.
Definition: BRTOS.h:375
void PreInstallTasks(void)
Function that initialize the kernel main variables. This function resets the kernel main variables...
Definition: BRTOS.c:675
void BRTOSInit(void)
Initialize BRTOS control blocks and tick timer (Internal kernel function).
Definition: BRTOS.c:1520
PriorityType OSEventWaitList
Task wait list for event to occur.
Definition: BRTOS.h:322
uint8_t OSEventState
Mutex state - Defines if the resource is available or not.
Definition: BRTOS.h:317
PriorityType OSEventWaitList
Task wait list for event to occur.
Definition: BRTOS.h:348
BRTOS_TH OSGetTaskPriority(BRTOS_TH task_handle)
Return the priority of the specified task. The user must call this function in order to receive the p...
Definition: BRTOS.c:309
uint8_t OSEventWait
Counter of waiting Tasks.
Definition: BRTOS.h:346
void OSIncCounter(void)
Update the tick counter.
Definition: BRTOS.c:402
uint8_t * OSQOut
Pointer to the next data in the queue output.
Definition: BRTOS.h:402
Definition: BRTOS.h:397
uint8_t OSEventAllocated
Indicate if the event is allocated or not.
Definition: BRTOS.h:372
uint32_t TaskAlloc
Used to search a empty task control block.
Definition: BRTOS.c:142
uint8_t OSEventCount
Semaphore Count - This value is increased with a post and decremented with a pend.
Definition: BRTOS.h:288
uint8_t SAScheduler(PriorityType ReadyList)
Sucessive Aproximation Scheduler (Internal kernel function).
Definition: BRTOS.c:1595
void * OSEventPointer
Pointer to the message structure / type.
Definition: BRTOS.h:349
uint8_t iNesting
Used to inform if the current code position is an interrupt handler code.
Definition: BRTOS.c:143
uint16_t iStackAddress
Virtual stack counter - Informs the stack occupation in bytes.
Definition: BRTOS.c:102
BRTOS types declaration.
Definition: BRTOS.h:315
uint8_t OSUnBlockPriority(uint8_t iPriority)
UnBlock a specific priority UnBlocks the task that is associated with the specified priority...
Definition: BRTOS.c:772
uint8_t OSEventWait
Counter of waiting Tasks.
Definition: BRTOS.h:374
uint8_t OSSchedule(void)
Priority Preemptive Scheduler (Internal kernel function).
Definition: BRTOS.c:261
uint8_t OSMaxPriority
Defines max priority accessing resource.
Definition: BRTOS.h:319
uint8_t OSBlockMultipleTask(uint8_t TaskStart, uint8_t TaskNumber)
Blocks a set of tasks.
Definition: BRTOS.c:941