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