Ignore:
Timestamp:
May 8, 2013, 5:10:33 PM (12 years ago)
Author:
David Azarewicz
Message:

Fixed up timer functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/os2ahci/libc.c

    r156 r157  
    4040/* ------------------------ typedefs and structures ------------------------ */
    4141
     42#ifdef NOT_USED
    4243/* mdelay() calibration status */
    4344typedef enum {
     
    4748  MD_CALIBRATION_DONE                 /* calibration complete */
    4849} MDCAL;
     50static void _cdecl _far mdelay_timer_callback  (ULONG timer_handle,
     51                                                ULONG parm1,
     52                                                ULONG parm2);
     53static int              mdelay_cal_end         (void);
     54#endif
    4955
    5056/* -------------------------- function prototypes -------------------------- */
     
    5460                                                int base,
    5561                                                int zero, int flen);
    56 static void _cdecl _far mdelay_timer_callback  (ULONG timer_handle,
    57                                                 ULONG parm1,
    58                                                 ULONG parm2);
    59 static int              mdelay_cal_end         (void);
    6062
    6163/* ------------------------ global/static variables ------------------------ */
     
    9294};
    9395
     96#ifdef NOT_USED
    9497/* delay loop calibration data */
    9598volatile MDCAL mdelay_cal_status = 0;     /* delay loop calibration status */
    9699volatile u32   mdelay_loops_per_ms = 0;   /* delay loop counter */
     100#endif
    97101
    98102/* very small heap for dynamic memory management */
     
    684688}
    685689
     690#ifdef NOT_USED
    686691/******************************************************************************
    687692 * Calibrate 'mdelay()' loop. This is done by setting up a 1 second timer
     
    764769  mdelay_cal_status = MD_CALIBRATION_DONE;
    765770}
    766 
    767 /******************************************************************************
    768  * Sleep specified number of milliseonds. This is implemented by yielding the
    769  * CPU until the system timer value indicates we're done. This function can
     771#endif
     772
     773/******************************************************************************
     774 * Setup the millisecond timer. This is implemented by blocking (yielding the
     775 * CPU) until the system timer value indicates we're done. This function can
    770776 * only be called at task time, or from a context hook.
    771777 *
     
    773779 *       can lead to intervals up to 55ms (18.2 timer interrupts per second).
    774780 */
     781void timer_init(TIMER far *pTimer, u32 Milliseconds)
     782{
     783  pTimer->Start = gis->msecs;
     784  pTimer->End = pTimer->Start + Milliseconds;
     785}
     786
     787/******************************************************************************
     788 * Check the millisecond timer. Block if not done.
     789 */
     790int timer_check_and_block(TIMER far *pTimer)
     791{
     792  u32 current;
     793
     794  current = gis->msecs;
     795  if (pTimer->Start < pTimer->End) {
     796    if ((current >= pTimer->End) || (current < pTimer->Start)) return 1;
     797  } else {
     798    if ((current >= pTimer->End) && (current < pTimer->Start)) return 1;
     799  }
     800  DevHelp_ProcBlock((ULONG)&timer_check_and_block, 1, WAIT_IS_INTERRUPTABLE);
     801  return 0;
     802}
     803
     804/******************************************************************************
     805 * Sleep specified number of milliseonds.
     806 */
    775807void msleep(u32 millies)
    776808{
    777   ULONG start;
    778   ULONG end;
    779   ULONG event_id;
    780 
    781   if (gis == NULL) {
    782     /* no global info segment; use mdelay() */
    783     mdelay(millies);
    784     return;
    785   }
    786 
    787   start = gis->msecs;
    788   end = start + millies;
    789   event_id = (ULONG)&msleep;
    790 
    791   if (end < start) {
    792     /* wrap-around; wait until 'msecs' has wrapped, too */
    793     while (gis->msecs >= start) {
    794       DevHelp_ProcBlock(event_id, 1, WAIT_IS_INTERRUPTABLE);
    795     }
    796   }
    797 
    798   while (gis->msecs <= end) {
    799     DevHelp_ProcBlock(event_id, 1, WAIT_IS_INTERRUPTABLE);
    800   }
     809  TIMER Timer;
     810
     811  timer_init(&Timer, millies);
     812  while (!timer_check_and_block(&Timer));
    801813}
    802814
     
    885897}
    886898
     899#ifdef NOT_USED
    887900/******************************************************************************
    888901 * Timer callback handler for 'mdelay_calibrate()'
     
    904917  return(mdelay_cal_status == MD_CALIBRATION_END);
    905918}
    906 
     919#endif
Note: See TracChangeset for help on using the changeset viewer.