Annotation of os2sdk/demos/examples/timer/timer.c, revision 1.1.1.1

1.1       root        1: /* This example illustrates the use of the following 286DOS functions:
                      2:  *     DOSTIMERSTART, DOSTIMERASYNC, DOSTIMERSTOP, DOSSLEEP
                      3:  *
                      4:  * Copyright (C) Microsoft Corp. 1986
                      5:  */
                      6: 
                      7: #include       <doscalls.h>    /* contains 286DOS function declarations */
                      8: 
                      9: #define SEMNAME        "\\SEM\\SOMESEM"  /* name of semaphore */
                     10: #define NOEXCLUSIVE 1          /* ownership of semaphore not exclusive  */
                     11: #define TIMERINTERVAL 1000L    /* timer interval */
                     12: #define ASYNCINTERVAL 2000     /* asynchronous timer interval */
                     13: #define NOTIMEOUT -1           /* no timeout */
                     14: #define BEEPFREQUENCY 400      /* frequency parameter to DOSBEEP */
                     15: #define BEEPDURATION  50        /* duration parameter to DOSBEEP */
                     16: 
                     17: main ()
                     18: {
                     19:        unsigned long   SemHandle;      /* storage for semaphore handle */
                     20:        unsigned        TimerHandle;    /* handle returned by DosTimerStart*/
                     21: 
                     22:        /* create a system semaphore */
                     23:        DOSCREATESEM (NOEXCLUSIVE, &SemHandle, SEMNAME);
                     24: 
                     25:        /*
                     26:         * DOSTIMERSTART/STOP - these functions provide a repetitive
                     27:         * asynchronous timer which clear a semaphore at a specified interval.
                     28:         */
                     29: 
                     30:        DOSSEMSET (SemHandle);          /* set the system semaphore */
                     31: 
                     32:        /* set the interval timer */
                     33:        DOSTIMERSTART (TIMERINTERVAL, SemHandle, &TimerHandle);
                     34: 
                     35:        /* normally, application would do some work in here */
                     36: 
                     37:        DOSSEMWAIT (SemHandle, (long) NOTIMEOUT); /* wait on the semaphore */
                     38:        DOSBEEP (BEEPFREQUENCY, BEEPDURATION);    /* beep when done */
                     39:        DOSTIMERSTOP (TimerHandle);               /* stop the interval timer */
                     40: 
                     41:        /*
                     42:         * DOSTIMERASYNC example. This function provides a one-shot
                     43:         * asynchronous timer which clears a specified semaphore after
                     44:         * a specified time delay.
                     45:         */
                     46: 
                     47:        DOSSEMSET (SemHandle);          /* set the system semaphore */
                     48: 
                     49:        /* start the asynchronous timer */
                     50:        DOSTIMERASYNC ((long) ASYNCINTERVAL, SemHandle, &TimerHandle);
                     51: 
                     52:        /* normally, application would do some work in here */
                     53: 
                     54:        DOSSEMWAIT (SemHandle,  (long) NOTIMEOUT); /* wait on the semaphore */
                     55:        DOSBEEP (BEEPFREQUENCY, BEEPDURATION);    /* beep when done */
                     56: 
                     57:        /*
                     58:         * DOSTIMERSTOP is used to cancel either type of timer. After using
                     59:         * this function you must put the semaphore back into a known state
                     60:         * if you need to use it again. Example of cancelling a timer:
                     61:         */
                     62: 
                     63:        DOSSEMSET (SemHandle);          /* set the system semaphore */
                     64: 
                     65:        /* start the asynchronous timer (specify a long time) */
                     66:        DOSTIMERASYNC ((long) (10*ASYNCINTERVAL), SemHandle, &TimerHandle);
                     67: 
                     68:        DOSTIMERSTOP (TimerHandle);     /* stop the asynchronous timer */
                     69:        DOSSEMCLEAR (SemHandle);        /* clear the system semaphore */
                     70:        DOSCLOSESEM (SemHandle);        /* close the system semaphore */
                     71: 
                     72:        /*
                     73:         * DOSSLEEP - simple synchronous suspend for specified interval.
                     74:         */
                     75:        DOSSLEEP(TIMERINTERVAL);
                     76:        DOSBEEP (BEEPFREQUENCY, BEEPDURATION);    /* beep when done */
                     77: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.