Adaptation/GUID-9986DCC6-EE73-59FB-BDAC-9B09DC64FBCE.dita
author Graeme Price <GRAEME.PRICE@NOKIA.COM>
Fri, 15 Oct 2010 14:32:18 +0100
changeset 15 307f4279f433
permissions -rw-r--r--
Initial contribution of the Adaptation Documentation.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-9986DCC6-EE73-59FB-BDAC-9B09DC64FBCE" xml:lang="en"><title>Client of Master Channel Tutorial</title><shortdesc>Describes a simple implementation of a client using the
master channel functionality.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>This document describes a simple implementation of an IIC client
using the master channel functionality. </p>
<section id="GUID-A16020C1-28AC-4B14-9ADD-EEDD9C8EC65D"><title>Purpose</title> <p>This tutorial explains how to use the IIC platform service API
as a master and to communicate with a peripheral using half-duplex. </p> <p><b>Intended Audience</b> </p> <p>Device driver writers. </p> <p><b>Required Background</b> </p> <p>Before you start, you must: </p> <ul>
<li id="GUID-E339C63B-A5B2-535A-9EEB-E42F5913695F"><p>Have installed
the platform specific implementation of IIC channels that is required
to support the IIC platform service API. </p> </li>
<li id="GUID-BF87DA07-52AD-5B46-BA69-61AB6E23CA38"><p>Include the <filepath>IIC.dll</filepath> in the <filepath>kernel.iby</filepath> file. </p> </li>
<li id="GUID-DE66833F-6DE6-5068-BE7B-A748ABFE9915"><p>Include the <filepath>iic.h</filepath> and <filepath>iic_channel.h</filepath> header files. </p> </li>
</ul> <p> <note>  The code example fragments are for synchronous operation.
For asynchronous operation, the buffers must be allocated on the heap. </note></p> </section>
<section id="GUID-420879EF-296C-4AB3-9B89-0C5BF6781206"><title>Implementing
the IIC platform service</title> <p>The Following tasks will be covered
in this tutorial: </p> <ul>
<li id="GUID-FF0DF82E-6D88-5C58-844C-2E1036816FAD"><p>Performing read/write
operations. </p> </li>
</ul> <p><b>Basic Procedure</b> </p> <p><note> The implementation
on which the following code examples are based is implemented IIC
via a SPI bus. On hardware with dedicated IIC ports, the IIC port
would be specified and the header data type would be TConfigIICV01.</note></p><p>The high level steps to performing read/write operations are
shown here: </p> <ol id="GUID-0080AB2C-6DC5-5128-B2FB-7E1D81859F7B">
<li id="GUID-3C607C4B-20B8-5ED7-8A82-BF75CC2C5286"><p>First set the
bus type, the channel number and the slave address. </p> <p>An example
of this is : </p> <codeblock id="GUID-A66F8DD0-A870-5210-9AAB-D3B837D0E831" xml:space="preserve">// Configure the port.
    busId.SetBusType(DIicBusChannel::ESpi);        // Specify which multi-wire bus is to be used. in this example, SPI.
    busId.SetChanNum(0);                           // Set the channel number.
    busId.SetSlaveAddr(13);                        // Set the slave address. </codeblock> </li>
<li id="GUID-27D5A0ED-818B-51AE-BB48-32929DB3E134"><p>Configure the
channel. </p> <p>An example of which, is : </p> <codeblock id="GUID-43A34CF2-6324-5026-BC9E-28CE4B8D95A6" xml:space="preserve">// create header - this configures a SPI port.
    const TConfigSpiV01 TestHeader =
        {
        ESpiWordWidth_8,                            // Set the word width. In this example, 8 bits.
        260000,                                     // Set the clock speed of the port. In this example, 260KHz.
        ESpiPolarityLowRisingEdge,                  // Set the clock mode value. In this example, Active high, odd edges.
        500,                                        // Set the timeout period. In this example, 500msec.
        EBigEndian,                                 // Set which endian is to be used. In this example, BigEndian is used.
        EMsbFirst,                                  // Set which bit order is to be used. In this example, the Msb is first.
        0,                                          // Set the number of transaction wait cycles. In this example, 0.
        ESpiCSPinActiveLow                          // Set the Chip select active mode. In this example, chip select is active low.
        };</codeblock> </li>
<li id="GUID-6748A0B1-6A37-50AB-9D93-A230F419059A"><p>Make linked
lists of the transfers that are to be carried out. </p> <p>An example
of this is : </p> <codeblock id="GUID-C112BD53-C69C-595B-8452-82826AEC37B3" xml:space="preserve">// Set the transaction header.
    TPckgBuf&lt;TConfigSpiV01&gt; header(TestHeader);

    // Set up a transmit transaction.
    // This txTransfer buffer acts as the start of the transaction linked list.
    TIicBusTransfer txTransfer(TIicBusTransfer::EMasterWrite, 8, &amp;txTransferBuf);

    // Set up a receive transaction.
    TIicBusTransfer rxTransfer(TIicBusTransfer::EMasterRead, 8, &amp;rxTransferBuf);

    // Add to the receive transaction to the transaction linked list.
    txTransfer.LinkAfter(&amp;rxTransfer);

    // Create a transaction using header and the transaction linked list.
    TIicBusTransaction transaction(&amp;header, &amp;txTransfer);</codeblock> </li>
<li id="GUID-B750A2D0-CFE2-584F-B2CF-5F19293B88BC"><p>Use the <xref href="GUID-69949E47-8FDF-3651-BEEF-43726EBEB5FF.dita#GUID-69949E47-8FDF-3651-BEEF-43726EBEB5FF/GUID-A1E7014A-6554-3D10-85E8-0DA839779800"><apiname>IicBus::QueueTransaction()</apiname></xref> method, specifying the configuration
of the port and the start location of the transaction linked lists.
This queues the transactions on to the selected IIC channel. </p> <p>An example of this is : </p> <codeblock id="GUID-5F929F5F-D8B3-5471-B65A-86D5D9DC8D7C" xml:space="preserve">// Queue the transaction.
 // Once this command has been executed, the value of r should be KErrNone.
    r = IicBus::QueueTransaction(busId.GetConfig(), &amp;transaction);</codeblock> </li>
</ol> </section>
</conbody><related-links>
<link href="GUID-F461CBB3-F8D1-5961-AD51-5741143A1CB1.dita"><linktext>Client
 of Slave Channel Tutorial</linktext></link>
<link href="GUID-B2F86F54-EF50-56DB-ADF7-15325AC9324D.dita"><linktext>IIC
Concepts</linktext></link>
<link href="GUID-3A30DA16-ECA8-5639-A9DC-6BE2AD55420B.dita"><linktext>I2C
Technology Guide</linktext></link>
</related-links></concept>