summaryrefslogtreecommitdiff
path: root/nuttx/arch/8051/src/up_blocktask.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/arch/8051/src/up_blocktask.c')
-rw-r--r--nuttx/arch/8051/src/up_blocktask.c113
1 files changed, 54 insertions, 59 deletions
diff --git a/nuttx/arch/8051/src/up_blocktask.c b/nuttx/arch/8051/src/up_blocktask.c
index 554111ae0..018577477 100644
--- a/nuttx/arch/8051/src/up_blocktask.c
+++ b/nuttx/arch/8051/src/up_blocktask.c
@@ -85,88 +85,83 @@
void up_block_task(FAR struct tcb_s *tcb, tstate_t task_state)
{
+ FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head;
+ bool switch_needed;
+
/* Verify that the context switch can be performed */
- if ((tcb->task_state < FIRST_READY_TO_RUN_STATE) ||
- (tcb->task_state > LAST_READY_TO_RUN_STATE))
- {
- PANIC(OSERR_BADBLOCKSTATE);
- }
- else
- {
- FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head;
- bool switch_needed;
+ ASSERT((tcb->task_state >= FIRST_READY_TO_RUN_STATE) &&
+ (tcb->task_state <= LAST_READY_TO_RUN_STATE));
- dbg("Blocking TCB=%p\n", tcb);
+ dbg("Blocking TCB=%p\n", tcb);
- /* Remove the tcb task from the ready-to-run list. If we
- * are blocking the task at the head of the task list (the
- * most likely case), then a context switch to the next
- * ready-to-run task is needed. In this case, it should
- * also be true that rtcb == tcb.
- */
+ /* Remove the tcb task from the ready-to-run list. If we
+ * are blocking the task at the head of the task list (the
+ * most likely case), then a context switch to the next
+ * ready-to-run task is needed. In this case, it should
+ * also be true that rtcb == tcb.
+ */
- switch_needed = sched_removereadytorun(tcb);
+ switch_needed = sched_removereadytorun(tcb);
- /* Add the task to the specified blocked task list */
+ /* Add the task to the specified blocked task list */
- sched_addblocked(tcb, (tstate_t)task_state);
+ sched_addblocked(tcb, (tstate_t)task_state);
- /* If there are any pending tasks, then add them to the g_readytorun
- * task list now
- */
+ /* If there are any pending tasks, then add them to the g_readytorun
+ * task list now
+ */
- if (g_pendingtasks.head)
- {
- switch_needed |= sched_mergepending();
- }
+ if (g_pendingtasks.head)
+ {
+ switch_needed |= sched_mergepending();
+ }
- /* Now, perform the context switch if one is needed */
+ /* Now, perform the context switch if one is needed */
- if (switch_needed)
+ if (switch_needed)
+ {
+ /* Are we in an interrupt handler? */
+
+ if (g_irqtos)
{
- /* Are we in an interrupt handler? */
+ /* Yes, then we have to do things differently.
+ * Just copy the current registers into the OLD rtcb.
+ */
- if (g_irqtos)
- {
- /* Yes, then we have to do things differently.
- * Just copy the current registers into the OLD rtcb.
- */
+ up_saveirqcontext(&tcb->xcp);
- up_saveirqcontext(&tcb->xcp);
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
+ */
- /* Restore the exception context of the rtcb at the (new) head
- * of the g_readytorun task list.
- */
+ rtcb = (FAR struct tcb_s*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
- rtcb = (FAR struct tcb_s*)g_readytorun.head;
- dbg("New Active Task TCB=%p\n", rtcb);
+ /* Then setup so that the context will be performed on exit
+ * from the interrupt.
+ */
- /* Then setup so that the context will be performed on exit
- * from the interrupt.
- */
+ g_irqcontext = &rtcb->xcp;
+ }
- g_irqcontext = &rtcb->xcp;
- }
+ /* Copy the user C context into the TCB at the (old) head of the
+ * g_readytorun Task list. if up_savecontext returns a non-zero
+ * value, then this is really the previously running task restarting!
+ */
- /* Copy the user C context into the TCB at the (old) head of the
- * g_readytorun Task list. if up_savecontext returns a non-zero
- * value, then this is really the previously running task restarting!
+ else if (!up_savecontext(&rtcb->xcp))
+ {
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
*/
- else if (!up_savecontext(&rtcb->xcp))
- {
- /* Restore the exception context of the rtcb at the (new) head
- * of the g_readytorun task list.
- */
-
- rtcb = (FAR struct tcb_s*)g_readytorun.head;
- dbg("New Active Task TCB=%p\n", rtcb);
+ rtcb = (FAR struct tcb_s*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
- /* Then switch contexts */
+ /* Then switch contexts */
- up_restorecontext(&rtcb->xcp);
- }
+ up_restorecontext(&rtcb->xcp);
}
}
}