10 uint8_t taskspace
[TASKSPACE
] = {0};
11 uint8_t *spacepointer
= (uint8_t *)&taskspace
;
16 memset(&taskspace
, 0, TASKSPACE
);
19 void task_register(void)
22 if(spacepointer
+sizeof(struct task
) > taskspace
+TASKSPACE
){
23 die("Out of memory... Not enough to allocate taskstruct");
26 //We haven't had a task before, therefore we initialize head
27 struct task
*t
= (struct task
*)spacepointer
;
30 t
->interval
= read16();
31 debug("interval: %d\n", t
->interval
);
34 if(is_interrupt_task(t
)) {
39 t
->tasklength
= read16();
40 debug("task interval: %d, length: %d\n", t
->interval
, t
->tasklength
);
42 if(spacepointer
+t
->tasklength
> taskspace
+TASKSPACE
){
43 die("Out of memory... Not enough to allocate bytes");
46 spacepointer
+= sizeof(struct task
);
48 spacepointer
+= t
->tasklength
;
51 for(i
= 0; i
<t
->tasklength
; i
++){
52 t
->bc
[i
] = read_byte();
55 //Return the task number for later removal
56 debug("Received a task of length %d", t
->tasklength
);
65 bool is_interrupt_task(struct task
*t
)
67 return t
->interval
& (2 <<14);
70 bool had_interrupt(struct task
* t
)
72 //Not implemented yet...
77 struct task
*task_head(void)
79 return spacepointer
== (uint8_t *)&taskspace
? NULL
80 : (struct task
*)&taskspace
;
83 struct task
*task_next(struct task
*t
)
85 uint8_t *next
= (uint8_t *)t
;
86 next
+= sizeof(struct task
);
87 next
+= t
->tasklength
;
89 return next
>= spacepointer
? NULL
: (struct task
*)next
;
92 void task_delete(uint8_t c
)
94 debug("Going to delete task: %i", c
);
95 debug("spacepointer: %p", spacepointer
);
96 struct task
*t
= task_head();
105 //We found the task, now we move everything from the end of the task up
106 //to the spacepointer right
107 uint8_t *start
= (uint8_t *)t
;
108 uint8_t *end
= start
+ sizeof(struct task
) + t
->tasklength
;
109 debug("Moving %lu bytes\n", spacepointer
-end
);
110 for(int i
= 0; i
<spacepointer
-end
; i
++){
114 //Decrement the spacepointer
115 spacepointer
-= end
-start
;
117 debug("spacepointer: %p", spacepointer
);