os/kernelhwsrv/kerneltest/e32test/examples/exdriver/exdriver_chnk/inc/exchnk.inl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/examples/exdriver/exdriver_chnk/inc/exchnk.inl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,322 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// This is an inline file and has the implementation of RExDriverChannel 
    1.18 +// derived from RBusLogicalChannel class. The member functions will 
    1.19 +// basically be wrappers of RBusLogicalChannel API.
    1.20 +// This file is included in exchnk.h
    1.21 +// 
    1.22 +//
    1.23 +
    1.24 +#ifndef __KERNEL_MODE__
    1.25 +/** 
    1.26 + VersionRequired() inline function to initialize TVersion object with 
    1.27 + driver Major number, Minor number and Build version number. This function
    1.28 + is provided just as a utility function to easily get the version details.
    1.29 + 
    1.30 + @return	initialized TVersion object
    1.31 + */
    1.32 +inline TVersion RExDriverChannel::VersionRequired()
    1.33 +	{	
    1.34 +	return (TVersion(EUartMajorVersionNumber,
    1.35 +					EUartMinorVersionNumber,
    1.36 +					EUartBuildVersionNumber));
    1.37 +	}
    1.38 +
    1.39 +/**
    1.40 + Open the driver for the specified unit. Unit information is passed as an 
    1.41 + argument by the user. User can open the driver for different units as supported
    1.42 + by the driver.
    1.43 + 
    1.44 + @param	aUnit
    1.45 + 		device unit number
    1.46 + 		
    1.47 + @return	return value of DoCreate(), i.e KErrNone or standard error code
    1.48 + */ 
    1.49 +inline TInt RExDriverChannel::Open(TInt aUnit)
    1.50 +	{
    1.51 +	// Call DoCreate() API of RBusLogicalChannel with driver name, 
    1.52 +	// version, unit number and owner. This will result in creating the 
    1.53 +	// logical channel by invoking Create() and DoCreate() of Logical Channel. 	
    1.54 +	//
    1.55 +	return DoCreate(KDriverName,VersionRequired(),aUnit,NULL,NULL,EOwnerThread);
    1.56 +	}
    1.57 +
    1.58 +/**
    1.59 + Gets the capabilities of a channel opened on the driver. User can use the
    1.60 + retrieved capabilities to configure different channels (if supported by 
    1.61 + driver) with supported configuration.
    1.62 + 
    1.63 + @param	aCaps
    1.64 + 		Descriptor to be filled with channel capabilities
    1.65 + 
    1.66 + @return	return value of DoControl(), i.e KErrNone or standard error code
    1.67 + */
    1.68 +inline TInt RExDriverChannel::Caps(TDes8& aCaps)
    1.69 +	{	
    1.70 +	// Call DoControl() API of RBusLogicalChannel with the request number 
    1.71 +	// and the caps buffer(structure) that has to be filled by the driver. 
    1.72 +	// This is a synchronous message and will be handled in driver/LDD 
    1.73 +	// DoControl() function
    1.74 +	//
    1.75 +	return DoControl(EControlCaps,(TAny*)&aCaps);
    1.76 +	}
    1.77 +		
    1.78 +/**
    1.79 + Configure the device (uart) internal loopback mode. User can configure the
    1.80 + device for internal loopback mode using this API. Loopback mode can be enabled 
    1.81 + or disabled by passing the mode as a parameter to this API.
    1.82 +
    1.83 + @param		aMode
    1.84 +			Holds the loopback enable and disable option
    1.85 +			KLoopbackEnable for enable and KLoopbackDisable for disable
    1.86 + 
    1.87 + @return	return value of DoControl(), i.e KErrNone or standard error code
    1.88 + */
    1.89 +inline TInt RExDriverChannel::SetIntLoopback(const TInt aMode)
    1.90 +	{	
    1.91 +	// Call DoControl() API of RBusLogicalChannel with the request number 
    1.92 +	// and the loopback mode. This is a synchronous message
    1.93 +	// and will be handled in driver/LDD DoControl() function
    1.94 +	//
    1.95 +	return DoControl(EControlSetIntLoopback,(TAny*)&aMode);
    1.96 +	}
    1.97 +	
    1.98 +/**
    1.99 + Configure the device (uart) for the specified settings. User initializes the 
   1.100 + configuration buffer, and passes this to the device driver. The config data 
   1.101 + structure is packaged as a buffer and passes as an argument.
   1.102 + 
   1.103 + @param	aConfig
   1.104 + 		buffer descriptor with device configuration information
   1.105 + 
   1.106 + @return	return value of DoControl(), i.e KErrNone or standard error code
   1.107 + */
   1.108 +inline TInt RExDriverChannel::SetConfig(const TDesC8& aConfig)
   1.109 +	{	
   1.110 +	// Call DoControl() API of RBusLogicalChannel with the request number 
   1.111 +	// and the config buffer(structure). This is a synchronous message
   1.112 +	// and will be handled in driver/LDD DoControl() function
   1.113 +	//
   1.114 +	return DoControl(EControlSetConfig,(TAny*)&aConfig);
   1.115 +	}
   1.116 +	
   1.117 +/**
   1.118 + Transmit the data to the device.It returns immediately after initiating
   1.119 + the transmit. The actual request completes asynchronously after the completion 
   1.120 + of the operation on the device and is notified then.
   1.121 + 
   1.122 + @param		aStatus
   1.123 + 			TRequestStatus object to hold the asynchronous request status
   1.124 + @param		aSize
   1.125 + 			Size of data to be transmitted
   1.126 + 
   1.127 + @return	KErrNone on success or KErrArgument on invalid length or offset.
   1.128 + */
   1.129 +inline TInt RExDriverChannel::TransmitData(TRequestStatus& aStatus, const TInt aSize,TInt aOffset)
   1.130 +	{
   1.131 +	
   1.132 +	// Invalid length or offset, return error
   1.133 +	if (aSize<=0 || aOffset<0)
   1.134 +		return KErrArgument;
   1.135 +		
   1.136 +	// Call DoRequest() API of RBusLogicalChannel with the request number,
   1.137 +	// TRequestStatus object to hold asynchronous request status, transmit buffer
   1.138 +	// and data length. This is a implemented as asynchronous message and will be
   1.139 +	// handled in driver/LDD DoRequest() function.Here the transmit buffer, aData
   1.140 +	// is filled by user and sent to the driver for writing to device.
   1.141 +	//
   1.142 +	DoRequest(ERequestTransmitData,aStatus,(TAny*)aOffset,(TAny*)aSize);
   1.143 +	
   1.144 +	return KErrNone;
   1.145 +	}
   1.146 +	
   1.147 +/** 
   1.148 + Receive the data from the device. User sends an empty buffer and reads the
   1.149 + data after the call. It returns immediately after initiating the receive. 
   1.150 + The actual request completes asynchronously after the completion of the 
   1.151 + operation on the device and is notified then.
   1.152 + 
   1.153 + @param		aStatus
   1.154 + 			TRequestStatus object to hold the asynchronous request status
   1.155 + 			 
   1.156 + @return	KErrNone on success or KErrArgument on invalid length
   1.157 + */
   1.158 +inline TInt RExDriverChannel::ReceiveData(TRequestStatus& aStatus,TInt aSize,TInt aOffset)
   1.159 +	{
   1.160 +			
   1.161 +	// Invalid length or offset, return error
   1.162 +	if (aSize<=0 || aOffset<0)
   1.163 +		return KErrArgument;
   1.164 +	// Call DoRequest() API of RBusLogicalChannel with the request number,
   1.165 +	// TRequestStatus object to hold asynchronous request status, receive buffer
   1.166 +	// and data length. This is a implemented as asynchronous message and will be
   1.167 +	// handled in driver/LDD DoRequest() function. Here, the receive buffer, aData
   1.168 +	// will be filled and returned with the received data by the driver read from 
   1.169 +	// the device.
   1.170 +	//
   1.171 +	DoRequest(ERequestReceiveData,aStatus,(TAny*)aOffset,(TAny*)aSize);
   1.172 +	
   1.173 +	return KErrNone;
   1.174 +	}
   1.175 +
   1.176 +/** 
   1.177 + Cancel Transmit request on the device. User can request to cancel any outstanding 
   1.178 + transmit requests. This request is handled by calling DoCancel() with appropriate
   1.179 + request mask
   1.180 +  
   1.181 + @param		none
   1.182 + 
   1.183 + @return	void
   1.184 + */
   1.185 +inline void RExDriverChannel::CancelTransmit()
   1.186 +	{
   1.187 +	// Call DoCancel() API of RBusLogicalChannel with the request number. This is 
   1.188 +	// handled in driver/LDD DoCancel() function. It will cancel the operation and 
   1.189 +	// also tidy up the request specific resources.
   1.190 +	//
   1.191 +	DoCancel(1<<ERequestTransmitData);
   1.192 +	}
   1.193 +
   1.194 +/** 
   1.195 + Cancel Receive request on the device. User can request to cancel any outstanding 
   1.196 + receive requests. This request is handled by calling DoCancel() with appropriate 
   1.197 + request mask. 
   1.198 +  
   1.199 + @param		none
   1.200 + 
   1.201 + @return	void
   1.202 + */
   1.203 +inline void RExDriverChannel::CancelReceive()
   1.204 +	{
   1.205 +	// Call DoCancel() API of RBusLogicalChannel with the request number. This is 
   1.206 +	// handled in driver/LDD DoCancel() function. It will cancel the operation and 
   1.207 +	// also tidy up the request specific resources.
   1.208 +	//
   1.209 +	DoCancel(1<<ERequestReceiveData);
   1.210 +	}
   1.211 +
   1.212 +
   1.213 +/** 
   1.214 + Get handle for Transmit chunk request on the device. User can request to get the
   1.215 + handle to Tx chunk by passing the appropriate aReqMask value. i.e EGetTxChunkHandle 
   1.216 +  
   1.217 + @param		aChunk
   1.218 + 			pointer to the chunk
   1.219 + 
   1.220 + @return	KErrNone on success, else standard error code
   1.221 + */	
   1.222 +inline TInt RExDriverChannel::GetTxChunkHandle(RChunk& aChunk)	
   1.223 +	{	
   1.224 +	TInt r;
   1.225 +	TInt handle;
   1.226 +	
   1.227 +	// Call DoControl() API of RBusLogicalChannel with the request number 
   1.228 +	// and the chunk reference. This is a synchronous message and will be
   1.229 +	// handled in driver/LDD DoControl() function
   1.230 +	//
   1.231 +	r = DoControl(EGetTxChunkHandle, (TAny*)&handle);	
   1.232 +	
   1.233 +	// Set the handle returned by the driver to the chunk. RChunk::SetHandle()
   1.234 +	// sets the specified handle value to the chunk.
   1.235 +	//
   1.236 +	if (r==KErrNone)
   1.237 +		aChunk.SetHandle(handle);		
   1.238 +	
   1.239 +	return r;
   1.240 +	}
   1.241 +
   1.242 +/** 
   1.243 + Get handle for Receive chunk request on the device. User can request to get the
   1.244 + handle to Rx chunk by passing the appropriate aReqMask value. i.e EGetTxChunkHandle 
   1.245 + 
   1.246 + @param		aChunk
   1.247 + 			pointer to the chunk
   1.248 + 			
   1.249 + @return	KErrNone on success, else standard error code
   1.250 + */	
   1.251 +inline TInt RExDriverChannel::GetRxChunkHandle(RChunk& aChunk)	
   1.252 +	{
   1.253 +	TInt r;
   1.254 +	TInt handle;
   1.255 +	
   1.256 +	// Call DoControl() API of RBusLogicalChannel with the request number 
   1.257 +	// and the chunk reference. This is a synchronous message and will be
   1.258 +	// handled in driver/LDD DoControl() function
   1.259 +	//
   1.260 +	r = DoControl(EGetRxChunkHandle, (TAny*)&handle);
   1.261 +	
   1.262 +	// Set the handle returned by the driver to the chunk. RChunk::SetHandle()
   1.263 +	// sets the specified handle value to the chunk.
   1.264 +	//
   1.265 +	if (r== KErrNone)	
   1.266 +		aChunk.SetHandle(handle);		
   1.267 +	
   1.268 +	return r;
   1.269 +	}
   1.270 +/** 
   1.271 + Pass the handle for Transmit chunk to the device. User can request to pass the
   1.272 + handle to Rx chunk by passing the appropriate aReqMask value. i.e EPassTxChunkHandle 
   1.273 +  
   1.274 + @param		aChunk
   1.275 + 			pointer to the chunk
   1.276 + 
   1.277 + @return	KErrNone on success, else standard error code
   1.278 + */	
   1.279 +inline TInt RExDriverChannel::PassTxChunkHandle(RChunk& aChunk)	
   1.280 +	{	
   1.281 +	TInt r;
   1.282 +	TInt handle;
   1.283 +	
   1.284 +	// Get the shared chunk handle.
   1.285 +	handle = aChunk.Handle();
   1.286 +	
   1.287 +	// Call DoControl() API of RBusLogicalChannel with the request number 
   1.288 +	// and the chunk reference. This is a synchronous message and will be
   1.289 +	// handled in driver/LDD DoControl() function
   1.290 +	//
   1.291 +	r = DoControl(EPassTxChunkHandle, (TAny*)&handle);	
   1.292 +		
   1.293 +	return r;
   1.294 +	}
   1.295 +
   1.296 +/** 
   1.297 + Pass the handle for Receive chunk to the device. User can request to pass the
   1.298 + handle to Rx chunk by passing the appropriate aReqMask value. i.e EPassRxChunkHandle 
   1.299 + 
   1.300 + @param		aChunk
   1.301 + 			pointer to the chunk
   1.302 + 			
   1.303 + @return	KErrNone on success, else standard error code
   1.304 + */	
   1.305 +inline TInt RExDriverChannel::PassRxChunkHandle(RChunk& aChunk)	
   1.306 +	{
   1.307 +	TInt r;
   1.308 +	TInt handle;
   1.309 +	
   1.310 +	// Get the shared chunk handle.
   1.311 +	handle = aChunk.Handle();
   1.312 +	// Call DoControl() API of RBusLogicalChannel with the request number 
   1.313 +	// and the chunk reference. This is a synchronous message and will be
   1.314 +	// handled in driver/LDD DoControl() function
   1.315 +	//
   1.316 +	r = DoControl(EPassRxChunkHandle, (TAny*)&handle);
   1.317 +		
   1.318 +	return r;
   1.319 +	}
   1.320 +#endif		
   1.321 +
   1.322 +	
   1.323 +//
   1.324 +// End of exchnk.inl
   1.325 +