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 | #include <bsp/clock-armv7m.h> |
---|
16 | |
---|
17 | #include <rtems.h> |
---|
18 | #include <rtems/sysinit.h> |
---|
19 | |
---|
20 | #ifdef ARM_MULTILIB_ARCH_V7M |
---|
21 | |
---|
22 | /* This is defined in dev/clock/clockimpl.h */ |
---|
23 | static void Clock_isr(void *arg); |
---|
24 | |
---|
25 | ARMV7M_Timecounter _ARMV7M_TC; |
---|
26 | |
---|
27 | static uint32_t _ARMV7M_TC_get_timecount(struct timecounter *base) |
---|
28 | { |
---|
29 | return _ARMV7M_Clock_counter((ARMV7M_Timecounter *) base); |
---|
30 | } |
---|
31 | |
---|
32 | static void _ARMV7M_Clock_handler(void) |
---|
33 | { |
---|
34 | _ARMV7M_Interrupt_service_enter(); |
---|
35 | Clock_isr(NULL); |
---|
36 | _ARMV7M_Interrupt_service_leave(); |
---|
37 | } |
---|
38 | |
---|
39 | static void _ARMV7M_Clock_handler_install(void) |
---|
40 | { |
---|
41 | _ARMV7M_Set_exception_priority_and_handler( |
---|
42 | ARMV7M_VECTOR_SYSTICK, |
---|
43 | BSP_ARMV7M_SYSTICK_PRIORITY, |
---|
44 | _ARMV7M_Clock_handler |
---|
45 | ); |
---|
46 | } |
---|
47 | |
---|
48 | static void _ARMV7M_Clock_initialize(void) |
---|
49 | { |
---|
50 | volatile ARMV7M_Systick *systick; |
---|
51 | ARMV7M_Timecounter *tc; |
---|
52 | |
---|
53 | systick = _ARMV7M_Systick; |
---|
54 | tc = &_ARMV7M_TC; |
---|
55 | |
---|
56 | systick->csr = ARMV7M_SYSTICK_CSR_ENABLE |
---|
57 | | ARMV7M_SYSTICK_CSR_TICKINT |
---|
58 | | ARMV7M_SYSTICK_CSR_CLKSOURCE; |
---|
59 | |
---|
60 | tc->base.tc_get_timecount = _ARMV7M_TC_get_timecount; |
---|
61 | tc->base.tc_counter_mask = 0xffffffff; |
---|
62 | tc->base.tc_frequency = _ARMV7M_Clock_frequency(); |
---|
63 | tc->base.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; |
---|
64 | rtems_timecounter_install(&tc->base); |
---|
65 | } |
---|
66 | |
---|
67 | static void _ARMV7M_Clock_initialize_early(void) |
---|
68 | { |
---|
69 | volatile ARMV7M_Systick *systick; |
---|
70 | uint32_t us_per_tick; |
---|
71 | uint64_t freq; |
---|
72 | uint32_t interval; |
---|
73 | |
---|
74 | systick = _ARMV7M_Systick; |
---|
75 | us_per_tick = rtems_configuration_get_microseconds_per_tick(); |
---|
76 | freq = _ARMV7M_Clock_frequency(); |
---|
77 | |
---|
78 | interval = (uint32_t) ((freq * us_per_tick) / 1000000); |
---|
79 | |
---|
80 | systick->rvr = interval; |
---|
81 | systick->cvr = 0; |
---|
82 | systick->csr = ARMV7M_SYSTICK_CSR_ENABLE | ARMV7M_SYSTICK_CSR_CLKSOURCE; |
---|
83 | } |
---|
84 | |
---|
85 | RTEMS_SYSINIT_ITEM( |
---|
86 | _ARMV7M_Clock_initialize_early, |
---|
87 | RTEMS_SYSINIT_CPU_COUNTER, |
---|
88 | RTEMS_SYSINIT_ORDER_FIRST |
---|
89 | ); |
---|
90 | |
---|
91 | #define Clock_driver_support_initialize_hardware() \ |
---|
92 | _ARMV7M_Clock_initialize() |
---|
93 | |
---|
94 | #define Clock_driver_support_install_isr(isr) \ |
---|
95 | _ARMV7M_Clock_handler_install() |
---|
96 | |
---|
97 | /* Include shared source clock driver code */ |
---|
98 | #include "../../../shared/dev/clock/clockimpl.h" |
---|
99 | |
---|
100 | #endif /* ARM_MULTILIB_ARCH_V7M */ |
---|