summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus/Test/CMock/examples/temp_sensor/src/TaskScheduler.c
blob: bcc0e64369f2ff6ad789cf1c4b4b7b880f900219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "Types.h"
#include "TaskScheduler.h"

typedef struct _Task
{
  bool    doIt;
  uint32  period;
  uint32  startTime;
} Task;

typedef struct _TaskSchedulerInstance
{
  Task usart;
  Task adc;
} TaskSchedulerInstance;

static TaskSchedulerInstance this;

void TaskScheduler_Init(void)
{
  this.usart.doIt = FALSE;
  this.usart.startTime = 0;

  //The correct period
  this.usart.period = 1000;

  this.adc.doIt = FALSE;
  this.adc.startTime = 0;
  this.adc.period = 100;
}

void TaskScheduler_Update(uint32 time)
{
  if ((time - this.usart.startTime) >= this.usart.period)
  {
    this.usart.doIt = TRUE;
    this.usart.startTime = time - (time % this.usart.period);
  }

  if ((time - this.adc.startTime) >= this.adc.period)
  {
    this.adc.doIt = TRUE;
    this.adc.startTime = time - (time % this.adc.period);
  }
}

bool TaskScheduler_DoUsart(void)
{
  bool doIt = FALSE;

  if (this.usart.doIt)
  {
    doIt = TRUE;
    this.usart.doIt = FALSE;
  }

  return doIt;
}

bool TaskScheduler_DoAdc(void)
{
  bool doIt = FALSE;

  if (this.adc.doIt)
  {
    doIt = TRUE;
    this.adc.doIt = FALSE;
  }

  return doIt;
}