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

Zephyr timing fix #166

Merged
merged 4 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ jobs:
# runtime-ref: ${{ github.ref }}
# compiler-ref: ${{ needs.fetch-lf.outputs.ref }}

lf-default-zephyr:
needs: fetch-lf
uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master
with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}

lf-default:
needs: fetch-lf
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
Expand Down
11 changes: 8 additions & 3 deletions core/platform/lf_zephyr_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Keep track of overflows to keep clocks monotonic
static int64_t _lf_timer_epoch_duration_nsec;
static int64_t _lf_timer_epoch_duration_usec;
static volatile int64_t _lf_timer_last_epoch_nsec = 0;

#if defined(LF_ZEPHYR_CLOCK_HI_RES)
Expand Down Expand Up @@ -108,9 +109,11 @@ void lf_initialize_clock() {
while(1) {};
}

// Calculate the duration of an epoch
// Calculate the duration of an epoch. Compute both
// nsec and usec now at boot to avoid these computations later
counter_max_ticks = counter_get_max_top_value(_lf_counter_dev);
_lf_timer_epoch_duration_nsec = counter_ticks_to_us(_lf_counter_dev, counter_max_ticks) * 1000LL;
_lf_timer_epoch_duration_usec = counter_ticks_to_us(_lf_counter_dev, counter_max_ticks);
_lf_timer_epoch_duration_nsec = _lf_timer_epoch_duration_usec * 1000LL;

// Set the max_top value to be the maximum
counter_max_ticks = counter_get_max_top_value(_lf_counter_dev);
Expand All @@ -137,8 +140,10 @@ void lf_initialize_clock() {
LF_PRINT_LOG("Using Low resolution zephyr kernel clock");
LF_PRINT_LOG("Kernel Clock has frequency of %u Hz\n", CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC);
_lf_timer_last_epoch_nsec = 0;
// Compute the duration of an
// Compute the duration of an epoch. Compute both
// nsec and usec now at boot to avoid these computations later
_lf_timer_epoch_duration_nsec = ((1LL << 32) * SECONDS(1))/CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
_lf_timer_epoch_duration_usec = _lf_timer_epoch_duration_nsec/1000;
#endif
}

Expand Down
1 change: 0 additions & 1 deletion include/core/platform/lf_zephyr_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ typedef int64_t _interval_t;
typedef uint32_t _microstep_t;

#ifdef LF_THREADED
#warning "Threaded support on Zephyr is still experimental"

typedef struct k_mutex _lf_mutex_t;
typedef struct k_condvar _lf_cond_t;
Expand Down