Changeset 374 for asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/hal/ticker_api.h
- Timestamp:
- Apr 5, 2019, 9:26:53 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/hal/ticker_api.h
r352 r374 21 21 22 22 #include <stdint.h> 23 #include <stdbool.h> 23 24 #include "device.h" 24 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 */ 25 32 typedef uint32_t timestamp_t; 26 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 27 40 /** Ticker's event structure 28 41 */ 29 42 typedef struct ticker_event_s { 30 timestamp_ttimestamp; /**< Event's timestamp */43 us_timestamp_t timestamp; /**< Event's timestamp */ 31 44 uint32_t id; /**< TimerEvent object */ 32 45 struct ticker_event_s *next; /**< Next event in the queue */ … … 34 47 35 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 36 57 37 58 /** Ticker's interface structure - required API for a ticker … … 43 64 void (*clear_interrupt)(void); /**< Clear interrupt function */ 44 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 */ 45 69 } ticker_interface_t; 46 70 … … 50 74 ticker_event_handler event_handler; /**< Event handler */ 51 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 */ 52 87 } ticker_event_queue_t; 53 88 … … 70 105 /** Initialize a ticker and set the event handler 71 106 * 72 * @param data The ticker's data107 * @param ticker The ticker object. 73 108 * @param handler A handler to be set 74 109 */ 75 void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler);110 void ticker_set_handler(const ticker_data_t *const ticker, ticker_event_handler handler); 76 111 77 112 /** IRQ handler that goes through the events to trigger overdue events. 78 113 * 79 * @param data The ticker's data80 */ 81 void ticker_irq_handler(const ticker_data_t *const data);114 * @param ticker The ticker object. 115 */ 116 void ticker_irq_handler(const ticker_data_t *const ticker); 82 117 83 118 /** Remove an event from the queue 84 119 * 85 * @param data The ticker's data120 * @param ticker The ticker object. 86 121 * @param obj The event object to be removed from the queue 87 122 */ 88 void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj);123 void ticker_remove_event(const ticker_data_t *const ticker, ticker_event_t *obj); 89 124 90 125 /** Insert an event to the queue 91 126 * 92 * @param data The ticker's data 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. 93 139 * @param obj The event object to be inserted to the queue 94 140 * @param timestamp The event's timestamp 95 141 * @param id The event object 96 142 */ 97 void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id); 98 99 /** Read the current ticker's timestamp 100 * 101 * @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. 102 166 * @return The current timestamp 103 167 */ 104 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); 105 179 106 180 /** Read the next event's timestamp 107 181 * 108 * @param data The ticker's data 182 * @param ticker The ticker object. 183 * @param timestamp The timestamp object. 109 184 * @return 1 if timestamp is pending event, 0 if there's no event pending 110 185 */ 111 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 */ 112 221 113 222 /**@}*/
Note:
See TracChangeset
for help on using the changeset viewer.