gfroerli / firmware

Firmware for the water temperature sensor project
GNU General Public License v3.0
6 stars 1 forks source link

Add custom Tim7Delay #77

Closed dbrgn closed 3 years ago

dbrgn commented 3 years ago

The HAL delay uses the systick timer (SYST). This timer is not available anymore when using RTIC with the scheduler.

Here's an implementation of DelayUs and DelayMs for TIM7 (with busy-looping until the update event of the timer is reached). It seems to work, although delays lower than ~4 µs cannot be achieved.

2020-08-21-010458_1813x523_scrot

The precision seems to be good enough for one-wire to work:

image

Busy-looping was the easiest approach and works, but seems a bit wasteful. Is this busy-looping standard practice? Would it be better to schedule an interrupt and WFI during looping? (I'm not sure if this could be implemented cleanly in a standalone implementation because interrupt handling ist done by RTIC...)

I think in our case it should be fine because we only use the blocking delay for very short intervals during things like one wire communication.

rnestler commented 3 years ago

Busy-looping was the easiest approach and works, but seems a bit wasteful. Is this busy-looping standard practice?

For short delays (<1ms) there is often no other way than busy-looping, since going to sleep and waking up again would take too long.

dbrgn commented 3 years ago

:+1: Do you want to review the code in-depth, or should we merge as-is?

dbrgn commented 3 years ago

@rnestler ping :slightly_smiling_face:

dbrgn commented 3 years ago

Example updated, fixup commits squashed.