os/kernelhwsrv/kerneltest/e32test/examples/exdriver/exdriver_int/inc/exint.inl
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
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 exint.h
    18 // 
    19 //
    20 
    21 /**
    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 */
    30 inline TVersion RExDriverChannel::VersionRequired()
    31 	{	
    32 	return (TVersion(EUartMajorVersionNumber,
    33 					EUartMinorVersionNumber,
    34 					EUartBuildVersionNumber));
    35 	}
    36 
    37 /**
    38  Open the driver for the specified unit. Unit information is passed as an 
    39  argument by the user. User can open the driver for different units as supported
    40  by the driver.
    41  
    42  @param	aUnit
    43  		device unit number
    44  		
    45  @return	return value of DoCreate(), i.e KErrNone or standard error code
    46  */ 
    47 inline TInt RExDriverChannel::Open(TInt aUnit)
    48 	{
    49 	// Call DoCreate() API of RBusLogicalChannel with driver name, 
    50 	// version, unit number and owner. This will result in creating the 
    51 	// logical channel by invoking Create() and DoCreate() of Logical Channel. 	
    52 	//
    53 	return DoCreate(KDriverName,VersionRequired(),aUnit,NULL,NULL,EOwnerThread);
    54 	}
    55 
    56 /**
    57  Gets the capabilities of a channel opened on the driver. User can use the
    58  retrieved capabilities to configure different channels (if supported by 
    59  driver) with supported configuration.
    60  
    61  @param	aCaps
    62  		Descriptor to be filled with channel capabilities
    63  
    64  @return	return value of DoControl(), i.e KErrNone or standard error code
    65  */
    66 inline TInt RExDriverChannel::Caps(TDes8& aCaps)
    67 	{	
    68 	// Call DoControl() API of RBusLogicalChannel with the request number 
    69 	// and the caps buffer(structure) that has to be filled by the driver. 
    70 	// This is a synchronous message and will be handled in driver/LDD 
    71 	// DoControl() function
    72 	//
    73 	return DoControl(EControlCaps,(TAny*)&aCaps);
    74 	}
    75 		
    76 /**
    77  Configure the device (uart) internal loopback mode. User can configure the
    78  device for internal loopback mode using this API. Loopback mode can be enabled 
    79  or disabled by passing the mode as a parameter to this API.
    80 
    81  @param		aMode
    82 			Holds the loopback enable and disable option
    83 			KLoopbackEnable for enable and KLoopbackDisable for disable
    84  
    85  @return	return value of DoControl(), i.e KErrNone or standard error code
    86  */
    87 inline TInt RExDriverChannel::SetIntLoopback(const TInt aMode)
    88 	{	
    89 	// Call DoControl() API of RBusLogicalChannel with the request number 
    90 	// and the loopback mode. This is a synchronous message
    91 	// and will be handled in driver/LDD DoControl() function
    92 	//
    93 	return DoControl(EControlSetIntLoopback,(TAny*)&aMode);
    94 	}
    95 	
    96 /**
    97  Configure the device (uart) for the specified settings. User initializes the 
    98  configuration buffer, and passes this to the device driver. The config data 
    99  structure is packaged as a buffer and passes as an argument.
   100  
   101  @param	aConfig
   102  		buffer descriptor with device configuration information
   103  
   104  @return	return value of DoControl(), i.e KErrNone or standard error code
   105  */
   106 inline TInt RExDriverChannel::SetConfig(const TDesC8& aConfig)
   107 	{	
   108 	// Call DoControl() API of RBusLogicalChannel with the request number 
   109 	// and the config buffer(structure). This is a synchronous message
   110 	// and will be handled in driver/LDD DoControl() function
   111 	//
   112 	return DoControl(EControlSetConfig,(TAny*)&aConfig);
   113 	}
   114 	
   115 /**
   116  Transmit the data to the device. User initializes the buffer and sends the 
   117  the buffer descriptor as an argument. It returns immediately after initiating
   118  the transmit. The actual request completes asynchronously after the completion 
   119  of the operation on the device and is notified then.
   120  
   121  @param		aStatus
   122  			TRequestStatus object to hold the asynchronous request status
   123  @param		aData
   124  			buffer holding the data to transmit
   125  
   126  @return	KErrNone on success or KErrArgument on invalid length
   127  */
   128 inline TInt RExDriverChannel::TransmitData(TRequestStatus& aStatus, const TDesC8& aData)
   129 	{
   130 	// Read the length of the data using TDesC8::Length(). It gives 8-bit data 
   131 	// items represented by the descriptor
   132 	//
   133 	TInt len = aData.Length();
   134 	if (!len)
   135 		return KErrArgument;	
   136 
   137 	// Call DoRequest() API of RBusLogicalChannel with the request number,
   138 	// TRequestStatus object to hold asynchronous request status, transmit buffer
   139 	// and data length. This is a implemented as asynchronous message and will be
   140 	// handled in driver/LDD DoRequest() function.Here the transmit buffer, aData
   141 	// is filled by user and sent to the driver for writing to device.
   142 	//
   143 	DoRequest(ERequestTransmitData,aStatus,(TAny*)&aData);
   144 	
   145 	return KErrNone;
   146 	}
   147 	
   148 /** 
   149  Receive the data from the device. User sends an empty buffer and reads the
   150  data after the call. It returns immediately after initiating the receive. 
   151  The actual request completes asynchronously after the completion of the 
   152  operation on the device and is notified then.
   153  
   154  @param		aData
   155  			buffer holding the data received
   156  
   157  @return	KErrNone on success or KErrArgument on invalid length
   158  */
   159 inline TInt RExDriverChannel::ReceiveData(TRequestStatus& aStatus, TDes8 &aData)
   160 	{	
   161 	// Read the length of the data using TDesC8::Length(). It gives 8-bit data 
   162 	// items represented by the descriptor
   163 	//
   164 	TInt len = aData.MaxLength();
   165 	if (!len)
   166 		return KErrArgument;	
   167 	
   168 	// Call DoRequest() API of RBusLogicalChannel with the request number,
   169 	// TRequestStatus object to hold asynchronous request status, receive buffer
   170 	// and data length. This is a implemented as asynchronous message and will be
   171 	// handled in driver/LDD DoRequest() function. Here, the receive buffer, aData
   172 	// will be filled and returned with the received data by the driver read from 
   173 	// the device.
   174 	//
   175 	DoRequest(ERequestReceiveData,aStatus,&aData);
   176 	
   177 	return KErrNone;
   178 	}
   179 
   180 /** 
   181  Cancel Transmit request on the device. User can request to cancel any outstanding 
   182  transmit requests. This request is handled by calling DoCancel() with appropriate
   183  request mask
   184   
   185  @param		none
   186  
   187  @return	void
   188  */
   189 inline void RExDriverChannel::CancelTransmit()
   190 	{
   191 	// Call DoCancel() API of RBusLogicalChannel with the request number. This is 
   192 	// handled in driver/LDD DoCancel() function. It will cancel the operation and 
   193 	// also tidy up the request specific resources.
   194 	//
   195 	DoCancel(1<<ERequestTransmitData);
   196 	}
   197 
   198 
   199 /** 
   200  Cancel Receive request on the device. User can request to cancel any outstanding 
   201  receive requests. This request is handled by calling DoCancel() with appropriate 
   202  request mask. 
   203   
   204  @param		none
   205  
   206  @return	void
   207  */
   208 inline void RExDriverChannel::CancelReceive()
   209 	{
   210 	// Call DoCancel() API of RBusLogicalChannel with the request number. This is 
   211 	// handled in driver/LDD DoCancel() function. It will cancel the operation and 
   212 	// also tidy up the request specific resources.
   213 	//
   214 	DoCancel(1<<ERequestReceiveData);
   215 	}
   216 
   217 //
   218 // End of exint.inl