Skip to content

Commit f2caf8f

Browse files
committed
feat: make osal an interface library
Expose a osal-interface target that is of cmake INTERFACE type. This target only defines the osal API and allow delaying the choice of linking of final osal port implementation to the link stage of the binary. This allow the Osal implementation to be defined by the integrator of used libraries. To accomplish this: - osal.h becomes static and common to all targets - osal_sys.h is changed to an internal implementation header for the osal port - Buld files are restructured to keep build configuration of a port in the port directory By default an osal cmake alias is added to remain compatible with previous solutions.
1 parent 9636b19 commit f2caf8f

23 files changed

Lines changed: 372 additions & 394 deletions

CMakeLists.txt

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,49 +52,31 @@ configure_file (
5252
${OSAL_BINARY_DIR}/src/version.h
5353
)
5454

55-
# Add platform-dependent targets early, so they can be configured by
56-
# platform
57-
add_library(osal "")
58-
59-
# Suppress certain warnings when building with MSVC
60-
if (WINDOWS_MONO)
61-
target_compile_options (osal
62-
PRIVATE
63-
/wd4820 # padding added
64-
)
65-
endif()
55+
add_library(osal-interface INTERFACE)
6656

67-
# Use position independent code if platform supports shared libraries
68-
get_property(SUPPORTS_SHARED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
69-
if (SUPPORTS_SHARED)
70-
set_property(TARGET osal PROPERTY POSITION_INDEPENDENT_CODE ON)
71-
endif()
57+
target_include_directories(osal-interface
58+
INTERFACE
59+
$<BUILD_INTERFACE:${OSAL_SOURCE_DIR}/include>
60+
$<INSTALL_INTERFACE:include>
61+
)
7262

7363
if (CMAKE_PROJECT_NAME STREQUAL OSAL AND BUILD_TESTING)
7464
add_executable(osal_test "")
7565
endif()
7666

67+
# The default system implementation of the OSAL
68+
# is defined by the build platform, but we provide
69+
# a common help string here.
70+
set (OSAL_DEFAULT_SYSTEM_HELP_STRING "The default Osal system implementation to use")
71+
7772
# Platform configuration
7873
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_SYSTEM_NAME}.cmake)
7974

80-
set_target_properties (osal
81-
PROPERTIES
82-
C_STANDARD 99
83-
)
84-
85-
target_compile_features(osal PUBLIC c_std_99)
86-
87-
target_include_directories(osal
88-
PUBLIC
89-
$<BUILD_INTERFACE:${OSAL_SOURCE_DIR}/include>
90-
$<INSTALL_INTERFACE:include>
91-
PRIVATE
92-
src
93-
${OSAL_BINARY_DIR}/src
94-
)
75+
# Add alias target for the default system
76+
add_library(osal ALIAS ${OSAL_DEFAULT_SYSTEM})
9577

9678
install(
97-
TARGETS osal
79+
TARGETS osal-interface
9880
EXPORT OsalTargets
9981
)
10082

cmake/Linux.cmake

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,14 @@
1212
# license. See the file LICENSE distributed with this software for
1313
# full license information.
1414
#*******************************************************************/
15-
1615
find_package(Threads)
1716

18-
option (USE_SCHED_FIFO
19-
"Use SCHED_FIFO policy. May require extra privileges to run"
20-
OFF)
21-
22-
target_sources(osal PRIVATE
23-
src/linux/osal.c
24-
src/linux/osal_log.c
25-
)
26-
27-
target_compile_options(osal
28-
PRIVATE
29-
-Wall
30-
-Wextra
31-
-Werror
32-
-Wno-unused-parameter
33-
$<$<BOOL:${USE_SCHED_FIFO}>:-DUSE_SCHED_FIFO>
34-
INTERFACE
35-
$<$<CONFIG:Coverage>:--coverage>
36-
)
37-
38-
target_include_directories(osal PUBLIC
39-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/linux>
40-
)
41-
42-
target_link_libraries(osal PUBLIC
43-
Threads::Threads
44-
rt
45-
INTERFACE
46-
$<$<CONFIG:Coverage>:--coverage>
47-
)
48-
49-
install(FILES
50-
src/linux/sys/osal_sys.h
51-
DESTINATION include/sys
52-
)
17+
add_subdirectory(src/linux)
5318

5419
if (BUILD_TESTING)
5520
set(GOOGLE_TEST_INDIVIDUAL TRUE)
5621
endif()
22+
23+
set (OSAL_DEFAULT_SYSTEM
24+
osal-linux
25+
CACHE STRING ${OSAL_DEFAULT_SYSTEM_HELP_STRING})

