Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/sam3: assert valid freq in timer_init() #19925

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cpu/sam3/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
* channel 1 toggles this line on each timer tick, the actual frequency
* driving channel 0 is f_ch2 / 2 --> f_ch0/1 = (MCK / 2) / 2 / freq.
*/
dev(tim)->TC_CHANNEL[1].TC_RC = (CLOCK_CORECLOCK / 4) / freq;
uint32_t tc_rc = (CLOCK_CORECLOCK / 4) / freq;
/* the API expects apps to know in advance which frequencies are possible
* and only configure with supported frequencies. So aid debugging with
* an assert */
assert(tc_rc * freq == CLOCK_CORECLOCK / 4);
dev(tim)->TC_CHANNEL[1].TC_RC = tc_rc;

/* start channel 1 */
dev(tim)->TC_CHANNEL[1].TC_CCR = (TC_CCR_CLKEN | TC_CCR_SWTRG);
Expand Down