Ignore:
Timestamp:
Jul 3, 2020, 7:19:17 PM (4 years ago)
Author:
coas-nagasima
Message:

ASP3, TINET, mbed を更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/asp3_dcre/mbed/hal/ticker_api.h

    r321 r429  
     1
     2/** \addtogroup hal */
     3/** @{*/
    14/* mbed Microcontroller Library
    25 * Copyright (c) 2015 ARM Limited
     
    1720#define MBED_TICKER_API_H
    1821
     22#include <stdint.h>
     23#include <stdbool.h>
    1924#include "device.h"
    2025
     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 */
    2132typedef uint32_t timestamp_t;
    2233
     34/**
     35 * A us timestamp stored in a 64 bit integer.
     36 * Can store timestamp up to 584810 years.
     37 */
     38typedef uint64_t us_timestamp_t;
     39
    2340/** Ticker's event structure
    2441 */
    2542typedef struct ticker_event_s {
    26     timestamp_t            timestamp; /**< Event's timestamp */
     43    us_timestamp_t         timestamp; /**< Event's timestamp */
    2744    uint32_t               id;        /**< TimerEvent object */
    2845    struct ticker_event_s *next;      /**< Next event in the queue */
     
    3047
    3148typedef void (*ticker_event_handler)(uint32_t id);
     49
     50/** Information about the ticker implementation
     51 */
     52typedef 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
    3257
    3358/** Ticker's interface structure - required API for a ticker
     
    3964    void (*clear_interrupt)(void);                /**< Clear interrupt function */
    4065    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 */
    4169} ticker_interface_t;
    4270
    43 /** Tickers events queue structure
     71/** Ticker's event queue structure
    4472 */
    4573typedef struct {
    4674    ticker_event_handler event_handler; /**< Event handler */
    4775    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 */
    4887} ticker_event_queue_t;
    4988
    50 /** Tickers data structure
     89/** Ticker's data structure
    5190 */
    5291typedef struct {
    5392    const ticker_interface_t *interface; /**< Ticker's interface */
    54     ticker_event_queue_t *queue;         /**< Ticker's events queue */
     93    ticker_event_queue_t *queue;         /**< Ticker's event queue */
    5594} ticker_data_t;
    5695
     
    5998#endif
    6099
    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.
    64108 * @param handler A handler to be set
    65109 */
    66 void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler);
    67 
    68 /** Irq handler which goes through the events to trigger events in the past.
    69  *
    70  * @param data    The ticker's data
    71  */
    72 void ticker_irq_handler(const ticker_data_t *const data);
     110void 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 */
     116void ticker_irq_handler(const ticker_data_t *const ticker);
    73117
    74118/** Remove an event from the queue
    75119 *
    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 */
     123void 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
    85140 * @param timestamp The event's timestamp
    86141 * @param id        The event object
    87142 */
    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
     143void 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 */
     158void 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.
    93166 * @return The current timestamp
    94167 */
    95 timestamp_t ticker_read(const ticker_data_t *const data);
     168timestamp_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 */
     178us_timestamp_t ticker_read_us(const ticker_data_t *const ticker);
    96179
    97180/** Read the next event's timestamp
    98181 *
    99  * @param data The ticker's data
     182 * @param ticker        The ticker object.
     183 * @param timestamp     The timestamp object.
    100184 * @return 1 if timestamp is pending event, 0 if there's no event pending
    101185 */
    102 int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *timestamp);
     186int 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 */
     198void 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 */
     207void ticker_resume(const ticker_data_t *const ticker);
     208
     209/* Private functions
     210 *
     211 * @cond PRIVATE
     212 *
     213 */
     214
     215int _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/**@}*/
    103223
    104224#ifdef __cplusplus
     
    107227
    108228#endif
     229
     230/** @}*/
Note: See TracChangeset for help on using the changeset viewer.