1 |
27 |
unneback |
//=============================================================================
|
2 |
|
|
//
|
3 |
|
|
// hal_diag.c
|
4 |
|
|
//
|
5 |
|
|
// HAL diagnostic output code
|
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): jskov
|
44 |
|
|
// Contributors:jskov
|
45 |
|
|
// Date: 2001-08-06
|
46 |
|
|
// Purpose: HAL diagnostic output
|
47 |
|
|
// Description: Implementations of HAL diagnostic output support.
|
48 |
|
|
//
|
49 |
|
|
//####DESCRIPTIONEND####
|
50 |
|
|
//
|
51 |
|
|
//=============================================================================
|
52 |
|
|
|
53 |
|
|
#include <pkgconf/hal.h>
|
54 |
|
|
#include CYGBLD_HAL_VARIANT_H // Variant specific configuration
|
55 |
|
|
#include CYGBLD_HAL_PLATFORM_H // Platform specific configuration
|
56 |
|
|
|
57 |
|
|
#include <cyg/infra/cyg_type.h> // base types
|
58 |
|
|
#include <cyg/infra/cyg_trac.h> // tracing macros
|
59 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
60 |
|
|
|
61 |
|
|
#include <cyg/hal/hal_arch.h> // basic machine info
|
62 |
|
|
#include <cyg/hal/hal_intr.h> // interrupt macros
|
63 |
|
|
#include <cyg/hal/hal_io.h> // IO macros
|
64 |
|
|
#include <cyg/hal/hal_diag.h>
|
65 |
|
|
#include <cyg/hal/drv_api.h>
|
66 |
|
|
#include <cyg/hal/hal_if.h> // interface API
|
67 |
|
|
#include <cyg/hal/hal_misc.h> // Helper functions
|
68 |
|
|
#include <cyg/hal/excalibur.h> // platform definitions
|
69 |
|
|
|
70 |
|
|
//-----------------------------------------------------------------------------
|
71 |
|
|
|
72 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_DIV (CYGNUM_HAL_ARM_EXCALIBUR_PERIPHERAL_CLOCK/CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD/16)
|
73 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_LSB (CYG_DEVICE_SERIAL_BAUD_DIV&0xff)
|
74 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_MSB ((CYG_DEVICE_SERIAL_BAUD_DIV>>8)&0xff)
|
75 |
|
|
|
76 |
|
|
//-----------------------------------------------------------------------------
|
77 |
|
|
typedef struct {
|
78 |
|
|
cyg_uint32 base;
|
79 |
|
|
cyg_int32 msec_timeout;
|
80 |
|
|
int isr_vector;
|
81 |
|
|
} channel_data_t;
|
82 |
|
|
|
83 |
|
|
//-----------------------------------------------------------------------------
|
84 |
|
|
|
85 |
|
|
static void
|
86 |
|
|
cyg_hal_plf_serial_init_channel(void* __ch_data)
|
87 |
|
|
{
|
88 |
|
|
cyg_uint32 base = ((channel_data_t*)__ch_data)->base;
|
89 |
|
|
|
90 |
|
|
// 8-1-no parity.
|
91 |
|
|
HAL_WRITE_UINT32(base+_UART_MC, _UART_MC_8BIT | _UART_MC_1STOP | _UART_MC_PARITY_NONE);
|
92 |
|
|
|
93 |
|
|
HAL_WRITE_UINT32(base+_UART_DIV_LO, CYG_DEVICE_SERIAL_BAUD_LSB);
|
94 |
|
|
HAL_WRITE_UINT32(base+_UART_DIV_HI, CYG_DEVICE_SERIAL_BAUD_MSB);
|
95 |
|
|
HAL_WRITE_UINT32(base+_UART_FCR, (_UART_FCR_TC | _UART_FCR_RC |
|
96 |
|
|
_UART_FCR_TX_THR_15 | _UART_FCR_RX_THR_1)); // clear & enableFIFO
|
97 |
|
|
|
98 |
|
|
// enable RX interrupts - otherwise ISR cannot be polled. Actual
|
99 |
|
|
// interrupt control of serial happens via INT_MASK
|
100 |
|
|
HAL_WRITE_UINT32(base+_UART_IES, _UART_INTS_RE);
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
void
|
104 |
|
|
cyg_hal_plf_serial_putc(void *__ch_data, char c)
|
105 |
|
|
{
|
106 |
|
|
cyg_uint32 base = ((channel_data_t*)__ch_data)->base;
|
107 |
|
|
cyg_uint32 tsr;
|
108 |
|
|
CYGARC_HAL_SAVE_GP();
|
109 |
|
|
|
110 |
|
|
do {
|
111 |
|
|
HAL_READ_UINT32(base+_UART_TSR, tsr);
|
112 |
|
|
// Wait for TXI flag to be set - or for the register to be
|
113 |
|
|
// zero (works around a HW bug it seems).
|
114 |
|
|
} while (tsr && (tsr & _UART_TSR_TXI) == 0);
|
115 |
|
|
|
116 |
|
|
HAL_WRITE_UINT32(base+_UART_TD, (cyg_uint32)(unsigned char)c);
|
117 |
|
|
|
118 |
|
|
CYGARC_HAL_RESTORE_GP();
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
static cyg_bool
|
122 |
|
|
cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
|
123 |
|
|
{
|
124 |
|
|
cyg_uint32 base = ((channel_data_t*)__ch_data)->base;
|
125 |
|
|
cyg_uint32 rsr, isr, data;
|
126 |
|
|
|
127 |
|
|
HAL_READ_UINT32(base+_UART_ISR, isr);
|
128 |
|
|
if (0 == (isr & _UART_INTS_RI)) {
|
129 |
|
|
HAL_READ_UINT32(base+_UART_RSR, rsr);
|
130 |
|
|
if (0 == rsr)
|
131 |
|
|
return false;
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
HAL_READ_UINT32(base+_UART_RD, data);
|
135 |
|
|
*ch = (cyg_uint8)(data & 0xff);
|
136 |
|
|
|
137 |
|
|
// Read RSR to clear interrupt, and RDS to clear errors
|
138 |
|
|
HAL_READ_UINT32(base+_UART_RSR, data);
|
139 |
|
|
HAL_READ_UINT32(base+_UART_RDS, data);
|
140 |
|
|
|
141 |
|
|
return true;
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
cyg_uint8
|
145 |
|
|
cyg_hal_plf_serial_getc(void* __ch_data)
|
146 |
|
|
{
|
147 |
|
|
cyg_uint8 ch;
|
148 |
|
|
CYGARC_HAL_SAVE_GP();
|
149 |
|
|
|
150 |
|
|
while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
|
151 |
|
|
|
152 |
|
|
CYGARC_HAL_RESTORE_GP();
|
153 |
|
|
return ch;
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
static channel_data_t excalibur_ser_channels[1] = {
|
157 |
|
|
{ (cyg_uint32)EXCALIBUR_UART0_BASE, 1000, CYGNUM_HAL_INTERRUPT_UART }
|
158 |
|
|
};
|
159 |
|
|
|
160 |
|
|
static void
|
161 |
|
|
cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
|
162 |
|
|
cyg_uint32 __len)
|
163 |
|
|
{
|
164 |
|
|
CYGARC_HAL_SAVE_GP();
|
165 |
|
|
|
166 |
|
|
while(__len-- > 0)
|
167 |
|
|
cyg_hal_plf_serial_putc(__ch_data, *__buf++);
|
168 |
|
|
|
169 |
|
|
CYGARC_HAL_RESTORE_GP();
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
static void
|
173 |
|
|
cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
|
174 |
|
|
{
|
175 |
|
|
CYGARC_HAL_SAVE_GP();
|
176 |
|
|
|
177 |
|
|
while(__len-- > 0)
|
178 |
|
|
*__buf++ = cyg_hal_plf_serial_getc(__ch_data);
|
179 |
|
|
|
180 |
|
|
CYGARC_HAL_RESTORE_GP();
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
cyg_bool
|
184 |
|
|
cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
|
185 |
|
|
{
|
186 |
|
|
int delay_count;
|
187 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
188 |
|
|
cyg_bool res;
|
189 |
|
|
CYGARC_HAL_SAVE_GP();
|
190 |
|
|
|
191 |
|
|
delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
|
192 |
|
|
|
193 |
|
|
for(;;) {
|
194 |
|
|
res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
|
195 |
|
|
if (res || 0 == delay_count--)
|
196 |
|
|
break;
|
197 |
|
|
|
198 |
|
|
CYGACC_CALL_IF_DELAY_US(100);
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
CYGARC_HAL_RESTORE_GP();
|
202 |
|
|
return res;
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
static int
|
206 |
|
|
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
|
207 |
|
|
{
|
208 |
|
|
static int irq_state = 0;
|
209 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
210 |
|
|
int ret = 0;
|
211 |
|
|
CYGARC_HAL_SAVE_GP();
|
212 |
|
|
|
213 |
|
|
switch (__func) {
|
214 |
|
|
case __COMMCTL_IRQ_ENABLE:
|
215 |
|
|
irq_state = 1;
|
216 |
|
|
|
217 |
|
|
// Need to keep it enabled to allow polling using ISR
|
218 |
|
|
//HAL_WRITE_UINT32(chan->base+_UART_IES, _UART_INTS_RE);
|
219 |
|
|
|
220 |
|
|
HAL_INTERRUPT_UNMASK(chan->isr_vector);
|
221 |
|
|
break;
|
222 |
|
|
case __COMMCTL_IRQ_DISABLE:
|
223 |
|
|
ret = irq_state;
|
224 |
|
|
irq_state = 0;
|
225 |
|
|
|
226 |
|
|
// Need to keep it enabled to allow polling using ISR
|
227 |
|
|
// HAL_WRITE_UINT32(chan->base+_UART_IEC, _UART_INTS_RE);
|
228 |
|
|
|
229 |
|
|
HAL_INTERRUPT_MASK(chan->isr_vector);
|
230 |
|
|
break;
|
231 |
|
|
case __COMMCTL_DBG_ISR_VECTOR:
|
232 |
|
|
ret = chan->isr_vector;
|
233 |
|
|
break;
|
234 |
|
|
case __COMMCTL_SET_TIMEOUT:
|
235 |
|
|
{
|
236 |
|
|
va_list ap;
|
237 |
|
|
|
238 |
|
|
va_start(ap, __func);
|
239 |
|
|
|
240 |
|
|
ret = chan->msec_timeout;
|
241 |
|
|
chan->msec_timeout = va_arg(ap, cyg_uint32);
|
242 |
|
|
|
243 |
|
|
va_end(ap);
|
244 |
|
|
}
|
245 |
|
|
default:
|
246 |
|
|
break;
|
247 |
|
|
}
|
248 |
|
|
CYGARC_HAL_RESTORE_GP();
|
249 |
|
|
return ret;
|
250 |
|
|
}
|
251 |
|
|
|
252 |
|
|
static int
|
253 |
|
|
cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
|
254 |
|
|
CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
|
255 |
|
|
{
|
256 |
|
|
int res = 0;
|
257 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
258 |
|
|
cyg_uint32 isr, ch, rsr;
|
259 |
|
|
char c;
|
260 |
|
|
CYGARC_HAL_SAVE_GP();
|
261 |
|
|
|
262 |
|
|
cyg_drv_interrupt_acknowledge(chan->isr_vector);
|
263 |
|
|
|
264 |
|
|
*__ctrlc = 0;
|
265 |
|
|
HAL_READ_UINT32(chan->base+_UART_ISR, isr);
|
266 |
|
|
HAL_READ_UINT32(chan->base+_UART_RSR, rsr);
|
267 |
|
|
|
268 |
|
|
// Again, check both RI and the RX FIFO count.
|
269 |
|
|
if ( ((isr & _UART_INTS_RI) != 0 ) || (rsr) ) {
|
270 |
|
|
|
271 |
|
|
HAL_READ_UINT32(chan->base+_UART_RD, ch);
|
272 |
|
|
|
273 |
|
|
c = (char)ch;
|
274 |
|
|
if( cyg_hal_is_break( &c , 1 ) )
|
275 |
|
|
*__ctrlc = 1;
|
276 |
|
|
|
277 |
|
|
res = CYG_ISR_HANDLED;
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
CYGARC_HAL_RESTORE_GP();
|
281 |
|
|
return res;
|
282 |
|
|
}
|
283 |
|
|
|
284 |
|
|
static void
|
285 |
|
|
cyg_hal_plf_serial_init(void)
|
286 |
|
|
{
|
287 |
|
|
hal_virtual_comm_table_t* comm;
|
288 |
|
|
int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
|
289 |
|
|
|
290 |
|
|
// Disable interrupts.
|
291 |
|
|
HAL_INTERRUPT_MASK(excalibur_ser_channels[0].isr_vector);
|
292 |
|
|
|
293 |
|
|
// Init channels
|
294 |
|
|
cyg_hal_plf_serial_init_channel(&excalibur_ser_channels[0]);
|
295 |
|
|
|
296 |
|
|
// Setup procs in the vector table
|
297 |
|
|
|
298 |
|
|
// Set channel 0
|
299 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
|
300 |
|
|
comm = CYGACC_CALL_IF_CONSOLE_PROCS();
|
301 |
|
|
CYGACC_COMM_IF_CH_DATA_SET(*comm, &excalibur_ser_channels[0]);
|
302 |
|
|
CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
|
303 |
|
|
CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
|
304 |
|
|
CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
|
305 |
|
|
CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
|
306 |
|
|
CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
|
307 |
|
|
CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
|
308 |
|
|
CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
|
309 |
|
|
|
310 |
|
|
// Restore original console
|
311 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
|
312 |
|
|
}
|
313 |
|
|
|
314 |
|
|
void
|
315 |
|
|
cyg_hal_plf_comms_init(void)
|
316 |
|
|
{
|
317 |
|
|
static int initialized = 0;
|
318 |
|
|
|
319 |
|
|
if (initialized)
|
320 |
|
|
return;
|
321 |
|
|
|
322 |
|
|
initialized = 1;
|
323 |
|
|
|
324 |
|
|
cyg_hal_plf_serial_init();
|
325 |
|
|
}
|
326 |
|
|
|
327 |
|
|
//-----------------------------------------------------------------------------
|
328 |
|
|
// LEDs
|
329 |
|
|
void
|
330 |
|
|
hal_diag_led(int n)
|
331 |
|
|
{
|
332 |
|
|
}
|
333 |
|
|
|
334 |
|
|
//-----------------------------------------------------------------------------
|
335 |
|
|
// End of hal_diag.c
|