Skip to content

Commit

Permalink
Merge pull request #383 from EhsanKhodadad/main
Browse files Browse the repository at this point in the history
Support for Patmos platform
  • Loading branch information
lhstrh authored Aug 2, 2024
2 parents 4026514 + 7b4408f commit 2581c15
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 14 deletions.
26 changes: 14 additions & 12 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include(${LF_ROOT}/core/lf_utils.cmake)
list(APPEND GENERAL_SOURCES tag.c clock.c port.c mixed_radix.c reactor_common.c lf_token.c environment.c)

# Add tracing support if requested
if (DEFINED LF_TRACE)
if(DEFINED LF_TRACE)
message(STATUS "Including sources specific to tracing.")
list(APPEND GENERAL_SOURCES tracepoint.c)
endif()
Expand All @@ -16,7 +16,7 @@ endif()
list(APPEND REACTORC_SOURCES ${GENERAL_SOURCES})

# Add sources for either threaded or single-threaded runtime
if (DEFINED FEDERATED)
if(DEFINED FEDERATED)
include(federated/CMakeLists.txt)
include(federated/network/CMakeLists.txt)
endif()
Expand All @@ -35,14 +35,14 @@ endif()

# Add sources for the local RTI if we are using scheduling enclaves
if(DEFINED LF_ENCLAVES)
include(federated/RTI/local_rti.cmake)
include(federated/RTI/local_rti.cmake)
endif()

# Include sources from subdirectories
include(utils/CMakeLists.txt)

if (DEFINED MODAL_REACTORS)
include(modal_models/CMakeLists.txt)
if(DEFINED MODAL_REACTORS)
include(modal_models/CMakeLists.txt)
endif()

# Print sources used for compilation
Expand All @@ -53,7 +53,7 @@ add_library(reactor-c)
target_sources(reactor-c PRIVATE ${REACTORC_SOURCES})
lf_enable_compiler_warnings(reactor-c)

if (DEFINED LF_TRACE)
if(DEFINED LF_TRACE)
include(${LF_ROOT}/trace/api/CMakeLists.txt)
target_link_libraries(reactor-c PUBLIC lf::trace-api)
# If the user specified an external trace plugin. Find it and link with it
Expand Down Expand Up @@ -106,18 +106,19 @@ target_include_directories(reactor-c PUBLIC ../include/core/threaded)
target_include_directories(reactor-c PUBLIC ../include/core/utils)
target_include_directories(reactor-c PUBLIC federated/RTI/)

if (APPLE)
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
if(APPLE)
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
endif()

# Link with OpenSSL library
if(DEFINED FEDERATED_AUTHENTICATED)
if (APPLE)
if(APPLE)
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)
endif()

find_package(OpenSSL REQUIRED)
target_link_libraries(reactor-c PUBLIC OpenSSL::SSL)
endif()
Expand All @@ -130,10 +131,11 @@ if(DEFINED FEDERATED)
endif()

# Unless specified otherwise initial event queue and reaction queue to size 10
if (NOT DEFINED INITIAL_EVENT_QUEUE_SIZE)
if(NOT DEFINED INITIAL_EVENT_QUEUE_SIZE)
set(INITIAL_EVENT_QUEUE_SIZE 10)
endif()
if (NOT DEFINED INITIAL_REACT_QUEUE_SIZE)

if(NOT DEFINED INITIAL_REACT_QUEUE_SIZE)
set(INITIAL_REACT_QUEUE_SIZE 10)
endif()

