source: rtems/bsps/arm/shared/clock/clock-armv7m.c @ 762fa62

5
Last change on this file since 762fa62 was 762fa62, checked in by Sebastian Huber <sebastian.huber@…>, on 05/22/18 at 06:52:13

arm: Simplify CPU counter support

Use the standard ARMv7-M systick module for the ARMv7-M CPU counter
instead of DWT counter since the DWT counter is affected by power saving
states.

Use an inline function for _CPU_Counter_difference() for all ARM BSPs.

Update #3456.

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[e263c16]1/*
[762fa62]2 * Copyright (c) 2011, 2018 Sebastian Huber.  All rights reserved.
[e263c16]3 *
4 *  embedded brains GmbH
[762fa62]5 *  Dornierstr. 4
[e263c16]6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
[c499856]12 * http://www.rtems.org/license/LICENSE.
[e263c16]13 */
14
[762fa62]15#include <bsp/clock-armv7m.h>
[e263c16]16
[762fa62]17#include <rtems.h>
18#include <rtems/sysinit.h>
[34c61517]19
20#ifdef ARM_MULTILIB_ARCH_V7M
21
[7632906]22/* This is defined in dev/clock/clockimpl.h */
[d2c665b7]23static void Clock_isr(void *arg);
[e263c16]24
[762fa62]25ARMV7M_Timecounter _ARMV7M_TC;
[e263c16]26
[762fa62]27static uint32_t _ARMV7M_TC_get_timecount(struct timecounter *base)
[76ac1ee3]28{
[762fa62]29  return _ARMV7M_Clock_counter((ARMV7M_Timecounter *) base);
[76ac1ee3]30}
31
[762fa62]32static void _ARMV7M_Clock_handler(void)
[e263c16]33{
34  _ARMV7M_Interrupt_service_enter();
[1aebb70]35  Clock_isr(NULL);
[e263c16]36  _ARMV7M_Interrupt_service_leave();
37}
38
[762fa62]39static void _ARMV7M_Clock_handler_install(void)
[e263c16]40{
[d8f05c83]41  _ARMV7M_Set_exception_priority_and_handler(
[e263c16]42    ARMV7M_VECTOR_SYSTICK,
[d8f05c83]43    BSP_ARMV7M_SYSTICK_PRIORITY,
[762fa62]44    _ARMV7M_Clock_handler
[e263c16]45  );
46}
47
[762fa62]48static void _ARMV7M_Clock_initialize(void)
[e263c16]49{
[762fa62]50  volatile ARMV7M_Systick *systick;
51  ARMV7M_Timecounter *tc;
52
53  systick = _ARMV7M_Systick;
54  tc = &_ARMV7M_TC;
55
[34c61517]56  systick->csr = ARMV7M_SYSTICK_CSR_ENABLE
57    | ARMV7M_SYSTICK_CSR_TICKINT
58    | ARMV7M_SYSTICK_CSR_CLKSOURCE;
[75acd9e]59
[762fa62]60  tc->base.tc_get_timecount = _ARMV7M_TC_get_timecount;
61  tc->base.tc_counter_mask = 0xffffffff;
62  tc->base.tc_frequency = _ARMV7M_Clock_frequency();
63  tc->base.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
64  rtems_timecounter_install(&tc->base);
[e263c16]65}
66
[762fa62]67static void _ARMV7M_Clock_initialize_early(void)
68{
69  volatile ARMV7M_Systick *systick;
70  uint32_t us_per_tick;
71  uint64_t freq;
72  uint32_t interval;
73
74  systick = _ARMV7M_Systick;
75  us_per_tick = rtems_configuration_get_microseconds_per_tick();
76  freq = _ARMV7M_Clock_frequency();
77
78  interval = (uint32_t) ((freq * us_per_tick) / 1000000);
79
80  systick->rvr = interval;
81  systick->cvr = 0;
82  systick->csr = ARMV7M_SYSTICK_CSR_ENABLE | ARMV7M_SYSTICK_CSR_CLKSOURCE;
83}
84
85RTEMS_SYSINIT_ITEM(
86  _ARMV7M_Clock_initialize_early,
87  RTEMS_SYSINIT_CPU_COUNTER,
88  RTEMS_SYSINIT_ORDER_FIRST
89);
90
91static void _ARMV7M_Clock_cleanup(void)
[e263c16]92{
93  volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
94
95  systick->csr = 0;
96}
97
98#define Clock_driver_support_initialize_hardware() \
[762fa62]99  _ARMV7M_Clock_initialize()
[e263c16]100
[f3b29236]101#define Clock_driver_support_install_isr(isr) \
[762fa62]102  _ARMV7M_Clock_handler_install()
[e263c16]103
104#define Clock_driver_support_shutdown_hardware() \
[762fa62]105  _ARMV7M_Clock_cleanup()
[e263c16]106
107/* Include shared source clock driver code */
[7632906]108#include "../../../shared/dev/clock/clockimpl.h"
[34c61517]109
110#endif /* ARM_MULTILIB_ARCH_V7M */
Note: See TracBrowser for help on using the repository browser.