|
0
|
1 //================================================================= |
|
|
2 // |
|
|
3 // serial_test.c |
|
|
4 // |
|
|
5 // Test that the device API for the serial device exists. |
|
|
6 // |
|
|
7 //================================================================= |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // October 31, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
|
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //================================================================= |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): proven |
|
|
33 // Contributors: proven |
|
|
34 // Date: 1998-10-08 |
|
|
35 // Description: Tests basic serial functionality. |
|
|
36 //####DESCRIPTIONEND#### |
|
|
37 |
|
|
38 #include <pkgconf/system.h> |
|
|
39 #include <cyg/infra/testcase.h> // Generic test macros |
|
|
40 #ifdef CYGPKG_KERNEL |
|
|
41 # include <pkgconf/kernel.h> |
|
|
42 #endif |
|
|
43 |
|
|
44 #ifndef CYGFUN_KERNEL_API_C |
|
|
45 |
|
|
46 externC void |
|
|
47 cyg_start(void) |
|
|
48 { |
|
|
49 CYG_TEST_INIT(); |
|
|
50 |
|
|
51 CYG_TEST_PASS_EXIT("N/A: Testing is not applicable " |
|
|
52 "to this configuration"); |
|
|
53 } |
|
|
54 |
|
|
55 #else |
|
|
56 |
|
|
57 #include <cyg/kernel/kapi.h> // All the kernel specific stuff |
|
|
58 #include <cyg/devs/common/table.h> // All the device specific stuff |
|
|
59 |
|
|
60 #define NTHREADS 1 |
|
|
61 #define STACKSIZE 4096 |
|
|
62 |
|
|
63 static cyg_handle_t thread[NTHREADS]; |
|
|
64 static cyg_thread thread_obj[NTHREADS]; |
|
|
65 static char stack[NTHREADS][STACKSIZE]; |
|
|
66 |
|
|
67 char message1[] = "This is test message 1.\n"; |
|
|
68 char message2[] = "This is test message 2.\n"; |
|
|
69 |
|
|
70 /* Only call routines that do not require user input */ |
|
|
71 void entry0(CYG_ADDRWORD data) |
|
|
72 { |
|
|
73 Cyg_IORB iorb1, iorb2; |
|
|
74 cyg_int32 baud_rate, i; |
|
|
75 |
|
|
76 /* Only call routines if there is a serial device in the system */ |
|
|
77 if ( NULL == Cyg_Device_Table[0].name || |
|
|
78 /* strcmp is not necessarily around */ |
|
|
79 's' != Cyg_Device_Table[0].name[0] || |
|
|
80 'e' != Cyg_Device_Table[0].name[1] || |
|
|
81 'r' != Cyg_Device_Table[0].name[2] || |
|
|
82 'i' != Cyg_Device_Table[0].name[3] || |
|
|
83 'a' != Cyg_Device_Table[0].name[4] || |
|
|
84 'l' != Cyg_Device_Table[0].name[5] ) { |
|
|
85 CYG_TEST_PASS_EXIT( "N/A: no serial device in Cyg_Device_Table" ); |
|
|
86 return; |
|
|
87 } |
|
|
88 |
|
|
89 iorb1.callback = NULL; |
|
|
90 iorb1.buffer = message1; |
|
|
91 iorb1.buffer_length = sizeof(message1) - 1; |
|
|
92 cyg_write_asynchronous(Cyg_Device_Table, &iorb1); |
|
|
93 |
|
|
94 iorb2.buffer = message2; |
|
|
95 iorb2.buffer_length = sizeof(message2) - 1; |
|
|
96 cyg_write_blocking(Cyg_Device_Table, &iorb2); |
|
|
97 |
|
|
98 for (i = 0; i < 1000000; i++); // Delay to flush the tx buffer |
|
|
99 |
|
|
100 if ((cyg_serial_rs232_get_baud_rate(Cyg_Device_Table, &baud_rate )) >= 0) { |
|
|
101 CYG_TEST_PASS_FAIL( |
|
|
102 (cyg_serial_rs232_set_baud_rate(Cyg_Device_Table, baud_rate,&i) >= 0), |
|
|
103 "Setting baud rate to previous baud rate."); |
|
|
104 } else { |
|
|
105 CYG_TEST_FAIL("Could not get baud rate."); |
|
|
106 } |
|
|
107 |
|
|
108 CYG_TEST_PASS_EXIT("serial_test"); |
|
|
109 } |
|
|
110 |
|
|
111 /* Make calls to the rest of the API */ |
|
|
112 void entry_bogus(CYG_ADDRWORD data) |
|
|
113 { |
|
|
114 Cyg_IORB iorb; |
|
|
115 char buf[1024]; |
|
|
116 cyg_uint32 old; |
|
|
117 iorb.buffer = buf; |
|
|
118 iorb.buffer_length = sizeof(buf); |
|
|
119 |
|
|
120 // Set mode to interrupt |
|
|
121 cyg_serial_rs232_set_kmode(Cyg_Device_Table, (cyg_uint32)1); |
|
|
122 // cyg_serial_rs232_get_kmode(Cyg_Device_Table); // Doesn't exist yet |
|
|
123 |
|
|
124 // These could go in the entry0 routine |
|
|
125 cyg_serial_rs232_get_line_mode(Cyg_Device_Table, &old); |
|
|
126 cyg_serial_rs232_set_line_mode(Cyg_Device_Table, 1, &old); |
|
|
127 |
|
|
128 cyg_serial_rs232_get_baud_rate(Cyg_Device_Table, &old); |
|
|
129 cyg_serial_rs232_set_baud_rate(Cyg_Device_Table, 1, &old); |
|
|
130 |
|
|
131 cyg_serial_rs232_get_read_mode(Cyg_Device_Table, &old); |
|
|
132 cyg_serial_rs232_set_read_mode(Cyg_Device_Table, 1, &old); |
|
|
133 |
|
|
134 cyg_serial_rs232_set_read_data(Cyg_Device_Table, 1, NULL, 0); |
|
|
135 cyg_read_asynchronous(Cyg_Device_Table, &iorb); |
|
|
136 cyg_read_blocking(Cyg_Device_Table, &iorb); |
|
|
137 cyg_read_cancel(Cyg_Device_Table, &iorb); |
|
|
138 |
|
|
139 // cyg_serial_rs232_set_write_mode(Cyg_Device_Table, 1);// Doesn't exist yet |
|
|
140 // cyg_serial_rs232_get_write_mode(Cyg_Device_Table);// Doesn't exist yet |
|
|
141 cyg_write_asynchronous(Cyg_Device_Table, &iorb); |
|
|
142 cyg_write_blocking(Cyg_Device_Table, &iorb); |
|
|
143 // cyg_write_cancel(Cyg_Device_Table, &iorb); // Doesn't exist yet |
|
|
144 } |
|
|
145 |
|
|
146 externC void |
|
|
147 cyg_start(void) |
|
|
148 { |
|
|
149 CYG_TEST_INIT(); |
|
|
150 |
|
|
151 cyg_thread_create(4, entry0, (cyg_addrword_t)0, "serial_test", |
|
|
152 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); |
|
|
153 cyg_thread_resume(thread[0]); |
|
|
154 |
|
|
155 cyg_scheduler_start(); |
|
|
156 |
|
|
157 CYG_TEST_FAIL_EXIT("Not reached"); |
|
|
158 |
|
|
159 entry_bogus(0); // To prevent selective linking from GC all the bogus calls. |
|
|
160 } |
|
|
161 |
|
|
162 #endif // ifdef CYGFUN_KERNEL_API_C |
|
|
163 |
|
|
164 // EOF serial_test.cxx |