source: rtems/c/src/lib/libbsp/arm/lpc24xx/clock/clock-config.c @ 9a9f662

4.104.115
Last change on this file since 9a9f662 was 9a9f662, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 10/10/08 at 15:44:40

* empty log message *

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup lpc24xx
5 *
6 * @brief Clock driver configuration.
7 */
8
9/*
10 * Copyright (c) 2008
11 * Embedded Brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * rtems@embedded-brains.de
16 *
17 * The license and distribution terms for this file may be found in the file
18 * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
19 */
20
21#define RTEMS_STATUS_CHECKS_USE_PRINTK
22
23#include <rtems/status-checks.h>
24
25#include <bsp.h>
26#include <bsp/lpc24xx.h>
27#include <bsp/irq.h>
28#include <bsp/system-clocks.h>
29
30/* This is defined in ../../../shared/clockdrv_shell.h */
31rtems_isr Clock_isr( rtems_vector_number vector);
32
33#define Clock_driver_support_at_tick() \
34 do { \
35   T0IR = TIR_MR0; \
36 } while (0)
37
38static void lpc24xx_clock_handler_install( void)
39{
40  rtems_status_code sc = RTEMS_SUCCESSFUL;
41
42  sc = rtems_interrupt_handler_install(
43    LPC24XX_IRQ_TIMER_0,
44    "Clock",
45    RTEMS_INTERRUPT_UNIQUE,
46    (rtems_interrupt_handler) Clock_isr,
47    NULL
48  );
49  RTEMS_CHECK_SC_VOID( sc, "Install clock interrupt handler");
50}
51
52static void lpc24xx_clock_initialize( void)
53{
54  rtems_interrupt_level level;
55  uint64_t interval = ((uint64_t) lpc24xx_cclk()
56    * (uint64_t) rtems_configuration_get_microseconds_per_tick()) / 1000000;
57
58  /* Set timer pclk to cclk */
59  rtems_interrupt_disable( level);
60  SET_PCLKSEL0_PCLK_TIMER0( PCLKSEL0, 1);
61  rtems_interrupt_enable( level);
62
63  /* Reset timer */
64  T0TCR = TCR_RST;
65
66  /* Clear interrupt flags */
67  T0IR = 0xff;
68
69  /* Set timer mode */
70  T0CCR = 0;
71
72  /* Timer is incremented every pclk tick */
73  T0PR = 0;
74
75  /* Set match registers */
76  T0MR0 = (uint32_t) interval;
77  T0MR1 = 0xdeadbeef;
78  T0MR2 = 0xdeadbeef;
79  T0MR3 = 0xdeadbeef;
80
81  /* Generate interrupt and reset counter on match with MR0 */
82  T0MCR = TMCR_MR0I | TMCR_MR0R;
83
84  /* No external match */
85  T0EMR = 0;
86
87  /* Enable timer */
88  T0TCR = TCR_EN;
89}
90
91static void lpc24xx_clock_cleanup( void)
92{
93  rtems_status_code sc = RTEMS_SUCCESSFUL;
94
95  /* Disable timer */
96  T0TCR = 0;
97
98  /* Remove interrupt handler */
99  sc = rtems_interrupt_handler_remove(
100    LPC24XX_IRQ_TIMER_0,
101    (rtems_interrupt_handler) Clock_isr,
102    NULL
103  );
104  RTEMS_CHECK_SC_VOID( sc, "Remove clock interrupt handler");
105}
106
107static uint32_t lpc24xx_clock_nanoseconds_since_last_tick( void)
108{
109  uint64_t clock = lpc24xx_cclk();
110  uint32_t clicks = T0TC;
111  uint64_t ns = ((uint64_t) clicks * 1000000000) / clock;
112 
113  return (uint32_t) ns;
114}
115 
116#define Clock_driver_support_initialize_hardware() lpc24xx_clock_initialize()
117
118#define Clock_driver_support_install_isr( isr, old_isr) lpc24xx_clock_handler_install()
119
120#define Clock_driver_support_shutdown_hardware() lpc24xx_clock_cleanup()
121 
122#define Clock_driver_nanoseconds_since_last_tick lpc24xx_clock_nanoseconds_since_last_tick
123
124/* Include shared source clock driver code */
125#include "../../../../libbsp/shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.