Enda Kilgarriff / platform_drivers
Embed: (wiki syntax)

« Back to documentation index

util.h File Reference

util.h File Reference

Implementation of utility functions. More...

Go to the source code of this file.

Functions

uint32_t find_first_set_bit (uint32_t word)
 Find first set bit in word.
uint32_t find_last_set_bit (uint32_t word)
 Find last set bit in word.
uint32_t find_closest (int32_t val, const int32_t *array, uint32_t size)
 Locate the closest element in an array.
uint32_t field_prep (uint32_t mask, uint32_t val)
 Shift the value and apply the specified mask.
uint32_t field_get (uint32_t mask, uint32_t word)
 Get a field specified by a mask from a word.
int32_t log_base_2 (uint32_t x)
 Log base 2 of the given number.
uint32_t greatest_common_divisor (uint32_t a, uint32_t b)
 Find greatest common divisor of the given two numbers.
void 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)
 Calculate best rational approximation for a given fraction.
uint32_t hweight8 (uint32_t word)
 Calculate the number of set bits.
uint64_t do_div (uint64_t *n, uint64_t base)
 Calculate the quotient and the remainder of an integer division.
uint64_t div64_u64_rem (uint64_t dividend, uint64_t divisor, uint64_t *remainder)
 Unsigned 64bit divide with 64bit divisor and remainder.
uint64_t div_u64_rem (uint64_t dividend, uint32_t divisor, uint32_t *remainder)
 Unsigned 64bit divide with 32bit divisor with remainder.
uint64_t div_u64 (uint64_t dividend, uint32_t divisor)
 Unsigned 64bit divide with 32bit divisor.
int32_t str_to_int32 (const char *str)
 Converts from string to int32_t.
uint32_t srt_to_uint32 (const char *str)
 Converts from string to uint32_t.

Detailed Description

Implementation of utility functions.

Author:
DBogdan (dragos.bogdan@analog.com)

Copyright 2018, 2020(c) Analog Devices, Inc.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  • The use of this software may or may not infringe the patent rights of one or more patent holders. This license does not release you from the requirement that you obtain separate licenses from these patent holders to use this software.
  • Use of the software either in source or binary form, must be run on or directly connected to an Analog Devices Inc. component.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file util.h.


Function Documentation

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

Unsigned 64bit divide with 64bit divisor and remainder.

Definition at line 207 of file util.c.

uint64_t div_u64 ( uint64_t  dividend,
uint32_t  divisor 
)

Unsigned 64bit divide with 32bit divisor.

Definition at line 227 of file util.c.

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

Unsigned 64bit divide with 32bit divisor with remainder.

Definition at line 217 of file util.c.

uint64_t do_div ( uint64_t *  n,
uint64_t  base 
)

Calculate the quotient and the remainder of an integer division.

Definition at line 193 of file util.c.

uint32_t field_get ( uint32_t  mask,
uint32_t  word 
)

Get a field specified by a mask from a word.

Definition at line 118 of file util.c.

uint32_t field_prep ( uint32_t  mask,
uint32_t  val 
)

Shift the value and apply the specified mask.

Definition at line 110 of file util.c.

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

Locate the closest element in an array.

Definition at line 89 of file util.c.

uint32_t find_first_set_bit ( uint32_t  word )

Find first set bit in word.

Definition at line 54 of file util.c.

uint32_t find_last_set_bit ( uint32_t  word )

Find last set bit in word.

Definition at line 71 of file util.c.

uint32_t greatest_common_divisor ( uint32_t  a,
uint32_t  b 
)

Find greatest common divisor of the given two numbers.

Definition at line 134 of file util.c.

uint32_t hweight8 ( uint32_t  word )

Calculate the number of set bits.

Definition at line 177 of file util.c.

int32_t log_base_2 ( uint32_t  x )

Log base 2 of the given number.

Definition at line 126 of file util.c.

void 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 
)

Calculate best rational approximation for a given fraction.

Definition at line 153 of file util.c.

uint32_t srt_to_uint32 ( const char *  str )

Converts from string to uint32_t.

Parameters:
*str
Returns:
uint32_t

Definition at line 255 of file util.c.

int32_t str_to_int32 ( const char *  str )

Converts from string to int32_t.

Parameters:
*str
Returns:
int32_t

Definition at line 239 of file util.c.