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 */ |
---|
25 | rtems_isr Clock_isr(rtems_vector_number vector); |
---|
26 | static void clock_isr_on(const rtems_irq_connect_data *unused); |
---|
27 | static void clock_isr_off(const rtems_irq_connect_data *unused); |
---|
28 | static int clock_isr_is_on(const rtems_irq_connect_data *irq); |
---|
29 | |
---|
30 | /* Replace the first value with the clock's interrupt name. */ |
---|
31 | rtems_irq_connect_data clock_isr_data = { |
---|
32 | .name = BSP_INT_TIMER1, |
---|
33 | .hdl = (rtems_irq_hdl)Clock_isr, |
---|
34 | .handle = (void *)BSP_INT_TIMER1, |
---|
35 | .on = clock_isr_on, |
---|
36 | .off = clock_isr_off, |
---|
37 | .isOn = clock_isr_is_on, |
---|
38 | }; |
---|
39 | |
---|
40 | /* If you follow the code, this is never used, so any value |
---|
41 | * should work |
---|
42 | */ |
---|
43 | #define CLOCK_VECTOR 0 |
---|
44 | |
---|
45 | |
---|
46 | /** |
---|
47 | * When we get the clock interrupt |
---|
48 | * - clear the interrupt bit? |
---|
49 | * - restart the timer? |
---|
50 | */ |
---|
51 | #define Clock_driver_support_at_tick() \ |
---|
52 | do { \ |
---|
53 | uint32_t reg; \ |
---|
54 | reg = MC9328MXL_TMR1_TSTAT; \ |
---|
55 | MC9328MXL_TMR1_TSTAT = 0; \ |
---|
56 | } while(0) |
---|
57 | |
---|
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 | #define Clock_driver_support_initialize_hardware() \ |
---|
81 | do { \ |
---|
82 | int freq; \ |
---|
83 | int cnt; \ |
---|
84 | freq = get_perclk1_freq(); \ |
---|
85 | printk("perclk1 freq is %d\n", freq); \ |
---|
86 | cnt = ((long long)freq * BSP_Configuration.microseconds_per_tick + 500000) / 1000000;\ |
---|
87 | printk("cnt freq is %d\n", cnt); \ |
---|
88 | MC9328MXL_TMR1_TCMP = cnt; \ |
---|
89 | /* use PERCLK1 as input, enable timer */ \ |
---|
90 | MC9328MXL_TMR1_TCTL = (MC9328MXL_TMR_TCTL_CLKSRC_PCLK1 | \ |
---|
91 | MC9328MXL_TMR_TCTL_TEN | \ |
---|
92 | MC9328MXL_TMR_TCTL_IRQEN); \ |
---|
93 | /* set prescaler to 1 (register value + 1) */ \ |
---|
94 | MC9328MXL_TMR1_TPRER = 0; \ |
---|
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 | MC9328MXL_TMR1_TCTL = 0; \ |
---|
107 | BSP_remove_rtems_irq_handler(&clock_isr_data); \ |
---|
108 | } while (0) |
---|
109 | |
---|
110 | /** |
---|
111 | * Enables clock interrupt. |
---|
112 | * |
---|
113 | * If the interrupt is always on, this can be a NOP. |
---|
114 | */ |
---|
115 | static void clock_isr_on(const rtems_irq_connect_data *unused) |
---|
116 | { |
---|
117 | MC9328MXL_TMR1_TCTL |= MC9328MXL_TMR_TCTL_IRQEN; |
---|
118 | MC9328MXL_AITC_INTENNUM = MC9328MXL_INT_TIMER1; |
---|
119 | |
---|
120 | return; |
---|
121 | } |
---|
122 | |
---|
123 | /** |
---|
124 | * Disables clock interrupts |
---|
125 | * |
---|
126 | * If the interrupt is always on, this can be a NOP. |
---|
127 | */ |
---|
128 | static void clock_isr_off(const rtems_irq_connect_data *unused) |
---|
129 | { |
---|
130 | MC9328MXL_TMR1_TCTL &= ~MC9328MXL_TMR_TCTL_IRQEN; |
---|
131 | MC9328MXL_AITC_INTDISNUM = MC9328MXL_INT_TIMER1; |
---|
132 | return; |
---|
133 | } |
---|
134 | |
---|
135 | /** |
---|
136 | * Tests to see if clock interrupt is enabled, and returns 1 if so. |
---|
137 | * If interrupt is not enabled, returns 0. |
---|
138 | * |
---|
139 | * If the interrupt is always on, this always returns 1. |
---|
140 | */ |
---|
141 | static int clock_isr_is_on(const rtems_irq_connect_data *irq) |
---|
142 | { |
---|
143 | return MC9328MXL_TMR1_TCTL & MC9328MXL_TMR_TCTL_IRQEN; |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | /* Make sure to include this, and only at the end of the file */ |
---|
148 | #include "../../../../libbsp/shared/clockdrv_shell.c" |
---|