mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-12-15 04:30:33 +00:00
Unify use of stdint names
This commit is contained in:
parent
62a7e54359
commit
11829e5883
@ -34,7 +34,7 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static const u8 BITN[16] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
|
||||
static const uint8_t BITN[16] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
|
||||
|
||||
/** \defgroup bits Bit Utils
|
||||
* Bit field packing, unpacking and utility functions.
|
||||
@ -49,7 +49,7 @@ static const u8 BITN[16] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
|
||||
* \return 1 if there are an odd number of bits set.
|
||||
* 0 if there are an even number of bits set.
|
||||
*/
|
||||
u8 parity(u32 x)
|
||||
uint8_t parity(uint32_t x)
|
||||
{
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
@ -68,10 +68,10 @@ u8 parity(u32 x)
|
||||
* \param len Length of bit field in bits.
|
||||
* \return Bit field as an unsigned value.
|
||||
*/
|
||||
u32 getbitu(const u8 *buff, u32 pos, u8 len)
|
||||
uint32_t getbitu(const uint8_t *buff, uint32_t pos, uint8_t len)
|
||||
{
|
||||
u32 bits = 0;
|
||||
u32 i = 0;
|
||||
uint32_t bits = 0;
|
||||
uint32_t i = 0;
|
||||
for (i = pos; i < pos + len; i++)
|
||||
{
|
||||
bits = (bits << 1) +
|
||||
@ -92,14 +92,14 @@ u32 getbitu(const u8 *buff, u32 pos, u8 len)
|
||||
* \param len Length of bit field in bits.
|
||||
* \return Bit field as a signed value.
|
||||
*/
|
||||
s32 getbits(const u8 *buff, u32 pos, u8 len)
|
||||
int32_t getbits(const uint8_t *buff, uint32_t pos, uint8_t len)
|
||||
{
|
||||
s32 bits = (s32)getbitu(buff, pos, len);
|
||||
int32_t bits = (int32_t)getbitu(buff, pos, len);
|
||||
|
||||
/* Sign extend, taken from:
|
||||
* http://graphics.stanford.edu/~seander/bithacks.html#VariableSignExtend
|
||||
*/
|
||||
s32 m = 1u << (len - 1);
|
||||
int32_t m = 1u << (len - 1);
|
||||
return (bits ^ m) - m;
|
||||
}
|
||||
|
||||
@ -112,15 +112,15 @@ s32 getbits(const u8 *buff, u32 pos, u8 len)
|
||||
* \param len Length of bit field in bits.
|
||||
* \param data Unsigned integer to be packed into bit field.
|
||||
*/
|
||||
void setbitu(u8 *buff, u32 pos, u32 len, u32 data)
|
||||
void setbitu(uint8_t *buff, uint32_t pos, uint32_t len, uint32_t data)
|
||||
{
|
||||
u32 mask = 1u << (len - 1);
|
||||
uint32_t mask = 1u << (len - 1);
|
||||
|
||||
if (len <= 0 || 32 < len)
|
||||
{
|
||||
return;
|
||||
}
|
||||
u32 i = 0;
|
||||
uint32_t i = 0;
|
||||
for (i = pos; i < pos + len; i++, mask >>= 1)
|
||||
{
|
||||
if (data & mask)
|
||||
@ -143,9 +143,9 @@ void setbitu(u8 *buff, u32 pos, u32 len, u32 data)
|
||||
* \param len Length of bit field in bits.
|
||||
* \param data Signed integer to be packed into bit field.
|
||||
*/
|
||||
void setbits(u8 *buff, u32 pos, u32 len, s32 data)
|
||||
void setbits(uint8_t *buff, uint32_t pos, uint32_t len, int32_t data)
|
||||
{
|
||||
setbitu(buff, pos, len, (u32)data);
|
||||
setbitu(buff, pos, len, (uint32_t)data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,7 +158,7 @@ void setbits(u8 *buff, u32 pos, u32 len, s32 data)
|
||||
*
|
||||
* \return None
|
||||
*/
|
||||
void bitshl(void *buf, u32 size, u32 shift)
|
||||
void bitshl(void *buf, uint32_t size, uint32_t shift)
|
||||
{
|
||||
if (shift > size * CHAR_BIT)
|
||||
{
|
||||
@ -170,9 +170,9 @@ void bitshl(void *buf, u32 size, u32 shift)
|
||||
unsigned char *dst = buf; /* Destination byte. */
|
||||
const unsigned char *src = dst + shift / CHAR_BIT; /* First source byte, possibly incomplete. */
|
||||
|
||||
u32 copy_bits = size * CHAR_BIT - shift; /* Number of bits to move */
|
||||
u32 byte_shift = copy_bits % CHAR_BIT; /* Shift of data */
|
||||
u32 full_bytes = copy_bits / CHAR_BIT; /* Number of bytes to move */
|
||||
uint32_t copy_bits = size * CHAR_BIT - shift; /* Number of bits to move */
|
||||
uint32_t byte_shift = copy_bits % CHAR_BIT; /* Shift of data */
|
||||
uint32_t full_bytes = copy_bits / CHAR_BIT; /* Number of bytes to move */
|
||||
|
||||
if (0 == byte_shift)
|
||||
{
|
||||
@ -184,8 +184,8 @@ void bitshl(void *buf, u32 size, u32 shift)
|
||||
else
|
||||
{
|
||||
/* Create an accumulator: it will hold a value of two consecutive bytes */
|
||||
u32 acc = *src++;
|
||||
u32 i = 0;
|
||||
uint32_t acc = *src++;
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < full_bytes; ++i)
|
||||
{
|
||||
acc = (acc << CHAR_BIT) | *src++;
|
||||
@ -215,22 +215,22 @@ void bitshl(void *buf, u32 size, u32 shift)
|
||||
* \todo This function can be optimized for copying aligned data and using
|
||||
* proper native type like long.
|
||||
*/
|
||||
void bitcopy(void *dst, u32 dst_index, const void *src, u32 src_index,
|
||||
u32 count)
|
||||
void bitcopy(void *dst, uint32_t dst_index, const void *src, uint32_t src_index,
|
||||
uint32_t count)
|
||||
{
|
||||
u32 limit1 = count / 32;
|
||||
u32 limit2 = count % 32;
|
||||
u32 idx = 0;
|
||||
uint32_t limit1 = count / 32;
|
||||
uint32_t limit2 = count % 32;
|
||||
uint32_t idx = 0;
|
||||
for (idx = 0; idx < limit1; ++idx)
|
||||
{
|
||||
u32 tmp = getbitu(src, src_index, 32);
|
||||
uint32_t tmp = getbitu(src, src_index, 32);
|
||||
setbitu(dst, dst_index, 32, tmp);
|
||||
src_index += 32;
|
||||
dst_index += 32;
|
||||
}
|
||||
if (0 != limit2)
|
||||
{
|
||||
u32 tmp = getbitu(src, src_index, limit2);
|
||||
uint32_t tmp = getbitu(src, src_index, limit2);
|
||||
setbitu(dst, dst_index, limit2, tmp);
|
||||
}
|
||||
}
|
||||
@ -243,9 +243,9 @@ void bitcopy(void *dst, u32 dst_index, const void *src, u32 src_index,
|
||||
*
|
||||
* \return Number of bits set to one or zero.
|
||||
*/
|
||||
u8 count_bits_u64(u64 v, u8 bv)
|
||||
uint8_t count_bits_u64(uint64_t v, uint8_t bv)
|
||||
{
|
||||
u8 r = 0;
|
||||
uint8_t r = 0;
|
||||
int i = 0;
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
@ -262,9 +262,9 @@ u8 count_bits_u64(u64 v, u8 bv)
|
||||
*
|
||||
* \return Number of bits set to one or zero.
|
||||
*/
|
||||
u8 count_bits_u32(u32 v, u8 bv)
|
||||
uint8_t count_bits_u32(uint32_t v, uint8_t bv)
|
||||
{
|
||||
u8 r = 0;
|
||||
uint8_t r = 0;
|
||||
int i = 0;
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
@ -281,9 +281,9 @@ u8 count_bits_u32(u32 v, u8 bv)
|
||||
*
|
||||
* \return Number of bits set to one or zero.
|
||||
*/
|
||||
u8 count_bits_u16(u16 v, u8 bv)
|
||||
uint8_t count_bits_u16(uint16_t v, uint8_t bv)
|
||||
{
|
||||
u8 r = 0;
|
||||
uint8_t r = 0;
|
||||
int i = 0;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
@ -300,9 +300,9 @@ u8 count_bits_u16(u16 v, u8 bv)
|
||||
*
|
||||
* \return Number of bits set to one or zero.
|
||||
*/
|
||||
u8 count_bits_u8(u8 v, u8 bv)
|
||||
uint8_t count_bits_u8(uint8_t v, uint8_t bv)
|
||||
{
|
||||
u8 r = 0;
|
||||
uint8_t r = 0;
|
||||
int i = 0;
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
|
@ -34,17 +34,17 @@
|
||||
|
||||
#include "swift_common.h"
|
||||
|
||||
u8 parity(u32 x);
|
||||
u32 getbitu(const u8 *buff, u32 pos, u8 len);
|
||||
s32 getbits(const u8 *buff, u32 pos, u8 len);
|
||||
void setbitu(u8 *buff, u32 pos, u32 len, u32 data);
|
||||
void setbits(u8 *buff, u32 pos, u32 len, s32 data);
|
||||
void bitcopy(void *dst, u32 dst_index,
|
||||
const void *src, u32 src_index, u32 count);
|
||||
void bitshl(void *buf, u32 size, u32 shift);
|
||||
u8 count_bits_u64(u64 v, u8 bv);
|
||||
u8 count_bits_u32(u32 v, u8 bv);
|
||||
u8 count_bits_u16(u16 v, u8 bv);
|
||||
u8 count_bits_u8(u8 v, u8 bv);
|
||||
uint8_t parity(uint32_t x);
|
||||
uint32_t getbitu(const uint8_t *buff, uint32_t pos, uint8_t len);
|
||||
int32_t getbits(const uint8_t *buff, uint32_t pos, uint8_t len);
|
||||
void setbitu(uint8_t *buff, uint32_t pos, uint32_t len, uint32_t data);
|
||||
void setbits(uint8_t *buff, uint32_t pos, uint32_t len, int32_t data);
|
||||
void bitcopy(void *dst, uint32_t dst_index,
|
||||
const void *src, uint32_t src_index, uint32_t count);
|
||||
void bitshl(void *buf, uint32_t size, uint32_t shift);
|
||||
uint8_t count_bits_u64(uint64_t v, uint8_t bv);
|
||||
uint8_t count_bits_u32(uint32_t v, uint8_t bv);
|
||||
uint8_t count_bits_u16(uint16_t v, uint8_t bv);
|
||||
uint8_t count_bits_u8(uint8_t v, uint8_t bv);
|
||||
|
||||
#endif /* LIBSWIFTNAV_BITS_H */
|
||||
|
@ -56,9 +56,9 @@
|
||||
*/
|
||||
|
||||
/** GPS L2C preamble */
|
||||
const u32 GPS_CNAV_PREAMBLE1 = 0x8Bu; /* (0b10001011u) */
|
||||
const uint32_t GPS_CNAV_PREAMBLE1 = 0x8Bu; /* (0b10001011u) */
|
||||
/** Inverted GPS L2C preamble */
|
||||
const u32 GPS_CNAV_PREAMBLE2 = 0x74u; /* (0b01110100u) */
|
||||
const uint32_t GPS_CNAV_PREAMBLE2 = 0x74u; /* (0b01110100u) */
|
||||
/** GPS L2C preamble length in bits */
|
||||
#define GPS_CNAV_PREAMBLE_LENGTH (8)
|
||||
/** GPS L2C CNAV message length in bits */
|
||||
@ -81,9 +81,9 @@ const u32 GPS_CNAV_PREAMBLE2 = 0x74u; /* (0b01110100u) */
|
||||
*
|
||||
* \private
|
||||
*/
|
||||
static u32 _cnav_compute_crc(cnav_v27_part_t *part)
|
||||
static uint32_t _cnav_compute_crc(cnav_v27_part_t *part)
|
||||
{
|
||||
u32 crc = crc24q_bits(0, part->decoded, GPS_CNAV_MSG_DATA_LENGTH,
|
||||
uint32_t crc = crc24q_bits(0, part->decoded, GPS_CNAV_MSG_DATA_LENGTH,
|
||||
part->invert);
|
||||
|
||||
return crc;
|
||||
@ -100,9 +100,9 @@ static u32 _cnav_compute_crc(cnav_v27_part_t *part)
|
||||
*
|
||||
* \private
|
||||
*/
|
||||
static u32 _cnav_extract_crc(const cnav_v27_part_t *part)
|
||||
static uint32_t _cnav_extract_crc(const cnav_v27_part_t *part)
|
||||
{
|
||||
u32 crc = getbitu(part->decoded, GPS_CNAV_MSG_DATA_LENGTH,
|
||||
uint32_t crc = getbitu(part->decoded, GPS_CNAV_MSG_DATA_LENGTH,
|
||||
GPS_CNAV_MSG_CRC_LENGTH);
|
||||
if (part->invert)
|
||||
{
|
||||
@ -136,7 +136,7 @@ static void _cnav_rescan_preamble(cnav_v27_part_t *part)
|
||||
size_t j = 0;
|
||||
for (i = 1, j = part->n_decoded - GPS_CNAV_PREAMBLE_LENGTH; i < j; ++i)
|
||||
{
|
||||
u32 c = getbitu(part->decoded, i, GPS_CNAV_PREAMBLE_LENGTH);
|
||||
uint32_t c = getbitu(part->decoded, i, GPS_CNAV_PREAMBLE_LENGTH);
|
||||
if (GPS_CNAV_PREAMBLE1 == c || GPS_CNAV_PREAMBLE2 == c)
|
||||
{
|
||||
part->preamble_seen = true;
|
||||
@ -171,7 +171,7 @@ static void _cnav_rescan_preamble(cnav_v27_part_t *part)
|
||||
*
|
||||
* \private
|
||||
*/
|
||||
static void _cnav_add_symbol(cnav_v27_part_t *part, u8 ch)
|
||||
static void _cnav_add_symbol(cnav_v27_part_t *part, uint8_t ch)
|
||||
{
|
||||
part->symbols[part->n_symbols++] = ch;
|
||||
|
||||
@ -240,8 +240,8 @@ static void _cnav_add_symbol(cnav_v27_part_t *part, u8 ch)
|
||||
{
|
||||
/* We have collected 300 bits starting from message preamble. Now try
|
||||
* to compute CRC-24Q */
|
||||
u32 crc = _cnav_compute_crc(part);
|
||||
u32 crc2 = _cnav_extract_crc(part);
|
||||
uint32_t crc = _cnav_compute_crc(part);
|
||||
uint32_t crc2 = _cnav_extract_crc(part);
|
||||
|
||||
if (part->message_lock)
|
||||
{
|
||||
@ -332,7 +332,7 @@ static void _cnav_msg_invert(cnav_v27_part_t *part)
|
||||
*
|
||||
* \private
|
||||
*/
|
||||
static bool _cnav_msg_decode(cnav_v27_part_t *part, cnav_msg_t *msg, u32 *delay)
|
||||
static bool _cnav_msg_decode(cnav_v27_part_t *part, cnav_msg_t *msg, uint32_t *delay)
|
||||
{
|
||||
bool res = false;
|
||||
if (GPS_CNAV_MSG_LENGTH <= part->n_decoded)
|
||||
@ -425,9 +425,9 @@ void cnav_msg_decoder_init(cnav_msg_decoder_t *dec)
|
||||
* \retval false More data is required.
|
||||
*/
|
||||
bool cnav_msg_decoder_add_symbol(cnav_msg_decoder_t *dec,
|
||||
u8 symbol,
|
||||
uint8_t symbol,
|
||||
cnav_msg_t *msg,
|
||||
u32 *pdelay)
|
||||
uint32_t *pdelay)
|
||||
{
|
||||
_cnav_add_symbol(&dec->part1, symbol);
|
||||
_cnav_add_symbol(&dec->part2, symbol);
|
||||
|
@ -60,11 +60,11 @@
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
u8 prn; /**< SV PRN. 0..31 */
|
||||
u8 msg_id; /**< Message id. 0..31 */
|
||||
u32 tow; /**< GPS ToW in 6-second units. Multiply to 6 to get seconds. */
|
||||
uint8_t prn; /**< SV PRN. 0..31 */
|
||||
uint8_t msg_id; /**< Message id. 0..31 */
|
||||
uint32_t tow; /**< GPS ToW in 6-second units. Multiply to 6 to get seconds. */
|
||||
bool alert; /**< CNAV message alert flag */
|
||||
u8 raw_msg[GPS_L2C_V27_DECODE_BITS + GPS_L2C_V27_DELAY_BITS]; /**< RAW MSG for GNSS-SDR */
|
||||
uint8_t raw_msg[GPS_L2C_V27_DECODE_BITS + GPS_L2C_V27_DELAY_BITS]; /**< RAW MSG for GNSS-SDR */
|
||||
} cnav_msg_t;
|
||||
|
||||
/**
|
||||
@ -112,7 +112,7 @@ void cnav_msg_decoder_init(cnav_msg_decoder_t *dec);
|
||||
bool cnav_msg_decoder_add_symbol(cnav_msg_decoder_t *dec,
|
||||
unsigned char symbol,
|
||||
cnav_msg_t *msg,
|
||||
u32 *delay);
|
||||
uint32_t *delay);
|
||||
|
||||
/** \} */
|
||||
/** \} */
|
||||
|
@ -39,7 +39,7 @@
|
||||
* Cyclic redundancy checks.
|
||||
* \{ */
|
||||
|
||||
static const u32 CRC24QTAB[256] = {
|
||||
static const uint32_t CRC24QTAB[256] = {
|
||||
0x000000, 0x864CFB, 0x8AD50D, 0x0C99F6, 0x93E6E1, 0x15AA1A, 0x1933EC, 0x9F7F17,
|
||||
0xA18139, 0x27CDC2, 0x2B5434, 0xAD18CF, 0x3267D8, 0xB42B23, 0xB8B2D5, 0x3EFE2E,
|
||||
0xC54E89, 0x430272, 0x4F9B84, 0xC9D77F, 0x56A868, 0xD0E493, 0xDC7D65, 0x5A319E,
|
||||
@ -88,9 +88,9 @@ static const u32 CRC24QTAB[256] = {
|
||||
*
|
||||
* \return CRC-24Q value
|
||||
*/
|
||||
u32 crc24q(const u8 *buf, u32 len, u32 crc)
|
||||
uint32_t crc24q(const uint8_t *buf, uint32_t len, uint32_t crc)
|
||||
{
|
||||
u32 i = 0;
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
crc = ((crc << 8) & 0xFFFFFF) ^ CRC24QTAB[((crc >> 16) ^ buf[i]) & 0xff];
|
||||
@ -113,13 +113,13 @@ u32 crc24q(const u8 *buf, u32 len, u32 crc)
|
||||
*
|
||||
* \return CRC-24Q value
|
||||
*/
|
||||
u32 crc24q_bits(u32 crc, const u8 *buf, u32 n_bits, bool invert)
|
||||
uint32_t crc24q_bits(uint32_t crc, const uint8_t *buf, uint32_t n_bits, bool invert)
|
||||
{
|
||||
u16 acc = 0;
|
||||
u8 b = 0;
|
||||
u32 shift = 8 - n_bits % 8;
|
||||
uint16_t acc = 0;
|
||||
uint8_t b = 0;
|
||||
uint32_t shift = 8 - n_bits % 8;
|
||||
|
||||
u32 i = 0;
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < n_bits / 8; ++i)
|
||||
{
|
||||
acc = (acc << 8) | *buf++;
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#include "swift_common.h"
|
||||
|
||||
u32 crc24q(const u8 *buf, u32 len, u32 crc);
|
||||
u32 crc24q_bits(u32 crc, const u8 *buf, u32 n_bits, bool invert);
|
||||
uint32_t crc24q(const uint8_t *buf, uint32_t len, uint32_t crc);
|
||||
uint32_t crc24q_bits(uint32_t crc, const uint8_t *buf, uint32_t n_bits, bool invert);
|
||||
|
||||
#endif /* LIBSWIFTNAV_EDC_H */
|
||||
|
@ -48,37 +48,6 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef COMMON_INT_TYPES
|
||||
#define COMMON_INT_TYPES
|
||||
|
||||
/** \defgroup common_inttypes Integer types
|
||||
* Specified-width integer type definitions for shorter and nicer code.
|
||||
*
|
||||
* These should be used in preference to unspecified width types such as
|
||||
* `int` which can lead to portability issues between different platforms.
|
||||
* \{ */
|
||||
|
||||
/** Signed 8-bit integer. */
|
||||
typedef int8_t s8;
|
||||
/** Signed 16-bit integer. */
|
||||
typedef int16_t s16;
|
||||
/** Signed 32-bit integer. */
|
||||
typedef int32_t s32;
|
||||
/** Signed 64-bit integer. */
|
||||
typedef int64_t s64;
|
||||
/** Unsigned 8-bit integer. */
|
||||
typedef uint8_t u8;
|
||||
/** Unsigned 16-bit integer. */
|
||||
typedef uint16_t u16;
|
||||
/** Unsigned 32-bit integer. */
|
||||
typedef uint32_t u32;
|
||||
/** Unsigned 64-bit integer. */
|
||||
typedef uint64_t u64;
|
||||
|
||||
#endif
|
||||
|
||||
/** \} */
|
||||
|
||||
/** \} */
|
||||
|
||||
#endif /* LIBSWIFTNAV_COMMON_H */
|
||||
|
Loading…
Reference in New Issue
Block a user