diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ed090be..11c5b46d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,9 @@ elseif (PLATFORM STREQUAL "ZEPHYR") elseif (PLATFORM STREQUAL "PICO") add_library(reactor-uc STATIC ${SOURCES}) target_link_libraries(reactor-uc PUBLIC pico_stdlib pico_sync) + +elseif (PLATFORM STREQUAL "PATMOS") + add_library(reactor-uc STATIC ${SOURCES}) else () message(FATAL_ERROR "No valid platform specified") endif () diff --git a/examples/patmos/CMakeLists.txt b/examples/patmos/CMakeLists.txt index 2c20226d..79d6327f 100644 --- a/examples/patmos/CMakeLists.txt +++ b/examples/patmos/CMakeLists.txt @@ -1,15 +1,7 @@ cmake_minimum_required(VERSION 3.22) -if(NOT DEFINED ENV{FP_SDK_PATH}) - message(FATAL_ERROR "FP_SDK_PATH environment variable not set!") -endif() +project(patmos) -include($ENV{FP_SDK_PATH}/cmake/riscv-toolchain.cmake) -include($ENV{FP_SDK_PATH}/cmake/fp-app.cmake) - -project(fp-lf) - -add_executable(fp-smoke src/main.c) +add_executable(patmos src/main.c) add_subdirectory(src-gen/Smoke) -target_link_libraries(fp-smoke PUBLIC Smoke) -fp_add_outputs(fp-smoke) +target_link_libraries(patmos PUBLIC Smoke) diff --git a/examples/patmos/src/main.c b/examples/patmos/src/main.c new file mode 100644 index 00000000..8417d948 --- /dev/null +++ b/examples/patmos/src/main.c @@ -0,0 +1,5 @@ +#include "lf_main.h" + +int main() { + lf_start(); +} diff --git a/src/federated.c b/src/federated.c index b2e17540..ca2ffd25 100644 --- a/src/federated.c +++ b/src/federated.c @@ -3,7 +3,7 @@ #include "reactor-uc/logging.h" #include "reactor-uc/platform.h" -#pragma GCC diagnostic ignored "-Wstack-usage=" +//#pragma GCC diagnostic ignored "-Wstack-usage=" THIS causes some problems with patmos-clang // TODO: Refactor so this function is available void LogicalConnection_trigger_downstreams(Connection *self, const void *value, size_t value_size); diff --git a/src/network_channel.c b/src/network_channel.c index 6ef0f6c5..0dfc17c6 100644 --- a/src/network_channel.c +++ b/src/network_channel.c @@ -26,6 +26,10 @@ #error "NETWORK_POSIC_TCP not supported on FlexPRET" #endif +#elif defined(PLATFORM_PATMOS) +#ifdef NETWORK_CHANNEL_TCP_POSIX +#error "NETWORK_POSIC_TCP not supported on FlexPRET" +#endif #else #error "Platform not supported" #endif diff --git a/src/platform.c b/src/platform.c index 2c7776fe..ad2bb9c4 100644 --- a/src/platform.c +++ b/src/platform.c @@ -1,6 +1,5 @@ #undef PLATFORM_POSIX -#define PLATFORM_PATMOS #if defined(PLATFORM_POSIX) #include "platform/posix/posix.c" diff --git a/src/platform/patmos/patmos.c b/src/platform/patmos/patmos.c index 2958a4b5..2f32f770 100644 --- a/src/platform/patmos/patmos.c +++ b/src/platform/patmos/patmos.c @@ -2,6 +2,7 @@ #include #include #include + #include #include @@ -14,7 +15,8 @@ void Platform_vprintf(const char *fmt, va_list args) { vprintf(fmt, args); } -lf_ret_t PlatformRiot_initialize(Platform *self) { +lf_ret_t PlatformPatmos_initialize(Platform *self) { + (void)self; //TODO: return LF_OK; } @@ -28,50 +30,46 @@ instant_t PlatformRiot_get_physical_time(Platform *self) { lf_ret_t PlatformRiot_wait_until_interruptible(Platform *untyped_self, instant_t wakeup_time) { PlatformPatmos* self = (PlatformPatmos*)untyped_self; self->async_event = false; - self->leave_critical_section(self); // turing on interrupts + untyped_self->leave_critical_section(untyped_self); // turing on interrupts - instant_t now = self->get_physical_time(self); - instant_t wakeup = now + sleep_duration; + instant_t now = untyped_self->get_physical_time(untyped_self); // Do busy sleep do { - now = self->get_physical_time(self); - } while ((now < wakeup) && !self->async_event); + now = untyped_self->get_physical_time(untyped_self); + } while ((now < wakeup_time) && !self->async_event); - self->enter_critical_section(self) + untyped_self->enter_critical_section(untyped_self); if (self->async_event) { self->async_event = false; - return -1; + return LF_ERR; } else { - return 0; + return LF_OK; } - interval_t sleep_duration = wakeup_time - self->get_physical_time(self); + interval_t sleep_duration = wakeup_time - untyped_self->get_physical_time(untyped_self); if (sleep_duration < 0) { return LF_OK; } - self->leave_critical_section(self); - int ret = ztimer64_mutex_lock_until(ZTIMER64_USEC, &((PlatformRiot *)self)->lock, NSEC_TO_USEC(wakeup_time)); - self->enter_critical_section(self); + untyped_self->leave_critical_section(untyped_self); - if (ret == 0) { - // the mutex was unlocked from IRQ (no timeout occurred) - return LF_SLEEP_INTERRUPTED; - } else { - return LF_OK; - } + return LF_OK; } -lf_ret_t PlatformRiot_wait_until(Platform *self, instant_t wakeup_time) { - interval_t sleep_duration = wakeup_time - self->get_physical_time(self); +lf_ret_t PlatformRiot_wait_until(Platform *untyped_self, instant_t wakeup_time) { + interval_t sleep_duration = wakeup_time - untyped_self->get_physical_time(untyped_self); if (sleep_duration < 0) { return LF_OK; } +instant_t now = untyped_self->get_physical_time(untyped_self); - ztimer64_sleep_until(ZTIMER64_USEC, NSEC_TO_USEC(wakeup_time)); + // Do busy sleep + do { + now = untyped_self->get_physical_time(untyped_self); + } while (now < wakeup_time); return LF_OK; } @@ -82,7 +80,7 @@ lf_ret_t PlatformRiot_wait_for(Platform *self, interval_t duration) { } instant_t now = self->get_physical_time(self); - instant_t wakeup = now + sleep_duration; + instant_t wakeup = now + duration; // Do busy sleep do { @@ -93,13 +91,13 @@ lf_ret_t PlatformRiot_wait_for(Platform *self, interval_t duration) { } void PlatformRiot_leave_critical_section(Platform *self) { + (void)self; intr_enable(); - return 0; } void PlatformRiot_enter_critical_section(Platform *self) { + (void)self; intr_disable(); - return 0; } void PlatformPatmos_new_async_event(Platform *self) { @@ -107,14 +105,14 @@ void PlatformPatmos_new_async_event(Platform *self) { } void Platform_ctor(Platform *self) { - self->initialize = PlatformRiot_initialize; + self->initialize = PlatformPatmos_initialize; self->enter_critical_section = PlatformRiot_enter_critical_section; self->leave_critical_section = PlatformRiot_leave_critical_section; self->get_physical_time = PlatformRiot_get_physical_time; self->wait_until = PlatformRiot_wait_until; self->wait_for = PlatformRiot_wait_for; self->wait_until_interruptible = PlatformRiot_wait_until_interruptible; - self->new_async_event = PlatformRiot_new_async_event; + self->new_async_event = PlatformPatmos_new_async_event; } Platform *Platform_new(void) { return (Platform *)&platform; }