## MMPM/2 Device Driver Reference

[prev][next][parent][TOC]

### Ring-0 Usage

The high-resolution timer provides the following two services:

callback every n milliseconds where n is an integer >= 1. This first option allows your device driver to register itself with the high-resolution timer . The device driver provides a 16:16 address of a function that the high- resolution timer calls every n milliseconds. Registration (and deregistration) cannot occur during interrupt time.

If a device driver re-registers itself-by calling the registration function with the same 16:16 pointer-the high-resolution timer simply changes the count. This can occur at interrupt time.

query the current time This second option is used to obtain a 16:16 pointer to the current count variable. This variable can then be read by the device driver to obtain the current time. Note that this variable is only updated if the high-resolution timer is active-which is only true if at least one driver or application has registered itself with the high-resolution timer. Also note that this variable can be synchronized to another timeclock.

To call the high-resolution timer, call DevHelp_AttachDD with the first parameter as "TIMER0$ ". Remember, DDTable must be allocated in the default data segment. If you make it a local non-static variable (i.e., it is on the stack), the DevHelp_AttachDD call will fail. For example:

    TIMER0_ATTACH_DD DDTable;

    PTMRFN ptmrfn;

    DDTable.pfn=NULL;

    if( DevHelp_AttachDD( ( NPSZ ) "TIMER0$ ", ( NPBYTE )  &DDTable ) )

    {

        // TIMER0.SYS not loaded

    }

    if( !DDTable.pfn )

    {

        // Something wrong with TIMER0.SYS

    }

    ptmrfn=DDTable.pfn;

To register your driver with TIMER0.SYS, do something like this:

    #define N    10                              // Call me every N milliseconds

    void __far __loadds InterruptHandler( void )

    {

       // This function is called every N milliseconds

    }

    if( ptmrfn( TMR0_REG, ( ULONG ) InterruptHandler, N ) )

    {

       // Registration failed

    }

A ptmrfn() call must occur at ring 0. This means that it cannot be made from your strategy INIT routine. The DevHelp_AttachDD call can be made from the INIT routine.

The ptrmfn() call cannot be made from INIT COMPLETE either. Attempts to do so will result in a return code of 6.