OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
Helper functions
Collaboration diagram for Helper functions:

Namespaces

namespace  qOS::bits
 Helper Bit-manipulation interfaces.
 

Functions

template<typename T , typename W >
void qOS::bits::multipleSet (T &dst, W xBits)
 Uses the bitwise OR operator to set bits into dst.
 
template<typename T , typename W >
void qOS::bits::multipleClear (T &dst, W xBits)
 Uses the bitwise AND operator to clear bits into dst.
 
template<typename T >
void qOS::bits::singleSet (T &dst, const size_t xBit)
 Uses the bitwise OR operator to set a single bit into dst.
 
template<typename T >
void qOS::bits::singleClear (T &dst, const size_t xBit)
 Uses the bitwise AND operator to clear a single bit into dst.
 
template<typename T >
bool qOS::bits::singleRead (T dst, const size_t xBit)
 Uses the bitwise AND operator to read the value of a single bit from dst.
 
template<typename T >
void qOS::bits::singleToggle (T &dst, const size_t xBit)
 Uses the bitwise XOR operator to toggle the value of a single bit from dst.
 
template<typename T >
void qOS::bits::singleWrite (T &dst, const size_t xBit, const bool value)
 Write the boolean value in a single bit of the dst variable.
 
template<typename T , typename W >
bool qOS::bits::multipleGet (T reg, W xBits)
 Read multiple bits by applying the mask given by xBits to the dst variable.
 
template<typename T , size_t n>
constexpr size_t qOS::arraySize (const T(&arr)[n]) noexcept
 Calculates the size of an array. This function takes a reference to an array and calculates its size. For a one-dimensional array, the size is simply the number of elements. For a multi-dimensional array, the size is the product of the sizes of all dimensions.
 
template<typename T >
qOS::clip (T x, const T Min, const T Max)
 Ensures that x is between the limits set by Min and Max.
 
template<typename T >
qOS::clipUpper (T x, const T Max)
 Ensures that x is bellow the limits set by Max.
 
template<typename T >
qOS::clipLower (T x, const T Min)
 Ensures that x is above the value set by Min.
 
template<typename T >
qOS::isBetween (T x, const T Low, const T High)
 Check if the value of x is within the limits defined by Low and High.
 
uint8_t qOS::byteNibbleHigh (uint8_t x)
 Read the high-nibble from x.
 
uint8_t qOS::byteNibbleLow (uint8_t x)
 Read the low-nibble from x.
 
uint8_t qOS::byteMergeNibbles (uint8_t h, uint8_t l)
 Merges two nibbles to form one byte.
 
uint16_t qOS::wordByteHigh (uint16_t x)
 Read the high-byte from x.
 
uint16_t qOS::wordByteLow (uint16_t x)
 Read the low-byte from x.
 
uint16_t qOS::wordMergeBytes (uint16_t h, uint16_t l)
 Merges two bytes to form one Word.
 
uint32_t qOS::dWordWordHigh (uint32_t x)
 Read the high-word from x.
 
uint32_t qOS::dWordWordLow (uint32_t x)
 Read the low-word from x.
 
uint32_t qOS::dwordMergeWords (uint32_t h, uint32_t l)
 Merges two words to form one DWord.
 

Detailed Description

Function Documentation

◆ arraySize()

template<typename T , size_t n>
size_t qOS::arraySize ( const T(&) arr[n])
constexprnoexcept

Calculates the size of an array. This function takes a reference to an array and calculates its size. For a one-dimensional array, the size is simply the number of elements. For a multi-dimensional array, the size is the product of the sizes of all dimensions.

Warning
This function only works for raw-arrays. It is not intended for boost or STL arrays and vectors
Template Parameters
TThe type of the array elements.
nThe size of the first dimension (for a multi-dimensional array).
Parameters
arrThe array whose size to calculate.
Returns
The size of the array.

◆ byteMergeNibbles()

uint8_t qOS::byteMergeNibbles ( uint8_t h,
uint8_t l )
inline

Merges two nibbles to form one byte.

Parameters
[in]hThe high nibble
[in]lThe low nibble
Returns
The value of the resulting byte

◆ byteNibbleHigh()

uint8_t qOS::byteNibbleHigh ( uint8_t x)
inline

Read the high-nibble from x.

Parameters
[in]xThe input variable
Returns
The value of the high nibble taken from x

◆ byteNibbleLow()

uint8_t qOS::byteNibbleLow ( uint8_t x)
inline

Read the low-nibble from x.

Parameters
[in]xThe input variable
Returns
The value of the low nibble taken from x

◆ clip()

template<typename T >
T qOS::clip ( T x,
const T Min,
const T Max )
inline

Ensures that x is between the limits set by Min and Max.

