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