1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// gps4020_misc.c
|
4 |
|
|
//
|
5 |
|
|
// HAL misc board support code for ARM GPS4020-1
|
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, 2003 Free Software Foundation, 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
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): gthomas
|
43 |
|
|
// Contributors: gthomas
|
44 |
|
|
// Date: 1999-02-20
|
45 |
|
|
// Purpose: HAL board support
|
46 |
|
|
// Description: Implementations of HAL board interfaces
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
//
|
50 |
|
|
//========================================================================*/
|
51 |
|
|
|
52 |
|
|
#include <pkgconf/hal.h>
|
53 |
|
|
|
54 |
|
|
#include <cyg/infra/cyg_type.h> // base types
|
55 |
|
|
#include <cyg/infra/cyg_trac.h> // tracing macros
|
56 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
57 |
|
|
|
58 |
|
|
#include <cyg/hal/hal_io.h> // IO macros
|
59 |
|
|
#include <cyg/hal/hal_arch.h> // Register state info
|
60 |
|
|
#include <cyg/hal/hal_diag.h>
|
61 |
|
|
#include <cyg/hal/hal_intr.h> // necessary?
|
62 |
|
|
#include <cyg/hal/hal_cache.h>
|
63 |
|
|
#include <cyg/hal/hal_if.h> // calling interface
|
64 |
|
|
#include <cyg/hal/hal_misc.h> // helper functions
|
65 |
|
|
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
|
66 |
|
|
#include <cyg/hal/drv_api.h> // HAL ISR support
|
67 |
|
|
#endif
|
68 |
|
|
|
69 |
|
|
#include <cyg/hal/gps4020.h>
|
70 |
|
|
|
71 |
|
|
static cyg_uint32 _period;
|
72 |
|
|
|
73 |
|
|
void hal_clock_initialize(cyg_uint32 period)
|
74 |
|
|
{
|
75 |
|
|
volatile struct _gps4020_timer *tc = (volatile struct _gps4020_timer *)GPS4020_TC1;
|
76 |
|
|
|
77 |
|
|
// Start timer in "reload" mode to set counter value
|
78 |
|
|
tc->tc[0].control = TC_CTL_SCR_HALT; // Disable timer
|
79 |
|
|
tc->tc[0].reload = period;
|
80 |
|
|
tc->tc[0].control = TC_CTL_IE | TC_CTL_SCR_COUNT | TC_CTL_MODE_RELOAD | TC_CTL_HEP | TC_CLOCK_BASE;
|
81 |
|
|
_period = period;
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period)
|
85 |
|
|
{
|
86 |
|
|
hal_clock_initialize(period);
|
87 |
|
|
_gps4020_watchdog(false);
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
void hal_clock_read(cyg_uint32 *pvalue)
|
91 |
|
|
{
|
92 |
|
|
volatile struct _gps4020_timer *tc = (volatile struct _gps4020_timer *)GPS4020_TC1;
|
93 |
|
|
*pvalue = _period - tc->tc[0].current;
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
//
|
97 |
|
|
// Delay for some number of micro-seconds
|
98 |
|
|
// Use timer #2 of TC2
|
99 |
|
|
//
|
100 |
|
|
void hal_delay_us(cyg_int32 usecs)
|
101 |
|
|
{
|
102 |
|
|
volatile struct _gps4020_timer *tc = (volatile struct _gps4020_timer *)GPS4020_TC2;
|
103 |
|
|
unsigned long val1, val2;
|
104 |
|
|
int timeout;
|
105 |
|
|
|
106 |
|
|
// Start timer in "reload" mode to set counter value
|
107 |
|
|
tc->tc[1].control = TC_CTL_SCR_HALT; // Disable timer
|
108 |
|
|
tc->tc[1].reload = usecs;
|
109 |
|
|
tc->tc[1].control = TC_CTL_SCR_COUNT | TC_CTL_MODE_RELOAD | TC_CTL_HEP | TC_CLOCK_BASE;
|
110 |
|
|
timeout = 10;
|
111 |
|
|
val1 = tc->tc[1].current;
|
112 |
|
|
while ((tc->tc[1].control & TC_CTL_OS) == 0) {
|
113 |
|
|
if (--timeout == 0) {
|
114 |
|
|
val2 = tc->tc[1].current;
|
115 |
|
|
if (val1 == val2) {
|
116 |
|
|
// Timer is stuck - use a cruder method!
|
117 |
|
|
while (--usecs > 0) ;
|
118 |
|
|
return;
|
119 |
|
|
}
|
120 |
|
|
}
|
121 |
|
|
}
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
void hal_hardware_init(void)
|
125 |
|
|
{
|
126 |
|
|
volatile struct _gps4020_intc *intc = (volatile struct _gps4020_intc *)GPS4020_INTC;
|
127 |
|
|
|
128 |
|
|
// Clear and reset all interrupt sources
|
129 |
|
|
intc->enable = 0;
|
130 |
|
|
// 3322 2222 2222 1111 1111 1100 0000 0000
|
131 |
|
|
// 1098 7654 3210 9876 5432 1098 7654 3210
|
132 |
|
|
intc->polarity = 0x1C01E01F; // 0001 1100 0000 0001 1110 0000 0001 1111;
|
133 |
|
|
intc->trigger = 0x000C00C0; // 0000 0000 0000 1100 0000 0000 1100 0000;
|
134 |
|
|
// Set up eCos/ROM interfaces
|
135 |
|
|
hal_if_init();
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
//
|
139 |
|
|
// This routine is called to respond to a hardware interrupt (IRQ). It
|
140 |
|
|
// should interrogate the hardware and return the IRQ vector number.
|
141 |
|
|
|
142 |
|
|
int hal_IRQ_handler(void)
|
143 |
|
|
{
|
144 |
|
|
volatile struct _gps4020_intc *intc = (volatile struct _gps4020_intc *)GPS4020_INTC;
|
145 |
|
|
int vec = (intc->IRQ_encoded >> 2);
|
146 |
|
|
return vec;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
//
|
150 |
|
|
// Interrupt control
|
151 |
|
|
//
|
152 |
|
|
|
153 |
|
|
void hal_interrupt_mask(int vector)
|
154 |
|
|
{
|
155 |
|
|
volatile struct _gps4020_intc *intc = (volatile struct _gps4020_intc *)GPS4020_INTC;
|
156 |
|
|
intc->enable &= ~(1<<vector);
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
void hal_interrupt_unmask(int vector)
|
160 |
|
|
{
|
161 |
|
|
volatile struct _gps4020_intc *intc = (volatile struct _gps4020_intc *)GPS4020_INTC;
|
162 |
|
|
intc->enable |= (1<<vector);
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
void hal_interrupt_acknowledge(int vector)
|
166 |
|
|
{
|
167 |
|
|
volatile struct _gps4020_intc *intc = (volatile struct _gps4020_intc *)GPS4020_INTC;
|
168 |
|
|
intc->reset = (1<<vector);
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
void hal_interrupt_configure(int vector, int level, int up)
|
172 |
|
|
{
|
173 |
|
|
// diag_printf("%s(%d,%d,%d)\n", __PRETTY_FUNCTION__, vector, level, up);
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
void hal_interrupt_set_level(int vector, int level)
|
177 |
|
|
{
|
178 |
|
|
// diag_printf("%s(%d,%d)\n", __PRETTY_FUNCTION__, vector, level);
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
//-----------------------------------------------------------------------------
|
182 |
|
|
// Reset board
|
183 |
|
|
|
184 |
|
|
void
|
185 |
|
|
hal_gps4020_reset(void)
|
186 |
|
|
{
|
187 |
|
|
volatile struct _gps4020_watchdog *wdg = (volatile struct _gps4020_watchdog *)GPS4020_WATCHDOG;
|
188 |
|
|
|
189 |
|
|
wdg->period = 1; // Almost as fast as possible
|
190 |
|
|
wdg->reset = GPS4020_WATCHDOG_RESET;
|
191 |
|
|
// Wait for it...
|
192 |
|
|
for(;;);
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
// Watchdog support
|
196 |
|
|
void
|
197 |
|
|
_gps4020_watchdog(bool is_idle)
|
198 |
|
|
{
|
199 |
|
|
volatile struct _gps4020_watchdog *wdg = (volatile struct _gps4020_watchdog *)GPS4020_WATCHDOG;
|
200 |
|
|
wdg->reset = GPS4020_WATCHDOG_RESET;
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
#ifdef CYGPKG_REDBOOT
|
204 |
|
|
#include <redboot.h>
|
205 |
|
|
RedBoot_idle(_gps4020_watchdog, RedBoot_AFTER_NETIO);
|
206 |
|
|
#endif
|
207 |
|
|
|
208 |
|
|
/*------------------------------------------------------------------------*/
|
209 |
|
|
// EOF hal_misc.c
|