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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [m68k/] [mcf52xx/] [var/] [current/] [src/] [hal_diag.c] - Blame information for rev 856

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

Line No. Rev Author Line
1 786 skrzyp
/*=============================================================================
2
//
3
//      hal_diag.c
4
//
5
//      ColdFire MCFxxxx HAL diagnostics support
6
//
7
//=============================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 2003, 2004, 2006, 2007, 2008 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):   bartv
43
// Date:        2003-06-04
44
//
45
//####DESCRIPTIONEND####
46
//===========================================================================*/
47
 
48
#include <pkgconf/system.h>
49
#include <pkgconf/hal.h>
50
#include <pkgconf/hal_m68k_mcfxxxx.h>
51
#ifdef CYGPKG_REDBOOT
52
# include <pkgconf/redboot.h>
53
#endif
54
#include CYGBLD_HAL_PLATFORM_H
55
 
56
#include <cyg/infra/cyg_type.h>         // base types
57
#include <cyg/hal/hal_arch.h>
58
#include <cyg/hal/hal_intr.h>
59
#include <cyg/hal/hal_io.h>
60
#include <cyg/hal/hal_if.h>
61
#include <cyg/hal/hal_misc.h>
62
#include <cyg/hal/hal_diag.h>
63
#include <cyg/hal/drv_api.h>
64
 
65
// There are two main possibilities:
66
// 1) the platform uses the standard MCFxxxx diagnostics support, by
67
//    enabling CYGINT_HAL_M68K_MCFxxxx_DIAGNOSTICS_USE_DEFAULT, and
68
//    the user has selected an available uart.
69
// 2) or the platform may provide its own diagnostics facilities.
70
 
71
#if defined(CYGINT_HAL_M68K_MCFxxxx_DIAGNOSTICS_USE_DEFAULT)
72
 
73
// Output goes via one of the UARTs. hal_diag.h will have provided
74
// _HAL_MCFxxxx_DIAG_UART_BASE_ and _HAL_MCFxxxx_DIAG_UART_ISRVEC_.
75
// Optionally the platform HAL can provide an extra INIT macro.
76
 
77
void
78
hal_mcfxxxx_diag_uart_init(cyg_uint8* base, cyg_uint32 baud)
79
{
80
#if defined(CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_COMMS) || defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
81
    static int  initialized;
82
    if (initialized) {
83
        return;
84
    }
85
    initialized = 1;
86
#endif
87
 
88
#ifdef HAL_MCFxxxx_UART_DIAG_PLATFORM_INIT    
89
    HAL_MCFxxxx_UART_DIAG_PLATFORM_INIT();
90
#endif
91
 
92
    // Various resets to get the UART in a known good state
93
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UCR, HAL_MCFxxxx_UARTx_UCR_MISC_RMRP);
94
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UCR, HAL_MCFxxxx_UARTx_UCR_MISC_RR);
95
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UCR, HAL_MCFxxxx_UARTx_UCR_MISC_RT);
96
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UCR, HAL_MCFxxxx_UARTx_UCR_MISC_RES);
97
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UCR, HAL_MCFxxxx_UARTx_UCR_MISC_RBCI);
98
 
99
    // Assume that this code will only run during system startup and with
100
    // interrupts disabled, so that imr1 and imr2 can be poked in succession.
101
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UMR, HAL_MCFxxxx_UARTx_UMR1_PM_NO     | HAL_MCFxxxx_UARTx_UMR1_BC_8);
102
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UMR, HAL_MCFxxxx_UARTx_UMR2_CM_NORMAL | HAL_MCFxxxx_UARTx_UMR2_SB_1);
103
 
104
    // Assert RTS, just in case the other side is interested
105
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UOP1, HAL_MCFxxxx_UARTx_UOP_RTS);
106
 
107
    // No hardware flow control based on fifo contents, no interrupts for change-of-state
108
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UACR, 0);
109
 
110
    // The IMR is write-only, so it is going to be difficult to set or clear just the
111
    // rxrdy bit. Instead leave the serial interrupt enabled here but mask/unmask it
112
    // inside the interrupt controller.
113
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UIMR, HAL_MCFxxxx_UARTx_UIMR_RXRDY);
114
 
115
    // Baud rate. Always use the internal prescaled CLKIN. The baud rate is
