1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/examples/exdriver/exdriver_int/inc/exint.inl Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,218 @@
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 exint.h
1.21 +//
1.22 +//
1.23 +
1.24 +/**
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 +*/
1.33 +inline TVersion RExDriverChannel::VersionRequired()
1.34 + {
1.35 + return (TVersion(EUartMajorVersionNumber,
1.36 + EUartMinorVersionNumber,
1.37 + EUartBuildVersionNumber));
1.38 + }
1.39 +
1.40 +/**
1.41 + Open the driver for the specified unit. Unit information is passed as an
1.42 + argument by the user. User can open the driver for different units as supported
1.43 + by the driver.
1.44 +
1.45 + @param aUnit
1.46 + device unit number
1.47 +
1.48 + @return return value of DoCreate(), i.e KErrNone or standard error code
1.49 + */
1.50 +inline TInt RExDriverChannel::Open(TInt aUnit)
1.51 + {
1.52 + // Call DoCreate() API of RBusLogicalChannel with driver name,
1.53 + // version, unit number and owner. This will result in creating the
1.54 + // logical channel by invoking Create() and DoCreate() of Logical Channel.
1.55 + //
1.56 + return DoCreate(KDriverName,VersionRequired(),aUnit,NULL,NULL,EOwnerThread);
1.57 + }
1.58 +
1.59 +/**
1.60 + Gets the capabilities of a channel opened on the driver. User can use the
1.61 + retrieved capabilities to configure different channels (if supported by
1.62 + driver) with supported configuration.
1.63 +
1.64 + @param aCaps
1.65 + Descriptor to be filled with channel capabilities
1.66 +
1.67 + @return return value of DoControl(), i.e KErrNone or standard error code
1.68 + */
1.69 +inline TInt RExDriverChannel::Caps(TDes8& aCaps)
1.70 + {
1.71 + // Call DoControl() API of RBusLogicalChannel with the request number
1.72 + // and the caps buffer(structure) that has to be filled by the driver.
1.73 + // This is a synchronous message and will be handled in driver/LDD
1.74 + // DoControl() function
1.75 + //
1.76 + return DoControl(EControlCaps,(TAny*)&aCaps);
1.77 + }
1.78 +
1.79 +/**
1.80 + Configure the device (uart) internal loopback mode. User can configure the
1.81 + device for internal loopback mode using this API. Loopback mode can be enabled
1.82 + or disabled by passing the mode as a parameter to this API.
1.83 +
1.84 + @param aMode
1.85 + Holds the loopback enable and disable option
1.86 + KLoopbackEnable for enable and KLoopbackDisable for disable
1.87 +
1.88 + @return return value of DoControl(), i.e KErrNone or standard error code
1.89 + */
1.90 +inline TInt RExDriverChannel::SetIntLoopback(const TInt aMode)
1.91 + {
1.92 + // Call DoControl() API of RBusLogicalChannel with the request number
1.93 + // and the loopback mode. This is a synchronous message
1.94 + // and will be handled in driver/LDD DoControl() function
1.95 + //
1.96 + return DoControl(EControlSetIntLoopback,(TAny*)&aMode);
1.97 + }
1.98 +
1.99 +/**
1.100 + Configure the device (uart) for the specified settings. User initializes the
1.101 + configuration buffer, and passes this to the device driver. The config data
1.102 + structure is packaged as a buffer and passes as an argument.
1.103 +
1.104 + @param aConfig
1.105 + buffer descriptor with device configuration information
1.106 +
1.107 + @return return value of DoControl(), i.e KErrNone or standard error code
1.108 + */
1.109 +inline TInt RExDriverChannel::SetConfig(const TDesC8& aConfig)
1.110 + {
1.111 + // Call DoControl() API of RBusLogicalChannel with the request number
1.112 + // and the config buffer(structure). This is a synchronous message
1.113 + // and will be handled in driver/LDD DoControl() function
1.114 + //
1.115 + return DoControl(EControlSetConfig,(TAny*)&aConfig);
1.116 + }
1.117 +
1.118 +/**
1.119 + Transmit the data to the device. User initializes the buffer and sends the
1.120 + the buffer descriptor as an argument. It returns immediately after initiating
1.121 + the transmit. The actual request completes asynchronously after the completion
1.122 + of the operation on the device and is notified then.
1.123 +
1.124 + @param aStatus
1.125 + TRequestStatus object to hold the asynchronous request status
1.126 + @param aData
1.127 + buffer holding the data to transmit
1.128 +
1.129 + @return KErrNone on success or KErrArgument on invalid length
1.130 + */
1.131 +inline TInt RExDriverChannel::TransmitData(TRequestStatus& aStatus, const TDesC8& aData)
1.132 + {
1.133 + // Read the length of the data using TDesC8::Length(). It gives 8-bit data
1.134 + // items represented by the descriptor
1.135 + //
1.136 + TInt len = aData.Length();
1.137 + if (!len)
1.138 + return KErrArgument;
1.139 +
1.140 + // Call DoRequest() API of RBusLogicalChannel with the request number,
1.141 + // TRequestStatus object to hold asynchronous request status, transmit buffer
1.142 + // and data length. This is a implemented as asynchronous message and will be
1.143 + // handled in driver/LDD DoRequest() function.Here the transmit buffer, aData
1.144 + // is filled by user and sent to the driver for writing to device.
1.145 + //
1.146 + DoRequest(ERequestTransmitData,aStatus,(TAny*)&aData);
1.147 +
1.148 + return KErrNone;
1.149 + }
1.150 +
1.151 +/**
1.152 + Receive the data from the device. User sends an empty buffer and reads the
1.153 + data after the call. It returns immediately after initiating the receive.
1.154 + The actual request completes asynchronously after the completion of the
1.155 + operation on the device and is notified then.
1.156 +
1.157 + @param aData
1.158 + buffer holding the data received
1.159 +
1.160 + @return KErrNone on success or KErrArgument on invalid length
1.161 + */
1.162 +inline TInt RExDriverChannel::ReceiveData(TRequestStatus& aStatus, TDes8 &aData)
1.163 + {
1.164 + // Read the length of the data using TDesC8::Length(). It gives 8-bit data
1.165 + // items represented by the descriptor
1.166 + //
1.167 + TInt len = aData.MaxLength();
1.168 + if (!len)
1.169 + return KErrArgument;
1.170 +
1.171 + // Call DoRequest() API of RBusLogicalChannel with the request number,
1.172 + // TRequestStatus object to hold asynchronous request status, receive buffer
1.173 + // and data length. This is a implemented as asynchronous message and will be
1.174 + // handled in driver/LDD DoRequest() function. Here, the receive buffer, aData
1.175 + // will be filled and returned with the received data by the driver read from
1.176 + // the device.
1.177 + //
1.178 + DoRequest(ERequestReceiveData,aStatus,&aData);
1.179 +
1.180 + return KErrNone;
1.181 + }
1.182 +
1.183 +/**
1.184 + Cancel Transmit request on the device. User can request to cancel any outstanding
1.185 + transmit requests. This request is handled by calling DoCancel() with appropriate
1.186 + request mask
1.187 +
1.188 + @param none
1.189 +
1.190 + @return void
1.191 + */
1.192 +inline void RExDriverChannel::CancelTransmit()
1.193 + {
1.194 + // Call DoCancel() API of RBusLogicalChannel with the request number. This is
1.195 + // handled in driver/LDD DoCancel() function. It will cancel the operation and
1.196 + // also tidy up the request specific resources.
1.197 + //
1.198 + DoCancel(1<<ERequestTransmitData);
1.199 + }
1.200 +
1.201 +
1.202 +/**
1.203 + Cancel Receive request on the device. User can request to cancel any outstanding
1.204 + receive requests. This request is handled by calling DoCancel() with appropriate
1.205 + request mask.
1.206 +
1.207 + @param none
1.208 +
1.209 + @return void
1.210 + */
1.211 +inline void RExDriverChannel::CancelReceive()
1.212 + {
1.213 + // Call DoCancel() API of RBusLogicalChannel with the request number. This is
1.214 + // handled in driver/LDD DoCancel() function. It will cancel the operation and
1.215 + // also tidy up the request specific resources.
1.216 + //
1.217 + DoCancel(1<<ERequestReceiveData);
1.218 + }
1.219 +
1.220 +//
1.221 +// End of exint.inl