-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLab2-6_Task_Management.cpp
61 lines (48 loc) · 1.32 KB
/
Lab2-6_Task_Management.cpp
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
#include <Arduino.h>
#include <Arduino_FreeRTOS.h>
void TaskFunction (void *Parameter);
void TaskPeriodic (void *Parameter);
void TaskDelay_ms(uint32_t ms);
void TaskDelayUntil_ms(TickType_t * const pxPreviousWakeTime, uint32_t ms);
void setup() {
static const char *TextForTask1 = "Task 1 is running";
static const char *TextForTask2 = "Task 2 is running";
Serial.begin(115200);
xTaskCreate(TaskFunction, "Task1", 1000, (void*)TextForTask1, 1, NULL);
xTaskCreate(TaskFunction, "Task2", 1000, (void*)TextForTask2, 2, NULL);
xTaskCreate(TaskPeriodic, "PeriodicTask", 1000, NULL, 3, NULL);
}
int counter = 0;
void loop() {
/*Do nothing*/
}
void TaskFunction(void *Parameter)
{
char *print_string;
TickType_t LastWakeTime;
print_string = (char*) Parameter;
while(1)
{
Serial.println(print_string);
TaskDelay_ms(200);
}
}
void TaskPeriodic(void *Parameter)
{
char *print_string;
TickType_t LastWakeTime;
LastWakeTime = xTaskGetTickCount();
while(1)
{
Serial.println("Periodic Task is running");
TaskDelayUntil_ms(&LastWakeTime,1000);
}
}
void TaskDelay_ms(uint32_t ms)
{
vTaskDelay(ms/portTICK_PERIOD_MS);
}
void TaskDelayUntil_ms(TickType_t * const pxPreviousWakeTime, uint32_t ms)
{
vTaskDelayUntil(pxPreviousWakeTime,(ms/portTICK_PERIOD_MS));
}