forked from ntueecamp/22-robot-dog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TaskTemplate
47 lines (40 loc) · 1.36 KB
/
TaskTemplate
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
/**
* @file TaskTemplate
* @author ntueecamp 2022 (FrSh28)
* @brief Templates for basic structure of a task and how to create a task
* @date 2022-06-28
*
*/
void someTask((void*) argv)
{
// do some thing...
while (true) // must have a infinite loop
{
// loop cycle of the task
// call `taskYIELD()` at least once or block on something to yield yourself
}
// should never get here
}
TaskHandle_t createSomeTask(int a, int b, int c)
{
// NOTE: you only need to do this if the arguments are not global and have too short lifetime
// CAUTION: if the task would be created and deleted more than once,
// special care are required to ensure no memory leak
int* argv = (int*)malloc(3 * sizeof(int));
// replace int by some large enough type if necessary
// replace 3 by the number of arguments your function needs
argv[0] = a;
argv[1] = b;
argv[2] = c;
BaseType_t xResult;
TaskHandle_t someTaskHandle;
xResult = xTaskCreate( someTask,
"SomeTask",
100, // stack size in words (4 bytes on ESP32), TBD
(void*) argv,
2, // priority, >= 2 is good, TBD
&someTaskHandle);
if (xResult != pdPASS)
return NULL;
return someTaskHandle;
}