10 uint8_t taskspace
[TASKSPACE
] = {0};
11 uint8_t *spacepointer
= (uint8_t *)&taskspace
;
13 struct task
*head
= NULL
;
17 memset(&taskspace
, 0, TASKSPACE
);
21 void task_register(void)
24 if(spacepointer
+sizeof(struct task
) > taskspace
+TASKSPACE
){
25 die("Out of memory... Not enough to allocate taskstruct");
28 //We haven't had a task before, therefore we initialize head
29 struct task
*t
= (struct task
*)spacepointer
;
35 t
->interval
= read16();
36 debug("interval: %d\n", t
->interval
);
39 if(is_interrupt_task(t
)) {
44 t
->tasklength
= read16();
45 debug("task interval: %d, length: %d\n", t
->interval
, t
->tasklength
);
47 if(spacepointer
+t
->tasklength
> taskspace
+TASKSPACE
){
48 die("Out of memory... Not enough to allocate bytes");
51 spacepointer
+= t
->tasklength
;
54 for(i
= 0; i
<t
->tasklength
; i
++){
55 t
->bc
[i
] = read_byte();
57 //Return the task number for later removal
58 debug("Received a task of length %d", t
->tasklength
);
67 bool is_interrupt_task(struct task
*t
)
69 return t
->interval
& (2 <<14);
72 bool had_interrupt(struct task
* t
)
74 //Not implemented yet...
79 struct task
*task_head(void)
84 struct task
*task_next(struct task
*t
)
90 uint8_t *next
= (uint8_t *)t
;
91 next
+= sizeof(struct task
);
92 next
+= t
->tasklength
;
94 return next
> spacepointer
? NULL
: (struct task
*)next
;
97 void task_delete(void)
100 struct task
*t
= NULL
;
108 //We found the task, now we move everything from the end of the task up
109 //to the spacepointer right
110 uint8_t *start
= (uint8_t *)t
;
111 uint8_t *end
= start
+ sizeof(struct task
) + t
->tasklength
;
112 debug("Moving %lu bytes\n", spacepointer
-end
);
113 for(int i
= 0; i
<spacepointer
-end
; i
++){
117 //Decrement the spacepointer
118 spacepointer
-= end
-start
;
124 //Write acknowledgement