MityDSP::tcDspGpio Class Reference
Instances of this class handle sending, receiving, and configuring a register containing 32 general purpose I/O pins.
More...
#include <core/DspGpio.h>
List of all members.
Public Types |
typedef void(* | tfIsrCallback )(tcDspGpio *, unsigned int, void *) |
| prototype for the ISR callback
|
Public Member Functions |
| tcDspGpio (void *apAddress, int anLevel=gnAutoLevel) |
| This constructor is used to open a GPIO core instance.
|
| ~tcDspGpio () |
| Default destructor.
|
bool | configurePins (unsigned int anMask, teGpioDirection aeDir, bool abIntRising=false, bool abIntFalling=false, SEM_Handle apSem=NULL) |
| This routine is used to configure a set of GPIO pins.
|
void | registerGlobalInputSemaphore (SEM_Handle ahGlobalSem) |
| This routine is used to register the global input semaphore.
|
void | registerIsrCallback (tfIsrCallback afCallback, void *apUserArg=NULL) |
| This method is used to register a callback that is activated whenever a configured input changes state.
|
unsigned int | readPins (unsigned int anMask) |
| This routine is used to read current GPIO pin values.
|
void | writePins (unsigned int anMask, unsigned int anValues) |
| This routine is used to write updated GPIO pin values.
|
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 | Lock (unsigned int &arCsr) |
void | Unlock (unsigned int anCsr) |
void | gpioInterrupt (void) |
| Interrupt service routine for the GPIO core.
|
Protected Attributes |
unsigned int | mnLastDir |
| Last known contents of DIR.
|
unsigned int | mnLastIorRead |
| Last read contents of IOR.
|
unsigned int | mnLastIorWrite |
| Last written contents of IOR.
|
unsigned int | mnLastIer |
| Last known contents of IER.
|
unsigned int | mnLastIef |
| Last known contents of IEF.
|
unsigned int | mnLastIpend |
| Last known contents of IPEND.
|
SEM_Handle * | mhMySemaphores |
| Pointer to registered semaphores.
|
LCK_Handle | mhMyMutex |
| Semaphore to use as a mutex lock.
|
SEM_Handle | mhGlobalInputSem |
| Posted whenever any other input sem is posted.
|
volatile unsigned int * | mpMyBaseReg |
| GPIO base register.
|
unsigned short | mnMyIntMask |
| GPIO interrupt mask.
|
int | mnMyIntLevel |
| GPIO interrupt level.
|
int | mnMyIntVector |
| GPIO interrupt vector.
|
tfIsrCallback | mfIsrCallback |
| Registered ISR callback function.
|
void * | mpUserArg |
| User-supplied argument for ISR callback.
|
Static Protected Attributes |
static const int | gnDirOffset = 1 |
static const int | gnIorOffset = 2 |
static const int | gnIerOffset = 3 |
static const int | gnIefOffset = 4 |
static const int | gnIpendOffset = 5 |
Detailed Description
Instances of this class handle sending, receiving, and configuring a register containing 32 general purpose I/O pins.
Each pin may be configured as an output or input, and its values may be read/written accordingly. In addition, inputs may be registered to raise an interrupt on either rising or falling edges. The ISR notifies the application via a counting semaphore.
- See also:
- tcDspGpio Page
Member Typedef Documentation
prototype for the ISR callback
Constructor & Destructor Documentation
tcDspGpio::tcDspGpio |
( |
void * |
apAddress, |
|
|
int |
anLevel = gnAutoLevel | |
|
) |
| | |
This constructor is used to open a GPIO core instance.
The base address and interrupt used by the core are provided. All pins are initially configured as inputs, with interrupts disabled. The default output values are all set to "0". An ISR is installed to detect and report input pin value changes.
- Parameters:
-
[in] | apAddress | The base address of the GPIO core. |
[in] | anLevel | The interrupt vector used by the core (default: gnAutoLevel). |
- Returns:
- None.
- See also:
- DspGpio.h
tcDspGpio::~tcDspGpio |
( |
|
) |
|
Member Function Documentation
int tcDspGpio::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.
- Parameters:
-
| ahMyObject | The "this->" pointer for the instance of tcDspGpio associated with this ISR. |
- Returns:
- 0
bool tcDspGpio::configurePins |
( |
unsigned int |
anMask, |
|
|
teGpioDirection |
aeDir, |
|
|
bool |
abIntRising = false , |
|
|
bool |
abIntFalling = false , |
|
|
SEM_Handle |
apSem = NULL | |
|
) |
| | |
This routine is used to configure a set of GPIO pins.
The mask field determines the pins being configured. The pin direction is set, as well as the rising and falling edge interrupt enables, and the callback semaphore for the ISR to use when an interrupt occurs.
The interrupt enables and semaphore are optional parameters and are only meaningful for pins configured as inputs.
- Parameters:
-
[in] | anMask | The pins to be configured. This can be any of gnGPIO_0..gnGPIO_31 or'd together as needed. |
[in] | aeDir | The pin direction (gnGpioInput or gnGpioOutput). |
[in] | abIntRising | Boolean indicating whether rising edge interrupts are enabled. |
[in] | abIntFalling | Boolean indicating whether falling edge interrupts are enabled. |
[in] | apSem | Semaphore handle for the ISR to use when this pin's interrupt is pending. |
- Returns:
- A boolean indicating whether or not a change was made.
void tcDspGpio::registerGlobalInputSemaphore |
( |
SEM_Handle |
ahGlobalSem |
) |
|
This routine is used to register the global input semaphore.
This is a semaphore that gets posted whenever any input event that has a registered individual semaphore occurs. This allows an application to pend on the global semaphore, and then check to see which of the individual semaphores actually occurred.
- Parameters:
-
[in] | ahGlobalSem | The handle of the semaphore to use as the global input semaphore (NULL to unregister). |
- Returns:
- None.
void tcDspGpio::registerIsrCallback |
( |
tfIsrCallback |
afCallback, |
|
|
void * |
apUserArg = NULL | |
|
) |
| | |
This method is used to register a callback that is activated whenever a configured input changes state.
The callback takes three parameters: A pointer to the current instance of tcDspGpio, a mask indicating the input(s) that triggered the interrupt, and the apUserArg supplied at time of registration (perhaps a this pointer to a C++ class instance).
- Note:
- The registered function is run in ISR space and therefore must not call any DSP/BIOS functions that can cause a context switch. In particular, the tcDspGpio read_pins method is safe, but write_pins may not be called.
- Parameters:
-
[in] | afCallback | The ISR callback to register (NULL for none). |
[in] | apUserArg | An argument to be supplied with the callback. |
- Returns:
- None.
unsigned int tcDspGpio::readPins |
( |
unsigned int |
anMask |
) |
|
This routine is used to read current GPIO pin values.
- Parameters:
-
[in] | anMask | The pins to be read. This can be any of gnGPIO_0..gnGPIO_31 or'd together as needed. |
- Returns:
- The current value associated with each pin specified. Individual pin values are extracted by or'ing the return value with the appropriate pin mask (gnGPIO_0..gnGPIO_31).
void tcDspGpio::writePins |
( |
unsigned int |
anMask, |
|
|
unsigned int |
anValues | |
|
) |
| | |
This routine is used to write updated GPIO pin values.
Only the values specified by the supplied mask are changed.
- Parameters:
-
[in] | anMask | The pins to be updated. This can be any of gnGPIO_0..gnGPIO_31 or'd together as needed. |
[in] | anValues | The updated values. To set a "1", set the appropriate pin mask (gnGPIO_0..gnGPIO_31). To set a "0" clear the mask. |
- Returns:
- None.
void MityDSP::tcDspGpio::Lock |
( |
unsigned int & |
arCsr |
) |
[inline, protected] |
void MityDSP::tcDspGpio::Unlock |
( |
unsigned int |
anCsr |
) |
[inline, protected] |
void tcDspGpio::gpioInterrupt |
( |
void |
|
) |
[protected] |
Interrupt service routine for the GPIO core.
The ISR reads and clears any pending interrupts. If any of the pins with pending interrupts has a semaphore associated with it, the ISR increments the semaphore value.
"Interrupt-ness" is taken care of by the 'dispatcher' in DSP/BIOS. Installed by the constructor.
Member Data Documentation
Last known contents of DIR.
Last read contents of IOR.
Last written contents of IOR.
Last known contents of IER.
Last known contents of IEF.
Last known contents of IPEND.
Pointer to registered semaphores.
Semaphore to use as a mutex lock.
Posted whenever any other input sem is posted.
Registered ISR callback function.
User-supplied argument for ISR callback.