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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [cygmon/] [v2_0/] [misc/] [bsp/] [common/] [bsp.c] - Blame information for rev 361

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      bsp.c
4
//
5
//      General BSP support.
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):    
44
// Contributors: gthomas
45
// Date:         1999-10-20
46
// Purpose:      General BSP support. 
47
// Description:  
48
//               
49
//
50
//####DESCRIPTIONEND####
51
//
52
//=========================================================================
53
 
54
 
55
#include <stdlib.h>
56
#include <bsp/cpu.h>
57
#include <bsp/bsp.h>
58
#include "bsp_if.h"
59
#include "gdb.h"
60
 
61
#ifndef DEBUG_BSP_INIT
62
#define DEBUG_BSP_INIT 0
63
#endif
64
 
65
struct bsp_comm_channel *_bsp_net_channel = NULL;
66
 
67
/*
68
 *  This is the array of pointers to interrupt controller descriptors.
69
 */
70
static struct bsp_irq_controller *_bsp_ictrl_table[BSP_MAX_IRQ_CONTROLLERS];
71
 
72
/*
73
 *  This is the array of second-level exception vectors.
74
 */
75
static bsp_vec_t *_bsp_exc_table[BSP_MAX_EXCEPTIONS];
76
 
77
 
78
/*
79
 * Debug (default exception) handler vector.
80
 */
81
bsp_handler_t _bsp_dbg_vector;
82
 
83
 
84
static bsp_shared_t __bsp_shared = {
85
    BSP_SHARED_DATA_VERSION,                                  /* version         */
86
    (const struct bsp_irq_controller **)&_bsp_ictrl_table[0], /* __ictrl_table   */
87
    &_bsp_exc_table[0],                                       /* __exc_table     */
88
    &_bsp_dbg_vector,                                         /* __dbg_vector    */
89
    (bsp_handler_t)0,                                         /* __kill_vector   */
90
    (struct bsp_comm_procs *)NULL,                            /* __console_procs */
91
    (struct bsp_comm_procs *)NULL,                            /* __debug_procs   */
92
    (void (*)(void *, int      ))NULL,                        /* __flush_dcache  */
93
    (void (*)(void *, int      ))NULL,                        /* __flush_icache  */
94
    (void (*)(void             ))NULL,                        /* __reset         */
95
    (void*)NULL,                                              /* __cpu_data      */
96
    (void*)NULL                                               /* __board_data    */
97
};
98
 
99
 
100
static void
101
default_cache_proc(void *p, int nbytes)
102
{
103
    /* do nothing */
104
}
105
 
106
 
107
static void
108
default_reset_proc(void)
109
{
110
    /* do nothing */
111
}
112
 
113
 
114
static int
115
find_comm_id(struct bsp_comm_procs *procs)
116
{
117
    int i;
118
 
119
    for (i = 0; i < _bsp_num_comms; i++)
120
        if (&_bsp_comm_list[i].procs == procs)
121
            return i;
122
 
123
    if (procs == &_bsp_net_channel->procs)
124
        return _bsp_num_comms;
125
 
126
    return -1;
127
}
128
 
129
 
130
/*
131
 * Set or get active debug channel.
132
 * Returns -1 if unsucessful.
133
 * If the passed in comm id is -1, then the id of the current channel
134
 * is returned.
135
 */
136
static int
137
set_debug_comm(int id)
138
{
139
    struct bsp_comm_channel *chan;
140
    struct bsp_comm_procs *procs;
141
    int  current_chan = find_comm_id(bsp_shared_data->__debug_procs);
142
 
143
    if (id < 0)
144
        return current_chan;
145
 
146
    if (id > _bsp_num_comms)
147
        return -1;
148
 
149
    if (id == _bsp_num_comms && _bsp_net_channel == NULL)
150
        return -1;
151
 
152
    if (id == current_chan)
153
        return 0;
154
 
155
    /* Remove existing channel */
156
    if ((procs = bsp_shared_data->__debug_procs) != NULL)
157
        (*procs->__control)(procs->ch_data, COMMCTL_REMOVE_DBG_ISR);
158
 
159
    /* Install new channel */
160
    if (id == _bsp_num_comms)
161
        chan = _bsp_net_channel;
162
    else
163
        chan = &_bsp_comm_list[id];
164
    bsp_shared_data->__debug_procs = &chan->procs;
165
    (*chan->procs.__control)(chan->procs.ch_data, COMMCTL_INSTALL_DBG_ISR);
166
 
167
    return 0;
168
}
169
 
170
 
171
/*
172
 * Set or get active console channel.
173
 * Returns -1 if unsucessful.
174
 * If the passed in comm id is -1, then the id of the current channel
175
 * is returned.
176
 */