116
    // determined by the platform.
117
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UCSR, HAL_MCFxxxx_UARTx_UCSR_RCS_CLKIN | HAL_MCFxxxx_UARTx_UCSR_TCS_CLKIN);
118
    HAL_MCFxxxx_UARTx_SET_BAUD(base, baud);
119
 
120
    // Enable both RX and TX
121
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UCR, HAL_MCFxxxx_UARTx_UCR_TC_TE | HAL_MCFxxxx_UARTx_UCR_RC_RE);
122
}
123
 
124
void
125
hal_mcfxxxx_diag_uart_putc(void* channel_data, char c)
126
{
127
    cyg_uint8*  base = (cyg_uint8*)channel_data;
128
    cyg_uint8   usr;
129
 
130
    do {
131
        HAL_READ_UINT8(base + HAL_MCFxxxx_UARTx_USR, usr);
132
    } while (!(usr & HAL_MCFxxxx_UARTx_USR_TXRDY) );
133
    HAL_WRITE_UINT8(base + HAL_MCFxxxx_UARTx_UTB, c);
134
}
135
 
136
cyg_uint8
137
hal_mcfxxxx_diag_uart_getc(void* channel_data)
138
{
139
    cyg_uint8*  base = (cyg_uint8*)channel_data;
140
    cyg_uint8   usr, data;
141
    do {
142
        HAL_READ_UINT8(base + HAL_MCFxxxx_UARTx_USR, usr);
143
    } while (!(usr & HAL_MCFxxxx_UARTx_USR_RXRDY));
144
    HAL_READ_UINT8(base + HAL_MCFxxxx_UARTx_URB, data);
145
    return data;
146
}
147
 
148
// Additional routines needed in virtual vector configurations.
149
# if defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG)
150
 
151
// State manipulated by the _control() function. Support for dynamic
152
// baud rates is optional. Some platforms may choose to provide this
153
// by implementing CYGSEM_REDBOOT_VARIABLE_BAUD_RATE
154
static int          msec_timeout    = 1;
155
static int          irq_enabled     = 0;
156
#  ifdef CYGSEM_REDBOOT_VARIABLE_BAUD_RATE
157
static cyg_uint32   baud_rate       = _HAL_MCFxxxx_DIAG_UART_BAUD_;
158
#  endif
159
 
160
static void
161
hal_mcfxxxx_diag_uart_write(void* channel_data, const cyg_uint8* buf, cyg_uint32 len)
162
{
163
    while (len-- > 0) {
164
        hal_mcfxxxx_diag_uart_putc(channel_data, *buf++);
165
    }
166
}
167
 
168
static void
169
hal_mcfxxxx_diag_uart_read(void* channel_data, cyg_uint8* buf, cyg_uint32 len)
170
{
171
    while (len-- > 0) {
172
        *buf++ = hal_mcfxxxx_diag_uart_getc(channel_data);
173
    }
174
}
175
 
176
static cyg_bool
177
hal_mcfxxxx_diag_uart_getc_timeout(void* channel_data, cyg_uint8* ch)
178
{
179
    cyg_uint8*  base = (cyg_uint8*)channel_data;
180
    cyg_uint8   usr;
181
    cyg_uint8   data;
182
    int         delay_count = msec_timeout * 10;
183
 
184
    while (delay_count-- > 0) {
185
        HAL_READ_UINT8(base + HAL_MCFxxxx_UARTx_USR, usr);
186
        if (usr & HAL_MCFxxxx_UARTx_USR_RXRDY) {
187
            HAL_READ_UINT8(base + HAL_MCFxxxx_UARTx_URB, data);
188
            *ch = data;
189
            return 1;
190
        }
191
        HAL_DELAY_US(100);
192
    }
193
    return 0;
194
}
195
 
196
static int
197
hal_mcfxxxx_diag_uart_isr(void* channel_data, int* ctrl_c, CYG_ADDRWORD isr_vector, CYG_ADDRWORD isr_data)
198
{
199
    cyg_uint8*  base = (cyg_uint8*)channel_data;
200
    cyg_uint8   usr;
201
    cyg_uint8   data;
202
 
203
    *ctrl_c = 0;
204
    HAL_READ_UINT8(base + HAL_MCFxxxx_UARTx_USR, usr);
205
    if (usr & HAL_MCFxxxx_UARTx_USR_RXRDY) {
206
        HAL_READ_UINT8(base + HAL_MCFxxxx_UARTx_URB, data);
207
        if (cyg_hal_is_break((char*)&data, 1)) {
208
            *ctrl_c = 1;
209
        }
210
    }
211
    return CYG_ISR_HANDLED;
212
}
213
 
