Introduction
The tcDspSpi class is used to provide a consistent method to access devices via an instance of the MityDSP SPI. Although tcDspSpi may be used directly by applications, it is usually used by higher-level classes to provide access to a specific device.
The tcDspSpi class provides a FIFO which can be used to read and/or write to the SPI. Serialization of access to multiple devices or to the same device across multiple threads must be provided by the application. The class provides interrupts when various transmit FIFO levels are reached (Empty, 1/4, 1/2, and 3/4 full).
The application may register a routine to be run in ISR context to provide specific functionality for each FIFO interrupt.
An instance of the tcDspSpi class is created by specifying the firmware base address of the core and the interrupt level used. This core supports specifying a level of gnAutoLevel, which automatically installs a vectored interrupt.
- See also:
- MityDSP::tcDspInterruptDispatch Class Reference
-
MityDSP::tcDspSpi Class Reference
Example
This is a simple example of tcDspSpi creation and usage:
{
SEM_handle MyClass::myFifoAlmostEmpty;
tcDspSpi *MyClass::mySpi;
static void MyClass::myIsrCallback(tcDspSpi *apSpi)
{
return;
}
void MyClass::doSomething(void)
{
int i;
unsigned int my_base_addr = 0xB0000200;
tcDspSpi::tuFifoData FifoData;
tcDspSpi::tuFifoData IncomingData[64];
LCK_Handle myLock = LCK_create(NULL);
mySpi =
new tcDspSpi((
void *)my_base_addr,
gnAutoLevel, myLock);
mySpi->SetFifoWidth(tcDspSpi::ee32Bit);
mySpi->SetTxClockEdge(tcDspSpi::eeFalling);
mySpi->SetRxClockEdge(tcDspSpi::eeFalling);
mySpi->SetClockGateWithSync(true);
mySpi->RegisterTxFIFOHandler(
eeOneQ, myIsrCallback);
mySpi->SetTxFIFOInterruptLevel(
eeOneQ,
true);
for (i=0; i<mySpi->GetTxFIFODepth(); i++)
{
FifoData.mnLword = i;
if (mySpi->WriteData(&FifoData, 1) != 1) break;
}
while (true)
{
:
:
SEM_pend(myFifoAlmostEmpty, SYS_FOREVER);
for (i=0; i<mySpi->GetTxFIFODepth(); i++)
{
FifoData.ms32Bit.mnFifoData = i;
if (mySpi->WriteData(&FifoData, 1) != 1) break;
}
:
:
mySpi->SetFifoWidth(tcDspSpi::ee32Bit);
for (i=0; i<64; i++) IncomingData[i].ms8Bit.mnFifoData = 0xFF;
bytes = mySpi->ReadData(IncomingData, 64);
:
:
}
}
}