Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: nRF51_Vdd TextLCD BME280
InterruptManager.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef MBED_INTERRUPTMANAGER_H 00017 #define MBED_INTERRUPTMANAGER_H 00018 00019 #include "cmsis.h" 00020 #include "platform/CallChain.h" 00021 #include "platform/PlatformMutex.h" 00022 #include "platform/NonCopyable.h" 00023 #include <string.h> 00024 00025 namespace mbed { 00026 /** \addtogroup drivers */ 00027 00028 /** Use this singleton if you need to chain interrupt handlers. 00029 * @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. 00030 * 00031 * @note Synchronization level: Thread safe 00032 * 00033 * Example (for LPC1768): 00034 * @code 00035 * #include "InterruptManager.h" 00036 * #include "mbed.h" 00037 * 00038 * Ticker flipper; 00039 * DigitalOut led1(LED1); 00040 * DigitalOut led2(LED2); 00041 * 00042 * void flip(void) { 00043 * led1 = !led1; 00044 * } 00045 * 00046 * void handler(void) { 00047 * led2 = !led1; 00048 * } 00049 * 00050 * int main() { 00051 * led1 = led2 = 0; 00052 * flipper.attach(&flip, 1.0); 00053 * InterruptManager::get()->add_handler(handler, TIMER3_IRQn); 00054 * } 00055 * @endcode 00056 * @ingroup drivers 00057 */ 00058 class InterruptManager : private NonCopyable<InterruptManager> { 00059 public: 00060 /** Get the instance of InterruptManager Class 00061 * @deprecated 00062 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future. 00063 * 00064 * @return the only instance of this class 00065 */ 00066 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00067 "public API of mbed-os and is being removed in the future.") 00068 static InterruptManager *get(); 00069 00070 /** Destroy the current instance of the interrupt manager 00071 * @deprecated 00072 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future. 00073 * 00074 */ 00075 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00076 "public API of mbed-os and is being removed in the future.") 00077 static void destroy(); 00078 00079 /** Add a handler for an interrupt at the end of the handler list 00080 * @deprecated 00081 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future. 00082 * 00083 * @param function the handler to add 00084 * @param irq interrupt number 00085 * 00086 * @returns 00087 * The function object created for 'function' 00088 */ 00089 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00090 "public API of mbed-os and is being removed in the future.") 00091 pFunctionPointer_t add_handler(void (*function)(void), IRQn_Type irq) 00092 { 00093 // Underlying call is thread safe 00094 return add_common(function, irq); 00095 } 00096 00097 /** Add a handler for an interrupt at the beginning of the handler list 00098 * @deprecated 00099 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future. 00100 * 00101 * @param function the handler to add 00102 * @param irq interrupt number 00103 * 00104 * @returns 00105 * The function object created for 'function' 00106 */ 00107 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00108 "public API of mbed-os and is being removed in the future.") 00109 pFunctionPointer_t add_handler_front(void (*function)(void), IRQn_Type irq) 00110 { 00111 // Underlying call is thread safe 00112 return add_common(function, irq, true); 00113 } 00114 00115 /** Add a handler for an interrupt at the end of the handler list 00116 * @deprecated 00117 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future. 00118 * 00119 * @param tptr pointer to the object that has the handler function 00120 * @param mptr pointer to the actual handler function 00121 * @param irq interrupt number 00122 * 00123 * @returns 00124 * The function object created for 'tptr' and 'mptr' 00125 */ 00126 template<typename T> 00127 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00128 "public API of mbed-os and is being removed in the future.") 00129 pFunctionPointer_t add_handler(T *tptr, void (T::*mptr)(void), IRQn_Type irq) 00130 { 00131 // Underlying call is thread safe 00132 return add_common(tptr, mptr, irq); 00133 } 00134 00135 /** Add a handler for an interrupt at the beginning of the handler list 00136 * @deprecated 00137 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future. 00138 * 00139 * @param tptr pointer to the object that has the handler function 00140 * @param mptr pointer to the actual handler function 00141 * @param irq interrupt number 00142 * 00143 * @returns 00144 * The function object created for 'tptr' and 'mptr' 00145 */ 00146 template<typename T> 00147 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00148 "public API of mbed-os and is being removed in the future.") 00149 pFunctionPointer_t add_handler_front(T *tptr, void (T::*mptr)(void), IRQn_Type irq) 00150 { 00151 // Underlying call is thread safe 00152 return add_common(tptr, mptr, irq, true); 00153 } 00154 00155 /** Remove a handler from an interrupt 00156 * @deprecated 00157 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future. 00158 * 00159 * @param handler the function object for the handler to remove 00160 * @param irq the interrupt number 00161 * 00162 * @returns 00163 * true if the handler was found and removed, false otherwise 00164 */ 00165 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00166 "public API of mbed-os and is being removed in the future.") 00167 bool remove_handler(pFunctionPointer_t handler, IRQn_Type irq); 00168 00169 private: 00170 InterruptManager(); 00171 ~InterruptManager(); 00172 00173 void lock(); 00174 void unlock(); 00175 00176 template<typename T> 00177 pFunctionPointer_t add_common(T *tptr, void (T::*mptr)(void), IRQn_Type irq, bool front = false) 00178 { 00179 _mutex.lock(); 00180 int irq_pos = get_irq_index(irq); 00181 bool change = must_replace_vector(irq); 00182 00183 pFunctionPointer_t pf = front ? _chains[irq_pos]->add_front(tptr, mptr) : _chains[irq_pos]->add(tptr, mptr); 00184 if (change) { 00185 NVIC_SetVector(irq, (uint32_t)&InterruptManager::static_irq_helper); 00186 } 00187 _mutex.unlock(); 00188 return pf; 00189 } 00190 00191 pFunctionPointer_t add_common(void (*function)(void), IRQn_Type irq, bool front = false); 00192 bool must_replace_vector(IRQn_Type irq); 00193 int get_irq_index(IRQn_Type irq); 00194 void irq_helper(); 00195 void add_helper(void (*function)(void), IRQn_Type irq, bool front = false); 00196 static void static_irq_helper(); 00197 00198 CallChain *_chains[NVIC_NUM_VECTORS]; 00199 static InterruptManager *_instance; 00200 PlatformMutex _mutex; 00201 }; 00202 00203 } // namespace mbed 00204 00205 #endif
Generated on Tue Jul 12 2022 15:15:47 by
