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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [sparclite/] [sleb/] [v2_0/] [src/] [hal_diag.c] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*=============================================================================
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 Red Hat, 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 version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//=============================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):   nickg
44
// Contributors:        nickg
45
// Date:        1998-03-02
46
// Purpose:     HAL diagnostic output
47
// Description: Implementations of HAL diagnostic output support.
48
//
49
//####DESCRIPTIONEND####
50
//
51
//===========================================================================*/
52
 
53
#include <pkgconf/system.h>
54
#include <pkgconf/hal.h>
55
#include <pkgconf/hal_sparclite.h>
56
#include <pkgconf/hal_sparclite_sleb.h>
57
 
58
#include <cyg/infra/cyg_type.h>          // base types
59
 
60
#include <cyg/hal/hal_arch.h>
61
#include <cyg/hal/hal_diag.h>
62
#include <cyg/hal/hal_intr.h>
63
 
64
#include <cyg/hal/hal_cygm.h>
65
 
66
/*---------------------------------------------------------------------------*/
67
 
68
#ifdef CYG_KERNEL_DIAG_GDB
69
 
70
#ifdef CYG_KERNEL_DIAG_GDB_SERIAL_DIRECT // then force $O packets to serial
71
 
72
void hal_diag_init(void)
73
{
74
    // hal_diag_init_serial();
75
}
76
 
77
void hal_diag_write_char_serial( char c )
78
{
79
    HAL_REORDER_BARRIER();
80
    HAL_DIAG_WRITE_CHAR_DIRECT( c );
81
    HAL_REORDER_BARRIER();
82
    HAL_DIAG_WRITE_CHAR_WAIT_FOR_EMPTY();
83
    HAL_REORDER_BARRIER();
84
}
85
 
86
void hal_diag_write_char(char c)
87
{
88
    static char line[100];
89
    static int pos = 0;
90
 
91
    // No need to send CRs
92
    if( c == '\r' ) return;
93
 
94
    line[pos++] = c;
95
 
96
    if( c == '\n' || pos == sizeof(line) )
97
    {
98
        CYG_INTERRUPT_STATE old;
99
 
100
        // Disable interrupts. This prevents GDB trying to interrupt us
101
        // while we are in the middle of sending a packet. The serial
102
        // receive interrupt will be seen when we re-enable interrupts
103
        // later.
104
 
105
        HAL_DISABLE_INTERRUPTS(old);
106
 
107
        while(1)
108
        {
109
            cyg_uint32 status, c1, tries;
110
            static char hex[] = "0123456789ABCDEF";
111
            cyg_uint8 csum = 0;
112
            int i;
113
 
114
            hal_diag_write_char_serial('$');
115
            hal_diag_write_char_serial('O');
116
            csum += 'O';
117
            for( i = 0; i < pos; i++ )
118
            {
119
                char ch = line[i];
120
                char h = hex[(ch>>4)&0xF];
121
                char l = hex[ch&0xF];
122
                hal_diag_write_char_serial(h);
123
                hal_diag_write_char_serial(l);
124
                csum += h;
125
                csum += l;
126
            }
127
            hal_diag_write_char_serial('#');
128
            hal_diag_write_char_serial(hex[(csum>>4)&0xF]);
129
            hal_diag_write_char_serial(hex[csum&0xF]);
130
 
131
            // Wait for the ACK character '+' from GDB here and handle
132
            // receiving a ^C instead.  This is the reason for this clause
133
            // being a loop.
134
            status = 0;
135
            tries = 1000000000;
136
            while ( 0 == (HAL_SPARC_86940_FLAG_RXRDY & status) ) {
137
                if ( 0 == --tries )
138
                    break;
139
                HAL_SPARC_86940_SDTR0_STAT_READ( status );
140
            }
141
            if ( 0 == tries )       // then we broke out after waiting
142
                continue;           // the outer loop, send the packet
143
 
144
            HAL_SPARC_86940_SDTR0_RXDATA_READ( c1 );
145
 
146
            // We must ack the interrupt caused by that read to avoid
147
            // confusing the GDB stub ROM.
148
            HAL_INTERRUPT_ACKNOWLEDGE( CYGNUM_HAL_VECTOR_INTERRUPT_10 );
149
 
150
            if( c1 == '+' )
151
                break;              // a good acknowledge
152
 
153
            if( c1 == 3 ) {
154
                // Ctrl-C: breakpoint.
155
                asm volatile( "ta 2; nop; nop; nop" );
156
                break;
157
            }
158
            // otherwise, loop round again
159
        }
160
 
161
        pos = 0;
162
 
163
        // And re-enable interrupts
164
        HAL_RESTORE_INTERRUPTS(old);
165
 
166
    }
167
}
168
#else // CYG_KERNEL_DIAG_GDB_SERIAL_DIRECT not defined; use CygMon
169
 
