From 3a0e84aa3a92be4b28e68cce88618091e70931ab Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Wed, 21 Feb 2024 11:46:00 +0100 Subject: [PATCH 1/8] Support for Patmos Platform --- core/platform/CMakeLists.txt | 37 ++++++++ low_level_platform/api/low_level_platform.h | 4 +- .../api/platform/lf_patmos_support.h | 54 ++++++++++++ low_level_platform/impl/src/lf_atomic_irq.c | 2 +- .../impl/src/lf_patmos_support.c | 87 +++++++++++++++++++ 5 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 core/platform/CMakeLists.txt create mode 100644 low_level_platform/api/platform/lf_patmos_support.h create mode 100644 low_level_platform/impl/src/lf_patmos_support.c diff --git a/core/platform/CMakeLists.txt b/core/platform/CMakeLists.txt new file mode 100644 index 000000000..479cd448b --- /dev/null +++ b/core/platform/CMakeLists.txt @@ -0,0 +1,37 @@ +# Check which system we are running on to select the correct platform support +# file and assign the file's path to LF_PLATFORM_FILE + +set(LF_PLATFORM_FILES + lf_unix_clock_support.c + lf_unix_syscall_support.c + lf_linux_support.c + lf_macos_support.c + lf_windows_support.c + lf_nrf52_support.c + lf_zephyr_support.c + lf_zephyr_clock_counter.c + lf_zephyr_clock_kernel.c + lf_rp2040_support.c + lf_patmos_support.c + lf_atomic_windows.c + lf_atomic_gcc_clang.c + lf_atomic_irq.c +) + +if(${CMAKE_SYSTEM_NAME} STREQUAL "Nrf52") + list(APPEND REACTORC_COMPILE_DEFS PLATFORM_NRF52) +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr") + list(APPEND REACTORC_COMPILE_DEFS PLATFORM_ZEPHYR) + set(PLATFORM_ZEPHYR true) +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Rp2040") + list(APPEND REACTORC_COMPILE_DEFS PLATFORM_RP2040) +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Patmos") + list(APPEND REACTORC_COMPILE_DEFS PLATFORM_PATMOS) + set(PLATFORM_PATMOS true) +endif() + +# Prepend all sources with platform +list(TRANSFORM LF_PLATFORM_FILES PREPEND platform/) + +# Add sources to the list for debug info +list(APPEND REACTORC_SOURCES ${LF_PLATFORM_FILES}) diff --git a/low_level_platform/api/low_level_platform.h b/low_level_platform/api/low_level_platform.h index 9611870cc..84b675fe0 100644 --- a/low_level_platform/api/low_level_platform.h +++ b/low_level_platform/api/low_level_platform.h @@ -47,7 +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" #elif defined(PLATFORM_RP2040) #include "platform/lf_rp2040_support.h" #elif defined(PLATFORM_FLEXPRET) diff --git a/low_level_platform/api/platform/lf_patmos_support.h b/low_level_platform/api/platform/lf_patmos_support.h new file mode 100644 index 000000000..9e434f2f6 --- /dev/null +++ b/low_level_platform/api/platform/lf_patmos_support.h @@ -0,0 +1,54 @@ + +/* Patmos API support for the C target of Lingua Franca. */ + +/************* +Copyright (c) 2024, The University of California at Berkeley. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +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 } + * @author{Abhi Gundrala } + * @author{Shaokai Lin } + */ + +#ifndef LF_PATMOS_SUPPORT_H +#define LF_PATMOS_SUPPORT_H + +#define LOG_LEVEL 2 +// This embedded platform has no TTY suport +#define NO_TTY + +#include // For fixed-width integral types +#include // For CLOCK_MONOTONIC +#include + +#include // Needed to define PRId64 and PRIu32 +#define PRINTF_TIME "%" PRId64 +#define PRINTF_MICROSTEP "%" PRIu32 +#define PRINTF_TAG "(%" PRId64 ", %" PRIu32 ")" + +#endif // LF_PATMOS_SUPPORT_H \ No newline at end of file diff --git a/low_level_platform/impl/src/lf_atomic_irq.c b/low_level_platform/impl/src/lf_atomic_irq.c index 2854a6f11..3a9d72086 100644 --- a/low_level_platform/impl/src/lf_atomic_irq.c +++ b/low_level_platform/impl/src/lf_atomic_irq.c @@ -1,5 +1,5 @@ #if defined(PLATFORM_ARDUINO) || defined(PLATFORM_NRF52) || defined(PLATFORM_ZEPHYR) || defined(PLATFORM_RP2040) || \ - defined(PLATFORM_FLEXPRET) + defined(PLATFORM_FLEXPRET) || defined(PLATFORM_PATMOS) /** * @author Erling Rennemo Jellum * @copyright (c) 2023 diff --git a/low_level_platform/impl/src/lf_patmos_support.c b/low_level_platform/impl/src/lf_patmos_support.c new file mode 100644 index 000000000..434b218de --- /dev/null +++ b/low_level_platform/impl/src/lf_patmos_support.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include "../platform.h" +#include +#include +#include + +// Keep track of physical actions being entered into the system +static volatile bool _lf_async_event = false; + +/** + * @brief Sleep until an absolute time. + * TODO: For improved power consumption this should be implemented with a HW timer and interrupts. + * + * @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(); + + // Do busy sleep + do { + _lf_clock_gettime(&now); + } while ((now < wakeup) && !_lf_async_event); + + lf_disable_interrupts_nested(); + + if (_lf_async_event) { + _lf_async_event = false; + return -1; + } else { + return 0; + } +} + +/** + * Patmos clock does not need initialization. + */ +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); + + *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() { + intr_disable(); + return 0; +} + +#endif +// Overwrite print functions with NoOp. +int puts(const char *str) {} + +#if 0 + +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) {} + +#endif \ No newline at end of file From 186cb68865372a92eed09d951a448c77256dbcbb Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Tue, 12 Mar 2024 14:02:12 +0100 Subject: [PATCH 2/8] Support for Patmos platform. --- core/CMakeLists.txt | 26 +++++++------ core/platform/CMakeLists.txt | 37 ------------------- .../api/platform/lf_patmos_support.h | 8 ++-- low_level_platform/impl/CMakeLists.txt | 3 ++ .../impl/src/lf_patmos_support.c | 34 ++++++++--------- 5 files changed, 36 insertions(+), 72 deletions(-) delete mode 100644 core/platform/CMakeLists.txt diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index ca51fd50c..6d938ae0c 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -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() @@ -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() @@ -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 @@ -53,7 +53,7 @@ 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) target_link_libraries(reactor-c PUBLIC lf::trace-api) # If the user specified an external trace plugin. Find it and link with it @@ -106,18 +106,19 @@ 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 " Scr ") +if(APPLE) + SET(CMAKE_C_ARCHIVE_CREATE " Scr ") SET(CMAKE_CXX_ARCHIVE_CREATE " Scr ") - SET(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") + SET(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") SET(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") 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() @@ -130,10 +131,11 @@ if(DEFINED FEDERATED) 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() diff --git a/core/platform/CMakeLists.txt b/core/platform/CMakeLists.txt deleted file mode 100644 index 479cd448b..000000000 --- a/core/platform/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Check which system we are running on to select the correct platform support -# file and assign the file's path to LF_PLATFORM_FILE - -set(LF_PLATFORM_FILES - lf_unix_clock_support.c - lf_unix_syscall_support.c - lf_linux_support.c - lf_macos_support.c - lf_windows_support.c - lf_nrf52_support.c - lf_zephyr_support.c - lf_zephyr_clock_counter.c - lf_zephyr_clock_kernel.c - lf_rp2040_support.c - lf_patmos_support.c - lf_atomic_windows.c - lf_atomic_gcc_clang.c - lf_atomic_irq.c -) - -if(${CMAKE_SYSTEM_NAME} STREQUAL "Nrf52") - list(APPEND REACTORC_COMPILE_DEFS PLATFORM_NRF52) -elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr") - list(APPEND REACTORC_COMPILE_DEFS PLATFORM_ZEPHYR) - set(PLATFORM_ZEPHYR true) -elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Rp2040") - list(APPEND REACTORC_COMPILE_DEFS PLATFORM_RP2040) -elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Patmos") - list(APPEND REACTORC_COMPILE_DEFS PLATFORM_PATMOS) - set(PLATFORM_PATMOS true) -endif() - -# Prepend all sources with platform -list(TRANSFORM LF_PLATFORM_FILES PREPEND platform/) - -# Add sources to the list for debug info -list(APPEND REACTORC_SOURCES ${LF_PLATFORM_FILES}) diff --git a/low_level_platform/api/platform/lf_patmos_support.h b/low_level_platform/api/platform/lf_patmos_support.h index 9e434f2f6..fed5ac853 100644 --- a/low_level_platform/api/platform/lf_patmos_support.h +++ b/low_level_platform/api/platform/lf_patmos_support.h @@ -30,20 +30,18 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This is based on lf_nrf_support.h in icyphy/lf-buckler. * - * @author{Soroush Bateni } - * @author{Abhi Gundrala } - * @author{Shaokai Lin } + * @author{Ehsan Khodadad } + * @author{Luca Pezzarossa } + * @author{Martin Schoeberl } */ #ifndef LF_PATMOS_SUPPORT_H #define LF_PATMOS_SUPPORT_H -#define LOG_LEVEL 2 // This embedded platform has no TTY suport #define NO_TTY #include // For fixed-width integral types -#include // For CLOCK_MONOTONIC #include #include // Needed to define PRId64 and PRIu32 diff --git a/low_level_platform/impl/CMakeLists.txt b/low_level_platform/impl/CMakeLists.txt index c0f2d8bb5..33315be2d 100644 --- a/low_level_platform/impl/CMakeLists.txt +++ b/low_level_platform/impl/CMakeLists.txt @@ -56,6 +56,7 @@ 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) @@ -95,6 +96,7 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FlexPRET") endif() 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) @@ -116,6 +118,7 @@ macro(low_level_platform_define 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) diff --git a/low_level_platform/impl/src/lf_patmos_support.c b/low_level_platform/impl/src/lf_patmos_support.c index 434b218de..f7efba220 100644 --- a/low_level_platform/impl/src/lf_patmos_support.c +++ b/low_level_platform/impl/src/lf_patmos_support.c @@ -9,7 +9,8 @@ // 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. @@ -63,25 +64,22 @@ int _lf_clock_gettime(instant_t* t) { #if defined(LF_SINGLE_THREADED) -int lf_enable_interrupts_nested() { - intr_enable(); - return 0; -} int lf_disable_interrupts_nested() { - intr_disable(); - return 0; + if (_lf_num_nested_critical_sections++ == 0) { + intr_disable(); + } + return 0; } -#endif -// Overwrite print functions with NoOp. -int puts(const char *str) {} - -#if 0 - -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) {} +int lf_enable_interrupts_nested() { + if (_lf_num_nested_critical_sections <= 0) { + return 1; + } + + if (--_lf_num_nested_critical_sections == 0) { + intr_enable(); + } + return 0; +} #endif \ No newline at end of file From 9a0939527e72616629c767ceb677f9b7d16c6ffd Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Wed, 3 Apr 2024 16:52:13 +0200 Subject: [PATCH 3/8] Update low_level_platform/impl/src/lf_patmos_support.c Co-authored-by: Marten Lohstroh --- low_level_platform/impl/src/lf_patmos_support.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/low_level_platform/impl/src/lf_patmos_support.c b/low_level_platform/impl/src/lf_patmos_support.c index f7efba220..8bdf6d579 100644 --- a/low_level_platform/impl/src/lf_patmos_support.c +++ b/low_level_platform/impl/src/lf_patmos_support.c @@ -82,4 +82,4 @@ int lf_enable_interrupts_nested() { return 0; } -#endif \ No newline at end of file +#endif From c2e260fa25135f1abdae555d37bc7f1d3173fc1d Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Wed, 3 Apr 2024 16:52:22 +0200 Subject: [PATCH 4/8] Update low_level_platform/api/platform/lf_patmos_support.h Co-authored-by: Marten Lohstroh --- low_level_platform/api/platform/lf_patmos_support.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/low_level_platform/api/platform/lf_patmos_support.h b/low_level_platform/api/platform/lf_patmos_support.h index fed5ac853..b71fff856 100644 --- a/low_level_platform/api/platform/lf_patmos_support.h +++ b/low_level_platform/api/platform/lf_patmos_support.h @@ -49,4 +49,4 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define PRINTF_MICROSTEP "%" PRIu32 #define PRINTF_TAG "(%" PRId64 ", %" PRIu32 ")" -#endif // LF_PATMOS_SUPPORT_H \ No newline at end of file +#endif // LF_PATMOS_SUPPORT_H From f14f319003025a40f22c4b2908b9132c380d7a19 Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Fri, 12 Apr 2024 17:08:32 +0200 Subject: [PATCH 5/8] Support for Patmos platform.. --- low_level_platform/api/low_level_platform.h | 4 +- .../api/platform/lf_patmos_support.h | 8 +-- low_level_platform/impl/CMakeLists.txt | 5 ++ .../impl/src/lf_patmos_support.c | 69 +++++++++---------- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/low_level_platform/api/low_level_platform.h b/low_level_platform/api/low_level_platform.h index 84b675fe0..afffd2a9e 100644 --- a/low_level_platform/api/low_level_platform.h +++ b/low_level_platform/api/low_level_platform.h @@ -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(PLATFORM_FLEXPRET) diff --git a/low_level_platform/api/platform/lf_patmos_support.h b/low_level_platform/api/platform/lf_patmos_support.h index b71fff856..afd7e1ce0 100644 --- a/low_level_platform/api/platform/lf_patmos_support.h +++ b/low_level_platform/api/platform/lf_patmos_support.h @@ -29,9 +29,9 @@ 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{Ehsan Khodadad } - * @author{Luca Pezzarossa } + * @author{Luca Pezzarossa } * @author{Martin Schoeberl } */ @@ -39,12 +39,12 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define LF_PATMOS_SUPPORT_H // This embedded platform has no TTY suport -#define NO_TTY +#define NO_TTY #include // For fixed-width integral types #include -#include // Needed to define PRId64 and PRIu32 +#include // Needed to define PRId64 and PRIu32 #define PRINTF_TIME "%" PRId64 #define PRINTF_MICROSTEP "%" PRIu32 #define PRINTF_TAG "(%" PRId64 ", %" PRIu32 ")" diff --git a/low_level_platform/impl/CMakeLists.txt b/low_level_platform/impl/CMakeLists.txt index 33315be2d..e47903b6a 100644 --- a/low_level_platform/impl/CMakeLists.txt +++ b/low_level_platform/impl/CMakeLists.txt @@ -44,6 +44,11 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FlexPRET") ${CMAKE_CURRENT_LIST_DIR}/src/lf_flexpret_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 FlexPRET, Linux, MacOS, nRF52, RP2040, Windows, and Zephyr.") endif() diff --git a/low_level_platform/impl/src/lf_patmos_support.c b/low_level_platform/impl/src/lf_patmos_support.c index 8bdf6d579..90c043776 100644 --- a/low_level_platform/impl/src/lf_patmos_support.c +++ b/low_level_platform/impl/src/lf_patmos_support.c @@ -13,73 +13,70 @@ static volatile bool _lf_async_event = false; 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_disable_interrupts_nested() { - if (_lf_num_nested_critical_sections++ == 0) { - intr_disable(); - } - return 0; + if (_lf_num_nested_critical_sections++ == 0) { + intr_disable(); + } + return 0; } int lf_enable_interrupts_nested() { - if (_lf_num_nested_critical_sections <= 0) { - return 1; - } - - if (--_lf_num_nested_critical_sections == 0) { - intr_enable(); - } - return 0; + if (_lf_num_nested_critical_sections <= 0) { + return 1; + } + + if (--_lf_num_nested_critical_sections == 0) { + intr_enable(); + } + return 0; } #endif From 4646de6ac4546be8679a63c2c4cedcc3060aa06f Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Fri, 19 Apr 2024 15:05:02 +0200 Subject: [PATCH 6/8] Update low_level_platform/impl/src/lf_patmos_support.c Co-authored-by: erling --- low_level_platform/impl/src/lf_patmos_support.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/low_level_platform/impl/src/lf_patmos_support.c b/low_level_platform/impl/src/lf_patmos_support.c index 90c043776..d1d1f8050 100644 --- a/low_level_platform/impl/src/lf_patmos_support.c +++ b/low_level_platform/impl/src/lf_patmos_support.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include "../platform.h" +#include "platform/lf_patmos_support.h" +#include "low_level_platform.h" #include #include #include From ec9b96a9fbf988d9f8e967e51c807d37995af2ab Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Fri, 19 Apr 2024 16:13:05 +0200 Subject: [PATCH 7/8] #if defined(PLATFORM_PATMOS) added to lf_patmos_support.c --- .../impl/src/lf_patmos_support.c | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/low_level_platform/impl/src/lf_patmos_support.c b/low_level_platform/impl/src/lf_patmos_support.c index d1d1f8050..fdfee79e7 100644 --- a/low_level_platform/impl/src/lf_patmos_support.c +++ b/low_level_platform/impl/src/lf_patmos_support.c @@ -1,3 +1,33 @@ +#if defined(PLATFORM_PATMOS) +/************* +Copyright (c) 2024, The University of California at Berkeley. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***************/ + +/** + * @author{Ehsan Khodadad } + * @author{Luca Pezzarossa } + * @author{Martin Schoeberl } + */ #include #include #include @@ -79,4 +109,6 @@ int lf_enable_interrupts_nested() { return 0; } -#endif +#endif // LF_SINGLE_THREADED + +#endif // PLATFORM_PATMOS From 7b4408fe8979a92e5f7701b008a2f9f4a6fe80b6 Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Fri, 2 Aug 2024 14:52:14 +0200 Subject: [PATCH 8/8] Support for Patmos Platform --- low_level_platform/api/CMakeLists.txt | 2 ++ low_level_platform/impl/CMakeLists.txt | 4 +++- low_level_platform/impl/src/lf_patmos_support.c | 4 ++++ platform/impl/CMakeLists.txt | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/low_level_platform/api/CMakeLists.txt b/low_level_platform/api/CMakeLists.txt index 9f2172bce..599f87e59 100644 --- a/low_level_platform/api/CMakeLists.txt +++ b/low_level_platform/api/CMakeLists.txt @@ -7,6 +7,8 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "nRF52") target_compile_definitions(lf-low-level-platform-api INTERFACE PLATFORM_NRF52) elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr") target_compile_definitions(lf-low-level-platform-api INTERFACE PLATFORM_ZEPHYR) +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Patmos") + target_compile_definitions(lf-low-level-platform-api INTERFACE PLATFORM_PATMOS) elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Rp2040") target_compile_definitions(lf-low-level-platform-api INTERFACE PLATFORM_RP2040) target_link_libraries(lf-low-level-platform-api INTERFACE pico_stdlib) diff --git a/low_level_platform/impl/CMakeLists.txt b/low_level_platform/impl/CMakeLists.txt index e47903b6a..ac035dcf4 100644 --- a/low_level_platform/impl/CMakeLists.txt +++ b/low_level_platform/impl/CMakeLists.txt @@ -50,7 +50,7 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Patmos") ${CMAKE_CURRENT_LIST_DIR}/src/lf_atomic_irq.c ) else() - message(FATAL_ERROR "Your platform is not supported! The C target supports FlexPRET, Linux, MacOS, nRF52, RP2040, Windows, and Zephyr.") + message(FATAL_ERROR "Your platform is not supported! The C target supports FlexPRET, Patmos, Linux, MacOS, nRF52, RP2040, Windows, and Zephyr.") endif() list(APPEND LF_LOW_LEVEL_PLATFORM_FILES ${CMAKE_CURRENT_LIST_DIR}/src/lf_platform_util.c) @@ -99,6 +99,8 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FlexPRET") ) endif() endif() +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Patmos") + add_library(lf-low-level-platform-impl STATIC ${LF_LOW_LEVEL_PLATFORM_FILES}) else() add_library(lf-low-level-platform-impl STATIC ${LF_LOW_LEVEL_PLATFORM_FILES}) diff --git a/low_level_platform/impl/src/lf_patmos_support.c b/low_level_platform/impl/src/lf_patmos_support.c index fdfee79e7..43f20710c 100644 --- a/low_level_platform/impl/src/lf_patmos_support.c +++ b/low_level_platform/impl/src/lf_patmos_support.c @@ -109,6 +109,10 @@ int lf_enable_interrupts_nested() { return 0; } +int _lf_single_threaded_notify_of_event() { + _lf_async_event = true; + return 0; +} #endif // LF_SINGLE_THREADED #endif // PLATFORM_PATMOS diff --git a/platform/impl/CMakeLists.txt b/platform/impl/CMakeLists.txt index 32753e7eb..3c86b3817 100644 --- a/platform/impl/CMakeLists.txt +++ b/platform/impl/CMakeLists.txt @@ -9,6 +9,9 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FlexPRET") add_library(lf-platform-impl STATIC) target_sources(lf-platform-impl PUBLIC ${LF_PLATFORM_FILES}) target_link_libraries(lf-platform-impl PRIVATE fp-sdk) +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Patmos") + add_library(lf-platform-impl STATIC) + target_sources(lf-platform-impl PUBLIC ${LF_PLATFORM_FILES}) else() add_library(lf-platform-impl STATIC) target_sources(lf-platform-impl PUBLIC ${LF_PLATFORM_FILES})