The tcDspCounter class is used to interface to the MityDSP event counter core.
More...
#include <core/DspCounter.h>
List of all members.
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.
|
Static Public Attributes |
static const int | gnNumCounters = 16 |
| 16 counters per core
|
static const unsigned int | gnMaxCounts = 0x40000000 |
| 30-bit counters (2^30)
|
Detailed Description
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.
- See also:
- tcDspCounter Page
Member Typedef Documentation
typedef void(* MityDSP::tcDspCounter::tfIsrCallback)(int) |
prototype for the ISR callbacks.
typedef void(* MityDSP::tcDspCounter::tfIsrCallbackWithArg)(int, void *) |
Constructor & Destructor Documentation
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.
- Parameters:
-
[in] | apAddress | Base Address of Counter core |
[in] | anLevel | Optional interrupt level parameter |
- Returns:
- None.
- See also:
- DspCounter.h
-
DspIntDispatch.h
tcDspCounter::~tcDspCounter |
( |
| ) |
|
Member Function Documentation
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.
- Parameters:
-
[in] | ahMyObject | The "this->" pointer for the instance of tcDspCounter associated with this ISR. |
- Returns:
- 0
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).
- Parameters:
-
[in] | anCounter | The counter number to read (0 - 15). |
- Returns:
- Counter value (0 - (depth-1)).
- See also:
- DspCounter.h
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).
- Parameters:
-
[in] | anCounter | The counter number to update (0 - 15). |
[in] | anNewCount | The new value (0 - (depth-1)). |
- Returns:
- None.
- See also:
- DspCounter.h
unsigned int tcDspCounter::getCounterDepth |
( |
int |
anCounter | ) |
|
Gets the current depth setting of the specified counter.
- Parameters:
-
[in] | anCounter | The counter whose depth is being read (0 - 15). |
- Returns:
- Counter depth (1 - 2^30).
- See also:
- DspCounter.h
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).
- Parameters:
-
[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). |
- Returns:
- None.
- See also:
- DspCounter.h
bool tcDspCounter::getInterruptEnable |
( |
int |
anCounter | ) |
|
Gets the state of the interrupt on counter rollover for the specified counter.
- Parameters:
-
[in] | anCounter | The counter whose interrupt state is being read (0 - 15). |
- Returns:
- True if rollover interrupts are enabled, false otherwise.
- See also:
- DspCounter.h
void tcDspCounter::setInterruptEnable |
( |
int |
anCounter, |
|
|
bool |
abEnable |
|
) |
| |
Sets the state of the interrupt on rollover for the specified counter.
- Parameters:
-
[in] | anCounter | The counter whose interrupt state is being set (0 - 15). |
[in] | abEnable | True to enable rollover interrupts false otherwise. |
- Returns:
- None.
- See also:
- DspCounter.h
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)
- Parameters:
-
[in] | anCounter | The counter to install the callback for. |
[in] | afCallback | Pointer to the callback routine (or NULL to disable callbacks. |
- Returns:
- None.
- See also:
- DspCounter.h
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)
- Parameters:
-
[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. |
- Returns:
- None.
- See also:
- DspCounter.h
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.
- Parameters:
-
[in] | anCwCounter | The CW quadrature counter. |
[in] | anCcwCounter | The CCW quadrature counter. |
[in] | anCounterDepth | The depth to set both counters to. |
- Returns:
- None.
- See also:
- DspCounter.h
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.
- Note:
- It is up to the application to handle rollover conditions. The recommended method to do this is to either set the depth of the counters such that rollover is not possible, or if this is not practical, periodically call initQuadratureCount to reset the counters while retaining the previous total rotation count.
- Parameters:
-
[in] | anCwCounter | The CW quadrature counter. |
[in] | anCcwCounter | The CCW quadrature counter. |
- Returns:
- Rotation count (CW is positive).
- See also:
- DspCounter.h
Member Data Documentation
const int MityDSP::tcDspCounter::gnNumCounters = 16 |
|
static |
const unsigned int MityDSP::tcDspCounter::gnMaxCounts = 0x40000000 |
|
static |
unsigned int MityDSP::tcDspCounter::mnInterruptCount |