sys/unaligned: Add 32 bit version

This commit is contained in:
Marian Buschsieweke 2020-07-28 17:26:24 +02:00
parent 72d6d9047f
commit 4f391007f0
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F

View File

@ -48,6 +48,11 @@ typedef struct __attribute__((packed)) {
uint16_t val; /**< value */
} uint16_una_t;
/** @brief Unaligned access helper struct (uint32_t version) */
typedef struct __attribute__((packed)) {
uint32_t val; /**< value */
} uint32_una_t;
/**
* @brief Get uint16_t from possibly unaligned pointer
*
@ -57,7 +62,20 @@ typedef struct __attribute__((packed)) {
*/
static inline uint16_t unaligned_get_u16(const void *ptr)
{
const uint16_una_t *tmp = ptr;
const uint16_una_t *tmp = (const uint16_una_t *)ptr;
return tmp->val;
}
/**
* @brief Get uint32_t from possibly unaligned pointer
*
* @param[in] ptr pointer to read from
*
* @returns value read from @p ptr
*/
static inline uint32_t unaligned_get_u32(const void *ptr)
{
const uint32_una_t *tmp = (const uint32_una_t *)ptr;
return tmp->val;
}