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

4.115
Last change on this file since 52258f1 was 52258f1, checked in by Joel Sherrill <joel.sherrill@…>, on 05/21/15 at 12:51:01

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

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[c468f18b]1/**
2 * @file
3 *
[7a6f8d0]4 * @ingroup lpc_clock
[c468f18b]5 *
6 * @brief Clock driver configuration.
7 */
8
9/*
[75acd9e]10 * Copyright (c) 2009-2015 embedded brains GmbH.  All rights reserved.
[f6083f0]11 *
12 *  embedded brains GmbH
[75acd9e]13 *  Dornierstr. 4
[f6083f0]14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
[c468f18b]17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
[c499856]20 * http://www.rtems.org/license/LICENSE.
[c468f18b]21 */
22
[34c61517]23#include <rtems.h>
[75acd9e]24#include <rtems/timecounter.h>
[34c61517]25
[c468f18b]26#include <bsp/lpc-clock-config.h>
27#include <bsp/lpc-timer.h>
28
[34c61517]29#ifdef ARM_MULTILIB_ARCH_V4
30
[c468f18b]31/* This is defined in ../../../shared/clockdrv_shell.h */
[b2d9478]32void Clock_isr(rtems_irq_hdl_param arg);
[c468f18b]33
[f6083f0]34static volatile lpc_timer *const lpc_clock =
[c468f18b]35  (volatile lpc_timer *) LPC_CLOCK_TIMER_BASE;
36
[75acd9e]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
[c468f18b]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;
[75acd9e]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);
[c468f18b]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) \
[c193baad]129  do {                                                 \
130    lpc_clock_handler_install();                       \
131    old_isr = NULL;                                    \
132  } while (0)
133
[c468f18b]134#define Clock_driver_support_shutdown_hardware() lpc_clock_cleanup()
135
136/* Include shared source clock driver code */
137#include "../../../../shared/clockdrv_shell.h"
[34c61517]138
139#endif /* ARM_MULTILIB_ARCH_V4 */
Note: See TracBrowser for help on using the repository browser.