author | arunabha |
Fri, 08 Oct 2010 13:00:25 +0100 | |
branch | BYD_LCD_Integration |
changeset 86 | 56c9b613f311 |
parent 77 | e5fd00cbb70a |
permissions | -rw-r--r-- |
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 |
// omap3530/omap3530_drivers/spi/slave.cpp |
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 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
19 |
#include <drivers/iic.h> |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
20 |
#include <drivers/iic_channel.h> |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
21 |
#include "psl_init.h" |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
22 |
#include "slave.h" |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
23 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
24 |
#error "Trying to use the SPI slave, but it's not implemented yet!" |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
25 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
26 |
// The timeout period to wait for a response from the client, expressed in milliseconds |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
27 |
// This is converted to timer ticks by the PIL, so the maximum value is 2147483. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
28 |
// The value should be selected to allow for the longest, slowest transfer |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
29 |
// const TInt KClientWaitTime = 2; // 2mS, when debugging might set up to KMaxWaitTime |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
30 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
31 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
32 |
// In an SMP system, use a spin lock to guard access to member variables iTrigger and iInProgress |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
33 |
#ifdef __SMP__ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
34 |
static TSpinLock IicPslSpinLock = TSpinLock(TSpinLock::EOrderGenericIrqLow3); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
35 |
#endif |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
36 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
37 |
// Callback function for the iHwGuardTimer timer. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
38 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
39 |
// Called in ISR context if the iHwGuardTimer expires. Sets iTransactionStatus to KErrTimedOut |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
40 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
41 |
void DSpiSlaveBeagle::TimeoutCallback(TAny* aPtr) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
42 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
43 |
__KTRACE_OPT(KIIC, Kern::Printf("DCsiChannelMaster::TimeoutCallback")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
44 |
DSpiSlaveBeagle *a = (DSpiSlaveBeagle*) aPtr; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
45 |
a->iTransactionStatus = KErrTimedOut; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
46 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
47 |
|
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 |
// Static method called by the ISR when the Master has ended a transfer |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
50 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
51 |
// The method checks and reports the Rx and Tx status to the PIL by calling NotifyClient with a bitmask described as follows:. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
52 |
// - If a Tx transfer has ended before all the data was transmitted, bitmask = (ETxAllBytes | ETxOverrun) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
53 |
// - If a Tx transfer has ended and all the data was transmitted, bitmask = ETxAllBytes |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
54 |
// - If a Rx transfer has ended before the expected amount of data was received, bitmask = (ERxAllBytes | ERxUnderrun) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
55 |
// - If a Rx transfer has ended and the expected amount of data was received, bitmask = ERxAllBytes |
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 |
void DSpiSlaveBeagle::NotifyClientEnd(DSpiSlaveBeagle* aPtr) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
58 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
59 |
__KTRACE_OPT(KIIC, Kern::Printf("NotifyClientEnd, iTrigger %x", aPtr->iTrigger)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
60 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
61 |
// Since a transfer has ended, may wish to disable interrupts at this point |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
62 |
// This will likely be supported with calls similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
63 |
// AsspRegister::Write32(aPtr->iChannelBase + KBusInterruptEnableOffset, KIicPslBusDisableBitMask); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
64 |
// Interrupt::Disable(aPtr->iRxInterruptId); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
65 |
// Interrupt::Disable(aPtr->iTxInterruptId); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
66 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
67 |
// iTrigger will have bits ETransmit and EReceive set according to the operation requested in the call to DoRequest |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
68 |
// Use variable flag for the bitmask to pass into the PIL method NotifyClient |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
69 |
TInt flag = 0; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
70 |
if(aPtr->iTrigger & EReceive) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
71 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
72 |
// Requested Rx operation has ended - check for RxUnderrun |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
73 |
flag = ERxAllBytes; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
74 |
if(aPtr->iRxDataEnd != aPtr->iRxData) |
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 |
flag |= ERxUnderrun; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
77 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
78 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
79 |
if(aPtr->iTrigger & ETransmit) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
80 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
81 |
// Requested Tx operation has ended - check for RxOverrun |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
82 |
flag |= ETxAllBytes; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
83 |
if(aPtr->iTxDataEnd != aPtr->iTxData) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
84 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
85 |
flag |= ETxOverrun; |
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 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
88 |
aPtr->NotifyClient(flag); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
89 |
} |
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 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
92 |
// ISR Handler |
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 |
// The ISR handler identifies the cause of the interrupt that lead to its invocation: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
95 |
// if the cause was transfer-related, it calls the PIL function NotifyClient to report a summary of the transfer status; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
96 |
// if the cause was completion of asynchronous channel capture, PIL function ChanCaptureCallback is called |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
97 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
98 |
// The ISR also clears the source of the interrupt, and (for transfer-related interrupts) transfers the next data |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
99 |
// between buffers and the hardware and updates the member variable iInProgress to indicate if a transfer has started or |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
100 |
// ended. If a transfer has ended before the expected amount of data has been transfered it calls function NotifyClientEnd. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
101 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
102 |
void DSpiSlaveBeagle::IicPslIsr(TAny* /*aPtr*/) |
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 |
// DSpiSlaveBeagle *a = (DSpiSlaveBeagle*) aPtr; |
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 |
// TInt intState = 0; // Variable to support use of spin lock |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
107 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
108 |
// TInt trigger = 0; // Record the Rx and Tx transfers |
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 |
// TUint32 intStatus = 0; // Record of the interrupts that are being reported |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
111 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
112 |
// Identify the cause of the interrupt. If this can be achieved by reading a single register, |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
113 |
// code similar to the following could be used: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
114 |
// intStatus = AsspRegister::Read32(a->iChannelBase + KIntStatusOffset); |
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 |
// Optional (not required if asynchronous channel capture is not supported) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
117 |
// If the cause of the interrupt is completion of asynchronous channel capture, the ISR will check the appropriate |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
118 |
// indicator for confirmation of success - for a real PSL, this may be by querying a bitmask in a register. For the template PSL, |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
119 |
// however, a dummy member variable (iAsyncConfig) has been used to represent the asynchronous operation instead. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
120 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
121 |
// if(iAsyncConfig == 1) // Replace with a check of the indicator that the interrupt was due to asynchrous channel capture |
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 |
// // The PIL function ChanCaptureCallback is now to be invoked. It takes as an argument either KErrNone or a |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
124 |
// // system-wide error code to indicate the cause of failure. For a real PSL, the argument would likely be determined |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
125 |
// // by reading a bitmask in a status register - but for the template port, just use KErrNone. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
126 |
// // |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
127 |
// a->ChanCaptureCallback(KErrNone); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
128 |
// return; |
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 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
131 |
// If an interrupt indicates that a transfer has started, or that it has now ended, (such as a chip select |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
132 |
// line transition for a SPI bus the member variable iInProgress should be modified accordingly. This should |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
133 |
// be done under the guard of spin lock macros since iInProgress can be accessed in the context of the Client |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
134 |
// thread (in DoRequest, ProcessData and InitTransfer). The following structure should be adopted: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
135 |
// intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
136 |
// <access a->iInProgress> |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
137 |
// __SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
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 |
// If a transfer has ended before the expected amount of data has been transfered, function NotifyClientEnd |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
140 |
// should be called, as follows: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
141 |
// a->NotifyClientEnd(a); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
142 |
// return; // Return now - the interrupt indicated transfer end, not receipt or transmission of data. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
143 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
144 |
// The transfers that had been started are indicated by the bitmask held in member variable iTrigger. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
145 |
// This must be accessed under the guard of a spin lock since it can be accessed in the context of the |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
146 |
// Client thread (in DoRequest, ProcessData and InitTransfer). The following structure should be adopted: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
147 |
// intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
148 |
// trigger = a->iTrigger; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
149 |
// __SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
150 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
151 |
// If the interrupt was raised for a Tx event, and a Tx transfer had been started (so the interrupt was not spurious) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
152 |
// then either prepare the next data to send, or, if all the data has been sent, call the PIL function NotifyClient |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
153 |
// with bitmask (ETxAllBytes | ETxUnderrun) so that, if the Client specified a ETxUnderrun notification, it will be alerted |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
154 |
// and can determine whether another buffer of data should be provide for transmission. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
155 |
// Code similar to the following could be used: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
156 |
// if(intStatus & KTxInterruptBitMask) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
157 |
// { |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
158 |
// if(trigger & ETransmit) |
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 |
// // Interrupt was not spurious |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
161 |
// if(a->iTxData == a->iTxDataEnd) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
162 |
// { |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
163 |
// // All the data to be transmitted has been sent, so call the PIL method NotifyClient |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
164 |
// a->NotifyClient(ETxAllBytes | ETxUnderrun); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
165 |
// } |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
166 |
// else |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
167 |
// { |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
168 |
// // There is more data to be sent |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
169 |
// // TUint8 nextTxValue = *iTxData; // For this example, assumes one byte of data is to be transmitted |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
170 |
// // but if operating in 16-bit mode, bytes may need arranging for |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
171 |
// // endianness |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
172 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
173 |
// // Write to the Tx register with something similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
174 |
// // AsspRegister::Write32(iChannelBase + KTxFifoOffset, nextTxValue); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
175 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
176 |
// iTxData += iWordSize; // Then increment the pointer to the data. In this example, 8-bit mode is assumed |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
177 |
// // (iWordSize=1), but if operating in 16-bit mode iTxData would be incremented |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
178 |
// // by the number of bytes specified in iWordSize |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
179 |
// } |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
180 |
// } |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
181 |
// } |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
182 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
183 |
// If the interrupt was raised for a Rx event, and a Rx transfer had been started (so the interrupt was not spurious) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
184 |
// read the received data from the hardware to the buffer. If a Rx FIFO is being used, use a loop to drain it - until |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
185 |
// the FIFO is empty or the buffer is full. If data remains after the buffer is full, an RxOverrun condition has occurred |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
186 |
// - so the PIL function NotifyClient should be called with bitmask (ERxAllBytes | ERxOverrun) so that, if the Client specified |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
187 |
// a ERxOverrun notification, it will be alerted and can determine whether another buffer should be provided to continue reception. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
188 |
// Code similar to the following could be used: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
189 |
// if(intStatus & KRxInterruptBitMask) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
190 |
// { |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
191 |
// if(trigger & EReceive) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
192 |
// { |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
193 |
// // Interrupt was not spurious |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
194 |
// while(AsspRegister::Read32(a->iChannelBase + KRxFifoLevelOffset)) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
195 |
// { |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
196 |
// if((a->iRxData - a->iRxDataEnd) >= a->iWordSize) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
197 |
// { |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
198 |
// // Space remains in the buffer, so copy the received data to it |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
199 |
// TUint8 nextRxValue = AsspRegister::Read32(a->iChannelBase + KRxFifoOffset); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
200 |
// *a->iRxData = nextRxValue; // For this example, assumes one byte of data is to be transmitted |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
201 |
// // but if operating in 16-bit mode, bytes may need arranging for |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
202 |
// // endianness |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
203 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
204 |
// a->iRxData += a->iWordSize; // Then increment the pointer to the data. In this example, 8-bit mode is assumed |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
205 |
// // (iWordSize=1), but if operating in 16-bit mode iRxData would be incremented |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
206 |
// // by the number of bytes specified in iWordSize |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
207 |
// } |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
208 |
// else |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
209 |
// { |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
210 |
// // The buffer is full but more data has been received - so there is an RxOverrun condition |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
211 |
// // Disable the hardware from receiving any more data and call the PIL function NotifyClient |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
212 |
// // with bitmask (ERxAllBytes | ERxOverrun). |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
213 |
// AsspRegister::Write32(a->iChannelBase + KRxFifoControl, KRxFifoDisableBitMask); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
214 |
// a->NotifyClient(ERxAllBytes | ERxOverrun); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
215 |
// break; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
216 |
// } |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
217 |
// } |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
218 |
// } |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
219 |
// else |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
220 |
// { |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
221 |
// // If the interrupt was spurious, ignore the data, and reset the FIFO |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
222 |
// AsspRegister::Write32(a->iChannelBase + KRxFifoControl, KRxFifoClearBitMask); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
223 |
// } |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
224 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
225 |
// Once the interrupts have been processed, clear the source. If this can be achieve by writing to |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
226 |
// a single register, code similar to the following could be used: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
227 |
// AsspRegister::Write32(a->iChannelBase + KIntStatusOffset, KAIntBitMask); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
228 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
229 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
230 |
|
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 |
// Constructor, first stage |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
233 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
234 |
// The PSL is responsible for setting the channel number - this is passed as the first parameter to |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
235 |
// this overload of the base class constructor |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
236 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
237 |
DSpiSlaveBeagle::DSpiSlaveBeagle(TInt aChannelNumber, TBusType aBusType, TChannelDuplex aChanDuplex) : |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
238 |
DIicBusChannelSlave(aBusType, aChanDuplex, 0), // Base class constructor. Initalise channel ID to zero. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
239 |
iHwGuardTimer(TimeoutCallback, this) // Timer to guard against hardware timeout |
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 |
iChannelNumber = aChannelNumber; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
242 |
__KTRACE_OPT(KIIC, Kern::Printf("DSpiSlaveBeagle::DSpiSlaveBeagle, iChannelNumber = %d\n", iChannelNumber)); |
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 |
|
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 |
// Second stage construction |
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 |
// Allocate and initialise objects required by the PSL channel implementation |
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 |
TInt DSpiSlaveBeagle::DoCreate() |
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 |
__KTRACE_OPT(KIIC, Kern::Printf("\nDSpiSlaveBeagle::DoCreate, ch: %d \n", iChannelNumber)); |
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 |
TInt r = KErrNone; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
255 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
256 |
// PIL Base class initialization. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
257 |
r = Init(); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
258 |
if(r == KErrNone) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
259 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
260 |
// At a minimum, this function must set the channel's unique channel ID. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
261 |
// When the channel is captured, this value will be combined with an instance count |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
262 |
// provided by the PIL to generate a value that will be used by a client as a unique |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
263 |
// identifer in subsequent calls to the Slave API. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
264 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
265 |
// There is no set format for the ID, it just needs to be unique. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
266 |
// Un-comment and complete the following line: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
267 |
// iChannelId = |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
268 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
269 |
// This method may also be concerned with setting the base register address iChannelBase), and allocating |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
270 |
// any objects that will be required to support operaton until the channel is deleted. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
271 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
272 |
// Un-comment and complete the following line: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
273 |
// iChannelBase = |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
274 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
275 |
return r; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
276 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
277 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
278 |
// static method used to construct the DSpiSlaveBeagle object. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
279 |
DSpiSlaveBeagle* DSpiSlaveBeagle::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
|
280 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
281 |
__KTRACE_OPT(KIIC, Kern::Printf("DSpiSlaveBeagle::NewL(): aChannelNumber = %d, BusType =%d", aChannelNumber, aBusType)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
282 |
DSpiSlaveBeagle *pChan = new DSpiSlaveBeagle(aChannelNumber, aBusType, aChanDuplex); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
283 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
284 |
TInt r = KErrNoMemory; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
285 |
if (pChan) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
286 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
287 |
r = pChan->DoCreate(); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
288 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
289 |
if (r != KErrNone) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
290 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
291 |
delete pChan; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
292 |
pChan = NULL; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
293 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
294 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
295 |
return pChan; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
296 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
297 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
298 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
299 |
// Validates the configuration information specified by the client when capturing the channel |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
300 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
301 |
// Called by the PIL as part of the Slave CaptureChannel processing |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
302 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
303 |
// If the pointer to the header is NULL, return KErrArgument. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
304 |
// If the content of the header is not valid for this channel, return KErrNotSupported. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
305 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
306 |
TInt DSpiSlaveBeagle::CheckHdr(TDes8* aHdrBuff) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
307 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
308 |
TInt r = KErrNone; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
309 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
310 |
if(!aHdrBuff) |
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 |
r = KErrArgument; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
313 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
314 |
else |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
315 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
316 |
// Check that the contents of the header are valid |
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 |
// The header will be specific to a particular bus type. Using a fictional |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
319 |
// bus type Abc,code similar to the following could be used to validate each |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
320 |
// member of the header: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
321 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
322 |
// TConfigAbcBufV01* headerBuf = (TConfigAbcBufV01*) aHdrBuff; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
323 |
// TConfigAbcV01 &abcHeader = (*headerBuf)(); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
324 |
// if( (abcHeader.iHeaderMember < ESomeMinValue) || |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
325 |
// (abcHeader.iHeaderMember > ESomeMaxValue)) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
326 |
// { |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
327 |
// __KTRACE_OPT(KIIC, Kern::Printf("iHeaderMember %d not supported",abcHeader.iHeaderMember)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
328 |
// r = KErrNotSupported; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
329 |
// } |
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 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
332 |
__KTRACE_OPT(KIIC, Kern::Printf("DSpiSlaveBeagle::CheckHdr() r %d", r)); |
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 |
return r; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
335 |
} |
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 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
338 |
// Method called in the context of the client thread, as a consequence of the PSL invocation of the |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
339 |
// PIL method NotifyClient when a bus event occurs. |
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 |
// This method updates the bitmask of requested operations (held in member variable iTrigger) and the |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
342 |
// PIL counts of data received and transmitted. If the event was a bus error, the bitmask of requested operations |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
343 |
// is cleared. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
344 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
345 |
void DSpiSlaveBeagle::ProcessData(TInt aTrigger, TIicBusSlaveCallback* aCb) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
346 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
347 |
__KTRACE_OPT(KIIC, Kern::Printf("DSpiSlaveBeagle::ProcessData(), trigger: %x\n", aTrigger)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
348 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
349 |
TInt intState; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
350 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
351 |
// If using the iInProgress member variable to indicate transitions on a chip-select line, and an interrupt |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
352 |
// occurred as a transfer was to end, then must ensure the transmission of data has ceased. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
353 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
354 |
// Must use spin lock to guard access since iInProgress is accessed by the ISR |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
355 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
356 |
TInt inProgress; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
357 |
intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
358 |
inProgress = iInProgress; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
359 |
__SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
360 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
361 |
if(!inProgress && // Transfer has now ended |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
362 |
(aTrigger & (ERxAllBytes | ETxAllBytes))) // Master has not yet finished transferring data |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
363 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
364 |
// Use the guard timer to make sure that transfer ends with an expected time - if this does not cease |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
365 |
// before the timer expires, iTransactionStatus will be set to KErrTimedOut by the callback function TimeoutCallback |
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 |
// Poll the relevant register to check for transfer activity, using code similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
368 |
// TInt8 transferring = AsspRegister::Read32(iChannelBase + KStatusRegisterOffset) & KTransferringBitMask); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
369 |
// For the template port, use a dummy variable instead of the register access (transferring = 1) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
370 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
371 |
TInt8 transferring = 1; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
372 |
iTransactionStatus = KErrNone; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
373 |
iHwGuardTimer.OneShot(NKern::TimerTicks(KTimeoutValue)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
374 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
375 |
while((iTransactionStatus == KErrNone) && |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
376 |
transferring); // Replace transferring with a register read, as described above |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
377 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
378 |
// At this point, either the transfer has ceased, or the timer expired - in either case, may disable the interrupt |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
379 |
// for the transfer now, using code similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
380 |
// AsspRegister::Write32(iChannelBase + KIntEnableRegisterOffset, KIntDisableBitMask); |
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 |
// Check for guard timer expiry |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
383 |
if(iTransactionStatus != KErrNone) |
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 |
__KTRACE_OPT(KIIC, Kern::Printf("DSpiSlaveBeagle::ProcessData - Transaction timed-out")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
386 |
return; |
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 |
else |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
389 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
390 |
iHwGuardTimer.Cancel(); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
391 |
} |
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 |
// If all transfer activity has now ceased, clear iTrigger |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
394 |
// Must use spin lock to guard access since iInProgress is accessed by the ISR |
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 |
intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
397 |
iTrigger = 0; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
398 |
__SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
399 |
} |
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 |
// If the PSL called the PIL function NotifyClient to indicate transfer activity (or error), the reason |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
402 |
// will be specified as a bitmask in aTrigger |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
403 |
// - if a Rx event occurred, the ERxAllBytes flag will be set |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
404 |
// - if a Tx event occurred, the ETxAllBytes flag will be set |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
405 |
// - if a bus error occurred, the EGeneralBusError flag will be set |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
406 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
407 |
if(aTrigger & ERxAllBytes) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
408 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
409 |
__KTRACE_OPT(KIIC, Kern::Printf("ProcessData - Rx Buf: %x\n", iRxData)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
410 |
__KTRACE_OPT(KIIC, Kern::Printf("ProcessData - Rx Bufend: %x\n", iRxDataEnd)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
411 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
412 |
// Clear the internal EReceive flag |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
413 |
// This must be done under guard of a spin lock since iTrigger is accessed by the ISR |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
414 |
intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
415 |
iTrigger &= ~EReceive; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
416 |
__SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
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 |
// Update the PIL count of Rx data (in the Callback object) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
419 |
aCb->SetRxWords(iNumRxWords - ((iRxDataEnd - iRxData) / iWordSize)); |
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 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
422 |
if(aTrigger & ETxAllBytes) |
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 |
__KTRACE_OPT(KIIC, Kern::Printf("ProcessData - Tx Buf: %x\n", iTxData)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
425 |
__KTRACE_OPT(KIIC, Kern::Printf("ProcessData - Tx Bufend: %x\n", iTxDataEnd)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
426 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
427 |
// Clear the internal ETransmit flag.. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
428 |
// This must be done under guard of a spin lock since iTrigger is accessed by the ISR |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
429 |
intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
430 |
iTrigger &= ~ETransmit; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
431 |
__SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
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 |
// Update the PIL count of Tx data (in the Callback object) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
434 |
aCb->SetTxWords(iNumTxWords - ((iTxDataEnd - iTxData) / iWordSize)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
435 |
} |
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 |
if(aTrigger & EGeneralBusError) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
438 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
439 |
__KTRACE_OPT(KIIC, Kern::Printf("BusError..")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
440 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
441 |
// Clear and disable relevant interrupts, possibly using code similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
442 |
// AsspRegister::Write32(iChannelBase + KIntEnableRegisterOffset, KIntDisableBitMask); |
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 |
// Clear internal flags |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
445 |
// This must be done under guard of a spin lock since iTrigger is accessed by the ISR |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
446 |
intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
447 |
iTrigger = 0; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
448 |
__SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
449 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
450 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
451 |
// Set the callback's trigger, for use by the PIL |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
452 |
aCb->SetTrigger(aTrigger | aCb->GetTrigger()); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
453 |
} |
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 |
|
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 |
// Method to initialise the hardware in accordance with the data provided by the Client |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
458 |
// in the configuration header when capturing the channel |
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 |
// This method is called from DoRequest and is expected to return a value to indicate success |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
461 |
// or a system wide error code to inform of the failure |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
462 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
463 |
TInt DSpiSlaveBeagle::ConfigureInterface() |
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 |
__KTRACE_OPT(KIIC, Kern::Printf("ConfigureInterface()")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
466 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
467 |
TInt r = KErrNone; |
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 |
// The header is stored in member variable iConfigHeader, and will be specific to a particular bus type. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
470 |
// Using a fictional bus type Abc, code similar to the following could be used to access each |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
471 |
// member of the header: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
472 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
473 |
// TConfigAbcBufV01* headerBuf = (TConfigAbcBufV01*) iConfigHeader; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
474 |
// TConfigAbcV01 &abcHeader = (*headerBuf)(); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
475 |
// TInt value = abcHeader.iTintMember; |
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 |
// Initialising the hardware may be achieved with calls similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
478 |
// AsspRegister::Write32(a->iChannelBase + KBusModeControlOffset, KIicPslModeControlBitMask); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
479 |
// GPIO::SetPinMode(aPinId, GPIO::EEnabled); |
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 |
// Binding an ISR may be achieved with calls similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
482 |
// r = Interrupt::Bind(iRxInterruptId, DSpiSlaveBeagle::IicPslIsr, this); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
483 |
// r = Interrupt::Bind(iTxInterruptId, DSpiSlaveBeagle::IicPslIsr, this); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
484 |
// Enabling interrupts may be achieved with calls similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
485 |
// r = Interrupt::Enable(iRxInterruptId); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
486 |
// r = Interrupt::Enable(iTxInterruptId); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
487 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
488 |
// Modifying a hardware register may not be a zero-delay operation. The member variable iHwGuardTimer could be used to guard a |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
489 |
// continuous poll of the hardware register that checks for the required change in the setting; TimeoutCallback is already |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
490 |
// assigned as the callback function for iHwGaurdTimer, and it modifies member variable iTransactionStatus to indicate a timeout |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
491 |
// - so the two could be used together as follows: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
492 |
// iTransactionStatus = KErrNone; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
493 |
// iHwGuardTimer.OneShot(NKern::TimerTicks(KTimeoutValue)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
494 |
// while((iTransactionStatus == KErrNone) && |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
495 |
// AsspRegister::Read32(iChannelBase + KRegisterOffset) & KRegisterFlagBitMask); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
496 |
// if(iTransactionStatus != KErrNone) |
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 |
// r = KErrGeneral; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
499 |
// } |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
500 |
// else |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
501 |
// { |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
502 |
// iHwGuardTimer.Cancel(); |
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 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
505 |
// DoRequest checks the return value so the variable r should be modified in the event of failure with a system-wide error code |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
506 |
// for example, if a register could not be modified, |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
507 |
// r = KErrGeneral; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
508 |
// __KTRACE_OPT(KIIC, Kern::Printf("ConfigureInterface failed with error %d\n",r)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
509 |
return r; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
510 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
511 |
|
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 |
// Method to start asynchronous initialisation of the hardware, in accordance with the data provided by the Client |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
514 |
// in the configuration header when capturing the channel. This differs from ConfigureInterface in that it |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
515 |
// merely starts the initialisation, then returns immediately; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
516 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
517 |
// The PSL is expected to be implemented as an asynchronous state machine, where events (for example hardware |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
518 |
// interrupts, or timer expiry) invoke callback functions that advance the state machine to the next state. Once |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
519 |
// all the required states have been transitioned, so that the PSL part of the CaptureChannel processing is |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
520 |
// complete, the ISR should be invoked, which will then call PIL method ChanCaptureCallback |
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 |
// This method is called from DoRequest and is expected to return a value to indicate success |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
523 |
// or a system wide error code to inform of the failure |
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 |
TInt DSpiSlaveBeagle::AsynchConfigureInterface() |
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 |
__KTRACE_OPT(KIIC, Kern::Printf("ConfigureInterface()")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
528 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
529 |
// TInt r = KErrNone; // A real implementation would use this as the return value to indicate success / failure |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
530 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
531 |
// Precisely what processing is done to 'start' the asynchronous processing is entirely platform-specific; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
532 |
// it may be the set-up and activation of a long-running operation that completes asynchronously. Regardless of what |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
533 |
// is done, its completion is expected to result in the ISR being run. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
534 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
535 |
// Whatever the operation, there must be some means of the ISR recognising that an asynchronous initialisation has |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
536 |
// been performed |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
537 |
// In a real PSL, this may be be checking a bitmask in a status register. For the template PSL, however, |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
538 |
// a dummy class member will be used (iAsyncConfig) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
539 |
// Since this member will be accessed by the ISR, it should, strictly speaking, be accessed under the guard of a spin lock |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
540 |
TInt intState; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
541 |
intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
542 |
iAsyncConfig = 1; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
543 |
__SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
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 |
return KErrNone; // A real implementation would return an indication of success / failure |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
546 |
} |
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 |
// Method called from DoRequest to start Tx and-or Rx transfer. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
549 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
550 |
// The method will initialise the hardware and pointers used to manage transfers, before returning a value to report success |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
551 |
// (KErrNone) or a system-wide error code that indicates the cause of failure. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
552 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
553 |
TInt DSpiSlaveBeagle::InitTransfer() |
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 |
__KTRACE_OPT(KIIC, Kern::Printf("DSpiSlaveBeagle::InitTransfer()")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
556 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
557 |
TInt r = KErrNone; |
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 |
// Local copies of member variables that must be accessed in a synchronised manner |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
560 |
TInt inProgress; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
561 |
TInt trigger; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
562 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
563 |
TInt intState; |
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 |
// Check if a transfer is already in progress. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
566 |
// If variable iInProgress is being used, this must be determined in a synchronised manner because the ISR modifies it. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
567 |
// Bus types that do not rely on chip-select transitions may use an alternative method to indicate if a transfer is in |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
568 |
// progress |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
569 |
intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
570 |
inProgress = iInProgress; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
571 |
__SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
572 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
573 |
if(!inProgress) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
574 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
575 |
// If no transfers are in progress, it may be necessary to initialise the hardware to support those that |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
576 |
// are being requested. This may include FIFO and interrupt initialisation, |
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 |
// Initialising the hardware may be achieved with calls similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
579 |
// AsspRegister::Write32(iChannelBase + KBusModeControlOffset, KIicPslModeControlBitMask); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
580 |
// GPIO::SetPinMode(aPinId, GPIO::EEnabled); |
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 |
// Check the current operations. This must be determined in a synchronised manner because ProcessData |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
584 |
// runs in the context of the Client thread and it modifies the value of iTrigger |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
585 |
intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
586 |
trigger = iTrigger; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
587 |
__SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
588 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
589 |
if(trigger & ETransmit) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
590 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
591 |
// If Tx transfers were not previously active, it may be necessary to initialise the Tx hardware here, e.g. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
592 |
// AsspRegister::Write32(iChannelBase + KBusModeControlOffset, KIicPslTxModeBitMask); |
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 |
// Initialise the Tx pointers |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
595 |
iTxData = iTxBuf + (iWordSize * iTxOffset); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
596 |
iTxDataEnd = iTxData + (iWordSize * iNumTxWords); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
597 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
598 |
__KTRACE_OPT(KIIC, Kern::Printf("Tx Buf: %x", iTxData)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
599 |
__KTRACE_OPT(KIIC, Kern::Printf("Tx Bufend: %x", iTxDataEnd)); |
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 |
// If using a FIFO, copy the data to it until either the FIFO is full or all the data has been copied |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
602 |
// This could be achieved with something similar to the following lines: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
603 |
// while(AsspRegister::Read32(iChannelBase + KFifoLevelOffset) <= (KFifoMaxLevel - iWordSize) && |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
604 |
// iTxData != iTxDataEnd) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
605 |
// For the template port, will just use a dummy variable (dummyFifoLvlChk )in place of the register read |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
606 |
TInt dummyFifoLvlChk = 0; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
607 |
while((dummyFifoLvlChk) && // Replace this dummy variable with a read of the hardware |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
608 |
(iTxData != iTxDataEnd)) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
609 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
610 |
// TUint8 nextTxValue = *iTxData; // For this example, assumes one byte of data is to be transmitted |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
611 |
// but if operating in 16-bit mode, bytes may need arranging for |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
612 |
// endianness |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
613 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
614 |
// Write to the Tx register with something similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
615 |
// AsspRegister::Write32(iChannelBase + KTxFifoOffset, nextTxValue); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
616 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
617 |
iTxData += iWordSize; // Then increment the pointer to the data. In this example, 8-bit mode is assumed |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
618 |
// (iWordSize=1), but if operating in 16-bit mode iTxData would be incremented |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
619 |
// by the number of bytes specified in iWordSize |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
620 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
621 |
// If a Tx FIFO is not being used, a single Tx value would be written - in which case the above loop would be replaced |
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 |
__KTRACE_OPT(KIIC, Kern::Printf("After adding:\n\rTx Buf: %x", iTxData)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
624 |
__KTRACE_OPT(KIIC, Kern::Printf("Tx Bufend: %x", iTxDataEnd)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
625 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
626 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
627 |
if(trigger & EReceive) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
628 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
629 |
// Initialise the Rx pointers |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
630 |
iRxData = iRxBuf + (iWordSize * iRxOffset); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
631 |
iRxDataEnd = iRxData + (iWordSize * iNumRxWords); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
632 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
633 |
__KTRACE_OPT(KIIC, Kern::Printf("Rx Buffer: %x", iRxData)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
634 |
__KTRACE_OPT(KIIC, Kern::Printf("Rx Bufend: %x", iRxDataEnd)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
635 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
636 |
// If Rx transfers were not previously active, it may be necessary to initialise the Rx hardware here, e.g. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
637 |
// AsspRegister::Write32(iChannelBase + KBusModeControlOffset, KIicPslRxModeBitMask); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
638 |
} |
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 |
// If there is some common configuration required to support Rx, Tx transfers, may do it here |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
641 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
642 |
return r; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
643 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
644 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
645 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
646 |
// The gateway function for PSL implementation |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
647 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
648 |
// This method is called by the PIL to perform one or more operations indicated in the bitmask aOperation, |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
649 |
// which corresponds to members of the TPslOperation enumeration. |
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 |
TInt DSpiSlaveBeagle::DoRequest(TInt aOperation) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
652 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
653 |
__KTRACE_OPT(KIIC, Kern::Printf("\nDSpiSlaveBeagle::DoRequest, Operation 0x%x\n", aOperation)); |
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 |
TInt r = KErrNone; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
656 |
TInt intState; |
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 |
if (aOperation & EAsyncConfigPwrUp) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
659 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
660 |
// The PIL has requested asynchronous operation of CaptureChannel. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
661 |
// The PSL should start the processing required for a channel to be captured, and then return immediately with |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
662 |
// error code KErrNone (if the processing was started without error), so that the client thread will be unblocked. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
663 |
// The PSL is expected to be implemented as an asynchronous state machine, where events (for example hardware |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
664 |
// interrupts, or timer expiry) invoke callback functions that advance the state machine to the next state. Once |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
665 |
// all the required states have been transitioned, so that the PSL part of the CaptureChannel processing is |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
666 |
// complete, the PSL should call the PIL function ChanCaptureCallback - this will lead to the Client-provided |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
667 |
// callback being executed in the context of the client thread |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
668 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
669 |
__KTRACE_OPT(KIIC, Kern::Printf("EAsyncConfigPwrUp")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
670 |
r = AsynchConfigureInterface(); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
671 |
if (r != KErrNone) |
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 |
__KTRACE_OPT(KIIC, Kern::Printf("AsynchConfigureInterface returned %d\n", r)); |
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 |
return r; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
676 |
} |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
677 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
678 |
if (aOperation & ESyncConfigPwrUp) |
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 |
// The PIL has requested synchronous operation of CaptureChannel. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
681 |
// The PSL should perform the processing required for a channel to be captured, and return a system-wide error |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
682 |
// code when this is complete to indicate the status of the capture. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
683 |
// Capturing a channel is expected to include initialisation of the hardware to enable operation in accordance |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
684 |
// with the configuration specified in the PIL member variable iConfigHeader, which holds the configuration |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
685 |
// specified by the Client. |
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 |
__KTRACE_OPT(KIIC, Kern::Printf("ESyncConfigPwrUp")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
688 |
r = ConfigureInterface(); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
689 |
if (r != KErrNone) |
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 |
__KTRACE_OPT(KIIC, Kern::Printf("ConfigureInterface returned %d\n", r)); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
692 |
return r; |
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 |
} |
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 |
if (aOperation & ETransmit) |
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 |
// The PIL has requested that a Tx operation be started. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
699 |
// Since the SPL may support simultaneous Rx and Tx operations, just set the flag in the iTrigger bitmask to |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
700 |
// indicate what has been requested. If both Rx and Tx operations are requested, and one completes ahead of the other, |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
701 |
// requiring the Client to provide a new buffer and associated call to DoRequest (as is the case if the Master wishes |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
702 |
// to transfer more data than the Slave buffer supported), it is possible that the other transfer could complete while |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
703 |
// this function is running; consequently, it may attempt to access iTrigger, and so cause data corruption. To cater for |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
704 |
// such situations, use a spin lock to guard access to iTrigger. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
705 |
// When the same check has been performed for Rx, call the InitTransfer function to start the required transfers. |
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 |
__KTRACE_OPT(KIIC, Kern::Printf("ETransmit")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
708 |
intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
709 |
iTrigger |= ETransmit; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
710 |
__SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
711 |
} |
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 |
if (aOperation & EReceive) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
714 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
715 |
// The PIL has requested that a Rx operation be started. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
716 |
// Since the SPL may support simultaneous Rx and Tx operations, just set the flag in the iTrigger bitmask to |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
717 |
// indicate what has been requested. If both Rx and Tx operations are requested, and one completes ahead of the other, |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
718 |
// requiring the Client to provide a new buffer and associated call to DoRequest (as is the case if the Master wishes |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
719 |
// to transfer more data than the Slave buffer supported), it is possible that the other transfer could complete while |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
720 |
// this function is running; consequently, it may attempt to access iTrigger, and so cause data corruption. To cater for |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
721 |
// such situations, use a spin lock to guard access to iTrigger. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
722 |
// When the same check has been performed for Tx, call the InitTransfer function to start the required transfers. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
723 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
724 |
__KTRACE_OPT(KIIC, Kern::Printf("EReceive")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
725 |
intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
726 |
iTrigger |= EReceive; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
727 |
__SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
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 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
730 |
if (aOperation & (EReceive | ETransmit)) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
731 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
732 |
// This code should only be executed once it has been checked whether Rx and Tx operations are required. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
733 |
r = InitTransfer(); |
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 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
736 |
if (aOperation & EAbort) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
737 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
738 |
// The PIL has requested that the current transaction be aborted. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
739 |
// This is the case if the Client has not responded within an expected time to specify the next steps in |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
740 |
// the transaction processing. The time allowed is specified by calling PIL function SetClientWaitTime, otherwise |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
741 |
// the time defaults to KSlaveDefCWaitTime. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
742 |
// If the PSL is able to satisfy this request it should, at a minimum, disable interrupts and update the member |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
743 |
// variables that indicate a transaction is in progress. If the PSL is unable to satisfy the request then the same |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
744 |
// behaviour will follow as if this request had not been made, so there is no point in modifying the state variables. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
745 |
// If both Rx and Tx operations had been requested, and one completes ahead of the other, it is possible that the other |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
746 |
// transfer could complete while this function is running; consequently, it may attempt to access iTrigger and iInProgress, |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
747 |
// and so cause data corruption. To cater for such situations, use a spin lock to guard access to iTrigger. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
748 |
// The PIL makes no assumptions of whether the PSL can support this request or not, and does not check the return |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
749 |
// value - so there is no need to set one. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
750 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
751 |
TUint8 dummyCanAbort = 1; // Dummy variable to represent a check of if it is possible to abort the current transaction |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
752 |
__KTRACE_OPT(KIIC, Kern::Printf("EAbort")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
753 |
intState = __SPIN_LOCK_IRQSAVE(IicPslSpinLock); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
754 |
if(dummyCanAbort) |
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 |
// The spin lock has been acquired, so it is safe to modify data and hardware registers that may be accessed as part of |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
757 |
// interrupt processing performed by an ISR - this is assuming that the ISR has been written to acquire the same spin lock. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
758 |
// Limit the processing to only that which is necessary to be processed under spin lock control, so as to not delay other |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
759 |
// threads of execution that are waiting for the spin lock to be freed. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
760 |
// Hardware may be configured using code similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
761 |
// AsspRegister::Write32(iChannelBase + KBusInterruptEnableOffset, KIicPslBusDisableBitMask); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
762 |
iInProgress = EFalse; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
763 |
iTrigger = 0; |
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 |
__SPIN_UNLOCK_IRQRESTORE(IicPslSpinLock, intState); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
766 |
// Having released the spin lock, now perform any actions that are not affected by pre-emption by an ISR, this may include code |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
767 |
// such as the following |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
768 |
// Interrupt::Disable(iRxInterruptId); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
769 |
// Interrupt::Disable(iTxInterruptId); |
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 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
772 |
if (aOperation & EPowerDown) |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
773 |
{ |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
774 |
// The PIL has requested that the channel be released. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
775 |
// If this channel is not part of a MasterSlave channel, the next Client will operate in Slave mode. In this case, it may only |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
776 |
// be necessary to disable interrupts, and reset the channel hardware. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
777 |
// If this channel represents the Slave of a MasterSlave channel, it is possible that some of the hardware is shared between the |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
778 |
// Master and Slave sub-channels. Since it may not be known whether the next Client of the parent channel will require operation |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
779 |
// in either Master or Slave mode, some additional processing may be required to allow for subsequent Master operation (for example. |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
780 |
// unbinding an interrupt). |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
781 |
// |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
782 |
__KTRACE_OPT(KIIC, Kern::Printf("EPowerDown")); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
783 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
784 |
// Resetting the hardware may be achieved with calls similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
785 |
// AsspRegister::Write32(iChannelBase + KBusInterruptEnableOffset, KIicPslBusDisableBitMask); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
786 |
// GPIO::SetPinMode(aPinId, GPIO::EDisabled); |
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 interrupts may be achieved with calls similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
789 |
// Interrupt::Disable(iRxInterruptId); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
790 |
// Interrupt::Disable(iTxInterruptId); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
791 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
792 |
// Unbinding an ISR may be achieved with calls similar to the following: |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
793 |
// Interrupt::Unbind(iRxInterruptId); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
794 |
// Interrupt::Unbind(iTxInterruptId); |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
795 |
|
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
796 |
// The PIL checks the return value so the variable r should be modified in the event of failure with a system-wide error code |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
797 |
// for example, if a register could not be modified, |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
798 |
// r = KErrGeneral; |
e5fd00cbb70a
Added IIC SPI implementation / tests (Master channel only)
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
diff
changeset
|
799 |
// __KTRACE_OPT(KIIC, Kern::Printf("EPowerDown failed with error %d\n",r)); |
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 |
return r; |
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 |