Exemplo n.º 1
0
status_t devices_init(void)
{
    bsp_task_init();
    gpio_init();
    key_init();
    return OK;
}
Exemplo n.º 2
0
/*-----------------------------------------------------------------------*/
task_t task_create(char *name, void (*task_func)(void *), void *parm, char *stack_base,
	size_t stack_size, uint8_t pri, uint32_t slice, uint32_t flags)
{
	uint32_t f;
	int i;
	struct dtask *task = NULL;

	if(pri >= MAX_PRIORITY_LEVEL)
		pri = pri/(256/MAX_PRIORITY_LEVEL);

	if(name == NULL || task_func == NULL)
		return RERROR;

	if(stack_size <= 100)
		return RERROR;
	
	/* find an unused task control block */
	SYS_FSAVE(f);
	for(i=1; i<MAX_TASK_NUMBER; i++)
	{
		if(systask[i].state == TASK_STATE_DEAD)
		{
			task = &systask[i];
			memset(task, 0, sizeof(struct dtask));
			task->state = TASK_STATE_SUSPEND;
			break;
		}
	}
	SYS_FRESTORE(f);
	if(task == NULL)
		return RERROR;

	if(stack_base == NULL)
		stack_base = malloc(stack_size);
	else
		flags |= TASK_FLAGS_STATICSTACK;
	
	if(stack_base)
	{
		memset(stack_base, TASK_STACK_INIT_CHAR, stack_size);
		task->sp = bsp_task_init(i, task_func, parm, (char *)(stack_base+stack_size-4), task_exit);

		strncpy((char *)systask[i].name, name, TASK_NAME_MAX_LENGTH-1);
		task->flags = flags;
		task->priority = pri;
		task->pri_origin = pri;
		task->timeslice_all = slice;
		task->timeslice_left = slice;
		task->stack_base = stack_base;
		task->stack_size = stack_size;
		task->taskq = NULL;
		task->errcode = 0;
		task->t_delay.onexpired_func = task_timeout;
		task->t_delay.param[0] = i;

#ifdef INCLUDE_JOURNAL
		journal_task_create(task);
#endif
#ifdef INCLUDE_PMCOUNTER
		PMC_PEG_COUNTER(PMC_sys32_counter[PMC_U32_nTask],1);
#endif

		return i;
	}
	else
	{
		SYS_FSAVE(f);
		task->state = TASK_STATE_DEAD;
		SYS_FRESTORE(f);
		return RERROR;
	}
}