The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
170:e95d10626187
mbed library release version 165

Who changed what in which revision?

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