Skip to content

Commit

Permalink
Support for Patmos platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
EhsanKhodadad committed Apr 12, 2024
1 parent 25ea199 commit 9d9239a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 106 deletions.
37 changes: 21 additions & 16 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include(${LF_ROOT}/core/lf_utils.cmake)
list(APPEND GENERAL_SOURCES tag.c clock.c port.c mixed_radix.c reactor_common.c lf_token.c environment.c)

# Add tracing support if requested
if (DEFINED LF_TRACE)
if(DEFINED LF_TRACE)
message(STATUS "Including sources specific to tracing.")
list(APPEND GENERAL_SOURCES tracepoint.c)
endif()
Expand All @@ -16,7 +16,7 @@ endif()
list(APPEND REACTORC_SOURCES ${GENERAL_SOURCES})

# Add sources for either threaded or single-threaded runtime
if (DEFINED FEDERATED)
if(DEFINED FEDERATED)
include(federated/CMakeLists.txt)
include(federated/network/CMakeLists.txt)
endif()
Expand All @@ -35,14 +35,14 @@ endif()

# Add sources for the local RTI if we are using scheduling enclaves
if(DEFINED LF_ENCLAVES)
include(federated/RTI/local_rti.cmake)
include(federated/RTI/local_rti.cmake)
endif()

# Include sources from subdirectories
include(utils/CMakeLists.txt)

if (DEFINED MODAL_REACTORS)
include(modal_models/CMakeLists.txt)
if(DEFINED MODAL_REACTORS)
include(modal_models/CMakeLists.txt)
endif()

# Print sources used for compilation
Expand All @@ -53,12 +53,14 @@ add_library(reactor-c)
target_sources(reactor-c PRIVATE ${REACTORC_SOURCES})
lf_enable_compiler_warnings(reactor-c)

if (DEFINED LF_TRACE)
if(DEFINED LF_TRACE)
include(${LF_ROOT}/trace/api/CMakeLists.txt)

if(NOT LF_TRACE_PLUGIN)
set(LF_TRACE_PLUGIN lf::trace-impl)
include(${LF_ROOT}/trace/impl/CMakeLists.txt)
endif()

message(STATUS "linking trace plugin library ${LF_TRACE_PLUGIN}")
target_link_libraries(reactor-c PUBLIC lf::trace-api)
target_link_libraries(reactor-c PRIVATE "${LF_TRACE_PLUGIN}")
Expand Down Expand Up @@ -93,34 +95,37 @@ target_include_directories(reactor-c PUBLIC ../include/core/threaded)
target_include_directories(reactor-c PUBLIC ../include/core/utils)
target_include_directories(reactor-c PUBLIC federated/RTI/)

if (APPLE)
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
if(APPLE)
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
endif()

# Link with OpenSSL library
if(DEFINED FEDERATED_AUTHENTICATED)
if (APPLE)
if(APPLE)
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)
endif()

find_package(OpenSSL REQUIRED)
target_link_libraries(reactor-c PUBLIC OpenSSL::SSL)
endif()

if(DEFINED _LF_CLOCK_SYNC_ON)
find_library(MATH_LIBRARY m)
if(MATH_LIBRARY)
target_link_libraries(reactor-c PUBLIC ${MATH_LIBRARY})
endif()
find_library(MATH_LIBRARY m)

if(MATH_LIBRARY)
target_link_libraries(reactor-c PUBLIC ${MATH_LIBRARY})
endif()
endif()

# Unless specified otherwise initial event queue and reaction queue to size 10
if (NOT DEFINED INITIAL_EVENT_QUEUE_SIZE)
if(NOT DEFINED INITIAL_EVENT_QUEUE_SIZE)
set(INITIAL_EVENT_QUEUE_SIZE 10)
endif()
if (NOT DEFINED INITIAL_REACT_QUEUE_SIZE)

if(NOT DEFINED INITIAL_REACT_QUEUE_SIZE)
set(INITIAL_REACT_QUEUE_SIZE 10)
endif()

