Skip to content

lp ticker - fix until methods - time is in period addition #60

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

0xc0170
Copy link
Contributor

@0xc0170 0xc0170 commented Mar 16, 2016

We should check if now and until are valid compare to the current time.
It can happen that real_now is far in the future, we should not sleep or set interrupt,
just return.

K64F is using deltas for setting the interrupt, we should use real_now
delta = time - real_now

This depends on ARMmbed/mbed-hal#78 (the doc update to clarify this is the intended behaviour).

I wrote simple test cases for this which are now passing with this patch set

void sleep_until_passed()
{
    uint32_t start = lp_ticker_read();
    uint32_t compare_match_start = lp_ticker_get_compare_match();
    // test when now < until < real_now (real_now could wrap around, should not affect it)
    lp_ticker_sleep_until(start - 10, start - 5);
    // we should not set a new compare match
    TEST_ASSERT_EQUAL(compare_match_start, lp_ticker_get_compare_match());
}

void set_interrupt_until_passed()
{
    uint32_t start = lp_ticker_read();
    uint32_t compare_match_start = lp_ticker_get_compare_match();
    // test when now < until < real_now
    lp_ticker_set_interrupt(start - 10, start - 5);

    // compare match should not change
    TEST_ASSERT_EQUAL(compare_match_start, lp_ticker_get_compare_match());
}

This is not ready for merging - one more thing left at least, is time_is_in_period should be available for our targets within HAL as it's intended to be checked. I am proposing to place it in mbed-hal as lp_ticker_time_is_in_period.

@bogdanm @autopulated

@0xc0170 0xc0170 force-pushed the fix_lp_ticker_until branch from e59f312 to bfd7ae5 Compare March 16, 2016 15:51
We should check if now and until are valid compare to the current time.
It can happen that real_now is far in the future, we should not sleep or set interrupt,
just return.

K64F is using deltas for setting the interrupt, we should use real_now
delta = time - real_now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants