Skip to content

Commit

Permalink
Merge pull request #106 from lf-lang/lock-time
Browse files Browse the repository at this point in the history
Platform support for Embedded targets
  • Loading branch information
lhstrh authored Dec 21, 2022
2 parents 2f43cf0 + 965e9b2 commit d97620b
Show file tree
Hide file tree
Showing 34 changed files with 1,304 additions and 711 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,24 @@ jobs:
unit-tests-single:
uses: lf-lang/reactor-c/.github/workflows/unit-tests.yml@main
with:
cmake-args: '-UNUMBER_OF_WORKERS'
cmake-args: '-UNUMBER_OF_WORKERS -DLF_UNTHREADED=1'

unit-tests-multi:
uses: lf-lang/reactor-c/.github/workflows/unit-tests.yml@main
with:
cmake-args: '-DNUMBER_OF_WORKERS=4'
cmake-args: '-DNUMBER_OF_WORKERS=4 -DLF_THREADED=1'

fetch-lf:
uses: lf-lang/lingua-franca/.github/workflows/extract-ref.yml@master
with:
file: 'lingua-franca-ref.txt'

# lf-ssh:
# needs: fetch-lf
# uses: lf-lang/reactor-c/.github/workflows/ssh.yml@main
# with:
# runtime-ref: ${{ github.ref }}
# compiler-ref: ${{ needs.fetch-lf.outputs.ref }}

lf-default:
needs: fetch-lf
Expand Down
10 changes: 6 additions & 4 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ define(FEDERATED_CENTRALIZED)
define(FEDERATED_DECENTRALIZED)
define(FEDERATED)
define(LF_REACTION_GRAPH_BREADTH)
define(LINGUA_FRANCA_TRACE)
define(LF_TRACE)
define(LF_THREADED)
define(LF_UNTHREADED)
define(LOG_LEVEL)
define(MODAL_REACTORS)
define(NUMBER_OF_FEDERATES)
Expand All @@ -54,7 +56,7 @@ message(STATUS "")
# List sources in this directory.
list(APPEND SINGLE_THREADED_SOURCES reactor.c)
list(APPEND GENERAL_SOURCES tag.c port.c mixed_radix.c reactor_common.c)
if (DEFINED LINGUA_FRANCA_TRACE)
if (DEFINED LF_TRACE)
message(STATUS "Including sources specific to tracing.")
list(APPEND GENERAL_SOURCES trace.c)
endif()
Expand All @@ -67,7 +69,7 @@ add_subdirectory(modal_models)
if(DEFINED NUMBER_OF_WORKERS)
message(STATUS "Including sources for threaded runtime with \
${NUMBER_OF_WORKERS} worker(s) with scheduler=${SCHEDULER} and \
tracing=${LINGUA_FRANCA_TRACE}.")
tracing=${LF_TRACE}.")
add_subdirectory(threaded)
else()
message(STATUS "Including sources for unthreaded runtime.")
Expand All @@ -89,7 +91,7 @@ target_include_directories(core PUBLIC ../include/core/modal_models)
target_include_directories(core PUBLIC ../include/core/threaded)
target_include_directories(core PUBLIC ../include/core/utils)

if(DEFINED NUMBER_OF_WORKERS OR DEFINED LINGUA_FRANCA_TRACE)
if(DEFINED LF_THREADED OR DEFINED LF_TRACE)
find_package(Threads REQUIRED)
target_link_libraries(core PUBLIC Threads::Threads)
endif()
5 changes: 3 additions & 2 deletions core/federated/RTI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ include_directories(${IncludeDir}/modal_models)
include_directories(${IncludeDir}/platform)
include_directories(${IncludeDir}/utils)


# Declare a new executable target and list all its sources
add_executable(
RTI
Expand All @@ -78,8 +79,8 @@ IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
target_compile_definitions(RTI PUBLIC LOG_LEVEL=4)
ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)

