-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
100 lines (76 loc) · 1.45 KB
/
main.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
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
95
96
97
98
99
100
#include <cstdio>
#include <cstdint>
#include <frt.h>
#include "uart.h"
namespace
{
class ExampleTask final :
public frt::Task<ExampleTask>
{
public:
bool run()
{
msleep(1000);
std::puts("Example FreeRTOS Task");
return true;
}
};
class BlinkTask final :
public frt::Task<BlinkTask>
{
public:
BlinkTask()
{
DDRB |= (1 << DDB5);
}
bool run()
{
PORTB ^= (1 << PB5);
msleep(100);
return true;
}
};
ExampleTask example_task;
BlinkTask blink_task;
}
int main()
{
uart_init();
std::puts("Example FreeRTOS Project");
example_task.start(1);
blink_task.start(2);
/* Start the scheduler. */
vTaskStartScheduler();
for (;;);
return 0;
}
volatile std::uint8_t counter = 0;
void vApplicationIdleHook()
{
static bool stopped = false;
static std::uint8_t seconds = 0;
if (counter > 62) {
counter = 0;
++seconds;
}
if (!stopped && seconds == 10) {
std::printf("ExampleTask used %u bytes of stack this time.\n", example_task.getUsedStackSize());
std::printf("BlinkTask used %u bytes of stack this time.\n", blink_task.getUsedStackSize());
std::puts("Stopping...");
example_task.stopFromIdleTask();
std::puts("Stopped.");
stopped = true;
}
}
void vApplicationTickHook()
{
++counter;
}
#if (configCHECK_FOR_STACK_OVERFLOW > 0)
void vApplicationStackOverflowHook(TaskHandle_t xTask, char* pcTaskName)
{
for (;;) {
std::printf("'%s' stack overflow!\n", pcTaskName);
}
}
#endif