177
static int
178
set_console_comm(int id)
179
{
180
    int  current_chan = find_comm_id(bsp_shared_data->__console_procs);
181
 
182
    if (id < 0)
183
        return current_chan;
184
 
185
    if (id > _bsp_num_comms)
186
        return -1;
187
 
188
    if (id == _bsp_num_comms && _bsp_net_channel == NULL)
189
        return -1;
190
 
191
    if (id == current_chan)
192
        return 0;
193
 
194
    /*
195
     * Install new channel. If its the same as the debug channel,
196
     * just clear the __console_procs and the bsp_console_*
197
     * interface functions will take care of the rest.
198
     */
199
    if (id == _bsp_num_comms)
200
        bsp_shared_data->__console_procs = &_bsp_net_channel->procs;
201
    else
202
        bsp_shared_data->__console_procs = &_bsp_comm_list[id].procs;
203
 
204
    if (bsp_shared_data->__console_procs == bsp_shared_data->__debug_procs)
205
        bsp_shared_data->__console_procs = NULL;
206
 
207
    return 0;
208
}
209
 
210
 
211
/*
212
 * Set or get the current baud rate of a serial comm channel.
213
 * Returns -1 on if unsuccessful.
214
 * If the given baud is -1, then the current baudrate is returned.
215
 */
216
int
217
set_serial_baud(int id, int baud)
218
{
219
    struct bsp_comm_channel *chan;
220
 
221
    if (id < 0 || id >= _bsp_num_comms)
222
        return -1;
223
 
224
    chan = &_bsp_comm_list[id];
225
 
226
    if (chan->info.kind != BSP_COMM_SERIAL)
227
        return -1;
228
 
229
    if (baud == -1)
230
        return (*chan->procs.__control)(chan->procs.ch_data,
231
                                        COMMCTL_GETBAUD);
232
 
233
    return (*chan->procs.__control)(chan->procs.ch_data,
234
                                    COMMCTL_SETBAUD, baud);
235
}
236
 
237
/*
238
 *  Final initialization before calling main.
239
 */
240
void
241
_bsp_init(void)
242
{
243
    struct bsp_comm_procs *com;
244
    extern void __init_irq_controllers(void);
245
 
246
    bsp_shared_data = &__bsp_shared;
247
    _bsp_dbg_vector = (bsp_handler_t)_bsp_gdb_handler;
248
    bsp_shared_data->__dbg_data = &_bsp_gdb_data;
249
 
250
    bsp_shared_data->__flush_dcache = default_cache_proc;
251
    bsp_shared_data->__flush_icache = default_cache_proc;
252
 
253
    bsp_shared_data->__reset = default_reset_proc;
254
 
255
    /*
256
     * General BSP information access.
257
     */
258
    bsp_shared_data->__sysinfo = _bsp_sysinfo;
259
 
260
    /*
261
     * Setup comm port handlers.
262
     */
263
    bsp_shared_data->__set_debug_comm = set_debug_comm;
264
    bsp_shared_data->__set_console_comm = set_console_comm;
265
    bsp_shared_data->__set_serial_baud = set_serial_baud;
266
 
267
    /*
268
     *  Very first thing is to initialize comm channels so
269
     *  we can have debug printfs working. None of this
270
     *  must rely on interrupts until interrupt controllers
271
     *  are initialized below.
272
     */
273
    _bsp_init_board_comm();
274
 
275
    /*
276
     * Assume first comm channel is the default.
277
     */
278
    bsp_shared_data->__debug_procs = &_bsp_comm_list[0].procs;
279
 
280
    /*
281
     * By default, console i/o goes through the debug channel.
282
     * We indicate this by making the console i/o procs
283
     * pointer NULL.
284
     */
285
    bsp_shared_data->__console_procs = NULL;
286
 
287
    /*
288
     * Install interrupt controllers.
289
     */
290
#if DEBUG_BSP_INIT
291
    bsp_printf("Installing interrupt controllers...\n");
292
#endif
293
 
294
    _bsp_install_cpu_irq_controllers();
295
    _bsp_install_board_irq_controllers();
296
 
297
#if DEBUG_BSP_INIT
298
    bsp_printf("Done installing interrupt controllers.\n");
299
    bsp_printf("Initializing interrupt controllers...\n");
300
#endif
301
    /*
302
     *  Actually run the init routines for all installed
303
     *  interrupt controllers.
304
     */
305
    __init_irq_controllers();
306
 
307
#if DEBUG_BSP_INIT
308
    bsp_printf("Done initializing interrupt controllers.\n");
309
    bsp_printf("CPU-specific initialization...\n");
310
#endif
311
 
312
    /*
313
     *  Final architecture specific initialization.
314
     */
315
    _bsp_cpu_init();
316
 
317
#if DEBUG_BSP_INIT
318
    bsp_printf("Done w/ CPU-specific initialization.\n");
319
    bsp_printf("Board specific initialization...\n");
320
#endif
321
    /*
322
     *  Final board specific initialization.
323
     */
324
    _bsp_board_init();
325
 
326
#if DEBUG_BSP_INIT
327
    bsp_printf("Done w/ board specific initialization.\n");
328
#endif
329
 
330
    /*
331
     * Now we can install the debug interrupt handler on the debug channel.
332
     */
333
    com = bsp_shared_data->__debug_procs;
334
    (*com->__control)(com->ch_data, COMMCTL_INSTALL_DBG_ISR);
335
 
336
 
337
    if (_bsp_net_channel != NULL) {
338
        set_debug_comm(_bsp_num_comms);
339
        set_console_comm(0);
340
    }
341
}

powered by: WebSVN 2.1.0

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