mirror of https://github.com/ARMmbed/mbed-os.git
[Nuvoton] Move nu_countdown_init/expired/free implementations to nu_timer.c from nu_timer.h
parent
d311a96061
commit
2b632b9eb0
|
@ -0,0 +1,47 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
* Copyright (c) 2015-2016 Nuvoton
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nu_timer.h"
|
||||||
|
#include "mbed_power_mgmt.h"
|
||||||
|
#include "mbed_critical.h"
|
||||||
|
|
||||||
|
void nu_countdown_init(struct nu_countdown_ctx_s *ctx, us_timestamp_t interval_us)
|
||||||
|
{
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
sleep_manager_lock_deep_sleep();
|
||||||
|
ctx->_ticker_data = get_us_ticker_data();
|
||||||
|
ctx->_interval_end_us = ticker_read_us(ctx->_ticker_data) + interval_us;
|
||||||
|
ctx->_expired = false;
|
||||||
|
core_util_critical_section_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nu_countdown_expired(struct nu_countdown_ctx_s *ctx)
|
||||||
|
{
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
if (! ctx->_expired) {
|
||||||
|
ctx->_expired = ticker_read_us(ctx->_ticker_data) >= ctx->_interval_end_us;
|
||||||
|
}
|
||||||
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
return ctx->_expired;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nu_countdown_free(struct nu_countdown_ctx_s *ctx)
|
||||||
|
{
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
sleep_manager_unlock_deep_sleep();
|
||||||
|
core_util_critical_section_exit();
|
||||||
|
}
|
|
@ -20,8 +20,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "mbed_power_mgmt.h"
|
|
||||||
#include "mbed_critical.h"
|
|
||||||
#include "ticker_api.h"
|
#include "ticker_api.h"
|
||||||
#include "us_ticker_api.h"
|
#include "us_ticker_api.h"
|
||||||
|
|
||||||
|
@ -58,33 +56,9 @@ struct nu_countdown_ctx_s {
|
||||||
bool _expired; // Expired or not
|
bool _expired; // Expired or not
|
||||||
};
|
};
|
||||||
|
|
||||||
__STATIC_INLINE void nu_countdown_init(struct nu_countdown_ctx_s *ctx, us_timestamp_t interval_us)
|
void nu_countdown_init(struct nu_countdown_ctx_s *ctx, us_timestamp_t interval_us);
|
||||||
{
|
bool nu_countdown_expired(struct nu_countdown_ctx_s *ctx);
|
||||||
core_util_critical_section_enter();
|
void nu_countdown_free(struct nu_countdown_ctx_s *ctx);
|
||||||
sleep_manager_lock_deep_sleep();
|
|
||||||
ctx->_ticker_data = get_us_ticker_data();
|
|
||||||
ctx->_interval_end_us = ticker_read_us(ctx->_ticker_data) + interval_us;
|
|
||||||
ctx->_expired = false;
|
|
||||||
core_util_critical_section_exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
__STATIC_INLINE bool nu_countdown_expired(struct nu_countdown_ctx_s *ctx)
|
|
||||||
{
|
|
||||||
core_util_critical_section_enter();
|
|
||||||
if (! ctx->_expired) {
|
|
||||||
ctx->_expired = ticker_read_us(ctx->_ticker_data) >= ctx->_interval_end_us;
|
|
||||||
}
|
|
||||||
core_util_critical_section_exit();
|
|
||||||
|
|
||||||
return ctx->_expired;
|
|
||||||
}
|
|
||||||
|
|
||||||
__STATIC_INLINE void nu_countdown_free(struct nu_countdown_ctx_s *ctx)
|
|
||||||
{
|
|
||||||
core_util_critical_section_enter();
|
|
||||||
sleep_manager_unlock_deep_sleep();
|
|
||||||
core_util_critical_section_exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue