The tcDspCounter class is used to interface to the MityDSP event counter core. More...
#include <core/DspCounter.h>
Public Types | |
typedef void(* | tfIsrCallback )(int) |
prototype for the ISR callbacks. | |
typedef void(* | tfIsrCallbackWithArg )(int, void *) |
Public Member Functions | |
tcDspCounter (void *apBaseAddr, int anLevel=gnAutoLevel) | |
This constructor is used to create an interface to the MityDSP counter core located at the specified base address. | |
~tcDspCounter () | |
This destructor is used to close up and free tcDspCounter resources. | |
unsigned int | getCount (int anCounter) |
Gets the current value of the specified counter. | |
void | setCount (int anCounter, unsigned int anNewCount) |
Sets the current value of the specified counter. | |
unsigned int | getCounterDepth (int anCounter) |
Gets the current depth setting of the specified counter. | |
void | setCounterDepth (int anCounter, unsigned int anNewDepth, bool abReInit=false) |
Sets the depth of the specified counter. | |
bool | getInterruptEnable (int anCounter) |
Gets the state of the interrupt on counter rollover for the specified counter. | |
void | setInterruptEnable (int anCounter, bool abEnable) |
Sets the state of the interrupt on rollover for the specified counter. | |
void | registerIsrHandler (int anCounter, tfIsrCallback afCallback) |
Registers the user-supplied callback to be run whenever the specified counter's rollover interrupt occurs. | |
void | registerIsrHandler (int anCounter, tfIsrCallbackWithArg afCallback, void *apUserArg=NULL) |
Registers the user-supplied callback to be run whenever the specified counter's rollover interrupt occurs. | |
void | initQuadratureCount (int anCwCounter, int anCcwCounter, unsigned int anCounterDepth) |
This is a utility routine to initialize a pair of counters as a quadrature (rotation) counter. | |
int | getQuadratureCount (int anCwCounter, int anCcwCounter) |
This is a utility routine that returns a quadrature count based on the two provided counters (a clockwise counter and a counter-clockwise counter). | |
Static Public Member Functions | |
static int | interrupt_dispatch (Arg arMyObject) |
Static interrupt dispatch routine. | |
Public Attributes | |
unsigned int | mnInterruptCount |
ISR counter (debug). | |
Static Public Attributes | |
static const int | gnNumCounters = 16 |
16 counters per core | |
static const unsigned int | gnMaxCounts = 0x40000000 |
30-bit counters (2^30) |
The tcDspCounter class is used to interface to the MityDSP event counter core.
Up to 16 30-bit counters are provided. The counters can each be individually configured with a maximum count and to interrupt when they rollover.
Utility routines are provided to use any properly configured pair of counters as part of a quadrature counter.
typedef void(* MityDSP::tcDspCounter::tfIsrCallback)(int) |
prototype for the ISR callbacks.
typedef void(* MityDSP::tcDspCounter::tfIsrCallbackWithArg)(int, void *) |
tcDspCounter::tcDspCounter | ( | void * | apAddress, | |
int | anLevel = gnAutoLevel | |||
) |
This constructor is used to create an interface to the MityDSP counter core located at the specified base address.
An interrupt level may be specified to install a chained ISR at the proper level, otherwise automatic interrupt vectoring is employed.
[in] | apAddress | Base Address of Counter core |
[in] | anLevel | Optional interrupt level parameter |
tcDspCounter::~tcDspCounter | ( | ) |
This destructor is used to close up and free tcDspCounter resources.
int tcDspCounter::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 tcDspCounter associated with this ISR. |
unsigned int tcDspCounter::getCount | ( | int | anCounter | ) |
Gets the current value of the specified counter.
The returned value is corrected so that it is relative to the depth of the counter (i.e. for a 1024 deep counter, 0-1023 is returned rather than 2^30-1024 - 2^30-1).
[in] | anCounter | The counter number to read (0 - 15). |
void tcDspCounter::setCount | ( | int | anCounter, | |
unsigned int | anNewCount | |||
) |
Sets the current value of the specified counter.
The provided value is relative to the current counter depth (i.e. for a 1024 deep counter, 0-1023 is provided rather than 2^30-1024 - 2^30-1).
[in] | anCounter | The counter number to update (0 - 15). |
[in] | anNewCount | The new value (0 - (depth-1)). |
unsigned int tcDspCounter::getCounterDepth | ( | int | anCounter | ) |
Gets the current depth setting of the specified counter.
[in] | anCounter | The counter whose depth is being read (0 - 15). |
void tcDspCounter::setCounterDepth | ( | int | anCounter, | |
unsigned int | anNewDepth, | |||
bool | abReInit = false | |||
) |
Sets the depth of the specified counter.
Optionally resets the counter to zero (relative to the provided depth).
[in] | anCounter | The counter whose depth is being set (0 - 15). |
[in] | anNewDepth | The new counter depth (1 - 2^30). |
[in] | abReInit | Also reset counter to zero (default:false). |
bool tcDspCounter::getInterruptEnable | ( | int | anCounter | ) |
Gets the state of the interrupt on counter rollover for the specified counter.
[in] | anCounter | The counter whose interrupt state is being read (0 - 15). |
void tcDspCounter::setInterruptEnable | ( | int | anCounter, | |
bool | abEnable | |||
) |
Sets the state of the interrupt on rollover for the specified counter.
[in] | anCounter | The counter whose interrupt state is being set (0 - 15). |
[in] | abEnable | True to enable rollover interrupts false otherwise. |
void tcDspCounter::registerIsrHandler | ( | int | anCounter, | |
tfIsrCallback | afCallback | |||
) |
Registers the user-supplied callback to be run whenever the specified counter's rollover interrupt occurs.
Caution should be used as this callback will execute in ISR context (no DSP/BIOS calls that can potentially block are allowed)
[in] | anCounter | The counter to install the callback for. |
[in] | afCallback | Pointer to the callback routine (or NULL to disable callbacks. |
void tcDspCounter::registerIsrHandler | ( | int | anCounter, | |
tfIsrCallbackWithArg | afCallback, | |||
void * | apUserArg = NULL | |||
) |
Registers the user-supplied callback to be run whenever the specified counter's rollover interrupt occurs.
Caution should be used as this callback will execute in ISR context (no DSP/BIOS calls that can potentially block are allowed)
[in] | anCounter | The counter to install the callback for. |
[in] | afCallback | Pointer to the callback routine (or NULL to disable callbacks. |
[in] | apUserArg | An argument to be supplied with the callback. |
void tcDspCounter::initQuadratureCount | ( | int | anCwCounter, | |
int | anCcwCounter, | |||
unsigned int | anCounterDepth | |||
) |
This is a utility routine to initialize a pair of counters as a quadrature (rotation) counter.
A "clockwise" and a "counter-clockwise" counter are provided. Both are set to the provided counter depth and reinitialized.
[in] | anCwCounter | The CW quadrature counter. |
[in] | anCcwCounter | The CCW quadrature counter. |
[in] | anCounterDepth | The depth to set both counters to. |
int tcDspCounter::getQuadratureCount | ( | int | anCwCounter, | |
int | anCcwCounter | |||
) |
This is a utility routine that returns a quadrature count based on the two provided counters (a clockwise counter and a counter-clockwise counter).
These counters should have been previously initialized using initQuadratureCount.
The returned value represents the number of rotations since initialization.
[in] | anCwCounter | The CW quadrature counter. |
[in] | anCcwCounter | The CCW quadrature counter. |
const int MityDSP::tcDspCounter::gnNumCounters = 16 [static] |
16 counters per core
const unsigned int MityDSP::tcDspCounter::gnMaxCounts = 0x40000000 [static] |
30-bit counters (2^30)
unsigned int MityDSP::tcDspCounter::mnInterruptCount |
ISR counter (debug).