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.
This is a simple example of tcDspI2c creation and usage: