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