Skip to content

Commit

Permalink
Patmos (#141)
Browse files Browse the repository at this point in the history
* first stab

* patmos fixes

* Patmos: fix function names

* clean up

* remove patmos examples, because they are in the template

* clean up

* clang19 formatting

* Some small fixes

---------

Co-authored-by: Martin Schoeberl <[email protected]>
Co-authored-by: erlingrj <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2024
1 parent 6e90658 commit b3c391a
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 4 deletions.
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

0 comments on commit b3c391a

Please sign in to comment.