2013-02-18 15:32:11 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2006-2013 ARM Limited
|
2018-11-09 11:22:52 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
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 "drivers/TimerEvent.h"
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
#include <stddef.h>
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "hal/ticker_api.h"
|
|
|
|
#include "hal/us_ticker_api.h"
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
namespace mbed {
|
|
|
|
|
2018-05-24 15:58:14 +00:00
|
|
|
TimerEvent::TimerEvent() : event(), _ticker_data(get_us_ticker_data())
|
|
|
|
{
|
2015-04-23 13:56:34 +00:00
|
|
|
ticker_set_handler(_ticker_data, (&TimerEvent::irq));
|
|
|
|
}
|
|
|
|
|
2018-05-24 15:58:14 +00:00
|
|
|
TimerEvent::TimerEvent(const ticker_data_t *data) : event(), _ticker_data(data)
|
|
|
|
{
|
2015-04-23 13:56:34 +00:00
|
|
|
ticker_set_handler(_ticker_data, (&TimerEvent::irq));
|
2013-02-18 15:32:11 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 15:58:14 +00:00
|
|
|
void TimerEvent::irq(uint32_t id)
|
|
|
|
{
|
|
|
|
TimerEvent *timer_event = (TimerEvent *)id;
|
2013-02-18 15:32:11 +00:00
|
|
|
timer_event->handler();
|
|
|
|
}
|
|
|
|
|
2018-05-24 15:58:14 +00:00
|
|
|
TimerEvent::~TimerEvent()
|
|
|
|
{
|
2013-02-18 15:32:11 +00:00
|
|
|
remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
// insert in to linked list
|
2018-05-24 15:58:14 +00:00
|
|
|
void TimerEvent::insert(timestamp_t timestamp)
|
|
|
|
{
|
2015-04-23 13:56:34 +00:00
|
|
|
ticker_insert_event(_ticker_data, &event, timestamp, (uint32_t)this);
|
2013-02-18 15:32:11 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 15:58:14 +00:00
|
|
|
void TimerEvent::insert_absolute(us_timestamp_t timestamp)
|
|
|
|
{
|
2017-05-31 18:14:21 +00:00
|
|
|
ticker_insert_event_us(_ticker_data, &event, timestamp, (uint32_t)this);
|
2017-03-31 13:30:42 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 15:58:14 +00:00
|
|
|
void TimerEvent::remove()
|
|
|
|
{
|
2015-04-23 13:56:34 +00:00
|
|
|
ticker_remove_event(_ticker_data, &event);
|
2013-02-18 15:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mbed
|