no-OS
Loading...
Searching...
No Matches
no_os_util.h File Reference

Header file of utility functions. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
Include dependency graph for no_os_util.h:

Macros

#define __no_os_weak__(x)
 
#define NO_OS_BIT(x)
 
#define NO_OS_BIT_ULL(x)
 
#define NO_OS_ARRAY_SIZE(x)
 
#define NO_OS_DIV_ROUND_UP(x, y)
 
#define NO_OS_DIV_ROUND_CLOSEST(x, y)
 
#define NO_OS_DIV_ROUND_CLOSEST_ULL(x, y)
 
#define no_os_min(x, y)
 
#define no_os_min_t(type, x, y)
 
#define no_os_max(x, y)
 
#define no_os_max_t(type, x, y)
 
#define no_os_clamp(val, min_val, max_val)
 
#define no_os_clamp_t(type, val, min_val, max_val)
 
#define no_os_swap(x, y)
 
#define no_os_round_up(x, y)
 
#define NO_OS_BITS_PER_LONG   32
 
#define NO_OS_GENMASK(h, l)
 
#define NO_OS_GENMASK_ULL(h, l)
 
#define no_os_bswap_constant_32(x)
 
#define no_os_bswap_constant_16(x)
 
#define no_os_bit_swap_constant_8(x)
 
#define NO_OS_U16_MAX   ((uint16_t)~0U)
 
#define NO_OS_S16_MAX   ((int16_t)(NO_OS_U16_MAX>>1))
 
#define NO_OS_DIV_U64(x, y)
 
#define NO_OS_UNUSED_PARAM(x)
 
#define no_os_shift_right(x, s)
 
#define no_os_align(x, align)
 
#define no_os_bcd2bin(x)
 
#define no_os_bin2bcd(x)
 
#define NO_OS_CONTAINER_OF(ptr, type, name)
 

Functions

int no_os_test_bit (int pos, const volatile void *addr)
 
uint32_t no_os_find_first_set_bit (uint32_t word)
 
uint64_t no_os_find_first_set_bit_u64 (uint64_t word)
 
uint32_t no_os_find_last_set_bit (uint32_t word)
 
uint64_t no_os_find_last_set_bit_u64 (uint64_t word)
 
uint32_t no_os_find_closest (int32_t val, const int32_t *array, uint32_t size)
 
uint32_t no_os_field_prep (uint32_t mask, uint32_t val)
 
uint64_t no_os_field_prep_u64 (uint64_t mask, uint64_t val)
 
uint32_t no_os_field_get (uint32_t mask, uint32_t word)
 
uint32_t no_os_field_max (uint32_t mask)
 
uint64_t no_os_field_max_u64 (uint64_t mask)
 
int32_t no_os_log_base_2 (uint32_t x)
 
uint32_t no_os_greatest_common_divisor (uint32_t a, uint32_t b)
 
uint64_t no_os_greatest_common_divisor_u64 (uint64_t a, uint64_t b)
 
uint32_t no_os_lowest_common_multiple (uint32_t a, uint32_t b)
 
void no_os_rational_best_approximation (uint32_t given_numerator, uint32_t given_denominator, uint32_t max_numerator, uint32_t max_denominator, uint32_t *best_numerator, uint32_t *best_denominator)
 
void no_os_rational_best_approximation_u64 (uint64_t given_numerator, uint64_t given_denominator, uint64_t max_numerator, uint64_t max_denominator, uint64_t *best_numerator, uint64_t *best_denominator)
 
unsigned int no_os_hweight8 (uint8_t word)
 
unsigned int no_os_hweight16 (uint16_t word)
 
unsigned int no_os_hweight32 (uint32_t word)
 
uint64_t no_os_do_div (uint64_t *n, uint64_t base)
 
uint64_t no_os_div64_u64_rem (uint64_t dividend, uint64_t divisor, uint64_t *remainder)
 
uint64_t no_os_div_u64_rem (uint64_t dividend, uint32_t divisor, uint32_t *remainder)
 
int64_t no_os_div_s64_rem (int64_t dividend, int32_t divisor, int32_t *remainder)
 
uint64_t no_os_div_u64 (uint64_t dividend, uint32_t divisor)
 
int64_t no_os_div_s64 (int64_t dividend, int32_t divisor)
 
int32_t no_os_str_to_int32 (const char *str)
 
uint32_t no_os_str_to_uint32 (const char *str)
 
void no_os_put_unaligned_be16 (uint16_t val, uint8_t *buf)
 
uint16_t no_os_get_unaligned_be16 (uint8_t *buf)
 
void no_os_put_unaligned_le16 (uint16_t val, uint8_t *buf)
 
