Debian Codegraph @

examples/temp_sensor/src/TaskScheduler.c

raw symbols SCIP
1 #include "Types.h"
2 #include "TaskScheduler.h"
3
4 typedef struct _Task
5 {
6 bool doIt;
7 uint32 period;
8 uint32 startTime;
9 } Task;
10
11 typedef struct _TaskSchedulerInstance
12 {
13 Task usart;
14 Task adc;
15 } TaskSchedulerInstance;
16
17 static TaskSchedulerInstance this;
18
19 void TaskScheduler_Init(void)
20 {
21 this.usart.doIt = FALSE;
22 this.usart.startTime = 0;
23
24 //The correct period
25 this.usart.period = 1000;
26
27 this.adc.doIt = FALSE;
28 this.adc.startTime = 0;
29 this.adc.period = 100;
30 }
31
32 void TaskScheduler_Update(uint32 time)
33 {
34 if ((time - this.usart.startTime) >= this.usart.period)
35 {
36 this.usart.doIt = TRUE;
37 this.usart.startTime = time - (time % this.usart.period);
38 }
39
40 if ((time - this.adc.startTime) >= this.adc.period)
41 {
42 this.adc.doIt = TRUE;
43 this.adc.startTime = time - (time % this.adc.period);
44 }
45 }
46
47 bool TaskScheduler_DoUsart(void)
48 {
49 bool doIt = FALSE;
50
51 if (this.usart.doIt)
52 {
53 doIt = TRUE;
54 this.usart.doIt = FALSE;
55 }
56
57 return doIt;
58 }
59
60 bool TaskScheduler_DoAdc(void)
61 {
62 bool doIt = FALSE;
63
64 if (this.adc.doIt)
65 {
66 doIt = TRUE;
67 this.adc.doIt = FALSE;
68 }
69
70 return doIt;
71 }
72