Software clock based on periodic calls to his tick function. More...
Files | |
file | clock.c |
Clock implementation. | |
file | clock.h |
Clock interface. | |
Classes | |
struct | clock_secondsCount |
Seconds count. More... | |
struct | clock_timeStamp |
Time stamp. More... | |
Typedefs | |
typedef struct clock_secondsCount | clock_secondsCount |
Seconds count. More... | |
typedef struct clock_timeStamp | clock_timeStamp |
Time stamp. More... | |
Functions | |
void | clock_init () |
Clock Initialization. More... | |
void | clock_tick () |
Clock tick. More... | |
void | clock_checkDelayedTick () |
Check delayed tick. More... | |
void | clock_getTime (clock_timeStamp *destTime) |
Get time. More... | |
void | clock_setTime (clock_timeStamp *sourceTime) |
Set time. More... | |
void | clock_adjTime (int64_t *adjValue) |
Adjust time. More... | |
void | clock_adjTimeValues (int64_t *adjValue, clock_timeStamp *time) |
Adjust time values. More... | |
void | clock_adjTick (Int32 adjValue) |
Adjust tick. More... | |
int64_t | clock_timeDiff (clock_timeStamp *t1, clock_timeStamp *t2) |
Time difference. More... | |
Variables | |
UInt32 | clock_tickSize |
Tick size (ns) More... | |
Software clock based on periodic calls to his tick function.
The tick size can be adjusted to compensate oscillator constant error. The clock can be adjusted and there is external functions to get current time from an epoch, initially the power up of the device or last reset.
typedef struct clock_secondsCount clock_secondsCount |
Seconds count.
The seconds count is split into 2 parts, the lower one with 32 bits and the higher one with 16 bits, forming 48 bits total. They are easily put together to represent a 48 bits integer, observing the bit order.
typedef struct clock_timeStamp clock_timeStamp |
Time stamp.
Representation of a time stamp, the range allows representation of UTC, TAI, and may be other time references.
void clock_adjTick | ( | Int32 | adjValue | ) |
Adjust tick.
This function adjusts the tick size.
[in] | adjValue | Amount of ns to add to the tick size. |
Definition at line 511 of file clock.c.
References CLOCK_TICK_SIZE_MAX, and clock_tickSize.
Referenced by clock_adjTime().
void clock_adjTime | ( | int64_t * | adjValue | ) |
Adjust time.
This function adjusts the clock time.
[in] | adjValue | Pointer to amount of ns to add to the clock time (signed). |
Definition at line 256 of file clock.c.
References clock_adjSumSinceSint, clock_adjTick(), clock_adjTimeValues(), and clock_ticksSinceSint.
Referenced by uart_proccessCmd().
void clock_adjTimeValues | ( | int64_t * | adjValue, |
clock_timeStamp * | time | ||
) |
Adjust time values.
This function adjusts a given time stamp.
[in] | adjValue | Pointer to amount of ns to add to the time stamp (signed). |
[in,out] | time | Time stamp that will be adjusted. |
Definition at line 304 of file clock.c.
References clock_checkDelayedTick(), CLOCK_CLEARADJUSTING, CLOCK_NS_IN_ONE_S, and CLOCK_SETADJUSTING.
Referenced by clock_adjTime().
void clock_checkDelayedTick | ( | ) |
Check delayed tick.
This function checks for a delayed tick call and executes it if needed.
Definition at line 202 of file clock.c.
References CLOCK_CLEARCALLTICK, CLOCK_GETCALLTICK, and clock_tick().
Referenced by clock_adjTimeValues(), clock_getTime(), and clock_setTime().
void clock_getTime | ( | clock_timeStamp * | destTime | ) |
Get time.
This function reads the current time.
[out] | destTime | Pointer to variable that will receive the time |
Definition at line 218 of file clock.c.
References clock_checkDelayedTick(), CLOCK_CLEARADJUSTING, and CLOCK_SETADJUSTING.
Referenced by ADC10_ISR().
void clock_init | ( | ) |
Clock Initialization.
This function initializes the clock variables.
Definition at line 148 of file clock.c.
References clock_adjSumSinceSint, CLOCK_CLEARADJUSTING, CLOCK_CLEARCALLTICK, CLOCK_DEFAULT_TICK_SIZE, clock_tickSize, clock_ticksSinceSint, im_disable_interrupt(), and im_enable_interrupt().
Referenced by main().
void clock_setTime | ( | clock_timeStamp * | sourceTime | ) |
Set time.
This function sets the current time.
[in] | sourceTime | Pointer to variable containing the time to which the clock time will be set. |
Definition at line 237 of file clock.c.
References clock_checkDelayedTick(), CLOCK_CLEARADJUSTING, and CLOCK_SETADJUSTING.
Referenced by uart_proccessCmd().
void clock_tick | ( | ) |
Clock tick.
This function advances the clock in tick size.
Definition at line 171 of file clock.c.
References CLOCK_GETADJUSTING, CLOCK_NS_IN_ONE_S, CLOCK_SETCALLTICK, clock_tickSize, and clock_ticksSinceSint.
Referenced by clock_checkDelayedTick(), and TMRB0_ISR().
int64_t clock_timeDiff | ( | clock_timeStamp * | t1, |
clock_timeStamp * | t2 | ||
) |
UInt32 clock_tickSize |
Tick size (ns)
Size of the tick of the clock, it can be adjusted to compensate oscillator error.
Definition at line 102 of file clock.c.
Referenced by clock_adjTick(), clock_init(), clock_tick(), and uart_proccessCmd().