Utilities

Utility functions for various cases. These function are used across entire middleware and can also be used by application.

group ESP_UTILS

Utilities.

Defines

ESP_ASSERT(msg, c)

Assert an input parameter if in valid range.

Note

Since this is a macro, it may only be used on a functions where return status is of type espr_t enumeration

Parameters
  • [in] msg: message to print to debug if test fails

  • [in] c: Condition to test

ESP_MEM_ALIGN(x)

Align x value to specific number of bytes, provided by ESP_CFG_MEM_ALIGNMENT configuration.

Return

Input value aligned to specific number of bytes

Parameters
  • [in] x: Input value to align

ESP_MIN(x, y)

Get minimal value between x and y inputs.

Return

Minimal value between x and y parameters

Parameters
  • [in] x: First input to test

  • [in] y: Second input to test

ESP_MAX(x, y)

Get maximal value between x and y inputs.

Return

Maximal value between x and y parameters

Parameters
  • [in] x: First input to test

  • [in] y: Second input to test

ESP_ARRAYSIZE(x)

Get size of statically declared array.

Return

Number of array elements

Parameters
  • [in] x: Input array

ESP_UNUSED(x)

Unused argument in a function call.

Note

Use this on all parameters in a function which are not used to prevent compiler warnings complaining about “unused variables”

Parameters
  • [in] x: Variable which is not used

ESP_U32(x)

Get input value casted to unsigned 32-bit value.

Parameters
  • [in] x: Input value

ESP_U16(x)

Get input value casted to unsigned 16-bit value.

Parameters
  • [in] x: Input value

ESP_U8(x)

Get input value casted to unsigned 8-bit value.

Parameters
  • [in] x: Input value

ESP_I32(x)

Get input value casted to signed 32-bit value.

Parameters
  • [in] x: Input value

ESP_I16(x)

Get input value casted to signed 16-bit value.

Parameters
  • [in] x: Input value

ESP_I8(x)

Get input value casted to signed 8-bit value.

Parameters
  • [in] x: Input value

ESP_SZ(x)

Get input value casted to size_t value.

Parameters
  • [in] x: Input value

esp_u32_to_str(num, out)

Convert unsigned 32-bit number to string.

Return

Pointer to output variable

Parameters
  • [in] num: Number to convert

  • [out] out: Output variable to save string

esp_u32_to_hex_str(num, out, w)

Convert unsigned 32-bit number to HEX string.

Return

Pointer to output variable

Parameters
  • [in] num: Number to convert

  • [out] out: Output variable to save string

  • [in] w: Width of output string. When number is shorter than width, leading 0 characters will apply

esp_i32_to_str(num, out)

Convert signed 32-bit number to string.

Return

Pointer to output variable

Parameters
  • [in] num: Number to convert

  • [out] out: Output variable to save string

esp_u16_to_str(num, out)

Convert unsigned 16-bit number to string.

Return

Pointer to output variable

Parameters
  • [in] num: Number to convert

  • [out] out: Output variable to save string

esp_u16_to_hex_str(num, out, w)

Convert unsigned 16-bit number to HEX string.

Return

Pointer to output variable

Parameters
  • [in] num: Number to convert

  • [out] out: Output variable to save string

  • [in] w: Width of output string. When number is shorter than width, leading 0 characters will apply.

esp_i16_to_str(num, out)

Convert signed 16-bit number to string.

Return

Pointer to output variable

Parameters
  • [in] num: Number to convert

  • [out] out: Output variable to save string

esp_u8_to_str(num, out)

Convert unsigned 8-bit number to string.

Return

Pointer to output variable

Parameters
  • [in] num: Number to convert

  • [out] out: Output variable to save string

esp_u8_to_hex_str(num, out, w)

Convert unsigned 16-bit number to HEX string.

Return

Pointer to output variable

Parameters
  • [in] num: Number to convert

  • [out] out: Output variable to save string

  • [in] w: Width of output string. When number is shorter than width, leading 0 characters will apply.

esp_i8_to_str(num, out)

Convert signed 8-bit number to string.

Return

Pointer to output variable

Parameters
  • [in] num: Number to convert

  • [out] out: Output variable to save string

Functions

char *esp_u32_to_gen_str(uint32_t num, char *out, uint8_t is_hex, uint8_t padding)

Convert unsigned 32-bit number to string.

Return

Pointer to output variable

Parameters
  • [in] num: Number to convert

  • [out] out: Output variable to save string

  • [in] is_hex: Set to 1 to output hex, 0 otherwise

  • [in] width: Width of output string. When number is shorter than width, leading 0 characters will apply. This parameter is valid only when formatting hex numbers

char *esp_i32_to_gen_str(int32_t num, char *out)

Convert signed 32-bit number to string.

Return

Pointer to output variable

Parameters
  • [in] num: Number to convert

  • [out] out: Output variable to save string