Expand Down
2 changes: 2 additions & 0 deletions low_level_platform/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "nRF52")
target_compile_definitions(lf-low-level-platform-api INTERFACE PLATFORM_NRF52)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr")
target_compile_definitions(lf-low-level-platform-api INTERFACE PLATFORM_ZEPHYR)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Patmos")
target_compile_definitions(lf-low-level-platform-api INTERFACE PLATFORM_PATMOS)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Rp2040")
target_compile_definitions(lf-low-level-platform-api INTERFACE PLATFORM_RP2040)
target_link_libraries(lf-low-level-platform-api INTERFACE pico_stdlib)
Expand Down
2 changes: 2 additions & 0 deletions low_level_platform/api/low_level_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ int lf_critical_section_exit(environment_t* env);
#include "platform/lf_zephyr_support.h"
#elif defined(PLATFORM_NRF52)
#include "platform/lf_nrf52_support.h"
#elif defined(PLATFORM_PATMOS)
#include "platform/lf_patmos_support.h"
#elif defined(PLATFORM_RP2040)
#include "platform/lf_rp2040_support.h"
#elif defined(PLATFORM_FLEXPRET)
Expand Down
52 changes: 52 additions & 0 deletions low_level_platform/api/platform/lf_patmos_support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

/* Patmos API support for the C target of Lingua Franca. */

/*************
Copyright (c) 2024, The University of California at Berkeley.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***************/

/**
* Patmos API support for the C target of Lingua Franca.
*
* This is based on lf_nrf_support.h in icyphy/lf-buckler.
*
* @author{Ehsan Khodadad <[email protected]>}
* @author{Luca Pezzarossa <[email protected]>}
* @author{Martin Schoeberl <[email protected]>}
*/

#ifndef LF_PATMOS_SUPPORT_H
#define LF_PATMOS_SUPPORT_H

// This embedded platform has no TTY suport
#define NO_TTY

#include <stdint.h> // For fixed-width integral types
#include <stdbool.h>

#include <inttypes.h> // Needed to define PRId64 and PRIu32
#define PRINTF_TIME "%" PRId64
#define PRINTF_MICROSTEP "%" PRIu32
#define PRINTF_TAG "(%" PRId64 ", %" PRIu32 ")"

#endif // LF_PATMOS_SUPPORT_H
12 changes: 11 additions & 1 deletion low_level_platform/impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FlexPRET")
${CMAKE_CURRENT_LIST_DIR}/src/lf_flexpret_support.c
${CMAKE_CURRENT_LIST_DIR}/src/lf_atomic_irq.c
)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Patmos")
set(LF_LOW_LEVEL_PLATFORM_FILES
${CMAKE_CURRENT_LIST_DIR}/src/lf_patmos_support.c
${CMAKE_CURRENT_LIST_DIR}/src/lf_atomic_irq.c
)
else()
message(FATAL_ERROR "Your platform is not supported! The C target supports FlexPRET, Linux, MacOS, nRF52, RP2040, Windows, and Zephyr.")
message(FATAL_ERROR "Your platform is not supported! The C target supports FlexPRET, Patmos, Linux, MacOS, nRF52, RP2040, Windows, and Zephyr.")
endif()

list(APPEND LF_LOW_LEVEL_PLATFORM_FILES ${CMAKE_CURRENT_LIST_DIR}/src/lf_platform_util.c)
Expand All @@ -56,6 +61,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr")
else()
message(STATUS "Building Zephyr library with Kernel clock ")
endif()

zephyr_library_named(lf-low-level-platform-impl)
zephyr_library_sources(${LF_LOW_LEVEL_PLATFORM_FILES})
zephyr_library_link_libraries(kernel)
Expand Down Expand Up @@ -93,8 +99,11 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FlexPRET")
)
endif()
endif()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Patmos")
add_library(lf-low-level-platform-impl STATIC ${LF_LOW_LEVEL_PLATFORM_FILES})
else()
add_library(lf-low-level-platform-impl STATIC ${LF_LOW_LEVEL_PLATFORM_FILES})

# Link the platform to a threading library
if(NOT DEFINED LF_SINGLE_THREADED OR DEFINED LF_TRACE)
find_package(Threads REQUIRED)
Expand All @@ -116,6 +125,7 @@ macro(low_level_platform_define X)
target_compile_definitions(lf-low-level-platform-impl PUBLIC ${X}=${${X}})
endif(DEFINED ${X})
endmacro()

