Skip to content

Commit

Permalink
Support for Patmos platform..
Browse files Browse the repository at this point in the history
  • Loading branch information
EhsanKhodadad committed Apr 12, 2024
1 parent 159c64f commit b3dcbac
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 43 deletions.
4 changes: 2 additions & 2 deletions low_level_platform/api/low_level_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ int lf_critical_section_exit(environment_t* env);
#elif defined(PLATFORM_ZEPHYR)
#include "platform/lf_zephyr_support.h"
#elif defined(PLATFORM_NRF52)
#include "platform/lf_nrf52_support.h"
#include "platform/lf_nrf52_support.h"
#elif defined(PLATFORM_PATMOS)
#include "platform/lf_patmos_support.h"
#include "platform/lf_patmos_support.h"
#elif defined(PLATFORM_RP2040)
#include "platform/lf_rp2040_support.h"
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
Expand Down
8 changes: 4 additions & 4 deletions low_level_platform/api/platform/lf_patmos_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ 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{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
#define NO_TTY

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

#include <inttypes.h> // Needed to define PRId64 and PRIu32
#include <inttypes.h> // Needed to define PRId64 and PRIu32
#define PRINTF_TIME "%" PRId64
#define PRINTF_MICROSTEP "%" PRIu32
#define PRINTF_TAG "(%" PRId64 ", %" PRIu32 ")"
Expand Down
5 changes: 5 additions & 0 deletions low_level_platform/impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ 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 "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 Linux, MacOS, Windows, Zephyr, Nrf52 and RP2040.")
endif()
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) || defined(PLATFORM_PATMOS)
#if defined(PLATFORM_ARDUINO) || defined(PLATFORM_NRF52) || defined(PLATFORM_ZEPHYR) || defined(PLATFORM_RP2040) || \
defined(PLATFORM_PATMOS)
/**
* @author Erling Rennemo Jellum
* @copyright (c) 2023
Expand Down
69 changes: 33 additions & 36 deletions low_level_platform/impl/src/lf_patmos_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,73 +13,70 @@ static volatile bool _lf_async_event = false;
static volatile int _lf_num_nested_critical_sections = 0;
/**
* @brief Sleep until an absolute time.
* TODO: For improved power consumption this should be implemented with a HW timer and interrupts.
* 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();
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);
// Do busy sleep
do {
_lf_clock_gettime(&now);
} while ((now < wakeup) && !_lf_async_event);

lf_disable_interrupts_nested();
lf_disable_interrupts_nested();

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

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

}
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).
* This has to be called at least once per 35 minutes to properly handle overflows of the 32-bit clock.
* TODO: This is only addressable by setting up interrupts on a timer peripheral to occur at wrap.
*/

int _lf_clock_gettime(instant_t* t) {

assert(t != NULL);
assert(t != NULL);

*t = get_cpu_usecs() * 1000;
return 0;
*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;
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;
if (_lf_num_nested_critical_sections <= 0) {
return 1;
}

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

#endif

0 comments on commit b3dcbac

Please sign in to comment.