source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/hal/mbed_lp_ticker_wrapper.c@ 374

Last change on this file since 374 was 374, checked in by coas-nagasima, 5 years ago

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

  • Property charset set to UTF-8
  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 3.0 KB
Line 
1/* mbed Microcontroller Library
2 * Copyright (c) 2018 ARM Limited
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#include "hal/mbed_lp_ticker_wrapper.h"
17
18#if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0)
19
20#include "hal/LowPowerTickerWrapper.h"
21#include "platform/mbed_critical.h"
22
23// Do not use SingletonPtr since this must be initialized in a critical section
24static LowPowerTickerWrapper *ticker_wrapper;
25static uint64_t ticker_wrapper_data[(sizeof(LowPowerTickerWrapper) + 7) / 8];
26static bool init = false;
27
28static void lp_ticker_wrapper_init()
29{
30 ticker_wrapper->init();
31}
32
33static uint32_t lp_ticker_wrapper_read()
34{
35 return ticker_wrapper->read();
36}
37
38static void lp_ticker_wrapper_set_interrupt(timestamp_t timestamp)
39{
40 ticker_wrapper->set_interrupt(timestamp);
41}
42
43static void lp_ticker_wrapper_disable_interrupt()
44{
45 ticker_wrapper->disable_interrupt();
46}
47
48static void lp_ticker_wrapper_clear_interrupt()
49{
50 ticker_wrapper->clear_interrupt();
51}
52
53static void lp_ticker_wrapper_fire_interrupt()
54{
55 ticker_wrapper->fire_interrupt();
56}
57
58static const ticker_info_t *lp_ticker_wrapper_get_info()
59{
60 return ticker_wrapper->get_info();
61}
62
63static void lp_ticker_wrapper_free()
64{
65 ticker_wrapper->free();
66}
67
68static const ticker_interface_t lp_interface = {
69 lp_ticker_wrapper_init,
70 lp_ticker_wrapper_read,
71 lp_ticker_wrapper_disable_interrupt,
72 lp_ticker_wrapper_clear_interrupt,
73 lp_ticker_wrapper_set_interrupt,
74 lp_ticker_wrapper_fire_interrupt,
75 lp_ticker_wrapper_free,
76 lp_ticker_wrapper_get_info
77};
78
79void lp_ticker_wrapper_irq_handler(ticker_irq_handler_type handler)
80{
81 core_util_critical_section_enter();
82
83 if (!init) {
84 // Force ticker to initialize
85 get_lp_ticker_data();
86 }
87
88 ticker_wrapper->irq_handler(handler);
89
90 core_util_critical_section_exit();
91}
92
93const ticker_data_t *get_lp_ticker_wrapper_data(const ticker_data_t *data)
94{
95 core_util_critical_section_enter();
96
97 if (!init) {
98 ticker_wrapper = new (ticker_wrapper_data) LowPowerTickerWrapper(data, &lp_interface, LPTICKER_DELAY_TICKS, LPTICKER_DELAY_TICKS);
99 init = true;
100 }
101
102 core_util_critical_section_exit();
103
104 return &ticker_wrapper->data;
105}
106
107void lp_ticker_wrapper_suspend()
108{
109 if (!init) {
110 // Force ticker to initialize
111 get_lp_ticker_data();
112 }
113
114 ticker_wrapper->suspend();
115}
116
117void lp_ticker_wrapper_resume()
118{
119 if (!init) {
120 // Force ticker to initialize
121 get_lp_ticker_data();
122 }
123
124 ticker_wrapper->resume();
125}
126
127#endif
Note: See TracBrowser for help on using the repository browser.