PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Committer:
Pokitto
Date:
Wed Oct 11 20:35:27 2017 +0000
Revision:
5:ea7377f3d1af
Fixed PokittoLib. Includes a working custom mbed-src

Who changed what in which revision?

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