Skip to content

Commit

Permalink
zcbor_common.h: Convert zcbor_flags_to_states, zcbor_round_up to macros
Browse files Browse the repository at this point in the history
for compatibility. IAR does not allow inline methods in array size
declarations.

Signed-off-by: Øyvind Rønningstad <[email protected]>
  • Loading branch information
oyvindronningstad committed Nov 13, 2024
1 parent 1f1db89 commit 4cd03fb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions include/zcbor_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,23 +511,23 @@ static inline size_t zcbor_round_up(size_t x, size_t align)
return (((x) + (align) - 1) / (align) * (align));
}

#define ZCBOR_ROUND_UP(x, align) (((x) + (align) - 1) / (align) * (align))

#define ZCBOR_BITS_PER_BYTE 8
/** Calculate the number of bytes needed to hold @p num_flags 1 bit flags
*/
static inline size_t zcbor_flags_to_bytes(size_t num_flags)
{
return zcbor_round_up(num_flags, ZCBOR_BITS_PER_BYTE) / ZCBOR_BITS_PER_BYTE;
return ZCBOR_ROUND_UP(num_flags, ZCBOR_BITS_PER_BYTE) / ZCBOR_BITS_PER_BYTE;
}

/** Calculate the number of zcbor_state_t instances needed to hold @p num_flags 1 bit flags
*/
static inline size_t zcbor_flags_to_states(size_t num_flags)
{
return zcbor_round_up(num_flags, sizeof(zcbor_state_t) * ZCBOR_BITS_PER_BYTE)
/ (sizeof(zcbor_state_t) * ZCBOR_BITS_PER_BYTE);
}
#define ZCBOR_FLAGS_TO_STATES(num_flags) \
(ZCBOR_ROUND_UP(num_flags, sizeof(zcbor_state_t) * ZCBOR_BITS_PER_BYTE) \
/ (sizeof(zcbor_state_t) * ZCBOR_BITS_PER_BYTE))

#define ZCBOR_FLAG_STATES(n_flags) zcbor_flags_to_states(n_flags)
#define ZCBOR_FLAG_STATES(n_flags) ZCBOR_FLAGS_TO_STATES(n_flags)

#else
#define ZCBOR_FLAG_STATES(n_flags) 0
Expand Down

0 comments on commit 4cd03fb

Please sign in to comment.