#include <assert.h>
#include <stdint.h>
Go to the source code of this file.
◆ DIV_H_INV_15625_32
#define DIV_H_INV_15625_32 0x431bde83ul |
Approximation of (2**l)/d for d=15625, l=12, 32 bits.
Definition at line 37 of file div.h.
◆ DIV_H_INV_15625_64
#define DIV_H_INV_15625_64 0x431bde82d7b634dbull |
Approximation of (2**l)/d for d=15625, l=12, 64 bits.
Definition at line 42 of file div.h.
◆ DIV_H_INV_15625_SHIFT
#define DIV_H_INV_15625_SHIFT 12 |
Required shifts for division by 15625, l above.
Definition at line 47 of file div.h.
◆ div_u32_by_15625div512()
static uint32_t div_u32_by_15625div512 |
( |
uint32_t |
val | ) |
|
|
inlinestatic |
Divide val by (15625/512)
This is used to quantize a 1MHz value to the closest 32768Hz value, e.g., for timers.
The algorithm uses the modular multiplicative inverse of 15625 to use only multiplication and bit shifts to perform the division.
The result will be equal to the mathematical expression: floor((val * 512) / 15625)
- Parameters
-
- Returns
- (val / (15625/512))
Definition at line 130 of file div.h.
◆ div_u32_by_44488()
static uint32_t div_u32_by_44488 |
( |
uint32_t |
val | ) |
|
|
inlinestatic |
Integer divide val by 44488.
- Parameters
-
- Returns
- (val / 44488)
Definition at line 164 of file div.h.
◆ div_u32_mod_44488()
static uint32_t div_u32_mod_44488 |
( |
uint32_t |
val | ) |
|
|
inlinestatic |
Modulo 44488.
- Parameters
-
- Returns
- (val % 44488)
Definition at line 175 of file div.h.
◆ div_u64_by_1000000()
static uint64_t div_u64_by_1000000 |
( |
uint64_t |
val | ) |
|
|
inlinestatic |
Integer divide val by 1000000.
- Parameters
-
- Returns
- (val / 1000000)
Definition at line 111 of file div.h.
◆ div_u64_by_125()
static uint32_t div_u64_by_125 |
( |
uint64_t |
val | ) |
|
|
inlinestatic |
Integer divide val by 125.
This function can be used to convert uint64_t microsecond times (or intervals) to milliseconds and store them in uint32_t variables, with up to ~50 days worth of milliseconds ((2**32*1000) -1). Use e.g., ms = div_u64_by_125(microseconds >> 3)
- Precondition
- val <= 536870911999 ((2**32 * 125) -1)
- Parameters
-
- Returns
- (val / 125)
Definition at line 91 of file div.h.
◆ div_u64_by_15625()
static uint64_t div_u64_by_15625 |
( |
uint64_t |
val | ) |
|
|
inlinestatic |
Integer divide val by 15625, 64 bit version.
- Parameters
-
- Returns
- (val / 15625)
Definition at line 70 of file div.h.
◆ div_u64_by_15625div512()
static uint64_t div_u64_by_15625div512 |
( |
uint64_t |
val | ) |
|
|
inlinestatic |
Divide val by (15625/512)
This is used to quantize a 1MHz value to the closest 32768Hz value, e.g., for timers.
- Parameters
-
- Returns
- (val / (15625/512))
Definition at line 144 of file div.h.