kernel: restore size and signedness behavior in deprecated time-related API

The addition of API to correctly handle conversion between durations
in different clocks inadvertently changed the type of the value
produced by the API.  Specific changes were:

s32_t z_ms_to_ticks(s32_t t) =>
  u32_t k_ms_to_ticks_ceil32(u32_t t) : signedness change
s32_t __ticks_to_us(s32_t t) =>
  u64_t k_ticks_to_us_floor64(u64_t t) : signedness and rank change
s32_t z_us_to_ticks(s32_t t) =>
  u64_t k_us_to_ticks_ceil64(u64_t t) : signedness and rank change
int sys_clock_hw_cycles_per_tick() =>
  u32_t k_ticks_to_cyc_floor32(1) : signedness change

The effect of this is to change the essential type of operands in
existing expressions, potentially resulting in behavior changes when
calculations were promoted to unsigned types, or code size by
requiring 64-bot arithmetic.

Add casts as necessary to preserve the original return type, and to
explicitly recognize impact of passing macro parameters into a context
where a specific type will be used.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2019-10-31 06:36:10 -05:00 committed by Anas Nashif
commit ae5e5b7753

View file

@ -73,17 +73,17 @@ extern void z_enable_sys_clock(void);
#endif
#define __ticks_to_ms(t) __DEPRECATED_MACRO \
k_ticks_to_ms_floor64(t)
k_ticks_to_ms_floor64((u64_t)(t))
#define z_ms_to_ticks(t) \
k_ms_to_ticks_ceil32(t)
((s32_t)k_ms_to_ticks_ceil32((u32_t)(t)))
#define __ticks_to_us(t) __DEPRECATED_MACRO \
k_ticks_to_us_floor64(t)
((s32_t)k_ticks_to_us_floor32((u32_t)(t)))
#define z_us_to_ticks(t) __DEPRECATED_MACRO \
k_us_to_ticks_ceil64(t)
((s32_t)k_us_to_ticks_ceil32((u32_t)(t)))
#define sys_clock_hw_cycles_per_tick() __DEPRECATED_MACRO \
k_ticks_to_cyc_floor32(1)
((int)k_ticks_to_cyc_floor32(1U))
#define SYS_CLOCK_HW_CYCLES_TO_NS64(t) __DEPRECATED_MACRO \
k_cyc_to_ns_floor64(t)
k_cyc_to_ns_floor64((u64_t)(X))
#define SYS_CLOCK_HW_CYCLES_TO_NS(t) __DEPRECATED_MACRO \
((u32_t)k_cyc_to_ns_floor64(t))