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.
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
@SYMTestCaseID          SYSLIB-STDLIB-CT-1100
sl@0
    34
@SYMTestCaseDesc	    Tests for writing to the serial port
sl@0
    35
@SYMTestPriority 	    High
sl@0
    36
@SYMTestActions  	    Tests for writing a buffer of size 1000 bytes to the serial port
sl@0
    37
@SYMTestExpectedResults Test must not fail
sl@0
    38
@SYMREQ                 REQ0000
sl@0
    39
*/		
sl@0
    40
void Writer(void)
sl@0
    41
	{
sl@0
    42
	int Port;
sl@0
    43
	SerialConfig sc;
sl@0
    44
	char *buffer;
sl@0
    45
sl@0
    46
	Port = open("COM1:",0);
sl@0
    47
	(void)ioctl(Port, COMMIOCTL_GETCONFIG, &sc);
sl@0
    48
	sc.iRate = Bps115200;
sl@0
    49
	sc.iParity = ParityNone;
sl@0
    50
	(void)ioctl(Port, COMMIOCTL_SETCONFIG, &sc);
sl@0
    51
	
sl@0
    52
	buffer = (char*)malloc(SIZE);
sl@0
    53
	memset(buffer, '*', SIZE);
sl@0
    54
sl@0
    55
	printf("writing monster block\n");
sl@0
    56
	write(Port, buffer, SIZE);
sl@0
    57
sl@0
    58
sl@0
    59
	printf("press a key\n");
sl@0
    60
	getchar();
sl@0
    61
	
sl@0
    62
	printf("writing monster block again\n");
sl@0
    63
	write(Port, buffer, SIZE);
sl@0
    64
	
sl@0
    65
	close(Port);
sl@0
    66
sl@0
    67
	}
sl@0
    68
sl@0
    69
void Reader(void)
sl@0
    70
	{
sl@0
    71
	int res;
sl@0
    72
	int Port;
sl@0
    73
	SerialConfig sc;
sl@0
    74
	char *buffer, *p;
sl@0
    75
sl@0
    76
	Port = open("COM1:",0);
sl@0
    77
	res = ioctl(Port, COMMIOCTL_GETCONFIG, &sc);
sl@0
    78
	sc.iRate = Bps115200;
sl@0
    79
	sc.iParity = ParityNone;
sl@0
    80
	res = ioctl(Port, COMMIOCTL_SETCONFIG, &sc);
sl@0
    81
	
sl@0
    82
	buffer = (char*)malloc(SIZE);
sl@0
    83
sl@0
    84
	res = 0;
sl@0
    85
	p = buffer;
sl@0
    86
sl@0
    87
	for(;;)
sl@0
    88
		{
sl@0
    89
		res = read(Port, p, 100);
sl@0
    90
		if (res > 0)
sl@0
    91
			p += res;
sl@0
    92
		else
sl@0
    93
			break;
sl@0
    94
		}
sl@0
    95
		
sl@0
    96
		
sl@0
    97
	
sl@0
    98
	close(Port);
sl@0
    99
sl@0
   100
	}
sl@0
   101
sl@0
   102
int main(void)
sl@0
   103
	{
sl@0
   104
	Writer();
sl@0
   105
	return 0;
sl@0
   106
	}
sl@0
   107