Changeset 75acd9e in rtems for c/src/lib/libbsp/sparc


Ignore:
Timestamp:
Apr 1, 2015, 1:33:25 PM (7 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/libbsp/sparc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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"
Note: See TracChangeset for help on using the changeset viewer.