source: rtems/bsps/arm/include/bsp/clock-armv7m.h @ 222570a

Last change on this file since 222570a was 222570a, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 9, 2019 at 6:06:01 AM

bsps/arm: Optimize ARMv7-M CPU counter

Update #3456.

  • Property mode set to 100644
File size: 1.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#ifndef BSP_CLOCK_ARMV7M_H
16#define BSP_CLOCK_ARMV7M_H
17
18#include <rtems/score/armv7m.h>
19#include <rtems/timecounter.h>
20
21#include <bsp.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif /* __cplusplus */
26
27#ifdef ARM_MULTILIB_ARCH_V7M
28
29typedef struct {
30  struct timecounter base;
31  uint32_t ticks;
32} ARMV7M_Timecounter;
33
34extern ARMV7M_Timecounter _ARMV7M_TC;
35
36static inline uint32_t _ARMV7M_Clock_frequency(void)
37{
38#ifdef BSP_ARMV7M_SYSTICK_FREQUENCY
39  return BSP_ARMV7M_SYSTICK_FREQUENCY;
40#else
41  volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
42  return ARMV7M_SYSTICK_CALIB_TENMS_GET(systick->calib) * 100;
43#endif
44}
45
46static uint32_t _ARMV7M_Clock_counter(ARMV7M_Timecounter *tc)
47{
48  volatile ARMV7M_Systick *systick;
49  rtems_interrupt_level level;
50  uint32_t interval;
51  uint32_t counter;
52  uint32_t ticks;
53  uint32_t csr;
54
55  rtems_interrupt_disable(level);
56  systick = _ARMV7M_Systick;
57  counter = systick->cvr;
58  csr = systick->csr;
59  interval = systick->rvr;
60  ticks = tc->ticks;
61
62  if (RTEMS_PREDICT_FALSE((csr & ARMV7M_SYSTICK_CSR_COUNTFLAG) != 0)) {
63    counter = systick->cvr;
64    ticks += interval;
65    tc->ticks = ticks;
66  }
67
68  counter = interval - counter + ticks;
69  rtems_interrupt_enable(level);
70
71  return counter;
72}
73
74#endif /* ARM_MULTILIB_ARCH_V7M */
75
76#ifdef __cplusplus
77}
78#endif /* __cplusplus */
79
80#endif /* BSP_CLOCK_ARMV7M_H */
Note: See TracBrowser for help on using the repository browser.