Note
If Min is greater than Max the result is undefined.
Parameters
[in]xThe value to clamp
[in]MinThe minimum value allowed.
[in]MaxThe maximum value allowed.
Returns
The value of x clamped to the range between Min and Max.

◆ clipLower()

template<typename T >
T qOS::clipLower ( T x,
const T Min )
inline

Ensures that x is above the value set by Min.

Parameters
[in]xThe value to clamp
[in]MinThe minimum value allowed.
Returns
The value of x clamped to the value of Min.

◆ clipUpper()

template<typename T >
T qOS::clipUpper ( T x,
const T Max )
inline

Ensures that x is bellow the limits set by Max.

Parameters
[in]xThe value to clamp
[in]MaxThe maximum value allowed.
Returns
The value of x clamped to the value of Max.

◆ dwordMergeWords()

uint32_t qOS::dwordMergeWords ( uint32_t h,
uint32_t l )
inline

Merges two words to form one DWord.

Parameters
[in]hThe high byte
[in]lThe low byte
Returns
The value of the resulting word

◆ dWordWordHigh()

uint32_t qOS::dWordWordHigh ( uint32_t x)
inline

Read the high-word from x.

Parameters
[in]xThe input variable
Returns
The value of the high word taken from x

◆ dWordWordLow()

uint32_t qOS::dWordWordLow ( uint32_t x)
inline

Read the low-word from x.

Parameters
[in]xThe input variable
Returns
The value of the low word taken from x

◆ isBetween()

template<typename T >
T qOS::isBetween ( T x,
const T Low,
const T High )
inline

Check if the value of x is within the limits defined by Low and High.

Parameters
[in]xThe value to check
[in]LowThe minimum value allowed.
[in]HighThe maximum value allowed.
Returns
true if the x is between the defined range. Otherwise returns false.

◆ multipleClear()

template<typename T , typename W >
void qOS::bits::multipleClear ( T & dst,
W xBits )
inline

Uses the bitwise AND operator to clear bits into dst.

Parameters
[in]dstThe variable where the operation will be applied
[in]xBitsIndicates which bits are to be cleared

◆ multipleGet()

template<typename T , typename W >
bool qOS::bits::multipleGet ( T reg,
W xBits )
inline

Read multiple bits by applying the mask given by xBits to the dst variable.

Parameters
[in]regThe variable where the operation will be applied
[in]xBitsThe bit mask
Returns
The dst variable masked with xBits.

◆ multipleSet()

template<typename T , typename W >
void qOS::bits::multipleSet ( T & dst,
W xBits )
inline

Uses the bitwise OR operator to set bits into dst.

Parameters
[in]dstThe variable where the operation will be applied
[in]xBitsIndicates which bits are to be set

◆ singleClear()

template<typename T >
void qOS::bits::singleClear ( T & dst,
const size_t xBit )
inline

Uses the bitwise AND operator to clear a single bit into dst.

Parameters
[in]dstThe variable where the operation will be applied
[in]xBitThe bit-index

◆ singleRead()

template<typename T >
bool qOS::bits::singleRead ( T dst,
const size_t xBit )
inline

Uses the bitwise AND operator to read the value of a single bit from dst.

Parameters
[in]dstThe variable where the operation will be applied
[in]xBitThe bit-index
Returns
The value of the requested bit.

◆ singleSet()

template<typename T >
void qOS::bits::singleSet ( T & dst,
const size_t xBit )
inline

Uses the bitwise OR operator to set a single bit into dst.

Parameters
[in]dstThe variable where the operation will be applied
[in]xBitThe bit-index

◆ singleToggle()

template<typename T >
void qOS::bits::singleToggle ( T & dst,
const size_t xBit )
inline

Uses the bitwise XOR operator to toggle the value of a single bit from dst.

Parameters
[in]dstThe variable where the operation will be applied
[in]xBitThe bit-index

◆ singleWrite()

template<typename T >
void qOS::bits::singleWrite ( T & dst,
const size_t xBit,
const bool value )
inline

Write the boolean value in a single bit of the dst variable.

Parameters
[in]dstThe variable where the operation will be applied
[in]xBitThe bit-index
[in]valueThe boolean value to write

◆ wordByteHigh()

uint16_t qOS::wordByteHigh ( uint16_t x)
inline

Read the high-byte from x.

Parameters
[in]xThe input variable
Returns
The value of the high byte taken from x

◆ wordByteLow()

uint16_t qOS::wordByteLow ( uint16_t x)
inline

Read the low-byte from x.

Parameters
[in]xThe input variable
Returns
The value of the low byte taken from x

◆ wordMergeBytes()

uint16_t qOS::wordMergeBytes ( uint16_t h,
uint16_t l )
inline

Merges two bytes to form one Word.

Parameters
[in]hThe high byte
[in]lThe low byte
Returns
The value of the resulting word