1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/unaligned: Add 64 bit version

Add helper function to access `uint64_t` values with possibly unaligned
pointers.
This commit is contained in:
Marian Buschsieweke 2020-08-14 10:09:33 +02:00
parent f64511ddb5
commit 030e0af985
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F

View File

@ -53,6 +53,11 @@ typedef struct __attribute__((packed)) {
uint32_t val; /**< value */
} uint32_una_t;
/** @brief Unaligned access helper struct (uint64_t version) */
typedef struct __attribute__((packed)) {
uint64_t val; /**< value */
} uint64_una_t;
/**
* @brief Get uint16_t from possibly unaligned pointer
*
@ -79,6 +84,19 @@ static inline uint32_t unaligned_get_u32(const void *ptr)
return tmp->val;
}
/**
* @brief Get uint64_t from possibly unaligned pointer
*
* @param[in] ptr pointer to read from
*
* @returns value read from @p ptr
*/
static inline uint64_t unaligned_get_u64(const void *ptr)
{
const uint64_una_t *tmp = (const uint64_una_t *)ptr;
return tmp->val;
}
#ifdef __cplusplus
}
#endif