lol
Fork of Application by
mbed-dev/hal/ticker_api.h@12:3a30cdffa27c, 2018-01-21 (annotated)
- Committer:
- danix
- Date:
- Sun Jan 21 22:28:30 2018 +0000
- Revision:
- 12:3a30cdffa27c
- Parent:
- 10:41552d038a69
Working acelerometer and mouse
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Zaitsev | 10:41552d038a69 | 1 | |
Zaitsev | 10:41552d038a69 | 2 | /** \addtogroup hal */ |
Zaitsev | 10:41552d038a69 | 3 | /** @{*/ |
Zaitsev | 10:41552d038a69 | 4 | /* mbed Microcontroller Library |
Zaitsev | 10:41552d038a69 | 5 | * Copyright (c) 2015 ARM Limited |
Zaitsev | 10:41552d038a69 | 6 | * |
Zaitsev | 10:41552d038a69 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Zaitsev | 10:41552d038a69 | 8 | * you may not use this file except in compliance with the License. |
Zaitsev | 10:41552d038a69 | 9 | * You may obtain a copy of the License at |
Zaitsev | 10:41552d038a69 | 10 | * |
Zaitsev | 10:41552d038a69 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
Zaitsev | 10:41552d038a69 | 12 | * |
Zaitsev | 10:41552d038a69 | 13 | * Unless required by applicable law or agreed to in writing, software |
Zaitsev | 10:41552d038a69 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
Zaitsev | 10:41552d038a69 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Zaitsev | 10:41552d038a69 | 16 | * See the License for the specific language governing permissions and |
Zaitsev | 10:41552d038a69 | 17 | * limitations under the License. |
Zaitsev | 10:41552d038a69 | 18 | */ |
Zaitsev | 10:41552d038a69 | 19 | #ifndef MBED_TICKER_API_H |
Zaitsev | 10:41552d038a69 | 20 | #define MBED_TICKER_API_H |
Zaitsev | 10:41552d038a69 | 21 | |
Zaitsev | 10:41552d038a69 | 22 | #include <stdint.h> |
Zaitsev | 10:41552d038a69 | 23 | #include "device.h" |
Zaitsev | 10:41552d038a69 | 24 | |
Zaitsev | 10:41552d038a69 | 25 | typedef uint32_t timestamp_t; |
Zaitsev | 10:41552d038a69 | 26 | |
Zaitsev | 10:41552d038a69 | 27 | /** Ticker's event structure |
Zaitsev | 10:41552d038a69 | 28 | */ |
Zaitsev | 10:41552d038a69 | 29 | typedef struct ticker_event_s { |
Zaitsev | 10:41552d038a69 | 30 | timestamp_t timestamp; /**< Event's timestamp */ |
Zaitsev | 10:41552d038a69 | 31 | uint32_t id; /**< TimerEvent object */ |
Zaitsev | 10:41552d038a69 | 32 | struct ticker_event_s *next; /**< Next event in the queue */ |
Zaitsev | 10:41552d038a69 | 33 | } ticker_event_t; |
Zaitsev | 10:41552d038a69 | 34 | |
Zaitsev | 10:41552d038a69 | 35 | typedef void (*ticker_event_handler)(uint32_t id); |
Zaitsev | 10:41552d038a69 | 36 | |
Zaitsev | 10:41552d038a69 | 37 | /** Ticker's interface structure - required API for a ticker |
Zaitsev | 10:41552d038a69 | 38 | */ |
Zaitsev | 10:41552d038a69 | 39 | typedef struct { |
Zaitsev | 10:41552d038a69 | 40 | void (*init)(void); /**< Init function */ |
Zaitsev | 10:41552d038a69 | 41 | uint32_t (*read)(void); /**< Read function */ |
Zaitsev | 10:41552d038a69 | 42 | void (*disable_interrupt)(void); /**< Disable interrupt function */ |
Zaitsev | 10:41552d038a69 | 43 | void (*clear_interrupt)(void); /**< Clear interrupt function */ |
Zaitsev | 10:41552d038a69 | 44 | void (*set_interrupt)(timestamp_t timestamp); /**< Set interrupt function */ |
Zaitsev | 10:41552d038a69 | 45 | } ticker_interface_t; |
Zaitsev | 10:41552d038a69 | 46 | |
Zaitsev | 10:41552d038a69 | 47 | /** Ticker's event queue structure |
Zaitsev | 10:41552d038a69 | 48 | */ |
Zaitsev | 10:41552d038a69 | 49 | typedef struct { |
Zaitsev | 10:41552d038a69 | 50 | ticker_event_handler event_handler; /**< Event handler */ |
Zaitsev | 10:41552d038a69 | 51 | ticker_event_t *head; /**< A pointer to head */ |
Zaitsev | 10:41552d038a69 | 52 | } ticker_event_queue_t; |
Zaitsev | 10:41552d038a69 | 53 | |
Zaitsev | 10:41552d038a69 | 54 | /** Ticker's data structure |
Zaitsev | 10:41552d038a69 | 55 | */ |
Zaitsev | 10:41552d038a69 | 56 | typedef struct { |
Zaitsev | 10:41552d038a69 | 57 | const ticker_interface_t *interface; /**< Ticker's interface */ |
Zaitsev | 10:41552d038a69 | 58 | ticker_event_queue_t *queue; /**< Ticker's event queue */ |
Zaitsev | 10:41552d038a69 | 59 | } ticker_data_t; |
Zaitsev | 10:41552d038a69 | 60 | |
Zaitsev | 10:41552d038a69 | 61 | #ifdef __cplusplus |
Zaitsev | 10:41552d038a69 | 62 | extern "C" { |
Zaitsev | 10:41552d038a69 | 63 | #endif |
Zaitsev | 10:41552d038a69 | 64 | |
Zaitsev | 10:41552d038a69 | 65 | /** |
Zaitsev | 10:41552d038a69 | 66 | * \defgroup hal_ticker Ticker HAL functions |
Zaitsev | 10:41552d038a69 | 67 | * @{ |
Zaitsev | 10:41552d038a69 | 68 | */ |
Zaitsev | 10:41552d038a69 | 69 | |
Zaitsev | 10:41552d038a69 | 70 | /** Initialize a ticker and set the event handler |
Zaitsev | 10:41552d038a69 | 71 | * |
Zaitsev | 10:41552d038a69 | 72 | * @param data The ticker's data |
Zaitsev | 10:41552d038a69 | 73 | * @param handler A handler to be set |
Zaitsev | 10:41552d038a69 | 74 | */ |
Zaitsev | 10:41552d038a69 | 75 | void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler); |
Zaitsev | 10:41552d038a69 | 76 | |
Zaitsev | 10:41552d038a69 | 77 | /** IRQ handler that goes through the events to trigger overdue events. |
Zaitsev | 10:41552d038a69 | 78 | * |
Zaitsev | 10:41552d038a69 | 79 | * @param data The ticker's data |
Zaitsev | 10:41552d038a69 | 80 | */ |
Zaitsev | 10:41552d038a69 | 81 | void ticker_irq_handler(const ticker_data_t *const data); |
Zaitsev | 10:41552d038a69 | 82 | |
Zaitsev | 10:41552d038a69 | 83 | /** Remove an event from the queue |
Zaitsev | 10:41552d038a69 | 84 | * |
Zaitsev | 10:41552d038a69 | 85 | * @param data The ticker's data |
Zaitsev | 10:41552d038a69 | 86 | * @param obj The event object to be removed from the queue |
Zaitsev | 10:41552d038a69 | 87 | */ |
Zaitsev | 10:41552d038a69 | 88 | void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj); |
Zaitsev | 10:41552d038a69 | 89 | |
Zaitsev | 10:41552d038a69 | 90 | /** Insert an event to the queue |
Zaitsev | 10:41552d038a69 | 91 | * |
Zaitsev | 10:41552d038a69 | 92 | * @param data The ticker's data |
Zaitsev | 10:41552d038a69 | 93 | * @param obj The event object to be inserted to the queue |
Zaitsev | 10:41552d038a69 | 94 | * @param timestamp The event's timestamp |
Zaitsev | 10:41552d038a69 | 95 | * @param id The event object |
Zaitsev | 10:41552d038a69 | 96 | */ |
Zaitsev | 10:41552d038a69 | 97 | void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id); |
Zaitsev | 10:41552d038a69 | 98 | |
Zaitsev | 10:41552d038a69 | 99 | /** Read the current ticker's timestamp |
Zaitsev | 10:41552d038a69 | 100 | * |
Zaitsev | 10:41552d038a69 | 101 | * @param data The ticker's data |
Zaitsev | 10:41552d038a69 | 102 | * @return The current timestamp |
Zaitsev | 10:41552d038a69 | 103 | */ |
Zaitsev | 10:41552d038a69 | 104 | timestamp_t ticker_read(const ticker_data_t *const data); |
Zaitsev | 10:41552d038a69 | 105 | |
Zaitsev | 10:41552d038a69 | 106 | /** Read the next event's timestamp |
Zaitsev | 10:41552d038a69 | 107 | * |
Zaitsev | 10:41552d038a69 | 108 | * @param data The ticker's data |
Zaitsev | 10:41552d038a69 | 109 | * @return 1 if timestamp is pending event, 0 if there's no event pending |
Zaitsev | 10:41552d038a69 | 110 | */ |
Zaitsev | 10:41552d038a69 | 111 | int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *timestamp); |
Zaitsev | 10:41552d038a69 | 112 | |
Zaitsev | 10:41552d038a69 | 113 | /**@}*/ |
Zaitsev | 10:41552d038a69 | 114 | |
Zaitsev | 10:41552d038a69 | 115 | #ifdef __cplusplus |
Zaitsev | 10:41552d038a69 | 116 | } |
Zaitsev | 10:41552d038a69 | 117 | #endif |
Zaitsev | 10:41552d038a69 | 118 | |
Zaitsev | 10:41552d038a69 | 119 | #endif |
Zaitsev | 10:41552d038a69 | 120 | |
Zaitsev | 10:41552d038a69 | 121 | /** @}*/ |