Browse Source

AP_HAL: added ptr accessors to sparse-endian.h

c415-sdk
Andrew Tridgell 5 years ago
parent
commit
19093e25be
  1. 11
      libraries/AP_HAL/utility/sparse-endian.h

11
libraries/AP_HAL/utility/sparse-endian.h

@ -84,5 +84,16 @@ static inline uint16_t be16toh(be16_t value) { return bswap_16_on_le((uint16_t _ @@ -84,5 +84,16 @@ static inline uint16_t be16toh(be16_t value) { return bswap_16_on_le((uint16_t _
static inline uint32_t be32toh(be32_t value) { return bswap_32_on_le((uint32_t __ap_force)value); }
static inline uint64_t be64toh(be64_t value) { return bswap_64_on_le((uint64_t __ap_force)value); }
// methods for misaligned buffers
static inline uint16_t le16toh_ptr(const uint8_t *p) { return p[0] | (p[1]<<8U); }
static inline uint32_t le32toh_ptr(const uint8_t *p) { return p[0] | (p[1]<<8U) | (p[2]<<16U) | (p[3]<<24U); }
static inline uint16_t be16toh_ptr(const uint8_t *p) { return p[1] | (p[0]<<8U); }
static inline uint32_t be32toh_ptr(const uint8_t *p) { return p[3] | (p[2]<<8U) | (p[1]<<16U) | (p[0]<<24U); }
static inline void put_le16_ptr(uint8_t *p, uint16_t v) { p[0] = (v&0xFF); p[1] = (v>>8); }
static inline void put_le32_ptr(uint8_t *p, uint32_t v) { p[0] = (v&0xFF); p[1] = (v>>8)&0xFF; p[2] = (v>>16)&0xFF; p[3] = (v>>24)&0xFF; }
static inline void put_be16_ptr(uint8_t *p, uint16_t v) { p[1] = (v&0xFF); p[0] = (v>>8); }
static inline void put_be32_ptr(uint8_t *p, uint32_t v) { p[3] = (v&0xFF); p[2] = (v>>8)&0xFF; p[1] = (v>>16)&0xFF; p[0] = (v>>24)&0xFF; }
#undef __ap_bitwise
#undef __ap_force

Loading…
Cancel
Save