diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2c757d8..298a3ec7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,9 @@ jobs: # - name: Setup upterm session # uses: lhotari/action-upterm@v1 - name: Format check - run: make format-check + run: | + clang-format --version + make format-check - name: Run unit tests run: make unit-test @@ -51,4 +53,4 @@ jobs: lcov-file: build/coverage.info delete-old-comments: true github-token: ${{ secrets.GITHUB_TOKEN }} - if: ${{ github.event_name == 'pull_request' }} \ No newline at end of file + if: ${{ github.event_name == 'pull_request' }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 05a8e253..9d3b0461 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/include/reactor-uc/platform/patmos/patmos.h b/include/reactor-uc/platform/patmos/patmos.h new file mode 100644 index 00000000..dc7ece09 --- /dev/null +++ b/include/reactor-uc/platform/patmos/patmos.h @@ -0,0 +1,13 @@ +#ifndef REACTOR_UC_PLATFORM_PATMOS_H +#define REACTOR_UC_PLATFORM_PATMOS_H + +#include "reactor-uc/platform.h" +#include "stdbool.h" + +typedef struct { + Platform super; + bool async_event; +} PlatformPatmos; + +void PlatformPatmos_ctor(Platform *self); +#endif diff --git a/src/federated.c b/src/federated.c index e9199a8f..35e3780c 100644 --- a/src/federated.c +++ b/src/federated.c @@ -314,4 +314,4 @@ void FederatedConnectionBundle_validate(FederatedConnectionBundle *bundle) { validate(bundle->serialize_hooks[i]); validate(bundle->outputs[i]->super.super.parent); } -} \ No newline at end of file +} diff --git a/src/network_channel.c b/src/network_channel.c index dc9c91cd..27d29322 100644 --- a/src/network_channel.c +++ b/src/network_channel.c @@ -28,6 +28,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 b81736cb..b5b506a8 100644 --- a/src/platform.c +++ b/src/platform.c @@ -1,3 +1,4 @@ + #if defined(PLATFORM_POSIX) #include "platform/posix/posix.c" #elif defined(PLATFORM_RIOT) @@ -8,6 +9,8 @@ #include "platform/flexpret/flexpret.c" #elif defined(PLATFORM_PICO) #include "platform/pico/pico.c" +#elif defined(PLATFORM_PATMOS) +#include "platform/patmos/patmos.c" #else #error "NO PLATFORM SPECIFIED" #endif diff --git a/src/platform/patmos/patmos.c b/src/platform/patmos/patmos.c new file mode 100644 index 00000000..7ca6bde0 --- /dev/null +++ b/src/platform/patmos/patmos.c @@ -0,0 +1,109 @@ +#include "reactor-uc/platform/patmos/patmos.h" +#include +#include +#include + +#include +#include + +static PlatformPatmos platform; + +void Platform_vprintf(const char *fmt, va_list args) { vprintf(fmt, args); } + +lf_ret_t PlatformPatmos_initialize(Platform *self) { + (void)self; + return LF_OK; +} + +instant_t PlatformPatmos_get_physical_time(Platform *self) { + (void)self; + return USEC(get_cpu_usecs()); +} + +lf_ret_t PlatformPatmos_wait_until_interruptible(Platform *untyped_self, instant_t wakeup_time) { + PlatformPatmos *self = (PlatformPatmos *)untyped_self; + self->async_event = false; + untyped_self->leave_critical_section(untyped_self); // turing on interrupts + + instant_t now = untyped_self->get_physical_time(untyped_self); + + // Do busy sleep + do { + now = untyped_self->get_physical_time(untyped_self); + } while ((now < wakeup_time) && !self->async_event); + + untyped_self->enter_critical_section(untyped_self); + + if (self->async_event) { + self->async_event = false; + return LF_ERR; + } else { + return LF_OK; + } + + interval_t sleep_duration = wakeup_time - untyped_self->get_physical_time(untyped_self); + if (sleep_duration < 0) { + return LF_OK; + } + + untyped_self->leave_critical_section(untyped_self); + + return LF_OK; +} + +lf_ret_t PlatformPatmos_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); + + // Do busy sleep + do { + now = untyped_self->get_physical_time(untyped_self); + } while (now < wakeup_time); + return LF_OK; +} + +lf_ret_t PlatformPatmos_wait_for(Platform *self, interval_t duration) { + (void)self; + if (duration <= 0) { + return LF_OK; + } + + instant_t now = self->get_physical_time(self); + instant_t wakeup = now + duration; + + // Do busy sleep + do { + now = self->get_physical_time(self); + } while ((now < wakeup)); + + return LF_OK; +} + +void PlatformPatmos_leave_critical_section(Platform *self) { + (void)self; + intr_enable(); +} + +void PlatformPatmos_enter_critical_section(Platform *self) { + (void)self; + intr_disable(); +} + +void PlatformPatmos_new_async_event(Platform *self) { ((PlatformPatmos *)self)->async_event = true; } + +void Platform_ctor(Platform *self) { + self->initialize = PlatformPatmos_initialize; + self->enter_critical_section = PlatformPatmos_enter_critical_section; + self->leave_critical_section = PlatformPatmos_leave_critical_section; + self->get_physical_time = PlatformPatmos_get_physical_time; + self->wait_until = PlatformPatmos_wait_until; + self->wait_for = PlatformPatmos_wait_for; + self->wait_until_interruptible = PlatformPatmos_wait_until_interruptible; + self->new_async_event = PlatformPatmos_new_async_event; +} + +Platform *Platform_new(void) { return (Platform *)&platform; } diff --git a/src/scheduler.c b/src/scheduler.c index 8cec05c3..96553c75 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -1,5 +1,4 @@ - #if defined(SCHEDULER_DYNAMIC) #include "./schedulers/dynamic/scheduler.c" #elif defined(SCHEDULER_STATIC)