source: rtems/c/src/lib/libcpu/arm/lpc22xx/clock/clockdrv.c @ 61e293b6

4.104.114.84.95
Last change on this file since 61e293b6 was 61e293b6, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 25, 2007 at 11:57:13 AM

Use current OAR license file URL.

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