660 if (c == 0) |
660 if (c == 0) |
661 return b; |
661 return b; |
662 else |
662 else |
663 return euclide(b, c); |
663 return euclide(b, c); |
664 } |
664 } |
665 |
665 |
666 void update_ticktime(unsigned long long time) { |
666 bool update_ticktime(unsigned long long time) { |
|
667 bool overflow = false; |
|
668 |
667 if (common_ticktime == 0) |
669 if (common_ticktime == 0) |
668 common_ticktime = time; |
670 common_ticktime = time; |
669 else if (time > common_ticktime) |
671 else if (time > common_ticktime) |
670 common_ticktime = euclide(time, common_ticktime); |
672 common_ticktime = euclide(time, common_ticktime); |
671 else |
673 else |
672 common_ticktime = euclide(common_ticktime, time); |
674 common_ticktime = euclide(common_ticktime, time); |
673 if (least_common_ticktime == 0) |
675 if (least_common_ticktime == 0) |
674 least_common_ticktime = time; |
676 least_common_ticktime = time; |
675 else |
677 else { |
676 least_common_ticktime = (least_common_ticktime * time) / common_ticktime; |
678 /* Test overflow on MUL by pre-condition: If (ULL_MAX / a) < b => overflow! */ |
677 } |
679 overflow = ((ULL_MAX / least_common_ticktime) < (time / common_ticktime)); |
678 |
680 least_common_ticktime = least_common_ticktime * (time / common_ticktime); |
|
681 } |
|
682 fprintf(stderr, "time=%llu least_common_ticktime=%llu common_ticktime=%llu\n", time, least_common_ticktime, common_ticktime ); |
|
683 return !overflow; |
|
684 } |
|
685 |
679 unsigned long long get_common_ticktime(void) { |
686 unsigned long long get_common_ticktime(void) { |
680 return common_ticktime; |
687 return common_ticktime; |
681 } |
688 } |
682 |
689 |
683 unsigned long get_greatest_tick_count(void) { |
690 unsigned long get_greatest_tick_count(void) { |
689 |
696 |
690 /* TASK task_name task_initialization */ |
697 /* TASK task_name task_initialization */ |
691 //SYM_REF2(task_configuration_c, task_name, task_initialization) |
698 //SYM_REF2(task_configuration_c, task_name, task_initialization) |
692 void *visit(task_initialization_c *symbol) { |
699 void *visit(task_initialization_c *symbol) { |
693 if (symbol->interval_data_source != NULL) { |
700 if (symbol->interval_data_source != NULL) { |
694 unsigned long long time = calculate_time(symbol->interval_data_source); |
701 unsigned long long time = calculate_time(symbol->interval_data_source); |
695 if (time < 0) ERROR; |
702 if (!update_ticktime(time)) |
696 else update_ticktime(time); |
703 /* time is being stored in ns resolution (MILLISECOND #define is set to 1000000) */ |
|
704 /* time is being stored in unsigned long long (ISO C99 guarantees at least 64 bits) */ |
|
705 /* 2⁶64ns works out to around 584.5 years, assuming 365.25 days per year */ |
|
706 STAGE4_ERROR(symbol, symbol, "Internal overflow calculating least common multiple of task intervals (must be < 584 years)."); |
697 } |
707 } |
698 return NULL; |
708 return NULL; |
699 } |
709 } |
700 }; |
710 }; |
701 |
711 |