Skip to content

Commit

Permalink
patmos fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Nov 28, 2024
1 parent 815ef4a commit 18be9a6
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 40 deletions.
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
14 changes: 3 additions & 11 deletions examples/patmos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions examples/patmos/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "lf_main.h"

int main() {
lf_start();
}
2 changes: 1 addition & 1 deletion src/federated.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/network_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion src/platform.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

#undef PLATFORM_POSIX
#define PLATFORM_PATMOS

#if defined(PLATFORM_POSIX)
#include "platform/posix/posix.c"
Expand Down
52 changes: 25 additions & 27 deletions src/platform/patmos/patmos.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <assert.h>
#include <stdbool.h>
#include <string.h>

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

Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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 {
Expand All @@ -93,28 +91,28 @@ 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) {
((PlatformPatmos*)self)->async_event = true;
}

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; }

0 comments on commit 18be9a6

Please sign in to comment.