COMMON - Common Utilities

Description

General purpose utilities and cross-compiler support.

This SDK supports the following compilers/IDEs:

  • Simplicity Studio
  • IAR Embedded Workbench
  • Keil µVision 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.

Macros

#define SL_CEILING (n, i)   ((((n) + (i) - 1U) / (i)) * (i))
Round n up to closest interval of i.
#define SL_FLOOR (n, i)   ((n / i) * i)
Round n down to closest interval of i.
#define STRINGIZE (X)   #X
Stringify X.
#define SL_MIN (a, b)   __extension__({ __typeof__(a)_a = (a); __typeof__(b)_b = (b); _a < _b ? _a : _b; })
A macro for getting the minimum value.
#define SL_MAX (a, b)   __extension__({ __typeof__(a)_a = (a); __typeof__(b)_b = (b); _a > _b ? _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)   __attribute__ ((aligned(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)   __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

Function Documentation

SL_CTZ()

uint32_t SL_CTZ ( uint32_t value )
inline

Count trailing number of zeros.

Use CLZ instruction if available.

Parameters
[in] value Data value to check for number of trailing zero bits.
Returns
A number of trailing zeros in value.

SL_RBIT()

uint32_t SL_RBIT ( uint32_t value )
inline

Reverse the bits.

Use the RBIT instruction if available, else process.

Parameters
[in] value Data value to reverse.
Returns
A reversed value.

SL_RBIT16()

uint16_t SL_RBIT16 ( uint16_t value )
inline

Reverse the bits.

Use the RBIT instruction if available, else process.

Parameters
[in] value 16-bit data value to reverse.
Returns
A 16-bit reversed value.

SL_RBIT8()

uint8_t SL_RBIT8 ( uint8_t value )
inline

Reverse the bits.

Use the RBIT instruction if available, else process.

Parameters
[in] value 8-bit data value to reverse.
Returns
A 8-bit reversed value.

SL_Log2ToDiv()

uint32_t SL_Log2ToDiv ( uint32_t log2 )
inline

Convert logarithm of 2 to division factor.

Parameters
[in] log2 Logarithm of 2.
Returns
Dividend.

Macro Definition Documentation

SL_CEILING

#define SL_CEILING ( n,
i
) ((((n) + (i) - 1U) / (i)) * (i))

Round n up to closest interval of i.

SL_FLOOR

#define SL_FLOOR ( n,
i
) ((n / i) * i)

Round n down to closest interval of i.

STRINGIZE

#define STRINGIZE ( X ) #X

Stringify X.

SL_MIN

#define SL_MIN ( a,
b
) __extension__({ __typeof__(a)_a = (a); __typeof__(b)_b = (b); _a < _b ? _a : _b; })

A macro for getting the minimum value.

No side-effects, a and b are evaluated one time only.

SL_MAX

#define SL_MAX ( a,
b
) __extension__({ __typeof__(a)_a = (a); __typeof__(b)_b = (b); _a > _b ? _a : _b; })

A macro for getting the maximum value.

No side-effects, a and b are evaluated one time only.

SL_ATTRIBUTE_PACKED

#define SL_ATTRIBUTE_PACKED   __attribute__ ((packed))

A GCC style macro for handling packed structures.

SL_PACK_START

#define SL_PACK_START ( x )

A macro for handling packed structures.


Use this macro before the structure definition.
X denotes the maximum alignment of structure members. X is not supported with GCC. GCC always uses 1 byte maximum alignment.

SL_PACK_END

#define SL_PACK_END ( )

A macro for handling packed structures.


Use this macro after the structure definition.
With GCC, add SL_ATTRIBUTE_PACKED after the closing curly braces of the structure definition.

SL_ATTRIBUTE_ALIGN

#define SL_ATTRIBUTE_ALIGN ( X ) __attribute__ ((aligned(X)))

GCC style macro for aligning a variable.

SL_ALIGN

#define SL_ALIGN ( X )

A macro for aligning a variable.


Use this macro before the variable definition.
X denotes the storage alignment value in bytes.
To be GCC-compatible, use SL_ATTRIBUTE_ALIGN(X) before the semicolon on normal variables. Use SL_ATTRIBUTE_ALIGN(X) before the opening curly brace on structure variables.

SL_WEAK

#define SL_WEAK   __attribute__ ((weak))

A macro for defining a weak symbol.

SL_NORETURN

#define SL_NORETURN   __attribute__ ((noreturn))

A macro for handling non-returning functions.

SL_ATTRIBUTE_SECTION

#define SL_ATTRIBUTE_SECTION ( X ) __attribute__ ((section(X)))

A macro for placing a variable in a section.


Use this macro after the variable definition, before the equal sign or a semicolon.
X denotes the section to place the variable in.

SL_FALLTHROUGH

#define SL_FALLTHROUGH

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

SL_IGNORE_TYPE_LIMIT_BEGIN

#define SL_IGNORE_TYPE_LIMIT_BEGIN

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