|
|
@ -51,9 +51,9 @@ void _exit(int code)
|
|
|
|
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
|
|
|
|
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 'Prepares' task for running.
|
|
|
|
* Exits the task (userspace call).
|
|
|
|
* Calls the task's main code, setting _exit() as the return point.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
__attribute__ ((naked))
|
|
|
|
__attribute__ ((naked))
|
|
|
|
void task_doexit(void)
|
|
|
|
void task_doexit(void)
|
|
|
@ -62,6 +62,10 @@ void task_doexit(void)
|
|
|
|
while (1);
|
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 'Prepares' task for running.
|
|
|
|
|
|
|
|
* Calls the task's main code, setting task_doexit() (_exit) as the return point.
|
|
|
|
|
|
|
|
*/
|
|
|
|
__attribute__ ((naked))
|
|
|
|
__attribute__ ((naked))
|
|
|
|
void task_crt0(void)
|
|
|
|
void task_crt0(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -103,7 +107,7 @@ task_t *task_create(void (*code)(void), uint16_t stackSize)
|
|
|
|
void task_init(void (*init)(void), uint16_t stackSize)
|
|
|
|
void task_init(void (*init)(void), uint16_t stackSize)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
current = (task_t *)malloc(sizeof(task_t));
|
|
|
|
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);
|
|
|
|
task_t *init_task = task_create(init, stackSize);
|
|
|
|
|
|
|
|
|
|
|
@ -116,14 +120,14 @@ void task_init(void (*init)(void), uint16_t stackSize)
|
|
|
|
// bit 0 - priv, bit 1 - psp/msp
|
|
|
|
// bit 0 - priv, bit 1 - psp/msp
|
|
|
|
asm("\
|
|
|
|
asm("\
|
|
|
|
mov r0, sp; \
|
|
|
|
mov r0, sp; \
|
|
|
|
mov %0, r0; \
|
|
|
|
|
|
|
|
msr psp, r0; \
|
|
|
|
msr psp, r0; \
|
|
|
|
mrs r0, control; \
|
|
|
|
mrs r0, control; \
|
|
|
|
orr r0, r0, #3; \
|
|
|
|
orr r0, r0, #3; \
|
|
|
|
cpsie i; \
|
|
|
|
cpsie i; \
|
|
|
|
msr control, r0; \
|
|
|
|
msr control, r0; \
|
|
|
|
" : "=r" (current->sp));
|
|
|
|
");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exit the current (fake) task
|
|
|
|
task_doexit();
|
|
|
|
task_doexit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -179,6 +183,7 @@ void PendSV_Handler(void)
|
|
|
|
" : "=r" (current->sp));
|
|
|
|
" : "=r" (current->sp));
|
|
|
|
|
|
|
|
|
|
|
|
// Load next task
|
|
|
|
// Load next task
|
|
|
|
|
|
|
|
prev = current;
|
|
|
|
uint32_t ticks = millis();
|
|
|
|
uint32_t ticks = millis();
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
current = current->next;
|
|
|
|
current = current->next;
|
|
|
|