arch/arm/nrf5x/board_initialize.c
/*
 * cpu_inittask - creates the initial state for a task
 *
 */
creates the initial state for a task
creates the initial state for a task
int cpu_inittask(tcb_t *task_tcb, int argc, char **argv)
{
  void **mcu_context = calloc(REG_NUMS, sizeof(void *));
  if (mcu_context == NULL)
  {
    return -ENOMEM;
  }
  void *bottom_sp = (unsigned int)task_tcb->stack_ptr_top - 8 * sizeof(void *);
  mcu_context[REG_R0]   = (void *)argc;
  mcu_context[REG_R1]   = (void *)argv;
  mcu_context[REG_LR]   = (void *)sched_default_task_exit_point;
  mcu_context[REG_PC]   = (void *)task_entry_point;
  mcu_context[REG_XPSR] = (void *)0x1000000;
  mcu_context[REG_SP]   = bottom_sp;
  cpu_stacking_s *initial_stack = (cpu_stacking_s *)bottom_sp;
  initial_stack->r0 = (void *)argc;
  initial_stack->r1 = (void *)argv;
  initial_stack->lr = (void *)sched_default_task_exit_point;
  initial_stack->pc = (void *)task_entry_point;
  initial_stack->xpsr = (void *)0x1000000;
  task_tcb->mcu_context = mcu_context;
  return 0;
}
int cpu_inittask ( tcb_t * task_tcb , int argc , char * * argv ) { void * * mcu_context = calloc ( REG_NUMS , sizeof ( void * ) ) ; if ( mcu_context == NULL ) { return - ENOMEM ; } void * bottom_sp = ( unsigned int ) task_tcb -> stack_ptr_top - 8 * sizeof ( void * ) ; mcu_context [ REG_R0 ] = ( void * ) argc ; mcu_context [ REG_R1 ] = ( void * ) argv ; mcu_context [ REG_LR ] = ( void * ) sched_default_task_exit_point ; mcu_context [ REG_PC ] = ( void * ) task_entry_point ; mcu_context [ REG_XPSR ] = ( void * ) 0x1000000 ; mcu_context [ REG_SP ] = bottom_sp ; cpu_stacking_s * initial_stack = ( cpu_stacking_s * ) bottom_sp ; initial_stack -> r0 = ( void * ) argc ; initial_stack -> r1 = ( void * ) argv ; initial_stack -> lr = ( void * ) sched_default_task_exit_point ; initial_stack -> pc = ( void * ) task_entry_point ; initial_stack -> xpsr = ( void * ) 0x1000000 ; task_tcb -> mcu_context = mcu_context ; return 0 ; }
cpu_inittask - creates the initial state for a task
cpu_inittask - creates the initial state for a task
/* Initial MCU context */ /* Setup the initial stack */ /* Setup the initial stack context  */