STM32G0 MCAL 0.0.1
Tiny MCAL for educational purpose.
|
This file contains the Bitfield functions for fixed point for 16 bit registers. More...
#include "Std_Types.h"
Go to the source code of this file.
Macros | |
#define | MAX_VALUE 32767 |
#define | MIN_VALUE -32768 |
#define | MAX_VALUE_USIGNED 0xFFFF |
Functions | |
static void | Bfx_SetBit_u16u8 (uint16 *Data, uint8 BitPn) |
Set a single bit in Data pointer | |
static void | Bfx_ClrBit_u16u8 (uint16 *Data, uint8 BitPn) |
Clears a single bit in Data pointer | |
static boolean | Bfx_GetBit_u16u8_u8 (uint16 Data, uint8 BitPn) |
Obtain one bit especified | |
static void | Bfx_SetBits_u16u8u8u8 (uint16 *Data, uint8 BitStartPn, uint8 BitLn, uint8 Status) |
Modifies consecutive bits acording to status | |
static uint8 | Bfx_GetBits_u16u8u8_u16 (uint16 Data, uint8 BitStartPn, uint8 BitLn) |
Obtains consecutive bits from an unsigned integer | |
static void | Bfx_SetBitMask_u16u16 (uint16 *Data, uint16 Mask) |
Using a mask to set bits | |
static void | Bfx_ClrBitMask_u16u16 (uint16 *Data, uint16 Mask) |
Using a mask to clear bits | |
static boolean | Bfx_TstBitMask_u16u16_u8 (uint16 Data, uint16 Mask) |
Compare a mask with a seccion of an unsigned integer | |
static boolean | Bfx_TstBitLnMask_u16u16_u8 (uint16 Data, uint16 Mask) |
Compare any bit of a mask with a seccion of an unsigned integer | |
static boolean | Bfx_TstParityEven_u16_u8 (uint16 Data) |
Determines if an unsigned integer has even parity | |
static void | Bfx_ToggleBits_u16 (uint16 *Data) |
Changes the value of every bit of an unsigned integer | |
static void | Bfx_ToggleBitMask_u16u16 (uint16 *Data, uint16 Mask) |
Using a mask to toggle bits | |
static void | Bfx_ShiftBitRt_u16u8 (uint16 *Data, uint8 ShiftCnt) |
Shifts a unsigned integer to the right acourding to ShiftCnt | |
static void | Bfx_ShiftBitLt_u16u8 (uint16 *Data, uint8 ShiftCnt) |
Shifts a unsigned integer to the left acourding to ShiftCnt | |
static void | Bfx_RotBitRt_u16u8 (uint16 *Data, uint8 ShiftCnt) |
Rotates a unsigned integer to the right acourding to ShiftCnt | |
static void | Bfx_RotBitLt_u16u8 (uint16 *Data, uint8 ShiftCnt) |
Rotates a unsigned integer to the left acourding to ShiftCnt | |
static void | Bfx_CopyBit_u16u8u16u8 (uint16 *DestinationData, uint8 DestinationPosition, uint16 SourceData, uint8 SourcePosition) |
Copies a bit from an integer to another | |
static void | Bfx_PutBits_u16u8u8u16 (uint16 *Data, uint8 BitStartPn, uint8 BitLn, uint16 Pattern) |
Takes a pattern and puts it in an unsigned integer | |
static void | Bfx_PutBitsMask_u16u16u16 (uint16 *Data, uint16 Pattern, uint16 Mask) |
Takes a pattern and a mask and puts it in an unsigned integer | |
static void | Bfx_PutBit_u16u8u8 (uint16 *Data, uint8 BitPn, boolean Status) |
Sets the bit of an unsigned integer according to Status | |
static uint8 | Bfx_CountLeadingOnes_u16 (uint16 Data) |
Counts consecutive ones | |
static uint8 | Bfx_CountLeadingZeros_u16 (uint16 Data) |
Counts consecutive zeros | |
static uint8 | Bfx_CountLeadingSigns_s16 (sint16 Data) |
Counts leading signs | |
static sint16 | Bfx_ShiftBitSat_s16s8_s16 (sint8 ShiftCnt, sint16 Data) |
Arithmetic shift with saturation | |
static uint16 | Bfx_ShiftBitSat_u16s8_u16 (sint8 ShiftCnt, uint16 Data) |
Arithmetic shift with saturation | |
This file contains the Bitfield functions for fixed point for 16 bit registers.
Bfx routines specification specifies the functionality, API and the configuration of the AUTOSAR library for BIT functionality dedicated to fixed-point arithmetic routines. All bit functions are re-entrant and can handle several simultaneous requests from the application.
Clears a single bit in Data pointer
This function shall clear the logical status of the input data to ’0’ at the requested bit position.
Data | Unsigned integer to modify |
BitPn | Number of bit to modify |
Using a mask to clear bits
This function shall clear the logical status to ’0’ for the input data for all the bit positions as per the mask.
Data | Unsigned integer to modify |
Mask | Mask that indicates the bits to clear |
|
inlinestatic |
Copies a bit from an integer to another
This function shall copy a bit from source data from bit position to destination data at bit position.
DestinationData | Unsigned integer receptor |
DestinationPosition | Destination bit |
SourceData | Unsigned integer source |
SourcePosition | Source bit |
Counts consecutive ones
Count the number of consecutive ones in Data starting with the most significant bit and return the result.
Data | Unsigned integer to check |
Counter |
Counts leading signs
Count the number of consecutive bits which have the same value as most significant bit in Data, starting with bit at position msb minus one. Put the result in Data. It is the number of leading sign bits minus one, giving the number of redundant sign bits in Data.
Data | Signed integer to count from |
Counter |
Counts consecutive zeros
Count the number of consecutive zeros in Data starting with the most significant bit and return the result.
Data | Unsigned integer to check |
Counter |
Obtain one bit especified
This function shall return the logical status of the input data for the requested bit position.
Data | Unsigned integer containing the bit |
BitPn | Number of bit to obtain |
Result |
Obtains consecutive bits from an unsigned integer
This function shall return the Bits of the input data starting from ’BitStartPn’ for the length of ’BitLn’.
Data | Unsigned integer with the bits |
BitStartPn | Bit that indicates the start of the bits to obtain |
BitLn | Number of bits to obtain |
Result |
Sets the bit of an unsigned integer according to Status
This function shall update the bit specified by BitPn of input data as ’1’ or ’0’ as per ’Status’ value.
Data | Unsigned integer to modify |
BitPn | Pin to modify |
Status | boolean value to set |
|
inlinestatic |
Takes a pattern and puts it in an unsigned integer
This function shall put bits as mentioned in Pattern to the input Data from the specified bit position.
Data | Unsigned integer to modify |
BitStartPn | LSB to start |
BitLn | Lenght of the chain of bits |
Pattern | Pattern to partially copy |
Takes a pattern and a mask and puts it in an unsigned integer
This function shall put all bits defined in Pattern and for which the corresponding Mask bit is set to 1 in the input Data.
Data | Unsigned integer to modify |
Pattern | Pattern to partially copy |
Mask | Mask that indicates the bits to copy |
Rotates a unsigned integer to the left acourding to ShiftCnt
This function shall rotate data to the right by ShiftCnt. The least significant bit is rotated to the most significant bit location for every single bit shift cycle.
Data | Unsigned integer to modify |
ShiftCnt | Number of shifts to perform |
Rotates a unsigned integer to the right acourding to ShiftCnt
This function shall rotate data to the right by ShiftCnt. The least significant bit is rotated to the most significant bit location for every single bit shift cycle.
Data | Unsigned integer to modify |
ShiftCnt | Number of shifts to perform |
Set a single bit in Data pointer
This function shall set the logical status of input data as ’1’ at the requested bit position.
Data | Unsigned integer to modify |
BitPn | Number of bit to modify |
Using a mask to set bits
This function shall set the data to logical status ’1’ as per the corresponding Mask bits when set to value 1 and remaining bits will retain their original values.
Data | Unsigned integer to modify |
Mask | Mask that indicates the bits to set |
|
inlinestatic |
Modifies consecutive bits acording to status
This function shall set the input data as ’1’ or ’0’ as per ’Status’ value starting from ’BitStartPn’ for the length ’BitLn’.
Data | Unsigned integer to modify |
BitStartPn | Bit that indicates the start of the bits to modify |
BitLn | Number of bits to modify |
Status | Value that the bits will take |
Shifts a unsigned integer to the left acourding to ShiftCnt
This function shall shift data to the left by ShiftCnt. The least significant bit (right-most bit) is replaced by a ’0’ bit and the most significant bit (left-most bit) is discarded for every single bit shift cycle.
Data | Unsigned integer to modify |
ShiftCnt | Number of shifts to perform |
Shifts a unsigned integer to the right acourding to ShiftCnt
This function shall shift data to the right by ShiftCnt. The most significant bit (left-most bit) is replaced by a ’0’ bit and the least significant bit (right-most bit) is discarded for every single bit shift cycle.
Data | Unsigned integer to modify |
ShiftCnt | Number of shifts to perform |
Arithmetic shift with saturation
If the shift count is greater than or equal to zero, then shift the value in Data by the amount specified by shift count to left. For this function, arithmetic shift is performed. The vacated bits are filled with zeros and the result is saturated if its sign bit differs from the sign bits that are shifted out. If the shift count is less than zero, right-shift the value in Data by the absolute value of the shift count. The vacated bits are filled with the sign-bit (the most significant bit) and bits shifted out are discarded.
ShiftCnt | Shift count |
Data | Signed integer to check |
Data |
< Maximun data value
< Minimun data value
Arithmetic shift with saturation
If the shift count is greater than or equal to zero, then shift the value in Data by the amount specified by shift count to left. For this function a logical shift is performed. In this case the result is saturated, if the leading one bit is shifted out. If the shift count is less than zero, right-shift the value in Data by the absolute value of the shift count. The vacated bits are filled with the sign-bit (the most significant bit) and bits shifted out are discarded.
ShiftCnt | Shift count |
Data | Unsigned integer to check |
Data |
< Maximum unsigned data value
Using a mask to toggle bits
This function toggles the bits of data when the corresponding bit of the mask is enabled and set to 1.
Data | Unsigned integer to modify |
Mask | Mask that indicates the bits to toggle |
|
inlinestatic |
Changes the value of every bit of an unsigned integer
This function toggles all the bits of data (1’s Complement Data).
Data | Unsigned integer to modify |
Compare any bit of a mask with a seccion of an unsigned integer
This function makes a test on the input data and if at least one bit is set as per the mask, then the function shall return TRUE, otherwise it shall return FALSE.
Data | Unsigned integer to compare |
Mask | Mask used to compare |
Result |
Compare a mask with a seccion of an unsigned integer
This function shall return TRUE, if all bits defined in Mask value are set in the input Data value. In all other cases this function shall return FALSE.
Data | Unsigned integer to compare |
Mask | Mask used to compare |
Result |
Determines if an unsigned integer has even parity
This function tests the number of bits set to 1. If this number is even, it shall return TRUE, otherwise it returns FALSE.
Data | Unsigned integer to compare |
Result |