Timer driver/utility for all platforms

Post your example source code and application notes to share with others
User avatar
dciliske
Posts: 614
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: Timer driver/utility for all platforms

Post by dciliske » Thu Feb 09, 2012 1:46 pm

Removed double post.
Last edited by dciliske on Thu Feb 09, 2012 1:56 pm, edited 1 time in total.
Dan Ciliske
Project Engineer
Netburner, Inc

User avatar
dciliske
Posts: 614
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: Timer driver/utility for all platforms

Post by dciliske » Thu Feb 09, 2012 1:48 pm

Following up on this thread, we've actually added this utility to the main NetBurner library for the next release. That said, it's a little more high level and user friendly. We have also changed the name to reflect the true nature of the utility (was StopWatch, now HiResTimer).

First and foremost, all MCF5272 based devices are not compatible with this library.

To use the utility, include the source and header file in your project.

The HiResTimer class has no public constructors. This is because a HiResTimer only has meaning in the context of a physical hardware timer, which are in limited supply. Instead, the user must obtain a pointer to a preconstructed object by calling on the static getHiResTimer method.

In general, other than the object oriented nature and a few inlines, the library interface remains relatively unchanged. The methods still have the same semantic names.

Methods provided:

Setup Functions

• getHiResTimer --- Obtain a pointer to one of the timers
• init --- Initializes the timer
• setInterruptFunction --- Sets the function to trigger when the timer’s delay/period expires
• clearInterruptFunction --- Removes the trigger function
Stopwatch Functions

• start --- Start the timer
• stop --- Stop the timer
• stopClear --- Stop and reset the timer
• readTime --- Gives the runtime since the timer started
• readLow --- Returns the current value of the hardware timer register.
• readHigh --- Returns the current cycle count

Delay Functions

• delay --- Switch tasks and delay the current task by the specified number of seconds
• pollingDelay --- (Busy wait) Delay the current task by the specified number of seconds

Other Functions

• getPrescaler --- Returns the active value for the hardware timer’s prescaler
• clockGenerator --- Sets the timer to fire the timer’s Interrupt Function at a given frequency
• toString --- Returns a pointer to a cstring of the timer object’s data

Macros
• DEFAULT_TIMER --- Sets the default timer to return, when no label is given
• TIMER_COUNT --- Sets the number of timer objects to create
DO NOT EXCEED THE HARDWARE COUNT!

-Dan
Attachments
HiResTimer.zip
Project files, including example.
(299.45 KiB) Downloaded 283 times
Dan Ciliske
Project Engineer
Netburner, Inc

Post Reply