aboutsummaryrefslogtreecommitdiff
path: root/main.c
blob: 703bbb59cd4df0468f896ba76ad9f65a4bc16cc1 (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
56
57
58
#include <stddef.h>
#include <stdio.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include "bug/panic.h"
#include "bug/debug.h"
#include "task/task.h"
#include "task/sched.h"
#include "task/idle.h"
#include "task/lock.h"
#include "task/idle.h"
#include "time/clock.h"
#include "io/io.h"
#include "mcu/io/usart.h"
#include "tshield/tshield.h"
#define IN_LENGTH 64

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

void worker() {
  char buffer[64];

  while(1) {
    int length = read(&usart0, buffer, 64);

    int led;
    int value;
    if (sscanf(buffer, "leds/%d:%d", &led, &value) == 2) {
       debug_led(led, value);
    } else {
      debug_led(0,1);
      WAIT_CYCLES(300000);
      debug_led(0,0);
    }
  }
}


DECLARE_TASK(task_idle, IDLE_STACK_SIZE, idle_entry, 0);
DECLARE_TASK(task1, DEFAULT_STACK_SIZE, worker, 1);

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

  open(&usart0);
  ioctl(&usart0, IOCTL_SET_BAUD, 115200);

  spawn_idle(&task_idle);
  spawn(&task1);

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