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

Last change on this file since b8a0a496 was b8a0a496, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 8, 2019 at 9:59:29 AM

bsps/arm: Fix ARMv7-M CPU counter

Read the current counter value again after we know that we had an
underflow.

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
54  systick = _ARMV7M_Systick;
55  interval = systick->rvr;
56
57  rtems_interrupt_disable(level);
58  counter = systick->cvr;
59  ticks = tc->ticks;
60
61  if ((systick->csr & ARMV7M_SYSTICK_CSR_COUNTFLAG) != 0) {
62    counter = systick->cvr;
63    ticks += interval;
64    tc->ticks = ticks;
65  }
66
67  counter = interval - counter + ticks;
68  rtems_interrupt_enable(level);
69
70  return counter;
71}
72
73#endif /* ARM_MULTILIB_ARCH_V7M */
74
75#ifdef __cplusplus
76}
77#endif /* __cplusplus */
78
79#endif /* BSP_CLOCK_ARMV7M_H */
Note: See TracBrowser for help on using the repository browser.