RTEMS 6.1-rc2
Loading...
Searching...
No Matches
clock-armv7m.h
1/*
2 * Copyright (c) 2011, 2018 Sebastian Huber. All rights reserved.
3 *
4 * The license and distribution terms for this file may be
5 * found in the file LICENSE in this distribution or at
6 * http://www.rtems.org/license/LICENSE.
7 */
8
9#ifndef BSP_CLOCK_ARMV7M_H
10#define BSP_CLOCK_ARMV7M_H
11
12#include <rtems/score/armv7m.h>
13#include <rtems/timecounter.h>
14
15#include <bsp.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21#ifdef ARM_MULTILIB_ARCH_V7M
22
23typedef struct {
24 struct timecounter base;
25 uint32_t ticks;
26} ARMV7M_Timecounter;
27
28extern ARMV7M_Timecounter _ARMV7M_TC;
29
30static inline uint32_t _ARMV7M_Clock_frequency(void)
31{
32#ifdef BSP_ARMV7M_SYSTICK_FREQUENCY
33 return BSP_ARMV7M_SYSTICK_FREQUENCY;
34#else
35 volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
36 return ARMV7M_SYSTICK_CALIB_TENMS_GET(systick->calib) * 100;
37#endif
38}
39
40static uint32_t _ARMV7M_Clock_counter(ARMV7M_Timecounter *tc)
41{
42 volatile ARMV7M_Systick *systick;
44 uint32_t interval;
45 uint32_t counter;
46 uint32_t ticks;
47 uint32_t csr;
48
50 systick = _ARMV7M_Systick;
51 counter = systick->cvr;
52 csr = systick->csr;
53 interval = systick->rvr;
54 ticks = tc->ticks;
55
56 if (RTEMS_PREDICT_FALSE((csr & ARMV7M_SYSTICK_CSR_COUNTFLAG) != 0)) {
57 counter = systick->cvr;
58 ticks += interval;
59 tc->ticks = ticks;
60 }
61
62 counter = interval - counter + ticks;
64
65 return counter;
66}
67
68#endif /* ARM_MULTILIB_ARCH_V7M */
69
70#ifdef __cplusplus
71}
72#endif /* __cplusplus */
73
74#endif /* BSP_CLOCK_ARMV7M_H */
This header file provides interfaces of the ARMv7-M architecture support.
#define RTEMS_PREDICT_FALSE(_exp)
Evaluates the integral expression and tells the compiler that the predicted value is false (0).
Definition: basedefs.h:732
ISR_Level rtems_interrupt_level
This integer type represents interrupt levels.
Definition: intr.h:111
#define rtems_interrupt_enable(_isr_cookie)
Restores the previous interrupt level on the current processor.
Definition: intr.h:311
#define rtems_interrupt_disable(_isr_cookie)
Disables the maskable interrupts on the current processor.
Definition: intr.h:264
Definition: timetc.h:60
This header file provides the Timecounter Support API.