Skip to content

Commit 2b632b9

Browse files
committed
[Nuvoton] Move nu_countdown_init/expired/free implementations to nu_timer.c from nu_timer.h
1 parent d311a96 commit 2b632b9

File tree

2 files changed

+50
-29
lines changed

2 files changed

+50
-29
lines changed

targets/TARGET_NUVOTON/nu_timer.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2015-2016 Nuvoton
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "nu_timer.h"
18+
#include "mbed_power_mgmt.h"
19+
#include "mbed_critical.h"
20+
21+
void nu_countdown_init(struct nu_countdown_ctx_s *ctx, us_timestamp_t interval_us)
22+
{
23+
core_util_critical_section_enter();
24+
sleep_manager_lock_deep_sleep();
25+
ctx->_ticker_data = get_us_ticker_data();
26+
ctx->_interval_end_us = ticker_read_us(ctx->_ticker_data) + interval_us;
27+
ctx->_expired = false;
28+
core_util_critical_section_exit();
29+
}
30+
31+
bool nu_countdown_expired(struct nu_countdown_ctx_s *ctx)
32+
{
33+
core_util_critical_section_enter();
34+
if (! ctx->_expired) {
35+
ctx->_expired = ticker_read_us(ctx->_ticker_data) >= ctx->_interval_end_us;
36+
}
37+
core_util_critical_section_exit();
38+
39+
return ctx->_expired;
40+
}
41+
42+
void nu_countdown_free(struct nu_countdown_ctx_s *ctx)
43+
{
44+
core_util_critical_section_enter();
45+
sleep_manager_unlock_deep_sleep();
46+
core_util_critical_section_exit();
47+
}

targets/TARGET_NUVOTON/nu_timer.h

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include <stdint.h>
2121
#include <stdbool.h>
2222
#include "cmsis.h"
23-
#include "mbed_power_mgmt.h"
24-
#include "mbed_critical.h"
2523
#include "ticker_api.h"
2624
#include "us_ticker_api.h"
2725

@@ -58,33 +56,9 @@ struct nu_countdown_ctx_s {
5856
bool _expired; // Expired or not
5957
};
6058

61-
__STATIC_INLINE void nu_countdown_init(struct nu_countdown_ctx_s *ctx, us_timestamp_t interval_us)
62-
{
63-
core_util_critical_section_enter();
64-
sleep_manager_lock_deep_sleep();
65-
ctx->_ticker_data = get_us_ticker_data();
66-
ctx->_interval_end_us = ticker_read_us(ctx->_ticker_data) + interval_us;
67-
ctx->_expired = false;
68-
core_util_critical_section_exit();
69-
}
70-
71-
__STATIC_INLINE bool nu_countdown_expired(struct nu_countdown_ctx_s *ctx)
72-
{
73-
core_util_critical_section_enter();
74-
if (! ctx->_expired) {
75-
ctx->_expired = ticker_read_us(ctx->_ticker_data) >= ctx->_interval_end_us;
76-
}
77-
core_util_critical_section_exit();
78-
79-
return ctx->_expired;
80-
}
81-
82-
__STATIC_INLINE void nu_countdown_free(struct nu_countdown_ctx_s *ctx)
83-
{
84-
core_util_critical_section_enter();
85-
sleep_manager_unlock_deep_sleep();
86-
core_util_critical_section_exit();
87-
}
59+
void nu_countdown_init(struct nu_countdown_ctx_s *ctx, us_timestamp_t interval_us);
60+
bool nu_countdown_expired(struct nu_countdown_ctx_s *ctx);
61+
void nu_countdown_free(struct nu_countdown_ctx_s *ctx);
8862

8963
#ifdef __cplusplus
9064
}

0 commit comments

Comments
 (0)