Adaptation/GUID-9986DCC6-EE73-59FB-BDAC-9B09DC64FBCE.dita
changeset 15 307f4279f433
equal deleted inserted replaced
14:578be2adaf3e 15:307f4279f433
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <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
       
    13 master channel functionality.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p>This document describes a simple implementation of an IIC client
       
    15 using the master channel functionality. </p>
       
    16 <section id="GUID-A16020C1-28AC-4B14-9ADD-EEDD9C8EC65D"><title>Purpose</title> <p>This tutorial explains how to use the IIC platform service API
       
    17 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>
       
    18 <li id="GUID-E339C63B-A5B2-535A-9EEB-E42F5913695F"><p>Have installed
       
    19 the platform specific implementation of IIC channels that is required
       
    20 to support the IIC platform service API. </p> </li>
       
    21 <li id="GUID-BF87DA07-52AD-5B46-BA69-61AB6E23CA38"><p>Include the <filepath>IIC.dll</filepath> in the <filepath>kernel.iby</filepath> file. </p> </li>
       
    22 <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>
       
    23 </ul> <p> <note>  The code example fragments are for synchronous operation.
       
    24 For asynchronous operation, the buffers must be allocated on the heap. </note></p> </section>
       
    25 <section id="GUID-420879EF-296C-4AB3-9B89-0C5BF6781206"><title>Implementing
       
    26 the IIC platform service</title> <p>The Following tasks will be covered
       
    27 in this tutorial: </p> <ul>
       
    28 <li id="GUID-FF0DF82E-6D88-5C58-844C-2E1036816FAD"><p>Performing read/write
       
    29 operations. </p> </li>
       
    30 </ul> <p><b>Basic Procedure</b> </p> <p><note> The implementation
       
    31 on which the following code examples are based is implemented IIC
       
    32 via a SPI bus. On hardware with dedicated IIC ports, the IIC port
       
    33 would be specified and the header data type would be TConfigIICV01.</note></p><p>The high level steps to performing read/write operations are
       
    34 shown here: </p> <ol id="GUID-0080AB2C-6DC5-5128-B2FB-7E1D81859F7B">
       
    35 <li id="GUID-3C607C4B-20B8-5ED7-8A82-BF75CC2C5286"><p>First set the
       
    36 bus type, the channel number and the slave address. </p> <p>An example
       
    37 of this is : </p> <codeblock id="GUID-A66F8DD0-A870-5210-9AAB-D3B837D0E831" xml:space="preserve">// Configure the port.
       
    38     busId.SetBusType(DIicBusChannel::ESpi);        // Specify which multi-wire bus is to be used. in this example, SPI.
       
    39     busId.SetChanNum(0);                           // Set the channel number.
       
    40     busId.SetSlaveAddr(13);                        // Set the slave address. </codeblock> </li>
       
    41 <li id="GUID-27D5A0ED-818B-51AE-BB48-32929DB3E134"><p>Configure the
       
    42 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.
       
    43     const TConfigSpiV01 TestHeader =
       
    44         {
       
    45         ESpiWordWidth_8,                            // Set the word width. In this example, 8 bits.
       
    46         260000,                                     // Set the clock speed of the port. In this example, 260KHz.
       
    47         ESpiPolarityLowRisingEdge,                  // Set the clock mode value. In this example, Active high, odd edges.
       
    48         500,                                        // Set the timeout period. In this example, 500msec.
       
    49         EBigEndian,                                 // Set which endian is to be used. In this example, BigEndian is used.
       
    50         EMsbFirst,                                  // Set which bit order is to be used. In this example, the Msb is first.
       
    51         0,                                          // Set the number of transaction wait cycles. In this example, 0.
       
    52         ESpiCSPinActiveLow                          // Set the Chip select active mode. In this example, chip select is active low.
       
    53         };</codeblock> </li>
       
    54 <li id="GUID-6748A0B1-6A37-50AB-9D93-A230F419059A"><p>Make linked
       
    55 lists of the transfers that are to be carried out. </p> <p>An example
       
    56 of this is : </p> <codeblock id="GUID-C112BD53-C69C-595B-8452-82826AEC37B3" xml:space="preserve">// Set the transaction header.
       
    57     TPckgBuf&lt;TConfigSpiV01&gt; header(TestHeader);
       
    58 
       
    59     // Set up a transmit transaction.
       
    60     // This txTransfer buffer acts as the start of the transaction linked list.
       
    61     TIicBusTransfer txTransfer(TIicBusTransfer::EMasterWrite, 8, &amp;txTransferBuf);
       
    62 
       
    63     // Set up a receive transaction.
       
    64     TIicBusTransfer rxTransfer(TIicBusTransfer::EMasterRead, 8, &amp;rxTransferBuf);
       
    65 
       
    66     // Add to the receive transaction to the transaction linked list.
       
    67     txTransfer.LinkAfter(&amp;rxTransfer);
       
    68 
       
    69     // Create a transaction using header and the transaction linked list.
       
    70     TIicBusTransaction transaction(&amp;header, &amp;txTransfer);</codeblock> </li>
       
    71 <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
       
    72 of the port and the start location of the transaction linked lists.
       
    73 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.
       
    74  // Once this command has been executed, the value of r should be KErrNone.
       
    75     r = IicBus::QueueTransaction(busId.GetConfig(), &amp;transaction);</codeblock> </li>
       
    76 </ol> </section>
       
    77 </conbody><related-links>
       
    78 <link href="GUID-F461CBB3-F8D1-5961-AD51-5741143A1CB1.dita"><linktext>Client
       
    79  of Slave Channel Tutorial</linktext></link>
       
    80 <link href="GUID-B2F86F54-EF50-56DB-ADF7-15325AC9324D.dita"><linktext>IIC
       
    81 Concepts</linktext></link>
       
    82 <link href="GUID-3A30DA16-ECA8-5639-A9DC-6BE2AD55420B.dita"><linktext>I2C
       
    83 Technology Guide</linktext></link>
       
    84 </related-links></concept>