sl@0
|
1 |
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <estlib.h>
|
sl@0
|
17 |
#include <stdlib.h> /* definition of exit() */
|
sl@0
|
18 |
#include <stdio.h>
|
sl@0
|
19 |
#include <errno.h>
|
sl@0
|
20 |
#include <string.h>
|
sl@0
|
21 |
#include <sys/unistd.h>
|
sl@0
|
22 |
#include <sys/ioctl.h>
|
sl@0
|
23 |
#include "CTEST.H"
|
sl@0
|
24 |
|
sl@0
|
25 |
#ifdef __cplusplus
|
sl@0
|
26 |
extern "C" {
|
sl@0
|
27 |
#endif
|
sl@0
|
28 |
|
sl@0
|
29 |
|
sl@0
|
30 |
#define SIZE 10000
|
sl@0
|
31 |
|
sl@0
|
32 |
int ReaderPort;
|
sl@0
|
33 |
int WriterPort;
|
sl@0
|
34 |
|
sl@0
|
35 |
/**
|
sl@0
|
36 |
@SYMTestCaseID SYSLIB-STDLIB-CT-1102
|
sl@0
|
37 |
@SYMTestCaseDesc Tests for serial port
|
sl@0
|
38 |
@SYMTestPriority High
|
sl@0
|
39 |
@SYMTestActions Tests by writing a string buffer to the port
|
sl@0
|
40 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
41 |
@SYMREQ REQ0000
|
sl@0
|
42 |
*/
|
sl@0
|
43 |
void Writer()
|
sl@0
|
44 |
{
|
sl@0
|
45 |
char *buffer;
|
sl@0
|
46 |
|
sl@0
|
47 |
buffer = (char*)malloc(SIZE);
|
sl@0
|
48 |
memset(buffer, '*', SIZE);
|
sl@0
|
49 |
|
sl@0
|
50 |
printf("\nbig write\n");
|
sl@0
|
51 |
(void)write(WriterPort, buffer, SIZE);
|
sl@0
|
52 |
(void)errno;
|
sl@0
|
53 |
printf("\n>>Writer<<small read\n");
|
sl@0
|
54 |
read(WriterPort,buffer,1);
|
sl@0
|
55 |
printf("\nbig write\n");
|
sl@0
|
56 |
write(WriterPort, buffer, SIZE);
|
sl@0
|
57 |
printf("\n>>Writer<<small read\n");
|
sl@0
|
58 |
read(WriterPort,buffer,1);
|
sl@0
|
59 |
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
/**
|
sl@0
|
63 |
@SYMTestCaseID SYSLIB-STDLIB-CT-1103
|
sl@0
|
64 |
@SYMTestCaseDesc Tests for serial port
|
sl@0
|
65 |
@SYMTestPriority High
|
sl@0
|
66 |
@SYMTestActions Notifies on a read operation
|
sl@0
|
67 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
68 |
@SYMREQ REQ0000
|
sl@0
|
69 |
*/
|
sl@0
|
70 |
void Watcher()
|
sl@0
|
71 |
{
|
sl@0
|
72 |
int res=0;
|
sl@0
|
73 |
int notify[2] = {0,0};
|
sl@0
|
74 |
int supported = 0;
|
sl@0
|
75 |
|
sl@0
|
76 |
|
sl@0
|
77 |
res = ioctl(ReaderPort, COMMIOCTL_NOTIFYSUPPORTED, &supported);
|
sl@0
|
78 |
printf("\nsupported notifies are %08x\n",supported);
|
sl@0
|
79 |
while (-1 != res)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
notify[0] = supported;
|
sl@0
|
82 |
printf("asking for %08x\n",notify[0]);
|
sl@0
|
83 |
res = ioctl(ReaderPort, COMMIOCTL_NOTIFY, ¬ify[0]);
|
sl@0
|
84 |
printf("\n**Notify** res = %d params %d, %d, errno %d\n",res, notify[0], notify[1],errno);
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
/**
|
sl@0
|
90 |
@SYMTestCaseID SYSLIB-STDLIB-CT-1104
|
sl@0
|
91 |
@SYMTestCaseDesc Tests for serial port
|
sl@0
|
92 |
@SYMTestPriority High
|
sl@0
|
93 |
@SYMTestActions Reads to buffer from serial port,test for failure conditions
|
sl@0
|
94 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
95 |
@SYMREQ REQ0000
|
sl@0
|
96 |
*/
|
sl@0
|
97 |
void Reader()
|
sl@0
|
98 |
{
|
sl@0
|
99 |
int res;
|
sl@0
|
100 |
char *buffer, *p;
|
sl@0
|
101 |
int x;
|
sl@0
|
102 |
|
sl@0
|
103 |
|
sl@0
|
104 |
|
sl@0
|
105 |
buffer = (char*)malloc(SIZE*2);
|
sl@0
|
106 |
|
sl@0
|
107 |
res = 0;
|
sl@0
|
108 |
p = buffer;
|
sl@0
|
109 |
|
sl@0
|
110 |
|
sl@0
|
111 |
x = 5000;
|
sl@0
|
112 |
res = ioctl(ReaderPort, COMMIOCTL_SETREADTIMEOUT, &x);
|
sl@0
|
113 |
|
sl@0
|
114 |
for(x = 0;;x++)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
res = read(ReaderPort, p, 100);
|
sl@0
|
117 |
if (res > 0)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
putchar('.');
|
sl@0
|
120 |
p += res;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
else
|
sl@0
|
123 |
{
|
sl@0
|
124 |
printf("\nread failed with errno %d\n",errno);
|
sl@0
|
125 |
break;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
}
|
sl@0
|
128 |
|
sl@0
|
129 |
printf("\n>>Reader<<small write\n");
|
sl@0
|
130 |
res = write(ReaderPort, buffer ,1);
|
sl@0
|
131 |
|
sl@0
|
132 |
printf("\n>>Reader<<set threshold\n");
|
sl@0
|
133 |
x = 100;
|
sl@0
|
134 |
res = ioctl(ReaderPort, COMMIOCTL_SETREADTHRESHOLD, &x);
|
sl@0
|
135 |
p = buffer;
|
sl@0
|
136 |
|
sl@0
|
137 |
printf("\nAnd again with a threshold of 100\n");
|
sl@0
|
138 |
|
sl@0
|
139 |
for(x = 0;;x++)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
res = read(ReaderPort, p, 100);
|
sl@0
|
142 |
if (res > 0)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
putchar('.');
|
sl@0
|
145 |
p += res;
|
sl@0
|
146 |
}
|
sl@0
|
147 |
else
|
sl@0
|
148 |
{
|
sl@0
|
149 |
printf("\nread failed with errno %d\n",errno);
|
sl@0
|
150 |
break;
|
sl@0
|
151 |
}
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
printf("\n>>Reader<<Small write\n");
|
sl@0
|
155 |
write(ReaderPort, buffer ,1);
|
sl@0
|
156 |
|
sl@0
|
157 |
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
#ifdef __cplusplus
|
sl@0
|
161 |
}
|
sl@0
|
162 |
#endif
|
sl@0
|
163 |
|
sl@0
|
164 |
int main(int, char**)
|
sl@0
|
165 |
{
|
sl@0
|
166 |
void* t1;
|
sl@0
|
167 |
void* t2;
|
sl@0
|
168 |
void* t3;
|
sl@0
|
169 |
|
sl@0
|
170 |
SerialConfig sc;
|
sl@0
|
171 |
|
sl@0
|
172 |
start_posix_server(); /* calls SpawnPosixServer from C++ code */
|
sl@0
|
173 |
|
sl@0
|
174 |
WriterPort = open("COM1:",0);
|
sl@0
|
175 |
if (-1 == WriterPort)
|
sl@0
|
176 |
exit(-1);
|
sl@0
|
177 |
(void)ioctl(WriterPort, COMMIOCTL_GETCONFIG, &sc);
|
sl@0
|
178 |
sc.iHandshake = 0;
|
sl@0
|
179 |
sc.iRate = Bps115200;
|
sl@0
|
180 |
sc.iParity = ParityNone;
|
sl@0
|
181 |
(void)ioctl(WriterPort, COMMIOCTL_SETCONFIG, &sc);
|
sl@0
|
182 |
|
sl@0
|
183 |
ReaderPort = open("COM2:",0);
|
sl@0
|
184 |
if (-1 == ReaderPort)
|
sl@0
|
185 |
exit(-2);
|
sl@0
|
186 |
(void)ioctl(ReaderPort, COMMIOCTL_GETCONFIG, &sc);
|
sl@0
|
187 |
sc.iHandshake = 0;
|
sl@0
|
188 |
sc.iRate = Bps115200;
|
sl@0
|
189 |
sc.iParity = ParityNone;
|
sl@0
|
190 |
(void)ioctl(ReaderPort, COMMIOCTL_SETCONFIG, &sc);
|
sl@0
|
191 |
|
sl@0
|
192 |
t3 = create_thread(Watcher, "watcher1");
|
sl@0
|
193 |
t1 = create_thread(Reader, "reader");
|
sl@0
|
194 |
t2 = create_thread(Writer, "writer");
|
sl@0
|
195 |
|
sl@0
|
196 |
start_thread(t3);
|
sl@0
|
197 |
start_thread(t2);
|
sl@0
|
198 |
start_thread(t1);
|
sl@0
|
199 |
|
sl@0
|
200 |
(void)wait_for_thread(t1);
|
sl@0
|
201 |
(void)wait_for_thread(t2);
|
sl@0
|
202 |
|
sl@0
|
203 |
close(WriterPort);
|
sl@0
|
204 |
close(ReaderPort);
|
sl@0
|
205 |
(void)wait_for_thread(t3);
|
sl@0
|
206 |
printf("\nPress a key\n");
|
sl@0
|
207 |
getchar();
|
sl@0
|
208 |
return 0;
|
sl@0
|
209 |
}
|
sl@0
|
210 |
|
sl@0
|
211 |
|