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