Changeset 370cdefd in rtems


Ignore:
Timestamp:
Jan 21, 2016, 9:53:16 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
5ebdd289
Parents:
12bc6c5
git-author:
Sebastian Huber <sebastian.huber@…> (01/21/16 09:53:16)
git-committer:
Sebastian Huber <sebastian.huber@…> (01/21/16 12:25:07)
Message:

arm: Use DWT CYCCNT for timecounter if available

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/shared/armv7m/clock/armv7m-clock-config.c

    r12bc6c5 r370cdefd  
    2626typedef struct {
    2727  rtems_timecounter_simple base;
     28  void (*tick)(void);
    2829  bool countflag;
    2930} ARMV7M_Timecounter;
     
    3132static ARMV7M_Timecounter _ARMV7M_TC;
    3233
    33 static uint32_t _ARMV7M_TC_get(rtems_timecounter_simple *tc)
     34static uint32_t _ARMV7M_TC_systick_get(rtems_timecounter_simple *tc)
    3435{
    3536  volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
     
    3839}
    3940
    40 static bool _ARMV7M_TC_is_pending(rtems_timecounter_simple *base)
     41static bool _ARMV7M_TC_systick_is_pending(rtems_timecounter_simple *base)
    4142{
    4243  ARMV7M_Timecounter *tc = (ARMV7M_Timecounter *) base;
     
    5960}
    6061
    61 static uint32_t _ARMV7M_TC_get_timecount(struct timecounter *tc)
     62static uint32_t _ARMV7M_TC_systick_get_timecount(struct timecounter *tc)
    6263{
    6364  return rtems_timecounter_simple_downcounter_get(
    6465    tc,
    65     _ARMV7M_TC_get,
    66     _ARMV7M_TC_is_pending
     66    _ARMV7M_TC_systick_get,
     67    _ARMV7M_TC_systick_is_pending
    6768  );
    6869}
    6970
    70 static void _ARMV7M_TC_at_tick(rtems_timecounter_simple *base)
     71static void _ARMV7M_TC_systick_at_tick(rtems_timecounter_simple *base)
    7172{
    7273  ARMV7M_Timecounter *tc = (ARMV7M_Timecounter *) base;
     
    7980}
    8081
    81 static void _ARMV7M_TC_tick(void)
     82static void _ARMV7M_TC_systick_tick(void)
    8283{
    8384  rtems_timecounter_simple_downcounter_tick(
    8485    &_ARMV7M_TC.base,
    85     _ARMV7M_TC_get,
    86     _ARMV7M_TC_at_tick
     86    _ARMV7M_TC_systick_get,
     87    _ARMV7M_TC_systick_at_tick
    8788  );
     89}
     90
     91static uint32_t _ARMV7M_TC_dwt_get_timecount(struct timecounter *tc)
     92{
     93  volatile ARMV7M_DWT *dwt = _ARMV7M_DWT;
     94
     95  return dwt->cyccnt;
     96}
     97
     98static void _ARMV7M_TC_dwt_tick(void)
     99{
     100  rtems_timecounter_tick();
     101}
     102
     103static void _ARMV7M_TC_tick(void)
     104{
     105  (*_ARMV7M_TC.tick)();
    88106}
    89107
     
    106124static void _ARMV7M_Systick_initialize(void)
    107125{
     126  volatile ARMV7M_DWT *dwt = _ARMV7M_DWT;
    108127  volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
    109128  #ifdef BSP_ARMV7M_SYSTICK_FREQUENCY
     
    114133  uint64_t us_per_tick = rtems_configuration_get_microseconds_per_tick();
    115134  uint64_t interval = (freq * us_per_tick) / 1000000ULL;
     135  uint32_t dwt_ctrl;
    116136
    117137  systick->rvr = (uint32_t) interval;
     
    121141    | ARMV7M_SYSTICK_CSR_CLKSOURCE;
    122142
    123   rtems_timecounter_simple_install(
    124     &_ARMV7M_TC.base,
    125     freq,
    126     interval,
    127     _ARMV7M_TC_get_timecount
    128   );
     143  dwt_ctrl = dwt->ctrl;
     144  if ((dwt_ctrl & ARMV7M_DWT_CTRL_NOCYCCNT) == 0) {
     145    dwt->ctrl = dwt_ctrl | ARMV7M_DWT_CTRL_CYCCNTENA;
     146    _ARMV7M_TC.base.tc.tc_get_timecount = _ARMV7M_TC_dwt_get_timecount;
     147    _ARMV7M_TC.base.tc.tc_counter_mask = 0xffffffff;
     148    _ARMV7M_TC.base.tc.tc_frequency = freq;
     149    _ARMV7M_TC.base.tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
     150    _ARMV7M_TC.tick = _ARMV7M_TC_dwt_tick;
     151    rtems_timecounter_install(&_ARMV7M_TC.base.tc);
     152  } else {
     153    _ARMV7M_TC.tick = _ARMV7M_TC_systick_tick;
     154    rtems_timecounter_simple_install(
     155      &_ARMV7M_TC.base,
     156      freq,
     157      interval,
     158      _ARMV7M_TC_systick_get_timecount
     159    );
     160  }
    129161}
    130162
  • cpukit/score/cpu/arm/rtems/score/armv7m.h

    r12bc6c5 r370cdefd  
    7474#endif
    7575} ARMV7M_Exception_frame;
     76
     77typedef struct {
     78  uint32_t comp;
     79  uint32_t mask;
     80  uint32_t function;
     81  uint32_t reserved;
     82} ARMV7M_DWT_comparator;
     83
     84typedef struct {
     85#define ARMV7M_DWT_CTRL_NOCYCCNT (1U << 25)
     86#define ARMV7M_DWT_CTRL_CYCCNTENA (1U << 0)
     87  uint32_t ctrl;
     88  uint32_t cyccnt;
     89  uint32_t cpicnt;
     90  uint32_t exccnt;
     91  uint32_t sleepcnt;
     92  uint32_t lsucnt;
     93  uint32_t foldcnt;
     94  uint32_t pcsr;
     95  ARMV7M_DWT_comparator comparator[249];
     96  uint32_t reserved_e0001fb0[1];
     97  uint32_t lar;
     98  uint32_t lsr;
     99} ARMV7M_DWT;
    76100
    77101typedef struct {
     
    324348  }
    325349
     350#define ARMV7M_DWT_BASE 0xe0001000
    326351#define ARMV7M_SCS_BASE 0xe000e000
    327352#define ARMV7M_ICTAC_BASE (ARMV7M_SCS_BASE + 0x0)
     
    331356#define ARMV7M_MPU_BASE (ARMV7M_SCS_BASE + 0xd90)
    332357
     358#define _ARMV7M_DWT \
     359  ((volatile ARMV7M_DWT *) ARMV7M_DWT_BASE)
    333360#define _ARMV7M_ICTAC \
    334361  ((volatile ARMV7M_ICTAC *) ARMV7M_ICTAC_BASE)
Note: See TracChangeset for help on using the changeset viewer.