170
// All this code provided by MSalter - ta.
171
 
172
struct bsp_comm_procs {
173
    void *ch_data;
174
    void (*__write)(void *ch_data, const char *buf, int len);
175
    int  (*__read)(void *ch_data, char *buf, int len);
176
    void (*__putc)(void *ch_data, char ch);
177
    int  (*__getc)(void *ch_data);
178
    int  (*__control)(void *ch_data, int func, ...);
179
};
180
 
181
// This is pointed to by entry BSP_NOTVEC_BSP_COMM_PROCS:
182
typedef struct {
183
    int  version;       /* version number for future expansion */
184
    void *__ictrl_table;
185
    void *__exc_table;
186
    void *__dbg_vector;
187
    void *__kill_vector;
188
    struct bsp_comm_procs *__console_procs;
189
    struct bsp_comm_procs *__debug_procs;
190
    void *__flush_dcache;
191
    void *__flush_icache;
192
    void *__cpu_data;
193
    void *__board_data;
194
    void *__sysinfo;
195
    int  (*__set_debug_comm)(int __comm_id);
196
    void *__set_console_comm;
197
} bsp_shared_t;
198
 
199
 
200
static int
201
hal_bsp_set_debug_comm(int arg)
202
{
203
    bsp_shared_t *shared;
204
 
205
    shared = (bsp_shared_t *)
206
        (CYGMON_VECTOR_TABLE[ BSP_NOTVEC_BSP_COMM_PROCS ]);
207
 
208
    if (0 != shared->__set_debug_comm) {
209
        return (*(shared->__set_debug_comm))(arg);
210
    }
211
    return 0;
212
}
213
 
214
static int
215
hal_bsp_console_write(const char *p, int len)
216
{
217
    bsp_shared_t *shared;
218
    struct bsp_comm_procs *com;
219
 
220
    shared = (bsp_shared_t *)
221
        (CYGMON_VECTOR_TABLE[ BSP_NOTVEC_BSP_COMM_PROCS ]);
222
 
223
    com = shared->__console_procs;
224
 
225
    if (0 != com) {
226
        com->__write(com->ch_data, p, len);
227
 
228
#if 1
229
        // FIXME: This is a workaround for PR 19926; CygMon does not
230
        // expect to be sharing the line with a serial driver (which
231
        // can be excused :) and so doesn't acknowledge the interrupt.
232
        // In normal circumstances CygMon would handle the resulting
233
        // interrupt and do the right thing.  However, when using the
234
        // serial driver it is handling the interrupts and gets
235
        // mightily confused by these spurious interrupts.
236
        //
237
        // As a workaround, ask CygMon which communication port is
238
        // using for console output. If this is the serial port 
239
        // (comm 0), acknowledge the interrupt.
240
        if ( 0 == hal_bsp_set_debug_comm( -1 ) )
241
            HAL_INTERRUPT_ACKNOWLEDGE( CYGNUM_HAL_VECTOR_INTERRUPT_10 );
242
#endif
243
 
244
        return 1;
245
    }
246
    return 0;
247
}
248
 
249
static void
250
hal_dumb_serial_write(const char *p, int len)
251
{
252
    int i;
253
    for ( i = 0 ; i < len; i++ ) {
254
        HAL_DIAG_WRITE_CHAR_DIRECT( p[ i ] );
255
    }
256
}
257
 
258
 
259
void hal_diag_init(void)
260
{
261
}
262
 
