【文章內(nèi)容簡介】
LOC_STACK option or, Using a delete hook. taskDelete(tid) 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Resource Reclamation Contrary to the philosophy of sharing system resources among all tasks. Can be an expensive process, which must be the application?s responsibility. TCB and stack are the only resources automatically reclaimed. Tasks are responsible for cleaning up after themselves. Deallocating memory. Releasing locks to system resources. Closing files which are open. Deleting child / client tasks when parent / server exits. 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 RealTime Multitasking Introduction Task Basics Task Control Error Status System Tasks 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Task Restart taskRestart (tid) Task is terminated and respawned with original arguments and tid. Usually used for error recovery. 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Task Suspend / Resume taskSuspend (tid) Makes task ineligible to execute. Can be added to pended or delayed state. taskResume (tid) Removes suspension. Usually used for debugging and development purposes. 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Task Delay To delay a task for a specified number of system clock ticks. To poll every 1/7 second: FOREVER { taskDelay (sysClkRateGet() / 7)。 ... } STATUS taskDelay (ticks) Use sysClkRateSet() to change the clock rate. Accurate only if clock rate is a multiple of seven ticks / seconds. Can suffer from “drift.” 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Reentrancy and Task Variables If tasks access the same global or static variables, the resource can bee corrupted (called a race condition). Possible Solutions: Task Variables cause a 32bit value to be saved and restored on context switchs, like a register. Use only stack variables in applications. Protect the resource with a semaphore. Use task variables to make the variable private to a task Caveat: task variables increase context switch times. See the taskVarLib manual pages for details. 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Task Hooks Userdefined code can be executed on every context switch, at task creation, or at task deletion: taskSwitchHookAdd () taskCreateHookAdd () taskDeleteHookAdd () VxWorks uses a switch hook to implement task variables. See manual pages on taskHookLib for details. 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Task Information Like i(), but also displays: Can also use show (): show (tNetTask, 1) Stack information Task options CPU registers FPU registers (if the VX_FP_TASK option bit is set) ti (taskNameOrId) 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Task Browser To obtain information about a specific task, click on the task?s summary line in the main target browser. 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 What is POSIX ? Originally, an IEEE mittee convened to create a standard interface to UNIX for: VxWors supports almost all of the POSIX Realtime Extensions. Increased portability. Convenience. Context switch times are very fast. Text, data, and bss are stored in a mon, global address space. The POSIX realtime extensions are based on implicit assumptions about the UNIX process model which do not always hold in VxWorks. In VxWorks, 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 What does VxWorks support ? Library Description aioPxLib Asynchornous I/O semPxLib POSIX Semaphores mqPxLib POSIX Message Queues mmanPxLib POSIX Memory Management schedPxLib POSIX Scheduler Interface sigLib POSIX Signals timerLib, clockLib POSIX Timer/Clock Interface dirLib File/Directory Information 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 RealTime Multitasking Introduction Task Basics Task Control Error Status System Tasks 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Error Status ? VxWorks里使用一個全局整型變量 errno來描述錯誤信息 – 程序執(zhí)行過程中我們可以設(shè)置并調(diào)用一些函數(shù)例程來檢測錯誤信息,并針對錯誤信息設(shè)置相應(yīng)的錯誤號 – 然后調(diào)用一些函數(shù)例程檢測錯誤號,當(dāng)程序執(zhí)行異常時可以根據(jù)錯誤號發(fā)現(xiàn)相應(yīng)的錯誤 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Errno and Context Switches At each context switch, the kernel saves and restores the value of errno. TCB errorStatus errno 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Setting Errno Lowest level routine to detect an error sets errno and returns ERROR: STATUS myRoutine () { ... if (myNumFlurbishes = MAX_FLURBISH) { errno = s_myLib_TOO_MANY_FLURBISHES。 return (ERROR)。 } … pMem=malloc(sizeof(myStruct))。 if ( pMem== NULL) { /* malloc() sets errno don’t redefine it */ return (ERROR)。 } ... } 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Examining Errno Examine errno to find out why a routine failed. if (reactorOk() == ERROR) { switch (errno) { case S_rctorLib_TEMP_DANGER_ZONE: startShutDown ()。 break。 case S_rctorLib_TEMP_CRITICAL_ZONE: logMsg (“Run!”)。 break。 case S_rctorLib_LEAK_POSSIBLE: checkVessel ()。 break。 default: startEmergProc ()。 } } errno is only valid after an error occurs. 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Interpreting Errno VxWorks uses the 32bit value errno as follows: Module numbers are defined in . Each module defines its own error numbers in its header file. Module number 0x11 (define in to be memLib) and Error number 0x01 (defined in to be “not enough memory”). For example, an errno of 0x110001 would be: module error number 31 15 0 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 Error Messages VxWorks uses an error symbol table (statSymTbl) to convert error numbers to error messages. To print the error message for the current task?s error status to STD_ERR: perror (“darn”) darn: S_Drv_NO_SUCH_FILE_OR_DIR To print the error message associated with an error number to the WindSh console : printErrno (0x110001) S_memLib_NOT_ENOUGH_MEMORY 嵌入式培訓(xùn)專題 微迪軟件培訓(xùn)中心 UserDefined Error Codes To get perror() to print your error messages: 1. Modify to reserve a module number: define M_myLib (501 16) 2. Define error macros in your header file (which must be in the wind/target/h directory): define S_myLib_BAD_STUFF (M_myLib | 1) 3. Rebu