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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [xscale/] [iq80310/] [v2_0/] [src/] [diag/] [io_utils.c] - Blame information for rev 594

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

Line No. Rev Author Line
1 27 unneback
//=============================================================================
2
//
3
//      io_utils.c - Cyclone Diagnostics
4
//
5
//=============================================================================
6
//####ECOSGPLCOPYRIGHTBEGIN####
7
// -------------------------------------------
8
// This file is part of eCos, the Embedded Configurable Operating System.
9
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
10
//
11
// eCos is free software; you can redistribute it and/or modify it under
12
// the terms of the GNU General Public License as published by the Free
13
// Software Foundation; either version 2 or (at your option) any later version.
14
//
15
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
16
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18
// for more details.
19
//
20
// You should have received a copy of the GNU General Public License along
21
// with eCos; if not, write to the Free Software Foundation, Inc.,
22
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23
//
24
// As a special exception, if other files instantiate templates or use macros
25
// or inline functions from this file, or you compile this file and link it
26
// with other works to produce a work based on this file, this file does not
27
// by itself cause the resulting work to be covered by the GNU General Public
28
// License. However the source code for this file must still be made available
29
// in accordance with section (3) of the GNU General Public License.
30
//
31
// This exception does not invalidate any other reasons why a work based on
32
// this file might be covered by the GNU General Public License.
33
//
34
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
35
// at http://sources.redhat.com/ecos/ecos-license/
36
// -------------------------------------------
37
//####ECOSGPLCOPYRIGHTEND####
38
//=============================================================================
39
//#####DESCRIPTIONBEGIN####
40
//
41
// Author(s):   Scott Coulter, Jeff Frazier, Eric Breeden
42
// Contributors:
43
// Date:        2001-01-25
44
// Purpose:     
45
// Description: 
46
//
47
//####DESCRIPTIONEND####
48
//
49
//===========================================================================*/
50
 
51
/*
52
 * i/o routines for tests.  Greg Ames, 9/17/90.
53
 *
54
 * Version: @(#)test_io.c       1.2 8/26/93
55
 */
56
#include <redboot.h>
57
#include <cyg/infra/diag.h>
58
#define printf diag_printf
59
 
60
 
61
#define TRUE    1
62
#define FALSE   0
63
 
64
 
65
#define ASCII_TO_DEC 48
66
void atod(char a, int* b)
67
{
68
    *b = (int)(a - ASCII_TO_DEC);
69
}
70
 
71
char xgetchar(void)
72
{
73
    hal_virtual_comm_table_t* __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
74
 
75
    if (__chan == NULL)
76
        __chan = CYGACC_CALL_IF_DEBUG_PROCS();
77
 
78
    return CYGACC_COMM_IF_GETC(*__chan);
79
}
80
 
81
int xgetchar_timeout(char *ch, int msec)
82
{
83
    bool res;
84
    int old_to;
85
    hal_virtual_comm_table_t *__chan;
86
 
87
    __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
88
    if (__chan == NULL)
89
        __chan = CYGACC_CALL_IF_DEBUG_PROCS();
90
 
91
    old_to = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_SET_TIMEOUT, msec);
92
    res = CYGACC_COMM_IF_GETC_TIMEOUT(*__chan, ch);
93
    CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_SET_TIMEOUT, old_to);
94
 
95
    return res;
96
}
97
 
98
/*
99
 * naive implementation of "gets"
100
 * (big difference from fgets == strips newline character)
101
 */
102
char* sgets(char *s)
103
{
104
    char *retval = s;
105
    char ch;
106
 
107
    while ((ch = (char)xgetchar())) {
108
        if (ch == 0x0d) { /* user typed enter */
109
            printf("\n");
110
            break;
111
        }
112
        if (ch == 0x08) { /* user typed backspace */
113
            printf ("\b");
114
            printf (" ");
115
            printf ("\b");
116
            s--;
117
        } else { /* user typed another character */
118
            printf("%c", ch);
119
            *s++ = ch;
120
        }
121
    }
122
 
123
    *s = '\0';
124
    return retval;
125
}
126
 
127
 
128
/* Returns true if theChar is a valid hex digit, false if not */
129
char ishex(char theChar)
130
{
131
    switch(theChar) {
132
    case '0':
133
    case '1':
134
    case '2':
135
    case '3':
136
    case '4':
137
    case '5':
138
    case '6':
139
    case '7':
140
    case '8':
141
    case '9':
142
    case 'A':
143
    case 'a':
144
    case 'B':
145
    case 'b':
146
    case 'C':
147
    case 'c':
148
    case 'D':
149
    case 'd':
150
    case 'E':
151
    case 'e':
152
    case 'F':
153
    case 'f':
154
        return 1;
155
    default:
156
        return 0;
157
    }
158
}
159
 
160
 
161
/* Returns true if theChar is a valid decimal digit, false if not */
162
char isdec(char theChar)
163
{
164
    switch(theChar) {
165
    case '0':
166
    case '1':
167
    case '2':
168
    case '3':
169
    case '4':
170
    case '5':
171
    case '6':
172
    case '7':
173
    case '8':
174
    case '9':
175
        return 1;
176
    default:
177
        return 0;
178
    }
179
}
180
 
181
/* Convert ascii code of hex digit to number (0-15) */
182
char hex2dec(char hex)
183
{
184
    if ((hex >= '0') && (hex <= '9'))
185
        return hex - '0';
186
    else if ((hex >= 'a') && (hex <= 'f'))
187
        return hex - 'a' + 10;
188
    else
189
        return hex - 'A' + 10;
190
}
191
 
192
 
193
/* Convert number (0-15) to ascii code of hex digit */
194
char dec2hex(char dec)
195
{
196
    return (dec <= 9) ? (dec + '0') : (dec - 10 + 'A');
197
}
198
 
199
 
200
/* Output an 8 bit number as 2 hex digits */
201
void hex8out(unsigned char num)
202
{
203
    printf("%02X",num);
204
}
205
 
206
 
207
/* Output an 32 bit number as 8 hex digits */
208
void hex32out(unsigned long num)
209
{
210
    printf("%08X",num);
211
}
212
 
213
 
214
/* Input a number as (at most 8) hex digits - returns value entered */
215
long hexIn(void)
216
{
217
    char input[40];
218
    long num;
219
    register int i;
220
 
221
    i = 0;
222
    num = 0;
223
 
224
    if (sgets (input)) { /* grab a line */
225
        num = hex2dec(input[i++]);            /* Convert MSD to dec */
226
        while(ishex(input[i]) && input[i]) {  /* Get next hex digit */
227
            num <<= 4;                                          /* Make room for next digit */
228
            num += hex2dec(input[i++]);         /* Add it in */
229
        }
230
    }
231
    return num;
232
}
233
 
234
 
235
/* Input a number as decimal digits - returns value entered */
236
long decIn(void)
237
{
238
    char input[40];
239
    int num;
240
    int tmp;
241
    register int i;
242
 
243
    i = 0;
244
    num = 0;
245
 
246
    if (sgets (input)) {  /* grab a line */
247
        atod(input[i++], &num);         /* Convert MSD to decimal */
248
        while(isdec(input[i]) && input[i]) { /* Get next decimal digit */
249
            num *= 10;                  /* Make room for next digit */
250
            atod(input[i++], &tmp);
251
            num += tmp;                         /* Add it in */
252
        }
253
    }
254
 
255
    return (num);
256
}
257
 
258
 

powered by: WebSVN 2.1.0

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