uint16_t no_os_get_unaligned_le16 (uint8_t *buf)
 
void no_os_put_unaligned_be24 (uint32_t val, uint8_t *buf)
 
uint32_t no_os_get_unaligned_be24 (uint8_t *buf)
 
void no_os_put_unaligned_le24 (uint32_t val, uint8_t *buf)
 
uint32_t no_os_get_unaligned_le24 (uint8_t *buf)
 
void no_os_put_unaligned_be32 (uint32_t val, uint8_t *buf)
 
uint32_t no_os_get_unaligned_be32 (uint8_t *buf)
 
void no_os_put_unaligned_le32 (uint32_t val, uint8_t *buf)
 
uint32_t no_os_get_unaligned_le32 (uint8_t *buf)
 
void no_os_put_unaligned_be64 (uint64_t val, uint8_t *buf)
 
uint64_t no_os_get_unaligned_be64 (uint8_t *buf)
 
void no_os_put_unaligned_le64 (uint64_t val, uint8_t *buf)
 
uint64_t no_os_get_unaligned_le64 (uint8_t *buf)
 
int16_t no_os_sign_extend16 (uint16_t value, int index)
 
int32_t no_os_sign_extend32 (uint32_t value, int index)
 
uint64_t no_os_mul_u32_u32 (uint32_t a, uint32_t b)
 
uint64_t no_os_mul_u64_u32_shr (uint64_t a, uint32_t mul, unsigned int shift)
 
uint64_t no_os_mul_u64_u32_div (uint64_t a, uint32_t mul, uint32_t divisor)
 
bool no_os_is_big_endian (void)
 
void no_os_memswap64 (void *buf, uint32_t bytes, uint32_t step)
 

Detailed Description

Header file of utility functions.

Author
DBogdan (drago.nosp@m.s.bo.nosp@m.gdan@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2018(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Macro Definition Documentation

◆ __no_os_weak__

#define __no_os_weak__ ( x)
Value:
__attribute__(x)

◆ no_os_align

#define no_os_align ( x,
align )
Value:
(((x) + ((typeof(x))(align) - 1)) & ~((typeof(x))(align) - 1))

◆ NO_OS_ARRAY_SIZE

#define NO_OS_ARRAY_SIZE ( x)
Value:
(sizeof(x) / sizeof((x)[0]))

◆ no_os_bcd2bin

#define no_os_bcd2bin ( x)
Value:
(((x) & 0x0f) + ((x) >> 4) * 10)

◆ no_os_bin2bcd

#define no_os_bin2bcd ( x)
Value:
((((x) / 10) << 4) + (x) % 10)

◆ NO_OS_BIT

#define NO_OS_BIT ( x)
Value:
(1 << (x))

◆ no_os_bit_swap_constant_8

#define no_os_bit_swap_constant_8 ( x)
Value:
((((x) & 0x80) >> 7) | \
(((x) & 0x40) >> 5) | \
(((x) & 0x20) >> 3) | \
(((x) & 0x10) >> 1) | \
(((x) & 0x08) << 1) | \
(((x) & 0x04) << 3) | \
(((x) & 0x02) << 5) | \
(((x) & 0x01) << 7))

◆ NO_OS_BIT_ULL

#define NO_OS_BIT_ULL ( x)
Value:
((uint64_t) 1 << (x))

◆ NO_OS_BITS_PER_LONG

#define NO_OS_BITS_PER_LONG   32

◆ no_os_bswap_constant_16

#define no_os_bswap_constant_16 ( x)
Value:
((((x) & (uint16_t)0xff00) >> 8) | \
(((x) & (uint16_t)0x00ff) << 8))

◆ no_os_bswap_constant_32

#define no_os_bswap_constant_32 ( x)
Value:
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))

◆ no_os_clamp

#define no_os_clamp ( val,
min_val,
max_val )
Value:
(no_os_max(no_os_min((val), (max_val)), (min_val)))
#define no_os_max(x, y)
Definition no_os_util.h:42
#define no_os_min(x, y)
Definition no_os_util.h:37

◆ no_os_clamp_t

#define no_os_clamp_t ( type,
val,
min_val,
max_val )
Value:
(type)no_os_clamp((type)(val), (type)(min_val), (type)(max_val))
#define no_os_clamp(val, min_val, max_val)
Definition no_os_util.h:47

◆ NO_OS_CONTAINER_OF

#define NO_OS_CONTAINER_OF ( ptr,
type,
name )
Value:
((type *)((char *)(ptr) - offsetof(type, name)))

◆ NO_OS_DIV_ROUND_CLOSEST

#define NO_OS_DIV_ROUND_CLOSEST ( x,
y )
Value:
(((x) + (y) / 2) / (y))

