MityDSP Documentation Index
tcDspI2c

Introduction

The tcDspI2c class is used to provide a consistent method to access devices via an instance of the MityDSP I2C bus. Although tcDspI2c may be used directly by applications, it is usually used by higher-level classes to provide access to a specific device.

To write data, the transmit FIFO is preloaded with the data using the WriteFifo method). Then a write request is made indicating the slave device address, its internal word address, and the number of sequential words to write (from the transmit FIFO). The IsDone method can be used to poll for completion.

Similarly, to read data a read request is made indicating the slave device address, its internal word address, and the number of sequential words to read (into the receive FIFO). The IsDone method can be used to poll for completion. Once done, the ReadFifo method can be used to read the results from the receive FIFO.

Besides polling the IsDone method, two other potentially more efficient ways to determine completion are provided. First, an optional non-zero timeout may be provided to IssueReadRequest and IssueWriteRequest methods. In this case, the routines pend for up to the provided period on an internal semaphore which is set when the done interrupt occurs.

Or, the application may register a routine to be run in ISR context to provide specific functionality for each "done" interrupt.

An instance of the tcDspI2c 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::tcDspI2c Class Reference

Example

This is a simple example of tcDspI2c creation and usage:

{
SEM_handle MyClass::myDoneFlag;
tcDspI2c *MyClass::myI2c;
static void MyClass::myIsrCallback(tcDspI2c *apI2c)
{
SEM_post(myDoneFlag);
return;
}
void MyClass::doSomething(void)
{
int i;
unsigned char data[4] = { 0xDE, 0xAD, 0xBE, 0xEF };
unsigned int my_base_addr = 0xB0000200;
unsigned char mySlave = 1;
unsigned char slaveWord = 3;
bool success;
// create access to the I2C
myI2c = new tcDspI2c((void *)my_base_addr);
// write data, waiting up to 2.5s for completion
myI2c->WriteFifo(data, 4);
success = myI2c->IssueWriteRequest(mySlave, slaveWord, 4, 2500);
// read data, polling for completion
myI2c->IssueReadRequest(mySlave, slaveWord, 4);
while (myI2c->IsDone() == false);
myI2c->ReadFifo(data, 4);
// initialize semaphore
myDoneFlag = SEM_create(0, NULL);
// register callback
myI2c->RegisterIsrCallback(myIsrCallback);
// enable interrupt
myI2c->EnableInterrupt(true);
// read data, using myIsrCallback to tell when it's done
myI2c->IssueReadRequest(mySlave, slaveWord, 4);
SEM_pend(myDoneFlag, SYS_FOREVER);
myI2c->ReadFifo(data, 4);
:
:
}
}

  
Generated on Mon Apr 22 2013 11:33:02 for MityDSP Core by  Doxygen Version 1.8.1.1
Copyright © 2009, Critical Link LLC, All rights reserved.