# Set the number of workers to enable threading
target_compile_definitions(RTI PUBLIC NUMBER_OF_WORKERS)
# Set LF_THREADING to get the threaded support
target_compile_definitions(RTI PUBLIC LF_THREADED=1)

# Find threads and link to it
find_package(Threads REQUIRED)
Expand Down
11 changes: 6 additions & 5 deletions core/federated/net_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ void encode_tag(
* Checks if str matches regex.
* @return true if there is a match, false otherwise.
*/
bool match_regex(char* str, char* regex) {
bool match_regex(const char* str, char* regex) {
regex_t regex_compiled;
regmatch_t group;
bool valid = false;
Expand Down Expand Up @@ -617,7 +617,7 @@ bool validate_port(char* port) {
* Checks if host is valid.
* @return true if valid, false otherwise.
*/
bool validate_host(char* host) {
bool validate_host(const char* host) {
// regex taken from LFValidator.xtend
char* ipv4_regex = "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])";
char* host_or_FQN_regex = "^([a-z0-9]+(-[a-z0-9]+)*)|(([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,})$";
Expand All @@ -629,7 +629,7 @@ bool validate_host(char* host) {
* Checks if user is valid.
* @return true if valid, false otherwise.
*/
bool validate_user(char* user) {
bool validate_user(const char* user) {
// regex taken from LFValidator.xtend
char* username_regex = "^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$";
return match_regex(user, username_regex);
Expand All @@ -639,7 +639,8 @@ bool validate_user(char* user) {
* Extract one match group from the rti_addr regex .
* @return true if SUCCESS, else false.
*/
bool extract_match_group(const char* rti_addr, char* dest, regmatch_t group, int max_len, int min_len, const char* err_msg) {
bool extract_match_group(const char* rti_addr, char* dest, regmatch_t group,
int max_len, int min_len, const char* err_msg) {
size_t size = group.rm_eo - group.rm_so;
if (size > max_len || size < min_len) {
lf_print_error("%s", err_msg);
Expand All @@ -655,7 +656,7 @@ bool extract_match_group(const char* rti_addr, char* dest, regmatch_t group, int
* @return true if success, else false.
*/
bool extract_match_groups(const char* rti_addr, char** rti_addr_strs, bool** rti_addr_flags, regmatch_t* group_array,
int* gids, int* max_lens, int* min_lens, const char** err_msgs) {
int* gids, int* max_lens, int* min_lens, const char** err_msgs) {
for (int i = 0; i < 3; i++) {
if (group_array[gids[i]].rm_so != -1) {
if (!extract_match_group(rti_addr, rti_addr_strs[i], group_array[gids[i]], max_lens[i], min_lens[i], err_msgs[i])) {
Expand Down
6 changes: 5 additions & 1 deletion core/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Arduino")
set(LF_PLATFORM_FILES lf_arduino_support.c)
add_compile_definitions(PUBLIC PLATFORM_ARDUINO)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Nrf52")
set(LF_PLATFORM_FILES lf_nrf52_support.c)
add_compile_definitions(PUBLIC PLATFORM_NRF52)
else()
message(FATAL_ERROR "Your platform is not supported! The C target supports Linux, MacOS, Windows, and Arduino.")
message(FATAL_ERROR "Your platform is not supported! The C target supports Linux, MacOS, Windows, Arduino and Nrf52.")
endif()

set(GENERAL_SOURCES ${LF_PLATFORM_FILES})
Expand Down
3 changes: 0 additions & 3 deletions core/platform/Platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(LF_PLATFORM_FILE lf_windows_support.c)
set(CMAKE_SYSTEM_VERSION 10.0)
message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Arduino")
set(LF_PLATFORM_FILE lf_arduino_support.c)
message("Using Arduino CMake")
else()
message(FATAL_ERROR "Your platform is not supported! The C target supports Linux, MacOS and Windows.")
endif()
Loading

0 comments on commit d97620b

Please sign in to comment.