Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patmos #141

Merged
merged 8 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' }}
if: ${{ github.event_name == 'pull_request' }}
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
13 changes: 13 additions & 0 deletions include/reactor-uc/platform/patmos/patmos.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/federated.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,4 @@ void FederatedConnectionBundle_validate(FederatedConnectionBundle *bundle) {
validate(bundle->serialize_hooks[i]);
validate(bundle->outputs[i]->super.super.parent);
}
}
}
4 changes: 4 additions & 0 deletions src/network_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/platform.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#if defined(PLATFORM_POSIX)
#include "platform/posix/posix.c"
#elif defined(PLATFORM_RIOT)
Expand All @@ -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
109 changes: 109 additions & 0 deletions src/platform/patmos/patmos.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "reactor-uc/platform/patmos/patmos.h"
#include <assert.h>
#include <stdbool.h>
#include <string.h>

#include <machine/rtc.h>
#include <machine/exceptions.h>

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; }
1 change: 0 additions & 1 deletion src/scheduler.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#if defined(SCHEDULER_DYNAMIC)
#include "./schedulers/dynamic/scheduler.c"
#elif defined(SCHEDULER_STATIC)
Expand Down
Loading