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): jskov
|
43 |
|
|
// Contributors:jskov
|
44 |
|
|
// Date: 2001-03-16
|
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 CYGBLD_HAL_PLATFORM_H
|
54 |
|
|
|
55 |
|
|
#include <cyg/infra/cyg_type.h> // base types
|
56 |
|
|
|
57 |
|
|
#include <cyg/hal/hal_arch.h> // SAVE/RESTORE GP macros
|
58 |
|
|
#include <cyg/hal/hal_io.h> // IO macros
|
59 |
|
|
#include <cyg/hal/hal_if.h> // interface API
|
60 |
|
|
#include <cyg/hal/hal_intr.h> // HAL_ENABLE/MASK/UNMASK_INTERRUPTS
|
61 |
|
|
#include <cyg/hal/hal_misc.h> // Helper functions
|
62 |
|
|
#include <cyg/hal/drv_api.h> // CYG_ISR_HANDLED
|
63 |
|
|
|
64 |
|
|
#include <cyg/hal/plf_io.h> // SIO registers
|
65 |
|
|
|
66 |
|
|
#define SIO_BRDDIV (((CYGNUM_HAL_ARM_E7T_CLOCK_SPEED/2/16/CYGNUM_HAL_VIRTUAL_VECTOR_CHANNELS_DEFAULT_BAUD)<<4))
|
67 |
|
|
|
68 |
|
|
//-----------------------------------------------------------------------------
|
69 |
|
|
typedef struct {
|
70 |
|
|
cyg_uint8* base;
|
71 |
|
|
cyg_int32 msec_timeout;
|
72 |
|
|
int isr_vector_rx;
|
73 |
|
|
int isr_vector_tx;
|
74 |
|
|
} channel_data_t;
|
75 |
|
|
|
76 |
|
|
//-----------------------------------------------------------------------------
|
77 |
|
|
|
78 |
|
|
char hextab[] = "0123456789ABCDEF";
|
79 |
|
|
|
80 |
|
|
void putc_ser(int c)
|
81 |
|
|
{
|
82 |
|
|
cyg_uint8* base = (cyg_uint8*)E7T_UART1_BASE;
|
83 |
|
|
cyg_uint32 status;
|
84 |
|
|
do {
|
85 |
|
|
HAL_READ_UINT32(base+E7T_UART_STAT, status);
|
86 |
|
|
} while ((status & E7T_UART_STAT_TXE) == 0);
|
87 |
|
|
|
88 |
|
|
HAL_WRITE_UINT32(base+E7T_UART_TXBUF, c);
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
void putint(int a)
|
92 |
|
|
{
|
93 |
|
|
int i;
|
94 |
|
|
putc_ser('0');
|
95 |
|
|
putc_ser('x');
|
96 |
|
|
for (i = 0; i < 8; i++) {
|
97 |
|
|
putc_ser(hextab[(a>>(28-(4*i))) & 0x0f]);
|
98 |
|
|
}
|
99 |
|
|
putc_ser('\r');
|
100 |
|
|
putc_ser('\n');
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
void
|
104 |
|
|
init_ser(void)
|
105 |
|
|
{
|
106 |
|
|
cyg_uint8* base = (cyg_uint8*)E7T_UART1_BASE;
|
107 |
|
|
|
108 |
|
|
// 8-1-no parity.
|
109 |
|
|
HAL_WRITE_UINT32(base+E7T_UART_LCON,
|
110 |
|
|
E7T_UART_LCON_8_DBITS|E7T_UART_LCON_1_SBITS|E7T_UART_LCON_NO_PARITY);
|
111 |
|
|
|
112 |
|
|
// Mask interrupts.
|
113 |
|
|
HAL_INTERRUPT_MASK(CYGNUM_HAL_INTERRUPT_UART0_RX);
|
114 |
|
|
HAL_INTERRUPT_MASK(CYGNUM_HAL_INTERRUPT_UART0_TX);
|
115 |
|
|
|
116 |
|
|
HAL_WRITE_UINT32(base+E7T_UART_BRDIV, SIO_BRDDIV);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
//-----------------------------------------------------------------------------
|
120 |
|
|
|
121 |
|
|
static void
|
122 |
|
|
cyg_hal_plf_serial_init_channel(void* __ch_data)
|
123 |
|
|
{
|
124 |
|
|
cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
|
125 |
|
|
|
126 |
|
|
// 8-1-no parity.
|
127 |
|
|
HAL_WRITE_UINT32(base+E7T_UART_LCON,
|
128 |
|
|
E7T_UART_LCON_8_DBITS|E7T_UART_LCON_1_SBITS|E7T_UART_LCON_NO_PARITY);
|
129 |
|
|
|
130 |
|
|
HAL_WRITE_UINT32(base+E7T_UART_BRDIV, SIO_BRDDIV);
|
131 |
|
|
|
132 |
|
|
// Mask interrupts
|
133 |
|
|
HAL_INTERRUPT_MASK(((channel_data_t*)__ch_data)->isr_vector_rx);
|
134 |
|
|
HAL_INTERRUPT_MASK(((channel_data_t*)__ch_data)->isr_vector_tx);
|
135 |
|
|
|
136 |
|
|
// Enable RX and TX
|
137 |
|
|
HAL_WRITE_UINT32(base+E7T_UART_CON, E7T_UART_CON_RXM_INT|E7T_UART_CON_TXM_INT);
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
void
|
141 |
|
|
cyg_hal_plf_serial_putc(void *__ch_data, char c)
|
142 |
|
|
{
|
143 |
|
|
cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
|
144 |
|
|
cyg_uint32 status, ch;
|
145 |
|
|
CYGARC_HAL_SAVE_GP();
|
146 |
|
|
|
147 |
|
|
do {
|
148 |
|
|
HAL_READ_UINT32(base+E7T_UART_STAT, status);
|
149 |
|
|
} while ((status & E7T_UART_STAT_TXE) == 0);
|
150 |
|
|
|
151 |
|
|
ch = (cyg_uint32)c;
|
152 |
|
|
HAL_WRITE_UINT32(base+E7T_UART_TXBUF, ch);
|
153 |
|
|
|
154 |
|
|
CYGARC_HAL_RESTORE_GP();
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
static cyg_bool
|
158 |
|
|
cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
|
159 |
|
|
{
|
160 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
161 |
|
|
cyg_uint8* base = chan->base;
|
162 |
|
|
cyg_uint32 stat;
|
163 |
|
|
cyg_uint32 c;
|
164 |
|
|
|
165 |
|
|
HAL_READ_UINT32(base+E7T_UART_STAT, stat);
|
166 |
|
|
if ((stat & E7T_UART_STAT_RDR) == 0)
|
167 |
|
|
return false;
|
168 |
|
|
|
169 |
|
|
HAL_READ_UINT32(base+E7T_UART_RXBUF, c);
|
170 |
|
|
*ch = (cyg_uint8)(c & 0xff);
|
171 |
|
|
|
172 |
|
|
HAL_INTERRUPT_ACKNOWLEDGE(chan->isr_vector_rx);
|
173 |
|
|
|
174 |
|
|
return true;
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
cyg_uint8
|
178 |
|
|
cyg_hal_plf_serial_getc(void* __ch_data)
|
179 |
|
|
{
|
180 |
|
|
cyg_uint8 ch;
|
181 |
|
|
CYGARC_HAL_SAVE_GP();
|
182 |
|
|
|
183 |
|
|
while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
|
184 |
|
|
|
185 |
|
|
CYGARC_HAL_RESTORE_GP();
|
186 |
|
|
return ch;
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
static void
|
190 |
|
|
cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
|
191 |
|
|
cyg_uint32 __len)
|
192 |
|
|
{
|
193 |
|
|
CYGARC_HAL_SAVE_GP();
|
194 |
|
|
|
195 |
|
|
while(__len-- > 0)
|
196 |
|
|
cyg_hal_plf_serial_putc(__ch_data, *__buf++);
|
197 |
|
|
|
198 |
|
|
CYGARC_HAL_RESTORE_GP();
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
static void
|
202 |
|
|
cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
|
203 |
|
|
{
|
204 |
|
|
CYGARC_HAL_SAVE_GP();
|
205 |
|
|
|
206 |
|
|
while(__len-- > 0)
|
207 |
|
|
*__buf++ = cyg_hal_plf_serial_getc(__ch_data);
|
208 |
|
|
|
209 |
|
|
CYGARC_HAL_RESTORE_GP();
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
cyg_bool
|
213 |
|
|
cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
|
214 |
|
|
{
|
215 |
|
|
int delay_count;
|
216 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
217 |
|
|
cyg_bool res;
|
218 |
|
|
CYGARC_HAL_SAVE_GP();
|
219 |
|
|
|
220 |
|
|
delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
|
221 |
|
|
|
222 |
|
|
for(;;) {
|
223 |
|
|
res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
|
224 |
|
|
if (res || 0 == delay_count--)
|
225 |
|
|
break;
|
226 |
|
|
|
227 |
|
|
CYGACC_CALL_IF_DELAY_US(100);
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
CYGARC_HAL_RESTORE_GP();
|
231 |
|
|
return res;
|
232 |
|
|
}
|
233 |
|
|
|
234 |
|
|
static int
|
235 |
|
|
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
|
236 |
|
|
{
|
237 |
|
|
static int irq_state = 0;
|
238 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
239 |
|
|
int ret = 0;
|
240 |
|
|
CYGARC_HAL_SAVE_GP();
|
241 |
|
|
|
242 |
|
|
switch (__func) {
|
243 |
|
|
case __COMMCTL_IRQ_ENABLE:
|
244 |
|
|
irq_state = 1;
|
245 |
|
|
HAL_INTERRUPT_ACKNOWLEDGE(chan->isr_vector_rx);
|
246 |
|
|
HAL_INTERRUPT_UNMASK(chan->isr_vector_rx);
|
247 |
|
|
break;
|
248 |
|
|
case __COMMCTL_IRQ_DISABLE:
|
249 |
|
|
ret = irq_state;
|
250 |
|
|
irq_state = 0;
|
251 |
|
|
HAL_INTERRUPT_MASK(chan->isr_vector_rx);
|
252 |
|
|
break;
|
253 |
|
|
case __COMMCTL_DBG_ISR_VECTOR:
|
254 |
|
|
ret = chan->isr_vector_rx;
|
255 |
|
|
break;
|
256 |
|
|
case __COMMCTL_SET_TIMEOUT:
|
257 |
|
|
{
|
258 |
|
|
va_list ap;
|
259 |
|
|
|
260 |
|
|
va_start(ap, __func);
|
261 |
|
|
|
262 |
|
|
ret = chan->msec_timeout;
|
263 |
|
|
chan->msec_timeout = va_arg(ap, cyg_uint32);
|
264 |
|
|
|
265 |
|
|
va_end(ap);
|
266 |
|
|
}
|
267 |
|
|
default:
|
268 |
|
|
break;
|
269 |
|
|
}
|
270 |
|
|
CYGARC_HAL_RESTORE_GP();
|
271 |
|
|
return ret;
|
272 |
|
|
}
|
273 |
|
|
|
274 |
|
|
static int
|
275 |
|
|
cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
|
276 |
|
|
CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
|
277 |
|
|
{
|
278 |
|
|
int res = 0;
|
279 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
280 |
|
|
cyg_uint32 c;
|
281 |
|
|
cyg_uint8 ch;
|
282 |
|
|
cyg_uint32 stat;
|
283 |
|
|
CYGARC_HAL_SAVE_GP();
|
284 |
|
|
|
285 |
|
|
*__ctrlc = 0;
|
286 |
|
|
HAL_READ_UINT32(chan->base+E7T_UART_STAT, stat);
|
287 |
|
|
if ( (stat & E7T_UART_STAT_RDR) != 0 ) {
|
288 |
|
|
|
289 |
|
|
HAL_READ_UINT32(chan->base+E7T_UART_RXBUF, c);
|
290 |
|
|
ch = (cyg_uint8)(c & 0xff);
|
291 |
|
|
if( cyg_hal_is_break( &ch , 1 ) )
|
292 |
|
|
*__ctrlc = 1;
|
293 |
|
|
|
294 |
|
|
res = CYG_ISR_HANDLED;
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
HAL_INTERRUPT_ACKNOWLEDGE(chan->isr_vector_rx);
|
298 |
|
|
|
299 |
|
|
CYGARC_HAL_RESTORE_GP();
|
300 |
|
|
return res;
|
301 |
|
|
}
|
302 |
|
|
|
303 |
|
|
static channel_data_t e7t_ser_channels[2] = {
|
304 |
|
|
{ (cyg_uint8*)E7T_UART0_BASE, 1000, CYGNUM_HAL_INTERRUPT_UART0_RX, CYGNUM_HAL_INTERRUPT_UART0_TX },
|
305 |
|
|
{ (cyg_uint8*)E7T_UART1_BASE, 1000, CYGNUM_HAL_INTERRUPT_UART1_RX, CYGNUM_HAL_INTERRUPT_UART1_TX }
|
306 |
|
|
};
|
307 |
|
|
|
308 |
|
|
static void
|
309 |
|
|
cyg_hal_plf_serial_init(void)
|
310 |
|
|
{
|
311 |
|
|
hal_virtual_comm_table_t* comm;
|
312 |
|
|
int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
|
313 |
|
|
|
314 |
|
|
// Init channels
|
315 |
|
|
cyg_hal_plf_serial_init_channel(&e7t_ser_channels[0]);
|
316 |
|
|
cyg_hal_plf_serial_init_channel(&e7t_ser_channels[1]);
|
317 |
|
|
|
318 |
|
|
// Setup procs in the vector table
|
319 |
|
|
|
320 |
|
|
// Set channel 0
|
321 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
|
322 |
|
|
comm = CYGACC_CALL_IF_CONSOLE_PROCS();
|
323 |
|
|
CYGACC_COMM_IF_CH_DATA_SET(*comm, &e7t_ser_channels[0]);
|
324 |
|
|
CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
|
325 |
|
|
CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
|
326 |
|
|
CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
|
327 |
|
|
CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
|
328 |
|
|
CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
|
329 |
|
|
CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
|
330 |
|
|
CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
|
331 |
|
|
|
332 |
|
|
// Set channel 1
|
333 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(1);
|
334 |
|
|
comm = CYGACC_CALL_IF_CONSOLE_PROCS();
|
335 |
|
|
CYGACC_COMM_IF_CH_DATA_SET(*comm, &e7t_ser_channels[1]);
|
336 |
|
|
CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
|
337 |
|
|
CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
|
338 |
|
|
CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
|
339 |
|
|
CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
|
340 |
|
|
CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
|
341 |
|
|
CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
|
342 |
|
|
CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
|
343 |
|
|
|
344 |
|
|
// Restore original console
|
345 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
|
346 |
|
|
}
|
347 |
|
|
|
348 |
|
|
void
|
349 |
|
|
cyg_hal_plf_comms_init(void)
|
350 |
|
|
{
|
351 |
|
|
static int initialized = 0;
|
352 |
|
|
|
353 |
|
|
if (initialized)
|
354 |
|
|
return;
|
355 |
|
|
|
356 |
|
|
initialized = 1;
|
357 |
|
|
|
358 |
|
|
cyg_hal_plf_serial_init();
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
//-----------------------------------------------------------------------------
|
362 |
|
|
// LED
|
363 |
|
|
void
|
364 |
|
|
hal_diag_led(int mask)
|
365 |
|
|
{
|
366 |
|
|
cyg_uint32 l;
|
367 |
|
|
|
368 |
|
|
HAL_READ_UINT32(E7T_IOPDATA, l);
|
369 |
|
|
l &= ~0x000000f0;
|
370 |
|
|
l |= (mask & 0xf) << 4;
|
371 |
|
|
HAL_WRITE_UINT32(E7T_IOPDATA, l);
|
372 |
|
|
}
|
373 |
|
|
|
374 |
|
|
//-----------------------------------------------------------------------------
|
375 |
|
|
// End of hal_diag.c
|