home *** CD-ROM | disk | FTP | other *** search
- [ 8. Software Timers]
- EMBEDDED DOS TIMER SERVICES
- ════════════════════════════════════════════════════════════════════════
- The timer object implements an extremely fast, centralized, method for
- scheduling a source of interrupt-time execution at a specific interval
- of time in the future.
-
- The timer object was designed to be extremely lightweight, especially
- acts of starting and stopping them, so that it could be used to time
- very high-speed events, such as packet retransmission timeouts in LAN
- transports. The design assumes that the creation of a timer can be a
- heavy event that is not performance critical. Because expiration timers
- almost never fire compared to the number of times that they are started
- and stopped, the starting and stopping of timers is made extremely fast.
-
- When a timer expiration routine executes, it must not block, because the
- expiration routine is executed at interrupt time, not task time. If it
- is desired to block in response to a timer expiration, task-time source
- of control can be gained by calling AllocateThread to create a parallel
- task-time environment, and then simply returning.
-
- 1. AllocateTimer
-
- A timer object is created with the AllocateTimer kernel function.
- Once the timer is allocated, it is automatically maintained by
- the kernel in response to service requests.
-
- At allocation time, the caller specifies a pointer to a function
- to be executed when and if the timer does expire. Additionally,
- a context value is specified by the caller that the kernel will
- pass to the expiration routine in the (BX) general register. In
- the portable request form, the interface automatically passes the
- context as a USHORT argument on the stack.
-
- This function returns a handle to a timer object that must be
- used by the caller in subsequent kernel services that operate on
- timers. The kernel initializes the timer object to contain the
- context value and the pointer to the expiration function, so that
- these values need not be specified on every start/stop request.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov ax, <Context> ; (AX) = context supplied to exp rtn.
- mov bx, CGROUP
- mov cx, OFFSET CGROUP:ExpirationRtn ; (CX:BX) = routine.
- mov dl, SYS_ALLOCATE_TIMER
- int 2dh ; (AX) = handle to timer.
- jc Failure
-
- Macro Instruction Format:
-
- label AllocateTimer <TimerHandle>, <Context>, <ExpirationRtn>
-
- Portable Request Format:
-
- STATUS AllocateTimer(
- OUT PHANDLE TimerHandle,
- IN USHORT Context,
- IN (*ExpirationRtn)(USHORT)
- );
-
- Parameters:
-
- TimerHandle - Specifies a 16-bit general purpose register or
- a pointer to a word in memory where the kernel will
- return a handle to the allocated timer.
-
- Context - Specifies a 16-bit general purpose register or a
- word in memory containing a value to be passed to the
- expiration routine when and if the timer expires.
-
- ExpirationRtn - Specifies a far address of a function to be
- executed when the timer expires. For the macro format
- only, the 16-bit offset is assumed to be relative to
- the current CS segment register. The portable form of
- the request passes a far code pointer in the format
- generated by the high level language.
-
- 2. DeallocateTimer
-
- A timer object is destroyed with the DeallocateTimer kernel
- function. Once the timer is deallocated, it is no longer
- available to the caller, and the handle becomes invalid.
-
- If a timer object is deallocated when it is still running, then
- the timer is stopped automatically by the kernel before
- destroying it.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov ax, <TimerHandle> ; (AX) = handle to timer.
- mov dl, SYS_DEALLOCATE_TIMER
- int 2dh
- jc Failure
-
- Macro Instruction Format:
-
- label DeallocateTimer <TimerHandle>
-
- Portable Request Format:
-
- STATUS DeallocateTimer(
- IN HANDLE TimerHandle
- );
-
- Parameters:
-
- TimerHandle - Specifies a 16-bit general purpose register or
- a word in memory containing a handle to the timer to be
- deallocated.
-
- 3. StartTimer
-
- A timer object is set to the running state with the StartTimer
- kernel function. If a timer is already in the running state,
- then it remains in the running state, and only the expiration
- time is changed. If a timer is in the stopped state, then it is
- moved to the running state, and the expiration time is set to the
- current time plus the specified number of milliseconds in
- DeltaTime.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov ax, <TimerHandle> ; (AX) = handle to timer.
- mov cx, <DeltaTime> ; (CX) = interval in milliseconds.
- int 2dh ; start the timer.
- jc Failure
-
- Macro Instruction Format:
-
- label StartTimer <TimerHandle>, <DeltaTime>
-
- Portable Request Format:
-
- STATUS StartTimer(
- IN HANDLE TimerHandle,
- IN USHORT DeltaTime
- );
-
- Parameters:
-
- TimerHandle - Specifies a 16-bit general purpose register or
- a word in memory containing a handle to the timer to be
- started.
-
- DeltaTime - Specifies a 16-bit general purpose register or a
- word in memory containing the number of milliseconds to
- defer execution of the expiration routine.
-
- 4. StopTimer
-
- A timer object is set to the stopped state with the StopTimer
- kernel function. If a timer is already in the running state,
- then its state is changed to stopped. If a timer is in the
- stopped state, then no operation is performed.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov ax, <TimerHandle> ; (AX) = handle to timer.
- mov dl, SYS_STOP_TIMER
- int 2dh
- jc Failure
-
- Macro Instruction Format:
-
- label StopTimer <TimerHandle>
-
- Portable Request Format:
-
- STATUS StopTimer(
- IN HANDLE TimerHandle
- );
-
- Parameters:
-
- TimerHandle - Specifies a 16-bit general purpose register or
- a word in memory containing a handle to the timer to be
- stopped.