1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// serial3.c
|
4 |
|
|
//
|
5 |
|
|
// Test data half-duplex receive and send.
|
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
|
44 |
|
|
// Contributors: jskov
|
45 |
|
|
// Date: 1999-03-17
|
46 |
|
|
// Description: Test the half-duplex receive and send capabilities of
|
47 |
|
|
// the serial driver.
|
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 |
|
|
// Package requirements
|
58 |
|
|
#if defined(CYGPKG_IO_SERIAL) && defined(CYGPKG_KERNEL)
|
59 |
|
|
|
60 |
|
|
#include <pkgconf/kernel.h>
|
61 |
|
|
|
62 |
|
|
// Package option requirements
|
63 |
|
|
#if defined(CYGFUN_KERNEL_API_C)
|
64 |
|
|
|
65 |
|
|
#include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL
|
66 |
|
|
#include <cyg/kernel/kapi.h>
|
67 |
|
|
unsigned char stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
|
68 |
|
|
cyg_thread thread_data;
|
69 |
|
|
cyg_handle_t thread_handle;
|
70 |
|
|
|
71 |
|
|
#include "ser_test_protocol.inl"
|
72 |
|
|
|
73 |
|
|
//---------------------------------------------------------------------------
|
74 |
|
|
// Serial test main function.
|
75 |
|
|
void
|
76 |
|
|
serial_test( void )
|
77 |
|
|
{
|
78 |
|
|
cyg_io_handle_t ser_handle;
|
79 |
|
|
|
80 |
|
|
test_open_ser(&ser_handle);
|
81 |
|
|
|
82 |
|
|
// We need the filter for this test.
|
83 |
|
|
test_ping(ser_handle);
|
84 |
|
|
|
85 |
|
|
#if (CYGINT_IO_SERIAL_TEST_SKIP_38400 > 0)
|
86 |
|
|
{
|
87 |
|
|
// The board is too slow to run the driver in interrupt mode
|
88 |
|
|
// at the default 38400 baud when doing this test, so run it
|
89 |
|
|
// at a slower rate.
|
90 |
|
|
cyg_ser_cfg_t slow_cfg = {
|
91 |
|
|
CYGNUM_SERIAL_BAUD_19200, CYGNUM_SERIAL_WORD_LENGTH_8,
|
92 |
|
|
CYGNUM_SERIAL_STOP_1, CYGNUM_SERIAL_PARITY_NONE,
|
93 |
|
|
CYGNUM_SERIAL_FLOW_NONE };
|
94 |
|
|
|
95 |
|
|
CYG_TEST_INFO("Reducing baud rate to 19200");
|
96 |
|
|
change_config(ser_handle, &slow_cfg);
|
97 |
|
|
}
|
98 |
|
|
#endif
|
99 |
|
|
|
100 |
|
|
// Start slowly, then go for max size.
|
101 |
|
|
{
|
102 |
|
|
test_binary(ser_handle, 16, MODE_EOP_ECHO);
|
103 |
|
|
test_binary(ser_handle, 128, MODE_EOP_ECHO);
|
104 |
|
|
test_binary(ser_handle, 256, MODE_EOP_ECHO);
|
105 |
|
|
test_binary(ser_handle, IN_BUFFER_SIZE, MODE_EOP_ECHO);
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
// Write some varying length packets.
|
109 |
|
|
{
|
110 |
|
|
int i;
|
111 |
|
|
for(i = 0; i < 8; i++) {
|
112 |
|
|
// No echo.
|
113 |
|
|
test_binary(ser_handle, 256 + 42*i, MODE_NO_ECHO);
|
114 |
|
|
test_binary(ser_handle, 64 + 7*i, MODE_NO_ECHO);
|
115 |
|
|
// Echo.
|
116 |
|
|
test_binary(ser_handle, 256 + 42*i, MODE_EOP_ECHO);
|
117 |
|
|
test_binary(ser_handle, 64 + 7*i, MODE_EOP_ECHO);
|
118 |
|
|
}
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
#if 0 // Disable this for now.
|
122 |
|
|
// End with some long packets.
|
123 |
|
|
{
|
124 |
|
|
test_binary(ser_handle, 2048, MODE_NO_ECHO);
|
125 |
|
|
test_binary(ser_handle, 16384, MODE_NO_ECHO);
|
126 |
|
|
test_binary(ser_handle, 65536, MODE_NO_ECHO);
|
127 |
|
|
}
|
128 |
|
|
#endif
|
129 |
|
|
|
130 |
|
|
CYG_TEST_PASS_FINISH("serial3 test OK");
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
void
|
134 |
|
|
cyg_start(void)
|
135 |
|
|
{
|
136 |
|
|
CYG_TEST_INIT();
|
137 |
|
|
cyg_thread_create(10, // Priority - just a number
|
138 |
|
|
(cyg_thread_entry_t*)serial_test, // entry
|
139 |
|
|
0, //
|
140 |
|
|
"serial_thread", // Name
|
141 |
|
|
&stack[0], // Stack
|
142 |
|
|
CYGNUM_HAL_STACK_SIZE_TYPICAL, // Size
|
143 |
|
|
&thread_handle, // Handle
|
144 |
|
|
&thread_data // Thread data structure
|
145 |
|
|
);
|
146 |
|
|
cyg_thread_resume(thread_handle);
|
147 |
|
|
cyg_scheduler_start();
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
#else // CYGFUN_KERNEL_API_C
|
151 |
|
|
#define N_A_MSG "Needs kernel C API"
|
152 |
|
|
#endif
|
153 |
|
|
|
154 |
|
|
#else // CYGPKG_IO_SERIAL && CYGPKG_KERNEL
|
155 |
|
|
#define N_A_MSG "Needs IO/serial and Kernel"
|
156 |
|
|
#endif
|
157 |
|
|
|
158 |
|
|
#ifdef N_A_MSG
|
159 |
|
|
void
|
160 |
|
|
cyg_start( void )
|
161 |
|
|
{
|
162 |
|
|
CYG_TEST_INIT();
|
163 |
|
|
CYG_TEST_NA( N_A_MSG);
|
164 |
|
|
}
|
165 |
|
|
#endif // N_A_MSG
|
166 |
|
|
// EOF serial3.c
|