cmake/OsalConfig.cmake.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ endif()
77
@PACKAGE_INIT@
88

99
include ( "${CMAKE_CURRENT_LIST_DIR}/OsalTargets.cmake" )
10+
11+
set (OSAL_DEFAULT_SYSTEM @OSAL_DEFAULT_SYSTEM@ CACHE STRING "@OSAL_DEFAULT_SYSTEM_HELP_STRING@")
12+
13+
if (TARGET ${OSAL_DEFAULT_SYSTEM})
14+
add_library (osal ALIAS ${OSAL_DEFAULT_SYSTEM})
15+
else()
16+
message (VERBOSE "Osal default system not available yet")
17+
endif()

cmake/STM32Cube.cmake

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,18 @@
1313
# full license information.
1414
#*******************************************************************/
1515

16-
target_sources(osal PRIVATE
17-
src/freertos/osal.c
18-
src/freertos/osal_log.c
19-
)
20-
21-
target_compile_options(osal
22-
PRIVATE
23-
-Wall
24-
-Wextra
25-
-Werror
26-
-Wno-unused-parameter
27-
)
28-
29-
target_include_directories(osal PUBLIC
30-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/freertos>
31-
)
32-
33-
install(FILES
34-
src/freertos/sys/osal_sys.h
35-
DESTINATION include/sys
36-
)
37-
3816
add_library(cube)
39-
target_link_libraries(osal cube)
4017
install(TARGETS cube EXPORT OsalTargets)
4118

4219
set(CORE_DIR src/freertos/${BOARD})
4320
include(STM32Cube/${BOARD})
21+
22+
add_subdirectory(src/freertos)
23+
target_link_libraries(osal-freertos
24+
PRIVATE
25+
cube
26+
)
27+
28+
set (OSAL_DEFAULT_SYSTEM
29+
osal-freertos
30+
CACHE STRING ${OSAL_DEFAULT_SYSTEM_HELP_STRING})

cmake/Windows.cmake

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,12 @@
1313
# full license information.
1414
#*******************************************************************/
1515

16-
target_sources(osal PRIVATE
17-
src/windows/osal.c
18-
src/windows/osal_log.c
19-
)
20-
21-
target_compile_options(osal
22-
PRIVATE
23-
$<$<C_COMPILER_ID:MSVC>:
24-
/W4
25-
/WX
26-
/wd4100
27-
/wd4152
28-
>
29-
30-
$<$<C_COMPILER_ID:GCC>:
31-
-Wall
32-
-Wextra
33-
-Werror
34-
-Wno-unused-parameter
35-
>
36-
37-
PUBLIC
38-
$<$<C_COMPILER_ID:MSVC>:
39-
/wd4200
40-
>
41-
)
42-
43-
target_link_libraries(osal
44-
winmm)
45-
46-
target_include_directories(osal PUBLIC
47-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/windows>
48-
)
49-
50-
install(FILES
51-
src/windows/sys/osal_sys.h
52-
DESTINATION include/sys
53-
)
16+
add_subdirectory(src/windows)
5417

5518
if (BUILD_TESTING)
5619
set(GOOGLE_TEST_INDIVIDUAL TRUE)
5720
endif()
21+
22+
set (OSAL_DEFAULT_SYSTEM
23+
osal-windows
24+
CACHE STRING ${OSAL_DEFAULT_SYSTEM_HELP_STRING})

cmake/iMX8MM.cmake

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,18 @@
1414
# full license information.
1515
#*******************************************************************/
1616

17-
target_sources(osal PRIVATE
18-
src/freertos/osal.c
19-
src/freertos/osal_log.c
20-
)
21-
22-
target_include_directories(osal PUBLIC
23-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/freertos/>
24-
)
25-
26-
install(FILES
27-
src/freertos/sys/osal_sys.h
28-
DESTINATION include/sys
29-
)
30-
3117
add_library(mcuxsdk)
32-
target_link_libraries(osal mcuxsdk)
3318
install(TARGETS mcuxsdk EXPORT OsalTargets)
3419

35-
3620
set(CORE_DIR src/freertos/${BOARD})
3721
include(MCUXSDK/${BOARD})
22+
23+
add_subdirectory(src/freertos)
24+
target_link_libraries(osal-freertos
25+
PRIVATE
26+
cube
27+
)
28+
29+
set (OSAL_DEFAULT_SYSTEM
30+
osal-freertos
31+
CACHE STRING ${OSAL_DEFAULT_SYSTEM_HELP_STRING})

