ThingSet / thingset-device-library

ThingSet library for resource-constrained devices written in C/C++
https://thingset.io/thingset-device-library/
Apache License 2.0
14 stars 6 forks source link

Add Zephyr requirement for LIBC #25

Closed martinjaeger closed 2 years ago

martinjaeger commented 2 years ago

ThingSet requires full libc (newlib-nano). This should be enabled in Zephyr by selecting CONFIG_REQUIRES_FULL_LIBC=y.

b0661 commented 2 years ago

You may use CONFIG_MINIMAL_LIBC with some minor adaptions. The only function that is really needed is strtod.

See:

https://github.com/ThingSet/thingset-device-library/blob/5b5e3f7f8491c5a0859c0f16ab586e1ea3364a87/zephyr/thingset/ts_impl_env.h#L87-L132

https://github.com/ThingSet/thingset-device-library/blob/5b5e3f7f8491c5a0859c0f16ab586e1ea3364a87/zephyr/thingset/ts_impl_libc_minimal.c

martinjaeger commented 2 years ago

I had the problem that it didn't find lroundf from math.h with only CONFIG_MINIMAL_LIBC. Enabling CONFIG_MINIMAL_LIBC_MALLOC did not make a difference.

b0661 commented 2 years ago

I had the problem that it didn't find lroundf from math.h with only CONFIG_MINIMAL_LIBC.

Sorry, I have 64 bit support enabled always - thus only using llroundf. In case you use gcc this may help instead:

static inline long int lroundf(float x) { return __builtin_lroundf(x); };

See also https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html

martinjaeger commented 2 years ago

Thanks, good hint. Yes, we're always using GCC, as Zephyr doesn't support any other compiler so far. So that might be an option.