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