Appiko
Macros | Enumerations
Common utilities

Common helpers used in C programs. More...

Macros

#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define MAX(a, b)   ((a) < (b) ? (b) : (a))
 
#define CONCAT_2(p1, p2)   CONCAT_2_(p1, p2)
 Concatenates or joins two parameters. More...
 
#define CONCAT_2_(p1, p2)   p1##p2
 
#define CONCAT_3(p1, p2, p3)   CONCAT_3_(p1, p2, p3)
 Concatenates or joins three parameters. More...
 
#define CONCAT_3_(p1, p2, p3)   p1##p2##p3
 
#define ARRAY_SIZE(arr)   (sizeof(arr) / sizeof((arr)[0]))
 
#define ROUNDED_DIV(A, B)   (((A) + ((B) / 2)) / (B))
 Rounded integer division where the result is the integer closest to the answer instead of flooring the result. More...
 
#define CEIL_DIV(A, B)   (((A) + (B) - 1) / (B))
 When the result of a division is not an integer, the result is rounded up to the next integer. More...
 
#define IS_POWER_OF_TWO(A)   ( ((A) != 0) && ((((A) - 1) & (A)) == 0) )
 Checks if an integer is a power of two. More...
 
#define MSEC_TO_UNITS(TIME, RESOLUTION)   (((TIME) * 1000) / (RESOLUTION))
 Macro for converting ms to ticks. More...
 
#define SET_BIT_VAR(VAR, BIT_NO)   (VAR | (1 << BIT_NO))
 Macro to set particular bit in a given variable without affecting other bits. More...
 
#define CLR_BIT_VAR(VAR, BIT_NO)   (VAR & ~(1 << BIT_NO))
 Macro to clear particular bit in a given variable without affecting other bits. More...
 

Enumerations

enum  { UNIT_0_625_MS = 625, UNIT_1_25_MS = 1250, UNIT_10_MS = 10000 }
 

Detailed Description

Macro Definition Documentation

◆ ARRAY_SIZE

#define ARRAY_SIZE (   arr)    (sizeof(arr) / sizeof((arr)[0]))

The number of elements inside a array

Definition at line 70 of file common_util.h.

◆ CEIL_DIV

#define CEIL_DIV (   A,
 
)    (((A) + (B) - 1) / (B))
Parameters
[in]ANumerator for the division.
[in]BDenominator for the division.
Returns
Rounded up result of dividing A by B.

Definition at line 90 of file common_util.h.

◆ CLR_BIT_VAR

#define CLR_BIT_VAR (   VAR,
  BIT_NO 
)    (VAR & ~(1 << BIT_NO))
Parameters
[in]VARVariable from which bit is to be clear
[in]BIT_NOBit number which is be clear

Definition at line 129 of file common_util.h.

◆ CONCAT_2

#define CONCAT_2 (   p1,
  p2 
)    CONCAT_2_(p1, p2)

Two level expansion are needed to make sure that the two parameters are fully expanded before joining them together.

Parameters
p1First parameter for concatenating
p2Second parameter for concatenating
Returns
Two parameters joined together.
See also
CONCAT_3

Definition at line 48 of file common_util.h.

◆ CONCAT_2_

#define CONCAT_2_ (   p1,
  p2 
)    p1##p2

Private macro used by CONCAT_2

Definition at line 50 of file common_util.h.

◆ CONCAT_3

#define CONCAT_3 (   p1,
  p2,
  p3 
)    CONCAT_3_(p1, p2, p3)

Two level expansion are needed to make sure that the three parameters are fully expanded before joining them together.

Parameters
p1First parameter for concatenating
p2Second parameter for concatenating
p3Third parameter for concatenating
Returns
Three parameters joined together.
See also
CONCAT_2

Definition at line 65 of file common_util.h.

◆ CONCAT_3_

#define CONCAT_3_ (   p1,
  p2,
  p3 
)    p1##p2##p3

Private macro used by CONCAT_3

Definition at line 67 of file common_util.h.

◆ IS_POWER_OF_TWO

#define IS_POWER_OF_TWO (   A)    ( ((A) != 0) && ((((A) - 1) & (A)) == 0) )
Parameters
[in]AThe number to be checked.
Returns
Bool representing if the value is a power of 2

Definition at line 99 of file common_util.h.

◆ MAX

#define MAX (   a,
 
)    ((a) < (b) ? (b) : (a))

The maximum of the two 32-bit arguments

Definition at line 34 of file common_util.h.

◆ MIN

#define MIN (   a,
 
)    ((a) < (b) ? (a) : (b))

The minimum of the two 32-bit arguments

Definition at line 32 of file common_util.h.

◆ MSEC_TO_UNITS

#define MSEC_TO_UNITS (   TIME,
  RESOLUTION 
)    (((TIME) * 1000) / (RESOLUTION))
Parameters
[in]TIMENumber of ms to convert.
[in]RESOLUTIONUnit to be converted to in [us/ticks].

Definition at line 113 of file common_util.h.

◆ ROUNDED_DIV

#define ROUNDED_DIV (   A,
 
)    (((A) + ((B) / 2)) / (B))
Parameters
[in]ANumerator for the division.
[in]BDenominator for the division.
Returns
Rounded integer from dividing A by B.

Definition at line 80 of file common_util.h.

◆ SET_BIT_VAR

#define SET_BIT_VAR (   VAR,
  BIT_NO 
)    (VAR | (1 << BIT_NO))
Parameters
[in]VARVariable from which bit is to be set
[in]BIT_NOBit number which is be set

Definition at line 121 of file common_util.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
UNIT_0_625_MS 

Number of us in 0.625 ms.

UNIT_1_25_MS 

Number of us in 1.25 ms.

UNIT_10_MS 

Number of us in 10 ms.

Definition at line 101 of file common_util.h.