Beispiel #1
0
/*****************************************************************
*	2015年01月24日10:03:22
*	V1.0 	By Breaker
*
*		u8 task_create(u8 rank, u32 task_func)
*   	任务初始化
*		return 返回任务ID,返回0任务创建失败
*/
u8 task_create(u8 rank, u32 task_func)
{
		/*1.检查参数合法性*/
		if( rank > MAX_rank + 1)
		{
				return NULL;
		}

		/*2.设置TASK_INFO*/
		u8 TID = task_get_id();
		if( NULL == TID )
		{
				return NULL;
		}

		TASK_INFO task_info_this;
		task_info_this.rank = rank;
		task_info_this.status = DEAD ;
		task_info_this.task_func = task_func ;
		task_info[TID] = task_info_this;
		//task_info.TRID 到 task_run 中设置


		/*3.设置tasktable*/
		task_table[TID].sp = (u32)task_stack[TID] + 1024;
		task_table[TID].lr = (u32)task_delete;
		task_table[TID].pc =(u32) task_func;
		task_table[TID].cpsr = 0x53;	//禁止fiq , svc模式
		task_table[TID].spsr = 0x53;
		return TID;
}
static void exec_trampoline(void) {
	sched_unlock();

	kill(task_get_id(task_get_parent(task_self())), SIGCHLD);

	_exit(exec_call());
}
Beispiel #3
0
/** Enable PIO for specified I/O range.
 *
 * @param pio_addr I/O start address.
 * @param size     Size of the I/O region.
 * @param virt     Virtual address for application's
 *                 PIO operations. Can be NULL for PMIO.
 *
 * @return EOK on success.
 * @return Negative error code on failure.
 *
 */
int pio_enable(void *pio_addr, size_t size, void **virt)
{
#ifdef IO_SPACE_BOUNDARY
	if (pio_addr < IO_SPACE_BOUNDARY) {
		if (virt)
			*virt = pio_addr;
		return iospace_enable(task_get_id(), pio_addr, size);
	}
#else
	(void) iospace_enable;
#endif
	if (!virt)
		return EINVAL;

	void *phys_frame =
	    (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE);
	size_t offset = pio_addr - phys_frame;
	size_t pages = SIZE2PAGES(offset + size);
	
	void *virt_page;
	int rc = physmem_map(phys_frame, pages,
	    AS_AREA_READ | AS_AREA_WRITE, &virt_page);
	if (rc != EOK)
		return rc;
	
	*virt = virt_page + offset;
	return EOK;
}
Beispiel #4
0
// Lua: pcm.new( type, pin )
static int pcm_new( lua_State *L )
{
  pud_t *pud = (pud_t *) lua_newuserdata( L, sizeof( pud_t ) );
  cfg_t *cfg = &(pud->cfg);
  int driver;

  cfg->rbuf_idx = cfg->fbuf_idx = 0;
  cfg->isr_throttled = -1;  // start ISR and reader in throttled mode

  driver = luaL_checkinteger( L, 1 );
  luaL_argcheck( L, (driver >= 0) && (driver < PCM_DRIVER_END), 1, "invalid driver" );

  cfg->self_ref      = LUA_NOREF;
  cfg->cb_data_ref   = cfg->cb_drained_ref = LUA_NOREF;
  cfg->cb_paused_ref = cfg->cb_stopped_ref = LUA_NOREF;
  cfg->cb_vu_ref     = LUA_NOREF;

  cfg->bufs[0].buf_size = cfg->bufs[1].buf_size = 0;
  cfg->bufs[0].data     = cfg->bufs[1].data     = NULL;
  cfg->bufs[0].len      = cfg->bufs[1].len      = 0;
  cfg->bufs[0].rpos     = cfg->bufs[1].rpos     = 0;
  cfg->bufs[0].empty    = cfg->bufs[1].empty    = TRUE;

  cfg->data_vu_task    = task_get_id( pcm_data_vu_task );
  cfg->vu_freq         = 10;
  cfg->data_play_task  = task_get_id( pcm_data_play_task );
  cfg->start_play_task = task_get_id( pcm_start_play_task );

  if (driver == PCM_DRIVER_SD) {
    cfg->pin = luaL_checkinteger( L, 2 );
    MOD_CHECK_ID(sigma_delta, cfg->pin);

    pud->drv = &pcm_drv_sd;

    pud->drv->init( cfg );

    /* set its metatable */
    lua_pushvalue( L, -1 );  // copy self userdata to the top of stack
    luaL_getmetatable( L, "pcm.driver" );
    lua_setmetatable( L, -2 );

    return 1;
  } else {
    pud->drv = NULL;
    return 0;
  }
}
Beispiel #5
0
static int xetpriority_match(int which, id_t who, struct task *task) {
	struct task_u_area *task_u_area;
	id_t real_who;
	int is_match;

	if (who != 0) {
		real_who = who;
	} else {
		struct task *self = task_self();
		struct task_u_area *self_u = task_resource_u_area(self);

		switch(which) {
		case PRIO_PROCESS:
			real_who = task_get_id(task_self());
			break;
		case PRIO_PGRP:
			real_who = self_u->regid;
			break;
		case PRIO_USER:
			real_who = self_u->reuid;
			break;
		default:
			assert(0);
		}
	}

	task_u_area = task_resource_u_area(task);

	switch (which) {
	case PRIO_PROCESS:
		is_match = task_get_id(task) == real_who;
		break;
	case PRIO_PGRP:
		is_match = task_u_area->regid == real_who;
		break;
	case PRIO_USER:
		is_match = task_u_area->reuid == real_who;
		break;
	default:
		assert(0);
	}

	return is_match;
}
Beispiel #6
0
void task_init(struct task *tsk, int id, struct task *parent,
		const char *name, struct thread *main_thread,
		task_priority_t priority) {
	assert(tsk == task_kernel_task());
	assert(id == task_get_id(tsk));
	assert(0 == strcmp(name, task_get_name(tsk)));
	assert(main_thread == task_get_main(tsk));
	assert(TASK_PRIORITY_DEFAULT == task_get_priority(tsk));

	if (main_thread != NULL) { /* check for thread.NoThreads module */
		main_thread->task = tsk;
	}

	task_resource_init(tsk);
}
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
#ifdef LUA_USE_MODULES_RTCTIME
    rtctime_late_startup ();
