The official mbed C/C SDK provides the software platform and libraries to build your applications.

Fork of mbed by mbed official

Committer:
Mikchel
Date:
Sun May 03 16:04:42 2015 +0000
Revision:
99:7f6c6de930c0
Parent:
98:8ab26030e058
12

Who changed what in which revision?

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