os/ossrv/genericopenlibs/cstdlib/TSTLIB/tsersig.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
int GlobalPort;
sl@0
    30
sl@0
    31
/**
sl@0
    32
@SYMTestCaseID          SYSLIB-STDLIB-CT-1109
sl@0
    33
@SYMTestCaseDesc	    Tests for serial port
sl@0
    34
@SYMTestPriority 	    High
sl@0
    35
@SYMTestActions  	    Open and configures the serial ports
sl@0
    36
@SYMTestExpectedResults Test must not fail
sl@0
    37
@SYMREQ                 REQ0000
sl@0
    38
*/					
sl@0
    39
void OpenAndConfigure(void)
sl@0
    40
	{
sl@0
    41
	SerialConfig sc;
sl@0
    42
sl@0
    43
	GlobalPort = open("COM1:",0);
sl@0
    44
	(void)ioctl(GlobalPort, COMMIOCTL_GETCONFIG, &sc);
sl@0
    45
	sc.iRate = Bps57600;
sl@0
    46
	sc.iParity = ParityNone;
sl@0
    47
	(void)ioctl(GlobalPort, COMMIOCTL_SETCONFIG, &sc);
sl@0
    48
	}
sl@0
    49
sl@0
    50
/**
sl@0
    51
@SYMTestCaseID          SYSLIB-STDLIB-CT-1110
sl@0
    52
@SYMTestCaseDesc	    Tests for serial port
sl@0
    53
@SYMTestPriority 	    High
sl@0
    54
@SYMTestActions  	    Notifies a thread for events on port 
sl@0
    55
@SYMTestExpectedResults Test must not fail
sl@0
    56
@SYMREQ                 REQ0000
sl@0
    57
*/					
sl@0
    58
sl@0
    59
void WaitForNotifyThread(void)
sl@0
    60
	{
sl@0
    61
	int val[2];
sl@0
    62
	int ret = 0;
sl@0
    63
	int signals = 0;
sl@0
    64
sl@0
    65
	
sl@0
    66
	while (ret != -1)
sl@0
    67
		{
sl@0
    68
		val[0] = 0;
sl@0
    69
		val[1] = -1;
sl@0
    70
		ret = ioctl(GlobalPort, COMMIOCTL_NOTIFYSUPPORTED, &signals);
sl@0
    71
		val[0] = KNotifyDataAvailable;
sl@0
    72
		ret = ioctl(GlobalPort, COMMIOCTL_NOTIFY, &val[0]);
sl@0
    73
		if ((ret != -1) || (val[0] != KNotifyDataAvailable))
sl@0
    74
			printf("NotifyThread returned %d, val[0] %d when checking data available\n", ret, val[0]);
sl@0
    75
sl@0
    76
sl@0
    77
		val[0] = signals & ~KNotifyDataAvailable; //no data avail as it returns an error
sl@0
    78
		ret = ioctl(GlobalPort, COMMIOCTL_NOTIFY, &val[0]);
sl@0
    79
		printf("NotifyThread ret = %d, val[0] is %d, val[1] is %d, errno is %d\n", ret, val[0], val[1], errno);
sl@0
    80
sl@0
    81
		}
sl@0
    82
	}
sl@0
    83
sl@0
    84
/**
sl@0
    85
@SYMTestCaseID          SYSLIB-STDLIB-CT-1111
sl@0
    86
@SYMTestCaseDesc	    Tests for serial port
sl@0
    87
@SYMTestPriority 	    High
sl@0
    88
@SYMTestActions  	    Keep reading infinitely from the port
sl@0
    89
@SYMTestExpectedResults Test must not fail
sl@0
    90
@SYMREQ                 REQ0000
sl@0
    91
*/					
sl@0
    92
void readloop(void)
sl@0
    93
	{
sl@0
    94
	char buf[100];
sl@0
    95
	int readcount = 10;
sl@0
    96
sl@0
    97
	while (readcount-- > 0)
sl@0
    98
		{
sl@0
    99
		read(GlobalPort, buf, 100);
sl@0
   100
		printf("ReadThread got %x\n", buf[0]);
sl@0
   101
		}
sl@0
   102
	}
sl@0
   103
sl@0
   104
int main(void)
sl@0
   105
	{
sl@0
   106
	void* t1;
sl@0
   107
	void*t2;
sl@0
   108
sl@0
   109
	start_posix_server();	/* calls SpawnPosixServer from C++ code */
sl@0
   110
sl@0
   111
	OpenAndConfigure();
sl@0
   112
sl@0
   113
sl@0
   114
	t1 = create_thread(WaitForNotifyThread, "notify");
sl@0
   115
	t2 = create_thread(readloop, "readloop");
sl@0
   116
sl@0
   117
	start_thread(t1);
sl@0
   118
	start_thread(t2);
sl@0
   119
sl@0
   120
	(void)wait_for_thread(t2);
sl@0
   121
	close(GlobalPort);		//closing the port will force a notify
sl@0
   122
	(void)wait_for_thread(t1);
sl@0
   123
	
sl@0
   124
	return 0;
sl@0
   125
	}
sl@0
   126