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