From 0cb54443bf5606d3392fa583c37c32a6779ba377 Mon Sep 17 00:00:00 2001 From: Mei Fong Low Date: Tue, 25 Mar 2025 17:20:52 +1100 Subject: [PATCH] Zephyr 3.7 update Update call to k_mem_slab_free to match Zephyr 3.5 API Update files prefixes Fix compiler around use of %f specifier for float type --- include/zpp/fmt.hpp | 216 +++++++++++++++++------------------ include/zpp/mem_slab.hpp | 2 +- include/zpp/thread_data.hpp | 2 +- include/zpp/thread_stack.hpp | 2 +- 4 files changed, 106 insertions(+), 116 deletions(-) diff --git a/include/zpp/fmt.hpp b/include/zpp/fmt.hpp index e74fb78..1df47dc 100644 --- a/include/zpp/fmt.hpp +++ b/include/zpp/fmt.hpp @@ -10,138 +10,129 @@ #include #include -#include #include +#include #include namespace zpp { namespace internal { -inline void print_arg() noexcept { } -inline void print_arg(bool v) noexcept { printk("%d", (int)v); } -inline void print_arg(float v) noexcept { printk("%f", v); } +inline void print_arg() noexcept {} +inline void print_arg(bool v) noexcept { printk("%d", static_cast(v)); } +inline void print_arg(float v) noexcept { printk("%f", static_cast(v)); } inline void print_arg(double v) noexcept { printk("%g", v); } inline void print_arg(char v) noexcept { printk("%c", v); } inline void print_arg(const char* v) noexcept { printk("%s", v); } inline void print_arg(const void* v) noexcept { printk("%p", v); } -inline void print_arg(uint8_t v) noexcept { printk("%d", (uint32_t)v); } -inline void print_arg(int8_t v) noexcept { printk("%d", (int32_t)v); } -inline void print_arg(uint16_t v) noexcept { printk("%d", (uint32_t)v); } -inline void print_arg(int16_t v) noexcept { printk("%d", (int32_t)v); } +inline void print_arg(uint8_t v) noexcept { printk("%d", static_cast(v)); } +inline void print_arg(int8_t v) noexcept { printk("%d", static_cast(v)); } +inline void print_arg(uint16_t v) noexcept { printk("%d", static_cast(v)); } +inline void print_arg(int16_t v) noexcept { printk("%d", static_cast(v)); } inline void print_arg(uint32_t v) noexcept { printk("%d", v); } inline void print_arg(int32_t v) noexcept { printk("%d", v); } inline void print_arg(uint64_t v) noexcept { printk("%lld", v); } inline void print_arg(int64_t v) noexcept { printk("%lld", v); } -template -inline void print_arg(std::chrono::duration v) -{ - using namespace std::chrono; - - auto s = duration_cast(v); - v -= duration_cast(s); - auto ms = duration_cast(v); - v -= duration_cast(ms); - auto us = duration_cast(v); - v -= duration_cast(us); - auto ns = duration_cast(v); - - printk("%d.%03d%03d%03ds", - (int)s.count(), (int)ms.count(), - (int)us.count(), (int)ns.count()); -} +template +inline void print_arg(std::chrono::duration v) { + using namespace std::chrono; -template -inline void print_arg(std::chrono::time_point v) -{ - print_arg(v.time_since_epoch()); -} + auto s = duration_cast(v); + v -= duration_cast(s); + auto ms = duration_cast(v); + v -= duration_cast(ms); + auto us = duration_cast(v); + v -= duration_cast(us); + auto ns = duration_cast(v); -inline void print_helper(const char* fmt) noexcept -{ - printk("%s", fmt); + printk("%d.%03d%03d%03ds", (int)s.count(), (int)ms.count(), (int)us.count(), (int)ns.count()); } -template -inline void print_helper(const char* fmt, T_FirstArg&& first, T_Args&&... args) noexcept -{ - enum class state { normal, format, open_brace, close_brace, done }; - - state s = state::normal; - size_t n = 0; - - while (true) { - char c = fmt[n++]; - - if (c == '\0') { - return; - } - - switch (s) { - case state::normal: - switch (c) { - case '{': - s = state::open_brace; - break; - case '}': - s = state::close_brace; - break; - default: - printk("%c", c); - break; - } - break; - - case state::open_brace: - switch(c) { - case '{': - s = state::normal; - printk("{"); - break; - - case '}': - s = state::done; - break; - - default: - s = state::format; - break; - } - break; - - case state::close_brace: - if (c == '}') { - printk("}"); - } - s = state::normal; - break; - - case state::format: - switch (c) { - case '}': - s = state::done; - break; - default: - break; - } - break; - - case state::done: - break; - - } +template +inline void print_arg(std::chrono::time_point v) { + print_arg(v.time_since_epoch()); +} - if (s == state::done) { - break; +inline void print_helper(const char* fmt) noexcept { printk("%s", fmt); } + +template +inline void print_helper(const char* fmt, T_FirstArg&& first, T_Args&&... args) noexcept { + enum class state { normal, format, open_brace, close_brace, done }; + + state s = state::normal; + size_t n = 0; + + while (true) { + char c = fmt[n++]; + + if (c == '\0') { + return; + } + + switch (s) { + case state::normal: + switch (c) { + case '{': + s = state::open_brace; + break; + case '}': + s = state::close_brace; + break; + default: + printk("%c", c); + break; + } + break; + + case state::open_brace: + switch (c) { + case '{': + s = state::normal; + printk("{"); + break; + + case '}': + s = state::done; + break; + + default: + s = state::format; + break; + } + break; + + case state::close_brace: + if (c == '}') { + printk("}"); + } + s = state::normal; + break; + + case state::format: + switch (c) { + case '}': + s = state::done; + break; + default: + break; + } + break; + + case state::done: + break; + } + + if (s == state::done) { + break; + } } - } - print_arg(std::forward(first)); - print_helper(&(fmt[n]), std::forward(args)...); + print_arg(std::forward(first)); + print_helper(&(fmt[n]), std::forward(args)...); } -} // namespace internal +} // namespace internal /// /// @brief simple typesafe print function @@ -153,12 +144,11 @@ inline void print_helper(const char* fmt, T_FirstArg&& first, T_Args&&... args) /// @param fmt The format string using {} as place holder /// @param args The needed arguments to print /// -template -inline void print(const char* fmt, T_Args&&... args) noexcept -{ - internal::print_helper(fmt, std::forward(args)...); +template +inline void print(const char* fmt, T_Args&&... args) noexcept { + internal::print_helper(fmt, std::forward(args)...); } -} // namespace zpp +} // namespace zpp -#endif // ZPP_INCLUDE_ZPP_FMT_HPP +#endif // ZPP_INCLUDE_ZPP_FMT_HPP diff --git a/include/zpp/mem_slab.hpp b/include/zpp/mem_slab.hpp index 3c36660..b928e99 100644 --- a/include/zpp/mem_slab.hpp +++ b/include/zpp/mem_slab.hpp @@ -102,7 +102,7 @@ class mem_slab_base { void deallocate(void* vp) noexcept { if (vp != nullptr) { - k_mem_slab_free(native_handle(), &vp); + k_mem_slab_free(native_handle(), vp); } } diff --git a/include/zpp/thread_data.hpp b/include/zpp/thread_data.hpp index e25e6b2..d68e8bd 100644 --- a/include/zpp/thread_data.hpp +++ b/include/zpp/thread_data.hpp @@ -8,7 +8,7 @@ #define ZPP_INCLUDE_ZPP_THREAD_DATA_HPP #include -#include +#include #include namespace zpp { diff --git a/include/zpp/thread_stack.hpp b/include/zpp/thread_stack.hpp index 391cc2a..a63a9bb 100644 --- a/include/zpp/thread_stack.hpp +++ b/include/zpp/thread_stack.hpp @@ -8,7 +8,7 @@ #define ZPP_INCLUDE_ZPP_THREAD_STACK_HPP #include -#include +#include #include namespace zpp {