Changeset 2f2a597 in rtems for c/src/lib/libbsp/i386/go32


Ignore:
Timestamp:
Jul 24, 1995, 2:00:27 PM (26 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
c35e9622
Parents:
1690c6b
Message:

hopefully works with regular timer and tm27

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/i386/go32/timer/timer.c

    r1690c6b r2f2a597  
    3535    return result;
    3636}
    37 static void restore_timer( void )
     37#else
     38extern rtems_isr timerisr();
     39static rtems_isr_entry Old_Ticker;
     40#endif
     41
     42static void Timer_exit( void )
    3843{
     44#if defined(pentium)
    3945    CLOCK_ENABLE();
     46#else /* pentium */
     47    extern void rtc_set_dos_date( void );
     48
     49    /* reset to DOS value: */
     50    outport_byte( TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN );
     51    outport_byte( TIMER_CNTR0, 0 );
     52    outport_byte( TIMER_CNTR0, 0 );
     53
     54    /* reset time-of-day */
     55    rtc_set_dos_date();
     56       
     57    /* re-enable old handler: assume it was one of ours */
     58    set_vector( (rtems_isr_entry)Old_Ticker, 0x8, 0 );
     59#endif /* pentium */
    4060}
    41 #else /* pentium */
    42 rtems_isr timerisr();
    43 
    44 #define TIMER_ISR_US  10000
    45 
    46 #endif /* pentium */
    4761
    4862void Timer_initialize()
    4963{
     64    extern int atexit( void (*)(void) );
     65
    5066    static int First = 1;
    51 #if defined(pentium)
    52     if ( First )  {
    53         extern int atexit( void (*)(void) );
    54         First = 0;
    55         /* Disable the programmable timer. */
    56         CLOCK_DISABLE();
    57         /* Try not to hose the system on return to DOS. */
    58         atexit( restore_timer );
    59     }
    60     Ttimer_val = rdtsc();
    61 #else /* pentium */
    62 
    63 #define WAIT() \
    64   { \
    65     Ttimer_val = 0; \
    66     while ( Ttimer_val == 0 ) \
    67       continue; \
    68     Ttimer_val = 0; \
    69   }
    7067
    7168    if ( First )  {
    7269        First = 0;
    7370
    74         /* install ISR */
    75         set_vector( timerisr, 0x8, 0 );
     71        /* Try not to hose the system on return to DOS. */
     72        atexit( Timer_exit );
    7673
    77        /* Wait for ISR to be called at least once */
    78        WAIT();
     74#if defined(pentium)
     75        /* Disable the programmable timer so ticks don't interfere. */
     76        CLOCK_DISABLE();
     77#else /* pentium */
     78        /* install a timer ISR */
     79        Old_Ticker = (rtems_isr_entry) set_vector( timerisr, 0x8, 0 );
    7980
    80        /* load timer for TIMER_ISR_US microsecond period */
    81        outport_byte( TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN );
    82        outport_byte( TIMER_CNTR0, US_TO_TICK(TIMER_ISR_US) >> 0 & 0xff);
    83        outport_byte( TIMER_CNTR0, US_TO_TICK(TIMER_ISR_US) >> 8 & 0xff);
     81        /* Wait for ISR to be called at least once */
     82        Ttimer_val = 0;
     83        while ( Ttimer_val == 0 )
     84            continue;
     85
     86        /* load timer for 250 microsecond period */
     87        outport_byte( TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN );
     88        outport_byte( TIMER_CNTR0, US_TO_TICK(250) >> 0 & 0xff );
     89        outport_byte( TIMER_CNTR0, US_TO_TICK(250) >> 8 & 0xff );
     90#endif /* PENTIUM */
    8491    }
    85 
     92#if defined(pentium)
     93    Ttimer_val = rdtsc();       /* read starting time */
     94#else
    8695    /* Wait for ISR to be called at least once */
    87     WAIT();
    88 #endif /* PENTIUM */
     96    asm( "sti" );
     97    Ttimer_val = 0;
     98    while ( Ttimer_val == 0 )
     99        continue;
     100    Ttimer_val = 0;
     101#endif
    89102}
    90103
     
    105118    inport_byte( TIMER_CNTR0, msb );
    106119    clicks = msb << 8 | lsb;
    107     total = (Ttimer_val * TIMER_ISR_US) + (TIMER_ISR_US - TICK_TO_US( clicks ));
     120    total = Ttimer_val + 250 - TICK_TO_US( clicks );
    108121#endif /* pentium */
    109122
Note: See TracChangeset for help on using the changeset viewer.