/*---------------------------------------------------------------------------*/ void dhcpc_request(void) { uip_ipaddr_t ipaddr; if(s.state == STATE_INITIAL) { uip_ipaddr(&ipaddr, 0,0,0,0); uip_sethostaddr(&ipaddr); s.task = posTaskCreate(dhcpTask, NULL, 1, 1000); POS_SETTASKNAME(s.task, "uip:dhcpc"); } }
void httpdTask(void* arg) { int lsn; socklen_t addrlen; #if UIP_CONF_IPV6 struct sockaddr_in6 me; struct sockaddr_in6 peer; me.sin6_family = AF_INET6; me.sin6_addr = in6addr_any; me.sin6_port = htons(80); #else struct sockaddr_in me; struct sockaddr_in peer; me.sin_family = AF_INET; me.sin_addr.s_addr = INADDR_ANY; me.sin_port = htons(80); #endif lsn = socket(AF_INET, SOCK_STREAM, 0); bind(lsn, (struct sockaddr*)&me, sizeof(me)); listen(lsn, 5); while (true) { int s = accept(lsn, (struct sockaddr*)&peer, &addrlen); if (s == -1) continue; POSTASK_t task; task = posTaskCreate(httpClientTask, (void*)(intptr_t)s, 1, 1200); if (task == NULL) { #if NOSCFG_FEATURE_CONOUT == 1 nosPrint(TRACENAME "out of tasks."); #endif closesocket(s); } POS_SETTASKNAME(task, "httpc"); } }
void netInit() { POSTASK_t t; int i; uipGiant = posSemaCreate(0); uipMutex = posMutexCreate(); pollTicks = INFINITE; P_ASSERT("netInit", uipGiant != NULL && uipMutex != NULL); POS_SETEVENTNAME(uipGiant, "uip:giant"); POS_SETEVENTNAME(uipMutex, "uip:mutex"); // uosFS setup netFS.base.mountPoint = "/socket"; netFS.base.cf = &netFSConf; uosMount(&netFS.base); // Initialize contiki-style timers (used by uip code) etimer_init(); dataToSend = 0; for(i = 0; i < UIP_CONNS; i++) uip_conns[i].appstate.file = NULL; #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) uip_udp_conns[i].appstate.file = NULL; #endif /* UIP_UDP */ netInterfaceInit(); uip_init(); #if NETSTACK_CONF_WITH_IPV6 == 0 uip_arp_init(); #endif t = posTaskCreate(netMainThread, NULL, NETCFG_TASK_PRIORITY, NETCFG_STACK_SIZE); P_ASSERT("netInit2", t != NULL); POS_SETTASKNAME(t, "uip:main"); }
static void nano_init(void *arg) { #if NOSCFG_FEATURE_REGISTRY != 0 REGELEM_t re; #endif POS_SETTASKNAME(posCurrentTask_g, "root task"); #if POSCFG_TASKSTACKTYPE == 0 posCurrentTask_g->nosstkroot = arg; posCurrentTask_g->exithook = nos_taskExitHook; #else (void) arg; #if NOSCFG_FEATURE_REGISTRY != 0 posCurrentTask_g->exithook = nos_taskExitHook; #endif #endif #if NOSCFG_FEATURE_CPUUSAGE != 0 nano_initCpuUsage(); #endif #if NOSCFG_FEATURE_REGISTRY != 0 nos_initRegistry(); #endif #if (NOSCFG_FEATURE_CONIN != 0) || (NOSCFG_FEATURE_CONOUT != 0) nos_initConIO(); #endif #if NOSCFG_FEATURE_BOTTOMHALF != 0 nos_initBottomHalfs(); #endif #if NOSCFG_FEATURE_REGISTRY != 0 re = nos_regNewSysKey(REGTYPE_TASK, "root-task"); if (re != NULL) { nos_regEnableSysKey(re, posTaskGetCurrent()); } #endif (taskparams_g.func)(taskparams_g.arg); }
NOSTASK_t POSCALL nosTaskCreate(POSTASKFUNC_t funcptr, void *funcarg, VAR_t priority, UINT_t stacksize, const char* name) { POSTASK_t task; #if NOSCFG_FEATURE_REGISTRY != 0 REGELEM_t re; #endif #if POSCFG_TASKSTACKTYPE == 0 void *stk; #endif #if NOSCFG_FEATURE_REGISTRY != 0 re = nos_regNewSysKey(REGTYPE_TASK, name == NULL ? (const char*)"t*" : name); if (re == NULL) return NULL; #else (void) name; #endif /*===============================================*/ #if POSCFG_TASKSTACKTYPE == 0 if (stacksize == 0) stacksize = NOSCFG_DEFAULT_STACKSIZE; task = NULL; stk = nosMemAlloc(NOSCFG_STKMEM_RESERVE + stacksize); if (stk != NULL) { posTaskSchedLock(); #if NOSCFG_STACK_GROWS_UP == 0 task = posTaskCreate(funcptr, funcarg, priority, (void*) (((MEMPTR_t)stk) + stacksize - (NOSCFG_STKMEM_RESERVE + 1))); #else task = posTaskCreate(funcptr, funcarg, priority, (void*) (((MEMPTR_t)stk) + NOSCFG_STKMEM_RESERVE)); #endif if (task != NULL) { task->nosstkroot = stk; task->exithook = nos_taskExitHook; #if NOSCFG_FEATURE_REGISTRY != 0 nos_regEnableSysKey(re, task); POS_SETTASKNAME(task, re->name); #else POS_SETTASKNAME(task, name); #endif } posTaskSchedUnlock(); #if POSCFG_FEATURE_SLEEP != 0 posTaskSleep(0); #elif POSCFG_FEATURE_YIELD != 0 posTaskYield(); #endif } /*-----------------------------------------------*/ #elif POSCFG_TASKSTACKTYPE == 1 if (stacksize == 0) stacksize = NOSCFG_DEFAULT_STACKSIZE; #if NOSCFG_FEATURE_REGISTRY != 0 posTaskSchedLock(); #endif task = posTaskCreate(funcptr, funcarg, priority, stacksize); #if NOSCFG_FEATURE_REGISTRY != 0 if (task != NULL) { task->exithook = nos_taskExitHook; nos_regEnableSysKey(re, task); POS_SETTASKNAME(task, re->name); } posTaskSchedUnlock(); #else POS_SETTASKNAME(task, name); #endif /*-----------------------------------------------*/ #elif POSCFG_TASKSTACKTYPE == 2 #if NOSCFG_FEATURE_REGISTRY != 0 posTaskSchedLock(); #endif (void) stacksize; task = posTaskCreate(funcptr, funcarg, priority); #if NOSCFG_FEATURE_REGISTRY != 0 if (task != NULL) { task->exithook = nos_taskExitHook; nos_regEnableSysKey(re, task); POS_SETTASKNAME(task, re->name); } posTaskSchedUnlock(); #else POS_SETTASKNAME(task, name); #endif #endif /* POSCFG_TASKSTACKTYPE == 2 */ /*===============================================*/ #if NOSCFG_FEATURE_REGISTRY != 0 if (task == NULL) { nos_regDelSysKey(REGTYPE_TASK, NULL, re); } #endif return (POSTASK_t) task; }
void initHttpd() { POSTASK_t task; task = posTaskCreate(httpdTask, NULL, 2, 400); POS_SETTASKNAME(task, "httpd"); }