Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 25 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,31 @@ configure_file (
${OSAL_BINARY_DIR}/src/version.h
)

# Add platform-dependent targets early, so they can be configured by
# platform
add_library(osal "")

# Suppress certain warnings when building with MSVC
if (WINDOWS_MONO)
target_compile_options (osal
PRIVATE
/wd4820 # padding added
)
endif()
add_library(osal-interface INTERFACE)

# Use position independent code if platform supports shared libraries
get_property(SUPPORTS_SHARED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
if (SUPPORTS_SHARED)
set_property(TARGET osal PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
target_include_directories(osal-interface
INTERFACE
$<BUILD_INTERFACE:${OSAL_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

if (CMAKE_PROJECT_NAME STREQUAL OSAL AND BUILD_TESTING)
add_executable(osal_test "")
endif()

# The default system implementation of the OSAL
# is defined by the build platform, but we provide
# a common help string here.
set (OSAL_DEFAULT_SYSTEM_HELP_STRING "The default Osal system implementation to use")

# Platform configuration
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_SYSTEM_NAME}.cmake)

set_target_properties (osal
PROPERTIES
C_STANDARD 99
)

target_compile_features(osal PUBLIC c_std_99)

target_include_directories(osal
PUBLIC
$<BUILD_INTERFACE:${OSAL_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
src
${OSAL_BINARY_DIR}/src
)
# Add alias target for the default system
add_library(osal ALIAS ${OSAL_DEFAULT_SYSTEM})

install(
TARGETS osal
TARGETS osal-interface
EXPORT OsalTargets
)

Expand Down Expand Up @@ -123,6 +105,17 @@ install(FILES
DESTINATION include
)

install(FILES
include/sys/osal_cc_clang.h
include/sys/osal_cc_gcc.h
include/sys/osal_cc_msvc.h
include/sys/osal_cc_rtk.h
include/sys/osal_cc.h
include/osal_log.h
DESTINATION include
)


if (CMAKE_PROJECT_NAME STREQUAL OSAL AND BUILD_TESTING)
add_subdirectory (test)
include(AddGoogleTest)
Expand Down
42 changes: 5 additions & 37 deletions cmake/Linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,14 @@
# license. See the file LICENSE distributed with this software for
# full license information.
#*******************************************************************/

find_package(Threads)

option (USE_SCHED_FIFO
"Use SCHED_FIFO policy. May require extra privileges to run"
OFF)

target_sources(osal PRIVATE
src/linux/osal.c
src/linux/osal_log.c
)

target_compile_options(osal
PRIVATE
-Wall
-Wextra
-Werror
-Wno-unused-parameter
$<$<BOOL:${USE_SCHED_FIFO}>:-DUSE_SCHED_FIFO>
INTERFACE
$<$<CONFIG:Coverage>:--coverage>
)

target_include_directories(osal PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/linux>
)

target_link_libraries(osal PUBLIC
Threads::Threads
rt
INTERFACE
$<$<CONFIG:Coverage>:--coverage>
)

install(FILES
src/linux/sys/osal_cc.h
src/linux/sys/osal_sys.h
DESTINATION include/sys
)
add_subdirectory(src/linux)

if (BUILD_TESTING)
set(GOOGLE_TEST_INDIVIDUAL TRUE)
endif()

set (OSAL_DEFAULT_SYSTEM
osal-linux
CACHE STRING ${OSAL_DEFAULT_SYSTEM_HELP_STRING})
8 changes: 8 additions & 0 deletions cmake/OsalConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ endif()
@PACKAGE_INIT@

include ( "${CMAKE_CURRENT_LIST_DIR}/OsalTargets.cmake" )

set (OSAL_DEFAULT_SYSTEM @OSAL_DEFAULT_SYSTEM@ CACHE STRING "@OSAL_DEFAULT_SYSTEM_HELP_STRING@")

if (TARGET ${OSAL_DEFAULT_SYSTEM})
add_library (osal ALIAS ${OSAL_DEFAULT_SYSTEM})
else()
message (VERBOSE "Osal default system not available yet")
endif()
34 changes: 10 additions & 24 deletions cmake/STM32Cube.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,18 @@
# full license information.
#*******************************************************************/

target_sources(osal PRIVATE
src/freertos/osal.c
src/freertos/osal_log.c
)

target_compile_options(osal
PRIVATE
-Wall
-Wextra
-Werror
-Wno-unused-parameter
)

target_include_directories(osal PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/freertos>
)

install(FILES
src/freertos/sys/osal_cc.h
src/freertos/sys/osal_sys.h
DESTINATION include/sys
)

add_library(cube)
target_link_libraries(osal cube)
install(TARGETS cube EXPORT OsalTargets)

set(CORE_DIR src/freertos/${BOARD})
include(STM32Cube/${BOARD})

add_subdirectory(src/freertos)
target_link_libraries(osal-freertos
PRIVATE
cube
)

set (OSAL_DEFAULT_SYSTEM
osal-freertos
CACHE STRING ${OSAL_DEFAULT_SYSTEM_HELP_STRING})
44 changes: 5 additions & 39 deletions cmake/Windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,12 @@
# full license information.
#*******************************************************************/

target_sources(osal PRIVATE
src/windows/osal.c
src/windows/osal_log.c
)

target_compile_options(osal
PRIVATE
$<$<C_COMPILER_ID:MSVC>:
/W4
/WX
/wd4100
/wd4152
>

$<$<C_COMPILER_ID:GCC>:
-Wall
-Wextra
-Werror
-Wno-unused-parameter
>

PUBLIC
$<$<C_COMPILER_ID:MSVC>:
/wd4200
>
)

target_link_libraries(osal
winmm)

target_include_directories(osal PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/windows>
)

install(FILES
src/windows/sys/osal_cc.h
src/windows/sys/osal_sys.h
DESTINATION include/sys
)
add_subdirectory(src/windows)

if (BUILD_TESTING)
set(GOOGLE_TEST_INDIVIDUAL TRUE)
endif()

set (OSAL_DEFAULT_SYSTEM
osal-windows
CACHE STRING ${OSAL_DEFAULT_SYSTEM_HELP_STRING})
27 changes: 10 additions & 17 deletions cmake/iMX8MM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,18 @@
# full license information.
#*******************************************************************/

target_sources(osal PRIVATE
src/freertos/osal.c
src/freertos/osal_log.c
)

target_include_directories(osal PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/freertos/>
)

install(FILES
src/freertos/sys/osal_cc.h
src/freertos/sys/osal_sys.h
DESTINATION include/sys
)

add_library(mcuxsdk)
target_link_libraries(osal mcuxsdk)
install(TARGETS mcuxsdk EXPORT OsalTargets)


set(CORE_DIR src/freertos/${BOARD})
include(MCUXSDK/${BOARD})

add_subdirectory(src/freertos)
target_link_libraries(osal-freertos
PRIVATE
cube
)

set (OSAL_DEFAULT_SYSTEM
osal-freertos
CACHE STRING ${OSAL_DEFAULT_SYSTEM_HELP_STRING})
29 changes: 4 additions & 25 deletions cmake/rt-kernel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,8 @@
# full license information.
#*******************************************************************/

target_sources(osal PRIVATE
src/rt-kernel/osal.c
src/rt-kernel/osal_log.c
)
add_subdirectory(src/rt-kernel)

target_compile_options(osal
PRIVATE
-Wall
-Wextra
-Werror
-Wno-unused-parameter
)

target_link_libraries(osal
kern
)

target_include_directories(osal PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/rt-kernel>
)

install(FILES
src/rt-kernel/sys/osal_cc.h
src/rt-kernel/sys/osal_sys.h
DESTINATION include/sys
)
set (OSAL_DEFAULT_SYSTEM
osal-rt-kernel
CACHE STRING ${OSAL_DEFAULT_SYSTEM_HELP_STRING})
37 changes: 7 additions & 30 deletions include/osal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extern "C" {
#include <stdint.h>
#include <stdbool.h>

#include "sys/osal_sys.h"
#include "sys/osal_cc.h"

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

#ifndef OS_WAIT_FOREVER
#define OS_WAIT_FOREVER 0xFFFFFFFF
#endif

#ifndef OS_MAIN
#define OS_MAIN int main
#endif

#ifndef OS_MUTEX
typedef void os_mutex_t;
#endif

#ifndef OS_SEM
typedef void os_sem_t;
#endif

#ifndef OS_THREAD
typedef void os_thread_t;
#endif

#ifndef OS_EVENT
typedef void os_event_t;
#endif

#ifndef OS_MBOX
typedef void os_mbox_t;
#endif

#ifndef OS_TIMER
typedef void os_timer_t;
#endif

#ifndef OS_TICK
typedef void os_tick_t;
#endif
typedef struct os_mutex os_mutex_t;
typedef struct os_sem os_sem_t;
typedef struct os_thread os_thread_t;
typedef struct os_event os_event_t;
typedef struct os_mbox os_mbox_t;
typedef struct os_timer os_timer_t;
typedef uint64_t os_tick_t;

void * os_malloc (size_t size);
void os_free (void * ptr);
Expand Down
26 changes: 26 additions & 0 deletions include/sys/osal_cc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
*
* www.rt-labs.com
* Copyright 2017 rt-labs AB, Sweden.
*
* This software is licensed under the terms of the BSD 3-clause
* license. See the file LICENSE distributed with this software for
* full license information.
********************************************************************/

#if defined(__rtk__)
#include "osal_cc_rtk.h"
#elif defined(__GNUC__) || defined(__GNUG__)
#include "osal_cc_gcc.h"
#elif defined(__clang__)
#include "osal_cc_clang.h"
#elif defined(_MSC_VER)
#include "osal_cc_msvc.h"
#else
#error "Unsupported compiler"
#endif
Loading