os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/hostbulktransfers.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// @file hostcontroltransfers.cpp
sl@0
    15
// @internalComponent
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include "hosttransfers.h"
sl@0
    20
#include <e32debug.h>
sl@0
    21
sl@0
    22
namespace NUnitTesting_USBDI
sl@0
    23
	{
sl@0
    24
	
sl@0
    25
	
sl@0
    26
CBulkTransfer::CBulkTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,TInt aMaxTransferSize,MTransferObserver& aObserver,TInt aTransferId)
sl@0
    27
:	CBaseTransfer(aPipe,aInterface,aObserver,aTransferId),
sl@0
    28
	iTransferDescriptor(aMaxTransferSize) // Allocate the buffer for bulk transfers
sl@0
    29
	{
sl@0
    30
sl@0
    31
	// Register the transfer descriptor with the interface
sl@0
    32
	
sl@0
    33
	TInt err(Interface().RegisterTransferDescriptor(iTransferDescriptor));
sl@0
    34
	if(err != KErrNone)
sl@0
    35
		{
sl@0
    36
		RDebug::Printf("<Error %d> Unable to register transfer descriptor",err);
sl@0
    37
		}
sl@0
    38
	}
sl@0
    39
	
sl@0
    40
	
sl@0
    41
CBulkTransfer::~CBulkTransfer()
sl@0
    42
	{
sl@0
    43
	LOG_FUNC
sl@0
    44
	
sl@0
    45
	// Cancel the transfer
sl@0
    46
sl@0
    47
	Cancel();
sl@0
    48
	}
sl@0
    49
	
sl@0
    50
	
sl@0
    51
TPtrC8 CBulkTransfer::DataPolled()
sl@0
    52
	{
sl@0
    53
	return iTransferDescriptor.Buffer();
sl@0
    54
	}
sl@0
    55
sl@0
    56
sl@0
    57
void CBulkTransfer::TransferIn(TInt aExpectedDataSize)
sl@0
    58
	{
sl@0
    59
	LOG_FUNC
sl@0
    60
	
sl@0
    61
	// Activate the asynchronous transfer 
sl@0
    62
	
sl@0
    63
	RDebug::Printf("Activating bulk in transfer");
sl@0
    64
	iTransferDescriptor.SaveData(aExpectedDataSize);
sl@0
    65
	Pipe().Transfer(iTransferDescriptor,iStatus);
sl@0
    66
	SetActive();
sl@0
    67
	}
sl@0
    68
sl@0
    69
void CBulkTransfer::TransferOut(const TDesC8& aBulkData, TBool aUseZLPIfRequired)
sl@0
    70
	{
sl@0
    71
	LOG_FUNC
sl@0
    72
sl@0
    73
	// Copy the data across
sl@0
    74
	if(aBulkData.Length() > iTransferDescriptor.iMaxSize)
sl@0
    75
		{
sl@0
    76
		RDebug::Printf("Too much data in bulk transfer. This test suite will now PANIC!");
sl@0
    77
		RDebug::Printf("Bytes requested %d, Max allowed %d", aBulkData.Length(), iTransferDescriptor.iMaxSize);
sl@0
    78
		ASSERT(EFalse);
sl@0
    79
		}
sl@0
    80
		
sl@0
    81
	TPtr8 buffer = iTransferDescriptor.WritableBuffer();
sl@0
    82
	buffer.Copy(aBulkData);
sl@0
    83
	RDebug::Printf("Transfer buffer now has %d bytes to write",buffer.Length());
sl@0
    84
	iTransferDescriptor.SaveData(buffer.Length());
sl@0
    85
	if(aUseZLPIfRequired)
sl@0
    86
		{
sl@0
    87
		iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESendZlpIfRequired); 
sl@0
    88
		}
sl@0
    89
	else
sl@0
    90
		{
sl@0
    91
		iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESuppressZlp);
sl@0
    92
		}
sl@0
    93
	
sl@0
    94
	// Activate the asynchronous transfer 
