Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

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