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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [gps4020/] [current/] [src/] [hal_diag.c] - Blame information for rev 791

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
//      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, 2003 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):   nickg, gthomas
43
// Contributors:nickg, gthomas
44
// Date:        1998-03-02
45
// Purpose:     HAL diagnostic output
46
// Description: Implementations of HAL diagnostic output support.
47
//
48
//####DESCRIPTIONEND####
49
//
50
//===========================================================================*/
51
 
52
#include <pkgconf/hal.h>
53
 
54
#include <cyg/infra/cyg_type.h>         // base types
55
#include <cyg/infra/cyg_trac.h>         // tracing macros
56
#include <cyg/infra/cyg_ass.h>          // assertion macros
57
 
58
#include <cyg/hal/hal_arch.h>           // SAVE/RESTORE GP macros
59
#include <cyg/hal/hal_io.h>             // IO macros
60
#include <cyg/hal/hal_if.h>             // interface API
61
#include <cyg/hal/hal_intr.h>           // HAL_ENABLE/MASK/UNMASK_INTERRUPTS
62
#include <cyg/hal/hal_misc.h>           // Helper functions
63
#include <cyg/hal/drv_api.h>            // CYG_ISR_HANDLED
64
 
65
#include <cyg/hal/gps4020.h>
66
 
67
//-----------------------------------------------------------------------------
68
typedef struct {
69
    volatile struct _gps4020_uart *base;
70
    cyg_int32             msec_timeout;
71
    int                   isr_vector;
72
    int                   int_state;
73
} channel_data_t;
74
 
75
static channel_data_t serial_channels[] = {
76
    { (volatile struct _gps4020_uart *)GPS4020_UART1, 1000, CYGNUM_HAL_INTERRUPT_UART1_RX, 0 },
77
};
78
 
79
//-----------------------------------------------------------------------------
80
 
81
static void
82
cyg_hal_plf_serial_init_channel(void* __ch_data)
83
{
84
    volatile struct _gps4020_uart *uart = ((channel_data_t*)__ch_data)->base;
85
    uart->mode = SMR_STOP_1 | SMR_PARITY_OFF | SMR_LENGTH_8;
86
    uart->baud = 0x15;  // FIXME - Magic for 57600
87
    uart->modem_control = SMR_DTR | SMR_RTS;
88
    uart->control = SCR_TEN | SCR_REN;
89
}
90
 
91
void
92
cyg_hal_plf_serial_putc(void *__ch_data, char c)
93
{
94
    volatile struct _gps4020_uart *uart = ((channel_data_t*)__ch_data)->base;
95
    // Wait for space for character
96
    do {
97
    } while ((uart->status & SSR_TxEmpty) == 0);
98
    uart->TxRx = c;
99
}
100
 
101
static cyg_bool
102
cyg_hal_plf_serial_getc_nonblock(void *__ch_data, cyg_uint8 *ch)
103
{
104
    volatile struct _gps4020_uart *uart = ((channel_data_t*)__ch_data)->base;
105
    if ((uart->status & SSR_RxFull) == 0) {
106
        return false;
107
    }
108
    *ch = uart->TxRx;
109
    return true;
110
}
111
 
112
cyg_uint8
113
cyg_hal_plf_serial_getc(void* __ch_data)
114
{
115
    cyg_uint8 ch;
116
 
117
    while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
118
 
119
    return ch;
120
}
121
 
122
static void
123
cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
124
                         cyg_uint32 __len)
125
{
126
    while(__len-- > 0)
127
        cyg_hal_plf_serial_putc(__ch_data, *__buf++);
128
}
129
 
130
static void
131
cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
132
{
133
    while(__len-- > 0)
134
        *__buf++ = cyg_hal_plf_serial_getc(__ch_data);
135
}
136
 
137
cyg_bool
138
cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
139
{
140
    int delay_count;
141
    channel_data_t* chan = (channel_data_t*)__ch_data;
142
    cyg_bool res;
143
 
144
    delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
145
 
146
    for(;;) {
147
        res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
148
        if (res || 0 == delay_count--)
149
            break;
150
        CYGACC_CALL_IF_DELAY_US(100);
151
    }
152
 
153
    return res;
154
}
155
 
156
static int
157
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
158
{
159
    channel_data_t* chan = (channel_data_t*)__ch_data;
160
    volatile struct _gps4020_uart *uart = ((channel_data_t*)__ch_data)->base;
161
    int ret = 0;
162
 
163
    switch (__func) {
164
    case __COMMCTL_IRQ_ENABLE:
165
        chan->int_state = 1;
166
        uart->control |= SCR_RIE;
167
        HAL_INTERRUPT_UNMASK(chan->isr_vector);
168
        break;
169
    case __COMMCTL_IRQ_DISABLE:
170
        ret = chan->int_state;
171
        chan->int_state = 0;
172
        uart->control &= ~SCR_RIE;
173
        HAL_INTERRUPT_MASK(chan->isr_vector);
174
        break;
175
    case __COMMCTL_DBG_ISR_VECTOR:
176
        ret = chan->isr_vector;
177
        break;
178
    case __COMMCTL_SET_TIMEOUT:
179
    {
180
        va_list ap;
181
 
182
        va_start(ap, __func);
183
 
184
        ret = chan->msec_timeout;
185
        chan->msec_timeout = va_arg(ap, cyg_uint32);
186
 
187
        va_end(ap);
188
    }
189
    default:
190
        break;
191
    }
192
    return ret;
193
}
194
 
195
static int
196
cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
197
                       CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
198
{
199
    int res = 0;
200
    channel_data_t* chan = (channel_data_t*)__ch_data;
201
    volatile struct _gps4020_uart *uart = ((channel_data_t*)__ch_data)->base;
202
    char c;
203
 
204
    cyg_drv_interrupt_acknowledge(chan->isr_vector);
205
    *__ctrlc = 0;
206
    if ((uart->status & SSR_RxFull) != 0) {
207
        c = uart->TxRx;
208
        if (cyg_hal_is_break(&c, 1))
209
            *__ctrlc = 1;
210
        res = CYG_ISR_HANDLED;
211
    }
212
    return res;
213
}
214
 
215
static void
216
cyg_hal_plf_serial_init(void)
217
{
218
    hal_virtual_comm_table_t* comm;
219
    int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
220
 
221
    // Init channel
222
    cyg_hal_plf_serial_init_channel(&serial_channels[0]);
223
 
224
    // Setup procs in the vector table
225
 
226
    // Set channel 0
227
    CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
228
    comm = CYGACC_CALL_IF_CONSOLE_PROCS();
229
    CYGACC_COMM_IF_CH_DATA_SET(*comm, &serial_channels[0]);
230
    CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
231
    CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
232
    CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
233
    CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
234
    CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
235
    CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
236
    CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
237
 
238
    // Restore original console
239
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
240
}
241
 
242
void
243
cyg_hal_plf_comms_init(void)
244
{
245
    static int initialized = 0;
246
 
247
    if (initialized)
248
        return;
249
 
250
    initialized = 1;
251
 
252
    cyg_hal_plf_serial_init();
253
}

powered by: WebSVN 2.1.0

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