9 extern uint8_t *mem_top
, *mem_bottom
, *mem_task
, *mem_sds
;
13 void task_register(void)
15 debug("free memory: %lu\n", mem_free());
17 if(mem_task
+sizeof(struct task
) > mem_sds
){
18 die("Out of memory... Not enough to allocate taskstruct");
21 struct task
*t
= (struct task
*)mem_task
;
24 t
->interval
= read16();
25 debug("interval: %d\n", t
->interval
);
28 if(is_interrupt_task(t
)) {
33 t
->tasklength
= read16();
34 debug("task interval: %d, length: %d\n", t
->interval
, t
->tasklength
);
36 if(mem_task
+t
->tasklength
> mem_sds
){
37 die("Out of memory... Not enough to allocate bytes");
40 mem_task
+= sizeof(struct task
);
42 mem_task
+= t
->tasklength
;
45 for(i
= 0; i
<t
->tasklength
; i
++){
46 t
->bc
[i
] = read_byte();
49 //Return the task number for later removal
50 debug("Received a task of length %d", t
->tasklength
);
59 debug("free memory: %lu\n", mem_free());
62 bool is_interrupt_task(struct task
*t
)
64 return t
->interval
& (2 <<14);
67 bool had_interrupt(struct task
* t
)
69 //Not implemented yet...
74 struct task
*task_head(void)
76 return mem_task
== mem_bottom
? NULL
: (struct task
*)mem_bottom
;
79 struct task
*task_next(struct task
*t
)
81 uint8_t *next
= (uint8_t *)t
+ sizeof(struct task
) + t
->tasklength
;
82 return next
>= mem_task
? NULL
: (struct task
*)next
;
85 void task_delete(uint8_t c
)
87 debug("Going to delete task: %i", c
);
88 struct task
*t
= task_head();
95 //Write acknowledgement
101 //We found the task, now we move everything from the end of the task up
102 //to the spacepointer right
103 uint8_t *start
= (uint8_t *)t
;
104 uint8_t *end
= start
+ sizeof(struct task
) + t
->tasklength
;
105 debug("Moving %lu bytes\n", mem_task
-end
);
106 for(int i
= 0; i
<mem_task
-end
; i
++){
110 //Decrement the spacepointer
111 mem_task
-= end
-start
;