1 |
786 |
skrzyp |
/*=============================================================================
|
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 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): nickg, gthomas
|
43 |
|
|
// Contributors:nickg, gthomas
|
44 |
|
|
// Date: 1998-03-02
|
45 |
|
|
// Purpose: HAL diagnostic output
|
46 |
|
|
// Description: Implementations of HAL diagnostic output support.
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
//
|
50 |
|
|
//===========================================================================*/
|
51 |
|
|
|
52 |
|
|
#include <pkgconf/hal.h>
|
53 |
|
|
#include <pkgconf/hal_arm_pid.h> // board specifics
|
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_arch.h> // basic machine info
|
60 |
|
|
#include <cyg/hal/hal_intr.h> // interrupt macros
|
61 |
|
|
#include <cyg/hal/hal_io.h> // IO macros
|
62 |
|
|
#include <cyg/hal/hal_diag.h>
|
63 |
|
|
#include <cyg/hal/drv_api.h>
|
64 |
|
|
#include <cyg/hal/hal_if.h> // interface API
|
65 |
|
|
#include <cyg/hal/hal_misc.h> // Helper functions
|
66 |
|
|
|
67 |
|
|
/*---------------------------------------------------------------------------*/
|
68 |
|
|
/* From serial_16550.h */
|
69 |
|
|
#if CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD==9600
|
70 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_MSB 0x00
|
71 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_LSB 0x0C
|
72 |
|
|
#endif
|
73 |
|
|
#if CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD==19200
|
74 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_MSB 0x00
|
75 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_LSB 0x06
|
76 |
|
|
#endif
|
77 |
|
|
#if CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD==38400
|
78 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_MSB 0x00
|
79 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_LSB 0x03
|
80 |
|
|
#endif
|
81 |
|
|
#if CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD==115200
|
82 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_MSB 0x00
|
83 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_LSB 0x01
|
84 |
|
|
#endif
|
85 |
|
|
|
86 |
|
|
#ifndef CYG_DEVICE_SERIAL_BAUD_MSB
|
87 |
|
|
#error Missing/incorrect serial baud rate defined - CDL error?
|
88 |
|
|
#endif
|
89 |
|
|
|
90 |
|
|
// Define the serial registers.
|
91 |
|
|
#define CYG_DEV_RBR 0x00 // receiver buffer register, read, dlab = 0
|
92 |
|
|
#define CYG_DEV_THR 0x00 // transmitter holding register, write, dlab = 0
|
93 |
|
|
#define CYG_DEV_DLL 0x00 // divisor latch (LS), read/write, dlab = 1
|
94 |
|
|
#define CYG_DEV_IER 0x04 // interrupt enable register, read/write, dlab = 0
|
95 |
|
|
#define CYG_DEV_DLM 0x04 // divisor latch (MS), read/write, dlab = 1
|
96 |
|
|
#define CYG_DEV_IIR 0x08 // interrupt identification register, read, dlab = 0
|
97 |
|
|
#define CYG_DEV_FCR 0x08 // fifo control register, write, dlab = 0
|
98 |
|
|
#define CYG_DEV_LCR 0x0C // line control register, read/write
|
99 |
|
|
#define CYG_DEV_MCR 0x10 // modem control register, read/write
|
100 |
|
|
#define CYG_DEV_LSR 0x14 // line status register, read
|
101 |
|
|
#define CYG_DEV_MSR 0x18 // modem status register, read
|
102 |
|
|
|
103 |
|
|
// Interrupt Enable Register
|
104 |
|
|
#define SIO_IER_RCV 0x01
|
105 |
|
|
#define SIO_IER_XMT 0x02
|
106 |
|
|
#define SIO_IER_LS 0x04
|
107 |
|
|
#define SIO_IER_MS 0x08
|
108 |
|
|
|
109 |
|
|
// The line status register bits.
|
110 |
|
|
#define SIO_LSR_DR 0x01 // data ready
|
111 |
|
|
#define SIO_LSR_OE 0x02 // overrun error
|
112 |
|
|
#define SIO_LSR_PE 0x04 // parity error
|
113 |
|
|
#define SIO_LSR_FE 0x08 // framing error
|
114 |
|
|
#define SIO_LSR_BI 0x10 // break interrupt
|
115 |
|
|
#define SIO_LSR_THRE 0x20 // transmitter holding register empty
|
116 |
|
|
#define SIO_LSR_TEMT 0x40 // transmitter register empty
|
117 |
|
|
#define SIO_LSR_ERR 0x80 // any error condition
|
118 |
|
|
|
119 |
|
|
// The modem status register bits.
|
120 |
|
|
#define SIO_MSR_DCTS 0x01 // delta clear to send
|
121 |
|
|
#define SIO_MSR_DDSR 0x02 // delta data set ready
|
122 |
|
|
#define SIO_MSR_TERI 0x04 // trailing edge ring indicator
|
123 |
|
|
#define SIO_MSR_DDCD 0x08 // delta data carrier detect
|
124 |
|
|
#define SIO_MSR_CTS 0x10 // clear to send
|
125 |
|
|
#define SIO_MSR_DSR 0x20 // data set ready
|
126 |
|
|
#define SIO_MSR_RI 0x40 // ring indicator
|
127 |
|
|
#define SIO_MSR_DCD 0x80 // data carrier detect
|
128 |
|
|
|
129 |
|
|
// The line control register bits.
|
130 |
|
|
#define SIO_LCR_WLS0 0x01 // word length select bit 0
|
131 |
|
|
#define SIO_LCR_WLS1 0x02 // word length select bit 1
|
132 |
|
|
#define SIO_LCR_STB 0x04 // number of stop bits
|
133 |
|
|
#define SIO_LCR_PEN 0x08 // parity enable
|
134 |
|
|
#define SIO_LCR_EPS 0x10 // even parity select
|
135 |
|
|
#define SIO_LCR_SP 0x20 // stick parity
|
136 |
|
|
#define SIO_LCR_SB 0x40 // set break
|
137 |
|
|
#define SIO_LCR_DLAB 0x80 // divisor latch access bit
|
138 |
|
|
|
139 |
|
|
// Modem Control Register
|
140 |
|
|
#define SIO_MCR_DTR 0x01
|
141 |
|
|
#define SIO_MCR_RTS 0x02
|
142 |
|
|
#define SIO_MCR_INT 0x08 // Enable interrupts
|
143 |
|
|
|
144 |
|
|
//-----------------------------------------------------------------------------
|
145 |
|
|
typedef struct {
|
146 |
|
|
cyg_uint8* base;
|
147 |
|
|
cyg_int32 msec_timeout;
|
148 |
|
|
int isr_vector;
|
149 |
|
|
} channel_data_t;
|
150 |
|
|
|
151 |
|
|
//-----------------------------------------------------------------------------
|
152 |
|
|
|
153 |
|
|
static void
|
154 |
|
|
cyg_hal_plf_serial_init_channel(void* __ch_data)
|
155 |
|
|
{
|
156 |
|
|
cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
|
157 |
|
|
cyg_uint8 lcr;
|
158 |
|
|
|
159 |
|
|
// 8-1-no parity.
|
160 |
|
|
HAL_WRITE_UINT8(base+CYG_DEV_LCR, SIO_LCR_WLS0 | SIO_LCR_WLS1);
|
161 |
|
|
|
162 |
|
|
HAL_READ_UINT8(base+CYG_DEV_LCR, lcr);
|
163 |
|
|
lcr |= SIO_LCR_DLAB;
|
164 |
|
|
HAL_WRITE_UINT8(base+CYG_DEV_LCR, lcr);
|
165 |
|
|
HAL_WRITE_UINT8(base+CYG_DEV_DLL, CYG_DEVICE_SERIAL_BAUD_LSB);
|
166 |
|
|
HAL_WRITE_UINT8(base+CYG_DEV_DLM, CYG_DEVICE_SERIAL_BAUD_MSB);
|
167 |
|
|
lcr &= ~SIO_LCR_DLAB;
|
168 |
|
|
HAL_WRITE_UINT8(base+CYG_DEV_LCR, lcr);
|
169 |
|
|
HAL_WRITE_UINT8(base+CYG_DEV_FCR, 0x07); // Enable & clear FIFO
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
void
|
173 |
|
|
cyg_hal_plf_serial_putc(void *__ch_data, char c)
|
174 |
|
|
{
|
175 |
|
|
cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
|
176 |
|
|
cyg_uint8 lsr;
|
177 |
|
|
CYGARC_HAL_SAVE_GP();
|
178 |
|
|
|
179 |
|
|
do {
|
180 |
|
|
HAL_READ_UINT8(base+CYG_DEV_LSR, lsr);
|
181 |
|
|
} while ((lsr & SIO_LSR_THRE) == 0);
|
182 |
|
|
|
183 |
|
|
HAL_WRITE_UINT8(base+CYG_DEV_THR, c);
|
184 |
|
|
|
185 |
|
|
CYGARC_HAL_RESTORE_GP();
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
static cyg_bool
|
189 |
|
|
cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
|
190 |
|
|
{
|
191 |
|
|
cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
|
192 |
|
|
cyg_uint8 lsr;
|
193 |
|
|
|
194 |
|
|
HAL_READ_UINT8(base+CYG_DEV_LSR, lsr);
|
195 |
|
|
if ((lsr & SIO_LSR_DR) == 0)
|
196 |
|
|
return false;
|
197 |
|
|
|
198 |
|
|
HAL_READ_UINT8(base+CYG_DEV_RBR, *ch);
|
199 |
|
|
|
200 |
|
|
return true;
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
cyg_uint8
|
204 |
|
|
cyg_hal_plf_serial_getc(void* __ch_data)
|
205 |
|
|
{
|
206 |
|
|
cyg_uint8 ch;
|
207 |
|
|
CYGARC_HAL_SAVE_GP();
|
208 |
|
|
|
209 |
|
|
while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
|
210 |
|
|
|
211 |
|
|
CYGARC_HAL_RESTORE_GP();
|
212 |
|
|
return ch;
|
213 |
|
|
}
|
214 |
|
|
|
215 |
|
|
static channel_data_t pid_ser_channels[2] = {
|
216 |
|
|
{ (cyg_uint8*)0x0D800000, 1000, CYGNUM_HAL_INTERRUPT_SERIALA },
|
217 |
|
|
{ (cyg_uint8*)0x0D800020, 1000, CYGNUM_HAL_INTERRUPT_SERIALB }
|
218 |
|
|
};
|
219 |
|
|
|
220 |
|
|
static void
|
221 |
|
|
cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
|
222 |
|
|
cyg_uint32 __len)
|
223 |
|
|
{
|
224 |
|
|
CYGARC_HAL_SAVE_GP();
|
225 |
|
|
|
226 |
|
|
while(__len-- > 0)
|
227 |
|
|
cyg_hal_plf_serial_putc(__ch_data, *__buf++);
|
228 |
|
|
|
229 |
|
|
CYGARC_HAL_RESTORE_GP();
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
static void
|
233 |
|
|
cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
|
234 |
|
|
{
|
235 |
|
|
CYGARC_HAL_SAVE_GP();
|
236 |
|
|
|
237 |
|
|
while(__len-- > 0)
|
238 |
|
|
*__buf++ = cyg_hal_plf_serial_getc(__ch_data);
|
239 |
|
|
|
240 |
|
|
CYGARC_HAL_RESTORE_GP();
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
cyg_bool
|
244 |
|
|
cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
|
245 |
|
|
{
|
246 |
|
|
int delay_count;
|
247 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
248 |
|
|
cyg_bool res;
|
249 |
|
|
CYGARC_HAL_SAVE_GP();
|
250 |
|
|
|
251 |
|
|
delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
|
252 |
|
|
|
253 |
|
|
for(;;) {
|
254 |
|
|
res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
|
255 |
|
|
if (res || 0 == delay_count--)
|
256 |
|
|
break;
|
257 |
|
|
|
258 |
|
|
CYGACC_CALL_IF_DELAY_US(100);
|
259 |
|
|
}
|
260 |
|
|
|
261 |
|
|
CYGARC_HAL_RESTORE_GP();
|
262 |
|
|
return res;
|
263 |
|
|
}
|
264 |
|
|
|
265 |
|
|
static int
|
266 |
|
|
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
|
267 |
|
|
{
|
268 |
|
|
static int irq_state = 0;
|
269 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
270 |
|
|
int ret = 0;
|
271 |
|
|
CYGARC_HAL_SAVE_GP();
|
272 |
|
|
|
273 |
|
|
switch (__func) {
|
274 |
|
|
case __COMMCTL_IRQ_ENABLE:
|
275 |
|
|
irq_state = 1;
|
276 |
|
|
|
277 |
|
|
HAL_WRITE_UINT8(chan->base+CYG_DEV_IER, SIO_IER_RCV);
|
278 |
|
|
HAL_WRITE_UINT8(chan->base+CYG_DEV_MCR, SIO_MCR_INT|SIO_MCR_DTR|SIO_MCR_RTS);
|
279 |
|
|
|
280 |
|
|
HAL_INTERRUPT_UNMASK(chan->isr_vector);
|
281 |
|
|
break;
|
282 |
|
|
case __COMMCTL_IRQ_DISABLE:
|
283 |
|
|
ret = irq_state;
|
284 |
|
|
irq_state = 0;
|
285 |
|
|
|
286 |
|
|
HAL_WRITE_UINT8(chan->base+CYG_DEV_IER, 0);
|
287 |
|
|
|
288 |
|
|
HAL_INTERRUPT_MASK(chan->isr_vector);
|
289 |
|
|
break;
|
290 |
|
|
case __COMMCTL_DBG_ISR_VECTOR:
|
291 |
|
|
ret = chan->isr_vector;
|
292 |
|
|
break;
|
293 |
|
|
case __COMMCTL_SET_TIMEOUT:
|
294 |
|
|
{
|
295 |
|
|
va_list ap;
|
296 |
|
|
|
297 |
|
|
va_start(ap, __func);
|
298 |
|
|
|
299 |
|
|
ret = chan->msec_timeout;
|
300 |
|
|
chan->msec_timeout = va_arg(ap, cyg_uint32);
|
301 |
|
|
|
302 |
|
|
va_end(ap);
|
303 |
|
|
}
|
304 |
|
|
default:
|
305 |
|
|
break;
|
306 |
|
|
}
|
307 |
|
|
CYGARC_HAL_RESTORE_GP();
|
308 |
|
|
return ret;
|
309 |
|
|
}
|
310 |
|
|
|
311 |
|
|
static int
|
312 |
|
|
cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
|
313 |
|
|
CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
|
314 |
|
|
{
|
315 |
|
|
int res = 0;
|
316 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
317 |
|
|
char c;
|
318 |
|
|
cyg_uint8 lsr;
|
319 |
|
|
CYGARC_HAL_SAVE_GP();
|
320 |
|
|
|
321 |
|
|
cyg_drv_interrupt_acknowledge(chan->isr_vector);
|
322 |
|
|
|
323 |
|
|
*__ctrlc = 0;
|
324 |
|
|
HAL_READ_UINT8(chan->base+CYG_DEV_LSR, lsr);
|
325 |
|
|
if ( (lsr & SIO_LSR_DR) != 0 ) {
|
326 |
|
|
|
327 |
|
|
HAL_READ_UINT8(chan->base+CYG_DEV_RBR, c);
|
328 |
|
|
if( cyg_hal_is_break( &c , 1 ) )
|
329 |
|
|
*__ctrlc = 1;
|
330 |
|
|
|
331 |
|
|
res = CYG_ISR_HANDLED;
|
332 |
|
|
}
|
333 |
|
|
|
334 |
|
|
CYGARC_HAL_RESTORE_GP();
|
335 |
|
|
return res;
|
336 |
|
|
}
|
337 |
|
|
|
338 |
|
|
static void
|
339 |
|
|
cyg_hal_plf_serial_init(void)
|
340 |
|
|
{
|
341 |
|
|
hal_virtual_comm_table_t* comm;
|
342 |
|
|
int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
|
343 |
|
|
|
344 |
|
|
// Disable interrupts.
|
345 |
|
|
HAL_INTERRUPT_MASK(pid_ser_channels[0].isr_vector);
|
346 |
|
|
HAL_INTERRUPT_MASK(pid_ser_channels[1].isr_vector);
|
347 |
|
|
|
348 |
|
|
// Init channels
|
349 |
|
|
cyg_hal_plf_serial_init_channel(&pid_ser_channels[0]);
|
350 |
|
|
cyg_hal_plf_serial_init_channel(&pid_ser_channels[1]);
|
351 |
|
|
|
352 |
|
|
// Setup procs in the vector table
|
353 |
|
|
|
354 |
|
|
// Set channel 0
|
355 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
|
356 |
|
|
comm = CYGACC_CALL_IF_CONSOLE_PROCS();
|
357 |
|
|
CYGACC_COMM_IF_CH_DATA_SET(*comm, &pid_ser_channels[0]);
|
358 |
|
|
CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
|
359 |
|
|
CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
|
360 |
|
|
CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
|
361 |
|
|
CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
|
362 |
|
|
CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
|
363 |
|
|
CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
|
364 |
|
|
CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
|
365 |
|
|
|
366 |
|
|
// Set channel 1
|
367 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(1);
|
368 |
|
|
comm = CYGACC_CALL_IF_CONSOLE_PROCS();
|
369 |
|
|
CYGACC_COMM_IF_CH_DATA_SET(*comm, &pid_ser_channels[1]);
|
370 |
|
|
CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
|
371 |
|
|
CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
|
372 |
|
|
CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
|
373 |
|
|
CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
|
374 |
|
|
CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
|
375 |
|
|
CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
|
376 |
|
|
CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
|
377 |
|
|
|
378 |
|
|
// Restore original console
|
379 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
|
380 |
|
|
}
|
381 |
|
|
|
382 |
|
|
void
|
383 |
|
|
cyg_hal_plf_comms_init(void)
|
384 |
|
|
{
|
385 |
|
|
static int initialized = 0;
|
386 |
|
|
|
387 |
|
|
if (initialized)
|
388 |
|
|
return;
|
389 |
|
|
|
390 |
|
|
initialized = 1;
|
391 |
|
|
|
392 |
|
|
cyg_hal_plf_serial_init();
|
393 |
|
|
}
|
394 |
|
|
|
395 |
|
|
/*---------------------------------------------------------------------------*/
|
396 |
|
|
|
397 |
|
|
#ifdef CYGHWR_HAL_ARM_PID_DIAG_LEDS
|
398 |
|
|
// Control the LEDs PP0-PP3. This requires the jumpers on pins 9-16 to
|
399 |
|
|
// be set on LK11, thus preventing the use of the parallel port.
|
400 |
|
|
|
401 |
|
|
#define CYG_DEVICE_PARALLEL_DATA 0x0d800040
|
402 |
|
|
|
403 |
|
|
void
|
404 |
|
|
hal_diag_led(int n)
|
405 |
|
|
{
|
406 |
|
|
HAL_WRITE_UINT8(CYG_DEVICE_PARALLEL_DATA, (n & 0xf) << 4);
|
407 |
|
|
}
|
408 |
|
|
#endif // CYGHWR_HAL_ARM_PID_DIAG_LEDS
|
409 |
|
|
|
410 |
|
|
|
411 |
|
|
//=============================================================================
|
412 |
|
|
// Compatibility with older stubs
|
413 |
|
|
//=============================================================================
|
414 |
|
|
|
415 |
|
|
#ifndef CYGSEM_HAL_VIRTUAL_VECTOR_DIAG
|
416 |
|
|
|
417 |
|
|
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
|
418 |
|
|
#include <cyg/hal/hal_stub.h> // cyg_hal_gdb_interrupt
|
419 |
|
|
#endif
|
420 |
|
|
|
421 |
|
|
#if CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL==0
|
422 |
|
|
// This is the base address of the A-channel
|
423 |
|
|
#define CYG_DEV_SERIAL_BASE 0x0D800000
|
424 |
|
|
#define CYG_DEVICE_SERIAL_INT CYGNUM_HAL_INTERRUPT_SERIALA
|
425 |
|
|
#else
|
426 |
|
|
// This is the base address of the B-channel
|
427 |
|
|
#define CYG_DEV_SERIAL_BASE 0x0D800020
|
428 |
|
|
#define CYG_DEVICE_SERIAL_INT CYGNUM_HAL_INTERRUPT_SERIALB
|
429 |
|
|
#endif
|
430 |
|
|
|
431 |
|
|
static channel_data_t pid_ser_channel = {
|
432 |
|
|
(cyg_uint8*)CYG_DEV_SERIAL_BASE, 0, 0
|
433 |
|
|
};
|
434 |
|
|
|
435 |
|
|
// Assumption: all diagnostic output must be GDB packetized unless this is a ROM (i.e.
|
436 |
|
|
// totally stand-alone) system.
|
437 |
|
|
|
438 |
|
|
#if defined(CYG_HAL_STARTUP_ROM) || !defined(CYGDBG_HAL_DIAG_TO_DEBUG_CHAN)
|
439 |
|
|
#define HAL_DIAG_USES_HARDWARE
|
440 |
|
|
#endif
|
441 |
|
|
|
442 |
|
|
#ifndef HAL_DIAG_USES_HARDWARE
|
443 |
|
|
#if (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL != CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL)
|
444 |
|
|
#define HAL_DIAG_USES_HARDWARE
|
445 |
|
|
#endif
|
446 |
|
|
#endif
|
447 |
|
|
|
448 |
|
|
#ifdef HAL_DIAG_USES_HARDWARE
|
449 |
|
|
|
450 |
|
|
void hal_diag_init(void)
|
451 |
|
|
{
|
452 |
|
|
static int init = 0;
|
453 |
|
|
char *msg = "\n\rARM eCos\n\r";
|
454 |
|
|
|
455 |
|
|
if (init++) return;
|
456 |
|
|
|
457 |
|
|
cyg_hal_plf_serial_init_channel(&pid_ser_channel);
|
458 |
|
|
|
459 |
|
|
while (*msg) cyg_hal_plf_serial_putc(&pid_ser_channel, *msg++);
|
460 |
|
|
}
|
461 |
|
|
|
462 |
|
|
#ifdef DEBUG_DIAG
|
463 |
|
|
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
|
464 |
|
|
#define DIAG_BUFSIZE 32
|
465 |
|
|
#else
|
466 |
|
|
#define DIAG_BUFSIZE 2048
|
467 |
|
|
#endif
|
468 |
|
|
static char diag_buffer[DIAG_BUFSIZE];
|
469 |
|
|
static int diag_bp = 0;
|
470 |
|
|
#endif
|
471 |
|
|
|
472 |
|
|
void hal_diag_write_char(char c)
|
473 |
|
|
{
|
474 |
|
|
hal_diag_init();
|
475 |
|
|
|
476 |
|
|
cyg_hal_plf_serial_putc(&pid_ser_channel, c);
|
477 |
|
|
|
478 |
|
|
#ifdef DEBUG_DIAG
|
479 |
|
|
diag_buffer[diag_bp++] = c;
|
480 |
|
|
if (diag_bp == DIAG_BUFSIZE) diag_bp = 0;
|
481 |
|
|
#endif
|
482 |
|
|
}
|
483 |
|
|
|
484 |
|
|
void hal_diag_read_char(char *c)
|
485 |
|
|
{
|
486 |
|
|
*c = cyg_hal_plf_serial_getc(&pid_ser_channel);
|
487 |
|
|
}
|
488 |
|
|
|
489 |
|
|
#else // HAL_DIAG relies on GDB
|
490 |
|
|
|
491 |
|
|
// Initialize diag port - assume GDB channel is already set up
|
492 |
|
|
void hal_diag_init(void)
|
493 |
|
|
{
|
494 |
|
|
if (0) cyg_hal_plf_serial_init_channel(&pid_ser_channel); // avoid warning
|
495 |
|
|
}
|
496 |
|
|
|
497 |
|
|
// Actually send character down the wire
|
498 |
|
|
static void
|
499 |
|
|
hal_diag_write_char_serial(char c)
|
500 |
|
|
{
|
501 |
|
|
hal_diag_init();
|
502 |
|
|
|
503 |
|
|
cyg_hal_plf_serial_putc(&pid_ser_channel, c);
|
504 |
|
|
}
|
505 |
|
|
|
506 |
|
|
static bool
|
507 |
|
|
hal_diag_read_serial(char *c)
|
508 |
|
|
{
|
509 |
|
|
long timeout = 1000000000; // A long time...
|
510 |
|
|
while (!cyg_hal_plf_serial_getc_nonblock(&pid_ser_channel, c))
|
511 |
|
|
if (0 == --timeout) return false;
|
512 |
|
|
|
513 |
|
|
return true;
|
514 |
|
|
}
|
515 |
|
|
|
516 |
|
|
void
|
517 |
|
|
hal_diag_read_char(char *c)
|
518 |
|
|
{
|
519 |
|
|
while (!hal_diag_read_serial(c)) ;
|
520 |
|
|
}
|
521 |
|
|
|
522 |
|
|
void
|
523 |
|
|
hal_diag_write_char(char c)
|
524 |
|
|
{
|
525 |
|
|
static char line[100];
|
526 |
|
|
static int pos = 0;
|
527 |
|
|
|
528 |
|
|
// No need to send CRs
|
529 |
|
|
if( c == '\r' ) return;
|
530 |
|
|
|
531 |
|
|
line[pos++] = c;
|
532 |
|
|
|
533 |
|
|
if( c == '\n' || pos == sizeof(line) )
|
534 |
|
|
{
|
535 |
|
|
CYG_INTERRUPT_STATE old;
|
536 |
|
|
|
537 |
|
|
// Disable interrupts. This prevents GDB trying to interrupt us
|
538 |
|
|
// while we are in the middle of sending a packet. The serial
|
539 |
|
|
// receive interrupt will be seen when we re-enable interrupts
|
540 |
|
|
// later.
|
541 |
|
|
|
542 |
|
|
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
|
543 |
|
|
CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION(old);
|
544 |
|
|
#else
|
545 |
|
|
HAL_DISABLE_INTERRUPTS(old);
|
546 |
|
|
#endif
|
547 |
|
|
|
548 |
|
|
while(1)
|
549 |
|
|
{
|
550 |
|
|
static char hex[] = "0123456789ABCDEF";
|
551 |
|
|
cyg_uint8 csum = 0;
|
552 |
|
|
int i;
|
553 |
|
|
char c1;
|
554 |
|
|
|
555 |
|
|
hal_diag_write_char_serial('$');
|
556 |
|
|
hal_diag_write_char_serial('O');
|
557 |
|
|
csum += 'O';
|
558 |
|
|
for( i = 0; i < pos; i++ )
|
559 |
|
|
{
|
560 |
|
|
char ch = line[i];
|
561 |
|
|
char h = hex[(ch>>4)&0xF];
|
562 |
|
|
char l = hex[ch&0xF];
|
563 |
|
|
hal_diag_write_char_serial(h);
|
564 |
|
|
hal_diag_write_char_serial(l);
|
565 |
|
|
csum += h;
|
566 |
|
|
csum += l;
|
567 |
|
|
}
|
568 |
|
|
hal_diag_write_char_serial('#');
|
569 |
|
|
hal_diag_write_char_serial(hex[(csum>>4)&0xF]);
|
570 |
|
|
hal_diag_write_char_serial(hex[csum&0xF]);
|
571 |
|
|
|
572 |
|
|
// Wait for the ACK character '+' from GDB here and handle
|
573 |
|
|
// receiving a ^C instead. This is the reason for this clause
|
574 |
|
|
// being a loop.
|
575 |
|
|
if (!hal_diag_read_serial(&c1))
|
576 |
|
|
continue; // No response - try sending packet again
|
577 |
|
|
|
578 |
|
|
if( c1 == '+' )
|
579 |
|
|
break; // a good acknowledge
|
580 |
|
|
|
581 |
|
|
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
|
582 |
|
|
cyg_drv_interrupt_acknowledge(CYG_DEVICE_SERIAL_INT);
|
583 |
|
|
if( c1 == 3 ) {
|
584 |
|
|
// Ctrl-C: breakpoint.
|
585 |
|
|
cyg_hal_gdb_interrupt ((target_register_t)__builtin_return_address(0));
|
586 |
|
|
break;
|
587 |
|
|
}
|
588 |
|
|
#endif
|
589 |
|
|
// otherwise, loop round again
|
590 |
|
|
}
|
591 |
|
|
|
592 |
|
|
pos = 0;
|
593 |
|
|
|
594 |
|
|
// And re-enable interrupts
|
595 |
|
|
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
|
596 |
|
|
CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION(old);
|
597 |
|
|
#else
|
598 |
|
|
HAL_RESTORE_INTERRUPTS(old);
|
599 |
|
|
#endif
|
600 |
|
|
|
601 |
|
|
}
|
602 |
|
|
}
|
603 |
|
|
#endif
|
604 |
|
|
|
605 |
|
|
#endif // CYGSEM_HAL_VIRTUAL_VECTOR_DIAG
|
606 |
|
|
|
607 |
|
|
/*---------------------------------------------------------------------------*/
|
608 |
|
|
/* End of hal_diag.c */
|