Expand Down
37 changes: 0 additions & 37 deletions core/platform/CMakeLists.txt

This file was deleted.

4 changes: 2 additions & 2 deletions low_level_platform/api/low_level_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ int lf_critical_section_exit(environment_t* env);
#elif defined(PLATFORM_ZEPHYR)
#include "platform/lf_zephyr_support.h"
#elif defined(PLATFORM_NRF52)
#include "platform/lf_nrf52_support.h"
#include "platform/lf_nrf52_support.h"
#elif defined(PLATFORM_PATMOS)
#include "platform/lf_patmos_support.h"
#include "platform/lf_patmos_support.h"
#elif defined(PLATFORM_RP2040)
#include "platform/lf_rp2040_support.h"
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
Expand Down
16 changes: 7 additions & 9 deletions low_level_platform/api/platform/lf_patmos_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,24 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Patmos API support for the C target of Lingua Franca.
*
* This is based on lf_nrf_support.h in icyphy/lf-buckler.
*
* @author{Soroush Bateni <[email protected]>}
* @author{Abhi Gundrala <[email protected]>}
* @author{Shaokai Lin <[email protected]>}
*
* @author{Ehsan Khodadad <[email protected]>}
* @author{Luca Pezzarossa <[email protected]>}
* @author{Martin Schoeberl <[email protected]>}
*/

#ifndef LF_PATMOS_SUPPORT_H
#define LF_PATMOS_SUPPORT_H

#define LOG_LEVEL 2
// This embedded platform has no TTY suport
#define NO_TTY
#define NO_TTY

#include <stdint.h> // For fixed-width integral types
#include <time.h> // For CLOCK_MONOTONIC
#include <stdbool.h>

#include <inttypes.h> // Needed to define PRId64 and PRIu32
#include <inttypes.h> // Needed to define PRId64 and PRIu32
#define PRINTF_TIME "%" PRId64
#define PRINTF_MICROSTEP "%" PRIu32
#define PRINTF_TAG "(%" PRId64 ", %" PRIu32 ")"

#endif // LF_PATMOS_SUPPORT_H
#endif // LF_PATMOS_SUPPORT_H
9 changes: 9 additions & 0 deletions low_level_platform/impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Rp2040")
${CMAKE_CURRENT_LIST_DIR}/src/lf_rp2040_support.c
${CMAKE_CURRENT_LIST_DIR}/src/lf_atomic_irq.c
)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Patmos")
set(LF_LOW_LEVEL_PLATFORM_FILES
${CMAKE_CURRENT_LIST_DIR}/src/lf_patmos_support.c
${CMAKE_CURRENT_LIST_DIR}/src/lf_atomic_irq.c
)
else()
message(FATAL_ERROR "Your platform is not supported! The C target supports Linux, MacOS, Windows, Zephyr, Nrf52 and RP2040.")
endif()
Expand All @@ -53,11 +58,13 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr")
else()
message(STATUS "Building Zephyr library with Kernel clock ")
endif()

zephyr_library_named(lf-low-level-platform-impl)
zephyr_library_sources(${LF_LOW_LEVEL_PLATFORM_FILES})
zephyr_library_link_libraries(kernel)
else()
add_library(lf-low-level-platform-impl STATIC ${LF_LOW_LEVEL_PLATFORM_FILES})

# Link the platform to a threading library
if(NOT DEFINED LF_SINGLE_THREADED OR DEFINED LF_TRACE)
find_package(Threads REQUIRED)
Expand All @@ -73,12 +80,14 @@ target_link_libraries(lf-low-level-platform-impl PUBLIC lf-logging-api)

target_compile_definitions(lf-low-level-platform-impl PUBLIC PLATFORM_${CMAKE_SYSTEM_NAME})
message(STATUS "Applying preprocessor definitions to platform...")

macro(low_level_platform_define X)
if(DEFINED ${X})
message(STATUS ${X}=${${X}})
target_compile_definitions(lf-low-level-platform-impl PUBLIC ${X}=${${X}})
endif(DEFINED ${X})
endmacro()

