1 | /* |
---|
2 | * Copyright (c) 2011, 2017 embedded brains GmbH. 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 | #include <rtems/timecounter.h> |
---|
10 | |
---|
11 | #include <libcpu/powerpc-utility.h> |
---|
12 | |
---|
13 | #include <bsp.h> |
---|
14 | #include <bsp/irq.h> |
---|
15 | |
---|
16 | /* This is defined in dev/clock/clockimpl.h */ |
---|
17 | static rtems_isr Clock_isr(void *arg); |
---|
18 | |
---|
19 | static struct timecounter t32mppc_clock_tc; |
---|
20 | |
---|
21 | #define CLOCK_DRIVER_USE_ONLY_BOOT_PROCESSOR |
---|
22 | |
---|
23 | void t32mppc_decrementer_dispatch(void) |
---|
24 | { |
---|
25 | PPC_SET_SPECIAL_PURPOSE_REGISTER(BOOKE_TSR, BOOKE_TSR_DIS); |
---|
26 | Clock_isr(NULL); |
---|
27 | } |
---|
28 | |
---|
29 | static uint32_t t32mppc_clock_get_timecount(struct timecounter *tc) |
---|
30 | { |
---|
31 | return ppc_time_base(); |
---|
32 | } |
---|
33 | |
---|
34 | static void t32mppc_clock_initialize(void) |
---|
35 | { |
---|
36 | uint64_t frequency = bsp_time_base_frequency / 10; |
---|
37 | uint32_t us_per_tick = rtems_configuration_get_microseconds_per_tick(); |
---|
38 | uint32_t interval = (uint32_t) ((frequency * us_per_tick) / 1000000); |
---|
39 | |
---|
40 | PPC_SET_SPECIAL_PURPOSE_REGISTER(BOOKE_DECAR, interval - 1); |
---|
41 | PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS( |
---|
42 | BOOKE_TCR, |
---|
43 | BOOKE_TCR_DIE | BOOKE_TCR_ARE |
---|
44 | ); |
---|
45 | ppc_set_decrementer_register(interval - 1); |
---|
46 | |
---|
47 | t32mppc_clock_tc.tc_get_timecount = t32mppc_clock_get_timecount; |
---|
48 | t32mppc_clock_tc.tc_counter_mask = 0xffffffff; |
---|
49 | t32mppc_clock_tc.tc_frequency = bsp_time_base_frequency; |
---|
50 | t32mppc_clock_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; |
---|
51 | rtems_timecounter_install(&t32mppc_clock_tc); |
---|
52 | } |
---|
53 | |
---|
54 | #define Clock_driver_support_initialize_hardware() \ |
---|
55 | t32mppc_clock_initialize() |
---|
56 | |
---|
57 | /* Include shared source clock driver code */ |
---|
58 | #include "../../../shared/dev/clock/clockimpl.h" |
---|