23 #include <msp430f2274.h>
39 #define CLOCK_DEFAULT_TICK_SIZE 250000
43 #define CLOCK_TICK_SIZE_MAX 500000
47 #define CLOCK_NS_IN_ONE_S 1000000000
56 #define CLOCK_FLAGADJUSTING 1
60 #define CLOCK_FLAGCALLTICK 2
65 #define CLOCK_GETADJUSTING clock_runningFlags & CLOCK_FLAGADJUSTING
69 #define CLOCK_SETADJUSTING clock_runningFlags |= CLOCK_FLAGADJUSTING
73 #define CLOCK_CLEARADJUSTING clock_runningFlags &= ~CLOCK_FLAGADJUSTING
78 #define CLOCK_GETCALLTICK clock_runningFlags & CLOCK_FLAGCALLTICK
82 #define CLOCK_SETCALLTICK clock_runningFlags |= CLOCK_FLAGCALLTICK
86 #define CLOCK_CLEARCALLTICK clock_runningFlags &= ~CLOCK_FLAGCALLTICK
155 clock_time.seconds.secondsLow = 0;
156 clock_time.seconds.secondsHigh = 0;
157 clock_time.nanoSeconds = 0;
179 clock_time.seconds.secondsLow += 1;
180 if (!clock_time.seconds.secondsLow) {
181 clock_time.seconds.secondsHigh += 1;
185 if (clock_time.seconds.secondsLow & 0x01) {
220 destTime->nanoSeconds = clock_time.nanoSeconds;
221 destTime->seconds.secondsLow = clock_time.seconds.secondsLow;
222 destTime->seconds.secondsHigh = clock_time.seconds.secondsHigh;
239 clock_time.seconds.secondsLow = sourceTime->seconds.secondsLow;
240 clock_time.seconds.secondsHigh = sourceTime->seconds.secondsHigh;
241 clock_time.nanoSeconds = sourceTime->nanoSeconds;
263 if ((((*adjValue) < 3000000000)
264 && (-(*adjValue) < 3000000000))) {
305 int64_t adjSeconds = 0;
306 Int32 adjNanoseconds;
310 if ((*adjValue >= 2147483647000000000)
311 || (*adjValue < -2147483648000000000))
328 adjSeconds = *adjValue;
330 adjSeconds += *adjValue;
332 adjSeconds += *adjValue;
334 adjSeconds += *adjValue;
336 adjSeconds += *adjValue;
338 adjSeconds += *adjValue;
340 adjSeconds += *adjValue;
342 adjSeconds += *adjValue;
344 adjSeconds += *adjValue;
346 adjSeconds += *adjValue;
348 adjSeconds += *adjValue;
350 adjSeconds += *adjValue;
352 adjSeconds += *adjValue;
354 adjSeconds += *adjValue;
356 adjSeconds += *adjValue;
358 adjSeconds += *adjValue;
360 adjSeconds += *adjValue;
362 adjSeconds += *adjValue;
364 adjSeconds += *adjValue;
366 adjSeconds += *adjValue;
368 adjSeconds += *adjValue;
370 adjSeconds += *adjValue;
372 adjSeconds += *adjValue;
374 adjSeconds += *adjValue;
376 adjSeconds += *adjValue;
378 adjSeconds += *adjValue;
380 adjSeconds += *adjValue;
382 adjSeconds += *adjValue;
384 adjSeconds += *adjValue;
386 adjSeconds += *adjValue;
388 adjSeconds += *adjValue;
390 adjSeconds += *adjValue;
392 adjSeconds += *adjValue;
394 adjSeconds += *adjValue;
396 adjSeconds += *adjValue;
398 adjSeconds += *adjValue;
400 adjSeconds += *adjValue;
402 adjSeconds += *adjValue;
404 adjSeconds += *adjValue;
406 adjSeconds += *adjValue;
408 adjSeconds += *adjValue;
410 adjSeconds += *adjValue;
412 adjSeconds += *adjValue;
414 adjSeconds += *adjValue;
418 tmpInt64 = adjSeconds;
420 tmpInt64 -= adjSeconds;
422 tmpInt64 -= adjSeconds;
424 tmpInt64 += adjSeconds;
426 tmpInt64 += adjSeconds;
428 tmpInt64 += adjSeconds;
430 tmpInt64 += adjSeconds;
432 tmpInt64 += adjSeconds;
434 tmpInt64 += adjSeconds;
436 tmpInt64 += adjSeconds;
439 adjNanoseconds = *adjValue - tmpInt64;
453 tmpInt64 = *adjValue;
462 adjNanoseconds = tmpInt64;
465 if (time == &clock_time) {
470 if (adjSeconds < 0) {
471 if (time->seconds.secondsLow < (UInt32) -adjSeconds)
472 time->seconds.secondsHigh -= 1;
473 time->seconds.secondsLow += adjSeconds;
475 time->seconds.secondsLow += adjSeconds;
476 if (time->seconds.secondsLow < (UInt32) adjSeconds)
477 time->seconds.secondsHigh += 1;
480 if ((adjNanoseconds < 0)
481 && (time->nanoSeconds < (UInt32) -adjNanoseconds)) {
482 if (!time->seconds.secondsLow)
483 time->seconds.secondsHigh -= 1;
484 time->seconds.secondsLow -= 1;
487 time->nanoSeconds += adjNanoseconds;
489 time->seconds.secondsLow += 1;
490 if (!time->seconds.secondsLow)
491 time->seconds.secondsHigh += 1;
496 if (time == &clock_time) {
536 if (t2->seconds.secondsHigh != t1->seconds.secondsHigh) {
537 r = -t1->seconds.secondsHigh;
538 r += t2->seconds.secondsHigh;
543 r -= t1->seconds.secondsLow;
544 r += t2->seconds.secondsLow;
578 r -= t1->nanoSeconds;
579 r += t2->nanoSeconds;
#define CLOCK_GETADJUSTING
Macro to test if clock is adjusting.
void clock_adjTimeValues(int64_t *adjValue, clock_timeStamp *time)
Adjust time values.
int64_t clock_adjSumSinceSint
Adjust sum since Sintonization.
Interruption management (enable/disable) interface.
void clock_tick()
Clock tick.
#define CLOCK_TICK_SIZE_MAX
Maximum value that tick size can be adjusted to (ns).
#define CLOCK_SETADJUSTING
Macro to set adjusting flag.
UInt32 clock_tickSize
Tick size (ns)
void im_disable_interrupt()
Disable interrupt.
void clock_init()
Clock Initialization.
#define CLOCK_DEFAULT_TICK_SIZE
Default tick size (ns) this may be changed as needed by the application.
void im_enable_interrupt()
Enable interrupt.
#define CLOCK_CLEARADJUSTING
Macro to clear adjusting flag.
clock_timeStamp clock_time
Clock time.
UInt16 clock_ticksSinceSint
Ticks since Sintonization.
void clock_adjTick(Int32 adjValue)
Adjust tick.
int64_t clock_timeDiff(clock_timeStamp *t1, clock_timeStamp *t2)
Time difference.
UInt8 clock_runningFlags
Flags for internal use.
#define CLOCK_GETCALLTICK
Macro to test if clock delayed tick is set.
#define CLOCK_CLEARCALLTICK
Macro to clear delayed tick flag.
void clock_checkDelayedTick()
Check delayed tick.
#define CLOCK_NS_IN_ONE_S
Alias to avoid mistyping.
#define CLOCK_SETCALLTICK
Macro to set delayed tick flag.
void clock_setTime(clock_timeStamp *sourceTime)
Set time.
void clock_adjTime(int64_t *adjValue)
Adjust time.
void clock_getTime(clock_timeStamp *destTime)
Get time.