Changeset 602e395 in rtems for c/src/lib/libbsp/arm/tms570


Ignore:
Timestamp:
Jul 16, 2015, 12:14:30 PM (4 years ago)
Author:
Pavel Pisa <pisa@…>
Branches:
4.11, master
Children:
069560a
Parents:
bea49c9
git-author:
Pavel Pisa <pisa@…> (07/16/15 12:14:30)
git-committer:
Joel Sherrill <joel.sherrill@…> (07/16/15 16:31:09)
Message:

bsp/tms570: fix get time resolution after infrastructure change to timecounter.

The update fixes breakage of TMS570 support after Alexander Krutwig
switch of RTEMS time read to timecounter mechanism

bsps: Convert clock drivers to use a timecounter

Mechanism to specify odd (non 1 Mhz) time base update frequencies
implemented after objections of Martin Galvan.

Code is adjusted to convert RTEMS configuration parameter
microseconds_per_tick to such odd base if
TMS570_PREFERRED_TC_FREQUENCY is specified appropriately.

Signed-off-by: Premysl Houdek <kom541000@…>
Signed-off-by: Pavel Pisa <pisa@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/tms570/clock/clock.c

    rbea49c9 r602e395  
    4040}
    4141
     42#ifndef TMS570_PREFERRED_TC_FREQUENCY
     43/*
     44 * Define preferred main time base counter frequency
     45 * The value of 1MHz is the best matching RTEMS
     46 * timing system because then there is no need
     47 * to scale RTEMS configuration microseconds_per_tick
     48 * parameter
     49 */
     50#define TMS570_PREFERRED_TC_FREQUENCY 1000000
     51#endif /* TMS570_PREFERRED_TC_FREQUENCY */
     52
    4253/**
    4354 *  @brief Initialize the HW peripheral for clock driver
     
    5061{
    5162
    52   uint32_t microsec_per_tick = rtems_configuration_get_microseconds_per_tick();
     63  uint32_t microsec_per_tick;
     64  uint32_t tc_frequency;
     65  uint32_t tc_prescaler;
     66  uint32_t tc_increments_per_tick;
     67
     68  microsec_per_tick = rtems_configuration_get_microseconds_per_tick();
     69  tc_frequency = TMS570_PREFERRED_TC_FREQUENCY;
    5370
    5471  rtems_counter_initialize_converter(BSP_PLL_OUT_CLOCK);
    5572
     73  tc_prescaler = (BSP_PLL_OUT_CLOCK + tc_frequency) / (tc_frequency * 2);
     74
     75  /* Recompute actual most close frequency which can be realized */
     76  tc_frequency = (BSP_PLL_OUT_CLOCK + tc_prescaler) / (tc_prescaler * 2);
     77
     78  /*
     79   * Recompute tick period to adjust for configurable or exact
     80   * preferred time base 1 usec resolution.
     81   */
     82  tc_increments_per_tick = ((uint64_t)microsec_per_tick * tc_frequency +
     83                           500000) / 1000000;
     84
    5685  /* Hardware specific initialize */
    5786  TMS570_RTI.RTIGCTRL = 0;
    58   TMS570_RTI.RTICPUC0 = BSP_PLL_OUT_CLOCK /1000000 / 2; /* prescaler */
     87  TMS570_RTI.RTICPUC0 = tc_prescaler - 1;
    5988  TMS570_RTI.RTITBCTRL = 2;
    6089  TMS570_RTI.RTICAPCTRL = 0;
     
    6796  TMS570_RTI.RTIINTFLAG = 0x0007000f;
    6897  /* set timer */
    69   TMS570_RTI.RTICOMP0 = TMS570_RTI.RTIFRC0 + microsec_per_tick;
    70   TMS570_RTI.RTICOMP0CLR = TMS570_RTI.RTICOMP0 + microsec_per_tick / 2;
    71   TMS570_RTI.RTIUDCP0 = microsec_per_tick;
     98  TMS570_RTI.RTICOMP0 = TMS570_RTI.RTIFRC0 + tc_increments_per_tick;
     99  TMS570_RTI.RTICOMP0CLR = TMS570_RTI.RTICOMP0 + tc_increments_per_tick / 2;
     100  TMS570_RTI.RTIUDCP0 = tc_increments_per_tick;
    72101  /* enable interupt */
    73102  TMS570_RTI.RTISETINTENA = 0x1;
     
    77106  tms570_rti_tc.tc_get_timecount = tms570_rti_get_timecount;
    78107  tms570_rti_tc.tc_counter_mask = 0xffffffff;
    79   tms570_rti_tc.tc_frequency = BSP_PLL_OUT_CLOCK;
     108  tms570_rti_tc.tc_frequency = tc_frequency;
    80109  tms570_rti_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
    81110  rtems_timecounter_install(&tms570_rti_tc);
Note: See TracChangeset for help on using the changeset viewer.