static REGELEM_t POSCALL n_regAlloc(void) { REGELEM_t re; #if NOS_REGKEY_PREALLOC > 1 UVAR_t i; #endif re = reglist_free_g; if (re != NULL) { reglist_free_g = re->next; } else { #if NOS_REGKEY_PREALLOC > 1 re = (REGELEM_t) nosMemAlloc( NOS_REGKEY_PREALLOC * ALIGNEDSIZE(sizeof(struct regelem)) ); if (re == NULL) return NULL; for (i=0; i<NOS_REGKEY_PREALLOC-1; ++i) { re->next = reglist_free_g; reglist_free_g = re; re = NEXTALIGNED(REGELEM_t, re); } #else re = (REGELEM_t) nosMemAlloc(sizeof(struct regelem)); if (re == NULL) return NULL; #endif } RESET_REFCOUNT(re); MARK_INVISIBLE(re); re->handle.generic = NULL; #ifdef POS_DEBUGHELP re->name[NOS_MAX_REGKEYLEN] = 0; #endif return re; }
void* POSCALL nosMessageAlloc(UINT_t msgSize) { void *buf; #if POSCFG_MSG_MEMORY != 0 if (msgSize > POSCFG_MSG_BUFSIZE) return NULL; buf = posMessageAlloc(); #else #if NOSCFG_FEATURE_MEMALLOC == 0 #error NOSCFG_FEATURE_MEMALLOC not enabled #endif buf = nosMemAlloc(msgSize); #endif return buf; }
NOSREGQHANDLE_t POSCALL nosRegQueryBegin(NOSREGTYPE_t type) { REGQUERY_t rq; if (type > MAX_REGTYPE) return NULL; rq = (REGQUERY_t) nosMemAlloc(sizeof(struct regquery)); if (rq != NULL) { rq->queryElem = NULL; rq->type = type; } return (NOSREGQHANDLE_t) rq; }
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; }