-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple_task_end.cpp
More file actions
94 lines (71 loc) · 1.88 KB
/
Copy pathsimple_task_end.cpp
File metadata and controls
94 lines (71 loc) · 1.88 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* @brief Test of the ability for a POSIX port freeRTOS program to exit
* cleanly after ending the scheduler.
*
* Program should exit after call to
* vTaskEndScheduler().
*
*/
#include "FreeRTOSConfig.h"
#include "FreeRTOS.h"
#include <thread>
#include <cstdio>
#include <cstring>
#include "task.h"
#include "unistd.h"
#define TASK_DEPTH 20000
static TaskHandle_t a_task;
static TaskHandle_t app_task;
bool main_running;
void a_task_function(void* arg)
{
printf("%s\n", __FUNCTION__);
// run test
vTaskDelay(pdMS_TO_TICKS(1000));
printf("%s asking main to shut down\n", __FUNCTION__);
main_running = false;
vTaskDelay(pdMS_TO_TICKS(250));
printf("%s ending scheduler\n", __FUNCTION__);
vTaskEndScheduler();
// should never reach here
printf("ERROR %s after end scheduler\n", __FUNCTION__);
}
static void app_main(void* arg)
{
printf("%s starting system up\n", __FUNCTION__);
///////
// create various tasks and objects for the system
// start the task
xTaskCreate(a_task_function,
"a_task",
TASK_DEPTH,
NULL,
1,
&a_task);
while(main_running)
{
vTaskDelay(pdMS_TO_TICKS(100));
}
// only for system testing case
// clean up tasks / objects
printf("%s calling vTaskDelete\n", __FUNCTION__);
// it isn't valid to return from a task, FreeRTOS
// requires that tasks delete themselves
vTaskDelete(NULL);
}
int main()
{
main_running = true;
// start the system up
xTaskCreate(app_main,
"app_main",
TASK_DEPTH,
NULL,
1,
&app_task);
printf("%s calling vTaskStartScheduler\n", __FUNCTION__);
// blocks until vTaskEndScheduler() is called
vTaskStartScheduler();
printf("%s exiting\n", __FUNCTION__);
return 0;
}