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): Patrick Doyle <wpd@delcomsys.com>
|
43 |
|
|
// Contributors:Patrick Doyle <wpd@delcomsys.com>
|
44 |
|
|
// Date: 2002-12-17
|
45 |
|
|
// Purpose: HAL diagnostic output
|
46 |
|
|
// This file contains the type definitions, constants, and function
|
47 |
|
|
// prototoypes that implement very simple access to the UART on the
|
48 |
|
|
// OMAP part.
|
49 |
|
|
// Description: Implementations of HAL diagnostic output support.
|
50 |
|
|
//
|
51 |
|
|
//####DESCRIPTIONEND####
|
52 |
|
|
//
|
53 |
|
|
//=============================================================================
|
54 |
|
|
|
55 |
|
|
#include <pkgconf/hal.h>
|
56 |
|
|
#include CYGBLD_HAL_VARIANT_H // Variant specific configuration
|
57 |
|
|
#include CYGBLD_HAL_PLATFORM_H // Platform specific configuration
|
58 |
|
|
|
59 |
|
|
#include <cyg/infra/cyg_type.h> // base types
|
60 |
|
|
#include <cyg/infra/cyg_trac.h> // tracing macros
|
61 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
62 |
|
|
|
63 |
|
|
#include <cyg/hal/hal_arch.h> // basic machine info
|
64 |
|
|
#include <cyg/hal/hal_intr.h> // interrupt macros
|
65 |
|
|
#include <cyg/hal/hal_io.h> // IO macros
|
66 |
|
|
#include <cyg/hal/hal_diag.h>
|
67 |
|
|
#include <cyg/hal/drv_api.h>
|
68 |
|
|
#include <cyg/hal/hal_if.h> // interface API
|
69 |
|
|
#include <cyg/hal/hal_misc.h> // Helper functions
|
70 |
|
|
#include <cyg/hal/innovator.h> // platform definitions
|
71 |
|
|
|
72 |
|
|
//-----------------------------------------------------------------------------
|
73 |
|
|
|
74 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_DIV (CYGNUM_HAL_ARM_INNOVATOR_PERIPHERAL_CLOCK/CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD/16)
|
75 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_LSB (CYG_DEVICE_SERIAL_BAUD_DIV&0xff)
|
76 |
|
|
#define CYG_DEVICE_SERIAL_BAUD_MSB ((CYG_DEVICE_SERIAL_BAUD_DIV>>8)&0xff)
|
77 |
|
|
|
78 |
|
|
//-----------------------------------------------------------------------------
|
79 |
|
|
typedef struct {
|
80 |
|
|
cyg_int32 msec_timeout;
|
81 |
|
|
#ifdef LATER
|
82 |
|
|
cyg_uint32 base;
|
83 |
|
|
int isr_vector;
|
84 |
|
|
#endif
|
85 |
|
|
} channel_data_t;
|
86 |
|
|
|
87 |
|
|
/************************************************************************
|
88 |
|
|
* Useful definitions -- note that 'USE_MODEM_UART' has not been extensively
|
89 |
|
|
* tested nor debugged (read -- it probably doesn't work).
|
90 |
|
|
************************************************************************/
|
91 |
|
|
/*#define USE_MODEM_UART*/
|
92 |
|
|
#ifdef USE_MODEM_UART
|
93 |
|
|
#define BASE_ADDR 0xfffce800
|
94 |
|
|
#define STRIDE 1
|
95 |
|
|
#else
|
96 |
|
|
#define BASE_ADDR 0xfffb0000
|
97 |
|
|
#define STRIDE 4
|
98 |
|
|
#endif
|
99 |
|
|
|
100 |
|
|
#define RHR 0x00
|
101 |
|
|
#define THR 0x00
|
102 |
|
|
#define DLL 0x00
|
103 |
|
|
#define DLH 0x01
|
104 |
|
|
#define IER 0x01
|
105 |
|
|
#define FCR 0x02
|
106 |
|
|
#define EFR 0x02
|
107 |
|
|
#define IIR 0x02
|
108 |
|
|
#define LCR 0x03
|
109 |
|
|
#define MCR 0x04
|
110 |
|
|
#define XON1 0x04
|
111 |
|
|
#define LSR 0x05
|
112 |
|
|
#define XON2 0x05
|
113 |
|
|
#define MSR 0x06
|
114 |
|
|
#define TCR 0x06
|
115 |
|
|
#define XOFF1 0x06
|
116 |
|
|
#define SPR 0x07
|
117 |
|
|
#define TLR 0x07
|
118 |
|
|
#define XOFF2 0x07
|
119 |
|
|
#define MDR1 0x08
|
120 |
|
|
#define UASR 0x0e
|
121 |
|
|
#define SCR 0x10
|
122 |
|
|
#define SSR 0x11
|
123 |
|
|
#define OSC_12M 0x13
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
/************************************************************************
|
127 |
|
|
* Data local to this file
|
128 |
|
|
************************************************************************/
|
129 |
|
|
#define write_serial(offset, value) \
|
130 |
|
|
*(volatile char *)(BASE_ADDR + STRIDE * (offset)) = value
|
131 |
|
|
|
132 |
|
|
#define read_serial(offset) \
|
133 |
|
|
(*(volatile char *)(BASE_ADDR + STRIDE * (offset)))
|
134 |
|
|
|
135 |
|
|
/************************************************************************
|
136 |
|
|
* Forward References
|
137 |
|
|
************************************************************************/
|
138 |
|
|
|
139 |
|
|
/************************************************************************
|
140 |
|
|
* Function:
|
141 |
|
|
* init_uart()
|
142 |
|
|
*
|
143 |
|
|
* Purpose:
|
144 |
|
|
* This procedure may be called in order to initialize the UART
|
145 |
|
|
* prior to use.
|
146 |
|
|
*
|
147 |
|
|
* Operation:
|
148 |
|
|
* Set up the UART for 115,200 baud, 8 bits, 1 stop bit, no parity.
|
149 |
|
|
*
|
150 |
|
|
* The UART is defined by the 'BASE_ADDR' macro.
|
151 |
|
|
*
|
152 |
|
|
* Notes/Issues:
|
153 |
|
|
* This pays some lip service to being able to use UART3, but since
|
154 |
|
|
* it seems to me that the use of UART3 requires that the DSP do
|
155 |
|
|
* some setup (at least, until I learn more), it probably won't
|
156 |
|
|
* work for UART3.
|
157 |
|
|
************************************************************************/
|
158 |
|
|
static void
|
159 |
|
|
quick_init_uart(void)
|
160 |
|
|
{
|
161 |
|
|
/* UART Software Reset */
|
162 |
|
|
write_serial(LCR, 0xBF); /* Access to EFR & UART break is removed */
|
163 |
|
|
write_serial(EFR, BIT_04); /* Set EFR[4] = 0x1 */
|
164 |
|
|
write_serial(LCR, 0x00); /* Access to IER & MCR is allowed */
|
165 |
|
|
|
166 |
|
|
write_serial(IER, 0x00); /* Disable all interrupts */
|
167 |
|
|
write_serial(MCR, 0x00); /* DTR, RTS, XON, loopbback inactive */
|
168 |
|
|
|
169 |
|
|
write_serial(MDR1,0x07); /* UART is in reset */
|
170 |
|
|
|
171 |
|
|
/* UART FIFO Configuration */
|
172 |
|
|
write_serial(MCR, read_serial(MCR) | BIT_06); /* Set MCR[6] = 1 */
|
173 |
|
|
write_serial(TCR, 0x0F); /* RTS off when Rx FIFO at 60 bytes, on at 0 */
|
174 |
|
|
write_serial(TLR, 0x88); /* set TX & RX trigger levels each to 32 */
|
175 |
|
|
write_serial(FCR, 0x07); /* Enable & reset FIFOs, triggers at 8 */
|
176 |
|
|
write_serial(LCR, 0xBF); /* Access EFR */
|
177 |
|
|
write_serial(EFR, 0xC0); /* Enable auto RTS & CTS */
|
178 |
|
|
write_serial(LCR, 0x00); /* Access to IER & MCR is allowed */
|
179 |
|
|
write_serial(MCR, read_serial(MCR) & ~BIT_06); /* Clear MCR[6] */
|
180 |
|
|
|
181 |
|
|
/* Baud Rate and Stop Configuration */
|
182 |
|
|
write_serial(LCR, 0x03); /* 8,N,1 */
|
183 |
|
|
#ifdef USE_MODEM_UART
|
184 |
|
|
write_serial(LCR, 0x83); /* gain access to DLH and DLL */
|
185 |
|
|
write_serial(DLH, 0x00); /* Divisor value = Operating Freq/(16 x Baud Rate) */
|
186 |
|
|
write_serial(DLL, 0x0D); /* DPLL2 configured for Operating Freq = 24 MHz */
|
187 |
|
|
/* Baud Rate = 115,200 bps */
|
188 |
|
|
#else
|
189 |
|
|
write_serial(OSC_12M, 1);/* Set divisor value to 6.5 */
|
190 |
|
|
write_serial(LCR, 0x83); /* gain access to DLH and DLL */
|
191 |
|
|
write_serial(DLH, 0x00); /* Divisor value =
|
192 |
|
|
* Operating Freq/(16 x 6.5 x Baud Rate) */
|
193 |
|
|
write_serial(DLL, 0x01); /* DPLL2 configured for Operating Freq = 12 MHz */
|
194 |
|
|
/* Baud Rate = 115,200 bps */
|
195 |
|
|
#endif
|
196 |
|
|
write_serial(LCR, 0x03); /* restore LCR */
|
197 |
|
|
|
198 |
|
|
write_serial(MDR1,0x00); /* enable UART */
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
/************************************************************************
|
202 |
|
|
* Function:
|
203 |
|
|
* putchar(c)
|
204 |
|
|
*
|
205 |
|
|
* Purpose:
|
206 |
|
|
* This procedure may be called in order to output a character on
|
207 |
|
|
* the serial port. It blocks until the serial port TX FIFO is
|
208 |
|
|
* empty.
|
209 |
|
|
*
|
210 |
|
|
* Operation:
|
211 |
|
|
* Write character to the Transmit Holding Register (THR). Can
|
212 |
|
|
* optionally map the Linefeed character to a Carriage Return
|
213 |
|
|
* character and/or output a Carriage Return character whenever
|
214 |
|
|
* a Linefeed character is seen, depending on #ifdefs.
|
215 |
|
|
*
|
216 |
|
|
* Notes/Issues:
|
217 |
|
|
* This could be optimized to block only when the serial port TX
|
218 |
|
|
* FIFO is full.
|
219 |
|
|
************************************************************************/
|
220 |
|
|
static void
|
221 |
|
|
quick_putchar(char c)
|
222 |
|
|
{
|
223 |
|
|
/* #define MAP_LF_TO_CR */
|
224 |
|
|
#ifdef MAP_LF_TO_CR
|
225 |
|
|
if (c == '\n') {
|
226 |
|
|
c = '\r';
|
227 |
|
|
}
|
228 |
|
|
#endif
|
229 |
|
|
while ((read_serial(LSR) & 0x20) == 0) ;
|
230 |
|
|
write_serial(THR, c);
|
231 |
|
|
|
232 |
|
|
/* #define DO_CRLF */
|
233 |
|
|
#ifdef DO_CRLF
|
234 |
|
|
if (c == '\n') {
|
235 |
|
|
quick_putchar('\r');
|
236 |
|
|
}
|
237 |
|
|
#endif
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
/************************************************************************
|
241 |
|
|
* Function:
|
242 |
|
|
* getchar()
|
243 |
|
|
*
|
244 |
|
|
* Purpose:
|
245 |
|
|
* This function may be called in order to read a character from
|
246 |
|
|
* the serial port.
|
247 |
|
|
*
|
248 |
|
|
* Operation:
|
249 |
|
|
* Poll the Line Status register until it indicates a character has
|
250 |
|
|
* been received. Return the character to the caller.
|
251 |
|
|
*
|
252 |
|
|
* Notes/Issues:
|
253 |
|
|
*
|
254 |
|
|
************************************************************************/
|
255 |
|
|
static int
|
256 |
|
|
quick_getchar(void)
|
257 |
|
|
{
|
258 |
|
|
while ((read_serial(LSR) & 0x01) == 0) ;
|
259 |
|
|
return(read_serial(RHR));
|
260 |
|
|
}
|
261 |
|
|
|
262 |
|
|
/************************************************************************
|
263 |
|
|
* Function:
|
264 |
|
|
* getchar_nonblock()
|
265 |
|
|
*
|
266 |
|
|
* Purpose:
|
267 |
|
|
* This function may be called in order to read a character from
|
268 |
|
|
* the serial port.
|
269 |
|
|
*
|
270 |
|
|
* Operation:
|
271 |
|
|
* Poll the Line Status register until it indicates a character has
|
272 |
|
|
* been received. Return the character to the caller.
|
273 |
|
|
*
|
274 |
|
|
* Notes/Issues:
|
275 |
|
|
*
|
276 |
|
|
************************************************************************/
|
277 |
|
|
static int
|
278 |
|
|
quick_getchar_nonblock(char *c)
|
279 |
|
|
{
|
280 |
|
|
if ((read_serial(LSR) & 0x01) == 0) {
|
281 |
|
|
return(0);
|
282 |
|
|
} else {
|
283 |
|
|
*c = read_serial(RHR);
|
284 |
|
|
return(1);
|
285 |
|
|
}
|
286 |
|
|
}
|
287 |
|
|
|
288 |
|
|
//-----------------------------------------------------------------------------
|
289 |
|
|
|
290 |
|
|
static void
|
291 |
|
|
cyg_hal_plf_serial_init_channel(void* __ch_data)
|
292 |
|
|
{
|
293 |
|
|
#ifdef LATER
|
294 |
|
|
cyg_uint32 base = ((channel_data_t*)__ch_data)->base;
|
295 |
|
|
|
296 |
|
|
// 8-1-no parity.
|
297 |
|
|
HAL_WRITE_UINT32(base+_UART_MC, _UART_MC_8BIT | _UART_MC_1STOP | _UART_MC_PARITY_NONE);
|
298 |
|
|
|
299 |
|
|
HAL_WRITE_UINT32(base+_UART_DIV_LO, CYG_DEVICE_SERIAL_BAUD_LSB);
|
300 |
|
|
HAL_WRITE_UINT32(base+_UART_DIV_HI, CYG_DEVICE_SERIAL_BAUD_MSB);
|
301 |
|
|
HAL_WRITE_UINT32(base+_UART_FCR, (_UART_FCR_TC | _UART_FCR_RC |
|
302 |
|
|
_UART_FCR_TX_THR_15 | _UART_FCR_RX_THR_1)); // clear & enableFIFO
|
303 |
|
|
|
304 |
|
|
// enable RX interrupts - otherwise ISR cannot be polled. Actual
|
305 |
|
|
// interrupt control of serial happens via INT_MASK
|
306 |
|
|
HAL_WRITE_UINT32(base+_UART_IES, _UART_INTS_RE);
|
307 |
|
|
#endif
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
void
|
311 |
|
|
cyg_hal_plf_serial_putc(void *__ch_data, char c)
|
312 |
|
|
{
|
313 |
|
|
#ifdef LATER
|
314 |
|
|
cyg_uint32 base = ((channel_data_t*)__ch_data)->base;
|
315 |
|
|
cyg_uint32 tsr;
|
316 |
|
|
CYGARC_HAL_SAVE_GP();
|
317 |
|
|
|
318 |
|
|
do {
|
319 |
|
|
HAL_READ_UINT32(base+_UART_TSR, tsr);
|
320 |
|
|
// Wait for TXI flag to be set - or for the register to be
|
321 |
|
|
// zero (works around a HW bug it seems).
|
322 |
|
|
} while (tsr && (tsr & _UART_TSR_TXI) == 0);
|
323 |
|
|
|
324 |
|
|
HAL_WRITE_UINT32(base+_UART_TD, (cyg_uint32)(unsigned char)c);
|
325 |
|
|
|
326 |
|
|
CYGARC_HAL_RESTORE_GP();
|
327 |
|
|
#else
|
328 |
|
|
quick_putchar(c);
|
329 |
|
|
#endif
|
330 |
|
|
}
|
331 |
|
|
|
332 |
|
|
static cyg_bool
|
333 |
|
|
cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
|
334 |
|
|
{
|
335 |
|
|
#ifdef LATER
|
336 |
|
|
cyg_uint32 base = ((channel_data_t*)__ch_data)->base;
|
337 |
|
|
cyg_uint32 rsr, isr, data;
|
338 |
|
|
|
339 |
|
|
HAL_READ_UINT32(base+_UART_ISR, isr);
|
340 |
|
|
if (0 == (isr & _UART_INTS_RI)) {
|
341 |
|
|
HAL_READ_UINT32(base+_UART_RSR, rsr);
|
342 |
|
|
if (0 == rsr)
|
343 |
|
|
return false;
|
344 |
|
|
}
|
345 |
|
|
|
346 |
|
|
HAL_READ_UINT32(base+_UART_RD, data);
|
347 |
|
|
*ch = (cyg_uint8)(data & 0xff);
|
348 |
|
|
|
349 |
|
|
// Read RSR to clear interrupt, and RDS to clear errors
|
350 |
|
|
HAL_READ_UINT32(base+_UART_RSR, data);
|
351 |
|
|
HAL_READ_UINT32(base+_UART_RDS, data);
|
352 |
|
|
|
353 |
|
|
return true;
|
354 |
|
|
#else
|
355 |
|
|
return(quick_getchar_nonblock(ch));
|
356 |
|
|
#endif
|
357 |
|
|
}
|
358 |
|
|
|
359 |
|
|
cyg_uint8
|
360 |
|
|
cyg_hal_plf_serial_getc(void* __ch_data)
|
361 |
|
|
{
|
362 |
|
|
#ifdef LATER
|
363 |
|
|
cyg_uint8 ch;
|
364 |
|
|
CYGARC_HAL_SAVE_GP();
|
365 |
|
|
|
366 |
|
|
while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
|
367 |
|
|
|
368 |
|
|
CYGARC_HAL_RESTORE_GP();
|
369 |
|
|
return ch;
|
370 |
|
|
#else
|
371 |
|
|
return(quick_getchar());
|
372 |
|
|
#endif
|
373 |
|
|
}
|
374 |
|
|
|
375 |
|
|
static channel_data_t innovator_ser_channels[1] = {
|
376 |
|
|
{ 1000 }
|
377 |
|
|
};
|
378 |
|
|
|
379 |
|
|
static void
|
380 |
|
|
cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
|
381 |
|
|
cyg_uint32 __len)
|
382 |
|
|
{
|
383 |
|
|
CYGARC_HAL_SAVE_GP();
|
384 |
|
|
|
385 |
|
|
while(__len-- > 0)
|
386 |
|
|
cyg_hal_plf_serial_putc(__ch_data, *__buf++);
|
387 |
|
|
|
388 |
|
|
CYGARC_HAL_RESTORE_GP();
|
389 |
|
|
}
|
390 |
|
|
|
391 |
|
|
static void
|
392 |
|
|
cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
|
393 |
|
|
{
|
394 |
|
|
CYGARC_HAL_SAVE_GP();
|
395 |
|
|
|
396 |
|
|
while(__len-- > 0)
|
397 |
|
|
*__buf++ = cyg_hal_plf_serial_getc(__ch_data);
|
398 |
|
|
|
399 |
|
|
CYGARC_HAL_RESTORE_GP();
|
400 |
|
|
}
|
401 |
|
|
|
402 |
|
|
cyg_bool
|
403 |
|
|
cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
|
404 |
|
|
{
|
405 |
|
|
int delay_count;
|
406 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
407 |
|
|
cyg_bool res;
|
408 |
|
|
CYGARC_HAL_SAVE_GP();
|
409 |
|
|
|
410 |
|
|
delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
|
411 |
|
|
|
412 |
|
|
for(;;) {
|
413 |
|
|
res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
|
414 |
|
|
if (res || 0 == delay_count--)
|
415 |
|
|
break;
|
416 |
|
|
|
417 |
|
|
CYGACC_CALL_IF_DELAY_US(100);
|
418 |
|
|
}
|
419 |
|
|
|
420 |
|
|
CYGARC_HAL_RESTORE_GP();
|
421 |
|
|
return res;
|
422 |
|
|
}
|
423 |
|
|
|
424 |
|
|
static int
|
425 |
|
|
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
|
426 |
|
|
{
|
427 |
|
|
static int irq_state = 0;
|
428 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
429 |
|
|
int ret = 0;
|
430 |
|
|
CYGARC_HAL_SAVE_GP();
|
431 |
|
|
|
432 |
|
|
switch (__func) {
|
433 |
|
|
case __COMMCTL_IRQ_ENABLE:
|
434 |
|
|
irq_state = 1;
|
435 |
|
|
|
436 |
|
|
// Need to keep it enabled to allow polling using ISR
|
437 |
|
|
//HAL_WRITE_UINT32(chan->base+_UART_IES, _UART_INTS_RE);
|
438 |
|
|
|
439 |
|
|
#ifdef LATER
|
440 |
|
|
HAL_INTERRUPT_UNMASK(chan->isr_vector);
|
441 |
|
|
#endif
|
442 |
|
|
break;
|
443 |
|
|
case __COMMCTL_IRQ_DISABLE:
|
444 |
|
|
ret = irq_state;
|
445 |
|
|
irq_state = 0;
|
446 |
|
|
|
447 |
|
|
// Need to keep it enabled to allow polling using ISR
|
448 |
|
|
// HAL_WRITE_UINT32(chan->base+_UART_IEC, _UART_INTS_RE);
|
449 |
|
|
|
450 |
|
|
#ifdef LATER
|
451 |
|
|
HAL_INTERRUPT_MASK(chan->isr_vector);
|
452 |
|
|
#endif
|
453 |
|
|
break;
|
454 |
|
|
case __COMMCTL_DBG_ISR_VECTOR:
|
455 |
|
|
#ifdef LATER
|
456 |
|
|
ret = chan->isr_vector;
|
457 |
|
|
#else
|
458 |
|
|
ret = 0;
|
459 |
|
|
#endif
|
460 |
|
|
break;
|
461 |
|
|
case __COMMCTL_SET_TIMEOUT:
|
462 |
|
|
{
|
463 |
|
|
va_list ap;
|
464 |
|
|
|
465 |
|
|
va_start(ap, __func);
|
466 |
|
|
|
467 |
|
|
ret = chan->msec_timeout;
|
468 |
|
|
chan->msec_timeout = va_arg(ap, cyg_uint32);
|
469 |
|
|
|
470 |
|
|
va_end(ap);
|
471 |
|
|
}
|
472 |
|
|
default:
|
473 |
|
|
break;
|
474 |
|
|
}
|
475 |
|
|
CYGARC_HAL_RESTORE_GP();
|
476 |
|
|
return ret;
|
477 |
|
|
}
|
478 |
|
|
|
479 |
|
|
static int
|
480 |
|
|
cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
|
481 |
|
|
CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
|
482 |
|
|
{
|
483 |
|
|
#ifdef LATER
|
484 |
|
|
int res = 0;
|
485 |
|
|
channel_data_t* chan = (channel_data_t*)__ch_data;
|
486 |
|
|
cyg_uint32 isr, ch, rsr;
|
487 |
|
|
char c;
|
488 |
|
|
CYGARC_HAL_SAVE_GP();
|
489 |
|
|
|
490 |
|
|
cyg_drv_interrupt_acknowledge(chan->isr_vector);
|
491 |
|
|
|
492 |
|
|
*__ctrlc = 0;
|
493 |
|
|
HAL_READ_UINT32(chan->base+_UART_ISR, isr);
|
494 |
|
|
HAL_READ_UINT32(chan->base+_UART_RSR, rsr);
|
495 |
|
|
|
496 |
|
|
// Again, check both RI and the RX FIFO count.
|
497 |
|
|
if ( ((isr & _UART_INTS_RI) != 0 ) || (rsr) ) {
|
498 |
|
|
|
499 |
|
|
HAL_READ_UINT32(chan->base+_UART_RD, ch);
|
500 |
|
|
|
501 |
|
|
c = (char)ch;
|
502 |
|
|
if( cyg_hal_is_break( &c , 1 ) )
|
503 |
|
|
*__ctrlc = 1;
|
504 |
|
|
|
505 |
|
|
res = CYG_ISR_HANDLED;
|
506 |
|
|
}
|
507 |
|
|
|
508 |
|
|
CYGARC_HAL_RESTORE_GP();
|
509 |
|
|
return res;
|
510 |
|
|
#else
|
511 |
|
|
return 0;
|
512 |
|
|
#endif
|
513 |
|
|
}
|
514 |
|
|
|
515 |
|
|
static void
|
516 |
|
|
cyg_hal_plf_serial_init(void)
|
517 |
|
|
{
|
518 |
|
|
hal_virtual_comm_table_t* comm;
|
519 |
|
|
int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
|
520 |
|
|
|
521 |
|
|
#ifdef LATER
|
522 |
|
|
// Disable interrupts.
|
523 |
|
|
HAL_INTERRUPT_MASK(innovator_ser_channels[0].isr_vector);
|
524 |
|
|
|
525 |
|
|
// Init channels
|
526 |
|
|
cyg_hal_plf_serial_init_channel(&innovator_ser_channels[0]);
|
527 |
|
|
#else
|
528 |
|
|
quick_init_uart();
|
529 |
|
|
#endif
|
530 |
|
|
|
531 |
|
|
// Setup procs in the vector table
|
532 |
|
|
|
533 |
|
|
// Set channel 0
|
534 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
|
535 |
|
|
comm = CYGACC_CALL_IF_CONSOLE_PROCS();
|
536 |
|
|
CYGACC_COMM_IF_CH_DATA_SET(*comm, &innovator_ser_channels[0]);
|
537 |
|
|
CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
|
538 |
|
|
CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
|
539 |
|
|
CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
|
540 |
|
|
CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
|
541 |
|
|
CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
|
542 |
|
|
CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
|
543 |
|
|
CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
|
544 |
|
|
|
545 |
|
|
// Restore original console
|
546 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
|
547 |
|
|
|
548 |
|
|
}
|
549 |
|
|
|
550 |
|
|
void
|
551 |
|
|
cyg_hal_plf_comms_init(void)
|
552 |
|
|
{
|
553 |
|
|
static int initialized = 0;
|
554 |
|
|
|
555 |
|
|
if (initialized)
|
556 |
|
|
return;
|
557 |
|
|
|
558 |
|
|
initialized = 1;
|
559 |
|
|
|
560 |
|
|
cyg_hal_plf_serial_init();
|
561 |
|
|
}
|
562 |
|
|
|
563 |
|
|
//-----------------------------------------------------------------------------
|
564 |
|
|
// LEDs
|
565 |
|
|
void
|
566 |
|
|
hal_diag_led(int n)
|
567 |
|
|
{
|
568 |
|
|
}
|
569 |
|
|
|
570 |
|
|
//-----------------------------------------------------------------------------
|
571 |
|
|
// End of hal_diag.c
|