#include <iostream>
using namespace std;
// Compute timer reload at compile time (with rounding)
constexpr unsigned int computeReload(unsigned int clockHz,
unsigned int intervalMs) {
return (clockHz * intervalMs + 500) / 1000;
}
// Precomputed reload values for 1 ms, 10 ms, 100 ms
constexpr unsigned int RELOAD_TABLE[3] = {
computeReload(1'000'000, 1),
computeReload(1'000'000, 10),
computeReload(1'000'000, 100)
};
int main() {
int idx;
cin >> idx;
cout << RELOAD_TABLE[idx];
return 0;
}
Explanation & Logic Summary:
constexpr ensures all reload values are computed at compile timeFirmware Relevance & Real Embedded Meaning:
This mirrors how real MCU HALs and RTOS kernels configure timers internally.
Input
0
Expected Output
1000