2013-08-08 09:58:34 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2006-2013 ARM Limited
|
|
|
|
*
|
|
|
|
* 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/Ticker.h"
|
2013-08-08 09:58:34 +00:00
|
|
|
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "drivers/TimerEvent.h"
|
|
|
|
#include "platform/FunctionPointer.h"
|
|
|
|
#include "hal/ticker_api.h"
|
2017-01-27 11:10:28 +00:00
|
|
|
#include "platform/mbed_critical.h"
|
2013-08-08 09:58:34 +00:00
|
|
|
|
|
|
|
namespace mbed {
|
|
|
|
|
|
|
|
void Ticker::detach() {
|
2016-05-31 22:57:41 +00:00
|
|
|
core_util_critical_section_enter();
|
2013-08-08 09:58:34 +00:00
|
|
|
remove();
|
2017-09-20 09:07:42 +00:00
|
|
|
// unlocked only if we were attached (we locked it) and this is not low power ticker
|
|
|
|
if(_function && _lock_deepsleep) {
|
2017-08-17 07:55:40 +00:00
|
|
|
sleep_manager_unlock_deep_sleep();
|
|
|
|
}
|
2017-09-20 09:07:42 +00:00
|
|
|
|
2017-02-15 21:19:38 +00:00
|
|
|
_function = 0;
|
2016-05-31 22:57:41 +00:00
|
|
|
core_util_critical_section_exit();
|
2013-08-08 09:58:34 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 13:36:55 +00:00
|
|
|
void Ticker::setup(us_timestamp_t t) {
|
2016-05-31 22:57:41 +00:00
|
|
|
core_util_critical_section_enter();
|
2013-08-08 09:58:34 +00:00
|
|
|
remove();
|
|
|
|
_delay = t;
|
2017-03-31 13:36:55 +00:00
|
|
|
insert_absolute(_delay + ticker_read_us(_ticker_data));
|
2016-05-31 22:57:41 +00:00
|
|
|
core_util_critical_section_exit();
|
2013-08-08 09:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Ticker::handler() {
|
2017-03-31 13:36:55 +00:00
|
|
|
insert_absolute(event.timestamp + _delay);
|
2017-09-09 16:41:01 +00:00
|
|
|
if (_function) {
|
|
|
|
_function();
|
|
|
|
}
|
2013-08-08 09:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mbed
|