mbed library sources. Supersedes mbed-src.

Dependents:   LPCXpresso1769_blinky

Fork of mbed-dev by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ticker_api.h Source File

ticker_api.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2015 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef MBED_TICKER_API_H
00017 #define MBED_TICKER_API_H
00018 
00019 #include <stdint.h>
00020 #include "device.h"
00021 
00022 typedef uint32_t timestamp_t;
00023 
00024 /** Ticker's event structure
00025  */
00026 typedef struct ticker_event_s {
00027     timestamp_t            timestamp; /**< Event's timestamp */
00028     uint32_t               id;        /**< TimerEvent object */
00029     struct ticker_event_s *next;      /**< Next event in the queue */
00030 } ticker_event_t;
00031 
00032 typedef void (*ticker_event_handler)(uint32_t id);
00033 
00034 /** Ticker's interface structure - required API for a ticker
00035  */
00036 typedef struct {
00037     void (*init)(void);                           /**< Init function */
00038     uint32_t (*read)(void);                       /**< Read function */
00039     void (*disable_interrupt)(void);              /**< Disable interrupt function */
00040     void (*clear_interrupt)(void);                /**< Clear interrupt function */
00041     void (*set_interrupt)(timestamp_t timestamp); /**< Set interrupt function */
00042 } ticker_interface_t;
00043 
00044 /** Ticker's event queue structure
00045  */
00046 typedef struct {
00047     ticker_event_handler event_handler; /**< Event handler */
00048     ticker_event_t *head;               /**< A pointer to head */
00049 } ticker_event_queue_t;
00050 
00051 /** Ticker's data structure
00052  */
00053 typedef struct {
00054     const ticker_interface_t *interface; /**< Ticker's interface */
00055     ticker_event_queue_t *queue;         /**< Ticker's event queue */
00056 } ticker_data_t;
00057 
00058 #ifdef __cplusplus
00059 extern "C" {
00060 #endif
00061 
00062 /**
00063  * \defgroup hal_ticker Ticker HAL functions
00064  * @{
00065  */
00066 
00067 /** Initialize a ticker and set the event handler
00068  *
00069  * @param data    The ticker's data
00070  * @param handler A handler to be set
00071  */
00072 void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler);
00073 
00074 /** IRQ handler that goes through the events to trigger overdue events.
00075  *
00076  * @param data    The ticker's data
00077  */
00078 void ticker_irq_handler(const ticker_data_t *const data);
00079 
00080 /** Remove an event from the queue
00081  *
00082  * @param data The ticker's data
00083  * @param obj  The event object to be removed from the queue
00084  */
00085 void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj);
00086 
00087 /** Insert an event to the queue
00088  *
00089  * @param data      The ticker's data
00090  * @param obj       The event object to be inserted to the queue
00091  * @param timestamp The event's timestamp
00092  * @param id        The event object
00093  */
00094 void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id);
00095 
00096 /** Read the current ticker's timestamp
00097  *
00098  * @param data The ticker's data
00099  * @return The current timestamp
00100  */
00101 timestamp_t ticker_read(const ticker_data_t *const data);
00102 
00103 /** Read the next event's timestamp
00104  *
00105  * @param data The ticker's data
00106  * @return 1 if timestamp is pending event, 0 if there's no event pending
00107  */
00108 int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *timestamp);
00109 
00110 /**@}*/
00111 
00112 #ifdef __cplusplus
00113 }
00114 #endif
00115 
00116 #endif