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

Support for FlexPRET platform #412

Merged
merged 42 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1acedd7
Add support for FlexPRET
magnmaeh Apr 21, 2024
eb79720
Add FlexPRET to error message
magnmaeh Apr 22, 2024
cacaff1
Add check on number of threads available in FlexPRET's hardware.
magnmaeh Apr 23, 2024
74fc601
Fixes to CMakeLists
magnmaeh Apr 25, 2024
14ed735
Fix bug: lf_available_cores() needs to return 1 less than FP_THREADS.
magnmaeh May 1, 2024
3bd8a10
Fix typo
magnmaeh May 2, 2024
1afab56
Add hacky solution to code size for FlexPRET.
magnmaeh May 3, 2024
bd54f00
Remove wrap hack and instead filter out newlib functions that cause l…
magnmaeh May 3, 2024
cc6163e
Fix small bug
magnmaeh May 3, 2024
b1b9a91
Minor fixes
magnmaeh May 3, 2024
50af7d4
Remove unecessary link in platform impl CMakeLists.txt
magnmaeh May 3, 2024
6900207
Merge branch 'main' into flexpret-support
magnmaeh May 3, 2024
596a344
Propagate low-level-platform interface to platform interface
magnmaeh May 3, 2024
e04610b
Merge branch 'flexpret-support' of github.com:magnmaeh/reactor-c into…
magnmaeh May 3, 2024
0366a73
Apply formatter
magnmaeh May 4, 2024
4764f1f
Add guard to flexpret_support.c which solves build errors for Ardunio…
magnmaeh May 4, 2024
9c5baec
Revert changes to propagating low-level-platform interface
magnmaeh May 5, 2024
9fdd189
Move a single CMake line for more consistency
magnmaeh May 5, 2024
e5216b6
Add explanation of #include platform in util.c
magnmaeh May 10, 2024
2041aff
Fix author in lf_flexpret_support.h
magnmaeh May 10, 2024
c518fd4
Alphabetical order on targets supported
magnmaeh May 10, 2024
d388cac
Add link to issue of decide between HRTT and SRTT in lf_thread_create.
magnmaeh May 10, 2024
7aecb2a
Fix 64-bit sleep and fix issues addressed in PR
magnmaeh May 11, 2024
9110250
Remove more redundant code
magnmaeh May 11, 2024
64f9339
Add workflow
magnmaeh May 11, 2024
81aa462
Formatting
magnmaeh May 11, 2024
09491de
Merge branch 'main' into flexpret-support
magnmaeh May 11, 2024
414cbba
Fix issues that came from cmake changes in fp SDK
magnmaeh May 14, 2024
d36cf28
Merge branch 'flexpret-support' of github.com:magnmaeh/reactor-c into…
magnmaeh May 14, 2024
b879063
Merge branch 'main' into flexpret-support
magnmaeh May 14, 2024
bb0a90b
Format fix
magnmaeh May 18, 2024
2e22d11
Merge branch 'main' into flexpret-support
magnmaeh May 18, 2024
9a28f5e
Rename NO_TTY -> NO_CLI and fix comments related to this.
magnmaeh May 18, 2024
9962705
Fix issue with vfprintf getting wrong declaration for FlexPRET.
magnmaeh May 18, 2024
8fff5f0
Fix merge conflict
magnmaeh May 18, 2024
3015a0d
Uncomment reference to FlexPRET workflow file that does not exist in …
magnmaeh May 18, 2024
3bd9121
Try to run FlexPRET tests in CI
magnmaeh May 18, 2024
35ffd7b
Fix url to point at fork
magnmaeh May 18, 2024
b230677
Revert ref to master
magnmaeh May 18, 2024
869d786
Revert changes to CI and add warning about FlexPRET issue in lf_flexp…
magnmaeh May 18, 2024
5b3a093
Add back flexpret CI
erlingrj May 22, 2024
538cf9f
Merge branch 'main' into flexpret-support
erlingrj May 22, 2024
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
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ jobs:
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
if: ${{ !github.event.pull_request.draft ||contains( github.event.pull_request.labels.*.name, 'zephyr') }}

lf-default-flexpret:
needs: [fetch-lf]
uses: lf-lang/lingua-franca/.github/workflows/c-flexpret-tests.yml@master
with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
if: ${{ !github.event.pull_request.draft ||contains( github.event.pull_request.labels.*.name, 'flexpret') }}

lf-default:
needs: [fetch-lf]
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
Expand Down
8 changes: 4 additions & 4 deletions core/reactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include "reactor_common.h"
#include "environment.h"

// Embedded platforms with no TTY shouldnt have signals
#if !defined(NO_TTY)
// Embedded platforms with no command line interface shouldnt have signals
#if !defined(NO_CLI)
#include <signal.h> // To trap ctrl-c and invoke termination().
#endif

