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

drivers: timer : cortex_m_systick MAX_TICKS protection #83450

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion drivers/timer/cortex_m_systick.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@

#define CYC_PER_TICK (sys_clock_hw_cycles_per_sec() \
/ CONFIG_SYS_CLOCK_TICKS_PER_SEC)
#define MAX_TICKS ((k_ticks_t)(COUNTER_MAX / CYC_PER_TICK) - 1)
/* add MAX_TICKS protection */
#define _MAX_TICKS (int)((k_ticks_t)(COUNTER_MAX / CYC_PER_TICK) - 1)
#define MAX_TICKS ((_MAX_TICKS > 0) ? _MAX_TICKS : 1)
#define MAX_CYCLES (MAX_TICKS * CYC_PER_TICK)

#if (COUNTER_MAX / CYC_PER_TICK) == 1
#pragma message("tickless doesn nothing as CONFIG_SYS_CLOCK_TICKS_PER_SEC too low")
#endif

/* Minimum cycles in the future to try to program. Note that this is
* NOT simply "enough cycles to get the counter read and reprogrammed
* reliably" -- it becomes the minimum value of the LOAD register, and
Expand Down
Loading