source: rtems/c/src/lib/libbsp/powerpc/qoriq/clock/clock-config.c @ 75acd9e

4.115
Last change on this file since 75acd9e was 75acd9e, checked in by Alexander Krutwig <alexander.krutwig@…>, on 04/01/15 at 13:33:25

bsps: Convert clock drivers to use a timecounter

Update #2271.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup QorIQ
5 *
6 * @brief QorIQ clock configuration.
7 */
8
9/*
10 * Copyright (c) 2011-2015 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#include <rtems/timecounter.h>
24
25#include <libcpu/powerpc-utility.h>
26
27#include <bsp.h>
28#include <bsp/qoriq.h>
29#include <bsp/irq.h>
30
31/* This is defined in clockdrv_shell.h */
32static rtems_isr Clock_isr(void *arg);
33
34static volatile qoriq_pic_global_timer *const qoriq_clock =
35  #if QORIQ_CLOCK_TIMER < 4
36    &qoriq.pic.gta [QORIQ_CLOCK_TIMER];
37  #else
38    &qoriq.pic.gtb [QORIQ_CLOCK_TIMER - 4];
39  #endif
40
41static volatile qoriq_pic_global_timer *const qoriq_timecounter =
42  #if QORIQ_CLOCK_TIMECOUNTER < 4
43    &qoriq.pic.gta [QORIQ_CLOCK_TIMECOUNTER];
44  #else
45    &qoriq.pic.gtb [QORIQ_CLOCK_TIMECOUNTER - 4];
46  #endif
47
48#define CLOCK_INTERRUPT (QORIQ_IRQ_GT_BASE + QORIQ_CLOCK_TIMER)
49
50static struct timecounter qoriq_clock_tc;
51
52static void qoriq_clock_handler_install(rtems_isr_entry *old_isr)
53{
54  rtems_status_code sc = RTEMS_SUCCESSFUL;
55
56  *old_isr = NULL;
57
58  sc = qoriq_pic_set_affinity(
59    CLOCK_INTERRUPT,
60    ppc_processor_id()
61  );
62  if (sc != RTEMS_SUCCESSFUL) {
63    rtems_fatal_error_occurred(0xdeadbeef);
64  }
65
66  sc = qoriq_pic_set_priority(
67    CLOCK_INTERRUPT,
68    QORIQ_PIC_PRIORITY_LOWEST,
69    NULL
70  );
71  if (sc != RTEMS_SUCCESSFUL) {
72    rtems_fatal_error_occurred(0xdeadbeef);
73  }
74
75  sc = rtems_interrupt_handler_install(
76    CLOCK_INTERRUPT,
77    "Clock",
78    RTEMS_INTERRUPT_UNIQUE,
79    Clock_isr,
80    NULL
81  );
82  if (sc != RTEMS_SUCCESSFUL) {
83    rtems_fatal_error_occurred(0xdeadbeef);
84  }
85}
86
87static uint32_t qoriq_clock_get_timecount(struct timecounter *tc)
88{
89  uint32_t ccr = qoriq_timecounter->ccr;
90
91  return GTCCR_COUNT_GET(-ccr);
92}
93
94static void qoriq_clock_initialize(void)
95{
96  uint32_t timer_frequency = BSP_bus_frequency / 8;
97  uint32_t interval = (uint32_t) (((uint64_t) timer_frequency
98    * (uint64_t) rtems_configuration_get_microseconds_per_tick()) / 1000000);
99
100  qoriq_clock->bcr = GTBCR_COUNT(interval);
101
102  qoriq_timecounter->bcr = GTBCR_COUNT(0xffffffff);
103
104  qoriq_clock_tc.tc_get_timecount = qoriq_clock_get_timecount;
105  qoriq_clock_tc.tc_counter_mask = GTCCR_COUNT_GET(0xffffffff);
106  qoriq_clock_tc.tc_frequency = timer_frequency;
107  qoriq_clock_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
108  rtems_timecounter_install(&qoriq_clock_tc);
109}
110
111static void qoriq_clock_cleanup(void)
112{
113  rtems_status_code sc = RTEMS_SUCCESSFUL;
114
115  qoriq_clock->bcr = GTBCR_CI;
116
117  sc = rtems_interrupt_handler_remove(
118    CLOCK_INTERRUPT,
119    Clock_isr,
120    NULL
121  );
122  if (sc != RTEMS_SUCCESSFUL) {
123    rtems_fatal_error_occurred(0xdeadbeef);
124  }
125}
126
127#define Clock_driver_support_at_tick()
128#define Clock_driver_support_initialize_hardware() \
129  qoriq_clock_initialize()
130#define Clock_driver_support_install_isr(clock_isr, old_isr) \
131  qoriq_clock_handler_install(&old_isr)
132#define Clock_driver_support_shutdown_hardware() \
133  qoriq_clock_cleanup()
134
135/* Include shared source clock driver code */
136#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.