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 May 22, 2018 at 6:52:13 AM

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
Line 
1/*
2 * Copyright (c) 2011, 2018 Sebastian Huber.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
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
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#include <bsp/clock-armv7m.h>
16
17#include <rtems.h>
18#include <rtems/sysinit.h>
19
20#ifdef ARM_MULTILIB_ARCH_V7M
21
22/* This is defined in dev/clock/clockimpl.h */
23static void Clock_isr(void *arg);
24
25ARMV7M_Timecounter _ARMV7M_TC;
26
27static uint32_t _ARMV7M_TC_get_timecount(struct timecounter *base)
28{
29  return _ARMV7M_Clock_counter((ARMV7M_Timecounter *) base);
30}
31
32static void _ARMV7M_Clock_handler(void)
33{
34  _ARMV7M_Interrupt_service_enter();
35  Clock_isr(NULL);
36  _ARMV7M_Interrupt_service_leave();
37}
38
39static void _ARMV7M_Clock_handler_install(void)
40{
41  _ARMV7M_Set_exception_priority_and_handler(
42    ARMV7M_VECTOR_SYSTICK,
43    BSP_ARMV7M_SYSTICK_PRIORITY,
44    _ARMV7M_Clock_handler
45  );
46}
47
48static void _ARMV7M_Clock_initialize(void)
49{
50  volatile ARMV7M_Systick *systick;
51  ARMV7M_Timecounter *tc;
52
53  systick = _ARMV7M_Systick;
54  tc = &_ARMV7M_TC;
55
56  systick->csr = ARMV7M_SYSTICK_CSR_ENABLE
57    | ARMV7M_SYSTICK_CSR_TICKINT
58    | ARMV7M_SYSTICK_CSR_CLKSOURCE;
59
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);
65}
66
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)
92{
93  volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
94
95  systick->csr = 0;
96}
97
98#define Clock_driver_support_initialize_hardware() \
99  _ARMV7M_Clock_initialize()
100
101#define Clock_driver_support_install_isr(isr) \
102  _ARMV7M_Clock_handler_install()
103
104#define Clock_driver_support_shutdown_hardware() \
105  _ARMV7M_Clock_cleanup()
106
107/* Include shared source clock driver code */
108#include "../../../shared/dev/clock/clockimpl.h"
109
110#endif /* ARM_MULTILIB_ARCH_V7M */
Note: See TracBrowser for help on using the repository browser.