Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
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 "device.h" 00020 00021 typedef uint32_t timestamp_t; 00022 00023 /** Ticker's event structure 00024 */ 00025 typedef struct ticker_event_s { 00026 timestamp_t timestamp; /**< Event's timestamp */ 00027 uint32_t id; /**< TimerEvent object */ 00028 struct ticker_event_s *next; /**< Next event in the queue */ 00029 } ticker_event_t; 00030 00031 typedef void (*ticker_event_handler)(uint32_t id); 00032 00033 /** Ticker's interface structure - required API for a ticker 00034 */ 00035 typedef struct { 00036 void (*init)(void); /**< Init function */ 00037 uint32_t (*read)(void); /**< Read function */ 00038 void (*disable_interrupt)(void); /**< Disable interrupt function */ 00039 void (*clear_interrupt)(void); /**< Clear interrupt function */ 00040 void (*set_interrupt)(timestamp_t timestamp); /**< Set interrupt function */ 00041 } ticker_interface_t; 00042 00043 /** Tickers events queue structure 00044 */ 00045 typedef struct { 00046 ticker_event_handler event_handler; /**< Event handler */ 00047 ticker_event_t *head; /**< A pointer to head */ 00048 } ticker_event_queue_t; 00049 00050 /** Tickers data structure 00051 */ 00052 typedef struct { 00053 const ticker_interface_t *interface; /**< Ticker's interface */ 00054 ticker_event_queue_t *queue; /**< Ticker's events queue */ 00055 } ticker_data_t; 00056 00057 #ifdef __cplusplus 00058 extern "C" { 00059 #endif 00060 00061 /** Initialize a ticker and sets the event handler 00062 * 00063 * @param data The ticker's data 00064 * @param handler A handler to be set 00065 */ 00066 void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler); 00067 00068 /** Irq handler which goes through the events to trigger events in the past. 00069 * 00070 * @param data The ticker's data 00071 */ 00072 void ticker_irq_handler(const ticker_data_t *const data); 00073 00074 /** Remove an event from the queue 00075 * 00076 * @param data The ticker's data 00077 * @param obj The event's queue to be removed 00078 */ 00079 void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj); 00080 00081 /** Insert an event from the queue 00082 * 00083 * @param data The ticker's data 00084 * @param obj The event's queue to be removed 00085 * @param timestamp The event's timestamp 00086 * @param id The event object 00087 */ 00088 void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id); 00089 00090 /** Read the current ticker's timestamp 00091 * 00092 * @param data The ticker's data 00093 * @return The current timestamp 00094 */ 00095 timestamp_t ticker_read(const ticker_data_t *const data); 00096 00097 /** Read the next event's timestamp 00098 * 00099 * @param data The ticker's data 00100 * @return 1 if timestamp is pending event, 0 if there's no event pending 00101 */ 00102 int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *timestamp); 00103 00104 #ifdef __cplusplus 00105 } 00106 #endif 00107 00108 #endif
Generated on Tue Jul 12 2022 18:56:14 by
