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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [at91/] [var/] [current/] [src/] [hal_diag_dbg.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/*=============================================================================
2
//
3
//      hal_diag_dbg.c
4
//
5
//      HAL diagnostic output code using the debug serial port
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, 2006 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, gthomas
44
// Date:        2001-07-12
45
// Purpose:     HAL diagnostic output
46
// Description: Implementations of HAL diagnostic output support.
47
//
48
//####DESCRIPTIONEND####
49
//
50
//===========================================================================*/
51
 
52
 
53
#include <pkgconf/hal.h>
54
#include <pkgconf/hal_arm_at91.h>
55
 
56
#include CYGBLD_HAL_PLATFORM_H
57
 
58
#include <cyg/infra/cyg_type.h>         // base types
59
 
60
#include <cyg/hal/hal_arch.h>           // SAVE/RESTORE GP macros
61
#include <cyg/hal/hal_io.h>             // IO macros
62
#include <cyg/hal/hal_if.h>             // interface API
63
#include <cyg/hal/hal_intr.h>           // HAL_ENABLE/MASK/UNMASK_INTERRUPTS
64
#include <cyg/hal/hal_misc.h>           // Helper functions
65
#include <cyg/hal/drv_api.h>            // CYG_ISR_HANDLED
66
#include <cyg/hal/hal_diag.h>
67
 
68
#include <cyg/hal/var_io.h>             // Device registers
69
 
70
#include "hal_diag_dcc.h"               // DCC initialization file
71
//-----------------------------------------------------------------------------
72
typedef struct {
73
    cyg_uint8* base;
74
    cyg_int32 msec_timeout;
75
    int isr_vector;
76
    cyg_uint32 baud_rate;
77
} channel_data_t;
78
 
79
//-----------------------------------------------------------------------------
80
 
81
static void
82
cyg_hal_plf_serial_dbg_init_channel(void* __ch_data)
83
{
84
    cyg_uint8 *base = ((channel_data_t*)__ch_data)->base;
85
 
86
    cyg_uint32 baud_value = 0;
87
    cyg_uint32 baud_rate  = ((channel_data_t*)__ch_data)->baud_rate;
88
 
89
    /* Enable pins to be driven by peripheral, using peripheral A. */
90
    HAL_WRITE_UINT32((AT91_PIO+AT91_PIO_ASR),
91
                     (AT91_PIO_PSR_DRXD |
92
                      AT91_PIO_PSR_DTXD));
93
 
94
    /* Disables the PIO from controlling the corresponding pin
95
      (enables peripheral control of the pin). */
96
    HAL_WRITE_UINT32((AT91_PIO+AT91_PIO_PDR),
97
                     (AT91_PIO_PSR_DRXD |
98
                      AT91_PIO_PSR_DTXD));
99
 
100
    /* Disable interrupt */
101
    HAL_WRITE_UINT32((base+AT91_DBG_IDR), 0xFFFFFFFF);
102
 
103
    /* Reset receiver and transmitter */
104
    HAL_WRITE_UINT32((base+AT91_DBG_CR),
105
                     (AT91_DBG_CR_RSTRX | AT91_DBG_CR_RSTTX |
106
                      AT91_DBG_CR_RXDIS | AT91_DBG_CR_TXDIS));
107
 
108
    baud_value = AT91_US_BAUD(baud_rate);
109
 
110
    HAL_WRITE_UINT32((base+AT91_DBG_BRGR), baud_value);
111
 
112
    /* Define the USART mode */
113
    /* (USART) Normal, 1 stop bit, No Parity, Character Length: 8 bits, Clock */
114
    HAL_WRITE_UINT32(base+AT91_DBG_MR,
115
                     (AT91_DBG_MR_CHMODE_NORMAL |
116
                      AT91_DBG_MR_PAR_NONE));
117
 
118
    /* Enable Transmitter */
119
    HAL_WRITE_UINT32((base+AT91_DBG_CR), AT91_DBG_CR_TXEN);
120
 
121
    /* Enable Receiver */
122
    HAL_WRITE_UINT32((base+AT91_DBG_CR), AT91_DBG_CR_RXEN);
123
}
124
 
125
void
126
cyg_hal_plf_serial_dbg_putc(void* __ch_data, char c)
127
{
128
    cyg_uint8 * base = ((channel_data_t*)__ch_data)->base;
129
    cyg_uint32 status;
130
    CYGARC_HAL_SAVE_GP();
131
 
132
    // Wait for Tx FIFO not full
133
    do
134
    {
135
        HAL_READ_UINT32((base+AT91_DBG_CSR), status);
136
    }
137
    while (!(status & AT91_DBG_CSR_TXRDY)) ;
138
 
139
    //UART TX data register
140
    HAL_WRITE_UINT8((base+AT91_DBG_THR), c);
141
 
142
    CYGARC_HAL_RESTORE_GP();
143
}
144
 
145
static cyg_bool
146
cyg_hal_plf_serial_dbg_getc_nonblock(void* __ch_data, cyg_uint8* ch)
147
{
148
    cyg_uint8 * base = ((channel_data_t*)__ch_data)->base;
149
    cyg_uint32 status;
150
 
151
    HAL_READ_UINT32((base+AT91_DBG_CSR), status);
152
    if (status & AT91_DBG_CSR_RXRDY)
153
      {
154
        HAL_READ_UINT8((base+AT91_DBG_RHR), *ch);
155
        return true;
156
    }
157
    return false;
158
}
159
 
160
cyg_uint8
161
cyg_hal_plf_serial_dbg_getc(void* __ch_data)
162
{
163
    cyg_uint8 ch;
164
    CYGARC_HAL_SAVE_GP();
165
 
166
    while (!cyg_hal_plf_serial_dbg_getc_nonblock(__ch_data, &ch));
167
 
168
    CYGARC_HAL_RESTORE_GP();
169
    return ch;
170
}
171
 
172
static void
173
cyg_hal_plf_serial_dbg_write(void* __ch_data, const cyg_uint8* __buf,
174
                             cyg_uint32 __len)
175
{
176
    CYGARC_HAL_SAVE_GP();
177
 
178
    while (__len-- > 0)
179
        cyg_hal_plf_serial_dbg_putc(__ch_data, *__buf++);
180
 
181
    CYGARC_HAL_RESTORE_GP();
182
}
183
 
184
static void
185
cyg_hal_plf_serial_dbg_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
186
{
187
    CYGARC_HAL_SAVE_GP();
188
 
189
    while (__len-- > 0)
190
        *__buf++ = cyg_hal_plf_serial_dbg_getc(__ch_data);
191
 
192
    CYGARC_HAL_RESTORE_GP();
193
}
194
 
195
cyg_bool
196
cyg_hal_plf_serial_dbg_getc_timeout(void* __ch_data, cyg_uint8* ch)
197
{
198
    int delay_count;
199
    channel_data_t* chan = (channel_data_t*)__ch_data;
200
    cyg_bool res;
201
    CYGARC_HAL_SAVE_GP();
202
 
203
    delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
204
 
205
    for (;;) {
206
        res = cyg_hal_plf_serial_dbg_getc_nonblock(__ch_data, ch);
207
        if (res || 0 == delay_count--)
208
            break;
209
 
210
        CYGACC_CALL_IF_DELAY_US(100);
211
    }
212
 
213
    CYGARC_HAL_RESTORE_GP();
214
    return res;
215
}
216
 
217
static int
218
cyg_hal_plf_serial_dbg_control(void *__ch_data, __comm_control_cmd_t __func, ...)
219
{
220
    static int irq_state = 0;
221
    channel_data_t* chan = (channel_data_t*)__ch_data;
222
    int ret = 0;
223
    va_list ap;
224
 
225
    CYGARC_HAL_SAVE_GP();
226
    va_start(ap, __func);
227
 
228
    switch (__func) {
229
      case __COMMCTL_GETBAUD:
230
        ret = chan->baud_rate;
231
        break;
232
      case __COMMCTL_SETBAUD:
233
        chan->baud_rate = va_arg(ap, cyg_int32);
234
        // Should we verify this value here?
235
        cyg_hal_plf_serial_dbg_init_channel(chan);
236
        ret = 0;
237
        break;
238
      case __COMMCTL_IRQ_ENABLE:
239
        irq_state = 1;
240
        HAL_INTERRUPT_UNMASK(chan->isr_vector);
241
        HAL_WRITE_UINT32((chan->base+AT91_DBG_IER), AT91_DBG_CSR_RXRDY);
242
        break;
243
      case __COMMCTL_IRQ_DISABLE:
244
        ret = irq_state;
245
        irq_state = 0;
246
        HAL_WRITE_UINT32((chan->base+AT91_DBG_IDR), AT91_DBG_CSR_RXRDY);
247
        HAL_INTERRUPT_MASK(chan->isr_vector);
248
        break;
249
      case __COMMCTL_DBG_ISR_VECTOR:
250
        ret = chan->isr_vector;
251
        break;
252
      case __COMMCTL_SET_TIMEOUT:
253
        ret = chan->msec_timeout;
254
        chan->msec_timeout = va_arg(ap, cyg_uint32);
255
      default:
256
        break;
257
    }
258
    CYGARC_HAL_RESTORE_GP();
259
    return ret;
260
}
261
 
262
static int
263
cyg_hal_plf_serial_dbg_isr(void *__ch_data, int* __ctrlc,
264
                       CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
265
{
266
    int res = 0;
267
    channel_data_t* chan = (channel_data_t*)__ch_data;
268
    cyg_uint32 status;
269
    cyg_uint32 c;
270
    cyg_uint8 ch;
271
    CYGARC_HAL_SAVE_GP();
272
 
273
    *__ctrlc = 0;
274
    HAL_READ_UINT32(chan->base+AT91_DBG_CSR, status);
275
    if ( (status & AT91_DBG_CSR_RXRDY) != 0 ) {
276
 
277
      HAL_READ_UINT32(chan->base+AT91_DBG_RHR, c);
278
      ch = (cyg_uint8)(c & 0xff);
279
      if( cyg_hal_is_break( &ch , 1 ) )
280
        *__ctrlc = 1;
281
 
282
      res = CYG_ISR_HANDLED;
283
    }
284
 
285
    HAL_INTERRUPT_ACKNOWLEDGE(chan->isr_vector);
286
 
287
    CYGARC_HAL_RESTORE_GP();
288
    return res;
289
}
290
 
291
static channel_data_t at91_ser_channels[1] = {
292
    { (cyg_uint8*)AT91_DBG, 1000, CYGNUM_HAL_INTERRUPT_DBG,
293
      CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD}
294
};
295
 
296
static void
297
cyg_hal_plf_serial_init(void)
298
{
299
    hal_virtual_comm_table_t* comm;
300
    int cur;
301
 
302
    cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
303
 
304
    // Init channels
305
    cyg_hal_plf_serial_dbg_init_channel(&at91_ser_channels[0]);
306
 
307
    // Setup procs in the vector table
308
 
309
    // Set channel 0
310
    CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
311
    comm = CYGACC_CALL_IF_CONSOLE_PROCS();
312
    CYGACC_COMM_IF_CH_DATA_SET(*comm, &at91_ser_channels[0]);
313
    CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_dbg_write);
314
    CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_dbg_read);
315
    CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_dbg_putc);
316
    CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_dbg_getc);
317
    CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_dbg_control);
318
    CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_dbg_isr);
319
    CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_dbg_getc_timeout);
320
 
321
    // Restore original console
322
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
323
}
324
 
325
void
326
cyg_hal_plf_comms_init(void)
327
{
328
    static int initialized = 0;
329
 
330
    if (initialized)
331
        return;
332
 
333
    initialized = 1;
334
 
335
    cyg_hal_plf_serial_init();
336
 
337
#ifdef CYGBLD_HAL_ARM_AT91_DCC
338
    cyg_hal_plf_dcc_init(CYGBLD_HAL_ARM_AT91_DCC_CHANNEL);
339
#endif
340
}
341
 
342
void
343
hal_diag_led(int mask)
344
{
345
    hal_at91_set_leds(mask);
346
}
347
 
348
//-----------------------------------------------------------------------------
349
// End of hal_diag_dbg.c

powered by: WebSVN 2.1.0

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