Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

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