Maxim mbed development library

Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

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