Ignore:
Timestamp:
Jul 31, 2013, 8:08:59 PM (12 years ago)
Author:
David Azarewicz
Message:

code cleanup - debug messages
fixed defect in smart ioctl

File:
1 edited

Legend:

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

    r160 r165  
    44 * Copyright (c) 2011 thi.guten Software Development
    55 * Copyright (c) 2011 Mensys B.V.
     6 * Portions copyright (c) 2013 David Azarewicz
    67 *
    78 * Authors: Christian Mueller, Markus Thielen
     
    3839#define HEAP_UNIT_CNT         (HEAP_SIZE / HEAP_UNIT)
    3940
    40 /* ------------------------ typedefs and structures ------------------------ */
    41 
    42 #ifdef NOT_USED
    43 /* mdelay() calibration status */
    44 typedef enum {
    45   MD_NOT_CALIBRATED,                  /* delay loop not calibrated */
    46   MD_CALIBRATION_START,               /* calibration run started */
    47   MD_CALIBRATION_END,                 /* calibration run ended */
    48   MD_CALIBRATION_DONE                 /* calibration complete */
    49 } MDCAL;
    50 static void _cdecl _far mdelay_timer_callback  (ULONG timer_handle,
    51                                                 ULONG parm1,
    52                                                 ULONG parm2);
    53 static int              mdelay_cal_end         (void);
    54 #endif
    55 
    5641/* -------------------------- function prototypes -------------------------- */
    5742
    58 static void             long_to_asc            (long val,
    59                                                 char _far *buf,
    60                                                 int base,
    61                                                 int zero, int flen);
     43static void long_to_asc(long val, char _far *buf, int base, int zero, int flen);
    6244
    6345/* ------------------------ global/static variables ------------------------ */
     
    9476};
    9577
    96 #ifdef NOT_USED
    97 /* delay loop calibration data */
    98 volatile MDCAL mdelay_cal_status = 0;     /* delay loop calibration status */
    99 volatile u32   mdelay_loops_per_ms = 0;   /* delay loop counter */
    100 #endif
    101 
    10278/* very small heap for dynamic memory management */
    10379static u8 heap_buf[HEAP_SIZE];
     
    688664}
    689665
    690 #ifdef NOT_USED
    691 /******************************************************************************
    692  * Calibrate 'mdelay()' loop. This is done by setting up a 1 second timer
    693  * with a callback that sets 'mdelay_done' to MD_CALIBRATION_END. Then it
    694  * calls mdelay() with a large milliseond value as initial delay loop counter.
    695  * When the timer triggers, 'mdelay()' will stop and update the delay loop
    696  * counter.
    697  *
    698  * This function needs to be called at device driver init time. Since it uses
    699  * ADD timers, it must be called with interrupts enabled. All this is not very
    700  * precise (we should wait for a clock tick before starting, ...) but we don't
    701  * really need precise timers.
    702  */
    703 void mdelay_cal(void)
    704 {
    705   ULONG timer_handle;
    706 
    707   dprintf("calibrating delay loop... ");
    708 
    709   mdelay_loops_per_ms = 100000;
    710   mdelay_cal_status = MD_CALIBRATION_START;
    711 
    712   ADD_StartTimerMS(&timer_handle, 1000, (PFN) mdelay_timer_callback, 0, 0);
    713   mdelay(999999999);
    714   ADD_CancelTimer(timer_handle);
    715 
    716   dprintf("done (loops per ms = %ld)\n", mdelay_loops_per_ms);
    717 }
    718 
    719 /******************************************************************************
    720  * Wait specified number of milliseconds. This is implemented using a busy
    721  * loop and is only good for delays in the millisecond range but never for more
    722  * than a few milliseconds and only in situations where a proper timer won't do.
    723  * As a rule of thumb, don't call this function and use ADD timers, instead.
    724  *
    725  * NOTES:
    726  *
    727  *  - Timers are problematic on x86 platforms because there's no reliable
    728  *    hardware timer on all architectures and the CPU clock speed may change
    729  *    while executing delay loops (AMD Cool&Quiet and Intel SpeedStep), thus
    730  *    calibration routines won't really be sufficient. But this usually only
    731  *    extends the delay and we don't really need a high precision timer. The
    732  *    exception are things like notebooks that are clocked slower when on
    733  *    battery and which got booted while on battery. Should still be OK,
    734  *    though, because our requirements are not that strict.
    735  *
    736  *  - The code in this function is inefficient by design to make sure it
    737  *    will work with future CPUs which might otherwise be too fast for
    738  *    our loop counters. Part of this design is using volatile variables to
    739  *    force memory operations.
    740  *
    741  *  - Before using this function, call mdelay_calibrate() to determine the
    742  *    number of inner loops required per millisecond.
    743  */
    744 void mdelay(u32 millies)
    745 {
    746   volatile u32 i;
    747   volatile u32 n;
    748 
    749   for (i = 0; i < millies; i++) {
    750     for (n = 0; n < mdelay_loops_per_ms; n++) {
    751       if (mdelay_cal_end()) {
    752         /* this is a calibration run that just ended */
    753         goto complete_calibration;
    754       }
    755     }
    756   }
    757   return;
    758 
    759 complete_calibration:
    760   /* complete calibration cycle */
    761   if (i < 1000) {
    762     /* Initial value for delay loop was too high; interpolate results for
    763      * an assumed initial delay loop divided by 1000.
    764      */
    765     i = i * 1000 + mdelay_loops_per_ms % 1000;
    766     mdelay_loops_per_ms /= 1000;
    767   }
    768   mdelay_loops_per_ms = (mdelay_loops_per_ms * i) / 1000;
    769   mdelay_cal_status = MD_CALIBRATION_DONE;
    770 }
    771 #endif
    772 
    773666/******************************************************************************
    774667 * Setup the millisecond timer. This is implemented by blocking (yielding the
     
    898791}
    899792
    900 #ifdef NOT_USED
    901 /******************************************************************************
    902  * Timer callback handler for 'mdelay_calibrate()'
    903  */
    904 static void _cdecl _far mdelay_timer_callback(ULONG timer_handle,
    905                                               ULONG parm1,
    906                                               ULONG parm2)
    907 {
    908   mdelay_cal_status = MD_CALIBRATION_END;
    909 }
    910 
    911 /******************************************************************************
    912  * Determine whether an mdelay calibration run has just ended. This is in a
    913  * function to prevent overzealous optimizers from removing the whole delay
    914  * loop in mdelay().
    915  */
    916 static int mdelay_cal_end(void)
    917 {
    918   return(mdelay_cal_status == MD_CALIBRATION_END);
    919 }
    920 #endif
Note: See TracChangeset for help on using the changeset viewer.