diff --git a/low_level_platform/api/low_level_platform.h b/low_level_platform/api/low_level_platform.h index 55373d071..212229db0 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(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) 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 f13ec4a2e..f8ccb31d8 100644 --- a/low_level_platform/impl/CMakeLists.txt +++ b/low_level_platform/impl/CMakeLists.txt @@ -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() diff --git a/low_level_platform/impl/src/lf_atomic_irq.c b/low_level_platform/impl/src/lf_atomic_irq.c index b65b5e76a..406d7ffeb 100644 --- a/low_level_platform/impl/src/lf_atomic_irq.c +++ b/low_level_platform/impl/src/lf_atomic_irq.c @@ -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 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