/** * @brief Context switch to the highest priority task while saving off the * current task state. * * This function needs to be externally synchronized. * We could be switching from the idle task. The priority searcher has been tuned * to return IDLE_PRIO for a completely empty run_queue case. */ void dispatch_save(void) { if(cur_tcb->cur_prio == HIGHEST_PRIO) return; tcb_t *dest, *temp; temp = cur_tcb; uint8_t hp = highest_prio(); /* If the idle task is he only next high prio task that means we are already running idle task */ if(hp == IDLE_PRIO) dest = cur_tcb; else dest = runqueue_remove(hp); /* Set cur_tcb to the task that we are about to run */ cur_tcb = dest; /* Set the cur_kstack var of the task that we are about to run */ cur_kstack = (int)dest->kstack_high; /* Add the task that we just switched from back to the queue */ runqueue_add(temp, temp->cur_prio); ctx_switch_full(&(dest->context), &(temp->context)); }
/** * @brief Context switch to the highest priority task while saving off the * current task state. * * This function needs to beexternally synchronized. * We could be switching from the idle task. The priority searcher has been tuned * to return IDLE_PRIO for a completely empty run_queue case. */ void dispatch_save(void) { uint8_t next_prio; tcb_t *next_tcb, *saved_cur_tcb; // printf("inside dispatch save\n"); // printf("added cur_tcb %u %p to run queue\n", cur_tcb->cur_prio, cur_tcb); next_prio = highest_prio(); /* * add the current task to the run queue... */ runqueue_add(cur_tcb, cur_tcb->cur_prio); // printf("next_prio is %u\n", next_prio); next_tcb = runqueue_remove(next_prio); // printf(" d save: removed next_tcb %u %p from run queue\n", next_tcb->cur_prio, next_tcb); // print_run_queue(); saved_cur_tcb = cur_tcb; cur_tcb = next_tcb; #if 0 printf("before calling ctx sw full, cur->context is %p\n", &(saved_cur_tcb->context)); printf("hexdump of cur->context is\n"); hexdump(&saved_cur_tcb->context, 160); printf("before calling ctx sw full, next->context is %p\n", &(next_tcb->context)); printf("hexdump of next->context is\n"); hexdump(&next_tcb->context, 160); #endif // disable_interrupts(); ctx_switch_full((volatile void *)(&(next_tcb->context)), (volatile void *)(&(saved_cur_tcb->context))); // while(1); }
/** * @brief Context switch to the highest priority task that is not this task -- * and save the current task but don't mark is runnable. * * There is always an idle task to switch to. */ void dispatch_sleep(void) { uint8_t next_prio; tcb_t *next_tcb, *saved_cur_tcb; // printf("inside dispatch sleep\n"); next_prio = highest_prio(); // printf("next_prio is %u\n", next_prio); next_tcb = runqueue_remove(next_prio); // printf("d sleep: removed next_tcb %u %p from run queue\n", next_tcb->cur_prio, next_tcb); // print_run_queue(); saved_cur_tcb = cur_tcb; cur_tcb = next_tcb; // printf("before calling ctx sw full, next->context->sp is %p\n", next_tcb->context.sp); // printf("before calling ctx sw full, cur->context->sp is %p\n", saved_cur_tcb->context.sp); // printf("in dispatch sleep, sp is %u\n", get_kernel_sp()); // hexdump(get_kernel_sp(), 200); // disable_interrupts(); // printf("inside dispatch sleep hexdump of cur->context is\n"); // hexdump(&saved_cur_tcb->context, 160); ctx_switch_full((volatile void *)(&(next_tcb->context)), (volatile void *)(&(saved_cur_tcb->context))); // while(1); }
/** * @brief Context switch to the highest priority task while saving off the * current task state. * * This function needs to be externally synchronized. * We could be switching from the idle task. The priority searcher has been tuned * to return IDLE_PRIO for a completely empty run_queue case. */ void dispatch_save(void) { uint8_t prio = highest_prio(); tcb_t *next_task = runqueue_remove(prio); //Enqueue current task runqueue_add(cur_tcb, cur_tcb->cur_prio); tcb_t *tmp_task = cur_tcb; cur_tcb = next_task; ctx_switch_full(&(next_task->context), &(tmp_task->context)); }
/** * @brief Context switch to the highest priority task that is not this task -- * and save the current task but don't mark is runnable. * * There is always an idle task to switch to. */ void dispatch_sleep(void) { uint8_t prio = highest_prio(); //printf("Highest prio is %d\n",prio); tcb_t *next_task = runqueue_remove(prio); tcb_t *tmp_task = cur_tcb; cur_tcb = next_task; ctx_switch_full(&(next_task->context), &(tmp_task->context)); }
/** * @brief Context switch to the highest priority task that is not this task -- * and save the current task but don't mark is runnable. * * There is always an idle task to switch to. */ void dispatch_sleep(void) { /* Similar implementation as dispatch_save but let the current task sleep, and don't * add it into the runqueue */ uint8_t prio = highest_prio(); tcb_t *new_task; new_task = runqueue_remove(prio); sched_context_t *cur_ctx = &(cur_tcb -> context); cur_tcb = new_task; ctx_switch_full(&(new_task -> context), cur_ctx); }
/** * @brief Context switch to the highest priority task while saving off the * current task state. * * This function needs to be externally synchronized. * We could be switching from the idle task. The priority searcher has been tuned * to return IDLE_PRIO for a completely empty run_queue case. */ void dispatch_save(void) { tcb_t *new_task; tcb_t *old_task = cur_tcb; uint8_t prio = highest_prio(); /* If the current task is not the highest priority task */ if (old_task -> cur_prio > prio) { new_task = runqueue_remove(prio); sched_context_t *old_ctx = &(old_task -> context); runqueue_add(old_task, old_task -> cur_prio); cur_tcb = new_task; /* !!! ctx_switch_full has not yet implemented */ ctx_switch_full(&(new_task -> context), old_ctx); } }
/** * @brief Context switch to the highest priority task that is not this task -- * and save the current task but don't mark is runnable. * * There is always an idle task to switch to. */ void dispatch_sleep(void) { tcb_t *dest, *temp; temp = cur_tcb; uint8_t cp = get_cur_prio(); /* i.e task that was just put to sleep */ uint8_t hp = highest_prio(); /* next task to run */ /* Run idle task if there are no other */ if(cp == hp) dest = runqueue_remove(IDLE_PRIO); else dest = runqueue_remove(hp); /* Set cur_tcb to the task that we are about to run */ cur_tcb = dest; /* Set the cur_kstack var of the task that we are about to run */ cur_kstack = (int)dest->kstack_high; ctx_switch_full(&(dest->context), &(temp->context)); }