Expand Down Expand Up @@ -319,8 +319,8 @@ int lf_reactor_c_main(int argc, const char* argv[]) {
// The above handles only "normal" termination (via a call to exit).
// As a consequence, we need to also trap Ctrl-C, which issues a SIGINT,
// and cause it to call exit.
// Embedded platforms with NO_TTY have no concept of a signal; for those, we exclude this call.
#ifndef NO_TTY
// Embedded platforms with NO_CLI have no concept of a signal; for those, we exclude this call.
#ifndef NO_CLI
signal(SIGINT, exit);
#endif
// Create and initialize the environment
Expand Down
4 changes: 2 additions & 2 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ void schedule_output_reactions(environment_t* env, reaction_t* reaction, int wor

/**
* Print a usage message.
* TODO: This is not necessary for NO_TTY
* TODO: This is not necessary for NO_CLI
*/
void usage(int argc, const char* argv[]) {
printf("\nCommand-line arguments: \n\n");
Expand Down Expand Up @@ -890,7 +890,7 @@ const char** default_argv = NULL;
* Process the command-line arguments. If the command line arguments are not
* understood, then print a usage message and return 0. Otherwise, return 1.
* @return 1 if the arguments processed successfully, 0 otherwise.
* TODO: Not necessary for NO_TTY
* TODO: Not necessary for NO_CLI
*/
int process_args(int argc, const char* argv[]) {
int i = 1;
Expand Down
5 changes: 5 additions & 0 deletions core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,13 @@ int lf_reactor_c_main(int argc, const char* argv[]) {

LF_PRINT_DEBUG("Start time: " PRINTF_TIME "ns", start_time);
struct timespec physical_time_timespec = {start_time / BILLION, start_time % BILLION};

#ifdef MINIMAL_STDLIB
lf_print("---- Start execution ----");
magnmaeh marked this conversation as resolved.
Show resolved Hide resolved
#else
lf_print("---- Start execution at time %s---- plus %ld nanoseconds", ctime(&physical_time_timespec.tv_sec),
physical_time_timespec.tv_nsec);
#endif // MINIMAL_STDLIB

// Create and initialize the environments for each enclave
lf_create_environments();
Expand Down
3 changes: 2 additions & 1 deletion core/utils/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "util.h"

#include <stdio.h>

#ifndef STANDALONE_RTI
#include "environment.h"
#endif

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h> // Defines memcpy()
Expand Down
3 changes: 3 additions & 0 deletions low_level_platform/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr")
target_compile_definitions(lf-low-level-platform-api INTERFACE PLATFORM_ZEPHYR)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Rp2040")
target_compile_definitions(lf-low-level-platform-api INTERFACE PLATFORM_RP2040)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FlexPRET")
target_compile_definitions(lf-low-level-platform-api INTERFACE PLATFORM_FLEXPRET)
target_link_libraries(lf-low-level-platform-api INTERFACE fp-sdk)
endif()
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 @@ -50,6 +50,8 @@ int lf_critical_section_exit(environment_t* env);
#include "platform/lf_nrf52_support.h"
#elif defined(PLATFORM_RP2040)
#include "platform/lf_rp2040_support.h"
#elif defined(PLATFORM_FLEXPRET)
#include "platform/lf_flexpret_support.h"
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
// Windows platforms
#include "platform/lf_windows_support.h"
Expand Down
4 changes: 2 additions & 2 deletions low_level_platform/api/platform/lf_arduino_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ typedef void* lf_thread_t;
#define LLONG_MIN (-LLONG_MAX - 1LL)
#define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)

// Arduinos are embedded platforms with no tty
#define NO_TTY
// Arduinos are embedded platforms with no command line interface
#define NO_CLI

#endif // LF_ARDUINO_SUPPORT_H
98 changes: 98 additions & 0 deletions low_level_platform/api/platform/lf_flexpret_support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* FlexPRET API support for the C target of Lingua Franca. */

/*************
Copyright (c) 2021, 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.
***************/

/**
* FlexPRET API support for the C target of Lingua Franca.
*
* @author{Magnus Mæhlum <[email protected]>}
*/

#ifndef LF_FLEXPRET_SUPPORT_H
#define LF_FLEXPRET_SUPPORT_H

#include <flexpret/flexpret.h>

/**
* Like nRF52, for FlexPRET, each mutex will control an interrupt.
*
* The mutex holds the interrupt number.
* For example, a mutex might be defined for the GPIOTE peripheral interrupt number
*
* When initialized, the interrupt is inserted into a global linked list
* for disabling and enabling all interrupts during sleep functions.
* - All interrupts are disabled by default after initialization
* - Priority levels are restricted between (0-7)
*
*/

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

// For convenience, the following string can be inserted in a printf
// format for printing both time and microstep as follows:
// printf("Tag is " PRINTF_TAG "\n", time_value, microstep);
#define PRINTF_TAG "(%" PRId64 ", %" PRIu32 ")"

#if !defined(LF_SINGLE_THREADED)
typedef fp_lock_t lf_mutex_t;
typedef fp_thread_t lf_thread_t;
typedef fp_cond_t lf_cond_t;
#endif

// This will filter out some unecessary calls to standard library functions
// and save code space
#define NO_CLI
#define MINIMAL_STDLIB

/**
* Need to include `stdio` here, because we #define `fprintf` and `vfprintf` below.
* Since stdio.h contains declarations for these functions, including it
* after will result in the following:
*
* #define fprintf(s, f, ...) printf(f, ##__VA_ARGS__)
*
* int fprintf (FILE *__restrict, const char *__restrict, ...)
* _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
*
* Which the preprocessor will replace with:
*
* int printf (FILE *__restrict, const char *__restrict, ...)
* _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
*
* Which will yield an error.
*
*/
#include <stdio.h>

// Likewise, fprintf is used to print to `stderr`, but FlexPRET has no `stderr`
// We instead redirect its output to normal printf
// Note: Most compilers do not support passing this on the command line, so CMake
// will drop it if you try... But that would be the better option.
#define fprintf(stream, fmt, ...) printf(fmt, ##__VA_ARGS__)
#define vfprintf(fp, fmt, args) vprintf(fmt, args)

#endif // LF_FLEXPRET_SUPPORT_H
5 changes: 3 additions & 2 deletions low_level_platform/api/platform/lf_nrf52_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef LF_NRF52_SUPPORT_H
#define LF_NRF52_SUPPORT_H

// This embedded platform has no TTY suport
#define NO_TTY
// This embedded platform has no command line interface
#define NO_CLI
#define MINIMAL_STDLIB

#include <stdint.h> // For fixed-width integral types
#include <stdbool.h>
Expand Down
3 changes: 2 additions & 1 deletion low_level_platform/api/platform/lf_rp2040_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#include <pico/stdlib.h>
#include <pico/sync.h>

#define NO_TTY
#define NO_CLI
#define MINIMAL_STDLIB

// Defines for formatting time in printf for pico
#define PRINTF_TAG "(" PRINTF_TIME ", " PRINTF_MICROSTEP ")"
Expand Down
3 changes: 2 additions & 1 deletion low_level_platform/api/platform/lf_zephyr_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <zephyr/kernel.h>

#define NO_TTY
#define NO_CLI
#define MINIMAL_STDLIB
#if !defined(LF_SINGLE_THREADED)

typedef struct k_mutex lf_mutex_t;
Expand Down
33 changes: 32 additions & 1 deletion low_level_platform/impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Rp2040")
${CMAKE_CURRENT_LIST_DIR}/src/lf_rp2040_support.c
${CMAKE_CURRENT_LIST_DIR}/src/lf_atomic_irq.c
)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FlexPRET")
set(LF_LOW_LEVEL_PLATFORM_FILES
${CMAKE_CURRENT_LIST_DIR}/src/lf_flexpret_support.c
${CMAKE_CURRENT_LIST_DIR}/src/lf_atomic_irq.c
)
else()
message(FATAL_ERROR "Your platform is not supported! The C target supports Linux, MacOS, Windows, Zephyr, Nrf52 and RP2040.")
message(FATAL_ERROR "Your platform is not supported! The C target supports FlexPRET, 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 @@ -54,6 +59,32 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr")
zephyr_library_named(lf-low-level-platform-impl)
zephyr_library_sources(${LF_LOW_LEVEL_PLATFORM_FILES})
zephyr_library_link_libraries(kernel)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FlexPRET")
add_library(lf-low-level-platform-impl STATIC ${LF_LOW_LEVEL_PLATFORM_FILES})
target_link_libraries(lf-low-level-platform-impl PRIVATE fp-sdk)

if (DEFINED NUMBER_OF_WORKERS)
magnmaeh marked this conversation as resolved.
Show resolved Hide resolved
# Verify that FlexPRET has the number of requested workers
# That information is available in the SDK's hwconfig
include($ENV{FP_SDK_PATH}/flexpret/hwconfig.cmake)
if (NOT DEFINED THREADS)
message(FATAL_ERROR
"Missing FlexPRET hardware configuration; check that FlexPRET has \
been installed to the SDK."
)
endif()

math(EXPR FLEXPRET_AVAILABLE_WORKERS "${THREADS} - 1")

if (${NUMBER_OF_WORKERS} GREATER ${FLEXPRET_AVAILABLE_WORKERS})
message(FATAL_ERROR
"Number of requested workers (${NUMBER_OF_WORKERS}) is higher \
than FlexPRET's number of available workers \
(${FLEXPRET_AVAILABLE_WORKERS}). Note that FlexPRET uses \
hardware threads, not the usual software threads"
)
endif()
endif()
else()
add_library(lf-low-level-platform-impl STATIC ${LF_LOW_LEVEL_PLATFORM_FILES})
# Link the platform to a threading library
Expand Down
3 changes: 2 additions & 1 deletion low_level_platform/impl/src/lf_atomic_irq.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if defined(PLATFORM_ARDUINO) || defined(PLATFORM_NRF52) || defined(PLATFORM_ZEPHYR) || defined(PLATFORM_RP2040)
#if defined(PLATFORM_ARDUINO) || defined(PLATFORM_NRF52) || defined(PLATFORM_ZEPHYR) || defined(PLATFORM_RP2040) || \
defined(PLATFORM_FLEXPRET)
/**
* @author Erling Rennemo Jellum
* @copyright (c) 2023
Expand Down
Loading
Loading