bsptemplate/asspandvariant/template_assp/iic/iic_psl.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <drivers/iic.h>
       
    20 #include <drivers/iic_channel.h>
       
    21 
       
    22 #include "iic_psl.h"
       
    23 
       
    24 #ifdef MASTER_MODE
       
    25 #include "iic_master.h"
       
    26 #endif
       
    27 #ifdef SLAVE_MODE
       
    28 #include "iic_slave.h"
       
    29 #endif
       
    30 
       
    31 
       
    32 // EXTENSION DLL ENTRY POINT
       
    33 DECLARE_EXTENSION_WITH_PRIORITY(BUS_IMPLMENTATION_PRIORITY)
       
    34 	{
       
    35 	// Array of pointers to the Channels that the PSL creates, for registration with the Bus Controller
       
    36 	// Use a local array, since the IIC Controller operates on a copy of the array entries.
       
    37 	DIicBusChannel* channelPtrArray[KIicPslNumOfChannels];
       
    38 
       
    39 	TInt r = KErrNone;
       
    40 
       
    41 #ifdef MASTER_MODE
       
    42 #ifndef SLAVE_MODE
       
    43 	// If only MASTER_MODE is declared - Create only DIicBusChannelMasterPsl channels
       
    44 	__KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating DIicBusChannelMasterPsl only\n"));
       
    45 
       
    46 	DIicBusChannel* chan = NULL;
       
    47 	for (TInt i = 0; i < KIicPslNumOfChannels; ++i)
       
    48 		{
       
    49 		// The first argument repesents the PSL-assigned channel number
       
    50 		// The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
       
    51 		chan = DIicBusChannelMasterPsl::New(i, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
       
    52 		if (!chan)
       
    53 			{
       
    54 			return KErrNoMemory;
       
    55 			}
       
    56 		channelPtrArray[i] = chan;
       
    57 		}
       
    58 
       
    59 #else /*SLAVE_MODE*/
       
    60 	// Master and Slave functionality is available, so create Master, Slave and MasterSlave Channels
       
    61 	// Create channel 0 as Master, channel 1 as a Slave, and channel 2 as MasterSlave.
       
    62 	__KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating Master, Slave and MasterSlave channels\n"));
       
    63 
       
    64 	DIicBusChannel* chan = NULL;
       
    65 
       
    66 	// Master channel
       
    67 	// The first argument repesents the PSL-assigned channel number
       
    68 	// The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
       
    69 	chan = DIicBusChannelMasterPsl::New(0, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
       
    70 	if (!chan)
       
    71 		{
       
    72 		return KErrNoMemory;
       
    73 		}
       
    74 	channelPtrArray[0] = chan;
       
    75 
       
    76 	// Slave channel
       
    77 	// The first argument repesents the PSL-assigned channel number
       
    78 	// The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
       
    79 	chan = DIicBusChannelSlavePsl::New(1, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
       
    80 	if (!chan)
       
    81 		{
       
    82 		return KErrNoMemory;
       
    83 		}
       
    84 	channelPtrArray[1] = chan;
       
    85 
       
    86 	// MasterSlave channel
       
    87 	// MasterSlave channels are not for derivation; instead, they have a pointer to a (derived) Master channel
       
    88 	// and a pointer to a (derived) Slave channel
       
    89 	DIicBusChannel* chanM = NULL;
       
    90 	DIicBusChannel* chanS = NULL;
       
    91 	// For MasterSlave channel, the channel number for both the Master and Slave channels must be the same
       
    92 	TInt msChanNum = 2;
       
    93 	// Master channel
       
    94 	// The first argument repesents the PSL-assigned channel number
       
    95 	// The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
       
    96 	chanM = DIicBusChannelMasterPsl::New(msChanNum, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
       
    97 	if (!chanM)
       
    98 		{
       
    99 		return KErrNoMemory;
       
   100 		}
       
   101 	// Slave channel
       
   102 	// The first argument repesents the PSL-assigned channel number
       
   103 	// The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
       
   104 	chanS = DIicBusChannelSlavePsl::New(msChanNum, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
       
   105 	if (!chanS)
       
   106 		{
       
   107 		return KErrNoMemory;
       
   108 		}
       
   109 	// MasterSlave channel
       
   110 	// The first argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
       
   111 	chan = new DIicBusChannelMasterSlave(DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex, (DIicBusChannelMaster*)chanM, (DIicBusChannelSlave*)chanS);
       
   112 	if (!chan)
       
   113 		{
       
   114 		return KErrNoMemory;
       
   115 		}
       
   116 	r = ((DIicBusChannelMasterSlave*)chan)->DoCreate();
       
   117 	channelPtrArray[2] = chan;
       
   118 
       
   119 
       
   120 #endif /*SLAVE_MODE*/
       
   121 #else /*MASTER_MODE*/
       
   122 
       
   123 #ifdef SLAVE_MODE
       
   124 	// If only SLAVE_MODE is declared - Create all as DIicBusChannelSlavePsl channels
       
   125 	__KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating DIicBusChannelSlavePsl only\n"));
       
   126 
       
   127 	DIicBusChannel* chan = NULL;
       
   128 	for (TInt i = 0; i < KIicPslNumOfChannels; ++i)
       
   129 		{
       
   130 		// The first argument repesents the PSL-assigned channel number
       
   131 		// The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
       
   132 		chan = DIicBusChannelSlavePsl::New(i, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
       
   133 		if (!chan)
       
   134 			{
       
   135 			return KErrNoMemory;
       
   136 			}
       
   137 		channelPtrArray[i] = chan;
       
   138 		}
       
   139 
       
   140 #endif
       
   141 #endif /*MASTER_MODE*/
       
   142 
       
   143 	// Register them with the Bus Controller
       
   144 	r = DIicBusController::RegisterChannels(channelPtrArray, KIicPslNumOfChannels);
       
   145 
       
   146 	return r;
       
   147 	}
       
   148 
       
   149