libosmocore 1.10.0.57-8972
Osmocom core library
|
Osmocom bit level support code. More...
Files | |
file | bits.h |
Osmocom bit level support code. | |
file | bits.c |
Macros | |
#define | OSMO_BIN_SPEC "%d%d%d%d%d%d%d%d" |
#define | OSMO_BIN_PRINT(byte) |
#define | OSMO_BIT_SPEC "%c%c%c%c%c%c%c%c" |
#define | OSMO_BIT_PRINT_EX(byte, ch) |
#define | OSMO_BIT_PRINT(byte) OSMO_BIT_PRINT_EX(byte, '1') |
Typedefs | |
typedef int8_t | sbit_t |
soft bit with value (-127...127), as commonly used in communications receivers such as [viterbi] decoders More... | |
typedef uint8_t | ubit_t |
unpacked bit (0 or 1): 1 bit per byte More... | |
typedef uint8_t | pbit_t |
packed bits (8 bits in a byte). More... | |
Enumerations | |
enum | osmo_br_mode { OSMO_BR_BITS_IN_DWORD = 31 , OSMO_BR_BYTES_IN_DWORD = 24 , OSMO_BR_BITS_IN_BYTE = 7 , OSMO_BR_WORD_SWAP = 16 } |
bit-reversal mode for osmo_bit_reversal() More... | |
Functions | |
static unsigned int | osmo_pbit_bytesize (unsigned int num_bits) |
determine how many bytes we would need for num_bits packed bits More... | |
int | osmo_ubit2pbit (pbit_t *out, const ubit_t *in, unsigned int num_bits) |
convert unpacked bits to packed bits, return length in bytes More... | |
int | osmo_pbit2ubit (ubit_t *out, const pbit_t *in, unsigned int num_bits) |
convert packed bits to unpacked bits, return length in bytes More... | |
void | osmo_nibble_shift_right (uint8_t *out, const uint8_t *in, unsigned int num_nibbles) |
Shift unaligned input to octet-aligned output. More... | |
void | osmo_nibble_shift_left_unal (uint8_t *out, const uint8_t *in, unsigned int num_nibbles) |
Shift unaligned input to octet-aligned output. More... | |
void | osmo_ubit2sbit (sbit_t *out, const ubit_t *in, unsigned int num_bits) |
convert unpacked bits to soft bits More... | |
void | osmo_sbit2ubit (ubit_t *out, const sbit_t *in, unsigned int num_bits) |
convert soft bits to unpacked bits More... | |
int | osmo_ubit2pbit_ext (pbit_t *out, unsigned int out_ofs, const ubit_t *in, unsigned int in_ofs, unsigned int num_bits, int lsb_mode) |
convert unpacked bits to packed bits (extended options) More... | |
int | osmo_pbit2ubit_ext (ubit_t *out, unsigned int out_ofs, const pbit_t *in, unsigned int in_ofs, unsigned int num_bits, int lsb_mode) |
convert packed bits to unpacked bits (extended options) More... | |
uint32_t | osmo_bit_reversal (uint32_t x, enum osmo_br_mode k) |
generalized bit reversal function More... | |
uint32_t | osmo_revbytebits_32 (uint32_t x) |
reverse the bit-order in each byte of a dword More... | |
uint32_t | osmo_revbytebits_8 (uint8_t x) |
reverse the bit order in a byte More... | |
void | osmo_revbytebits_buf (uint8_t *buf, int len) |
reverse bit-order of each byte in a buffer More... | |
static uint16_t | osmo_rol16 (uint16_t in, unsigned shift) |
left circular shift More... | |
Variables | |
static const uint8_t | flip_table [256] |
Osmocom bit level support code.
This module implements the notion of different bit-fields, such as
#define OSMO_BIN_PRINT | ( | byte | ) |
#define OSMO_BIN_SPEC "%d%d%d%d%d%d%d%d" |
#define OSMO_BIT_PRINT | ( | byte | ) | OSMO_BIT_PRINT_EX(byte, '1') |
#define OSMO_BIT_PRINT_EX | ( | byte, | |
ch | |||
) |
typedef uint8_t pbit_t |
typedef int8_t sbit_t |
soft bit with value (-127...127), as commonly used in communications receivers such as [viterbi] decoders
typedef uint8_t ubit_t |
unpacked bit (0 or 1): 1 bit per byte
enum osmo_br_mode |
bit-reversal mode for osmo_bit_reversal()
uint32_t osmo_bit_reversal | ( | uint32_t | x, |
enum osmo_br_mode | k | ||
) |
generalized bit reversal function
[in] | x | the 32bit value to be reversed |
[in] | k | the type of reversal requested |
This function reverses the bit order within a 32bit word. Depending on "k", it either reverses all bits in a 32bit dword, or the bytes in the dword, or the bits in each byte of a dword, or simply swaps the two 16bit words in a dword. See Chapter 7 "Hackers Delight"
void osmo_nibble_shift_left_unal | ( | uint8_t * | out, |
const uint8_t * | in, | ||
unsigned int | num_nibbles | ||
) |
Shift unaligned input to octet-aligned output.
[out] | out | output buffer, octet-aligned |
[in] | in | input buffer, unaligned |
[in] | num_nibbles | number of nibbles |
void osmo_nibble_shift_right | ( | uint8_t * | out, |
const uint8_t * | in, | ||
unsigned int | num_nibbles | ||
) |
Shift unaligned input to octet-aligned output.
[out] | out | output buffer, unaligned |
[in] | in | input buffer, octet-aligned |
[in] | num_nibbles | number of nibbles |
convert packed bits to unpacked bits, return length in bytes
[out] | out | output buffer of unpacked bits |
[in] | in | input buffer of packed bits |
[in] | num_bits | number of bits |
int osmo_pbit2ubit_ext | ( | ubit_t * | out, |
unsigned int | out_ofs, | ||
const pbit_t * | in, | ||
unsigned int | in_ofs, | ||
unsigned int | num_bits, | ||
int | lsb_mode | ||
) |
convert packed bits to unpacked bits (extended options)
[out] | out | output buffer of unpacked bits |
[in] | out_ofs | offset into output buffer |
[in] | in | input buffer of packed bits |
[in] | in_ofs | offset into input buffer |
[in] | num_bits | number of bits |
[in] | lsb_mode | Encode bits in LSB order instead of MSB |
|
inlinestatic |
determine how many bytes we would need for num_bits packed bits
[in] | num_bits | Number of packed bits |
uint32_t osmo_revbytebits_32 | ( | uint32_t | x | ) |
reverse the bit-order in each byte of a dword
[in] | x | 32bit input value |
See Chapter 7 "Hackers Delight"
References x.
uint32_t osmo_revbytebits_8 | ( | uint8_t | x | ) |
reverse the bit order in a byte
[in] | x | 8bit input value |
References flip_table, and x.
Referenced by osmo_isdnhdlc_decode(), and osmo_isdnhdlc_encode().
void osmo_revbytebits_buf | ( | uint8_t * | buf, |
int | len | ||
) |
reverse bit-order of each byte in a buffer
[in] | buf | buffer containing bytes to be bit-reversed |
[in] | len | length of buffer in bytes |
This function reverses the bits in each byte of the buffer
References flip_table, and len().
|
inlinestatic |
left circular shift
[in] | in | The 16 bit unsigned integer to be rotated |
[in] | shift | Number of bits to shift in to, [0;16] bits |
convert soft bits to unpacked bits
[out] | out | output buffer of unpacked bits |
[in] | in | input buffer of soft bits |
[in] | num_bits | number of bits |
convert unpacked bits to packed bits, return length in bytes
[out] | out | output buffer of packed bits |
[in] | in | input buffer of unpacked bits |
[in] | num_bits | number of bits |
int osmo_ubit2pbit_ext | ( | pbit_t * | out, |
unsigned int | out_ofs, | ||
const ubit_t * | in, | ||
unsigned int | in_ofs, | ||
unsigned int | num_bits, | ||
int | lsb_mode | ||
) |
convert unpacked bits to packed bits (extended options)
[out] | out | output buffer of packed bits |
[in] | out_ofs | offset into output buffer |
[in] | in | input buffer of unpacked bits |
[in] | in_ofs | offset into input buffer |
[in] | num_bits | number of bits |
[in] | lsb_mode | Encode bits in LSB order instead of MSB |
convert unpacked bits to soft bits
[out] | out | output buffer of soft bits |
[in] | in | input buffer of unpacked bits |
[in] | num_bits | number of bits |
|
static |
Referenced by osmo_revbytebits_8(), and osmo_revbytebits_buf().