1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// serial1.c
|
4 |
|
|
//
|
5 |
|
|
// Test serial driver API
|
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 serial driver API.
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
|
50 |
|
|
#include <pkgconf/system.h>
|
51 |
|
|
|
52 |
|
|
#include <cyg/infra/testcase.h> // test macros
|
53 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
54 |
|
|
|
55 |
|
|
// Package requirements
|
56 |
|
|
#if defined(CYGPKG_IO_SERIAL) && defined(CYGPKG_KERNEL)
|
57 |
|
|
|
58 |
|
|
#include <pkgconf/kernel.h>
|
59 |
|
|
|
60 |
|
|
// Package option requirements
|
61 |
|
|
#if defined(CYGFUN_KERNEL_API_C)
|
62 |
|
|
|
63 |
|
|
#include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL
|
64 |
|
|
#include <cyg/kernel/kapi.h>
|
65 |
|
|
unsigned char stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
|
66 |
|
|
cyg_thread thread_data;
|
67 |
|
|
cyg_handle_t thread_handle;
|
68 |
|
|
|
69 |
|
|
#include "ser_test_protocol.inl"
|
70 |
|
|
|
71 |
|
|
//---------------------------------------------------------------------------
|
72 |
|
|
// Serial test main function.
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
void
|
76 |
|
|
serial_api_test(int dummy)
|
77 |
|
|
{
|
78 |
|
|
cyg_io_handle_t handle;
|
79 |
|
|
int res, len;
|
80 |
|
|
unsigned char buffer[16];
|
81 |
|
|
|
82 |
|
|
// Always return...
|
83 |
|
|
if (dummy)
|
84 |
|
|
return;
|
85 |
|
|
|
86 |
|
|
CYG_TEST_FAIL_FINISH("Not reached");
|
87 |
|
|
|
88 |
|
|
test_open_ser(&handle);
|
89 |
|
|
|
90 |
|
|
// read & write
|
91 |
|
|
res = cyg_io_read(handle, &buffer[0], &len);
|
92 |
|
|
res = cyg_io_write(handle, &buffer[0], &len);
|
93 |
|
|
|
94 |
|
|
// cyg_io_get_config
|
95 |
|
|
cyg_io_get_config(handle,
|
96 |
|
|
CYG_IO_GET_CONFIG_SERIAL_INFO, &buffer[0], &len);
|
97 |
|
|
cyg_io_get_config(handle,
|
98 |
|
|
CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, &buffer[0], &len);
|
99 |
|
|
cyg_io_get_config(handle,
|
100 |
|
|
CYG_IO_GET_CONFIG_SERIAL_INPUT_FLUSH, &buffer[0], &len);
|
101 |
|
|
cyg_io_get_config(handle,
|
102 |
|
|
CYG_IO_GET_CONFIG_SERIAL_ABORT, &buffer[0], &len);
|
103 |
|
|
cyg_io_get_config(handle,
|
104 |
|
|
CYG_IO_GET_CONFIG_SERIAL_OUTPUT_FLUSH, &buffer[0], &len);
|
105 |
|
|
|
106 |
|
|
// cyg_io_set_config
|
107 |
|
|
cyg_io_set_config(handle,
|
108 |
|
|
CYG_IO_SET_CONFIG_SERIAL_INFO, &buffer[0], &len);
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
void
|
113 |
|
|
serial_test( void )
|
114 |
|
|
{
|
115 |
|
|
serial_api_test(1);
|
116 |
|
|
|
117 |
|
|
CYG_TEST_PASS_FINISH("serial1 test OK");
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
void
|
121 |
|
|
cyg_start(void)
|
122 |
|
|
{
|
123 |
|
|
CYG_TEST_INIT();
|
124 |
|
|
cyg_thread_create(10, // Priority - just a number
|
125 |
|
|
(cyg_thread_entry_t*)serial_test, // entry
|
126 |
|
|
0, //
|
127 |
|
|
"serial_thread", // Name
|
128 |
|
|
&stack[0], // Stack
|
129 |
|
|
CYGNUM_HAL_STACK_SIZE_TYPICAL, // Size
|
130 |
|
|
&thread_handle, // Handle
|
131 |
|
|
&thread_data // Thread data structure
|
132 |
|
|
);
|
133 |
|
|
cyg_thread_resume(thread_handle);
|
134 |
|
|
cyg_scheduler_start();
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
#else // CYGFUN_KERNEL_API_C
|
138 |
|
|
#define N_A_MSG "Needs kernel C API"
|
139 |
|
|
#endif
|
140 |
|
|
|
141 |
|
|
#else // CYGPKG_IO_SERIAL && CYGPKG_KERNEL
|
142 |
|
|
#define N_A_MSG "Needs IO/serial and Kernel"
|
143 |
|
|
#endif
|
144 |
|
|
|
145 |
|
|
#ifdef N_A_MSG
|
146 |
|
|
void
|
147 |
|
|
cyg_start( void )
|
148 |
|
|
{
|
149 |
|
|
CYG_TEST_INIT();
|
150 |
|
|
CYG_TEST_NA( N_A_MSG);
|
151 |
|
|
}
|
152 |
|
|
#endif // N_A_MSG
|
153 |
|
|
|
154 |
|
|
// EOF serial1.c
|