263
void hal_diag_write_char(char c)
264
{
265
    static char line[100];
266
    static int pos = 0;
267
 
268
    // No need to send CRs
269
    if( c == '\r' ) return;
270
 
271
    line[pos++] = c;
272
 
273
    if( c == '\n' || pos == sizeof(line) ) {
274
        CYG_INTERRUPT_STATE old;
275
 
276
        // Disable interrupts. This prevents GDB trying to interrupt us
277
        // while we are in the middle of sending a packet. The serial
278
        // receive interrupt will be seen when we re-enable interrupts
279
        // later.
280
 
281
        HAL_DISABLE_INTERRUPTS(old);
282
 
283
        if ( ! hal_bsp_console_write( line, pos ) )
284
            // then there is no function registered, just spew it out serial
285
            hal_dumb_serial_write( line, pos );
286
 
287
        pos = 0;
288
 
289
        // And re-enable interrupts
290
        HAL_RESTORE_INTERRUPTS(old);
291
 
292
    }
293
}
294
 
295
#endif  // CYG_KERNEL_DIAG_GDB_SERIAL_DIRECT not defined; use CygMon
296
 
297
#else // CYG_KERNEL_DIAG_GDB not defined, so we are going to the serial line
298
      // without GDB encoding - likely to be ROM startup.
299
 
300
/* Address of clock switch */
301
#define CLKSW_ADDR  0x01000003
302
 
303
/* Address of SW1 */
304
#define SW1_ADDR  0x02000003
305
 
306
void hal_diag_init(void)
307
{
308
    cyg_uint32 clk, tval;
309
 
310
    // first set the baud rate
311
 
312
    clk = *(unsigned char *)CLKSW_ADDR;
313
    if (clk & 0x80)
314
        clk = 10;
315
 
316
    clk = (clk & 0x3f) * 1000000;  /* in MHz */
317
 
318
    tval = clk / 19200;
319
    tval /= 32;
320
    tval -= 1;
321
 
322
    HAL_SPARC_86940_TCR3_WRITE(
323
        HAL_SPARC_86940_TCR_CE          |
324
        HAL_SPARC_86940_TCR_CLKINT      |
325
        HAL_SPARC_86940_TCR_OUTC3       |
326
        HAL_SPARC_86940_TCR_SQWAVE           );
327
 
328
    HAL_SPARC_86940_RELOAD3_WRITE( tval);
329
 
330
#define DELAY(x) \
331
    CYG_MACRO_START int i; for (i = 0; i < x; i++); CYG_MACRO_END
332
 
333
    HAL_SPARC_86940_SDTR0_CTRL_WRITE( 0 );
334
    DELAY(100);
335
    HAL_SPARC_86940_SDTR0_CTRL_WRITE( 0 );
336
    DELAY(100);
337
    HAL_SPARC_86940_SDTR0_CTRL_WRITE( 0 );
338
    DELAY(100);
339
 
340
    HAL_SPARC_86940_SDTR0_CTRL_WRITE( HAL_SPARC_86940_SER_CMD_IRST );
341
    DELAY(100);
342
 
343
    /* first write after reset is to mode register */
344
    HAL_SPARC_86940_SDTR0_CTRL_WRITE( HAL_SPARC_86940_SER_DIV16_CLK     |
345
                                      HAL_SPARC_86940_SER_8BITS         |
346
                                      HAL_SPARC_86940_SER_NO_PARITY     |
347
                                      HAL_SPARC_86940_SER_STOP1           );
348
    DELAY(100);
349
 
350
    /* subsequent writes are to command register */
351
    HAL_SPARC_86940_SDTR0_CTRL_WRITE( HAL_SPARC_86940_SER_CMD_RTS       |
352
                                      HAL_SPARC_86940_SER_CMD_DTR       |
353
                                      HAL_SPARC_86940_SER_CMD_EFR       |
354
                                      HAL_SPARC_86940_SER_CMD_RXEN      |
355
                                      HAL_SPARC_86940_SER_CMD_TXEN        );
356
    DELAY(100);
357
}
358
 
359
 
360
 
361
 
362
 
363
#endif // CYG_KERNEL_DIAG_GDB
364
 
365
/*---------------------------------------------------------------------------*/
366
/* 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.