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