Changeset 74af8c0 in rtems


Ignore:
Timestamp:
Apr 2, 2012, 9:32:11 AM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Children:
140c211
Parents:
99fcba89
Message:

bsps: More accurate PowerPC clock driver

The clock driver used previously the bsp_clicks_per_usec value. For a
33333333Hz time base frequency this leads to a relative error of one per
cent for example due to integer truncation.

Location:
c/src/lib/libbsp/powerpc
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/powerpc/gen5200/startup/bspstart.c

    r99fcba89 r74af8c0  
    106106#include <bsp/mpc5200.h>
    107107
    108 /*
    109  *  Driver configuration parameters
    110  */
    111 uint32_t   bsp_clicks_per_usec;
     108/* Configuration parameter for clock driver */
     109uint32_t bsp_time_base_frequency;
     110
     111/* Legacy */
     112uint32_t bsp_clicks_per_usec;
    112113
    113114void BSP_panic(char *s)
     
    158159  }
    159160
     161  bsp_time_base_frequency = XLB_CLOCK / 4;
    160162  bsp_clicks_per_usec    = (XLB_CLOCK/4000000);
    161163
  • c/src/lib/libbsp/powerpc/gen83xx/startup/bspstart.c

    r99fcba89 r74af8c0  
    3535unsigned int BSP_bus_frequency;
    3636
    37 /* Configuration parameters for clock driver, ... */
     37/* Configuration parameter for clock driver */
     38uint32_t bsp_time_base_frequency;
     39
     40/* Legacy */
    3841uint32_t bsp_clicks_per_usec;
    3942
     
    114117#ifdef HAS_UBOOT
    115118  BSP_bus_frequency = bsp_uboot_board_info.bi_busfreq;
    116   bsp_clicks_per_usec = bsp_uboot_board_info.bi_busfreq / 4000000;
    117119#else /* HAS_UBOOT */
    118120  BSP_bus_frequency = BSP_CLKIN_FRQ * BSP_SYSPLL_MF / BSP_SYSPLL_CKID;
    119   bsp_clicks_per_usec = BSP_bus_frequency / 4000000;
    120121#endif /* HAS_UBOOT */
     122  bsp_time_base_frequency = BSP_bus_frequency / 4;
     123  bsp_clicks_per_usec = bsp_time_base_frequency / 1000000;
    121124
    122125  /* Initialize some console parameters */
  • c/src/lib/libbsp/powerpc/mpc8260ads/startup/bspstart.c

    r99fcba89 r74af8c0  
    5959 */
    6060uint32_t   bsp_clock_speed;
     61uint32_t   bsp_time_base_frequency;
    6162uint32_t   bsp_clicks_per_usec;
    6263uint32_t   bsp_serial_per_sec;         /* Serial clocks per second */
     
    208209   *  initialize the device driver parameters
    209210   */
     211  bsp_time_base_frequency    = 10000000;
    210212  bsp_clicks_per_usec        = 10;  /* for 40MHz extclk */
    211213  bsp_serial_per_sec         = 40000000;
  • c/src/lib/libbsp/powerpc/qemuppc/startup/bspstart.c

    r99fcba89 r74af8c0  
    3333unsigned int BSP_bus_frequency;
    3434
    35 /*
    36  *  Driver configuration parameters
    37  */
    38 uint32_t   bsp_clicks_per_usec;
     35/* Configuration parameter for clock driver */
     36uint32_t bsp_time_base_frequency;
     37
     38/* Legacy */
     39uint32_t bsp_clicks_per_usec;
    3940
    4041/*
     
    7980   */
    8081  BSP_bus_frequency        = 20;
     82  bsp_time_base_frequency  = 20000000;
    8183  bsp_clicks_per_usec      = BSP_bus_frequency;
    8284
  • c/src/lib/libbsp/powerpc/qoriq/startup/bspstart.c

    r99fcba89 r74af8c0  
    4444unsigned int BSP_bus_frequency;
    4545
    46 /* Configuration parameters for clock driver, ... */
     46/* Configuration parameter for clock driver, ... */
    4747uint32_t bsp_clicks_per_usec;
    4848
  • c/src/lib/libbsp/powerpc/shared/clock/clock.c

    r99fcba89 r74af8c0  
    88
    99/*
    10  * Copyright (c) 2008-2011 embedded brains GmbH.  All rights reserved.
     10 * Copyright (c) 2008-2012 embedded brains GmbH.  All rights reserved.
    1111 *
    1212 *  embedded brains GmbH
     
    3333/*
    3434 * This variable must be defined in the BSP and valid before clock driver
    35  * initialization.  The clicks refer to the decrementer and time base.
     35 * initialization.
    3636 */
    37 extern uint32_t bsp_clicks_per_usec;
     37extern uint32_t bsp_time_base_frequency;
    3838
    3939#define PPC_CLOCK_DECREMENTER_MAX UINT32_MAX
     
    4747static uint32_t ppc_clock_decrementer_value = PPC_CLOCK_DECREMENTER_MAX;
    4848
    49 static uint32_t ppc_clock_next_time_base = 0;
     49static uint32_t ppc_clock_next_time_base;
     50
     51static uint64_t ppc_clock_factor;
    5052
    5153static void ppc_clock_no_tick(void)
     
    152154static uint32_t ppc_clock_nanoseconds_since_last_tick(void)
    153155{
    154         return ((ppc_clock_decrementer_value - ppc_decrementer_register()) * 1000) / bsp_clicks_per_usec;
     156        uint64_t k = ppc_clock_factor;
     157        uint32_t c = ppc_decrementer_register();
     158        uint32_t i = ppc_clock_decrementer_value + 1;
     159
     160        return (uint32_t) (((i - c) * k) >> 32);
    155161}
    156162
     
    166172rtems_device_driver Clock_initialize( rtems_device_major_number major, rtems_device_minor_number minor, void *arg)
    167173{
     174        uint64_t frequency = bsp_time_base_frequency;
     175        uint64_t us_per_tick = rtems_configuration_get_microseconds_per_tick();
     176        uint32_t interval = (uint32_t) ((frequency * us_per_tick) / 1000000);
     177
    168178        /* Current CPU type */
    169179        ppc_cpu_id_t cpu_type = get_ppc_cpu_type();
     
    185195        ppc_set_decrementer_register( PPC_CLOCK_DECREMENTER_MAX);
    186196
     197        /* Factor for nano seconds extension */
     198        ppc_clock_factor = (1000000000ULL << 32) / frequency;
     199
    187200        /* Decrementer value */
    188         ppc_clock_decrementer_value = bsp_clicks_per_usec * rtems_configuration_get_microseconds_per_tick() - 1;
     201        ppc_clock_decrementer_value = interval - 1;
    189202
    190203        /* Check decrementer value */
  • c/src/lib/libbsp/powerpc/tqm8xx/startup/bspstart.c

    r99fcba89 r74af8c0  
    4141uint32_t BSP_bus_frequency;
    4242
    43 /* Configuration parameters for clock driver, ... */
     43/* Configuration parameter for clock driver */
     44uint32_t bsp_time_base_frequency;
     45
     46/* Legacy */
    4447uint32_t bsp_clicks_per_usec; /* for PIT driver: OSCCLK */
     48
    4549/* for timer: */
    4650uint32_t   bsp_timer_average_overhead; /* Average overhead of timer in ticks */
     
    174178  }
    175179
    176   bsp_clicks_per_usec = BSP_bus_frequency/1000000/16;
     180  bsp_time_base_frequency = BSP_bus_frequency / 16;
     181  bsp_clicks_per_usec = bsp_time_base_frequency / 1000000;
    177182  bsp_timer_least_valid = 3;
    178183  bsp_timer_average_overhead = 3;
Note: See TracChangeset for help on using the changeset viewer.