sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <stdlib.h> /* definition of exit() */
|
sl@0
|
21 |
#include <stdio.h>
|
sl@0
|
22 |
#include <errno.h>
|
sl@0
|
23 |
#include <string.h>
|
sl@0
|
24 |
#include <sys/unistd.h>
|
sl@0
|
25 |
#include <sys/ioctl.h>
|
sl@0
|
26 |
#include "CTEST.H"
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
|
sl@0
|
30 |
#define SIZE 10000
|
sl@0
|
31 |
|
sl@0
|
32 |
|
sl@0
|
33 |
|
sl@0
|
34 |
void Writer(void)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
int Port;
|
sl@0
|
37 |
SerialConfig sc;
|
sl@0
|
38 |
char *buffer;
|
sl@0
|
39 |
|
sl@0
|
40 |
Port = open("COM1:",0);
|
sl@0
|
41 |
(void)ioctl(Port, COMMIOCTL_GETCONFIG, &sc);
|
sl@0
|
42 |
sc.iRate = Bps115200;
|
sl@0
|
43 |
sc.iParity = ParityNone;
|
sl@0
|
44 |
(void)ioctl(Port, COMMIOCTL_SETCONFIG, &sc);
|
sl@0
|
45 |
|
sl@0
|
46 |
buffer = (char*)malloc(SIZE);
|
sl@0
|
47 |
memset(buffer, '*', SIZE);
|
sl@0
|
48 |
|
sl@0
|
49 |
write(Port, buffer, SIZE);
|
sl@0
|
50 |
|
sl@0
|
51 |
close(Port);
|
sl@0
|
52 |
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
/**
|
sl@0
|
56 |
@SYMTestCaseID SYSLIB-STDLIB-CT-1101
|
sl@0
|
57 |
@SYMTestCaseDesc Tests for reading from the serial port
|
sl@0
|
58 |
@SYMTestPriority High
|
sl@0
|
59 |
@SYMTestActions Tests for reading into a buffer of size 1000 bytes from the serial port
|
sl@0
|
60 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
61 |
@SYMREQ REQ0000
|
sl@0
|
62 |
*/
|
sl@0
|
63 |
void Reader(void)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
int res;
|
sl@0
|
66 |
int Port;
|
sl@0
|
67 |
SerialConfig sc;
|
sl@0
|
68 |
char *buffer, *p;
|
sl@0
|
69 |
int x;
|
sl@0
|
70 |
|
sl@0
|
71 |
|
sl@0
|
72 |
Port = open("COM2:",0);
|
sl@0
|
73 |
res = ioctl(Port, COMMIOCTL_GETCONFIG, &sc);
|
sl@0
|
74 |
sc.iRate = Bps115200;
|
sl@0
|
75 |
sc.iParity = ParityNone;
|
sl@0
|
76 |
res = ioctl(Port, COMMIOCTL_SETCONFIG, &sc);
|
sl@0
|
77 |
|
sl@0
|
78 |
buffer = (char*)malloc(SIZE);
|
sl@0
|
79 |
|
sl@0
|
80 |
res = 0;
|
sl@0
|
81 |
p = buffer;
|
sl@0
|
82 |
|
sl@0
|
83 |
|
sl@0
|
84 |
x = 5000;
|
sl@0
|
85 |
res = ioctl(Port, COMMIOCTL_SETREADTIMEOUT, &x);
|
sl@0
|
86 |
|
sl@0
|
87 |
for(x = 0;;x++)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
res = read(Port, p, 100);
|
sl@0
|
90 |
if (res > 0)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
printf("read block %d int addr %x, bytes %d\n",x,p,res);
|
sl@0
|
93 |
p += res;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
else
|
sl@0
|
97 |
break;
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
|
sl@0
|
101 |
x = 100;
|
sl@0
|
102 |
res = ioctl(Port, COMMIOCTL_SETREADTHRESHOLD, &x);
|
sl@0
|
103 |
p = buffer;
|
sl@0
|
104 |
|
sl@0
|
105 |
printf("And again with a threshold of 100\n");
|
sl@0
|
106 |
|
sl@0
|
107 |
for(x = 0;;x++)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
res = read(Port, p, 100);
|
sl@0
|
110 |
if (res > 0)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
printf("read block %d int addr %x, bytes %d\n",x,p,res);
|
sl@0
|
113 |
p += res;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
else
|
sl@0
|
117 |
break;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
|
sl@0
|
121 |
close(Port);
|
sl@0
|
122 |
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
int main(void)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
Reader();
|
sl@0
|
128 |
return 0;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|