RTEMS  5.0.0
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
24 extern "C" {
25 #endif /* __cplusplus */
26 
27 #ifdef ARM_MULTILIB_ARCH_V7M
28 
29 typedef struct {
30  struct timecounter base;
31  uint32_t ticks;
32 } ARMV7M_Timecounter;
33 
34 extern ARMV7M_Timecounter _ARMV7M_TC;
35 
36 static 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 
46 static 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 
54  systick = _ARMV7M_Systick;
55  interval = systick->rvr;
56 
58  counter = systick->cvr;
59  ticks = tc->ticks;
60 
61  if ((systick->csr & ARMV7M_SYSTICK_CSR_COUNTFLAG) != 0) {
62  ticks += interval;
63  tc->ticks = ticks;
64  }
65 
66  counter = interval - counter + ticks;
68 
69  return counter;
70 }
71 
72 #endif /* ARM_MULTILIB_ARCH_V7M */
73 
74 #ifdef __cplusplus
75 }
76 #endif /* __cplusplus */
77 
78 #endif /* BSP_CLOCK_ARMV7M_H */
ARMV7M Architecture Support.
Timecounter API.
Definition: timetc.h:46
#define rtems_interrupt_disable(_isr_cookie)
Disable RTEMS Interrupt.
Definition: intr.h:99
#define rtems_interrupt_enable(_isr_cookie)
Enable RTEMS Interrupt.
Definition: intr.h:110
ISR_Level rtems_interrupt_level
Interrupt level type.
Definition: intr.h:42