10 uint8_t taskspace
[TASKSPACE
] = {0};
11 uint8_t *spacepointer
= (uint8_t *)&taskspace
;
16 memset(&taskspace
, 0, TASKSPACE
);
19 void task_register(void)
21 debug("free memory: %lu\n", ((uint8_t *)taskspace
)-spacepointer
+TASKSPACE
);
23 if(spacepointer
+sizeof(struct task
) > taskspace
+TASKSPACE
){
24 die("Out of memory... Not enough to allocate taskstruct");
27 //We haven't had a task before, therefore we initialize head
28 struct task
*t
= (struct task
*)spacepointer
;
31 t
->interval
= read16();
32 debug("interval: %d\n", t
->interval
);
35 if(is_interrupt_task(t
)) {
40 t
->tasklength
= read16();
41 debug("task interval: %d, length: %d\n", t
->interval
, t
->tasklength
);
43 if(spacepointer
+t
->tasklength
> taskspace
+TASKSPACE
){
44 die("Out of memory... Not enough to allocate bytes");
47 spacepointer
+= sizeof(struct task
);
49 spacepointer
+= t
->tasklength
;
52 for(i
= 0; i
<t
->tasklength
; i
++){
53 t
->bc
[i
] = read_byte();
56 //Return the task number for later removal
57 debug("Received a task of length %d", t
->tasklength
);
64 debug("free memory: %lu\n", ((uint8_t *)taskspace
)+TASKSPACE
-spacepointer
);
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)
81 return spacepointer
== (uint8_t *)&taskspace
? NULL
82 : (struct task
*)&taskspace
;
85 struct task
*task_next(struct task
*t
)
87 uint8_t *next
= (uint8_t *)t
;
88 next
+= sizeof(struct task
);
89 next
+= t
->tasklength
;
91 return next
>= spacepointer
? NULL
: (struct task
*)next
;
94 void task_delete(uint8_t c
)
96 debug("Going to delete task: %i", c
);
97 debug("spacepointer: %p", spacepointer
);
98 struct task
*t
= task_head();
107 //We found the task, now we move everything from the end of the task up
108 //to the spacepointer right
109 uint8_t *start
= (uint8_t *)t
;
110 uint8_t *end
= start
+ sizeof(struct task
) + t
->tasklength
;
111 debug("Moving %lu bytes\n", spacepointer
-end
);
112 for(int i
= 0; i
<spacepointer
-end
; i
++){
116 //Decrement the spacepointer
117 spacepointer
-= end
-start
;
119 debug("spacepointer: %p", spacepointer
);