1 | /* |
---|
2 | * MC9328MXL clock specific using the System Timer |
---|
3 | */ |
---|
4 | |
---|
5 | /* |
---|
6 | * Copyright (c) 2004 by Cogent Computer Systems |
---|
7 | * Written by Jay Monkman <jtm@lopingdog.com> |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.rtems.org/license/LICENSE. |
---|
12 | */ |
---|
13 | |
---|
14 | #include <rtems.h> |
---|
15 | #include <bsp.h> |
---|
16 | #include <bsp/irq.h> |
---|
17 | #include <mc9328mxl.h> |
---|
18 | #include <rtems/bspIo.h> /* for printk */ |
---|
19 | |
---|
20 | /* this is defined in ../../../shared/clockdrv_shell.h */ |
---|
21 | void Clock_isr(rtems_irq_hdl_param arg); |
---|
22 | static void clock_isr_on(const rtems_irq_connect_data *unused); |
---|
23 | static void clock_isr_off(const rtems_irq_connect_data *unused); |
---|
24 | static int clock_isr_is_on(const rtems_irq_connect_data *irq); |
---|
25 | |
---|
26 | /* Replace the first value with the clock's interrupt name. */ |
---|
27 | rtems_irq_connect_data clock_isr_data = { |
---|
28 | .name = BSP_INT_TIMER1, |
---|
29 | .hdl = Clock_isr, |
---|
30 | .handle = (void *)BSP_INT_TIMER1, |
---|
31 | .on = clock_isr_on, |
---|
32 | .off = clock_isr_off, |
---|
33 | .isOn = clock_isr_is_on, |
---|
34 | }; |
---|
35 | |
---|
36 | /** |
---|
37 | * When we get the clock interrupt |
---|
38 | * - clear the interrupt bit? |
---|
39 | * - restart the timer? |
---|
40 | */ |
---|
41 | #define Clock_driver_support_at_tick() \ |
---|
42 | do { \ |
---|
43 | uint32_t reg; \ |
---|
44 | \ |
---|
45 | reg = MC9328MXL_TMR1_TSTAT; \ |
---|
46 | (void) reg; /* avoid set but not used warning */ \ |
---|
47 | MC9328MXL_TMR1_TSTAT = 0; \ |
---|
48 | } while(0) |
---|
49 | |
---|
50 | /** |
---|
51 | * Installs the clock ISR. You shouldn't need to change this. |
---|
52 | */ |
---|
53 | #define Clock_driver_support_install_isr( _new ) \ |
---|
54 | BSP_install_rtems_irq_handler(&clock_isr_data) |
---|
55 | |
---|
56 | /** |
---|
57 | * Initialize the hardware for the clock |
---|
58 | * - Set the frequency |
---|
59 | * - enable it |
---|
60 | * - clear any pending interrupts |
---|
61 | * |
---|
62 | * Since you may want the clock always running, you can |
---|
63 | * enable interrupts here. If you do so, the clock_isr_on(), |
---|
64 | * clock_isr_off(), and clock_isr_is_on() functions can be |
---|
65 | * NOPs. |
---|
66 | */ |
---|
67 | #define Clock_driver_support_initialize_hardware() \ |
---|
68 | do { \ |
---|
69 | int freq; \ |
---|
70 | int cnt; \ |
---|
71 | freq = get_perclk1_freq(); \ |
---|
72 | printk("perclk1 freq is %d\n", freq); \ |
---|
73 | cnt = ((long long)freq * rtems_configuration_get_microseconds_per_tick() + 500000) / 1000000;\ |
---|
74 | printk("cnt freq is %d\n", cnt); \ |
---|
75 | MC9328MXL_TMR1_TCMP = cnt; \ |
---|
76 | /* use PERCLK1 as input, enable timer */ \ |
---|
77 | MC9328MXL_TMR1_TCTL = (MC9328MXL_TMR_TCTL_CLKSRC_PCLK1 | \ |
---|
78 | MC9328MXL_TMR_TCTL_TEN | \ |
---|
79 | MC9328MXL_TMR_TCTL_IRQEN); \ |
---|
80 | /* set prescaler to 1 (register value + 1) */ \ |
---|
81 | MC9328MXL_TMR1_TPRER = 0; \ |
---|
82 | } while (0) |
---|
83 | |
---|
84 | /** |
---|
85 | * Do whatever you need to shut the clock down and remove the |
---|
86 | * interrupt handler. Since this normally only gets called on |
---|
87 | * RTEMS shutdown, you may not need to do anything other than |
---|
88 | * remove the ISR. |
---|
89 | */ |
---|
90 | #define Clock_driver_support_shutdown_hardware() \ |
---|
91 | do { \ |
---|
92 | /* Disable timer */ \ |
---|
93 | MC9328MXL_TMR1_TCTL = 0; \ |
---|
94 | BSP_remove_rtems_irq_handler(&clock_isr_data); \ |
---|
95 | } while (0) |
---|
96 | |
---|
97 | /** |
---|
98 | * Enables clock interrupt. |
---|
99 | * |
---|
100 | * If the interrupt is always on, this can be a NOP. |
---|
101 | */ |
---|
102 | static void clock_isr_on(const rtems_irq_connect_data *unused) |
---|
103 | { |
---|
104 | MC9328MXL_TMR1_TCTL |= MC9328MXL_TMR_TCTL_IRQEN; |
---|
105 | MC9328MXL_AITC_INTENNUM = MC9328MXL_INT_TIMER1; |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * Disables clock interrupts |
---|
110 | * |
---|
111 | * If the interrupt is always on, this can be a NOP. |
---|
112 | */ |
---|
113 | static void clock_isr_off(const rtems_irq_connect_data *unused) |
---|
114 | { |
---|
115 | MC9328MXL_TMR1_TCTL &= ~MC9328MXL_TMR_TCTL_IRQEN; |
---|
116 | MC9328MXL_AITC_INTDISNUM = MC9328MXL_INT_TIMER1; |
---|
117 | } |
---|
118 | |
---|
119 | /** |
---|
120 | * Tests to see if clock interrupt is enabled, and returns 1 if so. |
---|
121 | * If interrupt is not enabled, returns 0. |
---|
122 | * |
---|
123 | * If the interrupt is always on, this always returns 1. |
---|
124 | */ |
---|
125 | static int clock_isr_is_on(const rtems_irq_connect_data *irq) |
---|
126 | { |
---|
127 | return MC9328MXL_TMR1_TCTL & MC9328MXL_TMR_TCTL_IRQEN; |
---|
128 | } |
---|
129 | |
---|
130 | #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER |
---|
131 | |
---|
132 | /* Make sure to include this, and only at the end of the file */ |
---|
133 | |
---|
134 | #include "../../../../libbsp/shared/clockdrv_shell.h" |
---|