◆ NO_OS_DIV_ROUND_CLOSEST_ULL

#define NO_OS_DIV_ROUND_CLOSEST_ULL ( x,
y )
Value:
#define NO_OS_DIV_ROUND_CLOSEST(x, y)
Definition no_os_util.h:32

◆ NO_OS_DIV_ROUND_UP

#define NO_OS_DIV_ROUND_UP ( x,
y )
Value:
(((x) + (y) - 1) / (y))

◆ NO_OS_DIV_U64

#define NO_OS_DIV_U64 ( x,
y )
Value:
(x / y)

◆ NO_OS_GENMASK

#define NO_OS_GENMASK ( h,
l )
Value:
({ \
uint32_t t = (uint32_t)(~0UL); \
t = t << (NO_OS_BITS_PER_LONG - (h - l + 1)); \
t = t >> (NO_OS_BITS_PER_LONG - (h + 1)); \
t; \
})
#define UL(v)
Definition gmsl_common.h:44
#define NO_OS_BITS_PER_LONG
Definition no_os_util.h:58

◆ NO_OS_GENMASK_ULL

#define NO_OS_GENMASK_ULL ( h,
l )
Value:
({ \
unsigned long long t = (unsigned long long)(~0ULL); \
t = t << (64 - (h - l + 1)); \
t = t >> (64 - (h + 1)); \
t; \
})

◆ no_os_max

#define no_os_max ( x,
y )
Value:
(((x) > (y)) ? (x) : (y))

◆ no_os_max_t

#define no_os_max_t ( type,
x,
y )
Value:
(type)no_os_max((type)(x), (type)(y))

◆ no_os_min

#define no_os_min ( x,
y )
Value:
(((x) < (y)) ? (x) : (y))

◆ no_os_min_t

#define no_os_min_t ( type,
x,
y )
Value:
(type)no_os_min((type)(x), (type)(y))

◆ no_os_round_up

#define no_os_round_up ( x,
y )
Value:
(((x)+(y)-1)/(y))

◆ NO_OS_S16_MAX

#define NO_OS_S16_MAX   ((int16_t)(NO_OS_U16_MAX>>1))

◆ no_os_shift_right

#define no_os_shift_right ( x,
s )
Value:
((x) < 0 ? -(-(x) >> (s)) : (x) >> (s))

◆ no_os_swap

#define no_os_swap ( x,
y )
Value:
{typeof(x) _tmp_ = (x); (x) = (y); (y) = _tmp_;}

◆ NO_OS_U16_MAX

#define NO_OS_U16_MAX   ((uint16_t)~0U)

◆ NO_OS_UNUSED_PARAM

#define NO_OS_UNUSED_PARAM ( x)
Value:
((void)x)

Function Documentation

◆ no_os_div64_u64_rem()

uint64_t no_os_div64_u64_rem ( uint64_t dividend,
uint64_t divisor,
uint64_t * remainder )

◆ no_os_div_s64()

int64_t no_os_div_s64 ( int64_t dividend,
int32_t divisor )

◆ no_os_div_s64_rem()

int64_t no_os_div_s64_rem ( int64_t dividend,
int32_t divisor,
int32_t * remainder )

◆ no_os_div_u64()

uint64_t no_os_div_u64 ( uint64_t dividend,
uint32_t divisor )

◆ no_os_div_u64_rem()

uint64_t no_os_div_u64_rem ( uint64_t dividend,
uint32_t divisor,
uint32_t * remainder )

◆ no_os_do_div()

uint64_t no_os_do_div ( uint64_t * n,
uint64_t base )

◆ no_os_field_get()

uint32_t no_os_field_get ( uint32_t mask,
uint32_t word )

◆ no_os_field_max()

uint32_t no_os_field_max ( uint32_t mask)

◆ no_os_field_max_u64()

uint64_t no_os_field_max_u64 ( uint64_t mask)

◆ no_os_field_prep()

uint32_t no_os_field_prep ( uint32_t mask,
uint32_t val )

◆ no_os_field_prep_u64()

uint64_t no_os_field_prep_u64 ( uint64_t mask,
uint64_t val )

◆ no_os_find_closest()

uint32_t no_os_find_closest ( int32_t val,
const int32_t * array,
uint32_t size )

◆ no_os_find_first_set_bit()

uint32_t no_os_find_first_set_bit ( uint32_t word)

◆ no_os_find_first_set_bit_u64()

uint64_t no_os_find_first_set_bit_u64 ( uint64_t word)

◆ no_os_find_last_set_bit()

uint32_t no_os_find_last_set_bit ( uint32_t word)

◆ no_os_find_last_set_bit_u64()