low_level_platform_define(LF_SINGLE_THREADED)
low_level_platform_define(LOG_LEVEL)
low_level_platform_define(MODAL_REACTORS)
Expand Down
2 changes: 1 addition & 1 deletion low_level_platform/impl/src/lf_atomic_irq.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#if defined(PLATFORM_ARDUINO) || defined(PLATFORM_NRF52) || defined(PLATFORM_ZEPHYR) || defined(PLATFORM_RP2040) || \
defined(PLATFORM_FLEXPRET)
defined(PLATFORM_FLEXPRET) || defined(PLATFORM_PATMOS)
/**
* @author Erling Rennemo Jellum
* @copyright (c) 2023
Expand Down
118 changes: 118 additions & 0 deletions low_level_platform/impl/src/lf_patmos_support.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#if defined(PLATFORM_PATMOS)
/*************
Copyright (c) 2024, The University of California at Berkeley.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***************/

/**
* @author{Ehsan Khodadad <[email protected]>}
* @author{Luca Pezzarossa <[email protected]>}
* @author{Martin Schoeberl <[email protected]>}
*/
#include <time.h>
#include <errno.h>
#include <assert.h>
#include "platform/lf_patmos_support.h"
#include "low_level_platform.h"
#include <machine/rtc.h>
#include <machine/exceptions.h>
#include <stdio.h>

// Keep track of physical actions being entered into the system
static volatile bool _lf_async_event = false;
// Keep track of whether we are in a critical section or not
static volatile int _lf_num_nested_critical_sections = 0;
/**
* @brief Sleep until an absolute time.
* Since there is no sleep mode in Patmos, and energy saving is not important for real-time systems,
* we just used a busy sleep.
*
* @param wakeup int64_t time of wakeup
* @return int 0 if successful sleep, -1 if awoken by async event
*/

int _lf_interruptable_sleep_until_locked(environment_t* env, instant_t wakeup) {
instant_t now;
_lf_async_event = false;
lf_enable_interrupts_nested();

// Do busy sleep
do {
_lf_clock_gettime(&now);
} while ((now < wakeup) && !_lf_async_event);

lf_disable_interrupts_nested();

if (_lf_async_event) {
_lf_async_event = false;
return -1;
} else {
return 0;
}
}

/**
* Patmos clock does not need initialization.
*/
void _lf_initialize_clock() {}

/**
* Write the current time in nanoseconds into the location given by the argument.
* This returns 0 (it never fails, assuming the argument gives a valid memory location).
*/

int _lf_clock_gettime(instant_t* t) {

assert(t != NULL);

*t = get_cpu_usecs() * 1000;

return 0;
}

#if defined(LF_SINGLE_THREADED)

int lf_disable_interrupts_nested() {
if (_lf_num_nested_critical_sections++ == 0) {
intr_disable();
}
return 0;
}

int lf_enable_interrupts_nested() {
if (_lf_num_nested_critical_sections <= 0) {
return 1;
}

if (--_lf_num_nested_critical_sections == 0) {
intr_enable();
}
return 0;
}

int _lf_single_threaded_notify_of_event() {
_lf_async_event = true;
return 0;
}
#endif // LF_SINGLE_THREADED

#endif // PLATFORM_PATMOS
3 changes: 3 additions & 0 deletions platform/impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FlexPRET")
add_library(lf-platform-impl STATIC)
target_sources(lf-platform-impl PUBLIC ${LF_PLATFORM_FILES})
target_link_libraries(lf-platform-impl PRIVATE fp-sdk)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Patmos")
add_library(lf-platform-impl STATIC)
target_sources(lf-platform-impl PUBLIC ${LF_PLATFORM_FILES})
else()
add_library(lf-platform-impl STATIC)
target_sources(lf-platform-impl PUBLIC ${LF_PLATFORM_FILES})
Expand Down

0 comments on commit 2581c15

Please sign in to comment.