mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 189:f392fc9709a3 1 /* mbed Microcontroller Library
AnnaBridge 189:f392fc9709a3 2 * Copyright (c) 2006-2013 ARM Limited
AnnaBridge 189:f392fc9709a3 3 * SPDX-License-Identifier: Apache-2.0
AnnaBridge 189:f392fc9709a3 4 *
AnnaBridge 189:f392fc9709a3 5 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 189:f392fc9709a3 6 * you may not use this file except in compliance with the License.
AnnaBridge 189:f392fc9709a3 7 * You may obtain a copy of the License at
AnnaBridge 189:f392fc9709a3 8 *
AnnaBridge 189:f392fc9709a3 9 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 189:f392fc9709a3 10 *
AnnaBridge 189:f392fc9709a3 11 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 189:f392fc9709a3 12 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 189:f392fc9709a3 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 189:f392fc9709a3 14 * See the License for the specific language governing permissions and
AnnaBridge 189:f392fc9709a3 15 * limitations under the License.
AnnaBridge 189:f392fc9709a3 16 */
AnnaBridge 189:f392fc9709a3 17 #ifndef MBED_INTERRUPTMANAGER_H
AnnaBridge 189:f392fc9709a3 18 #define MBED_INTERRUPTMANAGER_H
AnnaBridge 189:f392fc9709a3 19
AnnaBridge 189:f392fc9709a3 20 #include "cmsis.h"
AnnaBridge 189:f392fc9709a3 21 #include "platform/CallChain.h"
AnnaBridge 189:f392fc9709a3 22 #include "platform/PlatformMutex.h"
AnnaBridge 189:f392fc9709a3 23 #include "platform/NonCopyable.h"
AnnaBridge 189:f392fc9709a3 24 #include <string.h>
AnnaBridge 189:f392fc9709a3 25
AnnaBridge 189:f392fc9709a3 26 namespace mbed {
AnnaBridge 189:f392fc9709a3 27 /** \addtogroup drivers */
AnnaBridge 189:f392fc9709a3 28
AnnaBridge 189:f392fc9709a3 29 /** Use this singleton if you need to chain interrupt handlers.
AnnaBridge 189:f392fc9709a3 30 * @deprecated Do not use this class. This class is not part of the public API of mbed-os and is being removed in the future.
AnnaBridge 189:f392fc9709a3 31 *
AnnaBridge 189:f392fc9709a3 32 * @note Synchronization level: Thread safe
AnnaBridge 189:f392fc9709a3 33 *
AnnaBridge 189:f392fc9709a3 34 * Example (for LPC1768):
AnnaBridge 189:f392fc9709a3 35 * @code
AnnaBridge 189:f392fc9709a3 36 * #include "InterruptManager.h"
AnnaBridge 189:f392fc9709a3 37 * #include "mbed.h"
AnnaBridge 189:f392fc9709a3 38 *
AnnaBridge 189:f392fc9709a3 39 * Ticker flipper;
AnnaBridge 189:f392fc9709a3 40 * DigitalOut led1(LED1);
AnnaBridge 189:f392fc9709a3 41 * DigitalOut led2(LED2);
AnnaBridge 189:f392fc9709a3 42 *
AnnaBridge 189:f392fc9709a3 43 * void flip(void) {
AnnaBridge 189:f392fc9709a3 44 * led1 = !led1;
AnnaBridge 189:f392fc9709a3 45 * }
AnnaBridge 189:f392fc9709a3 46 *
AnnaBridge 189:f392fc9709a3 47 * void handler(void) {
AnnaBridge 189:f392fc9709a3 48 * led2 = !led1;
AnnaBridge 189:f392fc9709a3 49 * }
AnnaBridge 189:f392fc9709a3 50 *
AnnaBridge 189:f392fc9709a3 51 * int main() {
AnnaBridge 189:f392fc9709a3 52 * led1 = led2 = 0;
AnnaBridge 189:f392fc9709a3 53 * flipper.attach(&flip, 1.0);
AnnaBridge 189:f392fc9709a3 54 * InterruptManager::get()->add_handler(handler, TIMER3_IRQn);
AnnaBridge 189:f392fc9709a3 55 * }
AnnaBridge 189:f392fc9709a3 56 * @endcode
AnnaBridge 189:f392fc9709a3 57 * @ingroup drivers
AnnaBridge 189:f392fc9709a3 58 */
AnnaBridge 189:f392fc9709a3 59 class InterruptManager : private NonCopyable<InterruptManager> {
AnnaBridge 189:f392fc9709a3 60 public:
AnnaBridge 189:f392fc9709a3 61 /** Get the instance of InterruptManager Class
AnnaBridge 189:f392fc9709a3 62 * @deprecated
AnnaBridge 189:f392fc9709a3 63 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
AnnaBridge 189:f392fc9709a3 64 *
AnnaBridge 189:f392fc9709a3 65 * @return the only instance of this class
AnnaBridge 189:f392fc9709a3 66 */
AnnaBridge 189:f392fc9709a3 67 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
AnnaBridge 189:f392fc9709a3 68 "public API of mbed-os and is being removed in the future.")
AnnaBridge 189:f392fc9709a3 69 static InterruptManager *get();
AnnaBridge 189:f392fc9709a3 70
AnnaBridge 189:f392fc9709a3 71 /** Destroy the current instance of the interrupt manager
AnnaBridge 189:f392fc9709a3 72 * @deprecated
AnnaBridge 189:f392fc9709a3 73 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
AnnaBridge 189:f392fc9709a3 74 *
AnnaBridge 189:f392fc9709a3 75 */
AnnaBridge 189:f392fc9709a3 76 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
AnnaBridge 189:f392fc9709a3 77 "public API of mbed-os and is being removed in the future.")
AnnaBridge 189:f392fc9709a3 78 static void destroy();
AnnaBridge 189:f392fc9709a3 79
AnnaBridge 189:f392fc9709a3 80 /** Add a handler for an interrupt at the end of the handler list
AnnaBridge 189:f392fc9709a3 81 * @deprecated
AnnaBridge 189:f392fc9709a3 82 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
AnnaBridge 189:f392fc9709a3 83 *
AnnaBridge 189:f392fc9709a3 84 * @param function the handler to add
AnnaBridge 189:f392fc9709a3 85 * @param irq interrupt number
AnnaBridge 189:f392fc9709a3 86 *
AnnaBridge 189:f392fc9709a3 87 * @returns
AnnaBridge 189:f392fc9709a3 88 * The function object created for 'function'
AnnaBridge 189:f392fc9709a3 89 */
AnnaBridge 189:f392fc9709a3 90 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
AnnaBridge 189:f392fc9709a3 91 "public API of mbed-os and is being removed in the future.")
AnnaBridge 189:f392fc9709a3 92 pFunctionPointer_t add_handler(void (*function)(void), IRQn_Type irq)
AnnaBridge 189:f392fc9709a3 93 {
AnnaBridge 189:f392fc9709a3 94 // Underlying call is thread safe
AnnaBridge 189:f392fc9709a3 95 return add_common(function, irq);
AnnaBridge 189:f392fc9709a3 96 }
AnnaBridge 189:f392fc9709a3 97
AnnaBridge 189:f392fc9709a3 98 /** Add a handler for an interrupt at the beginning of the handler list
AnnaBridge 189:f392fc9709a3 99 * @deprecated
AnnaBridge 189:f392fc9709a3 100 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
AnnaBridge 189:f392fc9709a3 101 *
AnnaBridge 189:f392fc9709a3 102 * @param function the handler to add
AnnaBridge 189:f392fc9709a3 103 * @param irq interrupt number
AnnaBridge 189:f392fc9709a3 104 *
AnnaBridge 189:f392fc9709a3 105 * @returns
AnnaBridge 189:f392fc9709a3 106 * The function object created for 'function'
AnnaBridge 189:f392fc9709a3 107 */
AnnaBridge 189:f392fc9709a3 108 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
AnnaBridge 189:f392fc9709a3 109 "public API of mbed-os and is being removed in the future.")
AnnaBridge 189:f392fc9709a3 110 pFunctionPointer_t add_handler_front(void (*function)(void), IRQn_Type irq)
AnnaBridge 189:f392fc9709a3 111 {
AnnaBridge 189:f392fc9709a3 112 // Underlying call is thread safe
AnnaBridge 189:f392fc9709a3 113 return add_common(function, irq, true);
AnnaBridge 189:f392fc9709a3 114 }
AnnaBridge 189:f392fc9709a3 115
AnnaBridge 189:f392fc9709a3 116 /** Add a handler for an interrupt at the end of the handler list
AnnaBridge 189:f392fc9709a3 117 * @deprecated
AnnaBridge 189:f392fc9709a3 118 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
AnnaBridge 189:f392fc9709a3 119 *
AnnaBridge 189:f392fc9709a3 120 * @param tptr pointer to the object that has the handler function
AnnaBridge 189:f392fc9709a3 121 * @param mptr pointer to the actual handler function
AnnaBridge 189:f392fc9709a3 122 * @param irq interrupt number
AnnaBridge 189:f392fc9709a3 123 *
AnnaBridge 189:f392fc9709a3 124 * @returns
AnnaBridge 189:f392fc9709a3 125 * The function object created for 'tptr' and 'mptr'
AnnaBridge 189:f392fc9709a3 126 */
AnnaBridge 189:f392fc9709a3 127 template<typename T>
AnnaBridge 189:f392fc9709a3 128 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
AnnaBridge 189:f392fc9709a3 129 "public API of mbed-os and is being removed in the future.")
AnnaBridge 189:f392fc9709a3 130 pFunctionPointer_t add_handler(T *tptr, void (T::*mptr)(void), IRQn_Type irq)
AnnaBridge 189:f392fc9709a3 131 {
AnnaBridge 189:f392fc9709a3 132 // Underlying call is thread safe
AnnaBridge 189:f392fc9709a3 133 return add_common(tptr, mptr, irq);
AnnaBridge 189:f392fc9709a3 134 }
AnnaBridge 189:f392fc9709a3 135
AnnaBridge 189:f392fc9709a3 136 /** Add a handler for an interrupt at the beginning of the handler list
AnnaBridge 189:f392fc9709a3 137 * @deprecated
AnnaBridge 189:f392fc9709a3 138 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
AnnaBridge 189:f392fc9709a3 139 *
AnnaBridge 189:f392fc9709a3 140 * @param tptr pointer to the object that has the handler function
AnnaBridge 189:f392fc9709a3 141 * @param mptr pointer to the actual handler function
AnnaBridge 189:f392fc9709a3 142 * @param irq interrupt number
AnnaBridge 189:f392fc9709a3 143 *
AnnaBridge 189:f392fc9709a3 144 * @returns
AnnaBridge 189:f392fc9709a3 145 * The function object created for 'tptr' and 'mptr'
AnnaBridge 189:f392fc9709a3 146 */
AnnaBridge 189:f392fc9709a3 147 template<typename T>
AnnaBridge 189:f392fc9709a3 148 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
AnnaBridge 189:f392fc9709a3 149 "public API of mbed-os and is being removed in the future.")
AnnaBridge 189:f392fc9709a3 150 pFunctionPointer_t add_handler_front(T *tptr, void (T::*mptr)(void), IRQn_Type irq)
AnnaBridge 189:f392fc9709a3 151 {
AnnaBridge 189:f392fc9709a3 152 // Underlying call is thread safe
AnnaBridge 189:f392fc9709a3 153 return add_common(tptr, mptr, irq, true);
AnnaBridge 189:f392fc9709a3 154 }
AnnaBridge 189:f392fc9709a3 155
AnnaBridge 189:f392fc9709a3 156 /** Remove a handler from an interrupt
AnnaBridge 189:f392fc9709a3 157 * @deprecated
AnnaBridge 189:f392fc9709a3 158 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
AnnaBridge 189:f392fc9709a3 159 *
AnnaBridge 189:f392fc9709a3 160 * @param handler the function object for the handler to remove
AnnaBridge 189:f392fc9709a3 161 * @param irq the interrupt number
AnnaBridge 189:f392fc9709a3 162 *
AnnaBridge 189:f392fc9709a3 163 * @returns
AnnaBridge 189:f392fc9709a3 164 * true if the handler was found and removed, false otherwise
AnnaBridge 189:f392fc9709a3 165 */
AnnaBridge 189:f392fc9709a3 166 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
AnnaBridge 189:f392fc9709a3 167 "public API of mbed-os and is being removed in the future.")
AnnaBridge 189:f392fc9709a3 168 bool remove_handler(pFunctionPointer_t handler, IRQn_Type irq);
AnnaBridge 189:f392fc9709a3 169
AnnaBridge 189:f392fc9709a3 170 #if !defined(DOXYGEN_ONLY)
AnnaBridge 189:f392fc9709a3 171 private:
AnnaBridge 189:f392fc9709a3 172 InterruptManager();
AnnaBridge 189:f392fc9709a3 173 ~InterruptManager();
AnnaBridge 189:f392fc9709a3 174
AnnaBridge 189:f392fc9709a3 175 void lock();
AnnaBridge 189:f392fc9709a3 176 void unlock();
AnnaBridge 189:f392fc9709a3 177
AnnaBridge 189:f392fc9709a3 178 template<typename T>
AnnaBridge 189:f392fc9709a3 179 pFunctionPointer_t add_common(T *tptr, void (T::*mptr)(void), IRQn_Type irq, bool front = false)
AnnaBridge 189:f392fc9709a3 180 {
AnnaBridge 189:f392fc9709a3 181 _mutex.lock();
AnnaBridge 189:f392fc9709a3 182 int irq_pos = get_irq_index(irq);
AnnaBridge 189:f392fc9709a3 183 bool change = must_replace_vector(irq);
AnnaBridge 189:f392fc9709a3 184
AnnaBridge 189:f392fc9709a3 185 pFunctionPointer_t pf = front ? _chains[irq_pos]->add_front(tptr, mptr) : _chains[irq_pos]->add(tptr, mptr);
AnnaBridge 189:f392fc9709a3 186 if (change) {
AnnaBridge 189:f392fc9709a3 187 NVIC_SetVector(irq, (uint32_t)&InterruptManager::static_irq_helper);
AnnaBridge 189:f392fc9709a3 188 }
AnnaBridge 189:f392fc9709a3 189 _mutex.unlock();
AnnaBridge 189:f392fc9709a3 190 return pf;
AnnaBridge 189:f392fc9709a3 191 }
AnnaBridge 189:f392fc9709a3 192
AnnaBridge 189:f392fc9709a3 193 pFunctionPointer_t add_common(void (*function)(void), IRQn_Type irq, bool front = false);
AnnaBridge 189:f392fc9709a3 194 bool must_replace_vector(IRQn_Type irq);
AnnaBridge 189:f392fc9709a3 195 int get_irq_index(IRQn_Type irq);
AnnaBridge 189:f392fc9709a3 196 void irq_helper();
AnnaBridge 189:f392fc9709a3 197 void add_helper(void (*function)(void), IRQn_Type irq, bool front = false);
AnnaBridge 189:f392fc9709a3 198 static void static_irq_helper();
AnnaBridge 189:f392fc9709a3 199
AnnaBridge 189:f392fc9709a3 200 CallChain *_chains[NVIC_NUM_VECTORS];
AnnaBridge 189:f392fc9709a3 201 static InterruptManager *_instance;
AnnaBridge 189:f392fc9709a3 202 PlatformMutex _mutex;
AnnaBridge 189:f392fc9709a3 203 #endif
AnnaBridge 189:f392fc9709a3 204 };
AnnaBridge 189:f392fc9709a3 205
AnnaBridge 189:f392fc9709a3 206 } // namespace mbed
AnnaBridge 189:f392fc9709a3 207
AnnaBridge 189:f392fc9709a3 208 #endif