In many microcontrollers, periodic interrupts (1 ms, 10 ms, 100 ms, etc.) are generated using a hardware timer reload value.
This value must be computed using:
reload = timerClockHz × intervalSec
Since this value must be exact, firmware often computes it at compile time using constexpr.
Incorrect reload values cause jitter, drift, or system failure.
Your job is to compute the correct timer reload count at compile time for different timer intervals.
What you must do:
constexpr function named computeReload(clockHz × intervalMs + 500) / 1000 +500 is used for integer roundingconstexpr array named RELOAD_TABLEcomputeReloadtimerClockHz = 1'000'000 (1 MHz)Program input:
0 → 1 ms reload1 → 10 ms reload2 → 100 ms reloadProgram output:
RELOAD_TABLE[index]
Example 1
Input:
1
Output:
10000
Example 2
Input:
2
Output:
100000
Constraints:
computeReload must be declared constexprRELOAD_TABLE must be declared constexpr
Input
0
Expected Output
1000