6#ifndef INCLUDE_ZEPHYR_SYS_LINEAR_RANGE_H_
7#define INCLUDE_ZEPHYR_SYS_LINEAR_RANGE_H_
80#define LINEAR_RANGE_INIT(_min, _step, _min_idx, _max_idx) \
84 .min_idx = (_min_idx), \
85 .max_idx = (_max_idx), \
97 return r->max_idx -
r->min_idx + 1U;
113 for (
size_t i = 0U; i < r_cnt; i++) {
129 return r->min + (
int32_t)(
r->step * (
r->max_idx -
r->min_idx));
145 if ((idx < r->min_idx) || (idx >
r->max_idx)) {
149 *val =
r->min + (
int32_t)(
r->step * (idx -
r->min_idx));
171 for (
size_t i = 0U; (ret != 0) && (i < r_cnt); i++) {
235 for (
size_t i = 0U; i < r_cnt; i++) {
237 (i < (r_cnt - 1U))) {
271 if ((val_max < r->min) || (val_min > r_max)) {
275 if (val_min < r->min) {
280 if (val_max > r_max) {
291 if ((
r->min +
r->step * (*idx -
r->min_idx)) > val_max) {
324 for (
size_t i = 0U; i < r_cnt; i++) {
workaround assembler barfing for ST r
Definition asm-macro-32-bit-gnu.h:24
static int linear_range_group_get_win_index(const struct linear_range *r, size_t r_cnt, int32_t val_min, int32_t val_max, uint16_t *idx)
Obtain index in a group given a value that must be within a window of values.
Definition linear_range.h:318
static uint32_t linear_range_group_values_count(const struct linear_range *r, size_t r_cnt)
Obtain the number of values representable by a group of linear ranges.
Definition linear_range.h:108
static int linear_range_get_win_index(const struct linear_range *r, int32_t val_min, int32_t val_max, uint16_t *idx)
Obtain index given a window of values.
Definition linear_range.h:265
static int linear_range_get_value(const struct linear_range *r, uint16_t idx, int32_t *val)
Obtain value given a linear range index.
Definition linear_range.h:142
static int linear_range_get_index(const struct linear_range *r, int32_t val, uint16_t *idx)
Obtain index given a value.
Definition linear_range.h:193
static int linear_range_group_get_index(const struct linear_range *r, size_t r_cnt, int32_t val, uint16_t *idx)
Obtain index in a group given a value.
Definition linear_range.h:231
static int linear_range_group_get_value(const struct linear_range *r, size_t r_cnt, uint16_t idx, int32_t *val)
Obtain value in a group given a linear range index.
Definition linear_range.h:165
static uint32_t linear_range_values_count(const struct linear_range *r)
Obtain the number of values representable in a linear range.
Definition linear_range.h:95
static int32_t linear_range_get_max_value(const struct linear_range *r)
Obtain the maximum value representable by a linear range.
Definition linear_range.h:127
#define DIV_ROUND_UP(n, d)
Divide and round up.
Definition util.h:352
#define EINVAL
Invalid argument.
Definition errno.h:60
#define ERANGE
Result too large.
Definition errno.h:72
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Linear range.
Definition linear_range.h:61
int32_t min
Minimum value.
Definition linear_range.h:63
uint16_t min_idx
Minimum index (must be <= maximum index).
Definition linear_range.h:67
uint16_t max_idx
Maximum index (must be >= minimum index).
Definition linear_range.h:69
uint32_t step
Step value.
Definition linear_range.h:65