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