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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [serial/] [current/] [misc/] [console.c] - Blame information for rev 825

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        console.c
4
//
5
//        Initial device I/O tests
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 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):     gthomas
43
// Contributors:  gthomas
44
// Date:          1999-02-05
45
// Description:   Minimal testing of "console" I/O
46
//####DESCRIPTIONEND####
47
 
48
#include <pkgconf/kernel.h>
49
#include <pkgconf/io.h>
50
#include <pkgconf/io_serial.h>
51
#include <cyg/io/io.h>
52
#include <cyg/io/ttyio.h>
53
#include <cyg/infra/testcase.h>
54
#include <cyg/infra/diag.h>
55
#ifdef CYGFUN_KERNEL_API_C
56
#include <cyg/kernel/kapi.h>
57
#include <cyg/hal/hal_arch.h>
58
#define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
59
unsigned char stack[STACK_SIZE];
60
cyg_thread thread_data;
61
cyg_handle_t thread_handle;
62
#endif
63
 
64
static void
65
dump_buf_with_offset(unsigned char *p,
66
                     int s,
67
                     unsigned char *base)
68
{
69
    int i, c;
70
    if ((unsigned int)s > (unsigned int)p) {
71
        s = (unsigned int)s - (unsigned int)p;
72
    }
73
    while (s > 0) {
74
        if (base) {
75
            diag_printf("%08X: ", (int)p - (int)base);
76
        } else {
77
            diag_printf("%08X: ", p);
78
        }
79
        for (i = 0;  i < 16;  i++) {
80
            if (i < s) {
81
                diag_printf("%02X", p[i] & 0xFF);
82
            } else {
83
                diag_printf("  ");
84
            }
85
            if ((i % 2) == 1) diag_printf(" ");
86
            if ((i % 8) == 7) diag_printf(" ");
87
        }
88
        diag_printf(" |");
89
        for (i = 0;  i < 16;  i++) {
90
            if (i < s) {
91
                c = p[i] & 0xFF;
92
                if ((c < 0x20) || (c >= 0x7F)) c = '.';
93
            } else {
94
                c = ' ';
95
            }
96
            diag_printf("%c", c);
97
        }
98
        diag_printf("|\n");
99
        s -= 16;
100
        p += 16;
101
    }
102
}
103
 
104
static void
105
dump_buf(unsigned char *p, int s)
106
{
107
   dump_buf_with_offset(p, s, 0);
108
}
109
 
110
void
111
hang(void)
112
{
113
    while (true) ;
114
}
115
 
116
static int
117
strlen(char *c)
118
{
119
    int l = 0;
120
    while (*c++) l++;
121
    return l;
122
}
123
 
124
void
125
console_test( CYG_ADDRWORD x )
126
{
127
    Cyg_ErrNo res;
128
    cyg_io_handle_t handle;
129
    char msg[] = "This is a test\n";
130
    int msglen = sizeof(msg)-1;
131
    char in_msg[80];
132
    int in_msglen = sizeof(in_msg)-1;
133
    cyg_serial_info_t serial_info;
134
    cyg_tty_info_t tty_info;
135
    char short_msg[] = "This is a short message\n";
136
    char long_msg[] = "This is a longer message 0123456789abcdefghijklmnopqrstuvwxyz\n";
137
    char filler[] = "          ";
138
    char prompt[] = "\nPlease enter some data: ";
139
    int i, len;
140
 
141
    res = cyg_io_lookup(CYGDAT_IO_SERIAL_TTY_CONSOLE, &handle);
142
    if (res != ENOERR) {
143
        diag_printf("Can't lookup - DEVIO error: %d\n", res);
144
        return;
145
    }
146
    len = sizeof(serial_info);
147
    res = cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_INFO, &serial_info, &len);
148
    if (res != ENOERR) {
149
        diag_printf("Can't get serial config - DEVIO error: %d\n", res);
150
hang();
151
        return;
152
    }
153
    len = sizeof(tty_info);
154
    res = cyg_io_get_config(handle, CYG_IO_GET_CONFIG_TTY_INFO, &tty_info, &len);
155
    if (res != ENOERR) {
156
        diag_printf("Can't get tty config - DEVIO error: %d\n", res);
157
hang();
158
        return;
159
    }
160
    diag_printf("Config - baud: %d, stop: %d, parity: %d, out flags: %x, in flags: %x\n",
161
                serial_info.baud, serial_info.stop, serial_info.parity,
162
                tty_info.tty_out_flags, tty_info.tty_in_flags);
163
    len = sizeof(serial_info);
164
    res = cyg_io_set_config(handle, CYG_IO_SET_CONFIG_SERIAL_INFO, &serial_info, &len);
165
    if (res != ENOERR) {
166
        diag_printf("Can't set serial config - DEVIO error: %d\n", res);
167
hang();
168
        return;
169
    }
170
    len = sizeof(tty_info);
171
    res = cyg_io_set_config(handle, CYG_IO_SET_CONFIG_TTY_INFO, &tty_info, &len);
172
    if (res != ENOERR) {
173
        diag_printf("Can't set tty config - DEVIO error: %d\n", res);
174
hang();
175
        return;
176
    }
177
    msglen = strlen(msg);
178
    res = cyg_io_write(handle, msg, &msglen);
179
    if (res != ENOERR) {
180
        diag_printf("Can't write data - DEVIO error: %d\n", res);
181
hang();
182
        return;
183
    }
184
    for (i = 0;  i < 10;  i++) {
185
        len = strlen(short_msg);
186
        res = cyg_io_write(handle, short_msg, &len);
187
        if (res != ENOERR) {
188
            diag_printf("Can't write [short] data - DEVIO error: %d\n", res);
189
            hang();
190
            return;
191
        }
192
    }
193
    for (i = 0;  i < 100;  i++) {
194
        len = (i % 10) + 1;
195
        cyg_io_write(handle, filler, &len);
196
        len = strlen(long_msg);
197
        res = cyg_io_write(handle, long_msg, &len);
198
        if (res != ENOERR) {
199
            diag_printf("Can't write [long] data - DEVIO error: %d\n", res);
200
            hang();
201
            return;
202
        }
203
    }
204
    len = strlen(prompt);
205
    cyg_io_write(handle, prompt, &len);
206
    res = cyg_io_read(handle, in_msg, &in_msglen);
207
    if (res != ENOERR) {
208
        diag_printf("Can't read data - DEVIO error: %d\n", res);
209
hang();
210
        return;
211
    }
212
    diag_printf("Read %d bytes\n", in_msglen);
213
    dump_buf(in_msg, in_msglen);
214
    CYG_TEST_PASS_FINISH("Console I/O test OK");
215
}
216
 
217
void
218
cyg_start(void)
219
{
220
    CYG_TEST_INIT();
221
#ifdef CYGFUN_KERNEL_API_C
222
    cyg_thread_create(10,                   // Priority - just a number
223
                      (cyg_thread_entry_t*)console_test,         // entry
224
                      0,                    // 
225
                      "console_thread",     // Name
226
                      &stack[0],            // Stack
227
                      STACK_SIZE,           // Size
228
                      &thread_handle,       // Handle
229
                      &thread_data          // Thread data structure
230
        );
231
    cyg_thread_resume(thread_handle);
232
    cyg_scheduler_start();
233
#else
234
    console_test();
235
#endif
236
}
237
// EOF console.c

powered by: WebSVN 2.1.0

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