os/ossrv/genericopenlibs/cstdlib/TSTLIB/tser2w.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 *
    16 */
    17 
    18 
    19 
    20 #include <stdlib.h>	/* definition of exit() */
    21 #include <stdio.h>
    22 #include <errno.h>
    23 #include <string.h>
    24 #include <sys/unistd.h>
    25 #include <sys/ioctl.h>
    26 #include "CTEST.H"
    27 
    28 
    29 
    30 #define SIZE 10000
    31 
    32 /**
    33 @SYMTestCaseID          SYSLIB-STDLIB-CT-1100
    34 @SYMTestCaseDesc	    Tests for writing to the serial port
    35 @SYMTestPriority 	    High
    36 @SYMTestActions  	    Tests for writing a buffer of size 1000 bytes to the serial port
    37 @SYMTestExpectedResults Test must not fail
    38 @SYMREQ                 REQ0000
    39 */		
    40 void Writer(void)
    41 	{
    42 	int Port;
    43 	SerialConfig sc;
    44 	char *buffer;
    45 
    46 	Port = open("COM1:",0);
    47 	(void)ioctl(Port, COMMIOCTL_GETCONFIG, &sc);
    48 	sc.iRate = Bps115200;
    49 	sc.iParity = ParityNone;
    50 	(void)ioctl(Port, COMMIOCTL_SETCONFIG, &sc);
    51 	
    52 	buffer = (char*)malloc(SIZE);
    53 	memset(buffer, '*', SIZE);
    54 
    55 	printf("writing monster block\n");
    56 	write(Port, buffer, SIZE);
    57 
    58 
    59 	printf("press a key\n");
    60 	getchar();
    61 	
    62 	printf("writing monster block again\n");
    63 	write(Port, buffer, SIZE);
    64 	
    65 	close(Port);
    66 
    67 	}
    68 
    69 void Reader(void)
    70 	{
    71 	int res;
    72 	int Port;
    73 	SerialConfig sc;
    74 	char *buffer, *p;
    75 
    76 	Port = open("COM1:",0);
    77 	res = ioctl(Port, COMMIOCTL_GETCONFIG, &sc);
    78 	sc.iRate = Bps115200;
    79 	sc.iParity = ParityNone;
    80 	res = ioctl(Port, COMMIOCTL_SETCONFIG, &sc);
    81 	
    82 	buffer = (char*)malloc(SIZE);
    83 
    84 	res = 0;
    85 	p = buffer;
    86 
    87 	for(;;)
    88 		{
    89 		res = read(Port, p, 100);
    90 		if (res > 0)
    91 			p += res;
    92 		else
    93 			break;
    94 		}
    95 		
    96 		
    97 	
    98 	close(Port);
    99 
   100 	}
   101 
   102 int main(void)
   103 	{
   104 	Writer();
   105 	return 0;
   106 	}
   107