214
static int
215
hal_mcfxxxx_diag_uart_control(void* channel_data, __comm_control_cmd_t func, ...)
216
{
217
    int         result  = -1;
218
    va_list     args;
219
 
220
    va_start(args, func);
221
    switch(func) {
222
      case __COMMCTL_IRQ_ENABLE:
223
        result      = 0;
224
        irq_enabled = 1;
225
        HAL_INTERRUPT_UNMASK(_HAL_MCFxxxx_DIAG_UART_ISRVEC_);
226
        break;
227
      case __COMMCTL_IRQ_DISABLE:
228
        result = irq_enabled;
229
        irq_enabled = 0;
230
        HAL_INTERRUPT_MASK(_HAL_MCFxxxx_DIAG_UART_ISRVEC_);
231
        break;
232
      case __COMMCTL_DBG_ISR_VECTOR:
233
        result = _HAL_MCFxxxx_DIAG_UART_ISRVEC_;
234
        break;
235
      case __COMMCTL_SET_TIMEOUT:
236
        result = msec_timeout;
237
        msec_timeout = va_arg(args,cyg_uint32);
238
        break;
239
#ifdef CYGSEM_REDBOOT_VARIABLE_BAUD_RATE
240
      case __COMMCTL_GETBAUD:
241
        result = baud_rate;
242
        break;
243
      case __COMMCTL_SETBAUD:
244
        baud_rate = va_arg(args, cyg_uint32);
245
        HAL_MCFxxxx_UARTx_SET_BAUD(_HAL_MCFxxxx_DIAG_UART_BASE_, baud_rate);
246
        result = 0;
247
        break;
248
#endif        
249
      default:
250
        break;
251
    }
252
 
253
    CYG_UNUSED_PARAM(void*, channel_data);
254
    return result;
255
}
256
 
257
void
258
cyg_hal_plf_comms_init(void)
259
{
260
    hal_virtual_comm_table_t*   comm;
261
    int                         cur;
262
 
263
    hal_mcfxxxx_diag_uart_init((cyg_uint8*)_HAL_MCFxxxx_DIAG_UART_BASE_, CYGNUM_HAL_M68K_MCFxxxx_DIAGNOSTICS_BAUD);
264
    // For the diag channel we may want interrupts without explicitly installing
265
    // an interrupt handler, so the priority has to be set manually.
266
    HAL_INTERRUPT_SET_LEVEL(_HAL_MCFxxxx_DIAG_UART_ISRVEC_, CYGNUM_HAL_M68K_MCFxxxx_DIAGNOSTICS_ISRPRI);
267
 
268
    cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
269
 
270
    CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
271
    comm    = CYGACC_CALL_IF_CONSOLE_PROCS();
272
    CYGACC_COMM_IF_CH_DATA_SET(*comm, (void*)(_HAL_MCFxxxx_DIAG_UART_BASE_));
273
    CYGACC_COMM_IF_WRITE_SET(*comm, hal_mcfxxxx_diag_uart_write);
274
    CYGACC_COMM_IF_READ_SET(*comm, hal_mcfxxxx_diag_uart_read);
275
    CYGACC_COMM_IF_PUTC_SET(*comm, hal_mcfxxxx_diag_uart_putc);
276
    CYGACC_COMM_IF_GETC_SET(*comm, hal_mcfxxxx_diag_uart_getc);
277
    CYGACC_COMM_IF_CONTROL_SET(*comm, hal_mcfxxxx_diag_uart_control);
278
    CYGACC_COMM_IF_DBG_ISR_SET(*comm, hal_mcfxxxx_diag_uart_isr);
279
    CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, hal_mcfxxxx_diag_uart_getc_timeout);
280
 
281
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
282
}
283
# endif // CYGSEM_HAL_VIRTUAL_VECTOR_DIAG
284
 
285
#else
286
// The platform HAL must provide its own diagnostics routines.
287
#endif
288
 
289
/* 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.