COMMON - Common Utilities#

General purpose utilities and cross-compiler support.

This SDK supports the following compilers/IDEs:

  • Simplicity Studio

  • IAR Embedded Workbench

  • Keil uVision IDE

  • Plain armgcc

Certain compiler features such as alignment is implemented differently in the tools. Therefore, macros such as SL_ALIGN are provided to enable compiler independent code.

Note

  • RAM code macros are implemented in RAMFUNC. Cross-compiler RAM code support needs extended documentation and it is therefore implemented as a separate module.

Functions#

uint32_t
SL_CTZ(uint32_t value)

Count trailing number of zeros.

uint32_t
SL_RBIT(uint32_t value)

Reverse the bits.

uint16_t
SL_RBIT16(uint16_t value)

Reverse the bits.

uint8_t
SL_RBIT8(uint8_t value)

Reverse the bits.

uint32_t
SL_Log2ToDiv(uint32_t log2)

Convert logarithm of 2 to division factor.

uint32_t
SL_POPCOUNT32(uint32_t bitfield)

Count the number of bits that are set to 1 in a 32-bit bitfield.

Macros#

#define
_CONCAT_2 (first, second)

Macros to concatenate.

#define
SL_CONCAT_PASTER_2 (first, second)

sl concat paster 2.

#define
_CONCAT_3 (first, second, third)
#define
SL_CONCAT_PASTER_3 (first, second, third)

sl concat paster 3.

#define
_CONCAT_4 (first, second, third, fourth)
#define
SL_CONCAT_PASTER_4 (first, second, third, fourth)

sl concat paster 4.

#define
SL_CEILING (n, i)

Round n up to closest interval of i.

#define
SL_FLOOR (n, i)

Round n down to closest interval of i.

#define
STRINGIZE (X)

Stringify X.

#define
SL_BRANCH_LIKELY (x)

Macros for giving the compiler hints about the likelihood of a branch.

#define
SL_BRANCH_UNLIKELY (x)
#define
SL_MIN (a, b)

A macro for getting the minimum value.

#define
SL_MAX (a, b)

A macro for getting the maximum value.

#define
SL_ATTRIBUTE_PACKED __attribute__ ((packed))

A GCC style macro for handling packed structures.

#define
SL_PACK_START (x)

A macro for handling packed structures.

#define
SL_PACK_END ()

A macro for handling packed structures.

#define
SL_ATTRIBUTE_ALIGN (X)

GCC style macro for aligning a variable.

#define
SL_ALIGN (X)

A macro for aligning a variable.

#define
SL_WEAK __attribute__ ((weak))

A macro for defining a weak symbol.

#define
SL_NORETURN __attribute__ ((noreturn))

A macro for handling non-returning functions.

#define
SL_ATTRIBUTE_SECTION (X)

A macro for placing a variable in a section.

#define
SL_FALLTHROUGH

A macro for notifying the compiler of an intended switch case fallthrough.

#define
SL_IGNORE_TYPE_LIMIT_BEGIN

A macro for notifying the compiler to ignore type limit check.

#define
SL_IGNORE_TYPE_LIMIT_END

A MACRO to notify the compiler, limit END.

Function Documentation#

SL_CTZ#

uint32_t SL_CTZ (uint32_t value)

Count trailing number of zeros.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]value

Data value to check for number of trailing zero bits.

Use CLZ instruction if available.

Returns

  • A number of trailing zeros in value.


SL_RBIT#

uint32_t SL_RBIT (uint32_t value)

Reverse the bits.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]value

Data value to reverse.

Use the RBIT instruction if available, else process.

Returns

  • A reversed value.


SL_RBIT16#

uint16_t SL_RBIT16 (uint16_t value)

Reverse the bits.

Parameters
TypeDirectionArgument NameDescription
uint16_t[in]value

16-bit data value to reverse.

Use the RBIT instruction if available, else process.

Returns

  • A 16-bit reversed value.


SL_RBIT8#

uint8_t SL_RBIT8 (uint8_t value)

Reverse the bits.

Parameters
TypeDirectionArgument NameDescription
uint8_t[in]value

8-bit data value to reverse.

Use the RBIT instruction if available, else process.

Returns

  • A 8-bit reversed value.


SL_Log2ToDiv#

uint32_t SL_Log2ToDiv (uint32_t log2)

Convert logarithm of 2 to division factor.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]log2

Logarithm of 2.

Returns

  • Dividend.


SL_POPCOUNT32#

uint32_t SL_POPCOUNT32 (uint32_t bitfield)

Count the number of bits that are set to 1 in a 32-bit bitfield.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]bitfield

32-bit bitfield.

Returns

  • The number of bits that are set to 1 in the bitfield.