aboutsummaryrefslogtreecommitdiff
path: root/task.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2018-07-24 22:55:19 -0400
committerPaul Selkirk <paul@psgd.org>2018-07-25 01:08:20 -0400
commitf424af5cfc62bf4e0902831591a303b02e31a1ca (patch)
treeaa338109bde6a82abde6abe30769cb62e04745bf /task.c
parent49939b9954926ccb4b31238ab186693c28fab5c5 (diff)
parent7e6a9f76d8a72dead4763fbb726cfd60fece7b03 (diff)
Merge branch 'hashsig'
Diffstat (limited to 'task.c')
-rw-r--r--task.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/task.c b/task.c
index 36e8580..34daa24 100644
--- a/task.c
+++ b/task.c
@@ -131,6 +131,24 @@ tcb_t *task_add(char *name, funcp_t func, void *cookie, void *stack, size_t stac
return t;
}
+/* Reinitalize the current task.
+ * NOTE: This will destroy any state in the running task.
+ * DO NOT CALL THIS UNLESS YOU ARE REALLY SURE THAT'S WHAT YOU WANT TO DO.
+ */
+void task_mod(char *name, funcp_t func, void *cookie)
+{
+ tcb_t *t = cur_task;
+ t->name = name;
+ t->func = func;
+ t->cookie = cookie;
+ t->state = TASK_INIT;
+ t->stack_ptr = t->stack_base + t->stack_len;
+ for (uint32_t *p = (uint32_t *)t->stack_base; p < (uint32_t *)t->stack_ptr; ++p)
+ *p = STACK_GUARD_WORD;
+ __set_MSP((uint32_t)cur_task->stack_ptr);
+ task_yield();
+}
+
/* Set the idle hook function pointer.
*
* This function is called repeatedly when the system is idle (there are
@@ -232,11 +250,11 @@ void task_yield(void)
/* If there are no other runnable tasks (and cur_task is runnable),
* we don't need to context-switch.
*/
- if (next == cur_task)
+ if (next == cur_task && cur_task->state != TASK_INIT)
return;
/* Save current context, if there is one. */
- if (cur_task != NULL) {
+ if (cur_task != NULL && cur_task->state != TASK_INIT) {
__asm("push {r0-r12, lr}");
cur_task->stack_ptr = (void *)__get_MSP();