SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 09:08:29 2019 +0000
Revision:
0:aa3fc5ad02f7
SPKT

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phungductung 0:aa3fc5ad02f7 1 /* mbed Microcontroller Library
phungductung 0:aa3fc5ad02f7 2 * Copyright (c) 2015 ARM Limited
phungductung 0:aa3fc5ad02f7 3 *
phungductung 0:aa3fc5ad02f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
phungductung 0:aa3fc5ad02f7 5 * you may not use this file except in compliance with the License.
phungductung 0:aa3fc5ad02f7 6 * You may obtain a copy of the License at
phungductung 0:aa3fc5ad02f7 7 *
phungductung 0:aa3fc5ad02f7 8 * http://www.apache.org/licenses/LICENSE-2.0
phungductung 0:aa3fc5ad02f7 9 *
phungductung 0:aa3fc5ad02f7 10 * Unless required by applicable law or agreed to in writing, software
phungductung 0:aa3fc5ad02f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
phungductung 0:aa3fc5ad02f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
phungductung 0:aa3fc5ad02f7 13 * See the License for the specific language governing permissions and
phungductung 0:aa3fc5ad02f7 14 * limitations under the License.
phungductung 0:aa3fc5ad02f7 15 */
phungductung 0:aa3fc5ad02f7 16 #ifndef MBED_TICKER_API_H
phungductung 0:aa3fc5ad02f7 17 #define MBED_TICKER_API_H
phungductung 0:aa3fc5ad02f7 18
phungductung 0:aa3fc5ad02f7 19 #include "device.h"
phungductung 0:aa3fc5ad02f7 20
phungductung 0:aa3fc5ad02f7 21 typedef uint32_t timestamp_t;
phungductung 0:aa3fc5ad02f7 22
phungductung 0:aa3fc5ad02f7 23 /** Ticker's event structure
phungductung 0:aa3fc5ad02f7 24 */
phungductung 0:aa3fc5ad02f7 25 typedef struct ticker_event_s {
phungductung 0:aa3fc5ad02f7 26 timestamp_t timestamp; /**< Event's timestamp */
phungductung 0:aa3fc5ad02f7 27 uint32_t id; /**< TimerEvent object */
phungductung 0:aa3fc5ad02f7 28 struct ticker_event_s *next; /**< Next event in the queue */
phungductung 0:aa3fc5ad02f7 29 } ticker_event_t;
phungductung 0:aa3fc5ad02f7 30
phungductung 0:aa3fc5ad02f7 31 typedef void (*ticker_event_handler)(uint32_t id);
phungductung 0:aa3fc5ad02f7 32
phungductung 0:aa3fc5ad02f7 33 /** Ticker's interface structure - required API for a ticker
phungductung 0:aa3fc5ad02f7 34 */
phungductung 0:aa3fc5ad02f7 35 typedef struct {
phungductung 0:aa3fc5ad02f7 36 void (*init)(void); /**< Init function */
phungductung 0:aa3fc5ad02f7 37 uint32_t (*read)(void); /**< Read function */
phungductung 0:aa3fc5ad02f7 38 void (*disable_interrupt)(void); /**< Disable interrupt function */
phungductung 0:aa3fc5ad02f7 39 void (*clear_interrupt)(void); /**< Clear interrupt function */
phungductung 0:aa3fc5ad02f7 40 void (*set_interrupt)(timestamp_t timestamp); /**< Set interrupt function */
phungductung 0:aa3fc5ad02f7 41 } ticker_interface_t;
phungductung 0:aa3fc5ad02f7 42
phungductung 0:aa3fc5ad02f7 43 /** Tickers events queue structure
phungductung 0:aa3fc5ad02f7 44 */
phungductung 0:aa3fc5ad02f7 45 typedef struct {
phungductung 0:aa3fc5ad02f7 46 ticker_event_handler event_handler; /**< Event handler */
phungductung 0:aa3fc5ad02f7 47 ticker_event_t *head; /**< A pointer to head */
phungductung 0:aa3fc5ad02f7 48 } ticker_event_queue_t;
phungductung 0:aa3fc5ad02f7 49
phungductung 0:aa3fc5ad02f7 50 /** Tickers data structure
phungductung 0:aa3fc5ad02f7 51 */
phungductung 0:aa3fc5ad02f7 52 typedef struct {
phungductung 0:aa3fc5ad02f7 53 const ticker_interface_t *interface; /**< Ticker's interface */
phungductung 0:aa3fc5ad02f7 54 ticker_event_queue_t *queue; /**< Ticker's events queue */
phungductung 0:aa3fc5ad02f7 55 } ticker_data_t;
phungductung 0:aa3fc5ad02f7 56
phungductung 0:aa3fc5ad02f7 57 #ifdef __cplusplus
phungductung 0:aa3fc5ad02f7 58 extern "C" {
phungductung 0:aa3fc5ad02f7 59 #endif
phungductung 0:aa3fc5ad02f7 60
phungductung 0:aa3fc5ad02f7 61 /** Initialize a ticker and sets the event handler
phungductung 0:aa3fc5ad02f7 62 *
phungductung 0:aa3fc5ad02f7 63 * @param data The ticker's data
phungductung 0:aa3fc5ad02f7 64 * @param handler A handler to be set
phungductung 0:aa3fc5ad02f7 65 */
phungductung 0:aa3fc5ad02f7 66 void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler);
phungductung 0:aa3fc5ad02f7 67
phungductung 0:aa3fc5ad02f7 68 /** Irq handler which goes through the events to trigger events in the past.
phungductung 0:aa3fc5ad02f7 69 *
phungductung 0:aa3fc5ad02f7 70 * @param data The ticker's data
phungductung 0:aa3fc5ad02f7 71 */
phungductung 0:aa3fc5ad02f7 72 void ticker_irq_handler(const ticker_data_t *const data);
phungductung 0:aa3fc5ad02f7 73
phungductung 0:aa3fc5ad02f7 74 /** Remove an event from the queue
phungductung 0:aa3fc5ad02f7 75 *
phungductung 0:aa3fc5ad02f7 76 * @param data The ticker's data
phungductung 0:aa3fc5ad02f7 77 * @param obj The event's queue to be removed
phungductung 0:aa3fc5ad02f7 78 */
phungductung 0:aa3fc5ad02f7 79 void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj);
phungductung 0:aa3fc5ad02f7 80
phungductung 0:aa3fc5ad02f7 81 /** Insert an event from the queue
phungductung 0:aa3fc5ad02f7 82 *
phungductung 0:aa3fc5ad02f7 83 * @param data The ticker's data
phungductung 0:aa3fc5ad02f7 84 * @param obj The event's queue to be removed
phungductung 0:aa3fc5ad02f7 85 * @param timestamp The event's timestamp
phungductung 0:aa3fc5ad02f7 86 * @param id The event object
phungductung 0:aa3fc5ad02f7 87 */
phungductung 0:aa3fc5ad02f7 88 void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id);
phungductung 0:aa3fc5ad02f7 89
phungductung 0:aa3fc5ad02f7 90 /** Read the current ticker's timestamp
phungductung 0:aa3fc5ad02f7 91 *
phungductung 0:aa3fc5ad02f7 92 * @param data The ticker's data
phungductung 0:aa3fc5ad02f7 93 * @return The current timestamp
phungductung 0:aa3fc5ad02f7 94 */
phungductung 0:aa3fc5ad02f7 95 timestamp_t ticker_read(const ticker_data_t *const data);
phungductung 0:aa3fc5ad02f7 96
phungductung 0:aa3fc5ad02f7 97 /** Read the next event's timestamp
phungductung 0:aa3fc5ad02f7 98 *
phungductung 0:aa3fc5ad02f7 99 * @param data The ticker's data
phungductung 0:aa3fc5ad02f7 100 * @return 1 if timestamp is pending event, 0 if there's no event pending
phungductung 0:aa3fc5ad02f7 101 */
phungductung 0:aa3fc5ad02f7 102 int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *timestamp);
phungductung 0:aa3fc5ad02f7 103
phungductung 0:aa3fc5ad02f7 104 #ifdef __cplusplus
phungductung 0:aa3fc5ad02f7 105 }
phungductung 0:aa3fc5ad02f7 106 #endif
phungductung 0:aa3fc5ad02f7 107
phungductung 0:aa3fc5ad02f7 108 #endif