On Time RTOS-32 Documentation
Welcome
RTTarget-32
RTKernel-32
RTKernel-32 Programming Manual
RTKernel-32 Reference Manual
Module RTKernel-32
RTKernel-32 Configuration
Function RTKernelInit
Task Management
Enquiring Tasks
Time
Semaphores
Mailboxes
Message Passing
Interrupt Handling
Memory Pools
Kernel Tracer
Spinlocks
Miscellaneous RTKernel-32 Operations
Function RTKDebugVersion
Function RTKInitialized
Function RTKStackCheck
Function RTKCanPreempt
Function RTKPreemptionsON
Function RTKPreemptionsOFF
Function RTKScheduler
Function RTKSetMessageHandler
Function RTKSetTaskSwitchHook
Function RTKSetTaskStartStopHook
Function RTKFatalError
Function RTKInstallExitTask
Function RTKExit
Function RTKAlloc
Function RTKDeallocTerminatedTasks
Function RTKWin32ToRTKHandle
Function RTKToWin32Handle
Port I/O Functions
Module FineTime
Module Clock
Module Timer
Module RTCom
Module RTKeybrd
Module RTTextIO
Module CPUMoni
Module RTProf
RTFiles-32
RTIP-32
RTPEG-32
RTUSB-32
|
Function RTKInstallExitTask
RTKInstallExitTask installs an Exit Task if none has been created already:
void RTKInstallExitTask(unsigned StackSize,
unsigned long Flags,
const char * Name);
The three parameters are used as follows by RTKInstallExitTask:
if (Name == NULL)
Name = "Exit Task";
RTKCreateThread(ExitTask, RTK_MAX_PRIO, StackSize, Flags, NULL, Name);
The Exit Task created with this function can be used later to terminate the program with RTKExit in a defined context. RTKExit sends a message to the Exit Task which will then call C/C++ run-time system function exit(). Function exit() will then execute all exit handlers installed by the application through atexit() (including RTKernel-32's exit handler installed by RTKernelInit).
Terminating a program through the Exit Task can become necessary when the program context is undefined. For example, a program cannot be terminated directly from an interrupt handler or from an Idle Task. However, termination via the Exit Task is still possible in these cases.
The Exit Task is particularly useful for application debugging. Frequently, program execution is suspended by interrupting the program in an arbitrary context, and then restarted. Safe program termination is only possible through the Exit Task in this situation. For this reason, RTKernelInit calls
RTKInstallExitTask(0, 0, NULL);
RTCallDebugger(RT_DBG_CALLRESET, (DWORD)RTKExit, 0);
RTSetExitHandler(RTKExit);
at program startup if the program is running under the RTTarget-32 Debug Monitor and kernel flag RF_NO_EXIT_TASK has not been set by the application. Thus, applications usually do not need to call RTKInstallExitTask explicitly.
The recommended setup to ensure safe program termination or restart is:
- Install exit handlers using atexit() for all On Time RTOS-32 components which need to be shut down at program termination. For RTFiles-32, install RTFShutDown. For RTUSB-32, install RTUShutDown. For RTIP-32, install a custom exit handler which calls xn_interface_close for each opened interface (preferably interface option IO_HARD_CLOSE should be set for each interface).
- If the application contains custom software which programs devices to generate interrupts, install an exit handler with atexit() which programs the hardware to no longer generate interrupts.
- For applications using RTKernel-32, do not set kernel flag RF_NO_EXIT_TASK and do not call RTKInstallExitTask, RTCallDebugger(RT_DBG_CALLRESET, ...) or RTSetExitHandler.
- For applications not using RTKernel-32, call RTSetExitHandler(exit) and RTCallDebugger(RT_DBG_CALLRESET, (DWORD) exit, 0).
Function RTKFatalError
Function RTKExit
|