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: Improve the accuracy of the MCUX OS Timer #84938

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mmahadevan108
Copy link
Collaborator

  1. The sys_clock_idle_exit function could be invoked multiple times. Hence add code so that is counter is stopped and the OS Timer is initialized once.
  2. Reset the OS Timer when exiting low power modes where the OS Timer loses its state
  3. Improve the cycles conversion algorithm

1. The sys_clock_idle_exit function could be invoked multiple
   times. Hence add code so that is counter is stopped and the
   OS Timer is initialized once.
2. Reset the OS Timer when exiting low power modes where
   the OS Timer loses its state
3. Improve the cycles conversion algorithm

Signed-off-by: Mahesh Mahadevan <[email protected]>
Copy link
Member

@decsny decsny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the commit message is not clear about what the "improve cycles conversion algorithm" actually entails

is it possible to split these changes into 3 commits to make the changes easier to understand?

Comment on lines +120 to +124
/* Counter is set to wakeup the system after the requested time */
if (counter_start(counter_dev) != 0) {
ret = 1;
}
counter_running = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if counter_start fails, shouldn't counter_running be set to false ?

Comment on lines -89 to -90

timeout = k_ticks_to_us_ceil32(curr_timeout);
Copy link
Member

@decsny decsny Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change from ceil to near ? can it be in the commit message

Comment on lines -120 to -124

/* Counter is set to wakeup the system after the requested time */
if (counter_start(counter_dev) != 0) {
ret = 1;
}
Copy link
Member

@decsny decsny Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this moved before getting the timer value ? I didn't understand from the commit message

mcux_lpc_ostick_isr(NULL);
/* Announce the time slept to the kernel*/
mcux_lpc_ostick_isr(NULL);
}
} else {
ret = 1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole function is confusing to read, it can be cleaned up by inverting the conditionals, like

if (!counter_dev) {
   return 1;
}

if (!counter_running) {
   return 0;
}

/* rest of the code */

return 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Timer Timer platform: NXP Drivers NXP Semiconductors, drivers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants