SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
}
+
/**
- * 'Prepares' task for running.
- * Calls the task's main code, setting _exit() as the return point.
+ * Exits the task (userspace call).
*/
__attribute__ ((naked))
void task_doexit(void)
while (1);
}
+/**
+ * 'Prepares' task for running.
+ * Calls the task's main code, setting task_doexit() (_exit) as the return point.
+ */
__attribute__ ((naked))
void task_crt0(void)
{
void task_init(void (*init)(void), uint16_t stackSize)
{
current = (task_t *)malloc(sizeof(task_t));
- current->stack = 0;
+ current->stack = 0; // free() is called on this
task_t *init_task = task_create(init, stackSize);
// bit 0 - priv, bit 1 - psp/msp
asm("\
mov r0, sp; \
- mov %0, r0; \
msr psp, r0; \
mrs r0, control; \
orr r0, r0, #3; \
cpsie i; \
msr control, r0; \
- " : "=r" (current->sp));
+ ");
+ // exit the current (fake) task
task_doexit();
}
" : "=r" (current->sp));
// Load next task
+ prev = current;
uint32_t ticks = millis();
do {
current = current->next;