Changeset 429 for EcnlProtoTool/trunk/asp3_dcre/mbed/hal/ticker_api.h
- Timestamp:
- Jul 3, 2020, 7:19:17 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/asp3_dcre/mbed/hal/ticker_api.h
r321 r429 1 2 /** \addtogroup hal */ 3 /** @{*/ 1 4 /* mbed Microcontroller Library 2 5 * Copyright (c) 2015 ARM Limited … … 17 20 #define MBED_TICKER_API_H 18 21 22 #include <stdint.h> 23 #include <stdbool.h> 19 24 #include "device.h" 20 25 26 /** 27 * Legacy format representing a timestamp in us. 28 * Given it is modeled as a 32 bit integer, this type can represent timestamp 29 * up to 4294 seconds (71 minutes). 30 * Prefer using us_timestamp_t which store timestamp as 64 bits integer. 31 */ 21 32 typedef uint32_t timestamp_t; 22 33 34 /** 35 * A us timestamp stored in a 64 bit integer. 36 * Can store timestamp up to 584810 years. 37 */ 38 typedef uint64_t us_timestamp_t; 39 23 40 /** Ticker's event structure 24 41 */ 25 42 typedef struct ticker_event_s { 26 timestamp_ttimestamp; /**< Event's timestamp */43 us_timestamp_t timestamp; /**< Event's timestamp */ 27 44 uint32_t id; /**< TimerEvent object */ 28 45 struct ticker_event_s *next; /**< Next event in the queue */ … … 30 47 31 48 typedef void (*ticker_event_handler)(uint32_t id); 49 50 /** Information about the ticker implementation 51 */ 52 typedef struct { 53 uint32_t frequency; /**< Frequency in Hz this ticker runs at */ 54 uint32_t bits; /**< Number of bits this ticker supports */ 55 } ticker_info_t; 56 32 57 33 58 /** Ticker's interface structure - required API for a ticker … … 39 64 void (*clear_interrupt)(void); /**< Clear interrupt function */ 40 65 void (*set_interrupt)(timestamp_t timestamp); /**< Set interrupt function */ 66 void (*fire_interrupt)(void); /**< Fire interrupt right-away */ 67 void (*free)(void); /**< Disable function */ 68 const ticker_info_t *(*get_info)(void); /**< Return info about this ticker's implementation */ 41 69 } ticker_interface_t; 42 70 43 /** Ticker s eventsqueue structure71 /** Ticker's event queue structure 44 72 */ 45 73 typedef struct { 46 74 ticker_event_handler event_handler; /**< Event handler */ 47 75 ticker_event_t *head; /**< A pointer to head */ 76 uint32_t frequency; /**< Frequency of the timer in Hz */ 77 uint32_t bitmask; /**< Mask to be applied to time values read */ 78 uint32_t max_delta; /**< Largest delta in ticks that can be used when scheduling */ 79 uint64_t max_delta_us; /**< Largest delta in us that can be used when scheduling */ 80 uint32_t tick_last_read; /**< Last tick read */ 81 uint64_t tick_remainder; /**< Ticks that have not been added to base_time */ 82 us_timestamp_t present_time; /**< Store the timestamp used for present time */ 83 bool initialized; /**< Indicate if the instance is initialized */ 84 bool dispatching; /**< The function ticker_irq_handler is dispatching */ 85 bool suspended; /**< Indicate if the instance is suspended */ 86 uint8_t frequency_shifts; /**< If frequency is a value of 2^n, this is n, otherwise 0 */ 48 87 } ticker_event_queue_t; 49 88 50 /** Ticker s data structure89 /** Ticker's data structure 51 90 */ 52 91 typedef struct { 53 92 const ticker_interface_t *interface; /**< Ticker's interface */ 54 ticker_event_queue_t *queue; /**< Ticker's event squeue */93 ticker_event_queue_t *queue; /**< Ticker's event queue */ 55 94 } ticker_data_t; 56 95 … … 59 98 #endif 60 99 61 /** Initialize a ticker and sets the event handler 62 * 63 * @param data The ticker's data 100 /** 101 * \defgroup hal_ticker Ticker HAL functions 102 * @{ 103 */ 104 105 /** Initialize a ticker and set the event handler 106 * 107 * @param ticker The ticker object. 64 108 * @param handler A handler to be set 65 109 */ 66 void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler);67 68 /** I rq handler which goes through the events to trigger events in the past.69 * 70 * @param data The ticker's data71 */ 72 void ticker_irq_handler(const ticker_data_t *const data);110 void ticker_set_handler(const ticker_data_t *const ticker, ticker_event_handler handler); 111 112 /** IRQ handler that goes through the events to trigger overdue events. 113 * 114 * @param ticker The ticker object. 115 */ 116 void ticker_irq_handler(const ticker_data_t *const ticker); 73 117 74 118 /** Remove an event from the queue 75 119 * 76 * @param data The ticker's data 77 * @param obj The event's queue to be removed 78 */ 79 void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj); 80 81 /** Insert an event from the queue 82 * 83 * @param data The ticker's data 84 * @param obj The event's queue to be removed 120 * @param ticker The ticker object. 121 * @param obj The event object to be removed from the queue 122 */ 123 void ticker_remove_event(const ticker_data_t *const ticker, ticker_event_t *obj); 124 125 /** Insert an event to the queue 126 * 127 * The event will be executed in timestamp - ticker_read(). 128 * 129 * @warning This function does not consider timestamp in the past. If an event 130 * is inserted with a timestamp less than the current timestamp then the event 131 * will be executed in timestamp - ticker_read() us. 132 * The internal counter wrap very quickly it is hard to decide weither an 133 * event is in the past or in 1 hour. 134 * 135 * @note prefer the use of ticker_insert_event_us which allows registration of 136 * absolute timestamp. 137 * 138 * @param ticker The ticker object. 139 * @param obj The event object to be inserted to the queue 85 140 * @param timestamp The event's timestamp 86 141 * @param id The event object 87 142 */ 88 void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id); 89 90 /** Read the current ticker's timestamp 91 * 92 * @param data The ticker's data 143 void ticker_insert_event(const ticker_data_t *const ticker, ticker_event_t *obj, timestamp_t timestamp, uint32_t id); 144 145 /** Insert an event to the queue 146 * 147 * The event will be executed in timestamp - ticker_read_us() us. 148 * 149 * @note If an event is inserted with a timestamp less than the current 150 * timestamp then the event will be scheduled immediately resulting in 151 * an instant call to event handler. 152 * 153 * @param ticker The ticker object. 154 * @param obj The event object to be inserted to the queue 155 * @param timestamp The event's timestamp 156 * @param id The event object 157 */ 158 void ticker_insert_event_us(const ticker_data_t *const ticker, ticker_event_t *obj, us_timestamp_t timestamp, uint32_t id); 159 160 /** Read the current (relative) ticker's timestamp 161 * 162 * @warning Return a relative timestamp because the counter wrap every 4294 163 * seconds. 164 * 165 * @param ticker The ticker object. 93 166 * @return The current timestamp 94 167 */ 95 timestamp_t ticker_read(const ticker_data_t *const data); 168 timestamp_t ticker_read(const ticker_data_t *const ticker); 169 170 /** Read the current (absolute) ticker's timestamp 171 * 172 * @warning Return an absolute timestamp counting from the initialization of the 173 * ticker. 174 * 175 * @param ticker The ticker object. 176 * @return The current timestamp 177 */ 178 us_timestamp_t ticker_read_us(const ticker_data_t *const ticker); 96 179 97 180 /** Read the next event's timestamp 98 181 * 99 * @param data The ticker's data 182 * @param ticker The ticker object. 183 * @param timestamp The timestamp object. 100 184 * @return 1 if timestamp is pending event, 0 if there's no event pending 101 185 */ 102 int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *timestamp); 186 int ticker_get_next_timestamp(const ticker_data_t *const ticker, timestamp_t *timestamp); 187 188 /** Suspend this ticker 189 * 190 * When suspended reads will always return the same time and no 191 * events will be dispatched. When suspended the common layer 192 * will only ever call the interface function clear_interrupt() 193 * and that is only if ticker_irq_handler is called. 194 * 195 * 196 * @param ticker The ticker object. 197 */ 198 void ticker_suspend(const ticker_data_t *const ticker); 199 200 /** Resume this ticker 201 * 202 * When resumed the ticker will ignore any time that has passed 203 * and continue counting up where it left off. 204 * 205 * @param ticker The ticker object. 206 */ 207 void ticker_resume(const ticker_data_t *const ticker); 208 209 /* Private functions 210 * 211 * @cond PRIVATE 212 * 213 */ 214 215 int _ticker_match_interval_passed(timestamp_t prev_tick, timestamp_t cur_tick, timestamp_t match_tick); 216 217 /* 218 * @endcond PRIVATE 219 * 220 */ 221 222 /**@}*/ 103 223 104 224 #ifdef __cplusplus … … 107 227 108 228 #endif 229 230 /** @}*/
Note:
See TracChangeset
for help on using the changeset viewer.