-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from EhsanKhodadad/main
Support for Patmos platform
- Loading branch information
Showing
8 changed files
with
203 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <ehkh@dtu.dk>} | ||
* @author{Luca Pezzarossa <lpez@dtu.dk>} | ||
* @author{Martin Schoeberl <masca@dtu.dk>} | ||
*/ | ||
|
||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <ehkh@dtu.dk>} | ||
* @author{Luca Pezzarossa <lpez@dtu.dk>} | ||
* @author{Martin Schoeberl <masca@dtu.dk>} | ||
*/ | ||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters