make workable for linux again
[mTask.git] / int / nucleo-f767-blinky / src / task.c
1 #include <stdlib.h>
2 #include <string.h>
3
4 #ifndef STM32F767xx
5 #include <unistd.h>
6 #include <stdio.h>
7 #endif
8
9 #include "misc.h"
10 #include "task.h"
11
12 struct task tasks[MAXTASKS];
13
14 void task_init()
15 {
16 memset(&tasks, 0, sizeof(struct task)*MAXTASKS);
17 }
18
19 int task_register()
20 {
21 uint8_t ct;
22
23 for(ct = 0; ct<MAXTASKS; ct++)
24 if(!tasks[ct].used)
25 break;
26 if(ct == MAXTASKS)
27 die("Trying to add too much tasks...\n");
28
29 memset(&tasks[ct], 0, sizeof(struct task));
30 //Read interval
31 tasks[ct].interval = read16();
32 //Read tasklength
33 tasks[ct].tlen = read16();
34
35 if(tasks[ct].tlen > MAXTASKSIZE)
36 die("Task is too long: %d\n", tasks[ct].tlen);
37 //Read task bytecode
38 for(unsigned int i = 0; i<tasks[ct].tlen; i++){
39 tasks[ct].bc[i] = read_byte();
40 debug("t[][%i]: 0x%02x %d\n", i,
41 tasks[ct].bc[i], tasks[ct].bc[i]);
42 }
43 //Return the task number for later removal
44 debug("Received a task of length %d\n", tasks[ct].tlen);
45 tasks[ct].used = true;
46 return ct;
47 }
48
49 void task_delete()
50 {
51 tasks[read_byte()].used = false;
52 }
53
54 struct task *task_get(int num)
55 {
56 return tasks[num].used ? &tasks[num] : NULL;
57 }