• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* mbed Microcontroller Library
2  * Copyright (c) 2015 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include "us_ticker_api.h"
19 
20 #define DEVICE_USTICKER     1
21 
22 #if DEVICE_USTICKER
23 
24 static ticker_event_queue_t events = { 0 };
25 
26 static ticker_irq_handler_type irq_handler = ticker_irq_handler;
27 
28 static const ticker_interface_t us_interface = {
29     .init = us_ticker_init,
30     .read = us_ticker_read,
31     .disable_interrupt = us_ticker_disable_interrupt,
32     .clear_interrupt = us_ticker_clear_interrupt,
33     .set_interrupt = us_ticker_set_interrupt,
34     .fire_interrupt = us_ticker_fire_interrupt,
35     .get_info = us_ticker_get_info,
36     .free = us_ticker_free,
37     .runs_in_deep_sleep = false,
38 };
39 
40 static const ticker_data_t us_data = {
41     .interface = &us_interface,
42     .queue = &events
43 };
44 
get_us_ticker_data(void)45 const ticker_data_t *get_us_ticker_data(void)
46 {
47     return &us_data;
48 }
49 
set_us_ticker_irq_handler(ticker_irq_handler_type ticker_irq_handler)50 ticker_irq_handler_type set_us_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 
us_ticker_irq_handler(void)59 void us_ticker_irq_handler(void)
60 {
61     if (irq_handler) {
62         irq_handler(&us_data);
63     }
64 }
65 
66 #else
67 
get_us_ticker_data(void)68 const ticker_data_t *get_us_ticker_data(void)
69 {
70     return NULL;
71 }
72 
73 #endif  // DEVICE_USTICKER
74