-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLab2-5_Periodic_Task.cpp
47 lines (36 loc) · 1.03 KB
/
Lab2-5_Periodic_Task.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
#include <Arduino.h>
#include <Arduino_FreeRTOS.h>
void TaskFunction (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);
}
int counter = 0;
void loop() {
/*Do nothing*/
}
void TaskFunction(void *Parameter)
{
char *print_string;
TickType_t LastWakeTime;
print_string = (char*) Parameter;
LastWakeTime = xTaskGetTickCount();
while(1)
{
Serial.println(print_string);
TaskDelayUntil_ms(&LastWakeTime,500);
}
}
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));
}