uint64_t no_os_find_last_set_bit_u64 ( uint64_t word)

◆ no_os_get_unaligned_be16()

uint16_t no_os_get_unaligned_be16 ( uint8_t * buf)

◆ no_os_get_unaligned_be24()

uint32_t no_os_get_unaligned_be24 ( uint8_t * buf)

◆ no_os_get_unaligned_be32()

uint32_t no_os_get_unaligned_be32 ( uint8_t * buf)

◆ no_os_get_unaligned_be64()

uint64_t no_os_get_unaligned_be64 ( uint8_t * buf)

◆ no_os_get_unaligned_le16()

uint16_t no_os_get_unaligned_le16 ( uint8_t * buf)

◆ no_os_get_unaligned_le24()

uint32_t no_os_get_unaligned_le24 ( uint8_t * buf)

◆ no_os_get_unaligned_le32()

uint32_t no_os_get_unaligned_le32 ( uint8_t * buf)

◆ no_os_get_unaligned_le64()

uint64_t no_os_get_unaligned_le64 ( uint8_t * buf)

◆ no_os_greatest_common_divisor()

uint32_t no_os_greatest_common_divisor ( uint32_t a,
uint32_t b )

◆ no_os_greatest_common_divisor_u64()

uint64_t no_os_greatest_common_divisor_u64 ( uint64_t a,
uint64_t b )

◆ no_os_hweight16()

unsigned int no_os_hweight16 ( uint16_t word)

◆ no_os_hweight32()

unsigned int no_os_hweight32 ( uint32_t word)

◆ no_os_hweight8()

unsigned int no_os_hweight8 ( uint8_t word)

◆ no_os_is_big_endian()

bool no_os_is_big_endian ( void )

◆ no_os_log_base_2()

int32_t no_os_log_base_2 ( uint32_t x)

◆ no_os_lowest_common_multiple()

uint32_t no_os_lowest_common_multiple ( uint32_t a,
uint32_t b )

◆ no_os_memswap64()

void no_os_memswap64 ( void * buf,
uint32_t bytes,
uint32_t step )

◆ no_os_mul_u32_u32()

uint64_t no_os_mul_u32_u32 ( uint32_t a,
uint32_t b )

◆ no_os_mul_u64_u32_div()

uint64_t no_os_mul_u64_u32_div ( uint64_t a,
uint32_t mul,
uint32_t divisor )

◆ no_os_mul_u64_u32_shr()

uint64_t no_os_mul_u64_u32_shr ( uint64_t a,
uint32_t mul,
unsigned int shift )

◆ no_os_put_unaligned_be16()

void no_os_put_unaligned_be16 ( uint16_t val,
uint8_t * buf )

◆ no_os_put_unaligned_be24()

void no_os_put_unaligned_be24 ( uint32_t val,
uint8_t * buf )

◆ no_os_put_unaligned_be32()

void no_os_put_unaligned_be32 ( uint32_t val,
uint8_t * buf )

◆ no_os_put_unaligned_be64()

void no_os_put_unaligned_be64 ( uint64_t val,
uint8_t * buf )

◆ no_os_put_unaligned_le16()

void no_os_put_unaligned_le16 ( uint16_t val,
uint8_t * buf )

◆ no_os_put_unaligned_le24()

void no_os_put_unaligned_le24 ( uint32_t val,
uint8_t * buf )

◆ no_os_put_unaligned_le32()

void no_os_put_unaligned_le32 ( uint32_t val,
uint8_t * buf )

◆ no_os_put_unaligned_le64()

void no_os_put_unaligned_le64 ( uint64_t val,
uint8_t * buf )

◆ no_os_rational_best_approximation()

void no_os_rational_best_approximation ( uint32_t given_numerator,
uint32_t given_denominator,
uint32_t max_numerator,
uint32_t max_denominator,
uint32_t * best_numerator,
uint32_t * best_denominator )

◆ no_os_rational_best_approximation_u64()

void no_os_rational_best_approximation_u64 ( uint64_t given_numerator,
uint64_t given_denominator,
uint64_t max_numerator,
uint64_t max_denominator,
uint64_t * best_numerator,
uint64_t * best_denominator )

◆ no_os_sign_extend16()

int16_t no_os_sign_extend16 ( uint16_t value,
int index )

◆ no_os_sign_extend32()

int32_t no_os_sign_extend32 ( uint32_t value,
int index )

◆ no_os_str_to_int32()

int32_t no_os_str_to_int32 ( const char * str)

◆ no_os_str_to_uint32()

uint32_t no_os_str_to_uint32 ( const char * str)

◆ no_os_test_bit()

int no_os_test_bit ( int pos,
const volatile void * addr )
inline