os/ossrv/genericopenlibs/cstdlib/TSTLIB/tser2r.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/tser2r.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,130 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +#include <stdlib.h>	/* definition of exit() */
    1.24 +#include <stdio.h>
    1.25 +#include <errno.h>
    1.26 +#include <string.h>
    1.27 +#include <sys/unistd.h>
    1.28 +#include <sys/ioctl.h>
    1.29 +#include "CTEST.H"
    1.30 +
    1.31 +
    1.32 +
    1.33 +#define SIZE 10000
    1.34 +
    1.35 +
    1.36 +
    1.37 +void Writer(void)
    1.38 +	{
    1.39 +	int Port;
    1.40 +	SerialConfig sc;
    1.41 +	char *buffer;
    1.42 +
    1.43 +	Port = open("COM1:",0);
    1.44 +	(void)ioctl(Port, COMMIOCTL_GETCONFIG, &sc);
    1.45 +	sc.iRate = Bps115200;
    1.46 +	sc.iParity = ParityNone;
    1.47 +	(void)ioctl(Port, COMMIOCTL_SETCONFIG, &sc);
    1.48 +	
    1.49 +	buffer = (char*)malloc(SIZE);
    1.50 +	memset(buffer, '*', SIZE);
    1.51 +
    1.52 +	write(Port, buffer, SIZE);
    1.53 +	
    1.54 +	close(Port);
    1.55 +
    1.56 +	}
    1.57 +
    1.58 +/**
    1.59 +@SYMTestCaseID          SYSLIB-STDLIB-CT-1101
    1.60 +@SYMTestCaseDesc	    Tests for reading from the serial port
    1.61 +@SYMTestPriority 	    High
    1.62 +@SYMTestActions  	    Tests for reading into a buffer of size 1000 bytes from the serial port
    1.63 +@SYMTestExpectedResults Test must not fail
    1.64 +@SYMREQ                 REQ0000
    1.65 +*/		
    1.66 +void Reader(void)
    1.67 +	{
    1.68 +	int res;
    1.69 +	int Port;
    1.70 +	SerialConfig sc;
    1.71 +	char *buffer, *p;
    1.72 +	int x;
    1.73 +
    1.74 +
    1.75 +	Port = open("COM2:",0);
    1.76 +	res = ioctl(Port, COMMIOCTL_GETCONFIG, &sc);
    1.77 +	sc.iRate = Bps115200;
    1.78 +	sc.iParity = ParityNone;
    1.79 +	res = ioctl(Port, COMMIOCTL_SETCONFIG, &sc);
    1.80 +	
    1.81 +	buffer = (char*)malloc(SIZE);
    1.82 +
    1.83 +	res = 0;
    1.84 +	p = buffer;
    1.85 +	
    1.86 +
    1.87 +	x = 5000;
    1.88 +	res = ioctl(Port, COMMIOCTL_SETREADTIMEOUT, &x);
    1.89 +
    1.90 +	for(x = 0;;x++)
    1.91 +		{
    1.92 +		res = read(Port, p, 100);
    1.93 +		if (res > 0)
    1.94 +			{
    1.95 +			printf("read block %d int addr %x, bytes %d\n",x,p,res);
    1.96 +			p += res;
    1.97 +			}
    1.98 +
    1.99 +		else
   1.100 +			break;
   1.101 +		}
   1.102 +		
   1.103 +		
   1.104 +	x = 100;
   1.105 +	res = ioctl(Port, COMMIOCTL_SETREADTHRESHOLD, &x);
   1.106 +	p = buffer;
   1.107 +
   1.108 +	printf("And again with a threshold of 100\n");
   1.109 +	
   1.110 +	for(x = 0;;x++)
   1.111 +		{
   1.112 +		res = read(Port, p, 100);
   1.113 +		if (res > 0)
   1.114 +			{
   1.115 +			printf("read block %d int addr %x, bytes %d\n",x,p,res);
   1.116 +			p += res;
   1.117 +			}
   1.118 +
   1.119 +		else
   1.120 +			break;
   1.121 +		}
   1.122 +		
   1.123 +	
   1.124 +	close(Port);
   1.125 +
   1.126 +	}
   1.127 +
   1.128 +int main(void)
   1.129 +	{
   1.130 +	Reader();
   1.131 +	return 0;
   1.132 +	}
   1.133 +