-
-
Notifications
You must be signed in to change notification settings - Fork 347
Add hw_timer driver and clarify use of Timer1/Timer2
#1830
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
Conversation
PR SmingHub#1810 modified the calculations for `usToTimerTicks()` and `timerTicksToUs()`, but these are only applicable to Timer2 (which is a 32-bit up-counter). HardwareTimer uses Timer1 (a 23-bit down-counter) so the conversion functions are now static methods, now using a `muldiv()` function so times are rounded rather than truncated for better accuracy. Overflows are also handled in a more consistent fashion by using the maximal value rather than the modulus. Both timers default to /16 prescale, but are independently configurable. Note, however, that the Timer2 prescale must not be set directly as this drives software timers which are used internally by the SDK. Instead, this is set using a call to `system_timer_reinit`, which has been moved into the driver. Startup code now calls `hw_timer_init` instead to ensure a consistent state. HardwareTimer methods are now mainly in the header so the compiler can better optimise calls. A `state` variable also improves speed as RAM accesses are faster than I/O. The interval is stored as a tick value, rather than the time in microseconds, to avoid un-necessary recalculations. This makes calls to restart faster. A `setInterval` method has been added so pre-calculated tick values can be set directly. Rename `MAX_HW_TIMER1_INTERVAL_US` to `MAX_HW_TIMER1_INTERVAL` as it in ticks not microseconds. Host emulation of timers now implemented in an improved `hw_timer` driver. Added basic runtime support for rational number handling to complement std::ratio.
Add interrupts and timers pages Add notes to upgrading page
|
I've no idea what codacy is upset about. My guess was function return value unused. Any ideas? |
I've looked at the reported issues and will mark them as false-positive for now. Is the this PR tested on a real device and in the emulator :) ? Do you want to add something before merging it? |
And thanks a lot for the new and very well explained stuff. I like it a lot. |
b5807a6 to
bf449a0
Compare
|
Tested with LiveDebug, Servo samples, don't appear to be any others which use the HardwareTimer. I'll be adding loads more tests for this in the next PR. |
Add
hw_timerdriver and clarify distinction between Timer1 and Timer2.PR #1810 modified the calculations for
usToTimerTicks()andtimerTicksToUs(),but these are only applicable to Timer2 (which is a 32-bit up-counter).
HardwareTimer uses Timer1 (a 23-bit down-counter) so the conversion functions
are now static methods, now using a
muldiv()function so times are roundedrather than truncated for better accuracy. Overflows are also handled in a more
consistent fashion by using the maximal value rather than the modulus.
Both timers default to /16 prescale, but are independently configurable.
Note, however, that the Timer2 prescale must not be set directly as this drives
software timers which are used internally by the SDK. Instead, this is set using a
call to
system_timer_reinit, which has been moved into the driver.Startup code now calls
hw_timer_initinstead to ensure a consistent state.HardwareTimer methods are now mainly in the header so the compiler can better
optimise calls. A
statevariable also improves speed as RAM accesses are fasterthan I/O. The interval is stored as a tick value, rather than the time
in microseconds, to avoid un-necessary recalculations. This makes calls to restart
faster. A
setIntervalmethod has been added so pre-calculated tick values canbe set directly.
Rename
MAX_HW_TIMER1_INTERVAL_UStoMAX_HW_TIMER1_INTERVALas it in ticks not microseconds.Host emulation of timers now implemented in an improved
hw_timerdriver.Added basic runtime support for rational number handling to complement std::ratio.
Update documentation
Add interrupts and timers pages
Add notes to upgrading page
Restructure HostTests using task queue, add rational number tests