Need to create a timer/clocking mechanism for a ColdFire project, what is the best approach?

Hello all,

I am sitting here at my first embedded position trying to get up to speed with a very aggressive schedule. I have a few beginner's book on embedded system ( An Embedded Software Primer and Practical Statecharts in C/C++: Quantum Programming for Embedded Systems ), but my current problem is that I need to implement a configurable timer/clocking mechanism to be used as a trigger. From the requirements that I have there are specs that are similar to the following... // Semi type of requirements structure.... Initialization of the device shall be started. Wait for an Ack from the device If the device doesn't send an Ack within 5 seconds a failure shall be determined. Throughout the requirements there are numerous requirements for a time-out period, but I need to develop a nice programmable timer/clocking mechanism. The project has a simple scheduler that another developer has create that is calls our various subsystems that need to be called every 12.5 Hz or 10 Hz ( or whatever the requirement states ). Initially I was thinking of housing a simple count variable within the subsystem that increments the count variable and when it reaches the threshold value it would indicate that the elapsed time has expired. I don't really like this approach since this approach will have to be sprinkled throughout the code and perhaps more than once within a subsystem. I was thinking of creating a common timer mechanism that has a resolution of about 50 or 100 ms ( since most elapsed time-out periods are 1 to 5 seconds ) that when a subsystem needs a time-out timer it would pass in the Time-out Period and a call back function. So it would look something like // I think this prototype if correct, but correct me if I am wrong addTimeout( int timeOutPeriodInMs, void (*func)(void) ) Then within the Timeout module it would keep track of the time-out periods and when one has expired it would call the callback function. I am at a lose of how to correctly implement this. I have some ideas, but I don't know if they will work and I don't have a lot of time to test it. The chip that I am using is the Motorola ( now Freescale ) MCF5282 IC. Any help is GREATLY appreciated. Thanks

Mark

Reply to
LongBow
Loading thread data ...

... snip ...

Sounds like you have multiple events to time. Consider a single timer and a priority queue. If the queue is empty on a timer tick, nothing to do. Else decrement the 'time to live' counter of the top event. If it is zero, take action and remove the entry, then repeat from check empty. Else no action on this tick.

Now the problem is how to insert events into the queue. The time to live is obviously measured from now. This has to be converted, on queue entry, into time after any earlier event. The queue also has to have an identifier per event, so if the event does not time out (i.e. is satisfied normally) the event can be removed and any following events time to live corrected. And the event has to have a pointer to the action to be taken.

--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
     USE worldnet address!
Reply to
CBFalconer

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.