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