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