2013-02-18 15:32:11 +00:00
|
|
|
/* mbed Microcontroller Library
|
2015-04-23 13:56:34 +00:00
|
|
|
* Copyright (c) 2015 ARM Limited
|
2013-02-18 15:32:11 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "hal/us_ticker_api.h"
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2017-03-31 13:25:17 +00:00
|
|
|
static ticker_event_queue_t events = { 0 };
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2015-04-23 13:56:34 +00:00
|
|
|
static const ticker_interface_t us_interface = {
|
|
|
|
.init = us_ticker_init,
|
|
|
|
.read = us_ticker_read,
|
|
|
|
.disable_interrupt = us_ticker_disable_interrupt,
|
|
|
|
.clear_interrupt = us_ticker_clear_interrupt,
|
|
|
|
.set_interrupt = us_ticker_set_interrupt,
|
Ticker: add fire interrupt now function
fire_interrupt function should be used for events in the past. As we have now
64bit timestamp, we can figure out what is in the past, and ask a target to invoke
an interrupt immediately. The previous attemps in the target HAL tickers were not ideal, as it can wrap around easily (16 or 32 bit counters). This new
functionality should solve this problem.
set_interrupt for tickers in HAL code should not handle anything but the next match interrupt. If it was in the past is handled by the upper layer.
It is possible that we are setting next event to the close future, so once it is set it is already in the past. Therefore we add a check after set interrupt to verify it is in future.
If it is not, we fire interrupt immediately. This results in
two events - first one immediate, correct one. The second one might be scheduled in far future (almost entire ticker range),
that should be discarded.
The specification for the fire_interrupts are:
- should set pending bit for the ticker interrupt (as soon as possible),
the event we are scheduling is already in the past, and we do not want to skip
any events
- no arguments are provided, neither return value, not needed
- ticker should be initialized prior calling this function (no need to check if it is already initialized)
All our targets provide this new functionality, removing old misleading if (timestamp is in the past) checks.
2017-06-27 11:18:59 +00:00
|
|
|
.fire_interrupt = us_ticker_fire_interrupt,
|
2015-04-23 13:56:34 +00:00
|
|
|
};
|
2014-05-29 13:11:05 +00:00
|
|
|
|
2015-04-23 13:56:34 +00:00
|
|
|
static const ticker_data_t us_data = {
|
|
|
|
.interface = &us_interface,
|
2017-03-31 13:25:17 +00:00
|
|
|
.queue = &events
|
2015-04-23 13:56:34 +00:00
|
|
|
};
|
2015-02-25 15:31:24 +00:00
|
|
|
|
2015-04-23 13:56:34 +00:00
|
|
|
const ticker_data_t* get_us_ticker_data(void)
|
|
|
|
{
|
|
|
|
return &us_data;
|
2013-02-18 15:32:11 +00:00
|
|
|
}
|
2015-02-24 20:25:43 +00:00
|
|
|
|
2015-04-23 13:56:34 +00:00
|
|
|
void us_ticker_irq_handler(void)
|
|
|
|
{
|
|
|
|
ticker_irq_handler(&us_data);
|
2015-02-24 20:25:43 +00:00
|
|
|
}
|