test

Dependents:   robotic_fish_6

Committer:
juansal12
Date:
Fri Dec 03 23:00:34 2021 +0000
Revision:
0:c792b17d9f78
uploaded sofi code ;

Who changed what in which revision?

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