#endif

    UartBautRate br = BIT_RATE_DEFAULT;

    input_sig = task_get_id(handle_input);
    uart_init (br, br, input_sig);

#ifndef NODE_DEBUG
    system_set_os_print(0);
#endif

    system_init_done_cb(nodemcu_init);
}
void nodemcu_init(void)
{
    NODE_ERR("\n");
    // Initialize platform first for lua modules.
    if( platform_init() != PLATFORM_OK )
    {
        // This should never happen
        NODE_DBG("Can not init platform for modules.\n");
        return;
    }

#if defined(FLASH_SAFE_API)
    if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) {
        NODE_ERR("Self adjust flash size.\n");
        // Fit hardware real flash size.
        flash_rom_set_size_byte(flash_safe_get_size_byte());

        if( !fs_format() )
        {
            NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
            NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
        }
        else {
            NODE_ERR( "format done.\n" );
        }
        fs_unmount();   // mounted by format.

        // Reboot to get SDK to use (or write) init data at new location
        system_restart ();

        // Don't post the start_lua task, we're about to reboot...
        return;
    }
#endif // defined(FLASH_SAFE_API)

#if defined ( BUILD_SPIFFS )
    fs_mount();
    // test_spiffs();
#endif
    // endpoint_setup();

    task_post_low(task_get_id(start_lua),'s');
}
Beispiel #9
0
static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request)
{
	ipc_callid_t callid;
	task_id_t task_id;
	size_t len;
	
	task_id = task_get_id();
	
	if (!async_data_read_receive(&callid, &len)) {
		async_answer_0(callid, EINVAL);
		async_answer_0(rid, EINVAL);
		return;
	}
	
	if (len > sizeof(task_id))
		len = sizeof(task_id);
	
	async_data_read_finalize(callid, &task_id, len);
	async_answer_0(rid, EOK);
}
Beispiel #10
0
static size_t tb_snprint_thread_state(char *buff, size_t buff_sz,
		struct thread *t) {
	char *p = buff;
	char *end = buff + buff_sz;
	int is_current = (t == thread_self());

	p += tb_safe_snprintf(p, end-p,
		" --   %08x %c %c %c %c  thread %d  task %d ",
		t->critical_count,
		is_current      ? '*' : ' ',
		sched_active(&t->schedee) ? 'A' : ' ',
		t->schedee.ready        ? 'R' : ' ',
		t->schedee.waiting      ? 'W' : ' ',
		t->id, task_get_id(t->task));

	memset(p, '-', end-p-1);
	*(end-1) = '\0';

	return buff_sz;
}
Beispiel #11
0
/** Program loader main function.
 */