low_level_platform_define(LF_SINGLE_THREADED)
low_level_platform_define(LOG_LEVEL)
low_level_platform_define(MODAL_REACTORS)
Expand Down
3 changes: 2 additions & 1 deletion low_level_platform/impl/src/lf_atomic_irq.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if defined(PLATFORM_ARDUINO) || defined(PLATFORM_NRF52) || defined(PLATFORM_ZEPHYR) || defined(PLATFORM_RP2040) || defined(PLATFORM_PATMOS)
#if defined(PLATFORM_ARDUINO) || defined(PLATFORM_NRF52) || defined(PLATFORM_ZEPHYR) || defined(PLATFORM_RP2040) || \
defined(PLATFORM_PATMOS)
/**
* @author Erling Rennemo Jellum
* @copyright (c) 2023
Expand Down
78 changes: 37 additions & 41 deletions low_level_platform/impl/src/lf_patmos_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,75 @@

// Keep track of physical actions being entered into the system
static volatile bool _lf_async_event = false;

// Keep track of whether we are in a critical section or not
static volatile int _lf_num_nested_critical_sections = 0;
/**
* @brief Sleep until an absolute time.
* TODO: For improved power consumption this should be implemented with a HW timer and interrupts.
*
* Since there is no sleep mode in Patmos, and energy saving is not important for real-time systems,
* we just used a busy sleep.
*
* @param wakeup int64_t time of wakeup
* @return int 0 if successful sleep, -1 if awoken by async event
*/

int _lf_interruptable_sleep_until_locked(environment_t* env, instant_t wakeup) {
instant_t now;
_lf_async_event = false;
lf_enable_interrupts_nested();
instant_t now;
_lf_async_event = false;
lf_enable_interrupts_nested();

// Do busy sleep
do {
_lf_clock_gettime(&now);
} while ((now < wakeup) && !_lf_async_event);
// Do busy sleep
do {
_lf_clock_gettime(&now);
} while ((now < wakeup) && !_lf_async_event);

lf_disable_interrupts_nested();
lf_disable_interrupts_nested();

if (_lf_async_event) {
_lf_async_event = false;
return -1;
} else {
return 0;
}
if (_lf_async_event) {
_lf_async_event = false;
return -1;
} else {
return 0;
}
}

/**
* Patmos clock does not need initialization.
*/
void _lf_initialize_clock() {

}
void _lf_initialize_clock() {}

/**
* Write the current time in nanoseconds into the location given by the argument.
* This returns 0 (it never fails, assuming the argument gives a valid memory location).
* This has to be called at least once per 35 minutes to properly handle overflows of the 32-bit clock.
* TODO: This is only addressable by setting up interrupts on a timer peripheral to occur at wrap.
*/

int _lf_clock_gettime(instant_t* t) {

assert(t != NULL);
assert(t != NULL);

*t = get_cpu_usecs() * 1000;
return 0;
*t = get_cpu_usecs() * 1000;

return 0;
}

#if defined(LF_SINGLE_THREADED)

int lf_enable_interrupts_nested() {
intr_enable();
return 0;
}
int lf_disable_interrupts_nested() {
if (_lf_num_nested_critical_sections++ == 0) {
intr_disable();
return 0;
}
return 0;
}

#endif
// Overwrite print functions with NoOp.
int puts(const char *str) {}

#if 0
int lf_enable_interrupts_nested() {
if (_lf_num_nested_critical_sections <= 0) {
return 1;
}

int printf(const char *format, ...) {}
int sprintf(char *str, const char *format, ...) {}
int snprintf(char *str, size_t size, const char *format, ...) {}
int vprintf(const char *format, va_list ap) {}
int vfprintf(FILE *stream, const char *format, va_list arg) {}
if (--_lf_num_nested_critical_sections == 0) {
intr_enable();
}
return 0;
}

#endif
#endif

0 comments on commit 9d9239a

Please sign in to comment.