|
2
|
1 //========================================================================== |
|
|
2 // |
|
|
3 // pid_misc.c |
|
|
4 // |
|
|
5 // HAL misc board support code for ARM PID7 |
|
|
6 // |
|
|
7 //========================================================================== |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): gthomas |
|
|
33 // Contributors: gthomas |
|
|
34 // Date: 1999-02-20 |
|
|
35 // Purpose: HAL board support |
|
|
36 // Description: Implementations of HAL board interfaces |
|
|
37 // |
|
|
38 //####DESCRIPTIONEND#### |
|
|
39 // |
|
|
40 //===========================================================================*/ |
|
|
41 |
|
|
42 #include <pkgconf/hal.h> |
|
|
43 |
|
|
44 #include <cyg/infra/cyg_type.h> // base types |
|
|
45 #include <cyg/infra/cyg_trac.h> // tracing macros |
|
|
46 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
47 |
|
|
48 #include <cyg/hal/hal_io.h> // IO macros |
|
|
49 #include <cyg/hal/hal_arch.h> // Register state info |
|
|
50 #include <cyg/hal/hal_diag.h> |
|
|
51 #include <cyg/hal/hal_intr.h> // necessary? |
|
|
52 |
|
|
53 /*------------------------------------------------------------------------*/ |
|
|
54 // On-board timer |
|
|
55 /*------------------------------------------------------------------------*/ |
|
|
56 |
|
|
57 // Timer registers |
|
|
58 #define CYG_DEVICE_TIMER_BASE 0x0A800020 |
|
|
59 #define CYG_DEVICE_TIMER_LOAD \ |
|
|
60 ((volatile cyg_uint32 *) (CYG_DEVICE_TIMER_BASE + 0x00)) |
|
|
61 // Load value, read/write |
|
|
62 #define CYG_DEVICE_TIMER_CURRENT \ |
|
|
63 ((volatile cyg_uint32 *) (CYG_DEVICE_TIMER_BASE + 0x04)) |
|
|
64 // Current value, read |
|
|
65 #define CYG_DEVICE_TIMER_CONTROL \ |
|
|
66 ((volatile cyg_uint32 *) (CYG_DEVICE_TIMER_BASE + 0x08)) |
|
|
67 // Control register, read/write |
|
|
68 #define CYG_DEVICE_TIMER_CLEAR \ |
|
|
69 ((volatile cyg_uint32 *) (CYG_DEVICE_TIMER_BASE + 0x0C)) |
|
|
70 // Clears interrrupt, write only |
|
|
71 |
|
|
72 // Clock/timer control register |
|
|
73 #define CTL_ENABLE 0x80 // Bit 7: 1 - counter enabled |
|
|
74 #define CTL_DISABLE 0x00 // 0 - counter disabled |
|
|
75 #define CTL_FREERUN 0x00 // Bit 6: 0 - free running counter |
|
|
76 #define CTL_PERIODIC 0x40 // 1 - periodic timer mode |
|
|
77 #define CTL_SCALE_1 0x00 // Bits 32: 00 - Scale clock by 1 |
|
|
78 #define CTL_SCALE_16 0x04 // 01 - Scale by 16 |
|
|
79 #define CTL_SCALE_256 0x08 // 10 - Scale by 256 |
|
|
80 // 12.8us/tick |
|
|
81 |
|
|
82 // Interrupt controller registers |
|
|
83 #define CYG_DEVICE_ICTL_BASE 0x0A000000 |
|
|
84 #define CYG_DEVICE_IRQ_Status \ |
|
|
85 ((volatile cyg_uint32 *) (CYG_DEVICE_ICTL_BASE + 0x00)) |
|
|
86 // Current status, read only |
|
|
87 #define CYG_DEVICE_IRQ_Enable \ |
|
|
88 ((volatile cyg_uint32 *) (CYG_DEVICE_ICTL_BASE + 0x08)) |
|
|
89 // Enable status, read only |
|
|
90 #define CYG_DEVICE_IRQ_EnableSet \ |
|
|
91 ((volatile cyg_uint32 *) (CYG_DEVICE_ICTL_BASE + 0x08)) |
|
|
92 // Enable (1's only), write only |
|
|
93 #define CYG_DEVICE_IRQ_EnableClear \ |
|
|
94 ((volatile cyg_uint32 *) (CYG_DEVICE_ICTL_BASE + 0x0C)) |
|
|
95 // Disable (1's only), write only |
|
|
96 |
|
|
97 static cyg_uint32 _period; |
|
|
98 |
|
|
99 void hal_clock_initialize(cyg_uint32 period) |
|
|
100 { |
|
|
101 //diag_init(); diag_printf("%s(%d)\n", __PRETTY_FUNCTION__, period); |
|
|
102 //diag_printf("psr = %x\n", psr()); |
|
|
103 HAL_WRITE_UINT32(CYG_DEVICE_TIMER_CONTROL, CTL_DISABLE); // Turn off |
|
|
104 HAL_WRITE_UINT32(CYG_DEVICE_TIMER_LOAD, period); |
|
|
105 HAL_WRITE_UINT32(CYG_DEVICE_TIMER_CONTROL, |
|
|
106 CTL_ENABLE | CTL_PERIODIC | CTL_SCALE_16); |
|
|
107 _period = period; |
|
|
108 } |
|
|
109 |
|
|
110 void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period) |
|
|
111 { |
|
|
112 //diag_init(); diag_printf("%s\n", __PRETTY_FUNCTION__); |
|
|
113 HAL_WRITE_UINT32(CYG_DEVICE_TIMER_CLEAR, 0); |
|
|
114 _period = period; |
|
|
115 } |
|
|
116 |
|
|
117 void hal_clock_read(cyg_uint32 *pvalue) |
|
|
118 { |
|
|
119 cyg_uint32 value; |
|
|
120 // diag_init(); diag_printf("%s\n", __PRETTY_FUNCTION__); |
|
|
121 HAL_READ_UINT32(CYG_DEVICE_TIMER_CURRENT, value); |
|
|
122 value &= 0xFFFF; |
|
|
123 *pvalue = _period - (value & 0xFFFF); // Note: counter is only 16 bits |
|
|
124 // and decreases |
|
|
125 } |
|
|
126 |
|
|
127 void hal_hardware_init(void) |
|
|
128 { |
|
|
129 // Any hardware/platform initialization that needs to be done. |
|
|
130 HAL_WRITE_UINT32(CYG_DEVICE_IRQ_EnableClear, 0xFFFF); // Clear all |
|
|
131 // interrupt sources |
|
|
132 } |
|
|
133 |
|
|
134 // |
|
|
135 // This routine is called to respond to a hardware interrupt (IRQ). It |
|
|
136 // should interrogate the hardware and return the IRQ vector number. |
|
|
137 |
|
|
138 int hal_IRQ_handler(void) |
|
|
139 { |
|
|
140 // Do hardware-level IRQ handling |
|
|
141 int irq_status, vector; |
|
|
142 HAL_READ_UINT32(CYG_DEVICE_IRQ_Status, irq_status); |
|
|
143 //diag_init(); diag_printf("%s, status: %x\n", __PRETTY_FUNCTION__, irq_status); |
|
|
144 for (vector = 1; vector < 16; vector++) { |
|
|
145 if (irq_status & (1<<vector)) return vector; |
|
|
146 } |
|
|
147 return CYGNUM_HAL_INTERRUPT_unused; // This shouldn't happen! |
|
|
148 } |
|
|
149 |
|
|
150 // |
|
|
151 // Interrupt control |
|
|
152 // |
|
|
153 |
|
|
154 void hal_interrupt_mask(int vector) |
|
|
155 { |
|
|
156 //diag_init(); diag_printf("%s(%d)\n", __PRETTY_FUNCTION__, vector); |
|
|
157 HAL_WRITE_UINT32(CYG_DEVICE_IRQ_EnableClear, 1<<vector); |
|
|
158 } |
|
|
159 |
|
|
160 #if 0 |
|
|
161 void hal_interrupt_status(void) |
|
|
162 { |
|
|
163 int irq_status, irq_enable, timer_status, timer_value, timer_load; |
|
|
164 HAL_READ_UINT32(CYG_DEVICE_IRQ_Status, irq_status); |
|
|
165 HAL_READ_UINT32(CYG_DEVICE_IRQ_Enable, irq_enable); |
|
|
166 HAL_READ_UINT32(CYG_DEVICE_TIMER_LOAD, timer_load); |
|
|
167 HAL_READ_UINT32(CYG_DEVICE_TIMER_CURRENT, timer_value); |
|
|
168 HAL_READ_UINT32(CYG_DEVICE_TIMER_CONTROL, timer_status); |
|
|
169 diag_printf("Interrupt: IRQ: %x.%x, TIMER: %x.%x.%x, psr: %x\n", |
|
|
170 irq_status, irq_enable, timer_status, timer_value, |
|
|
171 timer_load, psr()); |
|
|
172 } |
|
|
173 #endif |
|
|
174 |
|
|
175 void hal_interrupt_unmask(int vector) |
|
|
176 { |
|
|
177 //diag_init(); diag_printf("%s(%d)\n", __PRETTY_FUNCTION__, vector); |
|
|
178 HAL_WRITE_UINT32(CYG_DEVICE_IRQ_EnableSet, 1<<vector); |
|
|
179 } |
|
|
180 |
|
|
181 void hal_interrupt_acknowledge(int vector) |
|
|
182 { |
|
|
183 //diag_init(); diag_printf("%s(%d)\n", __PRETTY_FUNCTION__, vector); |
|
|
184 } |
|
|
185 |
|
|
186 void hal_interrupt_configure(int vector, int level, int up) |
|
|
187 { |
|
|
188 //diag_init(); diag_printf("%s(%d,%d,%d)\n", __PRETTY_FUNCTION__, vector, level, up); |
|
|
189 } |
|
|
190 |
|
|
191 void hal_interrupt_set_level(int vector, int level) |
|
|
192 { |
|
|
193 //diag_init(); diag_printf("%s(%d,%d)\n", __PRETTY_FUNCTION__, vector, level); |
|
|
194 } |
|
|
195 |
|
|
196 void hal_show_IRQ(int vector, int data, int handler) |
|
|
197 { |
|
|
198 // diag_printf("IRQ - vector: %x, data: %x, handler: %x\n", vector, data, handler); |
|
|
199 } |
|
|
200 |
|
|
201 /*---------------------------------------------------------------------------*/ |
|
|
202 /* End of hal_misc.c */ |