From a4483f023ea4460c687781653c571f0e005c4beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ola=20Bj=C3=B6rsne?= Date: Thu, 30 Mar 2023 12:23:12 +0200 Subject: [PATCH 1/5] add CC_ALIGNED macro to osal_cc Change-Id: Idee151cba148e1e09bbac575df3440e8041cd44b --- src/freertos/sys/osal_cc.h | 1 + src/linux/sys/osal_cc.h | 1 + src/rt-kernel/sys/osal_cc.h | 1 + 3 files changed, 3 insertions(+) diff --git a/src/freertos/sys/osal_cc.h b/src/freertos/sys/osal_cc.h index cde7ec2..ab19a79 100644 --- a/src/freertos/sys/osal_cc.h +++ b/src/freertos/sys/osal_cc.h @@ -26,6 +26,7 @@ extern "C" #define CC_PACKED_BEGIN #define CC_PACKED_END #define CC_PACKED __attribute__((packed)) +#define CC_ALIGNED(n) __attribute__((aligned (n))) #define CC_FORMAT(str,arg) __attribute__((format (printf, str, arg))) diff --git a/src/linux/sys/osal_cc.h b/src/linux/sys/osal_cc.h index 7103750..fd51af0 100644 --- a/src/linux/sys/osal_cc.h +++ b/src/linux/sys/osal_cc.h @@ -42,6 +42,7 @@ static inline void cc_assert (int exp) CLANG_ANALYZER_NORETURN #define CC_PACKED_BEGIN #define CC_PACKED_END #define CC_PACKED __attribute__ ((packed)) +#define CC_ALIGNED(n) __attribute__((aligned (n))) #define CC_FORMAT(str, arg) __attribute__ ((format (printf, str, arg))) diff --git a/src/rt-kernel/sys/osal_cc.h b/src/rt-kernel/sys/osal_cc.h index 2bfc4b7..6c6f952 100644 --- a/src/rt-kernel/sys/osal_cc.h +++ b/src/rt-kernel/sys/osal_cc.h @@ -26,6 +26,7 @@ extern "C" { #define CC_PACKED_BEGIN #define CC_PACKED_END #define CC_PACKED __attribute__ ((packed)) +#define CC_ALIGNED(n) __attribute__((aligned (n))) #define CC_FORMAT(str, arg) __attribute__ ((format (printf, str, arg))) From 870c23a343d97d09c89b95f653c9e5b125eb455d Mon Sep 17 00:00:00 2001 From: Philip Vedin Date: Fri, 19 Jul 2024 14:30:52 +0000 Subject: [PATCH 2/5] osal: Avoid including winsock.h Windows applications using winsock2.h need to ensure that winsock.h is never included as well. One method of ensuring this is to always include winsock2.h before any windows.h includes. Another method that is perhaps more suitable for osal is to define WIN32_LEAN_AND_MEAN to reduce what windows.h includes. Change-Id: I50ee5e4394c28bae39d3fde5a478702d7dc5b36d --- src/windows/sys/osal_sys.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/windows/sys/osal_sys.h b/src/windows/sys/osal_sys.h index d2f336e..c5cf209 100644 --- a/src/windows/sys/osal_sys.h +++ b/src/windows/sys/osal_sys.h @@ -20,8 +20,14 @@ extern "C" { #endif +#define WIN32_LEAN_AND_MEAN /* Do not include */ #include +/* Libraries excluded by WIN32_LEAN_AND_MEAN */ +#include +#include +#include + #define OS_WAIT_FOREVER INFINITE #define OS_THREAD From e11dd1bb807876473b411fe46304813aab9216a2 Mon Sep 17 00:00:00 2001 From: Philip Vedin Date: Fri, 19 Jul 2024 14:37:07 +0000 Subject: [PATCH 3/5] osal: Suppress MSVC warning Change-Id: I28a3386907f05ac9a3336b41959aef0179e1cc85 --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0d6857..59b538a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,14 @@ configure_file ( # platform add_library(osal "") +# Suppress certain warnings when building with MSVC +if (WINDOWS_MONO) +target_compile_options (osal + PRIVATE + /wd4820 # padding added + ) +endif() + # Use position independent code if platform supports shared libraries get_property(SUPPORTS_SHARED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS) if (SUPPORTS_SHARED) From 4d462ebef9b32e6e3fb850a8b9cacfc80d190d2a Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Thu, 26 Sep 2024 17:32:46 +0200 Subject: [PATCH 4/5] Allow hooking os_log in application Make the os_log a pointer to the log function with a default value that uses standard logging on os. This allow the user of osal to override logging output by assigning an alternate function. Change-Id: I67fec7e4430898ac48a87a3229879f4fa7b78fce --- include/osal_log.h | 5 ++++- src/linux/osal_log.c | 4 +++- src/rt-kernel/osal_log.c | 4 +++- src/windows/osal_log.c | 4 +++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/osal_log.h b/include/osal_log.h index 55c1c7b..60230ba 100644 --- a/include/osal_log.h +++ b/include/osal_log.h @@ -69,7 +69,10 @@ extern "C" { #define LOG_ERROR_ENABLED(type) LOG_ENABLED (LOG_LEVEL_ERROR | type) #define LOG_FATAL_ENABLED(type) LOG_ENABLED (LOG_LEVEL_FATAL | type) -void os_log (uint8_t type, const char * fmt, ...) CC_FORMAT (2, 3); + +typedef void (*os_log_t) (uint8_t type, const char * fmt, ...) CC_FORMAT (2, 3); + +extern os_log_t os_log; #ifdef __cplusplus } diff --git a/src/linux/osal_log.c b/src/linux/osal_log.c index 8276ad7..946f7a6 100644 --- a/src/linux/osal_log.c +++ b/src/linux/osal_log.c @@ -19,7 +19,7 @@ #include #include -void os_log (uint8_t type, const char * fmt, ...) +static void os_log_impl (uint8_t type, const char * fmt, ...) { va_list list; time_t rawtime; @@ -56,3 +56,5 @@ void os_log (uint8_t type, const char * fmt, ...) va_end (list); fflush (stdout); } + +os_log_t os_log = os_log_impl; diff --git a/src/rt-kernel/osal_log.c b/src/rt-kernel/osal_log.c index 8726087..31d9f87 100644 --- a/src/rt-kernel/osal_log.c +++ b/src/rt-kernel/osal_log.c @@ -20,7 +20,7 @@ #include #include -void os_log (uint8_t type, const char * fmt, ...) +void os_log_impl (uint8_t type, const char * fmt, ...) { va_list list; @@ -49,3 +49,5 @@ void os_log (uint8_t type, const char * fmt, ...) vprintf (fmt, list); va_end (list); } + +os_log_t os_log = os_log_impl; diff --git a/src/windows/osal_log.c b/src/windows/osal_log.c index bb480cd..c6f213e 100644 --- a/src/windows/osal_log.c +++ b/src/windows/osal_log.c @@ -19,7 +19,7 @@ #include #include -void os_log (uint8_t type, const char * fmt, ...) +static void os_log_impl (uint8_t type, const char * fmt, ...) { va_list list; @@ -49,3 +49,5 @@ void os_log (uint8_t type, const char * fmt, ...) va_end (list); fflush (stdout); } + +os_log_t os_log = os_log_impl; From b7daba663df44e6b447f44bcce10662a7b63c3ee Mon Sep 17 00:00:00 2001 From: Hans-Erik Floryd Date: Wed, 22 Jan 2025 17:19:21 +0100 Subject: [PATCH 5/5] Fix linux timer for longer timeouts The linux timer did not work for timeouts >= 1 second. The tv_nsec timespec member must be in the range 0 - 999 999 999. Change-Id: I0dda046adb345efcca52250071e939ce82baf975 --- src/linux/osal.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/linux/osal.c b/src/linux/osal.c index ce932c8..fe8008c 100644 --- a/src/linux/osal.c +++ b/src/linux/osal.c @@ -545,10 +545,12 @@ void os_timer_set (os_timer_t * timer, uint32_t us) void os_timer_start (os_timer_t * timer) { struct itimerspec its; + uint32_t sec = timer->us / (1000 * 1000); + uint32_t us = timer->us - sec * 1000 * 1000; /* Start timer */ - its.it_value.tv_sec = 0; - its.it_value.tv_nsec = 1000 * timer->us; + its.it_value.tv_sec = sec; + its.it_value.tv_nsec = 1000 * us; its.it_interval.tv_sec = (timer->oneshot) ? 0 : its.it_value.tv_sec; its.it_interval.tv_nsec = (timer->oneshot) ? 0 : its.it_value.tv_nsec; timer_settime (timer->timerid, 0, &its, NULL);