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

4.104.114.84.95
Last change on this file since 1cfcfd3 was 1cfcfd3, checked in by Jay Monkman <jtm@…>, on Jul 15, 2004 at 6:25:44 AM

2004-07-15 Jay Monkman

  • ChangeLog?, Makefile.am, clock/.cvsignore, clock/clockdrv.c, include/mc9328mxl.h, irq/.cvsignore, irq/bsp_irq_asm.S, irq/bsp_irq_init.c, irq/irq.c, irq/irq.h, timer/.cvsignore, timer/timer.c: New files.
  • Property mode set to 100644
File size: 4.6 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
23/* this is defined in ../../../shared/clockdrv_shell.c */
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 = {BSP_INT_TIMER1,
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 * When we get the clock interrupt
46 *    - clear the interrupt bit?
47 *    - restart the timer?
48 */
49#define Clock_driver_support_at_tick()                \
50  do {                                                \
51        uint32_t reg;                                 \
52        reg = MC9328MXL_TMR1_TSTAT;                   \
53        MC9328MXL_TMR1_TSTAT = 0;                     \
54  } while(0)
55
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      BSP_install_rtems_irq_handler(&clock_isr_data);                       \
63     } while(0)
64
65
66/**
67 * Initialize the hardware for the clock
68 *   - Set the frequency
69 *   - enable it
70 *   - clear any pending interrupts
71 *
72 * Since you may want the clock always running, you can
73 * enable interrupts here. If you do so, the clock_isr_on(),
74 * clock_isr_off(), and clock_isr_is_on() functions can be
75 * NOPs.
76 */
77#define Clock_driver_support_initialize_hardware() \
78  do { \
79        int freq; \
80        int cnt; \
81        freq = get_perclk1_freq(); \
82        printk("perclk1 freq is %d\n", freq); \
83        cnt = ((freq / 1000) * BSP_Configuration.microseconds_per_tick) / 1000;\
84        printk("cnt freq is %d\n", cnt); \
85        MC9328MXL_TMR1_TCMP = cnt; \
86        /* use PERCLK1 as input, enable timer */ \
87        MC9328MXL_TMR1_TCTL = (MC9328MXL_TMR_TCTL_CLKSRC_PCLK1 | \
88                               MC9328MXL_TMR_TCTL_TEN | \
89                               MC9328MXL_TMR_TCTL_IRQEN); \
90        /* set prescaler to 1 (register value + 1) */ \
91        MC9328MXL_TMR1_TPRER = 0; \
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        MC9328MXL_TMR1_TCTL = 0; \
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    MC9328MXL_TMR1_TCTL |= MC9328MXL_TMR_TCTL_IRQEN;
115    MC9328MXL_AITC_INTENNUM = MC9328MXL_INT_TIMER1;
116
117    return;
118}
119
120/**
121 * Disables clock interrupts
122 *
123 * If the interrupt is always on, this can be a NOP.
124 */
125static void clock_isr_off(const rtems_irq_connect_data *unused)
126{
127    MC9328MXL_TMR1_TCTL &= ~MC9328MXL_TMR_TCTL_IRQEN;
128    MC9328MXL_AITC_INTDISNUM = MC9328MXL_INT_TIMER1;
129    return;
130}
131
132/**
133 * Tests to see if clock interrupt is enabled, and returns 1 if so.
134 * If interrupt is not enabled, returns 0.
135 *
136 * If the interrupt is always on, this always returns 1.
137 */
138static int clock_isr_is_on(const rtems_irq_connect_data *irq)
139{
140    return MC9328MXL_TMR1_TCTL & MC9328MXL_TMR_TCTL_IRQEN;
141}
142
143
144/* Make sure to include this, and only at the end of the file */
145#include "../../../../libbsp/shared/clockdrv_shell.c"
Note: See TracBrowser for help on using the repository browser.