# include/util.h File Reference

Misc utility functions and definitions. More...

`#include <types.h>`

Include dependency graph for util.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Defines
#define | xstr(s) str(s)
| Stringify the result after expansion of a macro argument.
#define | str(s) #s
| Stringify a macro argument without expansion.
#define | ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0]))
| Get the number of elements in array a.
#define | container_of(ptr, type, member) ((type *)((unsigned long)(ptr) - offsetof(type, member)))
| Get the containing object.
#define | div_ceil(a, b) (((a) + (b) - 1) / (b))
| Calculate using integer arithmetic.
## Functions
static int | isdigit (int c)
| Determine whether or not the character c is a digit.
static int | iscntrl (int c)
| Determine whether or not the character c is a control character.
static int | isspace (int c)
| Determine whether or not the character c is a space.
int | ilog2_undefined (void)
static int | ilog2 (unsigned int x)
| Calculate the base-2 logarithm of a number rounded down to the nearest integer.
static bool | is_power_of_two (unsigned long x)
| Test if a given value is a power of two.
static unsigned long | round_down (unsigned long x, unsigned int order)
| Round down to the nearest power of two boundary.
static unsigned long | round_up (unsigned long x, unsigned int order)
| Round up to the nearest power of two boundary.
static unsigned long | word_align (unsigned long x)
| Round up to the nearest word-aligned boundary.

## Detailed Description

Misc utility functions and definitions.

- Compiler: IAR EWAVR32 and GNU GCC for AVR32
- Supported devices: All devices
- AppNote:

Author:
  Atmel Corporation: http://www.atmel.com
  Support and FAQ: http://support.atmel.no/

Definition in file util.h.

## Define Documentation

#define ARRAY_LEN | ( | a |  | ) | (sizeof(a) / sizeof((a)[0]))

Get the number of elements in array a.

Definition at line 59 of file util.h.

Referenced by softirq_priv_do_pending(), and softirq_set_handler().

#define container_of | ( | ptr,
|  | type,
|  | member |  | ) | ((type *)((unsigned long)(ptr) - offsetof(type, member)))

Get the containing object.

Parameters:

  | ptr | Pointer to the contained object.
  | type | Type of the containing object.
  | member | Member name of the contained object inside the containing object.

Returns:
  Pointer to the containing object.

Definition at line 111 of file util.h.

Referenced by pdca_channel_of(), and sdmmc_card_get_slot().

#define div_ceil | ( | a,
|  | b |  | ) | (((a) + (b) - 1) / (b))

Calculate using integer arithmetic.

Parameters:

  | a | An integer
  | b | Another integer

Returns:
  (a / b) rounded up to the nearest integer.

Definition at line 237 of file util.h.

Referenced by ns2cyc(), and udelay().

#define str | ( | s |  | ) | #s

Stringify a macro argument without expansion.

Definition at line 54 of file util.h.

#define xstr | ( | s |  | ) | str(s)

Stringify the result after expansion of a macro argument.

Definition at line 49 of file util.h.

## Function Documentation

static int ilog2 | ( | unsigned int | x | ) | `[inline, static]`

Calculate the base-2 logarithm of a number rounded down to the nearest integer.

Parameters:

  | x | A 32-bit value

Returns:
  The base-2 logarithm of x, or -1 if x is 0.

Definition at line 128 of file util.h.

References count_leading_zeroes, ilog2_undefined(), and is_constant.

Referenced by usbb_udc_configure_ep(), and watchdog_set_timeout().

Here is the call graph for this function:

int ilog2_undefined | ( | void |  | ) |

For internal use only.

Undefined function. Will cause a link failure if ilog2() is called with an invalid constant value.

Referenced by ilog2().

static bool is_power_of_two | ( | unsigned long | x | ) | `[inline, static]`

Test if a given value is a power of two.

Parameters:

  | x | The value to test

Returns:
  true if x is a power of two, false otherwise

Definition at line 174 of file util.h.

static int iscntrl | ( | int | c | ) | `[inline, static]`

Determine whether or not the character c is a control character.

Parameters:

  | c | The character to consider.

Return values:

  | 0 | The character c is not a control character.
  | 1 | The character c is a control character.

Definition at line 81 of file util.h.

static int isdigit | ( | int | c | ) | `[inline, static]`

Determine whether or not the character c is a digit.

Parameters:

  | c | The character to consider.

Return values:

  | 0 | The character c is not a digit.
  | 1 | The character c is a digit.

Definition at line 68 of file util.h.

Referenced by console_vprintf().

static int isspace | ( | int | c | ) | `[inline, static]`

Determine whether or not the character c is a space.

Note:
  This implementation is very limited in that it doesn't consider a bunch of control characters that probably should be interpreted as space.

Parameters:

  | c | The character to consider.

Return values:

  | 0 | The character c is not a space.
  | 1 | The character c is a space.

Definition at line 97 of file util.h.

static unsigned long round_down | ( | unsigned long | x,
|  | unsigned int | order |
| ) |  |  | `[inline, static]`

Round down to the nearest power of two boundary.

Parameters:

  | x | A positive integer
  | order | log2 of the required boundary.

Returns:
  x rounded down to the nearest multiple of (1 << order)

Definition at line 186 of file util.h.

Referenced by physmem_alloc(), and round_up().

static unsigned long round_up | ( | unsigned long | x,
|  | unsigned int | order |
| ) |  |  | `[inline, static]`

Round up to the nearest power of two boundary.

Parameters:

  | x | A positive integer
  | order | log2 of the required boundary.

Returns:
  x rounded up to the next multiple of (1 << order)

Definition at line 198 of file util.h.

References round_down().

Referenced by dma_pool_init_coherent_physmem(), mem_pool_init(), mem_pool_init_physmem(), physmem_alloc_low(), and word_align().

Here is the call graph for this function:

static unsigned long word_align | ( | unsigned long | x | ) | `[inline, static]`

Round up to the nearest word-aligned boundary.

Parameters:

  | x | Address or offset to be word-aligned

Returns:
  The smallest number y where y >= x and y & 3 == 0.

Definition at line 209 of file util.h.

References round_up().

Here is the call graph for this function: