os/kernelhwsrv/kerneltest/e32test/examples/exdriver/exdriver_chnk/inc/exchnk.inl
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // This is an inline file and has the implementation of RExDriverChannel 
    15 // derived from RBusLogicalChannel class. The member functions will 
    16 // basically be wrappers of RBusLogicalChannel API.
    17 // This file is included in exchnk.h
    18 // 
    19 //
    20 
    21 #ifndef __KERNEL_MODE__
    22 /** 
    23  VersionRequired() inline function to initialize TVersion object with 
    24  driver Major number, Minor number and Build version number. This function
    25  is provided just as a utility function to easily get the version details.
    26  
    27  @return	initialized TVersion object
    28  */
    29 inline TVersion RExDriverChannel::VersionRequired()
    30 	{	
    31 	return (TVersion(EUartMajorVersionNumber,
    32 					EUartMinorVersionNumber,
    33 					EUartBuildVersionNumber));
    34 	}
    35 
    36 /**
    37  Open the driver for the specified unit. Unit information is passed as an 
    38  argument by the user. User can open the driver for different units as supported
    39  by the driver.
    40  
    41  @param	aUnit
    42  		device unit number
    43  		
    44  @return	return value of DoCreate(), i.e KErrNone or standard error code
    45  */ 
    46 inline TInt RExDriverChannel::Open(TInt aUnit)
    47 	{
    48 	// Call DoCreate() API of RBusLogicalChannel with driver name, 
    49 	// version, unit number and owner. This will result in creating the 
    50 	// logical channel by invoking Create() and DoCreate() of Logical Channel. 	
    51 	//
    52 	return DoCreate(KDriverName,VersionRequired(),aUnit,NULL,NULL,EOwnerThread);
    53 	}
    54 
    55 /**
    56  Gets the capabilities of a channel opened on the driver. User can use the
    57  retrieved capabilities to configure different channels (if supported by 
    58  driver) with supported configuration.
    59  
    60  @param	aCaps
    61  		Descriptor to be filled with channel capabilities
    62  
    63  @return	return value of DoControl(), i.e KErrNone or standard error code
    64  */
    65 inline TInt RExDriverChannel::Caps(TDes8& aCaps)
    66 	{	
    67 	// Call DoControl() API of RBusLogicalChannel with the request number 
    68 	// and the caps buffer(structure) that has to be filled by the driver. 
    69 	// This is a synchronous message and will be handled in driver/LDD 
    70 	// DoControl() function
    71 	//
    72 	return DoControl(EControlCaps,(TAny*)&aCaps);
    73 	}
    74 		
    75 /**
    76  Configure the device (uart) internal loopback mode. User can configure the
    77  device for internal loopback mode using this API. Loopback mode can be enabled 
    78  or disabled by passing the mode as a parameter to this API.
    79 
    80  @param		aMode
    81 			Holds the loopback enable and disable option
    82 			KLoopbackEnable for enable and KLoopbackDisable for disable
    83  
    84  @return	return value of DoControl(), i.e KErrNone or standard error code
    85  */
    86 inline TInt RExDriverChannel::SetIntLoopback(const TInt aMode)
    87 	{	
    88 	// Call DoControl() API of RBusLogicalChannel with the request number 
    89 	// and the loopback mode. This is a synchronous message
    90 	// and will be handled in driver/LDD DoControl() function
    91 	//
    92 	return DoControl(EControlSetIntLoopback,(TAny*)&aMode);
    93 	}
    94 	
    95 /**
    96  Configure the device (uart) for the specified settings. User initializes the 
    97  configuration buffer, and passes this to the device driver. The config data 
    98  structure is packaged as a buffer and passes as an argument.
    99  
   100  @param	aConfig
   101  		buffer descriptor with device configuration information
   102  
   103  @return	return value of DoControl(), i.e KErrNone or standard error code
   104  */
   105 inline TInt RExDriverChannel::SetConfig(const TDesC8& aConfig)
   106 	{	
   107 	// Call DoControl() API of RBusLogicalChannel with the request number 
   108 	// and the config buffer(structure). This is a synchronous message
   109 	// and will be handled in driver/LDD DoControl() function
   110 	//
   111 	return DoControl(EControlSetConfig,(TAny*)&aConfig);
   112 	}
   113 	
   114 /**
   115  Transmit the data to the device.It returns immediately after initiating
   116  the transmit. The actual request completes asynchronously after the completion 
   117  of the operation on the device and is notified then.
   118  
   119  @param		aStatus
   120  			TRequestStatus object to hold the asynchronous request status
   121  @param		aSize
   122  			Size of data to be transmitted
   123  
   124  @return	KErrNone on success or KErrArgument on invalid length or offset.
   125  */
   126 inline TInt RExDriverChannel::TransmitData(TRequestStatus& aStatus, const TInt aSize,TInt aOffset)
   127 	{
   128 	
   129 	// Invalid length or offset, return error
   130 	if (aSize<=0 || aOffset<0)
   131 		return KErrArgument;
   132 		
   133 	// Call DoRequest() API of RBusLogicalChannel with the request number,
   134 	// TRequestStatus object to hold asynchronous request status, transmit buffer
   135 	// and data length. This is a implemented as asynchronous message and will be
   136 	// handled in driver/LDD DoRequest() function.Here the transmit buffer, aData
   137 	// is filled by user and sent to the driver for writing to device.
   138 	//
   139 	DoRequest(ERequestTransmitData,aStatus,(TAny*)aOffset,(TAny*)aSize);
   140 	
   141 	return KErrNone;
   142 	}
   143 	
   144 /** 
   145  Receive the data from the device. User sends an empty buffer and reads the
   146  data after the call. It returns immediately after initiating the receive. 
   147  The actual request completes asynchronously after the completion of the 
   148  operation on the device and is notified then.
   149  
   150  @param		aStatus
   151  			TRequestStatus object to hold the asynchronous request status
   152  			 
   153  @return	KErrNone on success or KErrArgument on invalid length
   154  */
   155 inline TInt RExDriverChannel::ReceiveData(TRequestStatus& aStatus,TInt aSize,TInt aOffset)
   156 	{
   157 			
   158 	// Invalid length or offset, return error
   159 	if (aSize<=0 || aOffset<0)
   160 		return KErrArgument;
   161 	// Call DoRequest() API of RBusLogicalChannel with the request number,
   162 	// TRequestStatus object to hold asynchronous request status, receive buffer
   163 	// and data length. This is a implemented as asynchronous message and will be
   164 	// handled in driver/LDD DoRequest() function. Here, the receive buffer, aData
   165 	// will be filled and returned with the received data by the driver read from 
   166 	// the device.
   167 	//
   168 	DoRequest(ERequestReceiveData,aStatus,(TAny*)aOffset,(TAny*)aSize);
   169 	
   170 	return KErrNone;
   171 	}
   172 
   173 /** 
   174  Cancel Transmit request on the device. User can request to cancel any outstanding 
   175  transmit requests. This request is handled by calling DoCancel() with appropriate
   176  request mask
   177   
   178  @param		none
   179  
   180  @return	void
   181  */
   182 inline void RExDriverChannel::CancelTransmit()
   183 	{
   184 	// Call DoCancel() API of RBusLogicalChannel with the request number. This is 
   185 	// handled in driver/LDD DoCancel() function. It will cancel the operation and 
   186 	// also tidy up the request specific resources.
   187 	//
   188 	DoCancel(1<<ERequestTransmitData);
   189 	}
   190 
   191 /** 
   192  Cancel Receive request on the device. User can request to cancel any outstanding 
   193  receive requests. This request is handled by calling DoCancel() with appropriate 
   194  request mask. 
   195   
   196  @param		none
   197  
   198  @return	void
   199  */
   200 inline void RExDriverChannel::CancelReceive()
   201 	{
   202 	// Call DoCancel() API of RBusLogicalChannel with the request number. This is 
   203 	// handled in driver/LDD DoCancel() function. It will cancel the operation and 
   204 	// also tidy up the request specific resources.
   205 	//
   206 	DoCancel(1<<ERequestReceiveData);
   207 	}
   208 
   209 
   210 /** 
   211  Get handle for Transmit chunk request on the device. User can request to get the
   212  handle to Tx chunk by passing the appropriate aReqMask value. i.e EGetTxChunkHandle 
   213   
   214  @param		aChunk
   215  			pointer to the chunk
   216  
   217  @return	KErrNone on success, else standard error code
   218  */	
   219 inline TInt RExDriverChannel::GetTxChunkHandle(RChunk& aChunk)	
   220 	{	
   221 	TInt r;
   222 	TInt handle;
   223 	
   224 	// Call DoControl() API of RBusLogicalChannel with the request number 
   225 	// and the chunk reference. This is a synchronous message and will be
   226 	// handled in driver/LDD DoControl() function
   227 	//
   228 	r = DoControl(EGetTxChunkHandle, (TAny*)&handle);	
   229 	
   230 	// Set the handle returned by the driver to the chunk. RChunk::SetHandle()
   231 	// sets the specified handle value to the chunk.
   232 	//
   233 	if (r==KErrNone)
   234 		aChunk.SetHandle(handle);		
   235 	
   236 	return r;
   237 	}
   238 
   239 /** 
   240  Get handle for Receive chunk request on the device. User can request to get the
   241  handle to Rx chunk by passing the appropriate aReqMask value. i.e EGetTxChunkHandle 
   242  
   243  @param		aChunk
   244  			pointer to the chunk
   245  			
   246  @return	KErrNone on success, else standard error code
   247  */	
   248 inline TInt RExDriverChannel::GetRxChunkHandle(RChunk& aChunk)	
   249 	{
   250 	TInt r;
   251 	TInt handle;
   252 	
   253 	// Call DoControl() API of RBusLogicalChannel with the request number 
   254 	// and the chunk reference. This is a synchronous message and will be
   255 	// handled in driver/LDD DoControl() function
   256 	//
   257 	r = DoControl(EGetRxChunkHandle, (TAny*)&handle);
   258 	
   259 	// Set the handle returned by the driver to the chunk. RChunk::SetHandle()
   260 	// sets the specified handle value to the chunk.
   261 	//
   262 	if (r== KErrNone)	
   263 		aChunk.SetHandle(handle);		
   264 	
   265 	return r;
   266 	}
   267 /** 
   268  Pass the handle for Transmit chunk to the device. User can request to pass the
   269  handle to Rx chunk by passing the appropriate aReqMask value. i.e EPassTxChunkHandle 
   270   
   271  @param		aChunk
   272  			pointer to the chunk
   273  
   274  @return	KErrNone on success, else standard error code
   275  */	
   276 inline TInt RExDriverChannel::PassTxChunkHandle(RChunk& aChunk)	
   277 	{	
   278 	TInt r;
   279 	TInt handle;
   280 	
   281 	// Get the shared chunk handle.
   282 	handle = aChunk.Handle();
   283 	
   284 	// Call DoControl() API of RBusLogicalChannel with the request number 
   285 	// and the chunk reference. This is a synchronous message and will be
   286 	// handled in driver/LDD DoControl() function
   287 	//
   288 	r = DoControl(EPassTxChunkHandle, (TAny*)&handle);	
   289 		
   290 	return r;
   291 	}
   292 
   293 /** 
   294  Pass the handle for Receive chunk to the device. User can request to pass the
   295  handle to Rx chunk by passing the appropriate aReqMask value. i.e EPassRxChunkHandle 
   296  
   297  @param		aChunk
   298  			pointer to the chunk
   299  			
   300  @return	KErrNone on success, else standard error code
   301  */	
   302 inline TInt RExDriverChannel::PassRxChunkHandle(RChunk& aChunk)	
   303 	{
   304 	TInt r;
   305 	TInt handle;
   306 	
   307 	// Get the shared chunk handle.
   308 	handle = aChunk.Handle();
   309 	// Call DoControl() API of RBusLogicalChannel with the request number 
   310 	// and the chunk reference. This is a synchronous message and will be
   311 	// handled in driver/LDD DoControl() function
   312 	//
   313 	r = DoControl(EPassRxChunkHandle, (TAny*)&handle);
   314 		
   315 	return r;
   316 	}
   317 #endif		
   318 
   319 	
   320 //
   321 // End of exchnk.inl
   322