source: rtems/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c @ aaca942

4.104.114.84.95
Last change on this file since aaca942 was aaca942, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/05 at 23:30:45

2005-01-04 Joel Sherrill <joel@…>

  • at91rm9200/clock/clock.c, at91rm9200/irq/irq.c, at91rm9200/pmc/pmc.c, mc9328mxl/clock/clockdrv.c, mc9328mxl/irq/irq.c, mc9328mxl/irq/irq.h, shared/arm920/mmu.c: Remove warnings.
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  MC9328MXL clock specific using the System Timer
3 *
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 *  Copyright (c) 2004 by Cogent Computer Systems
8 *  Written by Jay Monkman <jtm@lopingdog.com>
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *
13 *  http://www.OARcorp.com/rtems/license.html.
14 *
15 *
16 *  clockdrv.c,v 1.1 2002/11/13 17:55:04 joel Exp
17*/
18#include <rtems.h>
19#include <bsp.h>
20#include <irq.h>
21#include <mc9328mxl.h>
22#include <rtems/bspIo.h>  /* for printk */
23
24/* this is defined in ../../../shared/clockdrv_shell.c */
25rtems_isr Clock_isr(rtems_vector_number vector);
26static void clock_isr_on(const rtems_irq_connect_data *unused);
27static void clock_isr_off(const rtems_irq_connect_data *unused);
28static int clock_isr_is_on(const rtems_irq_connect_data *irq);
29
30/* Replace the first value with the clock's interrupt name. */
31rtems_irq_connect_data clock_isr_data = {BSP_INT_TIMER1,
32                                         (rtems_irq_hdl)Clock_isr,
33                                         clock_isr_on,
34                                         clock_isr_off,
35                                         clock_isr_is_on,
36                                         3,     /* unused for ARM cpus */
37                                         0 };   /* unused for ARM cpus */
38
39/* If you follow the code, this is never used, so any value
40 * should work
41 */
42#define CLOCK_VECTOR 0
43
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        uint32_t reg;                                 \
53        reg = MC9328MXL_TMR1_TSTAT;                   \
54        MC9328MXL_TMR1_TSTAT = 0;                     \
55  } while(0)
56
57
58/**
59 * Installs the clock ISR. You shouldn't need to change this.
60 */
61#define Clock_driver_support_install_isr( _new, _old ) \
62  do {                                                 \
63      (_old) = NULL;                                   \
64      BSP_install_rtems_irq_handler(&clock_isr_data);  \
65  } while(0)
66
67
68/**
69 * Initialize the hardware for the clock
70 *   - Set the frequency
71 *   - enable it
72 *   - clear any pending interrupts
73 *
74 * Since you may want the clock always running, you can
75 * enable interrupts here. If you do so, the clock_isr_on(),
76 * clock_isr_off(), and clock_isr_is_on() functions can be
77 * NOPs.
78 */
79#define Clock_driver_support_initialize_hardware() \
80  do { \
81        int freq; \
82        int cnt; \
83        freq = get_perclk1_freq(); \
84        printk("perclk1 freq is %d\n", freq); \
85        cnt = ((freq / 1000) * BSP_Configuration.microseconds_per_tick) / 1000;\
86        printk("cnt freq is %d\n", cnt); \
87        MC9328MXL_TMR1_TCMP = cnt; \
88        /* use PERCLK1 as input, enable timer */ \
89        MC9328MXL_TMR1_TCTL = (MC9328MXL_TMR_TCTL_CLKSRC_PCLK1 | \
90                               MC9328MXL_TMR_TCTL_TEN | \
91                               MC9328MXL_TMR_TCTL_IRQEN); \
92        /* set prescaler to 1 (register value + 1) */ \
93        MC9328MXL_TMR1_TPRER = 0; \
94     } while (0)
95
96/**
97 * Do whatever you need to shut the clock down and remove the
98 * interrupt handler. Since this normally only gets called on
99 * RTEMS shutdown, you may not need to do anything other than
100 * remove the ISR.
101 */
102#define Clock_driver_support_shutdown_hardware()                        \
103  do {                                                                  \
104        /* Disable timer */ \
105        MC9328MXL_TMR1_TCTL = 0; \
106        BSP_remove_rtems_irq_handler(&clock_isr_data);                  \
107     } while (0)
108
109/**
110 * Enables clock interrupt.
111 *
112 * If the interrupt is always on, this can be a NOP.
113 */
114static void clock_isr_on(const rtems_irq_connect_data *unused)
115{
116    MC9328MXL_TMR1_TCTL |= MC9328MXL_TMR_TCTL_IRQEN;
117    MC9328MXL_AITC_INTENNUM = MC9328MXL_INT_TIMER1;
118
119    return;
120}
121
122/**
123 * Disables clock interrupts
124 *
125 * If the interrupt is always on, this can be a NOP.
126 */
127static void clock_isr_off(const rtems_irq_connect_data *unused)
128{
129    MC9328MXL_TMR1_TCTL &= ~MC9328MXL_TMR_TCTL_IRQEN;
130    MC9328MXL_AITC_INTDISNUM = MC9328MXL_INT_TIMER1;
131    return;
132}
133
134/**
135 * Tests to see if clock interrupt is enabled, and returns 1 if so.
136 * If interrupt is not enabled, returns 0.
137 *
138 * If the interrupt is always on, this always returns 1.
139 */
140static int clock_isr_is_on(const rtems_irq_connect_data *irq)
141{
142    return MC9328MXL_TMR1_TCTL & MC9328MXL_TMR_TCTL_IRQEN;
143}
144
145
146/* Make sure to include this, and only at the end of the file */
147#include "../../../../libbsp/shared/clockdrv_shell.c"
Note: See TracBrowser for help on using the repository browser.