cmake/rt-kernel.cmake

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,8 @@
1313
# full license information.
1414
#*******************************************************************/
1515

16-
target_sources(osal PRIVATE
17-
src/rt-kernel/osal.c
18-
src/rt-kernel/osal_log.c
19-
)
16+
add_subdirectory(src/rt-kernel)
2017

21-
target_compile_options(osal
22-
PRIVATE
23-
-Wall
24-
-Wextra
25-
-Werror
26-
-Wno-unused-parameter
27-
)
28-
29-
target_link_libraries(osal
30-
kern
31-
)
32-
33-
target_include_directories(osal PUBLIC
34-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/rt-kernel>
35-
)
36-
37-
install(FILES
38-
src/rt-kernel/sys/osal_sys.h
39-
DESTINATION include/sys
40-
)
18+
set (OSAL_DEFAULT_SYSTEM
19+
osal-rt-kernel
20+
CACHE STRING ${OSAL_DEFAULT_SYSTEM_HELP_STRING})

include/osal.h

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ extern "C" {
2525
#include <stdint.h>
2626
#include <stdbool.h>
2727

28-
#include "sys/osal_sys.h"
2928
#include "sys/osal_cc.h"
3029

3130
#ifndef MIN
@@ -44,41 +43,19 @@ extern "C" {
4443
#define NELEMENTS(a) (sizeof (a) / sizeof ((a)[0]))
4544
#endif
4645

47-
#ifndef OS_WAIT_FOREVER
4846
#define OS_WAIT_FOREVER 0xFFFFFFFF
49-
#endif
5047

5148
#ifndef OS_MAIN
5249
#define OS_MAIN int main
5350
#endif
5451

55-
#ifndef OS_MUTEX
56-
typedef void os_mutex_t;
57-
#endif
58-
59-
#ifndef OS_SEM
60-
typedef void os_sem_t;
61-
#endif
62-
63-
#ifndef OS_THREAD
64-
typedef void os_thread_t;
65-
#endif
66-
67-
#ifndef OS_EVENT
68-
typedef void os_event_t;
69-
#endif
70-
71-
#ifndef OS_MBOX
72-
typedef void os_mbox_t;
73-
#endif
74-
75-
#ifndef OS_TIMER
76-
typedef void os_timer_t;
77-
#endif
78-
79-
#ifndef OS_TICK
80-
typedef void os_tick_t;
81-
#endif
52+
typedef struct os_mutex os_mutex_t;
53+
typedef struct os_sem os_sem_t;
54+
typedef struct os_thread os_thread_t;
55+
typedef struct os_event os_event_t;
56+
typedef struct os_mbox os_mbox_t;
57+
typedef struct os_timer os_timer_t;
58+
typedef uint64_t os_tick_t;
8259

8360
void * os_malloc (size_t size);
8461
void os_free (void * ptr);

src/freertos/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#********************************************************************
2+
# _ _ _
3+
# _ __ | |_ _ | | __ _ | |__ ___
4+
# | '__|| __|(_)| | / _` || '_ \ / __|
5+
# | | | |_ _ | || (_| || |_) |\__ \
6+
# |_| \__|(_)|_| \__,_||_.__/ |___/
7+
#
8+
# www.rt-labs.com
9+
# Copyright 2021 rt-labs AB, Sweden.
10+
# Copyright 2023 NXP
11+
#
12+
# This software is licensed under the terms of the BSD 3-clause
13+
# license. See the file LICENSE distributed with this software for
14+
# full license information.
15+
#*******************************************************************/
16+
17+
set(_osal_sys osal-freertos)
18+
add_library(${_osal_sys})
19+
20+
target_include_directories(${_osal_sys} PRIVATE
21+
sys
22+
)
23+
24+
target_compile_definitions(${_osal_sys}
25+
PUBLIC
26+
"OS_MAIN=int _main"
27+
)
28+
29+
target_sources(${_osal_sys}
30+
PRIVATE
31+
osal.c
32+
osal_log.c
33+
)
34+
35+
target_link_libraries(${_osal_sys}
36+
PUBLIC
37+
osal-interface
38+
)
39+
40+
install(
41+
TARGETS ${_osal_sys}
42+
EXPORT OsalTargets
43+
)

0 commit comments

Comments
 (0)