Skip to content

Instantly share code, notes, and snippets.

@cdcs
Created June 27, 2013 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdcs/5874932 to your computer and use it in GitHub Desktop.
Save cdcs/5874932 to your computer and use it in GitHub Desktop.
void rtems_time_travel(long ticks)
{
/* a clock tick in a timespec structure */
struct timespec tick;
/* number of seconds elapsed */
uint32_t seconds;
/* Convert the tick quantum to a timespec */
/* convert a clock tick into nanoseconds */
tick.tv_nsec = _TOD_Microseconds_per_tick * 1000 * ticks;
/* the number of seconds is 0 (assumed the clock tick fits in the
* nanoseconds field */
tick.tv_sec = 0;
/* Update the counter of ticks since boot */
_Watchdog_Ticks_since_boot += ticks;
/* Update the timespec format uptime */
(void) _Timespec_Add_to(&_TOD_Uptime , &tick);
/* Update the timespec format TOD */
seconds = _Timespec_Add_to(&_TOD_Now , &tick);
/* adjust ticks chain*/
_Watchdog_Adjust_ticks(ticks);
/* If one second has passed (or more)*/
if(seconds > 0) {
/* adjust seconds chain */
_Watchdog_Adjust_seconds(WATCHDOG_FORWARD, seconds);
}
}
/* watchdog.inl */
/**
* @brief adjust the watchdog ticks chain forward or backwards by a specified
* amount of units
*
* This routine adjusts the ticks watchdog chain in the forward
* direction for UNITS ticks (ticks are monotonic). This is invoked when there
* a partition context switch
* @param[in] units the amount of units to adjust the chain
*/
RTEMS_INLINE_ROUTINE void _Watchdog_Adjust_ticks(
Watchdog_Interval units
)
{
/* adjust the watchdog seconds chain */
_Watchdog_Adjust(&_Watchdog_Ticks_chain , WATCHDOG_FORWARD , units);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment