OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [cortexm/] [a2fxxx/] [var/] [current/] [src/] [hal_diag.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
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, 2004, 2005, 2006, 2008, 2011
12
// Free Software Foundation, Inc.
13
//
14
// eCos is free software; you can redistribute it and/or modify it under
15
// the terms of the GNU General Public License as published by the Free
16
// Software Foundation; either version 2 or (at your option) any later
17
// version.
18
//
19
// eCos is distributed in the hope that it will be useful, but WITHOUT
20
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22
// for more details.
23
//
24
// You should have received a copy of the GNU General Public License
25
// along with eCos; if not, write to the Free Software Foundation, Inc.,
26
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
27
//
28
// As a special exception, if other files instantiate templates or use
29
// macros or inline functions from this file, or you compile this file
30
// and link it with other works to produce a work based on this file,
31
// this file does not by itself cause the resulting work to be covered by
32
// the GNU General Public License. However the source code for this file
33
// must still be made available in accordance with section (3) of the GNU
34
// General Public License v2.
35
//
36
// This exception does not invalidate any other reasons why a work based
37
// on this file might be covered by the GNU General Public License.
38
// -------------------------------------------
39
// ####ECOSGPLCOPYRIGHTEND####
40
//=============================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):   ccoutand
44
// Original:    nickg (STM32 HAL)
45
// Date:        2011-04-03
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_PLATFORM_H
55
 
56
#include <cyg/infra/cyg_type.h>         // base types
57
#include <cyg/infra/cyg_trac.h>         // tracing
58
 
59
#include <cyg/hal/hal_arch.h>           // SAVE/RESTORE GP macros
60
#include <cyg/hal/hal_io.h>             // IO macros
61
#include <cyg/hal/hal_if.h>             // interface API
62
#include <cyg/hal/hal_intr.h>           // HAL_ENABLE/MASK/UNMASK_INTERRUPTS
63
#include <cyg/hal/hal_misc.h>           // Helper functions
64
#include <cyg/hal/drv_api.h>            // CYG_ISR_HANDLED
65
 
66
#include <cyg/hal/var_io.h>             // USART registers
67
 
68
//-----------------------------------------------------------------------------
69
 
70
typedef struct {
71
    cyg_uint32          uart;
72
    CYG_ADDRESS         base;
73
    cyg_int32           msec_timeout;
74
    int                 isr_vector;
75
    cyg_uint32          rxpin;
76
    cyg_uint32          txpin;
77
    cyg_uint32          baud_rate;
78
    int                 irq_state;
79
 
80
} channel_data_t;
81
 
82
 
83
static channel_data_t a2fxxx_ser_channels[] = {
84
#if CYGINT_HAL_A2FXXX_UART0>0
85
    { 0,
86
      CYGHWR_HAL_A2FXXX_UART0,
87
      1000,
88
      CYGNUM_HAL_INTERRUPT_UART0,
89
      CYGHWR_HAL_A2FXXX_UART0_RX,
90
      CYGHWR_HAL_A2FXXX_UART0_TX,
91
      CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD},
92
#endif
93
#if CYGINT_HAL_A2FXXX_UART1>0
94
    { 1,
95
      CYGHWR_HAL_A2FXXX_UART1,
96
      1000,
97
      CYGNUM_HAL_INTERRUPT_UART1,
98
      CYGHWR_HAL_A2FXXX_UART1_RX,
99
      CYGHWR_HAL_A2FXXX_UART1_TX,
100
      CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD},
101
#endif
102
};
103
 
104
//-----------------------------------------------------------------------------
105
 
106
static void
107
hal_a2fxxx_serial_init_channel(void* __ch_data)
108
{
109
    channel_data_t *chan = (channel_data_t*)__ch_data;
110
    CYG_ADDRESS base = chan->base;
111
    cyg_uint32 lcr = CYGHWR_HAL_A2FXXX_UART16550_LCR_WLS_8BITS |
112
                     CYGHWR_HAL_A2FXXX_UART16550_LCR_STOP_1;
113
 
114
    // Enable the PIO lines for the serial channel
115
    CYGHWR_HAL_A2FXXX_GPIO_SET( chan->rxpin );
116
    CYGHWR_HAL_A2FXXX_GPIO_SET( chan->txpin );
117
 
118
    // Set baud rate
119
    hal_a2fxxx_uart_setbaud( base, chan->baud_rate );
120
 
121
    // 8-1-no parity
122
    HAL_WRITE_UINT32( base + CYGHWR_HAL_A2FXXX_UART16550_LCR, lcr );
123
 
124
    // Reset and clear TX/RX FIFO
125
    HAL_WRITE_UINT32( base + CYGHWR_HAL_A2FXXX_UART16550_FCR,
126
                     CYGHWR_HAL_A2FXXX_UART16550_FCR_CLEAR_TX_FIFO |
127
                     CYGHWR_HAL_A2FXXX_UART16550_FCR_CLEAR_RX_FIFO );
128
 
129
}
130
 
131
void
132
hal_a2fxxx_serial_putc(void *__ch_data, char c)
133
{
134
    CYG_ADDRESS base = ((channel_data_t*)__ch_data)->base;
135
    cyg_uint32 lsr;
136
    CYGARC_HAL_SAVE_GP();
137
 
138
     do
139
     {
140
         HAL_READ_UINT32(base + CYGHWR_HAL_A2FXXX_UART16550_LSR, lsr );
141
     } while ((lsr & CYGHWR_HAL_A2FXXX_UART16550_LSR_THRE) == 0);
142
 
143
     HAL_WRITE_UINT32(base + CYGHWR_HAL_A2FXXX_UART16550_THR, c );
144
 
145
    CYGARC_HAL_RESTORE_GP();
146
}
147
 
148
static cyg_bool
149
hal_a2fxxx_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
150
{
151
    CYG_ADDRESS base = ((channel_data_t*)__ch_data)->base;
152
    cyg_uint32 lsr;
153
    cyg_uint32 c;
154
    CYGARC_HAL_SAVE_GP();
155
 
156
    HAL_READ_UINT32(base + CYGHWR_HAL_A2FXXX_UART16550_LSR, lsr );
157
 
158
    if( (lsr & CYGHWR_HAL_A2FXXX_UART16550_LSR_DR) == 0 )
159
        return false;
160
 
161
    HAL_READ_UINT32(base + CYGHWR_HAL_A2FXXX_UART16550_RBR, c );
162
 
163
    *ch = (cyg_uint8)c;
164
 
165
    CYGARC_HAL_RESTORE_GP();
166
 
167
    return true;
168
}
169
 
170
cyg_uint8
171
hal_a2fxxx_serial_getc(void* __ch_data)
172
{
173
    cyg_uint8 ch;
174
    CYGARC_HAL_SAVE_GP();
175
 
176
    while(!hal_a2fxxx_serial_getc_nonblock(__ch_data, &ch));
177
 
178
    CYGARC_HAL_RESTORE_GP();
179
    return ch;
180
}
181
 
182
//=============================================================================
183
// Virtual vector HAL diagnostics
184
 
185
#if defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG)
186
 
187
static void
188
hal_a2fxxx_serial_write(void* __ch_data, const cyg_uint8* __buf,
189
                         cyg_uint32 __len)
190
{
191
    CYGARC_HAL_SAVE_GP();
192
 
193
    while(__len-- > 0)
194
        hal_a2fxxx_serial_putc(__ch_data, *__buf++);
195
 
196
    CYGARC_HAL_RESTORE_GP();
197
}
198
 
199
static void
200
hal_a2fxxx_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
201
{
202
    CYGARC_HAL_SAVE_GP();
203
 
204
    while(__len-- > 0)
205
        *__buf++ = hal_a2fxxx_serial_getc(__ch_data);
206
 
207
    CYGARC_HAL_RESTORE_GP();
208
}
209
 
210
cyg_bool
211
hal_a2fxxx_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
212
{
213
    int delay_count;
214
    channel_data_t* chan = (channel_data_t*)__ch_data;
215
    cyg_bool res;
216
    CYGARC_HAL_SAVE_GP();
217
 
218
    delay_count = chan->msec_timeout * 100; // delay in 10 us steps
219
 
220
    for(;;) {
221
        res = hal_a2fxxx_serial_getc_nonblock(__ch_data, ch);
222
        if (res || 0 == delay_count--)
223
            break;
224
 
225
        CYGACC_CALL_IF_DELAY_US(10);
226
    }
227
 
228
    CYGARC_HAL_RESTORE_GP();
229
    return res;
230
}
231
 
232
static int
233
hal_a2fxxx_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
234
{
235
    channel_data_t* chan = (channel_data_t*)__ch_data;
236
    CYG_ADDRESS base = ((channel_data_t*)__ch_data)->base;
237
    int ret = 0;
238
    cyg_uint32 ier;
239
 
240
    va_list ap;
241
 
242
    CYGARC_HAL_SAVE_GP();
243
 
244
    va_start(ap, __func);
245
 
246
    switch (__func) {
247
    case __COMMCTL_IRQ_ENABLE:
248
        chan->irq_state = 1;
249
        HAL_INTERRUPT_ACKNOWLEDGE( chan->isr_vector );
250
        HAL_INTERRUPT_UNMASK( chan->isr_vector );
251
        HAL_READ_UINT32(base + CYGHWR_HAL_A2FXXX_UART16550_IER, ier );
252
        ier |= CYGHWR_HAL_A2FXXX_UART16550_IER_ERBFI;
253
        HAL_WRITE_UINT32(base + CYGHWR_HAL_A2FXXX_UART16550_IER, ier );
254
        break;
255
    case __COMMCTL_IRQ_DISABLE:
256
        ret = chan->irq_state;
257
        chan->irq_state = 0;
258
        HAL_INTERRUPT_MASK( chan->isr_vector );
259
        HAL_READ_UINT32(base + CYGHWR_HAL_A2FXXX_UART16550_IER, ier );
260
        ier &= ~CYGHWR_HAL_A2FXXX_UART16550_IER_ERBFI;
261
        HAL_WRITE_UINT32(base + CYGHWR_HAL_A2FXXX_UART16550_IER, ier );
262
        break;
263
    case __COMMCTL_DBG_ISR_VECTOR:
264
        ret = chan->isr_vector;
265
        break;
266
    case __COMMCTL_SET_TIMEOUT:
267
    {
268
        va_list ap;
269
 
270
        va_start(ap, __func);
271
 
272
        ret = chan->msec_timeout;
273
        chan->msec_timeout = va_arg(ap, cyg_uint32);
274
 
275
        va_end(ap);
276
    }
277
    case __COMMCTL_GETBAUD:
278
        ret = chan->baud_rate;
279
        break;
280
    case __COMMCTL_SETBAUD:
281
        chan->baud_rate = va_arg(ap, cyg_int32);
282
        // Should we verify this value here?
283
        hal_a2fxxx_uart_setbaud( base, chan->baud_rate );
284
        ret = 0;
285
        break;
286
    default:
287
        break;
288
    }
289
    va_end(ap);
290
    CYGARC_HAL_RESTORE_GP();
291
    return ret;
292
}
293
 
294
static int
295
hal_a2fxxx_serial_isr(void *__ch_data, int* __ctrlc,
296
                       CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
297
{
298
    channel_data_t* chan = (channel_data_t*)__ch_data;
299
    cyg_uint8 ch;
300
 
301
    CYGARC_HAL_SAVE_GP();
302
 
303
     *__ctrlc = 0;
304
 
305
     if( hal_a2fxxx_serial_getc_nonblock(__ch_data, &ch) )
306
     {
307
         if( cyg_hal_is_break( (char *)&ch , 1 ) )
308
             *__ctrlc = 1;
309
     }
310
 
311
    HAL_INTERRUPT_ACKNOWLEDGE(chan->isr_vector);
312
 
313
    CYGARC_HAL_RESTORE_GP();
314
    return 1;
315
}
316
 
317
static void
318
hal_a2fxxx_serial_init(void)
319
{
320
    hal_virtual_comm_table_t* comm;
321
    int cur;
322
    int i;
323
 
324
    cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
325
 
326
    for( i = 0; i < CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS ; i++ )
327
    {
328
        hal_a2fxxx_serial_init_channel(&a2fxxx_ser_channels[i]);
329
 
330
        CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
331
        comm = CYGACC_CALL_IF_CONSOLE_PROCS();
332
        CYGACC_COMM_IF_CH_DATA_SET(*comm, &a2fxxx_ser_channels[i]);
333
        CYGACC_COMM_IF_WRITE_SET(*comm, hal_a2fxxx_serial_write);
334
        CYGACC_COMM_IF_READ_SET(*comm, hal_a2fxxx_serial_read);
335
        CYGACC_COMM_IF_PUTC_SET(*comm, hal_a2fxxx_serial_putc);
336
        CYGACC_COMM_IF_GETC_SET(*comm, hal_a2fxxx_serial_getc);
337
        CYGACC_COMM_IF_CONTROL_SET(*comm, hal_a2fxxx_serial_control);
338
        CYGACC_COMM_IF_DBG_ISR_SET(*comm, hal_a2fxxx_serial_isr);
339
        CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, hal_a2fxxx_serial_getc_timeout);
340
    }
341
 
342
    // Restore original console
343
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
344
 
345
    // set debug channel baud rate if different
346
#if (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD != CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL_BAUD)
347
    a2fxxx_ser_channels[CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL]->baud_rate =
348
        CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL_BAUD;
349
    update_baud_rate( &a2fxxx_ser_channels[CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL] );
350
#endif
351
 
352
}
353
 
354
void
355
cyg_hal_plf_comms_init(void)
356
{
357
    static int initialized = 0;
358
 
359
    if (initialized)
360
        return;
361
 
362
    initialized = 1;
363
 
364
    hal_a2fxxx_serial_init();
365
}
366
 
367
#endif
368
 
369
//=============================================================================
370
// Non-Virtual vector HAL diagnostics
371
 
372
#if !defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG)
373
 
374
void
375
hal_a2fxxx_diag_init(void)
376
{
377
    hal_a2fxxx_serial_init(
378
            &a2fxxx_ser_channels[CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL] );
379
}
380
 
381
void
382
hal_a2fxxx_diag_putc(char c)
383
{
384
    hal_a2fxxx_serial_putc(
385
            &a2fxxx_ser_channels[CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL], c);
386
}
387
 
388
cyg_uint8
389
hal_a2fxxx_diag_getc(void)
390
{
391
    return hal_a2fxxx_serial_getc(
392
            &a2fxxx_ser_channels[CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL] );
393
}
394
 
395
 
396
#endif
397
 
398
//-----------------------------------------------------------------------------
399
// End of hal_diag.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.