Index: c/src/lib/libbsp/m68k/uC5282/clock/clock.c =================================================================== RCS file: /usr1/CVS/rtems/c/src/lib/libbsp/m68k/uC5282/clock/clock.c,v retrieving revision 1.16 diff -u -r1.16 clock.c --- c/src/lib/libbsp/m68k/uC5282/clock/clock.c 26 Aug 2009 13:32:22 -0000 1.16 +++ c/src/lib/libbsp/m68k/uC5282/clock/clock.c 22 Oct 2009 19:12:17 -0000 @@ -30,15 +30,16 @@ #define IDLE_COUNTER __SRAMBASE[0] #define FILTERED_IDLE __SRAMBASE[1] #define MAX_IDLE_COUNT __SRAMBASE[2] -#define USEC_PER_TICK __SRAMBASE[3] +#define CNT_PER_TICK __SRAMBASE[3] +#define NSEC_PER_CNT __SRAMBASE[4] #define FILTER_SHIFT 6 uint32_t bsp_clock_nanoseconds_since_last_tick(void) { int i = MCF5282_PIT3_PCNTR; if (MCF5282_PIT3_PCSR & MCF5282_PIT_PCSR_PIF) - i = MCF5282_PIT3_PCNTR - USEC_PER_TICK; - return (USEC_PER_TICK - i) * 1000; + i = MCF5282_PIT3_PCNTR - CNT_PER_TICK; + return (CNT_PER_TICK - i) * NSEC_PER_CNT; } #define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick @@ -75,18 +76,30 @@ /* * Set up the clock hardware * - * Prescale so that it counts in microseconds - * System clock frequency better be 2**n (1<=n<=16) MHz! + * Prescale so that it counts in microseconds if system clock frequency + * is 2**n (1<=n<=16) MHz, or scale to closest ratio of 1 of x counts + * per n microseconds. */ #define Clock_driver_support_initialize_hardware() \ do { \ int level; \ - int preScaleCode = -2; \ + int divisor = 1; \ + int preScaleCode = -1; \ int preScaleDivisor = bsp_get_CPU_clock_speed() / 1000000; \ - while (preScaleDivisor) { \ + int uSecPerTick = rtems_configuration_get_microseconds_per_tick();\ + while (!(preScaleDivisor & 0x1)) { \ preScaleDivisor >>= 1; \ preScaleCode++; \ } \ + if(preScaleDivisor != 1) { \ + divisor = 2; \ + while((preScaleDivisor / divisor) > 0 && \ + (uSecPerTick % divisor) == 0) { \ + preScaleCode++; \ + divisor *= 2; \ + } \ + divisor /= 2; \ + } \ IDLE_COUNTER = 0; \ FILTERED_IDLE = 0; \ MAX_IDLE_COUNT = 0; \ @@ -101,8 +114,9 @@ MCF5282_PIT_PCSR_OVW | \ MCF5282_PIT_PCSR_PIE | \ MCF5282_PIT_PCSR_RLD; \ - USEC_PER_TICK = rtems_configuration_get_microseconds_per_tick(); \ - MCF5282_PIT3_PMR = USEC_PER_TICK - 1; \ + CNT_PER_TICK = (uSecPerTick / divisor) * preScaleDivisor; \ + NSEC_PER_CNT = (1000 / preScaleDivisor) * divisor; \ + MCF5282_PIT3_PMR = CNT_PER_TICK - 1; \ MCF5282_PIT3_PCSR = MCF5282_PIT_PCSR_PRE(preScaleCode) | \ MCF5282_PIT_PCSR_PIE | \ MCF5282_PIT_PCSR_RLD | \