source: rtems/c/src/lib/libcpu/arm/lpc22xx/clock/clockdrv.c @ 359e537

4.104.11
Last change on this file since 359e537 was 359e537, checked in by Ralf Corsepius <ralf.corsepius@…>, on Nov 30, 2009 at 5:09:41 AM

Whitespace removal.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  LPC22XX/LPC21xx clock specific using the System Timer
3 * Copyright (c) 2006 by Ray <rayx.cn@gmail.com>
4 *  Set the Time0 to generate click for RTEMS
5 *
6 *  This is hardware specific part of the clock driver. At the end of this
7 *  file, the generic part of the driver is #included.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *
12 *  http://www.rtems.com/license/LICENSE.
13 *
14 *
15 *  $Id$
16*/
17#include <rtems.h>
18#include <bsp.h>
19#include <irq.h>
20#include <lpc22xx.h>
21#include <rtems/bspIo.h>  /* for printk */
22
23/* this is defined in ../../../shared/clockdrv_shell.h */
24rtems_isr Clock_isr(rtems_vector_number vector);
25static void clock_isr_on(const rtems_irq_connect_data *unused);
26static void clock_isr_off(const rtems_irq_connect_data *unused);
27static int clock_isr_is_on(const rtems_irq_connect_data *irq);
28
29/* Replace the first value with the clock's interrupt name. */
30rtems_irq_connect_data clock_isr_data = {LPC22xx_INTERRUPT_TIMER0,
31                                         (rtems_irq_hdl)Clock_isr,
32                                         clock_isr_on,
33                                         clock_isr_off,
34                                         clock_isr_is_on,
35                                         3,     /* unused for ARM cpus */
36                                         0 };   /* unused for ARM cpus */
37
38/* If you follow the code, this is never used, so any value
39 * should work
40 */
41#define CLOCK_VECTOR 0
42
43
44
45/* use the /shared/clockdrv_shell.h code template */
46
47/**
48 * When we get the clock interrupt
49 *    - clear the interrupt bit?
50 *    - restart the timer?
51 */
52#define Clock_driver_support_at_tick() \
53 do {                                                   \
54          if (!(T0IR & 0x01)) return;   \
55          T0IR = 0x01;                  \
56          VICVectAddr = 0x00;\
57 } while(0)
58
59/**
60 * Installs the clock ISR. You shouldn't need to change this.
61 */
62#define Clock_driver_support_install_isr( _new, _old ) \
63  do {                                                 \
64      (_old) = NULL;                                   \
65      BSP_install_rtems_irq_handler(&clock_isr_data);  \
66  } while(0)
67
68
69/**
70 * Initialize the hardware for the clock
71 *   - Set the frequency
72 *   - enable it
73 *   - clear any pending interrupts
74 *
75 * Since you may want the clock always running, you can
76 * enable interrupts here. If you do so, the clock_isr_on(),
77 * clock_isr_off(), and clock_isr_is_on() functions can be
78 * NOPs.
79 */
80
81  /* set timer to generate interrupt every rtems_configuration_get_microseconds_per_tick()
82   * MR0/(LPC22xx_Fpclk/(PR0+1)) = 10/1000 = 0.01s
83   */
84
85#define Clock_driver_support_initialize_hardware() \
86  do { \
87        T0TCR &= 0;      /* disable and clear timer 0, set to  */ \
88        T0PC  = 0;            /* TC is incrementet on every pclk.*/ \
89        T0MR0 = ((LPC22xx_Fpclk/1000* rtems_configuration_get_microseconds_per_tick()) / 1000); /* initialize the timer period and prescaler */  \
90        /*T0PR = (((LPC22xx_Fpclk / 1000) * rtems_configuration_get_microseconds_per_tick()) / 1000-1); \ */ \
91        T0MCR |= 0x03;            /* generate interrupt when T0MR0 match T0TC and Reset Timer Count*/ \
92        T0EMR = 0;  /*No external match*/ \
93        T0TCR = 1; /*enable timer0*/ \
94        T0IR|=0x01;/*enable interrupt, skyeye will check this*/\
95   } while (0)
96
97/**
98 * Do whatever you need to shut the clock down and remove the
99 * interrupt handler. Since this normally only gets called on
100 * RTEMS shutdown, you may not need to do anything other than
101 * remove the ISR.
102 */
103#define Clock_driver_support_shutdown_hardware()                        \
104  do {                                                                  \
105        /* Disable timer */ \
106       T0TCR&=~0x02; \
107        BSP_remove_rtems_irq_handler(&clock_isr_data);                  \
108     } while (0)
109
110uint32_t bsp_clock_nanoseconds_since_last_tick(void)
111{
112        uint32_t clicks;
113
114        clicks = T0TC;  /*T0TC is the 32bit time counter 0*/
115
116        return (uint32_t) (rtems_configuration_get_microseconds_per_tick() - clicks) * 1000;
117}
118
119#define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick
120
121
122
123/**
124 * Enables clock interrupt.
125 *
126 * If the interrupt is always on, this can be a NOP.
127 */
128static void clock_isr_on(const rtems_irq_connect_data *unused)
129{
130        T0IR&=0x01;
131        //return;
132}
133
134/**
135 * Disables clock interrupts
136 *
137 * If the interrupt is always on, this can be a NOP.
138 */
139static void clock_isr_off(const rtems_irq_connect_data *unused)
140{
141        T0IR=0x00;
142        //return;
143}
144
145/**
146 * Tests to see if clock interrupt is enabled, and returns 1 if so.
147 * If interrupt is not enabled, returns 0.
148 *
149 * If the interrupt is always on, this always returns 1.
150 */
151static int clock_isr_is_on(const rtems_irq_connect_data *irq)
152{
153    return T0IR & 0x01;  /*MR0 mask*/
154}
155
156
157/* Make sure to include this, and only at the end of the file */
158#include "../../../../libbsp/shared/clockdrv_shell.h"
159
Note: See TracBrowser for help on using the repository browser.