aboutsummaryrefslogtreecommitdiff
path: root/main.c
blob: 526d75ff77853e7b35633dec616bea291cb27440 (plain) (blame)
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
#include <stddef.h>
#include <stdio.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include "task/task.h"
#include "task/sched.h"
#include "bug/panic.h"
#include "bug/debug.h"
#include "task/lock.h"
#include "time/clock.h"
#include "mcu/task/context.h"
#include "tshield/tshield.h"

#define WAIT_CYCLES(cycles) for (volatile unsigned long i = 0; i < cycles; ++i) {}

spin_lock_t on_lock = SPIN_LOCK_UNLOCKED;
volatile char on = 0;

void read(char id) {
  while(1) {
    spin_lock(&on_lock);
    debug_led(0,on);
    spin_unlock(&on_lock);
  }
}

void write( char id) {
  while(1) {
    spin_lock(&on_lock);
    on = !on;
    WAIT_CYCLES(30000);
    spin_unlock(&on_lock);
  }
}


DECLARE_TASK(task1, DEFAULT_STACK_SIZE, read, 1);
DECLARE_TASK(task2, DEFAULT_STACK_SIZE, write, 2);


int main(int argc, char *argv[]) {
  cli();
  tshield_init();
  

  spawn(&task1);
  spawn(&task2);
  
  sei();
  clock_init(10, schedule);
  clock_start();
  sched_init();
  panic(); //should never reach here
  while(1){}
}