source: rtems/c/src/lib/libbsp/arm/shared/lpc/clock/lpc-clock-config.c @ 52258f1

4.11
Last change on this file since 52258f1 was 52258f1, checked in by Joel Sherrill <joel.sherrill@…>, on May 21, 2015 at 12:51:01 PM

arm/shared/lpc/clock/lpc-clock-config.c: Remove unused variable warning

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup lpc_clock
5 *
6 * @brief Clock driver configuration.
7 */
8
9/*
10 * Copyright (c) 2009-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.h>
24#include <rtems/timecounter.h>
25
26#include <bsp/lpc-clock-config.h>
27#include <bsp/lpc-timer.h>
28
29#ifdef ARM_MULTILIB_ARCH_V4
30
31/* This is defined in ../../../shared/clockdrv_shell.h */
32void Clock_isr(rtems_irq_hdl_param arg);
33
34static volatile lpc_timer *const lpc_clock =
35  (volatile lpc_timer *) LPC_CLOCK_TIMER_BASE;
36
37static volatile lpc_timer *const lpc_timecounter =
38  (volatile lpc_timer *) LPC_CLOCK_TIMECOUNTER_BASE;
39
40static struct timecounter lpc_clock_tc;
41
42static uint32_t lpc_clock_tc_get_timecount(struct timecounter *tc)
43{
44  return lpc_timecounter->tc;
45}
46
47static void lpc_clock_at_tick(void)
48{
49  lpc_clock->ir = LPC_TIMER_IR_MR0;
50}
51
52static void lpc_clock_handler_install(void)
53{
54  rtems_status_code sc = RTEMS_SUCCESSFUL;
55
56  sc = rtems_interrupt_handler_install(
57    LPC_CLOCK_INTERRUPT,
58    "Clock",
59    RTEMS_INTERRUPT_UNIQUE,
60    (rtems_interrupt_handler) Clock_isr,
61    NULL
62  );
63  if (sc != RTEMS_SUCCESSFUL) {
64    rtems_fatal_error_occurred(0xdeadbeef);
65  }
66}
67
68static void lpc_clock_initialize(void)
69{
70  uint64_t interval = ((uint64_t) LPC_CLOCK_REFERENCE
71    * (uint64_t) rtems_configuration_get_microseconds_per_tick()) / 1000000;
72
73  /* Enable module */
74  LPC_CLOCK_MODULE_ENABLE();
75
76  /* Reset timer */
77  lpc_clock->tcr = LPC_TIMER_TCR_RST;
78
79  /* Clear interrupt flags */
80  lpc_clock->ir = LPC_TIMER_IR_ALL;
81
82  /* Set timer mode */
83  lpc_clock->ccr = 0;
84
85  /* Timer is incremented every PERIPH_CLK tick */
86  lpc_clock->pr = 0;
87
88  /* Set match registers */
89  lpc_clock->mr0 = (uint32_t) interval;
90
91  /* Generate interrupt and reset counter on match with MR0 */
92  lpc_clock->mcr = LPC_TIMER_MCR_MR0_INTR | LPC_TIMER_MCR_MR0_RST;
93
94  /* No external match */
95  lpc_clock->emr = 0x0;
96
97  /* Enable timer */
98  lpc_clock->tcr = LPC_TIMER_TCR_EN;
99
100  /* Install timecounter */
101  lpc_clock_tc.tc_get_timecount = lpc_clock_tc_get_timecount;
102  lpc_clock_tc.tc_counter_mask = 0xffffffff;
103  lpc_clock_tc.tc_frequency = LPC_CLOCK_REFERENCE;
104  lpc_clock_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
105  rtems_timecounter_install(&lpc_clock_tc);
106}
107
108static void lpc_clock_cleanup(void)
109{
110  rtems_status_code sc = RTEMS_SUCCESSFUL;
111
112  /* Disable timer */
113  lpc_clock->tcr = 0x0;
114
115  /* Remove interrupt handler */
116  sc = rtems_interrupt_handler_remove(
117    LPC_CLOCK_INTERRUPT,
118    (rtems_interrupt_handler) Clock_isr,
119    NULL
120  );
121  if (sc != RTEMS_SUCCESSFUL) {
122    rtems_fatal_error_occurred(0xdeadbeef);
123  }
124}
125
126#define Clock_driver_support_at_tick() lpc_clock_at_tick()
127#define Clock_driver_support_initialize_hardware() lpc_clock_initialize()
128#define Clock_driver_support_install_isr(isr, old_isr) \
129  do {                                                 \
130    lpc_clock_handler_install();                       \
131    old_isr = NULL;                                    \
132  } while (0)
133
134#define Clock_driver_support_shutdown_hardware() lpc_clock_cleanup()
135
136/* Include shared source clock driver code */
137#include "../../../../shared/clockdrv_shell.h"
138
139#endif /* ARM_MULTILIB_ARCH_V4 */
Note: See TracBrowser for help on using the repository browser.