mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Thu Sep 10 20:14:29 2015 +1000
Revision:
11:8123a070ade6
Parent:
1:71204b8406f2
Added .hgignore

Who changed what in which revision?

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