aboutsummaryrefslogtreecommitdiff
path: root/sem4/embedded/m7/m7.ino
blob: 27b1ea2591af7fa7e05198e9325c08ef7afa3e9c (plain)
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
#include <krnl.h>
#define STACK 200

char stk1[STACK];
char stk2[STACK];
struct k_t *tsk1, *tsk2, *sem1, *sem2;

#define DELAY 100000
void f1() {
    k_set_sem_timer(sem1, 50);
	for(;;) {
        k_wait(sem1, 0);
        PORTD &= ~(1 << 5);
        PORTD |= (1 << 4);
        k_eat_msec_time(20);
        PORTD &= ~(1 << 4);
	}
}

void f2() {
    k_set_sem_timer(sem2, 80);
	for(;;) {
        k_wait(sem2, 0);
        PORTD &= ~(1 << 5);
        PORTD |= (1 << 3);
        k_eat_msec_time(20);
        PORTD &= ~(1 << 3);
	}
}

void setup() {
    pinMode(13, OUTPUT);
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    Serial.begin(115200);
    Serial.println("Starting");

    k_init(2, 2, 0);

    sem1 = k_crt_sem(0, 1);
    sem2 = k_crt_sem(0, 1);

    tsk1 = k_crt_task(f1, 10, stk1, STACK);
    tsk2 = k_crt_task(f2, 10, stk2, STACK);

    k_start(1); 
}

void loop() {

}