1 //==========================================================================
5 // HAL misc board support code for ARM CMA230-1
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.
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.
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
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.
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.
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.
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####
44 // Contributors: gthomas
46 // Purpose: HAL board support
47 // Description: Implementations of HAL board interfaces
49 //####DESCRIPTIONEND####
51 //========================================================================*/
53 #include <pkgconf/hal.h>
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
59 #include <cyg/hal/hal_if.h> // calling interface API
60 #include <cyg/hal/hal_io.h> // IO macros
61 #include <cyg/hal/hal_arch.h> // Register state info
62 #include <cyg/hal/hal_diag.h>
63 #include <cyg/hal/hal_intr.h> // Interrupt names
64 #include <cyg/hal/hal_cache.h>
65 #include <cyg/hal/hal_cma230.h> // Hardware definitions
67 static cyg_uint32 _period;
69 // Use Timer/Counter #2 for system clock
71 void hal_clock_initialize(cyg_uint32 period)
74 *(volatile cyg_uint16 *)CMA230_TC_ENABLE = 0; // Disable timer
75 *(volatile cyg_uint16 *)CMA230_TC_CLEAR = 0; // Resets counter
76 *(volatile cyg_uint16 *)CMA230_TC_PRELOAD = period;
77 *(volatile cyg_uint16 *)CMA230_TC_ENABLE = 1; // Starts timer
81 // This routine is called during a clock interrupt.
83 void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period)
85 if (period != _period) {
86 *(volatile cyg_uint16 *)CMA230_TC_PRELOAD = period;
91 // Read the current value of the clock, returning the number of hardware "ticks"
92 // that have occurred (i.e. how far away the current value is from the start)
94 void hal_clock_read(cyg_uint32 *pvalue)
96 volatile cyg_int16 *tcct = (volatile cyg_int16 *)CMA230_TC_COUNT;
97 static cyg_int32 clock_val;
98 clock_val = *tcct; // Register has only 16 bits
99 *pvalue = (cyg_uint32)(_period - clock_val); // 'clock_val' counts down and wraps
103 // Early stage hardware initialization
104 // Some initialization has already been done before we get here. For now
105 // just set up the interrupt environment.
107 // Note: The hardware interrupt mask (read) doesn't seem to give reliable results.
108 static cyg_uint8 _imrr;
110 #define CMA230_IMRr (&_imrr)
112 void hal_hardware_init(void)
115 // Clear and initialize instruction cache
116 HAL_ICACHE_INVALIDATE_ALL();
119 // Any hardware/platform initialization that needs to be done.
120 // Reset all interrupt masks (disable all interrupt sources)
121 *(volatile cyg_uint8 *)CMA230_IMRw = 0;
122 *(volatile cyg_uint8 *)CMA230_CLR = 0xFF; // Clear all current interrupts
124 // Set up eCos/ROM interfaces
129 // This routine is called to respond to a hardware interrupt (IRQ). It
130 // should interrogate the hardware and return the IRQ vector number.
135 cyg_uint32 int_PC[2048];
139 int hal_IRQ_handler(HAL_SavedRegisters *regs)
141 volatile cyg_uint8 isr = *(volatile cyg_uint8 *)CMA230_ISR;
142 volatile cyg_uint8 *imrr = (volatile cyg_uint8 *)CMA230_IMRr;
144 isr &= *imrr; // The Interrupt Source Register shows _all_ current
145 // interrupt sources, not just the enabled ones
148 int_PC[tot_ints++] = 0xFFFFFFFF;
149 int_PC[tot_ints++] = isr;
150 int_PC[tot_ints++] = regs->cpsr;
151 int_PC[tot_ints++] = regs->pc;
152 if (tot_ints == 2048) tot_ints = 0;
156 for (vector = 0; vector < 8; vector++) {
157 if (isr & (1<<vector)) {
161 return CYGNUM_HAL_INTERRUPT_NONE; // This shouldn't happen!
168 // Disable (mask) an interrupt
169 void hal_interrupt_mask(int vector)
171 volatile cyg_uint8 *imrr = (volatile cyg_uint8 *)CMA230_IMRr;
172 volatile cyg_uint8 *imrw = (volatile cyg_uint8 *)CMA230_IMRw;
173 cyg_uint8 new_mask = *imrr & ~(1<<(vector-1));
178 // diag_printf("Mask interrupt #%d - mask: %x\n", vector, *imrr);
181 // Enable (unmask) an interrupt
182 void hal_interrupt_unmask(int vector)
184 volatile cyg_uint8 *imrr = (volatile cyg_uint8 *)CMA230_IMRr;
185 volatile cyg_uint8 *imrw = (volatile cyg_uint8 *)CMA230_IMRw;
186 cyg_uint8 new_mask = *imrr | (1<<(vector-1));
191 // diag_printf("Unmask interrupt #%d - mask: %x\n", vector, *imrr);
194 void hal_interrupt_acknowledge(int vector)
196 // These two vectors are "sticky" and must be reset
197 if ((vector == CYGNUM_HAL_INTERRUPT_TIMER) ||
198 (vector == CYGNUM_HAL_INTERRUPT_ABORT)) {
199 *(volatile cyg_uint8 *)CMA230_CLR = (1<<(vector-1));
203 void hal_interrupt_configure(int vector, int level, int up)
205 // No interrupts are configurable on this hardware
208 void hal_interrupt_set_level(int vector, int level)
210 // No interrupts are configurable on this hardware
213 /*------------------------------------------------------------------------*/