Utilities

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

group LWGSM_UTILS

Utilities.

Defines

LWGSM_ASSERT(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 lwgsmr_t enumeration

Parameters
  • c[in] Condition to test

LWGSM_MEM_ALIGN(x)

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

Parameters
  • x[in] Input value to align

Returns

Input value aligned to specific number of bytes

LWGSM_MIN(x, y)

Get minimal value between x and y inputs.

Parameters
  • x[in] First input to test

  • y[in] Second input to test

Returns

Minimal value between x and y parameters

LWGSM_MAX(x, y)

Get maximal value between x and y inputs.

Parameters
  • x[in] First input to test

  • y[in] Second input to test

Returns

Maximal value between x and y parameters

LWGSM_ARRAYSIZE(x)

Get size of statically declared array.

Parameters
  • x[in] Input array

Returns

Number of array elements

LWGSM_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
  • x[in] Variable which is not used

LWGSM_U32(x)

Get input value casted to unsigned 32-bit value.

Parameters
  • x[in] Input value

LWGSM_U16(x)

Get input value casted to unsigned 16-bit value.

Parameters
  • x[in] Input value

LWGSM_U8(x)

Get input value casted to unsigned 8-bit value.

Parameters
  • x[in] Input value

LWGSM_I32(x)

Get input value casted to signed 32-bit value.

Parameters
  • x[in] Input value

LWGSM_I16(x)

Get input value casted to signed 16-bit value.

Parameters
  • x[in] Input value

LWGSM_I8(x)

Get input value casted to signed 8-bit value.

Parameters
  • x[in] Input value

LWGSM_SZ(x)

Get input value casted to size_t value.

Parameters
  • x[in] Input value

lwgsm_u32_to_str(num, out)

Convert unsigned 32-bit number to string.

Parameters
  • num[in] Number to convert

  • out[out] Output variable to save string

Returns

Pointer to output variable

lwgsm_u32_to_hex_str(num, out, w)

Convert unsigned 32-bit number to HEX string.

Parameters
  • num[in] Number to convert

  • out[out] Output variable to save string

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

Returns

Pointer to output variable

lwgsm_i32_to_str(num, out)

Convert signed 32-bit number to string.

Parameters
  • num[in] Number to convert

  • out[out] Output variable to save string

Returns

Pointer to output variable

lwgsm_u16_to_str(num, out)

Convert unsigned 16-bit number to string.

Parameters
  • num[in] Number to convert

  • out[out] Output variable to save string

Returns

Pointer to output variable

lwgsm_u16_to_hex_str(num, out, w)

Convert unsigned 16-bit number to HEX string.

Parameters
  • num[in] Number to convert

  • out[out] Output variable to save string

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

Returns

Pointer to output variable

lwgsm_i16_to_str(num, out)

Convert signed 16-bit number to string.

Parameters
  • num[in] Number to convert

  • out[out] Output variable to save string

Returns

Pointer to output variable

lwgsm_u8_to_str(num, out)

Convert unsigned 8-bit number to string.

Parameters
  • num[in] Number to convert

  • out[out] Output variable to save string

Returns

Pointer to output variable

lwgsm_u8_to_hex_str(num, out, w)

Convert unsigned 16-bit number to HEX string.

Parameters
  • num[in] Number to convert

  • out[out] Output variable to save string

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

Returns

Pointer to output variable

lwgsm_i8_to_str(num, out)

Convert signed 8-bit number to string.

Parameters
  • num[in] Number to convert

  • out[out] Output variable to save string

Returns

Pointer to output variable

Functions

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

Convert unsigned 32-bit number to string.

Parameters
  • num[in] Number to convert

  • out[out] Output variable to save string

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

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

Returns

Pointer to output variable

char *lwgsm_i32_to_gen_str(int32_t num, char *out)

Convert signed 32-bit number to string.

Parameters
  • num[in] Number to convert

  • out[out] Output variable to save string

Returns

Pointer to output variable