t

Fork of mbed-dev by mbed official

Committer:
amithy
Date:
Thu Nov 09 22:14:37 2017 +0000
Revision:
178:c26431f84b0d
Parent:
149:156823d33999
Child:
167:e84263d55307
test export

Who changed what in which revision?

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