1 | /* |
---|
2 | * S3C2400 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 | * 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 | * $Id$ |
---|
14 | */ |
---|
15 | #include <rtems.h> |
---|
16 | #include <irq.h> |
---|
17 | #include <bsp.h> |
---|
18 | #include <s3c24xx.h> |
---|
19 | |
---|
20 | /* this is defined in ../../../shared/clockdrv_shell.h */ |
---|
21 | rtems_isr Clock_isr(rtems_vector_number vector); |
---|
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 = {BSP_INT_TIMER4, |
---|
28 | (rtems_irq_hdl)Clock_isr, |
---|
29 | NULL, |
---|
30 | clock_isr_on, |
---|
31 | clock_isr_off, |
---|
32 | clock_isr_is_on |
---|
33 | }; |
---|
34 | |
---|
35 | /* If you follow the code, this is never used, so any value |
---|
36 | * should work |
---|
37 | */ |
---|
38 | #define CLOCK_VECTOR 0 |
---|
39 | |
---|
40 | /** |
---|
41 | * Return the nanoseconds since last tick |
---|
42 | */ |
---|
43 | uint32_t clock_driver_get_nanoseconds_since_last_tick(void) |
---|
44 | { |
---|
45 | return 0; |
---|
46 | } |
---|
47 | |
---|
48 | #define Clock_driver_nanoseconds_since_last_tick \ |
---|
49 | clock_driver_get_nanoseconds_since_last_tick |
---|
50 | |
---|
51 | /** |
---|
52 | * When we get the clock interrupt |
---|
53 | * - clear the interrupt bit? |
---|
54 | * - restart the timer? |
---|
55 | */ |
---|
56 | #define Clock_driver_support_at_tick() \ |
---|
57 | do { \ |
---|
58 | ClearPending(BIT_TIMER4); \ |
---|
59 | } while(0) |
---|
60 | |
---|
61 | |
---|
62 | /** |
---|
63 | * Installs the clock ISR. You shouldn't need to change this. |
---|
64 | */ |
---|
65 | #define Clock_driver_support_install_isr( _new, _old ) \ |
---|
66 | do { \ |
---|
67 | _old = NULL; \ |
---|
68 | BSP_install_rtems_irq_handler(&clock_isr_data); \ |
---|
69 | } while(0) |
---|
70 | |
---|
71 | |
---|
72 | /** |
---|
73 | * Initialize the hardware for the clock |
---|
74 | * - Set the frequency |
---|
75 | * - enable it |
---|
76 | * - clear any pending interrupts |
---|
77 | * |
---|
78 | * Since you may want the clock always running, you can |
---|
79 | * enable interrupts here. If you do so, the clock_isr_on(), |
---|
80 | * clock_isr_off(), and clock_isr_is_on() functions can be |
---|
81 | * NOPs. |
---|
82 | */ |
---|
83 | #define Clock_driver_support_initialize_hardware() \ |
---|
84 | do { \ |
---|
85 | uint32_t cr; \ |
---|
86 | uint32_t freq; \ |
---|
87 | /* set MUX for Timer4 to 1/16 */ \ |
---|
88 | cr=rTCFG1 & 0xFFF0FFFF; \ |
---|
89 | rTCFG1=(cr | (3<<16)); \ |
---|
90 | freq = get_PCLK(); \ |
---|
91 | /* set TIMER4 counter, input freq=PLCK/16/16Mhz*/ \ |
---|
92 | freq = (freq /16)/16; \ |
---|
93 | rTCNTB4 = ((freq / 1000) * rtems_configuration_get_microseconds_per_tick()) / 1000; \ |
---|
94 | /*unmask TIMER4 irq*/ \ |
---|
95 | rINTMSK&=~BIT_TIMER4; \ |
---|
96 | /* start TIMER4 with autoreload */ \ |
---|
97 | cr=rTCON & 0xFF8FFFFF; \ |
---|
98 | rTCON=(cr|(0x6<<20)); \ |
---|
99 | rTCON=(cr|(0x5<<20)); \ |
---|
100 | } while (0) |
---|
101 | |
---|
102 | /** |
---|
103 | * Do whatever you need to shut the clock down and remove the |
---|
104 | * interrupt handler. Since this normally only gets called on |
---|
105 | * RTEMS shutdown, you may not need to do anything other than |
---|
106 | * remove the ISR. |
---|
107 | */ |
---|
108 | #define Clock_driver_support_shutdown_hardware() \ |
---|
109 | do { \ |
---|
110 | /* Disable timer */ \ |
---|
111 | BSP_remove_rtems_irq_handler(&clock_isr_data); \ |
---|
112 | } while (0) |
---|
113 | |
---|
114 | /** |
---|
115 | * Enables clock interrupt. |
---|
116 | * |
---|
117 | * If the interrupt is always on, this can be a NOP. |
---|
118 | */ |
---|
119 | static void clock_isr_on(const rtems_irq_connect_data *unused) |
---|
120 | { |
---|
121 | return; |
---|
122 | } |
---|
123 | |
---|
124 | /** |
---|
125 | * Disables clock interrupts |
---|
126 | * |
---|
127 | * If the interrupt is always on, this can be a NOP. |
---|
128 | */ |
---|
129 | static void clock_isr_off(const rtems_irq_connect_data *unused) |
---|
130 | { |
---|
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 | */ |
---|
140 | static int clock_isr_is_on(const rtems_irq_connect_data *irq) |
---|
141 | { |
---|
142 | return 1; |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | /* Make sure to include this, and only at the end of the file */ |
---|
147 | #include "../../../../libbsp/shared/clockdrv_shell.h" |
---|