mbed library for slider v2

Dependents:   kl46z_slider_v2

Committer:
mturner5
Date:
Wed Sep 14 07:04:27 2016 +0000
Revision:
0:b7116bd48af6
Tried to use the timer.

Who changed what in which revision?

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