-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.c
More file actions
64 lines (56 loc) · 1.22 KB
/
main.c
File metadata and controls
64 lines (56 loc) · 1.22 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
/**
* Blink example in ROS, DO NOT use any function in Arduino.h
*/
#include <avr/io.h>
#include "ros.h"
// include for simavr
// #include "avr_mcu_section.h"
// AVR_MCU(F_CPU, "atmega328p");
ROS_TCB task1;
ROS_TCB task2;
uint8_t task1_stack[ROS_DEFAULT_STACK_SIZE];
uint8_t task2_stack[ROS_DEFAULT_STACK_SIZE];
#define LED1 13
#define LED2 12
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define TASK1_PRIORITY 1
#define TASK2_PRIORITY 0 // max priority
void t1() {
while (1) {
// set LED1 high
bitSet(PORTB, 5);
ros_delay(200);
bitClear(PORTB, 5);
ros_delay(200);
}
}
void t2() {
while (1) {
bitSet(PORTB, 4);
// delay a second
ros_delay(100);
bitClear(PORTB, 4);
ros_delay(100);
}
}
void setup() {
// set LED 13 and LED 12 as output
bitSet(DDRB, 5);
bitSet(DDRB, 4);
bool os_started = ros_init();
if (os_started) {
ros_create_task(&task1, t1, TASK1_PRIORITY, task1_stack, ROS_DEFAULT_STACK_SIZE);
ros_create_task(&task2, t2, TASK2_PRIORITY, task2_stack, ROS_DEFAULT_STACK_SIZE);
ros_schedule();
}
}
void loop() {
// nothing
}
int main() {
setup();
// never call loop
loop();
return 0;
}