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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [serial/] [v2_0/] [tests/] [flow1.c] - Blame information for rev 223

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//        flow1.c
4
//
5
//        Test data half-duplex receive and send with flow control.
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):     jskov,jlarmour
44
// Contributors:  
45
// Date:          2000-07-27
46
// Description:   Test the half-duplex receive and send capabilities of 
47
//                the serial driver with flow control.
48
// Requirements:  This test requires the ser_filter on the host side.
49
// 
50
//####DESCRIPTIONEND####
51
 
52
#include <pkgconf/system.h>
53
 
54
#include <cyg/infra/testcase.h>         // test macros
55
#include <cyg/infra/cyg_ass.h>          // assertion macros
56
 
57
#ifdef CYGPKG_KERNEL
58
# include <pkgconf/kernel.h>
59
#endif
60
#ifdef CYGPKG_IO_SERIAL
61
# include <pkgconf/io_serial.h>
62
#endif
63
 
64
// Package requirements
65
#ifndef CYGPKG_IO_SERIAL
66
# define NA_MSG "Requires I/O serial package"
67
#elif !defined(CYGFUN_KERNEL_API_C)
68
# define NA_MSG "Requires kernel C API"
69
#elif !defined(CYGPKG_IO_SERIAL_FLOW_CONTROL)
70
# define NA_MSG "Requires serial flow control"
71
#endif
72
 
73
#ifdef NA_MSG
74
void
75
cyg_start( void )
76
{
77
    CYG_TEST_INIT();
78
    CYG_TEST_NA( NA_MSG);
79
}
80
#else
81
 
82
#include <cyg/hal/hal_arch.h>           // CYGNUM_HAL_STACK_SIZE_TYPICAL
83
#include <cyg/kernel/kapi.h>
84
unsigned char stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
85
cyg_thread thread_data;
86
cyg_handle_t thread_handle;
87
 
88
// redefine buffer size for large transfer tests
89
#ifndef CYGPKG_HAL_ARM_AEB
90
# define IN_BUFFER_SIZE 65536
91
#endif
92
 
93
#include "ser_test_protocol.inl"
94
 
95
 
96
//---------------------------------------------------------------------------
97
// run the tests
98
 
99
static void
100
run_tests( cyg_io_handle_t ser_handle )
101
{
102
 
103
 
104
    // Start slowly, then go for max size.
105
    {
106
        test_binary(ser_handle,             16, MODE_EOP_ECHO);
107
        test_binary(ser_handle,            128, MODE_EOP_ECHO);
108
        test_binary(ser_handle,            256, MODE_EOP_ECHO);
109
        test_binary(ser_handle, IN_BUFFER_SIZE, MODE_EOP_ECHO);
110
    }
111
 
112
    // Write some varying length packets.
113
    {
114
        int i;
115
        for(i = 0; i < 8; i++) {
116
            // No echo.
117
            test_binary(ser_handle,   256 + 42*i, MODE_NO_ECHO);
118
            test_binary(ser_handle,    64 +  7*i, MODE_NO_ECHO);
119
            // Echo.
120
            test_binary(ser_handle,   256 + 42*i, MODE_EOP_ECHO);
121
            test_binary(ser_handle,    64 +  7*i, MODE_EOP_ECHO);
122
        }
123
    }
124
 
125
    // End with some long packets.
126
    {
127
        test_binary(ser_handle,  2048, MODE_NO_ECHO);
128
        test_binary(ser_handle, 16384, MODE_NO_ECHO);
129
        test_binary(ser_handle, 65536, MODE_NO_ECHO);
130
    }
131
}
132
 
133
//---------------------------------------------------------------------------
134
// Serial test main function.
135
 
136
void
137
serial_test( void )
138
{
139
    cyg_io_handle_t ser_handle;
140
    cyg_ser_cfg_t *cfg=&test_configs[0];
141
    cyg_ser_cfg_t new_cfg;
142
    int count = sizeof(test_configs) / sizeof(cyg_ser_cfg_t);
143
    int i;
144
 
145
    test_open_ser(&ser_handle);
146
 
147
    // We need the filter for this test.
148
    test_ping(ser_handle);
149
 
150
    // Choose the configuration with the fastest baud rate, to be most
151
    // provocative. Start at 1 coz cfg already points at 0
152
    for (i=1; i<count; i++) {
153
        if (cfg->baud_rate < test_configs[i].baud_rate)
154
            cfg=&test_configs[i];
155
    }
156
 
157
    // Set flow control from configuration
158
    // Choose software first
159
 
160
#ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_SOFTWARE
161
    CYG_TEST_INFO("Setting software flow control");
162
 
163
    new_cfg = *cfg;
164
    new_cfg.flags |= CYGNUM_SERIAL_FLOW_XONXOFF_RX |
165
                     CYGNUM_SERIAL_FLOW_XONXOFF_TX;
166
    if (ENOERR == change_config(ser_handle, &new_cfg))
167
        run_tests( ser_handle );
168
#endif
169
 
170
    // hardware flow control
171
#ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_HW
172
    CYG_TEST_INFO("Setting hardware flow control");
173
 
174
    new_cfg = *cfg;
175
    new_cfg.flags |= CYGNUM_SERIAL_FLOW_RTSCTS_RX|CYGNUM_SERIAL_FLOW_RTSCTS_TX;
176
    if (ENOERR == change_config(ser_handle, &new_cfg))
177
        run_tests( ser_handle );
178
 
179
    CYG_TEST_INFO("Setting DSR/DTR hardware flow control");
180
 
181
    new_cfg = *cfg;
182
    new_cfg.flags |= CYGNUM_SERIAL_FLOW_DSRDTR_RX|CYGNUM_SERIAL_FLOW_DSRDTR_TX;
183
    if (ENOERR == change_config(ser_handle, &new_cfg))
184
        run_tests( ser_handle );
185
#endif
186
 
187
    CYG_TEST_PASS_FINISH("flow1 test OK");
188
}
189
 
190
void
191
cyg_start(void)
192
{
193
    CYG_TEST_INIT();
194
    cyg_thread_create(10,                   // Priority - just a number
195
                      (cyg_thread_entry_t*)serial_test,         // entry
196
                      0,                    // 
197
                      "serial_thread",     // Name
198
                      &stack[0],            // Stack
199
                      CYGNUM_HAL_STACK_SIZE_TYPICAL,           // Size
200
                      &thread_handle,       // Handle
201
                      &thread_data          // Thread data structure
202
        );
203
    cyg_thread_resume(thread_handle);
204
    cyg_scheduler_start();
205
}
206
 
207
#endif // ifndef NA_MSG
208
 
209
// EOF flow1.c

powered by: WebSVN 2.1.0

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