omap3530/omap3530_drivers/spi/master.cpp
author arunabha
Fri, 08 Oct 2010 13:00:25 +0100
branchBYD_LCD_Integration
changeset 86 56c9b613f311
parent 85 d93b485c1325
child 112 fdfa12d9a47a
permissions -rw-r--r--
Merge SPI and Touch driver template to BYD_LCD branch for integration.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
     1
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
     2
// All rights reserved.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
     3
// This component and the accompanying materials are made available
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
     4
// under the terms of the License "Eclipse Public License v1.0"
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
     5
// which accompanies this distribution, and is available
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
     7
//
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
     8
// Initial Contributors:
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    10
//
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    11
// Contributors:
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    12
// lukasz.forynski@gmail.com
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    13
//
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    14
// Description:
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    15
// Implementation of IIC master channel for a SPI bus.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    16
//
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    17
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    18
#define DBGPRINT(x)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    19
#define DBG_ERR(x) x
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    20
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    21
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    22
#ifdef _DEBUG
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    23
#define DEBUG_ONLY(x) //x
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    24
#else
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    25
#define DEBUG_ONLY(x)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    26
#endif
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    27
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    28
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    29
// DO NOT CHANGE THESE- trying to tune the driver (unless you really know what you're doing)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    30
// as this this is only for development purpose to tune the driver. Fifo mode is not yet enabled, but this
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    31
// doesn't affect operation. After development has been finished - these macros and #ifdefs will be removed
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    32
// entirely. For now only SINGLE_MODE should ever be defined.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    33
//#define USE_TX_FIFO
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    34
//#define USING_TX_COUNTER
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    35
//#define PER_TRANSFER_MODE
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    36
#define SINGLE_MODE
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    37
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    38
#include <assp/omap3530_assp/omap3530_assp_priv.h>
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    39
#include <assp/omap3530_assp/omap3530_prcm.h>
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    40
#include <drivers/iic.h>
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    41
#include "omap3530_spi.h"
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    42
#include "psl_init.h"
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    43
#include "master.h"
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    44
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    45
DSpiMasterBeagle::DSpiMasterBeagle(TInt aChannelNumber, TBusType aBusType, TChannelDuplex aChanDuplex) :
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    46
	DIicBusChannelMaster(aBusType, aChanDuplex),
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    47
	iTransferEndDfc(TransferEndDfc, this, KIicPslDfcPriority)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    48
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    49
	iChannelNumber = aChannelNumber;
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
    50
	iIrqId  = KMcSpiIrqId[iChannelNumber];
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    51
	iHwBase = KMcSpiRegBase[iChannelNumber];
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
    52
	iState  = EIdle;
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
    53
	iCurrSS = -1; // make sure channel will be fully configured on the first use
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    54
	DBGPRINT(Kern::Printf("DSpiMasterBeagle::DSpiMasterBeagle: at 0x%x, iChannelNumber = %d", this, iChannelNumber));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    55
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    56
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    57
TInt DSpiMasterBeagle::DoCreate()
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    58
	{
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
    59
	DBGPRINT(Kern::Printf("\nDSpiMasterBeagle::DoCreate() McSPI%d \n", iChannelNumber+1));
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    60
	DBGPRINT(Kern::Printf("HW revision is %x", AsspRegister::Read32(iHwBase + MCSPI_REVISION)));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    61
	TInt r = KErrNone;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    62
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    63
	// Create the DFCQ to be used by the channel
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    64
	if(!iDfcQ)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    65
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    66
		TBuf8<KMaxName> threadName (KIicPslThreadName);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    67
		threadName.AppendNum(iChannelNumber);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    68
		r = Kern::DfcQCreate(iDfcQ, KIicPslThreadPriority, &threadName);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    69
		if(r != KErrNone)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    70
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    71
			DBG_ERR(Kern::Printf("DFC Queue creation failed, channel number: %d, r = %d\n", iChannelNumber, r));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    72
			return r;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    73
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    74
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    75
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    76
	// PIL Base class initialization - this must be called prior to SetDfcQ(iDfcQ)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    77
	r = Init();
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    78
	if(r == KErrNone)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    79
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    80
		// Call base class function to set DFCQ pointers in the required objects
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    81
		// This also enables the channel to process transaction requests
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    82
		SetDfcQ(iDfcQ);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    83
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    84
		// PSL DFCQ initialisation for local DFC
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    85
		iTransferEndDfc.SetDfcQ(iDfcQ);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    86
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    87
		// Bind interrupts.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    88
		r = Interrupt::Bind(iIrqId, Isr, this);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    89
		if(r < KErrNone)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    90
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    91
			DBG_ERR(Kern::Printf("ERROR: InterruptBind error.. %d", r));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    92
			return r;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    93
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    94
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    95
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    96
	// Make sure clocks are enabled (TBD: this could go to 'PowerUp/PowerDown' if using PRM)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    97
	Prcm::SetClockState( Prcm::EClkMcSpi3_F, Prcm::EClkOn );
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    98
	Prcm::SetClockState( Prcm::EClkMcSpi3_I, Prcm::EClkOn );
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
    99
	// TODO:consider auto-idle for PRCM.CM_AUTOIDLE1_CORE
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   100
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   101
	// setup default spi pins. For channel 2 (McSPI3) it can be configured dynamically
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   102
	SetupSpiPins(iChannelNumber);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   103
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   104
	return r;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   105
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   106
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   107
// A static method used to construct the DSpiMasterBeagle object.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   108
DSpiMasterBeagle* DSpiMasterBeagle::New(TInt aChannelNumber, const TBusType aBusType, const TChannelDuplex aChanDuplex)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   109
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   110
	DBGPRINT(Kern::Printf("DSpiMasterBeagle::NewL(): ChannelNumber = %d, BusType =%d", aChannelNumber, aBusType));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   111
	DSpiMasterBeagle *pChan = new DSpiMasterBeagle(aChannelNumber, aBusType, aChanDuplex);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   112
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   113
	TInt r = KErrNoMemory;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   114
	if(pChan)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   115
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   116
		r = pChan->DoCreate();
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   117
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   118
	if(r != KErrNone)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   119
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   120
		delete pChan;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   121
		pChan = NULL;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   122
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   123
	return pChan;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   124
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   125
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   126
// This method is called by the PIL to initiate the transaction. After finishing it's processing,
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   127
// the PSL calls the PIL function CompleteRequest to indicate the success (or otherwise) of the request
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   128
TInt DSpiMasterBeagle::DoRequest(TIicBusTransaction* aTransaction)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   129
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   130
	DBGPRINT(Kern::Printf("\n=>DSpiMasterBeagle::DoRequest (aTransaction=0x%x)\n", aTransaction));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   131
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   132
	// If the pointer to the transaction passed in as a parameter, or its associated pointer to the
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   133
	// header information is NULL, return KErrArgument
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   134
	if(!aTransaction || !GetTransactionHeader(aTransaction))
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   135
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   136
		return KErrArgument;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   137
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   138
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   139
	// The PSL operates a simple state machine to ensure that only one transaction is processed
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   140
	// at a time - if the channel is currently busy, reject the request (PIL should not try that!)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   141
	if(iState != EIdle)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   142
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   143
		return KErrInUse;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   144
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   145
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   146
	// copy pointer to the transaction
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   147
	iCurrTransaction = aTransaction;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   148
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   149
	// Configure the hardware to support the transaction
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   150
	TInt r = PrepareConfiguration();
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   151
	if(r == KErrNone)
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   152
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   153
		r = ConfigureInterface();
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   154
		if(r == KErrNone)
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   155
			{
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   156
			// start processing transfers of this transaction.
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   157
			r = ProcessNextTransfers();
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   158
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   159
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   160
	return r;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   161
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   162
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   163
TInt DSpiMasterBeagle::PrepareConfiguration()
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   164
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   165
	TConfigSpiV01 &newHeader = (*(TConfigSpiBufV01*) (GetTransactionHeader(iCurrTransaction)))();
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   166
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   167
	// get the slave address (i.e. known as a 'channel' for the current SPI module)
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   168
	TInt busId       = iCurrTransaction->GetBusId();
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   169
	TInt slaveAddr   = GET_SLAVE_ADDR(busId);
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   170
	TInt slavePinSet = 0;
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   171
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   172
	if(slaveAddr >= KMcSpiNumSupportedSlaves[iChannelNumber]) // address is 0-based
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   173
		{
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   174
		DBG_ERR(Kern::Printf("Slave address for McSPI%d should be < %, was: %d !",
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   175
				iChannelNumber + 1, KMcSpiNumSupportedSlaves[iChannelNumber], slaveAddr));
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   176
		return KErrArgument; // Slave address out of range
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   177
		}
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   178
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   179
	// Slave addresses > 1 for McSPI3 (iChannel2) really means alternative pin settings,
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   180
	// so adjust it in such case. *Pin set indexes are +1 to skip over the pin set for McSPI4
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   181
	// channel in the pin configuration table.
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   182
	if(iChannelNumber == 2 && slaveAddr > 1)
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   183
		{
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   184
		slavePinSet  =  slaveAddr > 3 ?  3 : 2; // slaveAddr: 2-3: pin set 2(1*); 4-5: pin set 3(2*)
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   185
		slaveAddr &= 1; // modulo 2 (i.e. 2 CS for McSPI3)
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   186
		}
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   187
85
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   188
	// reconfigure pins if needed..
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   189
	if(slavePinSet != iCurrSlavePinSet)
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   190
		{
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   191
		iCurrSlavePinSet = slavePinSet;
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   192
		SetupSpiPins(iChannelNumber, iCurrSlavePinSet);
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   193
		}
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   194
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   195
	// store configuration parameters
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   196
	iCurrSS          = slaveAddr;
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   197
	iCurrHeader      = newHeader; //copy the header..
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   198
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   199
	return KErrNone;
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   200
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   201
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   202
// Init the hardware with the data provided in the transaction and slave-address field
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   203
// (these values are already stored in the iCurrHeader)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   204
TInt DSpiMasterBeagle::ConfigureInterface()
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   205
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   206
	DBGPRINT(Kern::Printf("ConfigureInterface()"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   207
82
65b40f262685 updated cs pin handling
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 77
diff changeset
   208
	// soft reset the SPI..
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   209
	TUint val = AsspRegister::Read32(iHwBase + MCSPI_SYSCONFIG);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   210
	val = MCSPI_SYSCONFIG_SOFTRESET;  // issue reset
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   211
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   212
	AsspRegister::Write32(iHwBase + MCSPI_SYSCONFIG, MCSPI_SYSCONFIG_SOFTRESET);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   213
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   214
	val = 0; // TODO will add here this 'smart-wait' stuff that was proposed earlier..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   215
	while (!(val & MCSPI_SYSSTATUS_RESETDONE))
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   216
		val = AsspRegister::Read32(iHwBase + MCSPI_SYSSTATUS);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   217
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   218
	// disable and clear all interrupts..
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   219
	AsspRegister::Write32(iHwBase + MCSPI_IRQENABLE, 0);
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   220
	AsspRegister::Write32(iHwBase + MCSPI_IRQSTATUS,
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   221
	                      MCSPI_IRQ_RX_FULL(iCurrSS) |
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   222
	                      MCSPI_IRQ_RX_FULL(iCurrSS) |
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   223
	                      MCSPI_IRQ_TX_UNDERFLOW(iCurrSS) |
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   224
	                      MCSPI_IRQ_TX_EMPTY(iCurrSS) |
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   225
	                      MCSPI_IRQ_RX_OVERFLOW);
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   226
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   227
	// channel configuration
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   228
	//	Set the SPI1.MCSPI_CHxCONF[18] IS bit to 0 for the spi1_somi pin in receive mode.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   229
	//	val = MCSPI_CHxCONF_IS; // pin selection (somi - simo)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   230
	// TODO configuration of PINS could also be configurable on a 'per SPI module' basis..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   231
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   232
	// Set the SPI1.MCSPI_CHxCONF[17] DPE1 bit to 0 and the SPI1.MCSPI_CHxCONF[16] DPE0 bit to 1 for the spi1.simo pin in transmit mode.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   233
	val = MCSPI_CHxCONF_DPE0;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   234
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   235
	// Set transmit & | receive mode for transmit only mode here. If needed - it will be changed dynamically.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   236
	val |= MCSPI_CHxCONF_TRM_NO_RECEIVE;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   237
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   238
	// set word length.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   239
	val |= SpiWordWidth(iCurrHeader.iWordWidth);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   240
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   241
	// use the appropriate word with (assuming the data is aligned to bytes).
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   242
	if(iCurrHeader.iWordWidth > ESpiWordWidth_16)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   243
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   244
		iWordSize = 4;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   245
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   246
	else if (iCurrHeader.iWordWidth > ESpiWordWidth_8)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   247
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   248
		iWordSize = 2;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   249
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   250
	else
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   251
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   252
		iWordSize = 1;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   253
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   254
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   255
	// set Slave Select / Chip select signal mode
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   256
	val |= iCurrHeader.iSSPinActiveMode == ESpiCSPinActiveLow ? MCSPI_CHxCONF_EPOL_LOW : 0;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   257
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   258
	// set the CLK POL and PHA (clock mode)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   259
	val |= SpiClkMode(iCurrHeader.iClkMode);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   260
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   261
	// Set clock. Note that CheckHdr() will be called prior to this function for this header,
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   262
	// so the value iClkSpeedHz is valid at this point, the KErrNotSupported is not possible
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   263
	// so the return value check can be ommited here
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   264
	val |= SpiClkValue(iCurrHeader.iClkSpeedHz);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   265
	// __ASSERT_DEBUG(val >= KErrNone, Kern::Fault("spi/master.cpp, line: ", __LINE__));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   266
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   267
#ifdef USE_TX_FIFO
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   268
	// enable fifo for transmission..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   269
	// Update me: this can only set in a 'single' mode.. or for only one channel
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   270
	// but at the momment IIC SPI is used in 'single' mode onlny..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   271
	val |= MCSPI_CHxCONF_FFEW;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   272
//	val |= MCSPI_CHxCONF_FFER; // fifo enable for receive.. (TODO)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   273
#endif
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   274
85
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   275
	val |= (iCurrHeader.iTransactionWaitCycles & 3) << MCSPI_CHxCONF_TCS_SHIFT;
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   276
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   277
	// update the register..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   278
	AsspRegister::Write32(iHwBase + MCSPI_CHxCONF(iCurrSS), val);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   279
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   280
	// set spim_somi pin direction to input
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   281
	val = MCSPI_SYST_SPIDATDIR0;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   282
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   283
	// drive csx pin to inactive state
82
65b40f262685 updated cs pin handling
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 77
diff changeset
   284
	if(iCurrHeader.iSSPinActiveMode == ESpiCSPinActiveLow)
65b40f262685 updated cs pin handling
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 77
diff changeset
   285
		{
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   286
		AsspRegister::Modify32(iHwBase + MCSPI_SYST, 1u << iCurrSS, 0);
82
65b40f262685 updated cs pin handling
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 77
diff changeset
   287
		}
65b40f262685 updated cs pin handling
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 77
diff changeset
   288
	else
65b40f262685 updated cs pin handling
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 77
diff changeset
   289
		{
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   290
		AsspRegister::Modify32(iHwBase + MCSPI_SYST, 0, (1u << iCurrSS));
82
65b40f262685 updated cs pin handling
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 77
diff changeset
   291
		}
65b40f262685 updated cs pin handling
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 77
diff changeset
   292
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   293
	// Set the MS bit to 0 to provide the clock (ie. to setup as master)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   294
#ifndef SINGLE_MODE
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   295
	AsspRegister::Write32(iHwBase + MCSPI_MODULCTRL, MCSPI_MODULCTRL_MS_MASTER);
85
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   296
	// change the pad config - now the SPI drives the line appropriately..
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   297
	SetCsActive(iChannelNumber, iCurrSS, iCurrSlavePinSet);
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   298
#else
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   299
	AsspRegister::Write32(iHwBase + MCSPI_MODULCTRL, MCSPI_MODULCTRL_MS_MASTER | MCSPI_MODULCTRL_SINGLE);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   300
#endif
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   301
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   302
	return KErrNone;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   303
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   304
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   305
TInt DSpiMasterBeagle::ProcessNextTransfers()
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   306
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   307
	DBGPRINT(Kern::Printf("DSpiMasterBeagle::ProcessNextTransfers():%s", iState==EIdle ? "first" : "next"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   308
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   309
	// Since new transfers are strating, clear exisiting flags
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   310
	iOperation.iValue = TIicOperationType::ENop;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   311
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   312
	// If this is the first transfer in the transaction the channel will be in state EIdle
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   313
	if(iState == EIdle)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   314
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   315
		// Get the pointer to half-duplex transfer object..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   316
		iHalfDTransfer = GetTransHalfDuplexTferPtr(iCurrTransaction);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   317
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   318
		// Get the pointer to full-duplex transfer object..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   319
		iFullDTransfer = GetTransFullDuplexTferPtr(iCurrTransaction);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   320
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   321
		// Update the channel state to EBusy and initialise the transaction status
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   322
		iState = EBusy;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   323
		iTransactionStatus = KErrNone;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   324
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   325
		// start timeout timer for this transaction
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   326
		StartSlaveTimeOutTimer(iCurrHeader.iTimeoutPeriod);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   327
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   328
	else
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   329
	// If not in state EIdle, get the next transfer in the linked-list held by the transaction
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   330
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   331
		// Get the pointer the next half-duplex transfer object..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   332
		iHalfDTransfer = GetTferNextTfer(iHalfDTransfer);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   333
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   334
		// Get the pointer to the next half-duplex transfer object..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   335
		if(iFullDTransfer)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   336
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   337
			iFullDTransfer = GetTferNextTfer(iFullDTransfer);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   338
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   339
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   340
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   341
	TInt r = KErrNone;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   342
	if(!iFullDTransfer && !iHalfDTransfer)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   343
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   344
		// There is no more to transfer - and all previous were were completed,
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   345
		DBGPRINT(Kern::Printf("All transfers completed successfully"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   346
		ExitComplete(KErrNone);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   347
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   348
	else
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   349
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   350
		// Process next transfers
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   351
		TInt8 hDTrType = (TInt8) GetTferType(iHalfDTransfer);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   352
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   353
		if(iFullDTransfer)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   354
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   355
			// For full-duplex transfer setup the read transfer first, as it doesn't
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   356
			// really start anything - SPI master starts operation when Tx (or clocks)starts..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   357
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   358
			if(hDTrType == TIicBusTransfer::EMasterRead)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   359
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   360
				r = StartTransfer(iHalfDTransfer, TIicBusTransfer::EMasterRead);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   361
				if(r != KErrNone)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   362
					{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   363
					return r;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   364
					}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   365
				r = StartTransfer(iFullDTransfer, TIicBusTransfer::EMasterWrite);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   366
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   367
			else // hDTrType == TIicBusTransfer::EMasterWrite)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   368
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   369
				r = StartTransfer(iFullDTransfer, TIicBusTransfer::EMasterRead);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   370
				if(r != KErrNone)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   371
					{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   372
					return r;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   373
					}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   374
				r = StartTransfer(iHalfDTransfer, TIicBusTransfer::EMasterWrite);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   375
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   376
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   377
		else
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   378
		// This is a HalfDuplex transfer - so just start it
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   379
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   380
			r = StartTransfer(iHalfDTransfer, hDTrType);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   381
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   382
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   383
	return r;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   384
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   385
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   386
TInt DSpiMasterBeagle::StartTransfer(TIicBusTransfer* aTransferPtr, TUint8 aType)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   387
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   388
	DBGPRINT(Kern::Printf("DSpiMasterBeagle::StartTransfer() @0x%x, aType: %s",
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   389
			               aTransferPtr, aType == TIicBusTransfer::EMasterWrite ? "write" : "read"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   390
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   391
	if(aTransferPtr == NULL)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   392
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   393
		DBG_ERR(Kern::Printf("DSpiMasterBeagle::StartTransfer - NULL pointer\n"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   394
		return KErrArgument;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   395
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   396
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   397
	TInt r = KErrNone;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   398
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   399
	switch(aType)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   400
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   401
		case TIicBusTransfer::EMasterWrite:
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   402
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   403
			DBGPRINT(Kern::Printf("Starting EMasterWrite, duplex=%x", iFullDTransfer));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   404
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   405
			// Get a pointer to the transfer object's buffer, to facilitate passing arguments to DoTransfer
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   406
			const TDes8* desBufPtr = GetTferBuffer(aTransferPtr);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   407
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   408
			DBGPRINT(Kern::Printf("Length %d, iWordSize %d", desBufPtr->Length(), iWordSize));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   409
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   410
			// Store the current address and ending address for Transmission - they are required by the ISR and DFC
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   411
			iTxData    = (TInt8*)  desBufPtr->Ptr();
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   412
			iTxDataEnd = (TInt8*) (iTxData + desBufPtr->Length());
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   413
			if ((TInt)iTxDataEnd % iWordSize)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   414
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   415
				DBG_ERR(Kern::Printf("Wrong configuration - word size does not match buffer length"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   416
				return KErrArgument;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   417
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   418
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   419
			DBGPRINT(Kern::Printf("Tx: Start: %x, End %x, bytes %d", iTxData, iTxDataEnd, desBufPtr->Length()));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   420
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   421
			// Set the flag to indicate that we'll be transmitting data
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   422
			iOperation.iOp.iIsTransmitting = ETrue;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   423
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   424
			// initiate the transmission..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   425
			r = DoTransfer(aType);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   426
			if(r != KErrNone)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   427
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   428
				DBG_ERR(Kern::Printf("Starting Write failed, r = %d", r));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   429
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   430
			break;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   431
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   432
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   433
		case TIicBusTransfer::EMasterRead:
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   434
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   435
			DBGPRINT(Kern::Printf("Starting EMasterRead, duplex=%x", iFullDTransfer));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   436
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   437
			// Get a pointer to the transfer object's buffer, to facilitate passing arguments to DoTransfer
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   438
			const TDes8* aBufPtr = GetTferBuffer(aTransferPtr);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   439
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   440
			// Store the current address and ending address for Reception - they are required by the ISR and DFC
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   441
			iRxData = (TInt8*) aBufPtr->Ptr();
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   442
			iRxDataEnd = (TInt8*) (iRxData + aBufPtr->Length());
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   443
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   444
			DBGPRINT(Kern::Printf("Rx: Start: %x, End %x, bytes %d", iRxData, iRxDataEnd, aBufPtr->Length()));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   445
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   446
			// Set the flag to indicate that we'll be receiving data
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   447
			iOperation.iOp.iIsReceiving = ETrue;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   448
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   449
			// initiate the reception
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   450
			r = DoTransfer(aType);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   451
			if(r != KErrNone)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   452
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   453
				DBG_ERR(Kern::Printf("Starting Read failed, r = %d", r));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   454
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   455
			break;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   456
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   457
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   458
		default:
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   459
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   460
			DBG_ERR(Kern::Printf("Unsupported TransactionType %x", aType));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   461
			r = KErrArgument;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   462
			break;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   463
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   464
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   465
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   466
	return r;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   467
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   468
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   469
// Method called by StartTransfer to actually initiate the transfers.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   470
TInt DSpiMasterBeagle::DoTransfer(TUint8 aType)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   471
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   472
	DBGPRINT(Kern::Printf("\nDSpiMasterBeagle::DoTransfer()"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   473
	TInt r = KErrNone;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   474
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   475
	AsspRegister::Write32(iHwBase + MCSPI_IRQSTATUS, ~0);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   476
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   477
	switch(aType)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   478
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   479
		case TIicBusTransfer::EMasterWrite:
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   480
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   481
			// enable the channel here..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   482
			AsspRegister::Write32(iHwBase + MCSPI_CHxCTRL(iCurrSS), MCSPI_CHxCTRL_EN);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   483
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   484
			AsspRegister::Modify32(iHwBase + MCSPI_IRQSTATUS, 0,
82
65b40f262685 updated cs pin handling
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 77
diff changeset
   485
			                       MCSPI_IRQ_TX_EMPTY(iCurrSS) /*| MCSPI_IRQ_TX_UNDERFLOW(iCurrSS)*/);
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   486
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   487
			AsspRegister::Modify32(iHwBase + MCSPI_IRQENABLE, 0,
82
65b40f262685 updated cs pin handling
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 77
diff changeset
   488
			                       MCSPI_IRQ_TX_EMPTY(iCurrSS) /*| MCSPI_IRQ_TX_UNDERFLOW(iCurrSS)*/);
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   489
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   490
#ifdef SINGLE_MODE
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   491
			// in SINGLE mode needs to manually assert CS line for current
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   492
			AsspRegister::Modify32(iHwBase + MCSPI_CHxCONF(iCurrSS), 0, MCSPI_CHxCONF_FORCE);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   493
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   494
			// change the pad config - now the SPI drives the line appropriately..
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   495
			SetCsActive(iChannelNumber, iCurrSS, iCurrSlavePinSet);
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   496
#endif /*SINGLE_MODE*/
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   497
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   498
#ifdef USE_TX_FIFO
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   499
			const TInt KTxFifoThreshold = 8;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   500
			TUint numWordsToTransfer = (iTxDataEnd - iTxData);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   501
			TUint wordsToWrite = Min(numWordsToTransfer/iWordSize, KTxFifoThreshold/iWordSize);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   502
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   503
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   504
			TInt iAlmostFullLevel = 0;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   505
			TInt iAlmostEmptyLevel = 1; //KTxFifoThreshold;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   506
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   507
			// setup FIFOs
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   508
			AsspRegister::Write32(iHwBase + MCSPI_XFERLEVEL,
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   509
								  MCSPI_XFERLEVEL_WCNT(0) | // total num words
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   510
								  MCSPI_XFERLEVEL_AFL(iAlmostFullLevel)     | // Rx almost full
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   511
								  MCSPI_XFERLEVEL_AEL(iAlmostEmptyLevel) );   // Tx almost empty
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   512
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   513
			// copy data to fifo..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   514
			for (TInt i = 0; i < wordsToWrite; i++)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   515
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   516
				iTxData += iWordSize;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   517
				AsspRegister::Write32(iHwBase + MCSPI_TXx(iCurrSS), *(iTxData -iWordSize));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   518
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   519
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   520
#else /*USE_TX_FIFO*/
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   521
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   522
			TUint val = 0;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   523
			for (TInt i = 0; i < iWordSize; i++)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   524
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   525
				val |= (*iTxData++) << i * 8;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   526
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   527
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   528
			DEBUG_ONLY(DumpCurrentStatus("DoTransfer(Write)"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   529
			AsspRegister::Write32(iHwBase + MCSPI_TXx(iCurrSS), val);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   530
#endif /*USE_TX_FIFO*/
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   531
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   532
			// enable system interrupt
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   533
			Interrupt::Enable(iIrqId);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   534
			break;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   535
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   536
		case TIicBusTransfer::EMasterRead:
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   537
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   538
			// enable transmit and receive..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   539
			AsspRegister::Modify32(iHwBase + MCSPI_CHxCONF(iCurrSS), MCSPI_CHxCONF_TRM_NO_RECEIVE, 0);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   540
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   541
			// for single read (not duplex) one way to to allow clock generation is to enable Tx
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   542
			// and write '0' to Txregister (just like in duplex transaction). We also need to assert Cs line.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   543
			if(!iFullDTransfer)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   544
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   545
				// enable the channel..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   546
				AsspRegister::Write32(iHwBase + MCSPI_CHxCTRL(iCurrSS), MCSPI_CHxCTRL_EN);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   547
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   548
				// enable TX and RX Empty interrupts
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   549
				AsspRegister::Modify32(iHwBase + MCSPI_IRQSTATUS, 0, MCSPI_IRQ_TX_EMPTY(iCurrSS) | MCSPI_IRQ_RX_FULL(iCurrSS));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   550
				AsspRegister::Modify32(iHwBase + MCSPI_IRQENABLE, 0, MCSPI_IRQ_TX_EMPTY(iCurrSS) | MCSPI_IRQ_RX_FULL(iCurrSS));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   551
#ifdef SINGLE_MODE
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   552
				// in SINGLE mode needs to manually assert CS line for current
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   553
				AsspRegister::Modify32(iHwBase + MCSPI_CHxCONF(iCurrSS), 0, MCSPI_CHxCONF_FORCE);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   554
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   555
				// change the pad config - now the SPI drives the line appropriately..
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   556
				SetCsActive(iChannelNumber, iCurrSS, iCurrSlavePinSet);
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   557
#endif /*SINGLE_MODE*/
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   558
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   559
			else
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   560
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   561
				// enable only interrupts for RX here. Tx is handled in EMasterWrite case above.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   562
				AsspRegister::Write32(iHwBase + MCSPI_IRQSTATUS, MCSPI_IRQ_RX_FULL(iCurrSS));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   563
				AsspRegister::Write32(iHwBase + MCSPI_IRQENABLE, MCSPI_IRQ_RX_FULL(iCurrSS));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   564
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   565
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   566
			DEBUG_ONLY(DumpCurrentStatus("DoTransfer(Read)"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   567
			// and enable system interrupts
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   568
			if(!iFullDTransfer)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   569
				Interrupt::Enable(iIrqId);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   570
			break;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   571
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   572
		default:
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   573
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   574
			DBG_ERR(Kern::Printf("Unsupported TransactionType %x", aType));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   575
			r = KErrArgument;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   576
			break;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   577
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   578
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   579
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   580
	return r;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   581
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   582
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   583
#ifdef _DEBUG
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   584
static TInt IsrCnt = 0;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   585
void DSpiMasterBeagle::DumpCurrentStatus(const TInt8* aWhere /*=NULL*/)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   586
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   587
	if(aWhere)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   588
		Kern::Printf("------ Status (%s)--------", aWhere);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   589
	else
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   590
		Kern::Printf("------ Status --------");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   591
	Kern::Printf("\niTransactionStatus: %d", iTransactionStatus);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   592
	Kern::Printf("iTransferEndDfc %s queued", iTransferEndDfc.Queued() ? "" : "NOT");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   593
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   594
	if(iOperation.iOp.iIsTransmitting)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   595
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   596
		Kern::Printf("TX STATUS:");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   597
		Kern::Printf("  iTxData    %x", iTxData);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   598
		Kern::Printf("  iTxDataEnd %x", iTxDataEnd);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   599
		Kern::Printf("  left to write: %x (words)", (iTxDataEnd - iTxData)/iWordSize);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   600
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   601
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   602
	if(iOperation.iOp.iIsReceiving)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   603
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   604
		Kern::Printf("RX STATUS:");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   605
		Kern::Printf("  iRxData    %x", iRxData);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   606
		Kern::Printf("  iRxDataEnd %x", iRxDataEnd);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   607
		Kern::Printf("  left to read: %x (words)", (iRxDataEnd - iRxData)/iWordSize);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   608
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   609
	Kern::Printf("  iCurrSS %d",iCurrSS);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   610
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   611
	Kern::Printf("IsrCnt %d", IsrCnt);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   612
	TUint status = AsspRegister::Read32(iHwBase + MCSPI_IRQSTATUS);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   613
	Kern::Printf("MCSPI_IRQSTATUS (0x%x):", status);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   614
	if(status & MCSPI_IRQ_TX_EMPTY(iCurrSS))
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   615
		Kern::Printf("   MCSPI_IRQ_TX_EMPTY");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   616
	if(status & MCSPI_IRQ_TX_UNDERFLOW(iCurrSS))
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   617
		Kern::Printf("   MCSPI_IRQ_TX_UNDERFLOW");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   618
	if(!iCurrSS && status & MCSPI_IRQ_RX_OVERFLOW)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   619
		Kern::Printf("   MCSPI_IRQ_RX_OVERFLOW");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   620
	if(status & MCSPI_IRQ_RX_FULL(iCurrSS))
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   621
		Kern::Printf("   MCSPI_IRQ_RX_FULL");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   622
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   623
	Kern::Printf("MCSPI_CHxSTAT(%d):", iCurrSS);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   624
	status = AsspRegister::Read32(iHwBase + MCSPI_CHxSTAT(iCurrSS));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   625
	if(status & MCSPI_CHxSTAT_RXFFF)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   626
		Kern::Printf("   MCSPI_CHxSTAT_RXFFF");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   627
	if(status & MCSPI_CHxSTAT_RXFFE)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   628
		Kern::Printf("   MCSPI_CHxSTAT_RXFFE");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   629
	if(status & MCSPI_CHxSTAT_TXFFF)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   630
		Kern::Printf("   MCSPI_CHxSTAT_TXFFF");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   631
	if(status & MCSPI_CHxSTAT_TXFFE)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   632
		Kern::Printf("   MCSPI_CHxSTAT_TXFFE");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   633
	if(status & MCSPI_CHxSTAT_EOT)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   634
		Kern::Printf("   MCSPI_CHxSTAT_EOT");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   635
	if(status & MCSPI_CHxSTAT_TXS)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   636
		Kern::Printf("   MCSPI_CHxSTAT_TXS");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   637
	if(status & MCSPI_CHxSTAT_RXS)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   638
		Kern::Printf("   MCSPI_CHxSTAT_RXS");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   639
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   640
	Kern::Printf("MCSPI_XFERLEVEL:");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   641
	status = AsspRegister::Read32(iHwBase + MCSPI_XFERLEVEL);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   642
	Kern::Printf("   MCSPI_XFERLEVEL_WCNT %d", status >> MCSPI_XFERLEVEL_WCNT_OFFSET);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   643
	Kern::Printf("   MCSPI_XFERLEVEL_AFL %d", (status >> MCSPI_XFERLEVEL_AFL_OFFSET) & 0x3F);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   644
	Kern::Printf("   MCSPI_XFERLEVEL_AEL %d\n", (status >> MCSPI_XFERLEVEL_AEL_OFFSET) & 0x1F);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   645
	Kern::Printf("---------------------------------------/*\n\n\n");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   646
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   647
#endif
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   648
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   649
void DSpiMasterBeagle::Isr(TAny* aPtr)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   650
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   651
	DSpiMasterBeagle *a = (DSpiMasterBeagle*) aPtr;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   652
	DEBUG_ONLY(IsrCnt++);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   653
	DEBUG_ONLY(a->DumpCurrentStatus("Isr entry"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   654
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   655
	TUint32 status = AsspRegister::Read32(a->iHwBase + MCSPI_IRQSTATUS);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   656
	AsspRegister::Write32(a->iHwBase + MCSPI_IRQSTATUS, status); // clear status bits..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   657
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   658
	// TX_EMPTY - when an item (or number of items if FIFO is used) was transmitted..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   659
	if(status & MCSPI_IRQ_TX_EMPTY(a->iCurrSS))
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   660
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   661
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   662
		if(a->iOperation.iOp.iIsTransmitting)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   663
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   664
#ifdef USE_TX_FIFO
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   665
			// when FIFO is used - should write (at least) the MCSPI_XFERLEVEL_AFL + 1 words to this register..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   666
			while(a->iTxData != a->iTxDataEnd)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   667
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   668
				AsspRegister::Write32(a->iHwBase + MCSPI_TXx(a->iCurrSS), *a->iTxData);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   669
				a->iTxData += a->iWordSize;	// Then increment the pointer to the data.s
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   670
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   671
				if(AsspRegister::Read32(a->iHwBase + MCSPI_CHxSTAT(a->iCurrSS)) & MCSPI_CHxSTAT_TXFFF)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   672
					{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   673
					break;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   674
					}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   675
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   676
#else
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   677
			// transfer next word..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   678
			if(a->iTxData != a->iTxDataEnd)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   679
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   680
				TUint val = 0;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   681
				for (TInt i = 0; i < a->iWordSize; i++)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   682
					{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   683
					val |= (*a->iTxData++) << i * 8;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   684
					}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   685
				AsspRegister::Write32(a->iHwBase + MCSPI_TXx(a->iCurrSS), val);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   686
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   687
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   688
			// check again - if this was the last one..and we're not waiting for rx - end transfer
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   689
			if(a->iTxData == a->iTxDataEnd && !a->iOperation.iOp.iIsReceiving)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   690
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   691
				Interrupt::Disable(a->iIrqId);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   692
				a->iTransferEndDfc.Add();
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   693
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   694
#endif
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   695
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   696
		else
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   697
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   698
			// writing a 'dummy' word (for read only transferss (writing 0 doesn't change line state)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   699
			AsspRegister::Write32(a->iHwBase + MCSPI_TXx(a->iCurrSS), 0);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   700
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   701
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   702
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   703
	if(status & MCSPI_IRQ_RX_FULL(a->iCurrSS))
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   704
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   705
		if(a->iOperation.iOp.iIsReceiving)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   706
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   707
			if(a->iRxDataEnd != a->iRxData)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   708
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   709
				TUint8 nextRxValue = AsspRegister::Read32(a->iHwBase + MCSPI_RXx(a->iCurrSS));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   710
				*a->iRxData = nextRxValue;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   711
				a->iRxData += a->iWordSize;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   712
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   713
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   714
			// If the Rx buffer is now full, finish the transmission.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   715
			if(a->iRxDataEnd == a->iRxData)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   716
				{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   717
				Interrupt::Disable(a->iIrqId);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   718
				a->iTransferEndDfc.Add();
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   719
				}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   720
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   721
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   722
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   723
#if 0 // TODO - probably master, as it creates CLK for slave - will never have to bother with this..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   724
	if(status & MCSPI_IRQ_TX_UNDERFLOW(a->iCurrSS))
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   725
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   726
		DBG_ERR(Kern::Printf("Underflow"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   727
		a->iTransactionStatus = KErrUnderflow;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   728
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   729
		// disable the channel..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   730
		AsspRegister::Modify32(a->iHwBase + MCSPI_CHxCTRL(0), MCSPI_CHxCTRL_EN, 0);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   731
		Interrupt::Disable(a->iIrqId);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   732
		DEBUG_ONLY(a->DumpCurrentStatus("TxUnderflow"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   733
		DBG_ERR(Kern::Fault("TxUnderflow", 0));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   734
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   735
#endif
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   736
#if defined(USE_TX_FIFO) && defined(USING_TX_COUNTER)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   737
	if(status & MCSPI_IRQSTATUS_EOW)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   738
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   739
		Kern::Printf("EOW");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   740
		// TODO: end of transfer..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   741
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   742
#endif
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   743
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   744
	// end of ISR processing
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   745
	DEBUG_ONLY(a->DumpCurrentStatus("Isr end"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   746
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   747
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   748
void DSpiMasterBeagle::TransferEndDfc(TAny* aPtr)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   749
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   750
	DBGPRINT(Kern::Printf("DSpiMasterBeagle::TransferEndDfc"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   751
	DSpiMasterBeagle *a = (DSpiMasterBeagle*) aPtr;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   752
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   753
	TUint chanStatus = AsspRegister::Read32(a->iHwBase + MCSPI_CHxSTAT(a->iCurrSS));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   754
	if(a->iOperation.iOp.iIsTransmitting)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   755
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   756
		TUint expected = MCSPI_CHxSTAT_EOT | MCSPI_CHxSTAT_TXS;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   757
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   758
#ifdef USE_TX_FIFO
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   759
		while(!AsspRegister::Read32(a->iHwBase + MCSPI_CHxSTAT(a->iCurrSS)) & MCSPI_CHxSTAT_TXFFE);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   760
#endif
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   761
		while(chanStatus & expected != expected)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   762
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   763
			chanStatus = AsspRegister::Read32(a->iHwBase + MCSPI_CHxSTAT(a->iCurrSS));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   764
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   765
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   766
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   767
	if(a->iOperation.iOp.iIsReceiving)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   768
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   769
		TUint expected = MCSPI_CHxSTAT_RXS;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   770
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   771
		while(chanStatus & expected != expected)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   772
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   773
			chanStatus = AsspRegister::Read32(a->iHwBase + MCSPI_CHxSTAT(a->iCurrSS));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   774
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   775
		__ASSERT_DEBUG(a->iRxDataEnd == a->iRxData,
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   776
		               Kern::Fault("SPI master: exiting not having received all?", 12));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   777
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   778
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   779
#ifdef SINGLE_MODE
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   780
	// manually de-assert CS line for this channel
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   781
	AsspRegister::Modify32(a->iHwBase + MCSPI_CHxCONF(a->iCurrSS), MCSPI_CHxCONF_FORCE, 0);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   782
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   783
	// put the CS signal to 'inactive' state (as on channel disable it would have a glitch)
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   784
	SetCsInactive(a->iChannelNumber, a->iCurrSS, a->iCurrHeader.iSSPinActiveMode, a->iCurrSlavePinSet);
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   785
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   786
#endif
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   787
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   788
	// disable the channel
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   789
	AsspRegister::Modify32(a->iHwBase + MCSPI_CHxCTRL(0), MCSPI_CHxCTRL_EN, 0);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   790
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   791
	// Start the next transfer for this transaction, if any remain
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   792
	if(a->iState == EBusy)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   793
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   794
		TInt err = a->ProcessNextTransfers();
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   795
		if(err != KErrNone)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   796
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   797
			// If the next transfer could not be started, complete the transaction with
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   798
			// the returned error code
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   799
			a->ExitComplete(err);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   800
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   801
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   802
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   803
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   804
void DSpiMasterBeagle::ExitComplete(TInt aErr, TBool aComplete /*= ETrue*/)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   805
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   806
	DBGPRINT(Kern::Printf("DSpiMasterBeagle::ExitComplete, aErr %d, aComplete %d", aErr, aComplete));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   807
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   808
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   809
	// in the case of error - make sure to reset the channel
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   810
	if(aErr != KErrNone)
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   811
		{
85
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   812
		// make sure CS is in inactive state (for the current / last transaction) on error
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   813
		// TODO: add extendable transaction support (..i.e. with no de-assertion of CS pin between such transactions)
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   814
		SetCsInactive(iChannelNumber, iCurrSS, iCurrHeader.iSSPinActiveMode, iCurrSlavePinSet);
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   815
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   816
		// disable this channel
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   817
		AsspRegister::Modify32(iHwBase + MCSPI_CHxCTRL(iCurrSS), MCSPI_CHxCTRL_EN, 0);
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   818
84
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   819
		AsspRegister::Write32(iHwBase + MCSPI_SYSCONFIG, MCSPI_SYSCONFIG_SOFTRESET);
09e266454dcf Update SPI master pin handling: added dynamic pin configuration for McSPI3 (needed if want to use multiple device on this interface. Now following number of Slave devices is available: McSPI1: 4, McSPI2: 2, McSPI3: 6 (2 per each pin configuration), McSPI4: 1. Only McSPI3 and McSPI4 are available now -there are issues with McSPI1 & 2 due to register access (something wrong with mapping? There is Fault Category: Exception Fault Reason: 10000000
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 82
diff changeset
   820
		iCurrSS = -1; // make sure the interface will be re-configured at next transaction
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   821
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   822
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   823
	// Disable interrupts for the channel
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   824
	Interrupt::Disable(iIrqId);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   825
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   826
	// Cancel any timers and DFCs..
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   827
	CancelTimeOut();
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   828
	iTransferEndDfc.Cancel();
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   829
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   830
	// Change the channel state back to EIdle
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   831
	iState = EIdle;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   832
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   833
	// Call the PIL method to complete the request
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   834
	if(aComplete)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   835
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   836
		CompleteRequest(aErr);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   837
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   838
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   839
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   840
#ifdef _DEBUG
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   841
void DumpHeader(TConfigSpiV01& aHeader)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   842
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   843
	Kern::Printf("header:");
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   844
	Kern::Printf("iWordWidth %d (%d bits)", aHeader.iWordWidth, (SpiWordWidth(aHeader.iWordWidth)) >> MCSPI_CHxCONF_WL_OFFSET + 1);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   845
	Kern::Printf("iClkSpeedHz %d", aHeader.iClkSpeedHz);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   846
	Kern::Printf("iClkMode %d", aHeader.iClkMode);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   847
	Kern::Printf("iTimeoutPeriod %d", aHeader.iTimeoutPeriod);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   848
	Kern::Printf("iBitOrder %d", aHeader.iBitOrder);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   849
	Kern::Printf("iTransactionWaitCycles %d", aHeader.iTransactionWaitCycles);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   850
	Kern::Printf("iSSPinActiveMode %d", aHeader.iSSPinActiveMode);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   851
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   852
#endif
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   853
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   854
// virtual method called by the PIL when a transaction is queued (with QueueTransaction).
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   855
// This is done in the context of the Client's thread.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   856
// The PSL is required to check that the transaction header is valid for this channel.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   857
TInt DSpiMasterBeagle::CheckHdr(TDes8* aHdrBuff)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   858
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   859
	TInt r = KErrNone;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   860
	if(!aHdrBuff)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   861
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   862
		r = KErrArgument;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   863
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   864
	else
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   865
		{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   866
		TConfigSpiV01 &header = (*(TConfigSpiBufV01*) (aHdrBuff))();
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   867
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   868
		// check if word width and clock are supported
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   869
		if(SpiWordWidth(header.iWordWidth) < KMinSpiWordWidth ||
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   870
		   SpiClkValue(header.iClkSpeedHz) < 0 || // == KErrNotSupported
85
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   871
		   header.iBitOrder == ELsbFirst ||  // this SPI only transmits MSB fist
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   872
		   (TUint)header.iTransactionWaitCycles > KMaxTransactionWaitTime) // max 3(+.5) cycles between words
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   873
			{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   874
#ifdef _DEBUG
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   875
			if(header.iBitOrder == ELsbFirst)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   876
				DBG_ERR(Kern::Printf("iClkSpeedHz value (%d) is not supported", header.iClkSpeedHz));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   877
			if(SpiClkValue(header.iClkSpeedHz) < 0)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   878
				DBG_ERR(Kern::Printf("iClkSpeedHz: %d is not supported", header.iClkSpeedHz));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   879
			if((SpiWordWidth(header.iWordWidth)+ 1) >> MCSPI_CHxCONF_WL_OFFSET < KMinSpiWordWidth)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   880
				DBG_ERR(Kern::Printf("iWordWidth: %d is not supported, min value is: %d",
85
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   881
						             SpiWordWidth(header.iWordWidth), KMinSpiWordWidth));
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   882
			if((TUint)header.iTransactionWaitCycles > 3)
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   883
				DBG_ERR(Kern::Printf("iTransactionWaitCycles: %d is not supported, value should be from 0 to %d",
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   884
				                     header.iTransactionWaitCycles, KMaxTransactionWaitTime));
d93b485c1325 updated SPI. Added template touch (byd_touch) -WORKING version,does not work-needs update as I missunderstood how the touchcontroller(chip) works. Submitting in order to share whatever there was-prior to going for holiday
Lukasz Forynski <lukasz.forynski@gmail.com>
parents: 84
diff changeset
   885
77
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   886
			DumpHeader(header);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   887
#endif
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   888
			r = KErrNotSupported;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   889
			DBG_ERR(Kern::Printf("DSpiMasterBeagle::CheckHdr()failed, r = %d", r));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   890
			}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   891
		}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   892
	return r;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   893
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   894
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   895
// This method is called by the PIL in the case of expiry of a timer for a transaction.
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   896
// TODO: this name is confusing - it could be changed in the PIL to reflect it's real purpose(TBD)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   897
// It has NOTHING to do with a Slave (i.e. slave might be completely silent for SPI-and master won't notice it!)
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   898
TInt DSpiMasterBeagle::HandleSlaveTimeout()
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   899
	{
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   900
	DBG_ERR(Kern::Printf("HandleSlaveTimeout"));
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   901
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   902
	// Stop the PSL's operation, and inform the PIL of the timeout
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   903
	ExitComplete(KErrTimedOut, EFalse);
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   904
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   905
	return KErrTimedOut;
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   906
	}
e5fd00cbb70a Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff changeset
   907