1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/bsptemplate/asspandvariant/template_assp/iic/iic_psl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,149 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <drivers/iic.h>
1.23 +#include <drivers/iic_channel.h>
1.24 +
1.25 +#include "iic_psl.h"
1.26 +
1.27 +#ifdef MASTER_MODE
1.28 +#include "iic_master.h"
1.29 +#endif
1.30 +#ifdef SLAVE_MODE
1.31 +#include "iic_slave.h"
1.32 +#endif
1.33 +
1.34 +
1.35 +// EXTENSION DLL ENTRY POINT
1.36 +DECLARE_EXTENSION_WITH_PRIORITY(BUS_IMPLMENTATION_PRIORITY)
1.37 + {
1.38 + // Array of pointers to the Channels that the PSL creates, for registration with the Bus Controller
1.39 + // Use a local array, since the IIC Controller operates on a copy of the array entries.
1.40 + DIicBusChannel* channelPtrArray[KIicPslNumOfChannels];
1.41 +
1.42 + TInt r = KErrNone;
1.43 +
1.44 +#ifdef MASTER_MODE
1.45 +#ifndef SLAVE_MODE
1.46 + // If only MASTER_MODE is declared - Create only DIicBusChannelMasterPsl channels
1.47 + __KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating DIicBusChannelMasterPsl only\n"));
1.48 +
1.49 + DIicBusChannel* chan = NULL;
1.50 + for (TInt i = 0; i < KIicPslNumOfChannels; ++i)
1.51 + {
1.52 + // The first argument repesents the PSL-assigned channel number
1.53 + // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
1.54 + chan = DIicBusChannelMasterPsl::New(i, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
1.55 + if (!chan)
1.56 + {
1.57 + return KErrNoMemory;
1.58 + }
1.59 + channelPtrArray[i] = chan;
1.60 + }
1.61 +
1.62 +#else /*SLAVE_MODE*/
1.63 + // Master and Slave functionality is available, so create Master, Slave and MasterSlave Channels
1.64 + // Create channel 0 as Master, channel 1 as a Slave, and channel 2 as MasterSlave.
1.65 + __KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating Master, Slave and MasterSlave channels\n"));
1.66 +
1.67 + DIicBusChannel* chan = NULL;
1.68 +
1.69 + // Master channel
1.70 + // The first argument repesents the PSL-assigned channel number
1.71 + // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
1.72 + chan = DIicBusChannelMasterPsl::New(0, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
1.73 + if (!chan)
1.74 + {
1.75 + return KErrNoMemory;
1.76 + }
1.77 + channelPtrArray[0] = chan;
1.78 +
1.79 + // Slave channel
1.80 + // The first argument repesents the PSL-assigned channel number
1.81 + // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
1.82 + chan = DIicBusChannelSlavePsl::New(1, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
1.83 + if (!chan)
1.84 + {
1.85 + return KErrNoMemory;
1.86 + }
1.87 + channelPtrArray[1] = chan;
1.88 +
1.89 + // MasterSlave channel
1.90 + // MasterSlave channels are not for derivation; instead, they have a pointer to a (derived) Master channel
1.91 + // and a pointer to a (derived) Slave channel
1.92 + DIicBusChannel* chanM = NULL;
1.93 + DIicBusChannel* chanS = NULL;
1.94 + // For MasterSlave channel, the channel number for both the Master and Slave channels must be the same
1.95 + TInt msChanNum = 2;
1.96 + // Master channel
1.97 + // The first argument repesents the PSL-assigned channel number
1.98 + // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
1.99 + chanM = DIicBusChannelMasterPsl::New(msChanNum, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
1.100 + if (!chanM)
1.101 + {
1.102 + return KErrNoMemory;
1.103 + }
1.104 + // Slave channel
1.105 + // The first argument repesents the PSL-assigned channel number
1.106 + // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
1.107 + chanS = DIicBusChannelSlavePsl::New(msChanNum, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
1.108 + if (!chanS)
1.109 + {
1.110 + return KErrNoMemory;
1.111 + }
1.112 + // MasterSlave channel
1.113 + // The first argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
1.114 + chan = new DIicBusChannelMasterSlave(DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex, (DIicBusChannelMaster*)chanM, (DIicBusChannelSlave*)chanS);
1.115 + if (!chan)
1.116 + {
1.117 + return KErrNoMemory;
1.118 + }
1.119 + r = ((DIicBusChannelMasterSlave*)chan)->DoCreate();
1.120 + channelPtrArray[2] = chan;
1.121 +
1.122 +
1.123 +#endif /*SLAVE_MODE*/
1.124 +#else /*MASTER_MODE*/
1.125 +
1.126 +#ifdef SLAVE_MODE
1.127 + // If only SLAVE_MODE is declared - Create all as DIicBusChannelSlavePsl channels
1.128 + __KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating DIicBusChannelSlavePsl only\n"));
1.129 +
1.130 + DIicBusChannel* chan = NULL;
1.131 + for (TInt i = 0; i < KIicPslNumOfChannels; ++i)
1.132 + {
1.133 + // The first argument repesents the PSL-assigned channel number
1.134 + // The second argument, DIicBusChannel::ESpi, should be replaced with the relevant bus type for the PSL
1.135 + chan = DIicBusChannelSlavePsl::New(i, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
1.136 + if (!chan)
1.137 + {
1.138 + return KErrNoMemory;
1.139 + }
1.140 + channelPtrArray[i] = chan;
1.141 + }
1.142 +
1.143 +#endif
1.144 +#endif /*MASTER_MODE*/
1.145 +
1.146 + // Register them with the Bus Controller
1.147 + r = DIicBusController::RegisterChannels(channelPtrArray, KIicPslNumOfChannels);
1.148 +
1.149 + return r;
1.150 + }
1.151 +
1.152 +