mirror of https://github.com/ARMmbed/mbed-os.git
ticker api: Schedule immediately event in the past.
parent
aeffd738c7
commit
ab09a1722f
|
@ -905,9 +905,9 @@ static void test_insert_event_us_in_overflow_range() {
|
|||
* When an event is inserted with ticker_insert_event_us and a timestamp less
|
||||
* than timestamp value in the ticker interface.
|
||||
* Then
|
||||
* - The event should not be in the queue
|
||||
* - The interrupt timestamp should be set to
|
||||
* interface_stub.timestamp + TIMESTAMP_MAX_DELTA.
|
||||
* - The event should be in the queue
|
||||
* - The interrupt timestamp should be set to interface_stub.timestamp so it
|
||||
* is scheduled immediately.
|
||||
*/
|
||||
static void test_insert_event_us_underflow() {
|
||||
ticker_set_handler(&ticker_stub, NULL);
|
||||
|
@ -922,15 +922,16 @@ static void test_insert_event_us_underflow() {
|
|||
const uint32_t expected_id = 0xDEADDEAF;
|
||||
|
||||
ticker_insert_event_us(
|
||||
&ticker_stub,
|
||||
&ticker_stub,
|
||||
&event, expected_timestamp, expected_id
|
||||
);
|
||||
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, queue_stub.head);
|
||||
TEST_ASSERT_EQUAL_PTR(&event, queue_stub.head);
|
||||
TEST_ASSERT_EQUAL_UINT32(
|
||||
interface_stub.timestamp + TIMESTAMP_MAX_DELTA,
|
||||
interface_stub.timestamp,
|
||||
interface_stub.interrupt_timestamp
|
||||
);
|
||||
TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call);
|
||||
}
|
||||
|
|
|
@ -109,16 +109,22 @@ static void update_present_time(const ticker_data_t *const ticker)
|
|||
static void schedule_interrupt(const ticker_data_t *const ticker)
|
||||
{
|
||||
update_present_time(ticker);
|
||||
uint32_t duration = MBED_TICKER_INTERRUPT_TIMESTAMP_MAX_DELTA;
|
||||
uint32_t relative_timeout = MBED_TICKER_INTERRUPT_TIMESTAMP_MAX_DELTA;
|
||||
|
||||
if (ticker->queue->head) {
|
||||
us_timestamp_t event_interval = (ticker->queue->head->timestamp - ticker->queue->present_time);
|
||||
if (event_interval < MBED_TICKER_INTERRUPT_TIMESTAMP_MAX_DELTA) {
|
||||
duration = event_interval;
|
||||
us_timestamp_t present = ticker->queue->present_time;
|
||||
us_timestamp_t next_event_timestamp = ticker->queue->head->timestamp;
|
||||
|
||||
// if the event at the head of the queue is in the past then schedule
|
||||
// it immediately.
|
||||
if (next_event_timestamp < present) {
|
||||
relative_timeout = 0;
|
||||
} else if ((next_event_timestamp - present) < MBED_TICKER_INTERRUPT_TIMESTAMP_MAX_DELTA) {
|
||||
relative_timeout = next_event_timestamp - present;
|
||||
}
|
||||
}
|
||||
|
||||
ticker->interface->set_interrupt(ticker->queue->present_time + duration);
|
||||
ticker->interface->set_interrupt(ticker->queue->present_time + relative_timeout);
|
||||
}
|
||||
|
||||
void ticker_set_handler(const ticker_data_t *const ticker, ticker_event_handler handler)
|
||||
|
@ -184,12 +190,6 @@ void ticker_insert_event_us(const ticker_data_t *const ticker, ticker_event_t *o
|
|||
// update the current timestamp
|
||||
update_present_time(ticker);
|
||||
|
||||
// filter out timestamp in the past
|
||||
if (timestamp < ticker->queue->present_time) {
|
||||
schedule_interrupt(ticker);
|
||||
return;
|
||||
}
|
||||
|
||||
// initialise our data
|
||||
obj->timestamp = timestamp;
|
||||
obj->id = id;
|
||||
|
|
Loading…
Reference in New Issue