sl@0
    95
	
sl@0
    96
	RDebug::Printf("Activating bulk out transfer");
sl@0
    97
	Pipe().Transfer(iTransferDescriptor,iStatus);
sl@0
    98
	SetActive();
sl@0
    99
	}
sl@0
   100
sl@0
   101
void CBulkTransfer::TransferOut(const TDesC8& aBulkDataPattern, TUint aNumBytes, TBool aUseZLPIfRequired)
sl@0
   102
	{
sl@0
   103
	LOG_FUNC
sl@0
   104
	
sl@0
   105
	TransferOut(aBulkDataPattern, 0, aNumBytes, aUseZLPIfRequired);
sl@0
   106
	}
sl@0
   107
sl@0
   108
sl@0
   109
void CBulkTransfer::TransferOut(const TDesC8& aBulkDataPattern, TUint aStartPoint, TUint aNumBytes, TBool aUseZLPIfRequired)
sl@0
   110
	{
sl@0
   111
	LOG_FUNC
sl@0
   112
sl@0
   113
	// Copy the data across
sl@0
   114
	if(aNumBytes > iTransferDescriptor.iMaxSize)
sl@0
   115
		{
sl@0
   116
		RDebug::Printf("Too much data in bulk transfer. This test suite will now PANIC!");
sl@0
   117
		RDebug::Printf("Bytes requested %d, Max allowed %d", aNumBytes, iTransferDescriptor.iMaxSize);
sl@0
   118
		ASSERT(EFalse);
sl@0
   119
		}
sl@0
   120
	if(aBulkDataPattern.Length()<=0)
sl@0
   121
		{
sl@0
   122
		RDebug::Printf("ZERO LENGTH data pattern used in TransferOut. This test suite will now PANIC!");
sl@0
   123
		ASSERT(EFalse);
sl@0
   124
		}
sl@0
   125
	TUint startPoint = aStartPoint%aBulkDataPattern.Length();
sl@0
   126
	TUint numStartBytes = (aBulkDataPattern.Length() - startPoint)%aBulkDataPattern.Length();
sl@0
   127
	TUint fullRepeats = (aNumBytes-numStartBytes)/aBulkDataPattern.Length();
sl@0
   128
	TUint numEndBytes = aNumBytes - fullRepeats*aBulkDataPattern.Length() - numStartBytes;
sl@0
   129
	TPtr8 buffer = iTransferDescriptor.WritableBuffer();
sl@0
   130
	buffer.Zero(); //set length to zero
sl@0
   131
	if(numStartBytes)
sl@0
   132
		{
sl@0
   133
		buffer.Append(aBulkDataPattern.Right(numStartBytes));
sl@0
   134
		}
sl@0
   135
	for(TUint i = 0; i<fullRepeats; i++)
sl@0
   136
		{
sl@0
   137
		buffer.Append(aBulkDataPattern);
sl@0
   138
		}
sl@0
   139
	if(numEndBytes)
sl@0
   140
		{
sl@0
   141
		buffer.Append(aBulkDataPattern.Left(numEndBytes));
sl@0
   142
		}
sl@0
   143
	RDebug::Printf("Transfer buffer now has %d bytes to write",buffer.Length());
sl@0
   144
	iTransferDescriptor.SaveData(buffer.Length());	
sl@0
   145
	if(aUseZLPIfRequired)
sl@0
   146
		{
sl@0
   147
		iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESendZlpIfRequired); 
sl@0
   148
		}
sl@0
   149
	else
sl@0
   150
		{
sl@0
   151
		iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESuppressZlp);
sl@0
   152
		}
sl@0
   153
	
sl@0
   154
	// Activate the asynchronous transfer 
sl@0
   155
	
sl@0
   156
	RDebug::Printf("Activating bulk out transfer");
sl@0
   157
	Pipe().Transfer(iTransferDescriptor,iStatus);
sl@0
   158
	SetActive();
sl@0
   159
	}
sl@0
   160
sl@0
   161
	}