int main(int argc, char *argv[])
{
	/* Set a handler of incomming connections. */
	async_set_client_connection(ldr_connection);
	
	/* Introduce this task to the NS (give it our task ID). */
	task_id_t id = task_get_id();
	int rc = ns_intro(id);
	if (rc != EOK)
		return rc;
	
	/* Register at naming service. */
	rc = service_register(SERVICE_LOAD);
	if (rc != EOK)
		return rc;
	
	async_manager();
	
	/* Never reached */
	return 0;
}
Beispiel #12
0
// Lua: node.task.post([priority],task_cb) -- schedule a task for execution next
static int node_task_post( lua_State* L )
{
  int n = 1, Ltype = lua_type(L, 1);
  unsigned priority = TASK_PRIORITY_MEDIUM;
  if (Ltype == LUA_TNUMBER) {
    priority = (unsigned) luaL_checkint(L, 1);
    luaL_argcheck(L, priority <= TASK_PRIORITY_HIGH, 1, "invalid  priority");
    Ltype = lua_type(L, ++n);
  }
  luaL_argcheck(L, Ltype == LUA_TFUNCTION || Ltype == LUA_TLIGHTFUNCTION, n, "invalid function");
  lua_pushvalue(L, n);

  int task_fn_ref = luaL_ref(L, LUA_REGISTRYINDEX);

  if (!do_node_task_handle)  // bind the task handle to do_node_task on 1st call
    do_node_task_handle = task_get_id(do_node_task);

  if(!task_post(priority, do_node_task_handle, (task_param_t)task_fn_ref)) {
    luaL_unref(L, LUA_REGISTRYINDEX, task_fn_ref);
    luaL_error(L, "Task queue overflow. Task not posted");
  }
  return 0;
}
Beispiel #13
0
int ega_init(void)
{
	sysarg_t present;
	int rc = sysinfo_get_value("fb", &present);
	if (rc != EOK)
		present = false;
	
	if (!present)
		return ENOENT;
	
	sysarg_t kind;
	rc = sysinfo_get_value("fb.kind", &kind);
	if (rc != EOK)
		kind = (sysarg_t) -1;
	
	if (kind != 2)
		return EINVAL;
	
	sysarg_t paddr;
	rc = sysinfo_get_value("fb.address.physical", &paddr);
	if (rc != EOK)
		return rc;
	
	sysarg_t width;
	rc = sysinfo_get_value("fb.width", &width);
	if (rc != EOK)
		return rc;
	
	sysarg_t height;
	rc = sysinfo_get_value("fb.height", &height);
	if (rc != EOK)
		return rc;
	
	rc = iospace_enable(task_get_id(), (void *) EGA_IO_BASE, EGA_IO_SIZE);
	if (rc != EOK)
		return rc;
	
	ega.width = width;
	ega.height = height;
	
	ega.size = (width * height) << 1;
	
	rc = physmem_map((void *) paddr,
	    ALIGN_UP(ega.size, PAGE_SIZE) >> PAGE_WIDTH,
	    AS_AREA_READ | AS_AREA_WRITE, (void *) &ega.addr);
	if (rc != EOK)
		return rc;
	
	sysarg_t blinking;
	rc = sysinfo_get_value("fb.blinking", &blinking);
	if (rc != EOK)
		blinking = false;
	
	ega.style_normal = 0xf0;
	ega.style_inverted = 0x0f;
	
	if (blinking) {
		ega.style_normal &= 0x77;
		ega.style_inverted &= 0x77;
	}
	
	ega.backbuf = NULL;
	
	fbdev_t *dev = fbdev_register(&ega_ops, (void *) &ega);
	if (dev == NULL) {
		as_area_destroy(ega.addr);
		return EINVAL;
	}
	
	return EOK;
}