FreeCalypso > hg > freecalypso-sw
diff gsm-fw/gpf/osl/os_pro_fl.c @ 341:fcbdb2ae1a47
OSL: os_CreateTask() done
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 03 May 2014 12:24:56 +0000 |
parents | de7141ad907e |
children | 1c94c36ca3e4 |
line wrap: on
line diff
--- a/gsm-fw/gpf/osl/os_pro_fl.c Sat May 03 00:33:45 2014 +0000 +++ b/gsm-fw/gpf/osl/os_pro_fl.c Sat May 03 12:24:56 2014 +0000 @@ -16,10 +16,10 @@ typedef unsigned char u_char; +extern VOID *TCD_Current_Thread; extern T_OS_TASK_TABLE_ENTRY TaskTable[]; -extern VOID *TCD_Current_Thread; +extern VOID os_TaskEntry(UNSIGNED, VOID *); -/* .bss */ static NU_SEMAPHORE ProSemCB; #define OS_NU_TASK_MAGIC 0xdeafbeef @@ -63,7 +63,7 @@ return(OS_ERROR); Untouched = 0; for (sp = StackBase; sp < StackBase + Size; sp++) { - if (*sp != 0xFE) + if (*sp != INITIAL_STACK_VALUE) break; Untouched++; } @@ -186,3 +186,43 @@ NU_Release_Semaphore(&ProSemCB); return(OS_OK); } + +GLOBAL LONG +os_CreateTask(OS_HANDLE Caller, char *Name, + void (*TaskEntry)(OS_HANDLE, ULONG), ULONG StackSize, + USHORT Priority, OS_HANDLE *TaskHandle, OS_HANDLE MemPoolHandle) +{ + STATUS sem_sts; + USHORT Handle; + u_char *stack; + + sem_sts = NU_Obtain_Semaphore(&ProSemCB, NU_SUSPEND); + for (Handle = 1; Handle <= MaxTasks; Handle++) + if (!TaskTable[Handle].Name[0]) + break; + if (Handle > MaxTasks) { +return_error: if (sem_sts == NU_SUCCESS) + NU_Release_Semaphore(&ProSemCB); + return(OS_ERROR); + } + if (os_AllocateMemory(Handle, &TaskTable[Handle].Stack, StackSize + 4, + 0, MemPoolHandle) != OS_OK) + goto return_error; + stack = (u_char *)TaskTable[Handle].Stack + 4; + memset(stack, INITIAL_STACK_VALUE, StackSize); + *TaskTable[Handle].Stack = GUARD_PATTERN; + if (NU_Create_Task(&TaskTable[Handle].TaskCB.TCB, Name, os_TaskEntry, + Handle, 0, stack, StackSize, + 255 - Priority, 0, NU_PREEMPT, NU_NO_START) + != NU_SUCCESS) + goto return_error; + strncpy(TaskTable[Handle].Name, Name, RESOURCE_NAMELEN); + TaskTable[Handle].Name[RESOURCE_NAMELEN-1] = 0; + TaskTable[Handle].TaskEntry = TaskEntry; + TaskTable[Handle].TaskCB.magic_nr = OS_NU_TASK_MAGIC; + TaskTable[Handle].TaskCB.handle = Handle; + *TaskHandle = Handle; + if (sem_sts == NU_SUCCESS) + NU_Release_Semaphore(&ProSemCB); + return(OS_OK); +}