RtCreateTimer
RtCreateTimer creates a timer associated with the specified clock, and returns a handle to the timer.
Syntax
HANDLE RtCreateTimer( PSECURITY_ATTRIBUTES pThreadAttributes, ULONG StackSize, VOID (RTFCNDCL *Routine) (PVOID context), PVOID Context, ULONG Priority, CLOCK Clock );
Parameters
pThreadAttributes (ignored by RTSS)
An optional pointer to a SECURITY_ATTRIBUTES structure to be used at handler thread creation. Pass in NULL for default.
StackSize
The stack size for handler thread. Use a size of 0 for default.
Routine
A pointer to the routine to be run upon completion. The routine takes a single PVOID argument and returns VOID.
Context
The argument to the routine, cast as a PVOID.
Priority
The handler thread priority as defined below.
Clock
A clock identifier as defined below in the Comments sections.
Return Value
A non-zero handle to the timer if the function succeeds, A NULL handle if the function fails
To set the timer to expire, see RtSetTimer or RtSetTimerRelative. When the timer expires, the specified routine runs with the specified argument.
Remarks
RtCreateTimer allocates a new timer and returns a handle to it. Legal clock values, as enumerated in rtapi.h, are listed below:
Meaning |
|
CLOCK_1 |
One millisecond timer. |
CLOCK_2 |
Real-time HAL timer. Default is 100 microseconds. |
CLOCK_3 |
Real-time HAL timer. Use the actual timer period to set and deliver the clock values, to calculate the expiration values and response latencies of timers based on this clock. |
CLOCK_FASTEST |
The fastest available clock and time on the system. This is usually CLOCK_2. |
CLOCK_SYSTEM |
Same as CLOCK_1. |
The timer routine will run as a separate handling thread. pThreadAttributes, StackSize, and Priority are used to control the creation of the handler thread. See CreateThread and RtSetThreadPriority for details on these parameters.
To run a different handling routine/context, a new timer must be created.
NOTE: When called in a Windows application, RtCreateTimer sets the Win32 timer thread priority to THREAD_PRIORITY_TIME_CRITICAL by default, and sets the proxy thread priority based on the function parameter, Priority. You can change the priority of the Win32 timer thread priority in the first call to the timer handling routine.
NOTE: If you call RtCreateTimer on a system with more than one processor, the processor affinity for the timer handler will default to the affinity of the calling process or thread. For information about setting processor affinity, see RtCreateTimerEx.
NOTE: If your timer period is close to Real-time subsystem’s HAL timer period, the overhead of Subsystem tick processing may cause a much larger response latency of your timer handling routine (IST). In this case, you should configure a much smaller HAL timer period. For example, if your timer period is 100 us, you should configure HAL period to a smaller value, such as 20 us, depending on your processor frequency. See the Control Panel for how to modify the Hal timer period.
Requirements
Minimum Supported Version | RTX64 2013 |
Header | Rtapi.h |
Library | RtApi.lib (Windows), Rtx_Rtss.lib (RTSS) |
See Also: