-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_tasks.cpp
More file actions
43 lines (36 loc) · 845 Bytes
/
example_tasks.cpp
File metadata and controls
43 lines (36 loc) · 845 Bytes
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
#define F_CPU 8000000
#include "tasks.h"
#include "ports.h"
typedef PIN_C1 Led1;
typedef PIN_C3 LedButton;
typedef PIN_B1 Button;
void initPorts() {
Led1::DDR = ports::DataDirection::Out;
LedButton::DDR = ports::DataDirection::Out;
Button::DDR = ports::DataDirection::Input;
}
// «TASK_EX»
uint16_t toggleLed1(uint16_t) {
Led1::toggle();
return clock::ms_to_units<300>();
}
#define NEW_TASK toggleLed1
#include REGISTER_TASK
// Instead of fetching the current input from a pin,
// an irq-task could set a flag. The current code
// would toggle continuously while the button is pressed.
void toggleLedButton(uint32_t) {
if (Button::PIN) {
LedButton::toggle();
}
}
#define NEW_TASK toggleLedButton
#include REGISTER_TASK
int main(void) {
initPorts();
for(;;) {
EXEC_TASKS();
}
}
#include REGISTER_IRQS
/*¤*/