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.
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 // Underlying call is thread safe 00093 return add_common(function, irq); 00094 } 00095 00096 /** Add a handler for an interrupt at the beginning of the handler list 00097 * @deprecated 00098 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future. 00099 * 00100 * @param function the handler to add 00101 * @param irq interrupt number 00102 * 00103 * @returns 00104 * The function object created for 'function' 00105 */ 00106 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00107 "public API of mbed-os and is being removed in the future.") 00108 pFunctionPointer_t add_handler_front(void (*function)(void), IRQn_Type irq) { 00109 // Underlying call is thread safe 00110 return add_common(function, irq, true); 00111 } 00112 00113 /** Add a handler for an interrupt at the end of the handler list 00114 * @deprecated 00115 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future. 00116 * 00117 * @param tptr pointer to the object that has the handler function 00118 * @param mptr pointer to the actual handler function 00119 * @param irq interrupt number 00120 * 00121 * @returns 00122 * The function object created for 'tptr' and 'mptr' 00123 */ 00124 template<typename T> 00125 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00126 "public API of mbed-os and is being removed in the future.") 00127 pFunctionPointer_t add_handler(T* tptr, void (T::*mptr)(void), IRQn_Type irq) { 00128 // Underlying call is thread safe 00129 return add_common(tptr, mptr, irq); 00130 } 00131 00132 /** Add a handler for an interrupt at the beginning of the handler list 00133 * @deprecated 00134 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future. 00135 * 00136 * @param tptr pointer to the object that has the handler function 00137 * @param mptr pointer to the actual handler function 00138 * @param irq interrupt number 00139 * 00140 * @returns 00141 * The function object created for 'tptr' and 'mptr' 00142 */ 00143 template<typename T> 00144 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00145 "public API of mbed-os and is being removed in the future.") 00146 pFunctionPointer_t add_handler_front(T* tptr, void (T::*mptr)(void), IRQn_Type irq) { 00147 // Underlying call is thread safe 00148 return add_common(tptr, mptr, irq, true); 00149 } 00150 00151 /** Remove a handler from an interrupt 00152 * @deprecated 00153 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future. 00154 * 00155 * @param handler the function object for the handler to remove 00156 * @param irq the interrupt number 00157 * 00158 * @returns 00159 * true if the handler was found and removed, false otherwise 00160 */ 00161 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00162 "public API of mbed-os and is being removed in the future.") 00163 bool remove_handler(pFunctionPointer_t handler, IRQn_Type irq); 00164 00165 private: 00166 InterruptManager(); 00167 ~InterruptManager(); 00168 00169 void lock(); 00170 void unlock(); 00171 00172 template<typename T> 00173 pFunctionPointer_t add_common(T *tptr, void (T::*mptr)(void), IRQn_Type irq, bool front=false) { 00174 _mutex.lock(); 00175 int irq_pos = get_irq_index(irq); 00176 bool change = must_replace_vector(irq); 00177 00178 pFunctionPointer_t pf = front ? _chains[irq_pos]->add_front(tptr, mptr) : _chains[irq_pos]->add(tptr, mptr); 00179 if (change) 00180 NVIC_SetVector(irq, (uint32_t)&InterruptManager::static_irq_helper); 00181 _mutex.unlock(); 00182 return pf; 00183 } 00184 00185 pFunctionPointer_t add_common(void (*function)(void), IRQn_Type irq, bool front=false); 00186 bool must_replace_vector(IRQn_Type irq); 00187 int get_irq_index(IRQn_Type irq); 00188 void irq_helper(); 00189 void add_helper(void (*function)(void), IRQn_Type irq, bool front=false); 00190 static void static_irq_helper(); 00191 00192 CallChain* _chains[NVIC_NUM_VECTORS]; 00193 static InterruptManager* _instance; 00194 PlatformMutex _mutex; 00195 }; 00196 00197 } // namespace mbed 00198 00199 #endif
Generated on Tue Jul 12 2022 14:23:50 by
