navienginebsp/naviengine_assp/csi/csi_psl.cpp
changeset 0 5de814552237
equal deleted inserted replaced
-1:000000000000 0:5de814552237
       
     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 "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 #ifdef STANDALONE_CHANNEL
       
    20 #include <drivers/iic_transaction.h>
       
    21 #else
       
    22 #include <drivers/iic.h>
       
    23 #endif
       
    24 
       
    25 #include <drivers/iic_channel.h>
       
    26 #include <assp/naviengine/naviengine.h>
       
    27 #include "csi_psl.h"
       
    28 
       
    29 #ifdef MASTER_MODE
       
    30 #include "csi_master.h"
       
    31 #endif
       
    32 #ifdef SLAVE_MODE
       
    33 #include "csi_slave.h"
       
    34 #endif
       
    35 
       
    36 #include "hcrconfig.h"
       
    37 #include "hcrconfig_csi.h"
       
    38 
       
    39 // table of pointers to the channels - to be filled with pointers to channels
       
    40 // and used to register these channels with the Bus Controller
       
    41 // (definition)
       
    42 DIicBusChannel** ChannelPtrArray;
       
    43 
       
    44 // EXTENSION DLL ENTRY POINT
       
    45 DECLARE_EXTENSION_WITH_PRIORITY(BUS_IMPLMENTATION_PRIORITY)
       
    46 	{
       
    47 	TInt r = KErrNone;
       
    48 #ifndef STANDALONE_CHANNEL
       
    49 
       
    50 	HCR::TSettingId settingId;
       
    51 	settingId.iCat = KHcrCat_HWServ_CSI;
       
    52 	settingId.iKey = KHcrKey_CSI_NumOfChannels;
       
    53 	TInt32 csiNumOfChannels;
       
    54 
       
    55 	r = HCR::GetInt(settingId, csiNumOfChannels);
       
    56 	if(r != KErrNone) 
       
    57 		{
       
    58 		__KTRACE_OPT(KIIC, Kern::Printf("Failed to read HCR setting for category = %d and key = %d\n", settingId.iCat, settingId.iKey));
       
    59 		return r;
       
    60 		}
       
    61 	ChannelPtrArray = new DIicBusChannel*[csiNumOfChannels];
       
    62 
       
    63 #ifdef MASTER_MODE
       
    64 #ifndef SLAVE_MODE
       
    65 	// If only MASTER_MODE is declared - Create all as DCsiChannelMaster channels
       
    66 	__KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating DCsiChannelMaster only"));
       
    67 
       
    68 	DIicBusChannel* chan = NULL;
       
    69 	for (TInt i = 0; i < csiNumOfChannels; ++i)
       
    70 		{
       
    71 		chan = DCsiChannelMaster::New(i, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
       
    72 		if (!chan)
       
    73 			{
       
    74 			return KErrNoMemory;
       
    75 			}
       
    76 		ChannelPtrArray[i] = chan;
       
    77 		}
       
    78 
       
    79 #else /*SLAVE_MODE*/
       
    80 	// both - Master and Slave channels.. or MasterSlaveChannels..
       
    81 	// for now, create channel 0 as Master, and channel 1 as a Slave.
       
    82 	__KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating Master and Slave"));
       
    83 
       
    84 	DIicBusChannel* chan = NULL;
       
    85 	// create channel 0 - as master..
       
    86 	chan = DCsiChannelMaster::New(0, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
       
    87 	if (!chan)
       
    88 		{
       
    89 		return KErrNoMemory;
       
    90 		}
       
    91 	ChannelPtrArray[0] = chan;
       
    92 
       
    93 	// and created channel 1 - as slave..
       
    94 	chan = DCsiChannelSlave::New(1, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
       
    95 	if (!chan)
       
    96 		{
       
    97 		return KErrNoMemory;
       
    98 		}
       
    99 	ChannelPtrArray[1] = chan;
       
   100 
       
   101 #endif /*SLAVE_MODE*/
       
   102 #else /*MASTER_MODE*/
       
   103 
       
   104 #ifdef SLAVE_MODE
       
   105 	// If only SLAVE_MODE is declared - Create all as DCsiChannelMaster channels
       
   106 	__KTRACE_OPT(KIIC, Kern::Printf("\n\nCreating DCsiChannelSlave only"));
       
   107 
       
   108 	DIicBusChannel* chan = NULL;
       
   109 	for (TInt i = 0; i < csiNumOfChannels; ++i)
       
   110 		{
       
   111 		chan = DCsiChannelSlave::New(i, DIicBusChannel::ESpi, DIicBusChannel::EFullDuplex);
       
   112 		if (!chan)
       
   113 			{
       
   114 			return KErrNoMemory;
       
   115 			}
       
   116 		ChannelPtrArray[i] = chan;
       
   117 		}
       
   118 
       
   119 #endif
       
   120 #endif /*MASTER_MODE*/
       
   121 
       
   122 	// Register them with the Bus Controller
       
   123 	r = DIicBusController::RegisterChannels(ChannelPtrArray, csiNumOfChannels);
       
   124 #endif/*STANDALONE_CHANNEL*/
       
   125 
       
   126 	return r;
       
   127 	}
       
   128 
       
   129 // helper function - to dump the supplied configuration
       
   130 #ifdef _DEBUG
       
   131 void DumpConfiguration(const TConfigSpiBufV01& spiHeader, TInt aCsPin)
       
   132 	{
       
   133 #ifdef DUMP_CONFIG
       
   134 	__KTRACE_OPT(KIIC, Kern::Printf("new configuration:\n"));
       
   135 	__KTRACE_OPT(KIIC, Kern::Printf("iWordWidth %d", spiHeader().iWordWidth));
       
   136 	__KTRACE_OPT(KIIC, Kern::Printf("iClkSpeedHz: %d", spiHeader().iClkSpeedHz));
       
   137 	__KTRACE_OPT(KIIC, Kern::Printf("iClkMode %d", spiHeader().iClkMode));
       
   138 	__KTRACE_OPT(KIIC, Kern::Printf("iTimeoutPeriod %d", spiHeader().iTimeoutPeriod));
       
   139 	__KTRACE_OPT(KIIC, Kern::Printf("iBitOrder %d", spiHeader().iBitOrder));
       
   140 	__KTRACE_OPT(KIIC, Kern::Printf("iTransactionWaitCycles %d", spiHeader().iTransactionWaitCycles));
       
   141 	__KTRACE_OPT(KIIC, Kern::Printf("iSSPinActiveMode %d", spiHeader().iSSPinActiveMode));
       
   142 	__KTRACE_OPT(KIIC, Kern::Printf("csPin %d\n", aCsPin));
       
   143 #endif
       
   144 	}
       
   145 #endif
       
   146