Пример #1
0
int task_create(task_t* tasks, size_t num_tasks)
{
  size_t i;

  if (num_tasks > OS_MAX_TASKS - 2)
  	return -EINVAL;

  if (!valid_addr(tasks, sizeof(task_t) * num_tasks, USR_START_ADDR, USR_END_ADDR))
  	return -EFAULT;

  task_t *(task_array[OS_MAX_TASKS]);
  for (i = 0; i < num_tasks; i++)
  {
    task_array[i] = &(tasks[i]);
  }

  if (!assign_schedule(task_array, num_tasks))
  {
    return -ESCHED;
  }

  disable_interrupts();
  tasks_created = 1;
  allocate_tasks(task_array, num_tasks);
  dispatch_nosave();

  // This should never return
  return -1;
}
Пример #2
0
int task_create(task_t* tasks, size_t num_tasks) {
    // Sanity checks.
    if (num_tasks > OS_AVAIL_TASKS) return -EINVAL;
    
    /*
     * Assign schedule via RMA scheduling.
     */
    task_t* sorted_tasks[num_tasks];
    size_t i;
    
    // Prep
    for (i = 0; i < num_tasks; i++) {
        sorted_tasks[i] = tasks + i;
    }
    
    INT_ATOMIC_START;
    // Perform UB test.
    if (!assign_schedule(sorted_tasks, num_tasks)) return -EFAULT;
    
    // Init TCBs
    if (!allocate_tasks(sorted_tasks, num_tasks)) return -EFAULT;
    
    // Start device interrupt timer.
    reg_write(OSTMR_OSMR_ADDR(2),
        reg_read(OSTMR_OSCR_ADDR) + get_ticks(DEV_INT_PERIOD));
    
    // Start tasks
    dispatch_nosave();
    INT_ATOMIC_END;
    
    return 0;
}