Instances of this class handle access to a "generic" implementation of the I2C interface for the MityDSP. More...
#include <core/DspI2c.h>
Public Types | |
typedef void(* | tfIsrCallback )(tcDspI2c *) |
prototype for the ISR callbacks. | |
typedef void(* | tfIsrCallbackWithArg )(tcDspI2c *, void *) |
Public Member Functions | |
tcDspI2c (void *apAddress, int anLevel=gnAutoLevel) | |
This constructor is used to open an istance of the DspI2c interface. | |
~tcDspI2c () | |
This destructor is used to close up and free the resources tied to the associated I2C interface. | |
bool | IsDone (void) |
Routine returns true if the previous operation is complete. | |
bool | IsTxEmpty (void) |
Checks the transmit FIFO to see if it's empty. | |
bool | IsRxEmpty (void) |
Checks the receive FIFO to see if it's empty. | |
unsigned int | GetFIFODepth (void) |
Returns the depth of the transmit and receive FIFO. | |
void | FlushRxFIFO (void) |
This routine will flush the I2C read FIFO. | |
int | ReadFIFO (unsigned char *apData, int anMaxWords) |
Reads 8-bit words from the receive FIFO until either the FIFO is empty or the maximum specified words have been read. | |
int | ReadFIFO (unsigned short *apData, int anMaxWords) |
Reads 16-bit words from the receive FIFO until either the FIFO is empty or the maximum specified words have been read. | |
void | FlushTxFIFO (void) |
This routine will flush the I2C transmit FIFO. | |
int | WriteFIFO (unsigned char *apData, int anNumWords) |
Writes the specified number of 8-bit words to the transmit FIFO. | |
int | WriteFIFO (unsigned short *apData, int anNumWords) |
Writes the specified number of 16-bit words to the transmit FIFO. | |
bool | IssueReadRequest (unsigned char anSlaveAddr, unsigned char anWordAddr, int anNumWords, unsigned int anTimeout=0) |
Posts a read request on the I2C bus. | |
bool | IssueWriteRequest (unsigned char anSlaveAddr, unsigned char anWordAddr, int anNumWords, unsigned int anTimeout=0) |
Posts a write request on the I2C bus. | |
void | EnableInterrupt (bool abEnable) |
Sets or clears the I2C interrupt enable. | |
void | RegisterIsrCallback (tfIsrCallback afCallback) |
Registers the specified ISR callback for the "done" interrupt. | |
void | RegisterIsrCallback (tfIsrCallbackWithArg afCallback, void *apUserArg=NULL) |
Registers the specified ISR callback for the "done" interrupt. | |
Static Public Member Functions | |
static int | interrupt_dispatch (Arg arMyObject) |
Static interrupt dispatch routine. | |
Public Attributes | |
unsigned int | mnInterruptCount |
ISR counter (debug). | |
Protected Member Functions | |
void | i2cInterrupt (void) |
Interrupt service routine for the I2C class. | |
Protected Attributes | |
SEM_Handle | mhMyMutex |
To serialize access. | |
SEM_Handle | mhDone |
Used to indicate command done. | |
unsigned int | mnFifoDepth |
depth of firmware FIFO | |
bool | mbIntState |
state of interrupt enable | |
tfIsrCallback | mfIsrCallback |
Callback without argument. | |
tfIsrCallbackWithArg | mfIsrCallbackWithArg |
Callback with argument. | |
void * | mpUserArg |
User supplied ISR arg. | |
volatile unsigned int * | mpBaseAddr |
firmware base address | |
unsigned short | mnMyIntMask |
core interrupt mask | |
int | mnMyIntLevel |
core interrupt level | |
int | mnMyIntVector |
core interrupt vector | |
Static Protected Attributes | |
static unsigned int | mnTicksPerSec = (1000 * CLK_countspms()) / CLK_getprd() |
Conversion from low resolution. |
Instances of this class handle access to a "generic" implementation of the I2C interface for the MityDSP.
typedef void(* MityDSP::tcDspI2c::tfIsrCallback)(tcDspI2c *) |
prototype for the ISR callbacks.
typedef void(* MityDSP::tcDspI2c::tfIsrCallbackWithArg)(tcDspI2c *, void *) |
tcDspI2c::tcDspI2c | ( | void * | apAddress, | |
int | anLevel = gnAutoLevel | |||
) |
This constructor is used to open an istance of the DspI2c interface.
[in] | apAddress | Base Address of I2C core |
[in] | anLevel | Optional parameter to force a chained interrupt at the specified level. |
tcDspI2c::~tcDspI2c | ( | ) |
This destructor is used to close up and free the resources tied to the associated I2C interface.
int tcDspI2c::interrupt_dispatch | ( | Arg | ahMyObject | ) | [static] |
Static interrupt dispatch routine.
Required because of the hidden this pointer associated with a member function, which cannot be passed directly to the interrupt dispatcher.
[in] | ahMyObject | The "this->" pointer for the instance of tcDspI2c associated with this ISR. |
bool tcDspI2c::IsDone | ( | void | ) |
Routine returns true if the previous operation is complete.
bool tcDspI2c::IsTxEmpty | ( | void | ) |
Checks the transmit FIFO to see if it's empty.
bool tcDspI2c::IsRxEmpty | ( | void | ) |
Checks the receive FIFO to see if it's empty.
unsigned int tcDspI2c::GetFIFODepth | ( | void | ) |
Returns the depth of the transmit and receive FIFO.
Both FIFOs have the same depth.
void tcDspI2c::FlushRxFIFO | ( | void | ) |
This routine will flush the I2C read FIFO.
It is useful when a clearing operation is require or after initialization.
int tcDspI2c::ReadFIFO | ( | unsigned char * | apData, | |
int | anMaxWords | |||
) |
Reads 8-bit words from the receive FIFO until either the FIFO is empty or the maximum specified words have been read.
[out] | apData | Pointer to storage for the received data. |
[in] | anMaxWords | Maximum words to store in apData. |
int tcDspI2c::ReadFIFO | ( | unsigned short * | apData, | |
int | anMaxWords | |||
) |
Reads 16-bit words from the receive FIFO until either the FIFO is empty or the maximum specified words have been read.
[out] | apData | Pointer to storage for the received data. |
[in] | anMaxWords | Maximum words to store in apData. |
void tcDspI2c::FlushTxFIFO | ( | void | ) |
This routine will flush the I2C transmit FIFO.
It is useful when a clearing operation is require or after initialization.
int tcDspI2c::WriteFIFO | ( | unsigned char * | apData, | |
int | anNumWords | |||
) |
Writes the specified number of 8-bit words to the transmit FIFO.
[in] | apData | Pointer to the data to transmit. |
[in] | anNumWords | Number of words in apData. |
int tcDspI2c::WriteFIFO | ( | unsigned short * | apData, | |
int | anNumWords | |||
) |
Writes the specified number of 16-bit words to the transmit FIFO.
[in] | apData | Pointer to the data to transmit. |
[in] | anNumWords | Number of words in apData. |
bool tcDspI2c::IssueReadRequest | ( | unsigned char | anSlaveAddr, | |
unsigned char | anWordAddr, | |||
int | anNumWords, | |||
unsigned int | anTimeout = 0 | |||
) |
Posts a read request on the I2C bus.
The address of the slave device, the word address within the device, and the number of sequential words to read are provided.
If a non-zero timeout is provided, the routine waits for the specified number of milliseconds for the request to complete.
[in] | anSlaveAddr | Address of device on I2C bus |
[in] | anWordAddr | Address of word to read within selected device |
[in] | anNumWords | Number of words to read sequentially from device |
[in] | anTimeout | Time (in millisecs) to wait for completion |
bool tcDspI2c::IssueWriteRequest | ( | unsigned char | anSlaveAddr, | |
unsigned char | anWordAddr, | |||
int | anNumWords, | |||
unsigned int | anTimeout = 0 | |||
) |
Posts a write request on the I2C bus.
The address of the slave device, the word address within the device, and the number of sequential words to write are provided.
If a non-zero timeout is provided, the routine waits for the specified number of milliseconds for the request to complete.
[in] | anSlaveAddr | Address of device on I2C bus |
[in] | anWordAddr | Address of word to write within selected device |
[in] | anNumWords | Number of words to write sequentially to device |
[in] | anTimeout | Time (in millisecs) to wait for completion |
void tcDspI2c::EnableInterrupt | ( | bool | abEnable | ) |
void tcDspI2c::RegisterIsrCallback | ( | tfIsrCallback | afCallback | ) |
Registers the specified ISR callback for the "done" interrupt.
[in] | afCallback | The callback to associate with the interrupt (or NULL for none). |
void tcDspI2c::RegisterIsrCallback | ( | tfIsrCallbackWithArg | afCallback, | |
void * | apUserArg = NULL | |||
) |
Registers the specified ISR callback for the "done" interrupt.
[in] | afCallback | The callback to associate with the interrupt (or NULL for none). |
[in] | apUserArg | An argument to be supplied with the callback. |
void tcDspI2c::i2cInterrupt | ( | void | ) | [protected] |
Interrupt service routine for the I2C class.
The ISR reads and clears any pending done interrupt and sets the internal semaphore. If an interrupts callback is registered, the routine is called.
"Interrupt-ness" is taken care of by the 'dispatcher' in DSP/BIOS. Installed by the constructor.
unsigned int MityDSP::tcDspI2c::mnInterruptCount |
ISR counter (debug).
unsigned int tcDspI2c::mnTicksPerSec = (1000 * CLK_countspms()) / CLK_getprd() [static, protected] |
Conversion from low resolution.
SEM_Handle MityDSP::tcDspI2c::mhMyMutex [protected] |
To serialize access.
SEM_Handle MityDSP::tcDspI2c::mhDone [protected] |
Used to indicate command done.
unsigned int MityDSP::tcDspI2c::mnFifoDepth [protected] |
depth of firmware FIFO
bool MityDSP::tcDspI2c::mbIntState [protected] |
state of interrupt enable
tfIsrCallback MityDSP::tcDspI2c::mfIsrCallback [protected] |
Callback without argument.
Callback with argument.
void* MityDSP::tcDspI2c::mpUserArg [protected] |
User supplied ISR arg.
volatile unsigned int* MityDSP::tcDspI2c::mpBaseAddr [protected] |
firmware base address
unsigned short MityDSP::tcDspI2c::mnMyIntMask [protected] |
core interrupt mask
int MityDSP::tcDspI2c::mnMyIntLevel [protected] |
core interrupt level
int MityDSP::tcDspI2c::mnMyIntVector [protected] |
core interrupt vector