CustomTime

Description

Provides extra common functions necessary for executing time-based code

CustomTimer

CustomTimer is a structure that holds two variables, useful for holding timer logic.

StoredTime - unsigned int - holds the timer start time.

Delay - unsigned int - holds the delay time before the timer finishes.

Wait(dt)

Wait() is a pause function that executes blocking code.  Reads the clock time and waits until the wait time has expired before returning to the parent function.  Returns nothing.

dt - type unsigned int - time to pause.

TimerDone(Timer, CurrentTime)

TimerDone() tests whether the CustomTimer has finished.  It returns a non-zero unsigned char if finished, and 0 if not.

Timer – type CustomTimer – holds timer data

CustomTime – type unsigned int – holds the current time, for evaluating done condition

TimerUpdate(Timer, CurrentTime)

TimerUpdate () updates Timer’s internal stored time with CurrentTime, and then returns that Timer.

Timer – type CustomTimer – holds timer data

CustomTime – type unsigned int – holds the current time, for updating internal stored time

Implementation

Wait(dt)

Create two variables, t0 and t1

Set t0 equal to the current time

Execute the following code:

            Set t1 equal to the current time

While the difference between t1 and t0 is less than dt.

TimerDone(Timer, CurrentTime)

If (CurrentTime-StoredTime) is greater than Delay, return 1.

Otherwise return zero

TimerUpdate(CustomTimer Timer, unsigned int CurrentTime)

Set Timer.StoredTime equal to CurrentTime

Return the Timer structure.