RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
clock-armv7m.h
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;
50 uint32_t interval;
51 uint32_t counter;
52 uint32_t ticks;
53 uint32_t csr;
54
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;
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 */
ARMV7M Architecture Support.
ISR_Level rtems_interrupt_level
Interrupt level type.
Definition: intr.h:42
#define rtems_interrupt_enable(_isr_cookie)
Enable RTEMS Interrupt.
Definition: intr.h:110
#define rtems_interrupt_disable(_isr_cookie)
Disable RTEMS Interrupt.
Definition: intr.h:99
#define RTEMS_PREDICT_FALSE(_exp)
Returns the value of the specified integral expression and tells the compiler that the predicted valu...
Definition: basedefs.h:388
Definition: timetc.h:46
Timecounter API.