[riot-notifications] [RIOT] xtimer: Add support for arbitrary frequency hardware timers (32768 Hz support) (#3990)
Joakim NohlgÄrd
notifications at github.com
Wed Sep 30 11:22:03 CEST 2015
> + * (512 / 15625), which reduces the truncation caused by the integer widths */
> +
> +inline static uint32_t _xtimer_us_to_ticks(uint32_t us) {
> + /* return (usec * 512) / 15625; */
> + /*
> + * Optimization to avoid division instructions or division libraries.
> + * This code gives equivalent machine code on ARMv7-M (Cortex-M3, M4) as
> + * generated by compiling the above code line.
> + * at -O2 or higher with GCC 4.9. Cortex-M4 with optimization level -Os or
> + * lower does not automatically perform this optimization.
> + * Cortex-M0 (ARMv6-M) does not have hardware division and will insert a
> + * call to the helper function __aeabi_uidiv which is quite complex and
> + * slow, and uses an additional 200 bytes of ROM compared to the helper
> + * function required for multiplying two 32 bit integers into a 64 bit result.
> + */
> + return ((uint64_t)(us << 9) * 0x431bde83ul) >> (12 + 32);
I was worrying about the big scary modular arithmetic magic constant would mess up the division if didn't shift first to get the proper fixed-point number.
I will update the PR.
---
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/3990/files#r40773873
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20150930/c39a9a72/attachment.html>
More information about the notifications
mailing list