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