1 | /* mbed Microcontroller Library
|
---|
2 | * Copyright (c) 2015 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/lp_ticker_api.h"
|
---|
17 | #include "hal/mbed_lp_ticker_wrapper.h"
|
---|
18 |
|
---|
19 | #if DEVICE_LPTICKER
|
---|
20 |
|
---|
21 | static ticker_event_queue_t events = { 0 };
|
---|
22 |
|
---|
23 | static ticker_irq_handler_type irq_handler = ticker_irq_handler;
|
---|
24 |
|
---|
25 | static const ticker_interface_t lp_interface = {
|
---|
26 | .init = lp_ticker_init,
|
---|
27 | .read = lp_ticker_read,
|
---|
28 | .disable_interrupt = lp_ticker_disable_interrupt,
|
---|
29 | .clear_interrupt = lp_ticker_clear_interrupt,
|
---|
30 | .set_interrupt = lp_ticker_set_interrupt,
|
---|
31 | .fire_interrupt = lp_ticker_fire_interrupt,
|
---|
32 | .get_info = lp_ticker_get_info,
|
---|
33 | .free = lp_ticker_free,
|
---|
34 | };
|
---|
35 |
|
---|
36 | static const ticker_data_t lp_data = {
|
---|
37 | .interface = &lp_interface,
|
---|
38 | .queue = &events,
|
---|
39 | };
|
---|
40 |
|
---|
41 | const ticker_data_t *get_lp_ticker_data(void)
|
---|
42 | {
|
---|
43 | #if LPTICKER_DELAY_TICKS > 0
|
---|
44 | return get_lp_ticker_wrapper_data(&lp_data);
|
---|
45 | #else
|
---|
46 | return &lp_data;
|
---|
47 | #endif
|
---|
48 | }
|
---|
49 |
|
---|
50 | ticker_irq_handler_type set_lp_ticker_irq_handler(ticker_irq_handler_type ticker_irq_handler)
|
---|
51 | {
|
---|
52 | ticker_irq_handler_type prev_irq_handler = irq_handler;
|
---|
53 |
|
---|
54 | irq_handler = ticker_irq_handler;
|
---|
55 |
|
---|
56 | return prev_irq_handler;
|
---|
57 | }
|
---|
58 |
|
---|
59 | void lp_ticker_irq_handler(void)
|
---|
60 | {
|
---|
61 | #if LPTICKER_DELAY_TICKS > 0
|
---|
62 | lp_ticker_wrapper_irq_handler(irq_handler);
|
---|
63 | #else
|
---|
64 | if (irq_handler) {
|
---|
65 | irq_handler(&lp_data);
|
---|
66 | }
|
---|
67 | #endif
|
---|
68 | }
|
---|
69 |
|
---|
70 | #endif
|
---|