Changeset 75acd9e in rtems


Ignore:
Timestamp:
Apr 1, 2015, 1:33:25 PM (5 years ago)
Author:
Alexander Krutwig <alexander.krutwig@…>
Branches:
4.11, 5, master
Children:
a9c4f15d
Parents:
7cd2484
git-author:
Alexander Krutwig <alexander.krutwig@…> (04/01/15 13:33:25)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/20/15 06:40:34)
Message:

bsps: Convert clock drivers to use a timecounter

Update #2271.

Location:
c/src/lib
Files:
48 edited

Legend:

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

    r7cd2484 r75acd9e  
    1616
    1717#include <rtems.h>
     18#include <rtems/timecounter.h>
    1819#include <bsp.h>
    1920
    2021#include <libcpu/omap_timer.h>
    2122
    22 #ifdef ARM_MULTILIB_ARCH_V4
     23static struct timecounter beagle_clock_tc;
    2324
    2425static omap_timer_registers_t regs_v1 = {
     
    116117#endif
    117118
    118 static int done = 0;
    119 
    120119#if IS_AM335X
    121120#define FRCLOCK_HZ (16*1500000)
     
    182181  mmio_set(fr_timer->base + fr_timer->regs->TCLR,
    183182      OMAP3_TCLR_OVF_TRG | OMAP3_TCLR_AR | OMAP3_TCLR_ST);
    184   done = 1;
    185 }
    186 
    187 static inline uint32_t
    188 read_frc(void)
    189 {
    190   if (done == 0) {
    191     return 0;
    192   }
     183}
     184
     185static uint32_t
     186beagle_clock_get_timecount(struct timecounter *tc)
     187{
    193188  return mmio_read(fr_timer->base + fr_timer->regs->TCRR);
    194189}
    195 
    196 static uint32_t last_tick_nanoseconds;
    197190
    198191static void
     
    263256#endif
    264257
     258  /* Install timecounter */ \
     259  beagle_clock_tc.tc_get_timecount = beagle_clock_get_timecount;
     260  beagle_clock_tc.tc_counter_mask = 0xffffffff;
     261  beagle_clock_tc.tc_frequency = FRCLOCK_HZ;
     262  beagle_clock_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
     263  rtems_timecounter_install(&beagle_clock_tc);
    265264}
    266265
    267266static void beagle_clock_at_tick(void)
    268267{
    269   last_tick_nanoseconds = read_frc();
    270 
    271268  mmio_write(timer->base + timer->regs->TISR,
    272269    OMAP3_TISR_MAT_IT_FLAG | OMAP3_TISR_OVF_IT_FLAG |
     
    316313}
    317314
    318 static inline uint32_t beagle_clock_nanoseconds_since_last_tick(void)
    319 {
    320   /* this arithmetic also works if read_frc() wraps around, as long
    321    * as the subtraction wraps around too
    322    */
    323   return (read_frc() - (uint64_t) last_tick_nanoseconds) * 1000000000 / FRCLOCK_HZ;
    324 }
    325 
    326315#define Clock_driver_support_at_tick() beagle_clock_at_tick()
    327316#define Clock_driver_support_initialize_hardware() beagle_clock_initialize()
     
    333322
    334323#define Clock_driver_support_shutdown_hardware() beagle_clock_cleanup()
    335 #define Clock_driver_nanoseconds_since_last_tick \
    336   beagle_clock_nanoseconds_since_last_tick
    337324
    338325/* Include shared source clock driver code */
    339326#include "../../shared/clockdrv_shell.h"
    340 
    341 #endif /* ARM_MULTILIB_ARCH_V4 */
  • c/src/lib/libbsp/arm/edb7312/clock/clockdrv.c

    r7cd2484 r75acd9e  
    6969  } while (0)
    7070
     71#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     72
    7173#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/arm/gba/clock/clockdrv.c

    r7cd2484 r75acd9e  
    9393}
    9494
     95#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     96
    9597#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/arm/lpc176x/include/lpc-clock-config.h

    r7cd2484 r75acd9e  
    3434#define LPC_CLOCK_INTERRUPT LPC176X_IRQ_TIMER_0
    3535#define LPC_CLOCK_TIMER_BASE TMR0_BASE_ADDR
     36#define LPC_CLOCK_TIMECOUNTER_BASE TMR1_BASE_ADDR
    3637#define LPC_CLOCK_REFERENCE LPC176X_PCLK
    3738#define LPC_CLOCK_MODULE_ENABLE() \
  • c/src/lib/libbsp/arm/lpc24xx/include/lpc-clock-config.h

    r7cd2484 r75acd9e  
    3636#define LPC_CLOCK_TIMER_BASE TMR0_BASE_ADDR
    3737
     38#define LPC_CLOCK_TIMECOUNTER_BASE TMR1_BASE_ADDR
     39
    3840#define LPC_CLOCK_REFERENCE LPC24XX_PCLK
    3941
  • c/src/lib/libbsp/arm/lpc32xx/include/lpc-clock-config.h

    r7cd2484 r75acd9e  
    4545#define LPC_CLOCK_TIMER_BASE LPC32XX_BASE_TIMER_0
    4646
     47#define LPC_CLOCK_TIMECOUNTER_BASE LPC32XX_BASE_TIMER_1
     48
    4749#define LPC_CLOCK_REFERENCE LPC32XX_PERIPH_CLK
    4850
  • c/src/lib/libbsp/arm/nds/clock/clock.c

    r7cd2484 r75acd9e  
    8282}
    8383
     84#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     85
    8486#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/arm/raspberrypi/clock/clockdrv.c

    r7cd2484 r75acd9e  
    7373}
    7474
    75 /*
    76  *  Return the nanoseconds since last tick
    77  */
    78 static uint32_t raspberrypi_clock_nanoseconds_since_last_tick(void)
    79 {
    80   return 0;
    81 }
    82 
    8375#define Clock_driver_support_at_tick() raspberrypi_clock_at_tick()
    8476
     
    9385#define Clock_driver_support_shutdown_hardware() raspberrypi_clock_cleanup()
    9486
    95 #define Clock_driver_nanoseconds_since_last_tick \
    96   raspberrypi_clock_nanoseconds_since_last_tick
    97 
     87#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
    9888
    9989#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/arm/shared/arm-a9mpcore-clock-config.c

    r7cd2484 r75acd9e  
    11/*
    2  * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2013-2015 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    1818#include <bsp/arm-a9mpcore-regs.h>
    1919#include <bsp/arm-a9mpcore-clock.h>
     20#include <rtems/timecounter.h>
    2021
    2122#define A9MPCORE_GT ((volatile a9mpcore_gt *) BSP_ARM_A9MPCORE_GT_BASE)
    2223
    23 static uint64_t a9mpcore_clock_last_tick_k;
    24 
    25 static uint32_t a9mpcore_clock_last_tick_cmpvallower;
    26 
    27 static uint32_t a9mpcore_clock_autoinc;
     24static struct timecounter a9mpcore_tc;
    2825
    2926/* This is defined in clockdrv_shell.h */
     
    3936{
    4037  volatile a9mpcore_gt *gt = A9MPCORE_GT;
    41 
    42   /*
    43    * FIXME: Now the _TOD_Get_with_nanoseconds() yields wrong values until
    44    * _TOD_Tickle_ticks() managed to update the uptime.  See also PR2180.
    45    */
    46   a9mpcore_clock_last_tick_cmpvallower =
    47     gt->cmpvallower - a9mpcore_clock_autoinc;
    4838
    4939  gt->irqst = A9MPCORE_GT_IRQST_EFLG;
     
    8171}
    8272
     73static uint32_t a9mpcore_clock_get_timecount(struct timecounter *tc)
     74{
     75  volatile a9mpcore_gt *gt = A9MPCORE_GT;
     76
     77  return gt->cntrlower;
     78}
     79
    8380static void a9mpcore_clock_initialize(void)
    8481{
     
    9996  gt->autoinc = interval;
    10097
    101   a9mpcore_clock_last_tick_k = (UINT64_C(1000000000) << 32) / periphclk;
    102   a9mpcore_clock_last_tick_cmpvallower = (uint32_t) cmpval - interval;
    103   a9mpcore_clock_autoinc = interval;
    104 
    10598  gt->ctrl = A9MPCORE_GT_CTRL_AUTOINC_EN
    10699    | A9MPCORE_GT_CTRL_IRQ_EN
    107100    | A9MPCORE_GT_CTRL_COMP_EN
    108101    | A9MPCORE_GT_CTRL_TMR_EN;
     102
     103  a9mpcore_tc.tc_get_timecount = a9mpcore_clock_get_timecount;
     104  a9mpcore_tc.tc_counter_mask = 0xffffffff;
     105  a9mpcore_tc.tc_frequency = periphclk;
     106  a9mpcore_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
     107  rtems_timecounter_install(&a9mpcore_tc);
    109108}
    110109
     
    148147}
    149148
    150 static uint32_t a9mpcore_clock_nanoseconds_since_last_tick(void)
    151 {
    152   volatile a9mpcore_gt *gt = A9MPCORE_GT;
    153   uint64_t k = a9mpcore_clock_last_tick_k;
    154   uint32_t n = a9mpcore_clock_last_tick_cmpvallower;
    155   uint32_t c = gt->cntrlower;
    156 
    157   return (uint32_t) (((c - n) * k) >> 32);
    158 }
    159 
    160149#define Clock_driver_support_at_tick() \
    161150  a9mpcore_clock_at_tick()
     
    166155#define Clock_driver_support_install_isr(isr, old_isr) \
    167156  do { \
    168     a9mpcore_clock_handler_install();   \
     157    a9mpcore_clock_handler_install(); \
    169158    old_isr = NULL; \
    170159  } while (0)
     
    173162  a9mpcore_clock_cleanup()
    174163
    175 #define Clock_driver_nanoseconds_since_last_tick \
    176   a9mpcore_clock_nanoseconds_since_last_tick
    177 
    178164/* Include shared source clock driver code */
    179165#include "../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/arm/shared/armv7m/clock/armv7m-clock-config.c

    r7cd2484 r75acd9e  
    1414
    1515#include <rtems.h>
     16#include <rtems/timecounter.h>
    1617#include <rtems/score/armv7m.h>
    1718
     
    2324static void Clock_isr(void *arg);
    2425
    25 #define _ARMV7M_Systick_get_factor(freq) \
    26   ((1000000000ULL << 32) / (freq))
     26static rtems_timecounter_simple _ARMV7M_TC;
    2727
    28 #ifdef BSP_ARMV7M_SYSTICK_FREQUENCY
    29   #define _ARMV7M_Systick_factor \
    30     _ARMV7M_Systick_get_factor(BSP_ARMV7M_SYSTICK_FREQUENCY)
    31 #else
    32   static uint64_t _ARMV7M_Systick_factor;
    33 #endif
     28static uint32_t _ARMV7M_TC_get(rtems_timecounter_simple *tc)
     29{
     30  volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
     31
     32  return systick->cvr;
     33}
     34
     35static bool _ARMV7M_TC_is_pending(rtems_timecounter_simple *tc)
     36{
     37  volatile ARMV7M_SCB *scb = _ARMV7M_SCB;
     38
     39  return ((scb->icsr & ARMV7M_SCB_ICSR_PENDSTSET) != 0);
     40}
     41
     42static uint32_t _ARMV7M_TC_get_timecount(struct timecounter *tc)
     43{
     44  return rtems_timecounter_simple_downcounter_get(
     45    tc,
     46    _ARMV7M_TC_get,
     47    _ARMV7M_TC_is_pending
     48  );
     49}
     50
     51static void _ARMV7M_TC_tick(void)
     52{
     53  rtems_timecounter_simple_downcounter_tick(&_ARMV7M_TC, _ARMV7M_TC_get);
     54}
    3455
    3556static void _ARMV7M_Systick_at_tick(void)
     
    6889  uint64_t interval = (freq * us_per_tick) / 1000000ULL;
    6990
    70   #ifndef BSP_ARMV7M_SYSTICK_FREQUENCY
    71     _ARMV7M_Systick_factor = _ARMV7M_Systick_get_factor(freq);
    72   #endif
    73 
    7491  systick->rvr = (uint32_t) interval;
    7592  systick->cvr = 0;
     
    7794    | ARMV7M_SYSTICK_CSR_TICKINT
    7895    | ARMV7M_SYSTICK_CSR_CLKSOURCE;
     96
     97  rtems_timecounter_simple_install(
     98    &_ARMV7M_TC,
     99    freq,
     100    interval,
     101    _ARMV7M_TC_get_timecount
     102  );
    79103}
    80104
     
    86110}
    87111
    88 static uint32_t _ARMV7M_Systick_nanoseconds_since_last_tick(void)
    89 {
    90   volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
    91   volatile ARMV7M_SCB *scb = _ARMV7M_SCB;
    92   uint32_t rvr = systick->rvr;
    93   uint32_t c = rvr - systick->cvr;
    94 
    95   if ((scb->icsr & ARMV7M_SCB_ICSR_PENDSTSET) != 0) {
    96     c = rvr - systick->cvr + rvr;
    97   }
    98 
    99   return (uint32_t) ((c * _ARMV7M_Systick_factor) >> 32);
    100 }
     112#define Clock_driver_timecounter_tick() _ARMV7M_TC_tick()
    101113
    102114#define Clock_driver_support_at_tick() \
     
    115127  _ARMV7M_Systick_cleanup()
    116128
    117 #define Clock_driver_nanoseconds_since_last_tick \
    118   _ARMV7M_Systick_nanoseconds_since_last_tick
    119 
    120129/* Include shared source clock driver code */
    121130#include "../../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/arm/shared/lpc/clock/lpc-clock-config.c

    r7cd2484 r75acd9e  
    88
    99/*
    10  * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
     10 * Copyright (c) 2009-2015 embedded brains GmbH.  All rights reserved.
    1111 *
    1212 *  embedded brains GmbH
    13  *  Obere Lagerstr. 30
     13 *  Dornierstr. 4
    1414 *  82178 Puchheim
    1515 *  Germany
     
    2222
    2323#include <rtems.h>
     24#include <rtems/timecounter.h>
    2425
    2526#include <bsp/lpc-clock-config.h>
     
    3334static volatile lpc_timer *const lpc_clock =
    3435  (volatile lpc_timer *) LPC_CLOCK_TIMER_BASE;
     36
     37static volatile lpc_timer *const lpc_timecounter =
     38  (volatile lpc_timer *) LPC_CLOCK_TIMECOUNTER_BASE;
     39
     40static struct timecounter lpc_clock_tc;
     41
     42static uint32_t lpc_clock_tc_get_timecount(struct timecounter *tc)
     43{
     44  return lpc_timecounter->tc;
     45}
    3546
    3647static void lpc_clock_at_tick(void)
     
    5768static void lpc_clock_initialize(void)
    5869{
     70  uint32_t mask;
    5971  uint64_t interval = ((uint64_t) LPC_CLOCK_REFERENCE
    6072    * (uint64_t) rtems_configuration_get_microseconds_per_tick()) / 1000000;
     
    8698  /* Enable timer */
    8799  lpc_clock->tcr = LPC_TIMER_TCR_EN;
     100
     101  /* Install timecounter */
     102  lpc_clock_tc.tc_get_timecount = lpc_clock_tc_get_timecount;
     103  lpc_clock_tc.tc_counter_mask = 0xffffffff;
     104  lpc_clock_tc.tc_frequency = LPC_CLOCK_REFERENCE;
     105  lpc_clock_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
     106  rtems_timecounter_install(&lpc_clock_tc);
    88107}
    89108
     
    106125}
    107126
    108 static uint32_t lpc_clock_nanoseconds_since_last_tick(void)
    109 {
    110   uint64_t k = (1000000000ULL << 32) / LPC_CLOCK_REFERENCE;
    111   uint64_t c = lpc_clock->tc;
    112 
    113   if ((lpc_clock->ir & LPC_TIMER_IR_MR0) != 0) {
    114     c = lpc_clock->tc + lpc_clock->mr0;
    115   }
    116 
    117   return (uint32_t) ((c * k) >> 32);
    118 }
    119 
    120127#define Clock_driver_support_at_tick() lpc_clock_at_tick()
    121128#define Clock_driver_support_initialize_hardware() lpc_clock_initialize()
     
    127134
    128135#define Clock_driver_support_shutdown_hardware() lpc_clock_cleanup()
    129 #define Clock_driver_nanoseconds_since_last_tick \
    130   lpc_clock_nanoseconds_since_last_tick
    131136
    132137/* Include shared source clock driver code */
  • c/src/lib/libbsp/arm/tms570/clock/clock.c

    r7cd2484 r75acd9e  
    3131#include <bsp/tms570-rti.h>
    3232#include <rtems/counter.h>
     33#include <rtems/timecounter.h>
    3334
    34 /**
    35  *  holds HW counter value since last interrupt event
    36  *  sets in tms570_clock_driver_support_at_tick
    37  *  used in tms570_clock_driver_nanoseconds_since_last_tick
    38  */
    39 static uint32_t tms570_rti_last_tick_fcr0;
     35static struct timecounter tms570_rti_tc;
     36
     37static uint32_t tms570_rti_get_timecount(struct timecounter tc)
     38{
     39  return TMS570_RTI.RTIFRC0;
     40}
    4041
    4142/**
     
    7374  /* enable timer */
    7475  TMS570_RTI.RTIGCTRL = 1;
     76  /* set timecounter */
     77  tms570_rti_tc.tc_get_timecount = tms570_rti_get_timecount;
     78  tms570_rti_tc.tc_counter_mask = 0xffffffff;
     79  tms570_rti_tc.tc_frequency = BSP_PLL_OUT_CLOCK;
     80  tms570_rti_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
     81  rtems_timecounter_install(&tms570_rti_tc);
    7582}
    7683
     
    8390{
    8491  TMS570_RTI.RTIINTFLAG = 0x00000001;
    85   tms570_rti_last_tick_fcr0 = TMS570_RTI.RTICOMP0 - TMS570_RTI.RTIUDCP0;
    8692}
    8793
     
    125131}
    126132
    127 /**
    128  * @brief returns the nanoseconds since last tick
    129  *
    130  * Return the nanoseconds since last tick
    131  *
    132  * @retval x nanoseconds
    133  *
    134  */
    135 static uint32_t tms570_clock_driver_nanoseconds_since_last_tick( void )
    136 {
    137   uint32_t actual_fcr0 = TMS570_RTI.RTIFRC0;
    138   uint32_t usec_since_tick;
    139 
    140   usec_since_tick = actual_fcr0 - tms570_rti_last_tick_fcr0;
    141 
    142   return usec_since_tick * 1000;
    143 }
    144 
    145133#define Clock_driver_support_initialize_hardware \
    146134                        tms570_clock_driver_support_initialize_hardware
     
    151139#define Clock_driver_support_shutdown_hardware \
    152140                        tms570_clock_driver_support_shutdown_hardware
    153 #define Clock_driver_nanoseconds_since_last_tick \
    154                         tms570_clock_driver_nanoseconds_since_last_tick
    155141
    156142#define Clock_driver_support_install_isr(Clock_isr, Old_ticker ) \
  • c/src/lib/libbsp/i386/pc386/clock/ckinit.c

    r7cd2484 r75acd9e  
    2929#include <libcpu/cpuModel.h>
    3030#include <assert.h>
     31#include <rtems/timecounter.h>
    3132
    3233#define CLOCK_VECTOR 0
     
    4041static void Clock_driver_support_at_tick_empty(void);
    4142static void clockOff(void);
    42 static void Clock_driver_support_at_tick_tsc(void);
    43 static uint32_t bsp_clock_nanoseconds_since_last_tick_tsc(void);
    44 static uint32_t bsp_clock_nanoseconds_since_last_tick_i8254(void);
    4543static void Clock_isr_handler(void *param);
    4644
    4745/*
    48  * Roughly the number of cycles per tick and per nanosecond. Note that these
     46 * Roughly the number of cycles per second. Note that these
    4947 * will be wildly inaccurate if the chip speed changes due to power saving
    5048 * or thermal modes.
     
    5250 * NOTE: These are only used when the TSC method is used.
    5351 */
    54 uint64_t pc586_tsc_per_tick;
    55 uint64_t pc586_nanoseconds_per_tick;
    56 
    57 uint64_t pc586_tsc_at_tick;
     52static uint64_t pc586_tsc_frequency;
     53
     54static struct timecounter pc386_tc;
    5855
    5956/* this driver may need to count ISRs per tick */
     
    6158#define CLOCK_DRIVER_ISRS_PER_TICK_VALUE pc386_isrs_per_tick
    6259
    63 /* The driver uses the count in Clock_driver_support_at_tick */
    64 extern volatile uint32_t Clock_driver_isrs;
     60extern volatile uint32_t Clock_driver_ticks;
    6561
    6662#define READ_8254( _lsb, _msb )                               \
     
    7571 *  tick method is preferred.
    7672 */
    77 void     (*Clock_driver_support_at_tick)(void) = NULL;
    78 uint32_t (*Clock_driver_nanoseconds_since_last_tick)(void) = NULL;
    79 
    80 /*
    81  *  What do we do at each clock tick?
    82  */
    83 static void Clock_driver_support_at_tick_tsc(void)
    84 {
    85   pc586_tsc_at_tick = rdtsc();
    86 }
    87 
    88 static void Clock_driver_support_at_tick_empty(void)
    89 {
    90 }
     73#define Clock_driver_support_at_tick()
    9174
    9275#define Clock_driver_support_install_isr( _new, _old ) \
     
    9578  } while(0)
    9679
    97 /*
    98  * Get nanoseconds using Pentium-compatible TSC register
    99  */
    100 static uint32_t bsp_clock_nanoseconds_since_last_tick_tsc(void)
    101 {
    102   uint64_t                 diff_nsec;
    103 
    104   diff_nsec = rdtsc() - pc586_tsc_at_tick;
    105 
    106   /*
    107    * At this point, with a hypothetical 10 GHz CPU clock and 100 Hz tick
    108    * clock, diff_nsec <= 27 bits.
    109    */
    110   diff_nsec *= pc586_nanoseconds_per_tick; /* <= 54 bits */
    111   diff_nsec /= pc586_tsc_per_tick;
    112 
    113   if (diff_nsec > pc586_nanoseconds_per_tick)
    114     /*
    115      * Hmmm... Some drift or rounding. Pin the value to 1 nanosecond before
    116      * the next tick.
    117      */
    118     /*    diff_nsec = pc586_nanoseconds_per_tick - 1; */
    119     diff_nsec = 12345;
    120 
    121   return (uint32_t)diff_nsec;
    122 }
    123 
    124 /*
    125  * Get nanoseconds using 8254 timer chip
    126  */
    127 static uint32_t bsp_clock_nanoseconds_since_last_tick_i8254(void)
    128 {
    129   uint32_t                 usecs, clicks, isrs;
    130   uint32_t                 usecs1, usecs2;
     80static uint32_t pc386_get_timecount_tsc(struct timecounter *tc)
     81{
     82  return (uint32_t)rdtsc();
     83}
     84
     85static uint32_t pc386_get_timecount_i8254(struct timecounter *tc)
     86{
     87  uint32_t                 irqs;
    13188  uint8_t                  lsb, msb;
    13289  rtems_interrupt_level    level;
     
    13794  rtems_interrupt_disable(level);
    13895    READ_8254(lsb, msb);
    139     isrs = Clock_driver_isrs;
     96    irqs = Clock_driver_ticks;
    14097  rtems_interrupt_enable(level);
    14198
    142   /*
    143    *  Now do the math
    144    */
    145   /* convert values read into counter clicks */
    146   clicks = ((msb << 8) | lsb);
    147 
    148   /* whole ISRs we have done since the last tick */
    149   usecs1 = (pc386_isrs_per_tick - isrs - 1) * pc386_microseconds_per_isr;
    150 
    151   /* the partial ISR we in the middle of now */
    152   usecs2 = pc386_microseconds_per_isr - TICK_TO_US(clicks);
    153 
    154   /* total microseconds */
    155   usecs = usecs1 + usecs2;
    156   #if 0
    157     printk( "usecs1=%d usecs2=%d ", usecs1, usecs2 );
    158     printk( "maxclicks=%d clicks=%d ISRs=%d ISRsper=%d usersPer=%d usecs=%d\n",
    159     pc386_clock_click_count, clicks,
    160     Clock_driver_isrs, pc386_isrs_per_tick,
    161     pc386_microseconds_per_isr, usecs );
    162   #endif
    163 
    164   /* return it in nanoseconds */
    165   return usecs * 1000;
    166 
     99  return (irqs + 1) * pc386_microseconds_per_isr - ((msb << 8) | lsb);
    167100}
    168101
     
    175108  uint8_t               then_lsb, then_msb, now_lsb, now_msb;
    176109  uint32_t              i;
    177 
    178   pc586_nanoseconds_per_tick =
    179     rtems_configuration_get_microseconds_per_tick() * 1000;
    180110
    181111  /*
     
    205135  }
    206136
    207   pc586_tsc_per_tick = rdtsc() - begin_time;
    208 
    209   /* Initialize "previous tick" counters */
    210   pc586_tsc_at_tick = rdtsc();
     137  pc586_tsc_frequency = rdtsc() - begin_time;
    211138
    212139#if 0
    213   printk( "CPU clock at %u MHz\n", (uint32_t)(pc586_tsc_per_tick / 1000000));
     140  printk( "CPU clock at %u MHz\n", (uint32_t)(pc586_tsc_frequency / 1000000));
    214141#endif
    215 
    216   pc586_tsc_per_tick /= rtems_clock_get_ticks_per_second();
    217142}
    218143
     
    300225  if ( use_8254 ) {
    301226    /* printk( "Use 8254\n" ); */
    302     Clock_driver_support_at_tick = Clock_driver_support_at_tick_empty;
    303     Clock_driver_nanoseconds_since_last_tick =
    304       bsp_clock_nanoseconds_since_last_tick_i8254;
     227    pc386_tc.tc_get_timecount = pc386_get_timecount_i8254;
     228    pc386_tc.tc_counter_mask = 0xffffffff;
     229    pc386_tc.tc_frequency = TIMER_TICK;
    305230  } else {
    306231    /* printk( "Use TSC\n" ); */
    307     Clock_driver_support_at_tick = Clock_driver_support_at_tick_tsc;
    308     Clock_driver_nanoseconds_since_last_tick =
    309       bsp_clock_nanoseconds_since_last_tick_tsc;
    310   }
    311 
    312   /* Shell installs nanosecond handler before calling
    313    * Clock_driver_support_initialize_hardware() :-(
    314    * so we do it again now that we're ready.
    315    */
    316   rtems_clock_set_nanoseconds_extension(
    317     Clock_driver_nanoseconds_since_last_tick
    318   );
    319 
     232    pc386_tc.tc_get_timecount = pc386_get_timecount_tsc;
     233    pc386_tc.tc_counter_mask = 0xffffffff;
     234    pc386_tc.tc_frequency = pc586_tsc_frequency;
     235  }
     236
     237  pc386_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
     238  rtems_timecounter_install(&pc386_tc);
    320239  Clock_isr_enabled = true;
    321240}
  • c/src/lib/libbsp/lm32/shared/clock/ckinit.c

    r7cd2484 r75acd9e  
    7676}
    7777
     78#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     79
    7880#include "../../../shared/clockdrv_shell.h"
    7981
  • c/src/lib/libbsp/lm32/shared/milkymist_clock/ckinit.c

    r7cd2484 r75acd9e  
    4747}
    4848
     49#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     50
    4951#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/m68k/av5282/clock/clock.c

    r7cd2484 r75acd9e  
    5959    } while (0)
    6060
     61#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     62
    6163#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/m68k/gen68360/clock/clock.c

    r7cd2484 r75acd9e  
    9999    } while (0)
    100100
     101#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     102
    101103#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/m68k/genmcf548x/clock/clock.c

    r7cd2484 r75acd9e  
    9999  } while (0)
    100100
     101#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     102
    101103#include "../../../shared/clockdrv_shell.h"
    102104
  • c/src/lib/libbsp/m68k/mcf52235/clock/clock.c

    r7cd2484 r75acd9e  
    44
    55#include <rtems.h>
     6#include <rtems/timecounter.h>
    67#include <bsp.h>
    78
     
    1112#define CLOCK_VECTOR (64+56)
    1213
    13 static uint32_t s_pcntrAtTick = 0;
    14 static uint32_t s_nanoScale = 0;
     14static rtems_timecounter_simple mcf52235_tc;
    1515
    16 /*
    17  * Provide nanosecond extension
    18  * Interrupts are disabled when this is called
    19  */
    20 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
     16static uint32_t mcf52235_tc_get(rtems_timecounter_simple *tc)
    2117{
    22   uint32_t i;
    23 
    24   if (MCF_PIT1_PCSR & MCF_PIT_PCSR_PIF) {
    25     i = s_pcntrAtTick + (MCF_PIT1_PMR - MCF_PIT1_PCNTR);
    26   }
    27   else {
    28     i = s_pcntrAtTick - MCF_PIT1_PCNTR;
    29   }
    30   return i * s_nanoScale;
     18  return MCF_PIT1_PCNTR;
    3119}
    3220
    33 #define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick
     21static bool mcf52235_tc_is_pending(rtems_timecounter_simple *tc)
     22{
     23  return (MCF_PIT1_PCSR & MCF_PIT_PCSR_PIF) != 0;
     24}
     25
     26static uint32_t mcf52235_tc_get_timecount(struct timecounter *tc)
     27{
     28  return rtems_timecounter_simple_downcounter_get(
     29    tc,
     30    mcf52235_tc_get,
     31    mcf52235_tc_is_pending
     32  );
     33}
     34
     35static void mcf52235_tc_tick(void)
     36{
     37  rtems_timecounter_simple_downcounter_tick(&mcf52235_tc, mcf52235_tc_get);
     38}
    3439
    3540/*
     
    3843#define Clock_driver_support_at_tick()             \
    3944    do {                                           \
    40         s_pcntrAtTick = MCF_PIT1_PCNTR;            \
    4145        MCF_PIT1_PCSR |= MCF_PIT_PCSR_PIF;         \
    4246    } while (0)                                    \
     
    6569static void Clock_driver_support_initialize_hardware(void)
    6670{
     71  uint32_t mask;
    6772  int level;
    6873  uint32_t pmr;
     
    7782    preScaleCode++;
    7883  }
    79   s_nanoScale = 1000000000 / (clk >> preScaleCode);
    8084
    8185  MCF_INTC0_ICR56 = MCF_INTC_ICR_IL(PIT3_IRQ_LEVEL) |
     
    9195  MCF_PIT1_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) |
    9296    MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN;
    93   s_pcntrAtTick = MCF_PIT1_PCNTR;
     97
     98  rtems_timecounter_simple_install(
     99    &mcf52235_tc,
     100    clk >> preScaleCode,
     101    pmr,
     102    mcf52235_tc_get_timecount
     103  );
    94104}
    95105
     106#define Clock_driver_timecounter_tick() mcf52235_tc_tick()
     107
    96108#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/m68k/mcf5225x/clock/clock.c

    r7cd2484 r75acd9e  
    44
    55#include <rtems.h>
     6#include <rtems/timecounter.h>
    67#include <bsp.h>
    78
     
    1112#define CLOCK_VECTOR (64+56)
    1213
    13 static uint32_t s_pcntrAtTick = 0;
    14 static uint32_t s_nanoScale = 0;
     14static rtems_timecounter_simple mcf5225x_tc;
    1515
    16 /*
    17  * Provide nanosecond extension
    18  * Interrupts are disabled when this is called
    19  */
    20 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
     16static uint32_t mcf5225x_tc_get(rtems_timecounter_simple *tc)
    2117{
    22     return MCF_PIT1_PCSR & MCF_PIT_PCSR_PIF ? (s_pcntrAtTick + (MCF_PIT1_PMR - MCF_PIT1_PCNTR)) * s_nanoScale : (s_pcntrAtTick - MCF_PIT1_PCNTR) * s_nanoScale;
     18  return MCF_PIT1_PCNTR;
    2319}
    2420
    25 #define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick
     21static bool mcf5225x_tc_is_pending(rtems_timecounter_simple *tc)
     22{
     23  return (MCF_PIT1_PCSR & MCF_PIT_PCSR_PIF) != 0;
     24}
     25
     26static uint32_t mcf5225x_tc_get_timecount(struct timecounter *tc)
     27{
     28  return rtems_timecounter_simple_downcounter_get(
     29    tc,
     30    mcf5225x_tc_get,
     31    mcf5225x_tc_is_pending
     32  );
     33}
     34
     35static void mcf5225x_tc_tick(void)
     36{
     37  rtems_timecounter_simple_downcounter_tick(&mcf5225x_tc, mcf5225x_tc_get);
     38}
    2639
    2740/*
     
    3043#define Clock_driver_support_at_tick()             \
    3144    do {                                           \
    32         s_pcntrAtTick = MCF_PIT1_PCNTR;            \
    3345        MCF_PIT1_PCSR |= MCF_PIT_PCSR_PIF;         \
    3446    } while (0)                                    \
     
    5769static void Clock_driver_support_initialize_hardware(void)
    5870{
     71  uint32_t mask;
    5972  int level;
    6073  uint32_t pmr;
     
    6982    preScaleCode++;
    7083  }
    71   s_nanoScale = 1000000000 / (clk >> preScaleCode);
    7284
    7385  MCF_INTC0_ICR56 = MCF_INTC_ICR_IL(PIT3_IRQ_LEVEL) |
     
    8395  MCF_PIT1_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) |
    8496    MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN;
    85   s_pcntrAtTick = MCF_PIT1_PCNTR;
     97
     98  rtems_timecounter_simple_install(
     99    &mcf5225x_tc,
     100    clk >> preScaleCode,
     101    pmr,
     102    mcf5225x_tc_get_timecount
     103  );
    86104}
    87105
     106#define Clock_driver_timecounter_tick() mcf5225x_tc_tick()
     107
    88108#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/m68k/mcf5235/clock/clock.c

    r7cd2484 r75acd9e  
    5959    } while (0)
    6060
     61#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     62
    6163#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/m68k/mcf5329/clock/clock.c

    r7cd2484 r75acd9e  
    44
    55#include <rtems.h>
     6#include <rtems/timecounter.h>
    67#include <bsp.h>
    78
     
    1112#define CLOCK_VECTOR (128+46)
    1213
    13 static uint32_t s_pcntrAtTick = 0;
    14 static uint32_t s_nanoScale = 0;
     14static rtems_timecounter_simple mcf5329_tc;
    1515
    16 /*
    17  * Provide nanosecond extension
    18  */
    19 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
     16static uint32_t mcf5329_tc_get(rtems_timecounter_simple *tc)
    2017{
    21   uint32_t i;
    22 
    23   if (MCF_PIT3_PCSR & MCF_PIT_PCSR_PIF) {
    24     i = s_pcntrAtTick + (MCF_PIT3_PMR - MCF_PIT3_PCNTR);
    25   } else {
    26     i = s_pcntrAtTick - MCF_PIT3_PCNTR;
    27   }
    28   return i * s_nanoScale;
     18  return MCF_PIT3_PCNTR;
    2919}
    3020
    31 #define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick
     21static bool mcf5329_tc_is_pending(rtems_timecounter_simple *tc)
     22{
     23  return (MCF_PIT3_PCSR & MCF_PIT_PCSR_PIF) != 0;
     24}
     25
     26static uint32_t mcf5329_tc_get_timecount(struct timecounter *tc)
     27{
     28  return rtems_timecounter_simple_downcounter_get(
     29    tc,
     30    mcf5329_tc_get,
     31    mcf5329_tc_is_pending
     32  );
     33}
     34
     35static void mcf5329_tc_tick(void)
     36{
     37  rtems_timecounter_simple_downcounter_tick(&mcf5329_tc, mcf5329_tc_get);
     38}
    3239
    3340/*
     
    3643#define Clock_driver_support_at_tick()             \
    3744    do {                                           \
    38         s_pcntrAtTick = MCF_PIT3_PCNTR;            \
    3945        MCF_PIT3_PCSR |= MCF_PIT_PCSR_PIF;         \
    4046    } while (0)                                    \
    41 
    4247
    4348/*
     
    7681    preScaleCode++;
    7782  }
    78   s_nanoScale = 1000000000 / (clk >> preScaleCode);
    79 
    8083  MCF_INTC1_ICR46 = MCF_INTC_ICR_IL(PIT3_IRQ_LEVEL);
    8184
     
    9093  MCF_PIT3_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) |
    9194    MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN;
    92   s_pcntrAtTick = MCF_PIT3_PCNTR;
     95
     96  rtems_timecounter_simple_install(
     97    &mcf5329_tc,
     98    clk >> preScaleCode,
     99    pmr,
     100    mcf5329_tc_get_timecount
     101  );
    93102}
    94103
     104#define Clock_driver_timecounter_tick() mcf5329_tc_tick()
     105
    95106#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/m68k/sim68000/clock/clockdrv.c

    r7cd2484 r75acd9e  
    4949}
    5050
     51#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     52
    5153#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/m68k/uC5282/clock/clock.c

    r7cd2484 r75acd9e  
    1313
    1414#include <rtems.h>
     15#include <rtems/timecounter.h>
    1516#include <bsp.h>
    1617#include <mcf5282/mcf5282.h>
     
    2021 */
    2122#define CLOCK_VECTOR (64+58)
     23
     24static rtems_timecounter_simple uC5282_tc;
     25
     26static uint32_t uC5282_tc_get(rtems_timecounter_simple *tc)
     27{
     28  return MCF5282_PIT3_PCNTR;
     29}
     30
     31static bool uC5282_tc_is_pending(rtems_timecounter_simple *tc)
     32{
     33  return (MCF5282_PIT3_PCSR & MCF5282_PIT_PCSR_PIF) != 0;
     34}
     35
     36static uint32_t uC5282_tc_get_timecount(struct timecounter *tc)
     37{
     38  return rtems_timecounter_simple_downcounter_get(
     39    tc,
     40    uC5282_tc_get,
     41    uC5282_tc_is_pending
     42  );
     43}
     44
     45static void uC5282_tc_tick(void)
     46{
     47  rtems_timecounter_simple_downcounter_tick(&uC5282_tc, uC5282_tc_get);
     48}
    2249
    2350/*
     
    3158#define NSEC_PER_PITC   __SRAMBASE.nsec_per_pitc
    3259#define FILTER_SHIFT    6
    33 
    34 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
    35 {
    36     int i = MCF5282_PIT3_PCNTR;
    37     if (MCF5282_PIT3_PCSR & MCF5282_PIT_PCSR_PIF)
    38         i = MCF5282_PIT3_PCNTR - PITC_PER_TICK;
    39     return (PITC_PER_TICK - i) * NSEC_PER_PITC;
    40 }
    41 
    42 #define Clock_driver_nanoseconds_since_last_tick \
    43     bsp_clock_nanoseconds_since_last_tick
    4460
    4561/*
     
    84100#define Clock_driver_support_initialize_hardware()                       \
    85101    do {                                                                 \
    86                 unsigned long long N;                                            \
     102        unsigned long long N;                                            \
    87103        int level;                                                       \
    88104        int preScaleCode = 0;                                            \
     
    117133                            MCF5282_PIT_PCSR_RLD |                       \
    118134                            MCF5282_PIT_PCSR_EN;                         \
     135         rtems_timecounter_simple_install( \
     136           &uC5282_tc, \
     137           bsp_get_CPU_clock_speed() >> (preScaleCode + 1), \
     138           PITC_PER_TICK, \
     139           uC5282_tc_get_timecount \
     140         ); \
    119141    } while (0)
    120142
     
    136158}
    137159
     160#define Clock_driver_timecounter_tick() uC5282_tc_tick()
     161
    138162#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/mips/csb350/clock/clockdrv.c

    r7cd2484 r75acd9e  
    8989#define Clock_driver_support_shutdown_hardware()
    9090
     91#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     92
    9193#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/mips/genmongoosev/clock/clockdrv.c

    r7cd2484 r75acd9e  
    5555  MONGOOSEV_WRITE_REGISTER( CLOCK_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER, 0 )
    5656
     57#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     58
    5759#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/mips/jmr3904/clock/clockdrv.c

    r7cd2484 r75acd9e  
    5656#define Clock_driver_support_shutdown_hardware()
    5757
     58#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     59
    5860#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/mips/rbtx4925/clock/clockdrv.c

    r7cd2484 r75acd9e  
    124124  } while(0)
    125125
     126#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
    126127
    127128#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/mips/rbtx4938/clock/clockdrv.c

    r7cd2484 r75acd9e  
    115115
    116116
     117#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     118
    117119#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/mips/shared/clock/clockdrv.c

    r7cd2484 r75acd9e  
    4444  } while(0)
    4545
    46 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
    47 {
    48   return 0;
    49 }
    50 
    51 #define Clock_driver_nanoseconds_since_last_tick \
    52   bsp_clock_nanoseconds_since_last_tick
    53 
    5446#define Clock_driver_support_shutdown_hardware() \
    5547  do { \
     
    5749  } while (0)
    5850
     51#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     52
    5953#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/nios2/nios2_iss/clock/clock.c

    r7cd2484 r75acd9e  
    5050}
    5151
     52#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     53
    5254#include "../../../shared/clockdrv_shell.h"
    5355
  • c/src/lib/libbsp/or1k/generic_or1k/clock/clockdrv.c

    r7cd2484 r75acd9e  
    2323#include <rtems/score/cpu.h>
    2424#include <rtems/score/or1k-utility.h>
     25#include <rtems/timecounter.h>
    2526
    2627/* The number of clock cycles before generating a tick timer interrupt. */
    2728#define TTMR_NUM_OF_CLOCK_TICKS_INTERRUPT     0x09ED9
    2829#define OR1K_CLOCK_CYCLE_TIME_NANOSECONDS     10
     30
     31static struct timecounter or1ksim_tc;
    2932
    3033/* CPU counter */
     
    7073}
    7174
     75static uint32_t or1ksim_get_timecount(struct timecounter *tc)
     76{
     77  uint32_t ticks_since_last_timer_interrupt;
     78
     79  ticks_since_last_timer_interrupt = _OR1K_mfspr(CPU_OR1K_SPR_TTCR);
     80
     81  return cpu_counter_ticks + ticks_since_last_timer_interrupt;
     82}
     83
     84CPU_Counter_ticks _CPU_Counter_read(void)
     85{
     86  return or1ksim_get_timecount(NULL);
     87}
     88
    7289static void generic_or1k_clock_initialize(void)
    7390{
     91  uint64_t frequency = (1000000000 / OR1K_CLOCK_CYCLE_TIME_NANOSECONDS);
    7492  uint32_t TTMR;
    7593
     
    91109  _OR1K_mtspr(CPU_OR1K_SPR_TTCR, 0);
    92110
    93   /* Initialize CPU Counter */
    94   cpu_counter_ticks = 0;
     111  /* Initialize timecounter */
     112  or1ksim_tc.tc_get_timecount = or1ksim_get_timecount;
     113  or1ksim_tc.tc_counter_mask = 0xffffffff;
     114  or1ksim_tc.tc_frequency = frequency;
     115  or1ksim_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
     116  rtems_timecounter_install(&or1ksim_tc);
    95117}
    96118
    97  static void generic_or1k_clock_cleanup(void)
     119static void generic_or1k_clock_cleanup(void)
    98120{
    99121 uint32_t sr;
     
    110132}
    111133
    112 /*
    113  *  Return the nanoseconds since last tick
    114  */
    115 static uint32_t generic_or1k_clock_nanoseconds_since_last_tick(void)
    116 {
    117   return
    118   TTMR_NUM_OF_CLOCK_TICKS_INTERRUPT * OR1K_CLOCK_CYCLE_TIME_NANOSECONDS;
    119 }
    120 
    121 CPU_Counter_ticks _CPU_Counter_read(void)
    122 {
    123   uint32_t ticks_since_last_timer_interrupt;
    124 
    125   ticks_since_last_timer_interrupt = _OR1K_mfspr(CPU_OR1K_SPR_TTCR);
    126 
    127   return cpu_counter_ticks + ticks_since_last_timer_interrupt;
    128 }
    129 
    130134CPU_Counter_ticks _CPU_Counter_difference(
    131135  CPU_Counter_ticks second,
     
    135139  return second - first;
    136140}
     141
    137142#define Clock_driver_support_at_tick() generic_or1k_clock_at_tick()
    138143
     
    147152#define Clock_driver_support_shutdown_hardware() generic_or1k_clock_cleanup()
    148153
    149 #define Clock_driver_nanoseconds_since_last_tick \
    150   generic_or1k_clock_nanoseconds_since_last_tick
    151 
    152154#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/powerpc/mpc55xxevb/clock/clock-config.c

    r7cd2484 r75acd9e  
    2727#include <mpc55xx/regs.h>
    2828
     29#include <rtems/timecounter.h>
     30
    2931void Clock_isr(void *arg);
    3032
    31 static uint64_t mpc55xx_clock_factor;
     33static rtems_timecounter_simple mpc55xx_tc;
    3234
    3335#if defined(MPC55XX_CLOCK_EMIOS_CHANNEL)
    3436
    3537#include <mpc55xx/emios.h>
     38
     39static uint32_t mpc55xx_tc_get(rtems_timecounter_simple *tc)
     40{
     41  return EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL].CCNTR.R;
     42}
     43
     44static bool mpc55xx_tc_is_pending(rtems_timecounter_simple *tc)
     45{
     46  return EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL].CSR.B.FLAG != 0;
     47}
     48
     49static uint32_t mpc55xx_tc_get_timecount(struct timecounter *tc)
     50{
     51  return rtems_timecounter_simple_upcounter_get(
     52    tc,
     53    mpc55xx_tc_get,
     54    mpc55xx_tc_is_pending
     55  );
     56}
     57
     58static void mpc55xx_tc_tick(void)
     59{
     60  rtems_timecounter_simple_upcounter_tick(&mpc55xx_tc, mpc55xx_tc_get);
     61}
    3662
    3763static void mpc55xx_clock_at_tick(void)
     
    6187static void mpc55xx_clock_initialize(void)
    6288{
     89  uint32_t mask;
    6390  volatile struct EMIOS_CH_tag *regs = &EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL];
    6491  union EMIOS_CCR_tag ccr = MPC55XX_ZERO_FLAGS;
     
    6895  uint64_t us_per_tick = rtems_configuration_get_microseconds_per_tick();
    6996  uint64_t interval = (reference_clock * us_per_tick) / 1000000;
    70 
    71   mpc55xx_clock_factor = (1000000000ULL << 32) / reference_clock;
    7297
    7398  /* Apply prescaler */
     
    111136  ccr.B.FREN = 1;
    112137  regs->CCR.R = ccr.R;
     138
     139  rtems_timecounter_simple_install(
     140    &mpc55xx_tc,
     141    reference_clock,
     142    interval,
     143    mpc55xx_tc_get_timecount
     144  );
    113145}
    114146
     
    123155}
    124156
    125 static uint32_t mpc55xx_clock_nanoseconds_since_last_tick(void)
    126 {
    127   volatile struct EMIOS_CH_tag *regs = &EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL];
    128   uint64_t c = regs->CCNTR.R;
    129   union EMIOS_CSR_tag csr = { .R = regs->CSR.R };
    130   uint64_t k = mpc55xx_clock_factor;
    131 
    132   if (csr.B.FLAG != 0) {
    133     c = regs->CCNTR.R + regs->CADR.R + 1;
    134   }
    135 
    136   return (uint32_t) ((c * k) >> 32);
    137 }
    138 
    139157#elif defined(MPC55XX_CLOCK_PIT_CHANNEL)
     158
     159static uint32_t mpc55xx_tc_get(rtems_timecounter_simple *tc)
     160{
     161  return PIT_RTI.CHANNEL [MPC55XX_CLOCK_PIT_CHANNEL].CVAL.R;
     162}
     163
     164static bool mpc55xx_tc_is_pending(rtems_timecounter_simple *tc)
     165{
     166  return PIT_RTI.CHANNEL [MPC55XX_CLOCK_PIT_CHANNEL].TFLG.B.TIF != 0;
     167}
     168
     169static uint32_t mpc55xx_tc_get_timecount(struct timecounter *tc)
     170{
     171  return rtems_timecounter_simple_downcounter_get(
     172    tc,
     173    mpc55xx_tc_get,
     174    mpc55xx_tc_is_pending
     175  );
     176}
     177
     178static void mpc55xx_tc_tick(void)
     179{
     180  rtems_timecounter_simple_downcounter_tick(&mpc55xx_tc, mpc55xx_tc_get);
     181}
    140182
    141183static void mpc55xx_clock_at_tick(void)
     
    167209static void mpc55xx_clock_initialize(void)
    168210{
     211  uint32_t mask;
    169212  volatile PIT_RTI_CHANNEL_tag *channel =
    170213    &PIT_RTI.CHANNEL [MPC55XX_CLOCK_PIT_CHANNEL];
     
    175218  PIT_RTI_TCTRL_32B_tag tctrl = { .B = { .TIE = 1, .TEN = 1 } };
    176219
    177   mpc55xx_clock_factor = (1000000000ULL << 32) / reference_clock;
    178 
    179220  PIT_RTI.PITMCR.R = pitmcr.R;
    180221  channel->LDVAL.R = interval;
    181222  channel->TCTRL.R = tctrl.R;
     223
     224  rtems_timecounter_simple_install(
     225    &mpc55xx_tc,
     226    reference_clock,
     227    interval,
     228    mpc55xx_tc_get_timecount
     229  );
    182230}
    183231
     
    190238}
    191239
    192 static uint32_t mpc55xx_clock_nanoseconds_since_last_tick(void)
    193 {
    194   volatile PIT_RTI_CHANNEL_tag *channel =
    195     &PIT_RTI.CHANNEL [MPC55XX_CLOCK_PIT_CHANNEL];
    196   uint32_t c = channel->CVAL.R;
    197   uint32_t i = channel->LDVAL.R;
    198   uint64_t k = mpc55xx_clock_factor;
    199 
    200   if (channel->TFLG.B.TIF != 0) {
    201     c = channel->CVAL.R - i;
    202   }
    203 
    204   return (uint32_t) (((i - c) * k) >> 32);
    205 }
    206 
    207240#endif
    208241
     242#define Clock_driver_timecounter_tick() mpc55xx_tc_tick()
    209243#define Clock_driver_support_at_tick() \
    210244  mpc55xx_clock_at_tick()
     
    218252#define Clock_driver_support_shutdown_hardware() \
    219253  mpc55xx_clock_cleanup()
    220 #define Clock_driver_nanoseconds_since_last_tick \
    221   mpc55xx_clock_nanoseconds_since_last_tick
    222254
    223255/* Include shared source clock driver code */
  • c/src/lib/libbsp/powerpc/qoriq/clock/clock-config.c

    r7cd2484 r75acd9e  
    88
    99/*
    10  * Copyright (c) 2011-2012 embedded brains GmbH.  All rights reserved.
     10 * Copyright (c) 2011-2015 embedded brains GmbH.  All rights reserved.
    1111 *
    1212 *  embedded brains GmbH
    13  *  Obere Lagerstr. 30
     13 *  Dornierstr. 4
    1414 *  82178 Puchheim
    1515 *  Germany
     
    2020 * http://www.rtems.org/license/LICENSE.
    2121 */
     22
     23#include <rtems/timecounter.h>
    2224
    2325#include <libcpu/powerpc-utility.h>
     
    3032static rtems_isr Clock_isr(void *arg);
    3133
    32 static uint32_t qoriq_clock_last_ccr;
    33 
    34 static uint32_t qoriq_clock_nanoseconds_per_timer_tick;
    35 
    3634static volatile qoriq_pic_global_timer *const qoriq_clock =
    3735  #if QORIQ_CLOCK_TIMER < 4
     
    4139  #endif
    4240
     41static volatile qoriq_pic_global_timer *const qoriq_timecounter =
     42  #if QORIQ_CLOCK_TIMECOUNTER < 4
     43    &qoriq.pic.gta [QORIQ_CLOCK_TIMECOUNTER];
     44  #else
     45    &qoriq.pic.gtb [QORIQ_CLOCK_TIMECOUNTER - 4];
     46  #endif
     47
    4348#define CLOCK_INTERRUPT (QORIQ_IRQ_GT_BASE + QORIQ_CLOCK_TIMER)
     49
     50static struct timecounter qoriq_clock_tc;
    4451
    4552static void qoriq_clock_handler_install(rtems_isr_entry *old_isr)
     
    7885}
    7986
     87static uint32_t qoriq_clock_get_timecount(struct timecounter *tc)
     88{
     89  uint32_t ccr = qoriq_timecounter->ccr;
     90
     91  return GTCCR_COUNT_GET(-ccr);
     92}
     93
    8094static void qoriq_clock_initialize(void)
    8195{
    8296  uint32_t timer_frequency = BSP_bus_frequency / 8;
    83   uint32_t nanoseconds_per_second = 1000000000;
    8497  uint32_t interval = (uint32_t) (((uint64_t) timer_frequency
    8598    * (uint64_t) rtems_configuration_get_microseconds_per_tick()) / 1000000);
    8699
    87   qoriq_clock_nanoseconds_per_timer_tick =
    88     nanoseconds_per_second / timer_frequency;
     100  qoriq_clock->bcr = GTBCR_COUNT(interval);
    89101
    90   qoriq_clock->bcr = GTBCR_COUNT(interval);
    91   qoriq_clock_last_ccr = qoriq_clock->ccr;
     102  qoriq_timecounter->bcr = GTBCR_COUNT(0xffffffff);
     103
     104  qoriq_clock_tc.tc_get_timecount = qoriq_clock_get_timecount;
     105  qoriq_clock_tc.tc_counter_mask = GTCCR_COUNT_GET(0xffffffff);
     106  qoriq_clock_tc.tc_frequency = timer_frequency;
     107  qoriq_clock_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
     108  rtems_timecounter_install(&qoriq_clock_tc);
    92109}
    93110
     
    108125}
    109126
    110 static void qoriq_clock_at_tick(void)
    111 {
    112   qoriq_clock_last_ccr = qoriq_clock->ccr;
    113 }
    114 
    115 static uint32_t qoriq_clock_nanoseconds_since_last_tick(void)
    116 {
    117   uint32_t ccr = qoriq_clock->ccr;
    118   uint32_t bcr = qoriq_clock->bcr;
    119 
    120   if ((ccr & GTCCR_TOG) != (qoriq_clock_last_ccr & GTCCR_TOG)) {
    121     bcr += bcr;
    122   }
    123 
    124   return (bcr - GTCCR_COUNT_GET(ccr)) * qoriq_clock_nanoseconds_per_timer_tick;
    125 }
    126 
    127 #define Clock_driver_support_at_tick() \
    128   qoriq_clock_at_tick()
     127#define Clock_driver_support_at_tick()
    129128#define Clock_driver_support_initialize_hardware() \
    130129  qoriq_clock_initialize()
     
    133132#define Clock_driver_support_shutdown_hardware() \
    134133  qoriq_clock_cleanup()
    135 #define Clock_driver_nanoseconds_since_last_tick \
    136   qoriq_clock_nanoseconds_since_last_tick
    137134
    138135/* Include shared source clock driver code */
  • c/src/lib/libbsp/powerpc/qoriq/configure.ac

    r7cd2484 r75acd9e  
    155155RTEMS_BSPOPTS_HELP([QORIQ_CLOCK_TIMER],[global timer used for system clock, 0..3 maps to A0..A3, and 4..7 maps to B0..B3])
    156156
     157RTEMS_BSPOPTS_SET([QORIQ_CLOCK_TIMECOUNTER],[qoriq_core_1],[5])
     158RTEMS_BSPOPTS_SET([QORIQ_CLOCK_TIMECOUNTER],[*],[1])
     159RTEMS_BSPOPTS_HELP([QORIQ_CLOCK_TIMECOUNTER],[global timer used for the timecounter, 0..3 maps to A0..A3, and 4..7 maps to B0..B3])
     160
    157161RTEMS_BSPOPTS_SET([QORIQ_CHIP_VARIANT],[qoriq_t2080*],[QORIQ_CHIP_T2080])
    158162RTEMS_BSPOPTS_SET([QORIQ_CHIP_VARIANT],[qoriq_t4240*],[QORIQ_CHIP_T4240])
  • c/src/lib/libbsp/powerpc/shared/clock/clock.c

    r7cd2484 r75acd9e  
    88
    99/*
    10  * Copyright (c) 2008-2013 embedded brains GmbH.  All rights reserved.
     10 * Copyright (c) 2008-2015 embedded brains GmbH.  All rights reserved.
    1111 *
    1212 *  embedded brains GmbH
     
    2323#include <rtems.h>
    2424#include <rtems/clockdrv.h>
     25#include <rtems/timecounter.h>
    2526
    2627#include <libcpu/powerpc-utility.h>
     
    4748static uint32_t ppc_clock_next_time_base;
    4849
    49 static uint64_t ppc_clock_factor;
     50static struct timecounter ppc_tc;
     51
     52static uint32_t ppc_get_timecount(struct timecounter *tc)
     53{
     54  return ppc_time_base();
     55}
    5056
    5157static void ppc_clock_no_tick(void)
     
    162168}
    163169
    164 static uint32_t ppc_clock_nanoseconds_since_last_tick(void)
    165 {
    166   uint64_t k = ppc_clock_factor;
    167   uint32_t c = ppc_decrementer_register();
    168   uint32_t i = ppc_clock_decrementer_value + 1;
    169 
    170   return (uint32_t) (((i - c) * k) >> 32);
    171 }
    172 
    173 static uint32_t ppc_clock_nanoseconds_since_last_tick_ppc405(void)
    174 {
    175   uint64_t k = ppc_clock_factor;
    176   uint32_t i = ppc_clock_decrementer_value;
    177   uint32_t c = i - PPC_SPECIAL_PURPOSE_REGISTER(PPC405_PIT);
    178 
    179   if ((PPC_SPECIAL_PURPOSE_REGISTER(PPC405_TSR) & BOOKE_TSR_DIS) != 0) {
    180     c = i - PPC_SPECIAL_PURPOSE_REGISTER(PPC405_PIT) + i;
    181   }
    182 
    183   return (uint32_t) ((c * k) >> 32);
    184 }
    185 
    186170void Clock_exit(void)
    187171{
     
    202186  uint64_t us_per_tick = rtems_configuration_get_microseconds_per_tick();
    203187  uint32_t interval = (uint32_t) ((frequency * us_per_tick) / 1000000);
     188  uint32_t mask;
    204189
    205190  /*
    206191   * Set default ticker.
    207    *
    208    * The function rtems_clock_tick() returns a status code.  This value
    209    * will be discarded since the RTEMS documentation claims that it is
    210    * always successful.
    211192   */
    212   ppc_clock_tick = (void (*)(void)) rtems_clock_tick;
    213 
    214   /* Factor for nano seconds extension */
    215   ppc_clock_factor = (1000000000ULL << 32) / frequency;
     193  ppc_clock_tick = rtems_timecounter_tick;
    216194
    217195  if (ppc_cpu_is_bookE() != PPC_BOOKE_405) {
     
    224202      RTEMS_SYSLOG_ERROR( "decrementer value would be zero, will be set to maximum value instead\n");
    225203    }
    226 
    227     /* Set the nanoseconds since last tick handler */
    228     rtems_clock_set_nanoseconds_extension( ppc_clock_nanoseconds_since_last_tick);
    229 
    230204    if (ppc_cpu_is_bookE()) {
    231205      /* Set decrementer auto-reload value */
     
    254228    ppc_clock_decrementer_value = interval;
    255229
    256     /* Set the nanoseconds since last tick handler */
    257     rtems_clock_set_nanoseconds_extension(ppc_clock_nanoseconds_since_last_tick_ppc405);
    258 
    259230    /* Install exception handler */
    260231    ppc_exc_set_handler(ASM_BOOKE_DEC_VECTOR, ppc_clock_exception_handler_ppc405);
     
    267238  }
    268239
     240  /* Install timecounter */
     241  ppc_tc.tc_get_timecount = ppc_get_timecount;
     242  ppc_tc.tc_counter_mask = 0xffffffff;
     243  ppc_tc.tc_frequency = frequency;
     244  ppc_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
     245  rtems_timecounter_install(&ppc_tc);
     246
    269247  return RTEMS_SUCCESSFUL;
    270248}
  • c/src/lib/libbsp/shared/clock_driver_simidle.c

    r7cd2484 r75acd9e  
    2828    clock_driver_enabled = false; \
    2929  } while (0)
     30
     31#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
    3032
    3133#include "clockdrv_shell.h"
  • c/src/lib/libbsp/shared/clockdrv_shell.h

    r7cd2484 r75acd9e  
    2121#include <rtems/clockdrv.h>
    2222
     23#ifdef Clock_driver_nanoseconds_since_last_tick
     24#error "Update driver to use the timecounter instead of nanoseconds extension"
     25#endif
     26
    2327/**
    2428 * @defgroup bsp_clock Clock Support
     
    3842#ifndef Clock_driver_support_find_timer
    3943  #define Clock_driver_support_find_timer()
     44#endif
     45
     46/*
     47 * A specialized clock driver may use for example rtems_timecounter_tick_simple()
     48 * instead of the default.
     49 */
     50#ifndef Clock_driver_timecounter_tick
     51  #ifdef CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     52    #define Clock_driver_timecounter_tick() rtems_clock_tick()
     53  #else
     54    #define Clock_driver_timecounter_tick() rtems_timecounter_tick()
     55  #endif
    4056#endif
    4157
     
    7995
    8096  #if CLOCK_DRIVER_USE_FAST_IDLE
    81     do {
    82       rtems_clock_tick();
    83     } while (
    84       _Thread_Heir == _Thread_Executing
    85         && _Thread_Executing->Start.entry_point
    86           == (Thread_Entry) rtems_configuration_get_idle_task()
    87     );
    88 
    89     Clock_driver_support_at_tick();
    90     return;
     97    {
     98      struct timecounter *tc = _Timecounter;
     99      uint64_t us_per_tick = rtems_configuration_get_microseconds_per_tick();
     100      uint32_t interval = (uint32_t)
     101        ((tc->tc_frequency * us_per_tick) / 1000000);
     102
     103      Clock_driver_timecounter_tick();
     104
     105      while (
     106        _Thread_Heir == _Thread_Executing
     107          && _Thread_Executing->Start.entry_point
     108            == (Thread_Entry) rtems_configuration_get_idle_task()
     109      ) {
     110        _Timecounter_Tick_simple(interval, (*tc->tc_get_timecount)(tc));
     111      }
     112
     113      Clock_driver_support_at_tick();
     114    }
    91115  #else
    92116    /*
     
    102126       */
    103127      if ( !Clock_driver_isrs ) {
    104         rtems_clock_tick();
     128        Clock_driver_timecounter_tick();
    105129
    106130        Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK;
     
    111135       *  The driver is one ISR per clock tick.
    112136       */
    113       rtems_clock_tick();
     137      Clock_driver_timecounter_tick();
    114138    #endif
    115139  #endif
     
    161185  Clock_driver_support_install_isr( Clock_isr, Old_ticker );
    162186
    163   #if defined(Clock_driver_nanoseconds_since_last_tick)
    164     rtems_clock_set_nanoseconds_extension(
    165       Clock_driver_nanoseconds_since_last_tick
    166     );
    167   #endif
    168 
    169187  /*
    170188   *  Now initialize the hardware that is the source of the tick ISR.
  • c/src/lib/libbsp/sparc/erc32/clock/ckinit.c

    r7cd2484 r75acd9e  
    2626#include <bspopts.h>
    2727#include <rtems/counter.h>
     28#include <rtems/timecounter.h>
    2829
    2930#if SIMSPARC_FAST_IDLE==1
     
    4546extern int CLOCK_SPEED;
    4647
    47 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
     48static rtems_timecounter_simple erc32_tc;
     49
     50static uint32_t erc32_tc_get( rtems_timecounter_simple *tc )
    4851{
    49   uint32_t clicks;
    50   uint32_t usecs;
    51 
    52   clicks = ERC32_MEC.Real_Time_Clock_Counter;
    53 
    54   if ( ERC32_Is_interrupt_pending( ERC32_INTERRUPT_REAL_TIME_CLOCK ) ) {
    55     clicks = ERC32_MEC.Real_Time_Clock_Counter;
    56     usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
    57   } else {
    58     usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
    59   }
    60   return usecs * 1000;
     52  return ERC32_MEC.Real_Time_Clock_Counter;
    6153}
    6254
    63 #define Clock_driver_nanoseconds_since_last_tick \
    64   bsp_clock_nanoseconds_since_last_tick
     55static bool erc32_tc_is_pending( rtems_timecounter_simple *tc )
     56{
     57  return ERC32_Is_interrupt_pending( ERC32_INTERRUPT_REAL_TIME_CLOCK );
     58}
     59
     60static uint32_t erc32_tc_get_timecount( struct timecounter *tc )
     61{
     62  return rtems_timecounter_simple_downcounter_get(
     63    tc,
     64    erc32_tc_get,
     65    erc32_tc_is_pending
     66  );
     67}
     68
     69static void erc32_tc_tick( void )
     70{
     71  rtems_timecounter_simple_downcounter_tick(
     72    &erc32_tc,
     73    erc32_tc_get
     74  );
     75}
    6576
    6677static CPU_Counter_ticks erc32_counter_difference(
     
    7687#define Clock_driver_support_initialize_hardware() \
    7788  do { \
     89    uint32_t frequency = 1000000; \
    7890    /* approximately 1 us per countdown */ \
    7991    ERC32_MEC.Real_Time_Clock_Scalar  = CLOCK_SPEED - 1; \
     
    90102        ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
    91103        ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO \
     104    );  \
     105    rtems_timecounter_simple_install( \
     106        &erc32_tc, \
     107        frequency, \
     108        rtems_configuration_get_microseconds_per_tick(), \
     109        erc32_tc_get_timecount \
    92110    ); \
    93111    _SPARC_Counter_initialize( \
     
    95113      erc32_counter_difference \
    96114    ); \
    97     rtems_counter_initialize_converter(1000000); \
     115    rtems_counter_initialize_converter( frequency ); \
    98116  } while (0)
     117
     118#define Clock_driver_timecounter_tick() erc32_tc_tick()
    99119
    100120#define Clock_driver_support_shutdown_hardware() \
  • c/src/lib/libbsp/sparc/leon2/clock/ckinit.c

    r7cd2484 r75acd9e  
    2525#include <bsp.h>
    2626#include <bspopts.h>
     27#include <rtems/timecounter.h>
    2728
    2829#if SIMSPARC_FAST_IDLE==1
    2930#define CLOCK_DRIVER_USE_FAST_IDLE 1
    3031#endif
     32
     33static rtems_timecounter_simple leon2_tc;
     34
     35static uint32_t leon2_tc_get( rtems_timecounter_simple *tc )
     36{
     37  return LEON_REG.Timer_Counter_1;
     38}
     39
     40static bool leon2_tc_is_pending( rtems_timecounter_simple *tc )
     41{
     42  return LEON_Is_interrupt_pending( LEON_INTERRUPT_TIMER1 );
     43}
     44
     45static uint32_t leon2_tc_get_timecount( struct timecounter *tc )
     46{
     47  return rtems_timecounter_simple_downcounter_get(
     48    tc,
     49    leon2_tc_get,
     50    leon2_tc_is_pending
     51  );
     52}
     53
     54static void leon2_tc_tick( void )
     55{
     56  rtems_timecounter_simple_downcounter_tick( &leon2_tc, leon2_tc_get );
     57}
    3158
    3259/*
     
    5582        LEON_REG_TIMER_COUNTER_LOAD_COUNTER  \
    5683    ); \
     84    rtems_timecounter_simple_install( \
     85      &leon2_tc, \
     86      1000000, \
     87      rtems_configuration_get_microseconds_per_tick(), \
     88      leon2_tc_get_timecount \
     89    ); \
    5790  } while (0)
    5891
     
    6396  } while (0)
    6497
    65 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
    66 {
    67   uint32_t clicks;
    68   uint32_t usecs;
    69 
    70   clicks = LEON_REG.Timer_Counter_1;
    71 
    72   if ( LEON_Is_interrupt_pending( LEON_INTERRUPT_TIMER1 ) ) {
    73     clicks = LEON_REG.Timer_Counter_1;
    74     usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
    75   } else {
    76     usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
    77   }
    78   return usecs * 1000;
    79 }
    80 
    81 #define Clock_driver_nanoseconds_since_last_tick \
    82     bsp_clock_nanoseconds_since_last_tick
     98#define Clock_driver_timecounter_tick() leon2_tc_tick()
    8399
    84100#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/sparc/leon3/clock/ckinit.c

    r7cd2484 r75acd9e  
    2525#include <ambapp.h>
    2626#include <rtems/score/profiling.h>
     27#include <rtems/timecounter.h>
    2728
    2829/* The LEON3 BSP Timer driver can rely on the Driver Manager if the
     
    4041/* LEON3 Timer system interrupt number */
    4142static int clkirq;
     43
     44static bool leon3_tc_use_irqmp;
     45
     46static rtems_timecounter_simple leon3_tc;
     47
     48static uint32_t leon3_tc_get(rtems_timecounter_simple *tc)
     49{
     50  return LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
     51}
     52
     53static bool leon3_tc_is_pending(rtems_timecounter_simple *tc)
     54{
     55  return LEON_Is_interrupt_pending(clkirq);
     56}
     57
     58static uint32_t leon3_tc_get_timecount(struct timecounter *tc)
     59{
     60  return rtems_timecounter_simple_downcounter_get(
     61    tc,
     62    leon3_tc_get,
     63    leon3_tc_is_pending
     64  );
     65}
     66
     67static uint32_t leon3_tc_get_timecount_irqmp(struct timecounter *tc)
     68{
     69  return LEON3_IrqCtrl_Regs->timestamp[0].counter;
     70}
     71
     72static void leon3_tc_tick(void)
     73{
     74  if (leon3_tc_use_irqmp) {
     75    rtems_timecounter_tick();
     76  } else {
     77    rtems_timecounter_simple_downcounter_tick(&leon3_tc, leon3_tc_get);
     78  }
     79}
    4280
    4381static void leon3_clock_profiling_interrupt_delay(void)
     
    113151}
    114152
     153static void leon3_clock_initialize(void)
     154{
     155  volatile struct irqmp_timestamp_regs *irqmp_ts =
     156    &LEON3_IrqCtrl_Regs->timestamp[0];
     157
     158  LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].reload =
     159    rtems_configuration_get_microseconds_per_tick() - 1;
     160  LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl =
     161    GPTIMER_TIMER_CTRL_EN | GPTIMER_TIMER_CTRL_RS |
     162      GPTIMER_TIMER_CTRL_LD | GPTIMER_TIMER_CTRL_IE;
     163
     164  if (leon3_irqmp_has_timestamp(irqmp_ts)) {
     165    leon3_tc.tc.tc_get_timecount = leon3_tc_get_timecount_irqmp;
     166    leon3_tc.tc.tc_counter_mask = 0xffffffff;
     167    leon3_tc.tc.tc_frequency = ambapp_freq_get(&ambapp_plb, LEON3_Timer_Adev);
     168    leon3_tc.tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
     169    leon3_tc_use_irqmp = true;
     170    rtems_timecounter_install(&leon3_tc.tc);
     171  } else {
     172    rtems_timecounter_simple_install(
     173      &leon3_tc,
     174      LEON3_GPTIMER_0_FREQUENCY_SET_BY_BOOT_LOADER,
     175      rtems_configuration_get_microseconds_per_tick(),
     176      leon3_tc_get_timecount
     177    );
     178  }
     179}
     180
    115181#define Clock_driver_support_initialize_hardware() \
    116   do { \
    117     LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].reload = \
    118       rtems_configuration_get_microseconds_per_tick() - 1; \
    119     \
    120     LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = \
    121       GPTIMER_TIMER_CTRL_EN | GPTIMER_TIMER_CTRL_RS | \
    122         GPTIMER_TIMER_CTRL_LD | GPTIMER_TIMER_CTRL_IE; \
    123   } while (0)
     182  leon3_clock_initialize()
    124183
    125184#define Clock_driver_support_shutdown_hardware() \
     
    129188  } while (0)
    130189
    131 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
    132 {
    133   uint32_t clicks;
    134   uint32_t usecs;
    135 
    136   if ( !LEON3_Timer_Regs )
    137     return 0;
    138 
    139   clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
    140 
    141   if ( LEON_Is_interrupt_pending( clkirq ) ) {
    142     clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
    143     usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
    144   } else {
    145     usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
    146   }
    147   return usecs * 1000;
    148 }
    149 
    150 #define Clock_driver_nanoseconds_since_last_tick \
    151         bsp_clock_nanoseconds_since_last_tick
     190#define Clock_driver_timecounter_tick() leon3_tc_tick()
    152191
    153192#include "../../../shared/clockdrv_shell.h"
  • c/src/lib/libbsp/sparc64/shared/clock/ckinit.c

    r7cd2484 r75acd9e  
    115115  } while ( 0 )
    116116
     117#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     118
    117119#include "../../../shared/clockdrv_shell.h"
    118120
  • c/src/lib/libcpu/arm/at91rm9200/clock/clock.c

    r7cd2484 r75acd9e  
    2222#include <at91rm9200.h>
    2323#include <at91rm9200_pmc.h>
    24 
    25 static unsigned long st_pimr_reload;
    2624
    2725/**
     
    7876  } while(0)
    7977
    80 uint16_t st_pimr_value;
    8178static void Clock_driver_support_initialize_hardware(void)
    8279{
    8380  uint32_t st_str;
    8481  int slck;
     82  unsigned long value;
    8583
    8684  /* the system timer is driven from SLCK */
    8785  slck = at91rm9200_get_slck();
    88   st_pimr_value = (((rtems_configuration_get_microseconds_per_tick() * slck) +
     86  value = (((rtems_configuration_get_microseconds_per_tick() * slck) +
    8987                      (1000000/2))/ 1000000);
    90   st_pimr_reload = st_pimr_value;
    9188
    9289  /* read the status to clear the int */
     
    9895
    9996  /* set the timer value */
    100   ST_REG(ST_PIMR) = st_pimr_reload;
     97  ST_REG(ST_PIMR) = value;
    10198}
    102 
    103 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
    104 {
    105   uint16_t slck_counts;
    106 
    107   slck_counts = st_pimr_value - st_pimr_reload;
    108   return (rtems_configuration_get_microseconds_per_tick() * slck_counts * 1000)
    109      / st_pimr_value;
    110 }
    111 
    112 #define Clock_driver_nanoseconds_since_last_tick \
    113   bsp_clock_nanoseconds_since_last_tick
    11499
    115100#define Clock_driver_support_at_tick() \
     
    127112}
    128113
     114#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     115
    129116#include "../../../../libbsp/shared/clockdrv_shell.h"
  • c/src/lib/libcpu/arm/lpc22xx/clock/clockdrv.c

    r7cd2484 r75acd9e  
    1818#include <lpc22xx.h>
    1919#include <rtems/bspIo.h>  /* for printk */
     20#include <rtems/timecounter.h>
    2021
    2122void Clock_isr(rtems_irq_hdl_param arg);
     
    2324static void clock_isr_off(const rtems_irq_connect_data *unused);
    2425static int clock_isr_is_on(const rtems_irq_connect_data *irq);
     26
     27static rtems_timecounter_simple lpc22xx_tc;
     28
     29static uint32_t lpc22xx_tc_get(rtems_timecounter_simple *tc)
     30{
     31  return T0TC;
     32}
     33
     34static bool lpc22xx_tc_is_pending(rtems_timecounter_simple *tc)
     35{
     36  return (T0IR & 0x1) != 0;
     37}
     38
     39static uint32_t lpc22xx_tc_get_timecount(struct timecounter *tc)
     40{
     41  return rtems_timecounter_simple_upcounter_get(
     42    tc,
     43    lpc22xx_tc_get,
     44    lpc22xx_tc_is_pending
     45  );
     46}
     47
     48static void lpc22xx_tc_tick(void)
     49{
     50  rtems_timecounter_simple_upcounter_tick(&lpc22xx_tc, lpc22xx_tc_get);
     51}
    2552
    2653/* Replace the first value with the clock's interrupt name. */
     
    75102#define Clock_driver_support_initialize_hardware() \
    76103  do { \
     104    uint32_t mask; \
    77105    /* disable and clear timer 0, set to  */ \
    78106    T0TCR &= 0;                              \
    79     /* TC is incrementet on every pclk.*/    \
     107    /* TC is incremented on every pclk.*/    \
    80108    T0PC   = 0;                              \
    81109    /* initialize the timer period and prescaler */  \
     
    90118    /* enable interrupt, skyeye will check this*/ \
    91119    T0IR |= 0x01; \
     120    /* install timecounter */ \
     121    rtems_timecounter_simple_install( \
     122      &lpc22xx_tc, \
     123      LPC22xx_Fpclk, \
     124      T0MR0, \
     125      lpc22xx_tc_get_timecount \
     126    ); \
    92127  } while (0)
    93128
     
    104139    BSP_remove_rtems_irq_handler(&clock_isr_data);                  \
    105140  } while (0)
    106 
    107 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
    108 {
    109   uint32_t clicks;
    110   uint32_t microseconds;
    111 
    112   clicks = T0TC;  /* T0TC is the 32bit time counter 0 */
    113 
    114   microseconds = (rtems_configuration_get_microseconds_per_tick() - clicks);
    115   return microseconds * 1000;
    116 }
    117 
    118 #define Clock_driver_nanoseconds_since_last_tick \
    119         bsp_clock_nanoseconds_since_last_tick
    120141
    121142/**
     
    150171}
    151172
     173#define Clock_driver_timecounter_tick() lpc22xx_tc_tick()
     174
    152175/* Make sure to include this, and only at the end of the file */
    153176#include "../../../../libbsp/shared/clockdrv_shell.h"
  • c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c

    r7cd2484 r75acd9e  
    131131}
    132132
     133#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     134
    133135/* Make sure to include this, and only at the end of the file */
     136
    134137#include "../../../../libbsp/shared/clockdrv_shell.h"
  • c/src/lib/libcpu/arm/pxa255/clock/clock.c

    r7cd2484 r75acd9e  
    117117}
    118118
     119#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     120
    119121#include "../../../../libbsp/shared/clockdrv_shell.h"
  • c/src/lib/libcpu/arm/s3c24xx/clock/clockdrv.c

    r7cd2484 r75acd9e  
    2727  .isOn   = clock_isr_is_on,
    2828};
    29 
    30 /**
    31  *  Return the nanoseconds since last tick
    32  */
    33 static uint32_t clock_driver_get_nanoseconds_since_last_tick(void)
    34 {
    35   return 0;
    36 }
    37 
    38 #define Clock_driver_nanoseconds_since_last_tick \
    39   clock_driver_get_nanoseconds_since_last_tick
    4029
    4130/**
     
    7564        uint32_t cr; \
    7665        uint32_t freq; \
     66        uint32_t mask; \
    7767        /* set MUX for Timer4 to 1/16 */ \
    7868        cr=rTCFG1 & 0xFFF0FFFF; \
     
    132122}
    133123
     124#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
     125
    134126/* Make sure to include this, and only at the end of the file */
    135127#include "../../../../libbsp/shared/clockdrv_shell.h"
  • c/src/lib/libcpu/powerpc/mpc6xx/clock/c_clock.c

    r7cd2484 r75acd9e  
    3030#include <rtems/bspIo.h>                /* for printk() */
    3131#include <libcpu/powerpc-utility.h>
     32#include <rtems/timecounter.h>
    3233
    3334#include <bspopts.h>   /* for CLOCK_DRIVER_USE_FAST_IDLE */
     
    4950static uint32_t   Clock_Decrementer_value;
    5051
    51 /*
    52  *  This is the value by which elapsed count down timer ticks are multiplied to
    53  *  give an elapsed duration in nanoseconds, left-shifted by 32 bits
    54  */
    55 static uint64_t   Clock_Decrementer_reference;
     52static struct timecounter Clock_TC;
     53
     54static uint32_t Clock_Get_timecount(struct timecounter *tc)
     55{
     56  return ppc_time_base();
     57}
    5658
    5759void clockOff(void* unused)
     
    9597{
    9698  #if (CLOCK_DRIVER_USE_FAST_IDLE == 1)
    97     do {
    98       rtems_clock_tick();
    99     } while (
     99    rtems_interrupt_level level;
     100    uint32_t tb;
     101
     102    rtems_interrupt_disable(level);
     103
     104    tb = ppc_time_base();
     105    rtems_timecounter_tick();
     106
     107    while (
    100108      _Thread_Heir == _Thread_Executing
    101109        && _Thread_Executing->Start.entry_point
    102110          == (Thread_Entry) rtems_configuration_get_idle_task()
    103     );
    104 
     111    ) {
     112      tb += Clock_Decrementer_value;
     113      ppc_set_time_base( tb );
     114      rtems_timecounter_tick();
     115    }
     116
     117    rtems_interrupt_enable(level);
    105118  #else
    106     rtems_clock_tick();
     119    rtems_timecounter_tick();
    107120  #endif
    108121}
     
    142155
    143156    Clock_driver_ticks += 1;
    144 
    145157    /*
    146158     *  Real Time Clock counter/timer is set to automatically reload.
     
    188200}
    189201
    190 
    191202/*
    192203 *  Clock_exit
     
    198209{
    199210  (void) BSP_disconnect_clock_handler ();
    200 }
    201 
    202 static uint32_t Clock_driver_nanoseconds_since_last_tick(void)
    203 {
    204   uint32_t clicks, tmp;
    205 
    206   PPC_Get_decrementer( clicks );
    207 
    208   /*
    209    * Multiply by 1000 here separately from below so we do not overflow
    210    * and get a negative value.
    211    */
    212   tmp = (Clock_Decrementer_value - clicks) * 1000;
    213   tmp /= (BSP_bus_frequency/BSP_time_base_divisor);
    214 
    215   return tmp * 1000;
    216 }
    217 
    218 static uint32_t Clock_driver_nanoseconds_since_last_tick_bookE(void)
    219 {
    220   uint32_t clicks;
    221   uint64_t c;
    222 
    223   PPC_Get_decrementer( clicks );
    224   c = Clock_Decrementer_value - clicks;
    225 
    226   /*
    227    * Check whether a clock tick interrupt is pending and hence that the
    228    * decrementer's wrapped. If it has, we'll compensate by returning a time one
    229    * tick period longer.
    230    *
    231    * We have to check interrupt status after reading the decrementer. If we
    232    * don't, we may miss an interrupt and read a wrapped decrementer value
    233    * without compensating for it
    234    */
    235   if ( _read_BOOKE_TSR() & BOOKE_TSR_DIS )
    236   {
    237     /*
    238      * Re-read the decrementer: The tick interrupt may have been
    239      * generated and the decrementer wrapped during the time since we
    240      * last read it and the time we checked the interrupt status
    241      */
    242     PPC_Get_decrementer( clicks );
    243     c = (Clock_Decrementer_value - clicks) + Clock_Decrementer_value;
    244   }
    245 
    246   return (uint32_t)((c * Clock_Decrementer_reference) >> 32);
    247211}
    248212
     
    263227            rtems_configuration_get_milliseconds_per_tick();
    264228
    265   Clock_Decrementer_reference = ((uint64_t)1000000U<<32)/
    266             (BSP_bus_frequency/BSP_time_base_divisor);
    267 
    268229  /* set the decrementer now, prior to installing the handler
    269230   * so no interrupts will happen in a while.
     
    284245
    285246    rtems_interrupt_enable(l);
    286 
    287     /*
    288      *  Set the nanoseconds since last tick handler
    289      */
    290     rtems_clock_set_nanoseconds_extension(
    291       Clock_driver_nanoseconds_since_last_tick_bookE
    292     );
    293   }
    294   else
    295   {
    296     /*
    297      *  Set the nanoseconds since last tick handler
    298      */
    299     rtems_clock_set_nanoseconds_extension(
    300       Clock_driver_nanoseconds_since_last_tick
    301     );
    302   }
     247  }
     248
     249  Clock_TC.tc_get_timecount = Clock_Get_timecount;
     250  Clock_TC.tc_counter_mask = 0xffffffff;
     251  Clock_TC.tc_frequency = (1000 * BSP_bus_frequency) / BSP_time_base_divisor;
     252  Clock_TC.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
     253  rtems_timecounter_install(&Clock_TC);
    303254
    304255  /*
Note: See TracChangeset for help on using the changeset viewer.