]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/e7t/v2_0/src/e7t_misc.c
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / e7t / v2_0 / src / e7t_misc.c
1 //==========================================================================
2 //
3 //      e7t_misc.c
4 //
5 //      HAL misc board support code for ARM E7T
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 //
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
42 //
43 // Author(s):    gthomas
44 // Contributors: gthomas, jskov
45 // Date:         2001-03-16
46 // Purpose:      HAL board support
47 // Description:  Implementations of HAL board interfaces
48 //
49 //####DESCRIPTIONEND####
50 //
51 //========================================================================*/
52
53 #include <pkgconf/hal.h>
54
55 #include <cyg/infra/cyg_type.h>         // base types
56 #include <cyg/infra/cyg_trac.h>         // tracing macros
57 #include <cyg/infra/cyg_ass.h>          // assertion macros
58
59 #include <cyg/hal/hal_io.h>             // IO macros
60 #include <cyg/hal/hal_arch.h>           // Register state info
61 #include <cyg/hal/hal_diag.h>
62 #include <cyg/hal/hal_intr.h>           // necessary?
63 #include <cyg/hal/hal_cache.h>
64 #include <cyg/hal/hal_if.h>             // calling interface
65 #include <cyg/hal/hal_misc.h>           // helper functions
66 #ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
67 #include <cyg/hal/drv_api.h>            // HAL ISR support
68 #endif
69 #include <cyg/hal/plf_io.h>             // platform registers
70
71 static cyg_uint32 _period;
72
73 #ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
74 static cyg_interrupt abort_interrupt;
75 static cyg_handle_t  abort_interrupt_handle;
76
77 // This ISR is called only for the Abort button interrupt
78 static int
79 e7t_abort_isr(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs)
80 {
81     cyg_hal_user_break((CYG_ADDRWORD*)regs);
82     cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_EXT0);
83     return 0;  // No need to run DSR
84 }
85 #endif
86
87 void hal_clock_initialize(cyg_uint32 period)
88 {
89     cyg_uint32 tmod;
90
91     // Disable timer 0
92     HAL_READ_UINT32(E7T_TMOD, tmod);
93     tmod &= ~(E7T_TMOD_TE0);
94     HAL_WRITE_UINT32(E7T_TMOD, 0);
95
96     tmod &= ~(E7T_TMOD_TMD0 | E7T_TMOD_TCLR0);
97     tmod |= E7T_TMOD_TE0;
98
99     // Set counter
100     HAL_WRITE_UINT32(E7T_TDATA0, period);
101
102     // And enable timer
103     HAL_WRITE_UINT32(E7T_TMOD, tmod);
104
105     _period = period;
106
107 #ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
108     cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_EXT0,
109                              99,           // Priority
110                              0,            // Data item passed to interrupt handler
111                              e7t_abort_isr,
112                              0,
113                              &abort_interrupt_handle,
114                              &abort_interrupt);
115     cyg_drv_interrupt_attach(abort_interrupt_handle);
116     cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_EXT0);
117 #endif
118 }
119
120 void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period)
121 {
122     _period = period;
123 }
124
125 void hal_clock_read(cyg_uint32 *pvalue)
126 {
127     cyg_uint32 value;
128
129     HAL_READ_UINT32(E7T_TCNT0, value);
130     *pvalue = _period - value;
131 }
132
133 // -------------------------------------------------------------------------
134 //
135 // Delay for some number of micro-seconds
136 //
137 void hal_delay_us(cyg_int32 usecs)
138 {
139     cyg_uint32 count;
140     cyg_uint32 ticks = ((CYGNUM_HAL_RTC_PERIOD*CYGNUM_HAL_RTC_DENOMINATOR)/1000000) * usecs;
141     cyg_uint32 tmod;
142
143     // Disable timer 1
144     HAL_READ_UINT32(E7T_TMOD, tmod);
145     tmod &= ~(E7T_TMOD_TE1);
146     HAL_WRITE_UINT32(E7T_TMOD, tmod);
147
148     tmod &= ~(E7T_TMOD_TMD1 | E7T_TMOD_TCLR1);
149     tmod |= E7T_TMOD_TE1;
150
151     // Clear pending flag
152     HAL_WRITE_UINT32(E7T_INTPND, (1 << CYGNUM_HAL_INTERRUPT_TIMER1));
153
154     // Set counter
155     HAL_WRITE_UINT32(E7T_TDATA1, ticks);
156
157     // And enable timer
158     HAL_WRITE_UINT32(E7T_TMOD, tmod);
159
160     // Wait for timer to underflow. Can't test the timer completion
161     // bit without actually enabling the interrupt. So instead watch
162     // the counter.
163     ticks /= 2;                         // wait for this threshold
164
165     // Wait till timer counts below threshold
166     do {
167         HAL_READ_UINT32(E7T_TCNT1, count);
168     } while (count >= ticks);
169     // then wait for it to be reloaded
170     do {
171         HAL_READ_UINT32(E7T_TCNT1, count);
172     } while (count < ticks);
173
174     // Then disable timer 1 again
175     tmod &= ~E7T_TMOD_TE1;
176     HAL_WRITE_UINT32(E7T_TMOD, tmod);
177 }
178
179 // -------------------------------------------------------------------------
180 // Hardware init
181 void hal_hardware_init(void)
182 {
183     cyg_uint32 intmask;
184
185     // Set up eCos/ROM interfaces
186     hal_if_init();
187
188     // Enable cache
189     HAL_WRITE_UINT32(E7T_SYSCFG, 
190                      0x07FFFF80|E7T_SYSCFG_CM_0R_8C|E7T_SYSCFG_WE);
191     HAL_UCACHE_INVALIDATE_ALL();
192     HAL_UCACHE_ENABLE();
193
194     // Clear global interrupt mask bit
195     HAL_READ_UINT32(E7T_INTMSK, intmask);
196     intmask &= ~E7T_INTMSK_GLOBAL;
197     HAL_WRITE_UINT32(E7T_INTMSK, intmask);
198 }
199
200 //
201 // This routine is called to respond to a hardware interrupt (IRQ).  It
202 // should interrogate the hardware and return the IRQ vector number.
203
204 int hal_IRQ_handler(void)
205 {
206     // Do hardware-level IRQ handling
207     cyg_uint32 irq_status;
208     HAL_READ_UINT32(E7T_INTOFFSET_IRQ, irq_status);
209     irq_status = irq_status / 4;
210     if (CYGNUM_HAL_ISR_MAX >= irq_status)
211         return irq_status;
212     // It's a bit bogus to test for FIQs after IRQs, but we use the
213     // latter more, so don't impose the overhead of checking for FIQs
214     HAL_READ_UINT32(E7T_INTOFFSET_FIQ, irq_status);
215     irq_status = irq_status / 4;
216     if (CYGNUM_HAL_ISR_MAX >= irq_status)
217         return irq_status;
218     return CYGNUM_HAL_INTERRUPT_NONE;
219 }
220
221 //
222 // Interrupt control
223 //
224
225 void hal_interrupt_mask(int vector)
226 {
227     cyg_uint32 mask, old_mask;
228     HAL_READ_UINT32(E7T_INTMSK, mask);
229     old_mask = mask;
230     mask |= (1<<vector);
231     HAL_WRITE_UINT32(E7T_INTMSK, mask);
232 }
233
234 void hal_interrupt_unmask(int vector)
235 {
236     cyg_uint32 mask, old_mask;
237     HAL_READ_UINT32(E7T_INTMSK, mask);
238     old_mask = mask;
239     mask &= ~(1<<vector);
240     HAL_WRITE_UINT32(E7T_INTMSK, mask);
241 }
242
243 void hal_interrupt_acknowledge(int vector)
244 {
245     HAL_WRITE_UINT32(E7T_INTPND, (1<<vector));
246 }
247
248 void hal_interrupt_configure(int vector, int level, int up)
249 {
250 }
251
252 void hal_interrupt_set_level(int vector, int level)
253 {
254 }
255
256 void hal_show_IRQ(int vector, int data, int handler)
257 {
258 }
259
260 //--------------------------------------------------------------------------
261 // EOF hal_misc.c