Rahul Dahiya
/
STM32F7 Ethernet
STM32F7 Ethernet interface for nucleo STM32F767
Embed:
(wiki syntax)
Show/hide line numbers
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 * 00030 * @note Synchronization level: Thread safe 00031 * 00032 * Example (for LPC1768): 00033 * @code 00034 * #include "InterruptManager.h" 00035 * #include "mbed.h" 00036 * 00037 * Ticker flipper; 00038 * DigitalOut led1(LED1); 00039 * DigitalOut led2(LED2); 00040 * 00041 * void flip(void) { 00042 * led1 = !led1; 00043 * } 00044 * 00045 * void handler(void) { 00046 * led2 = !led1; 00047 * } 00048 * 00049 * int main() { 00050 * led1 = led2 = 0; 00051 * flipper.attach(&flip, 1.0); 00052 * InterruptManager::get()->add_handler(handler, TIMER3_IRQn); 00053 * } 00054 * @endcode 00055 * @ingroup drivers 00056 */ 00057 class InterruptManager : private NonCopyable<InterruptManager> { 00058 public: 00059 /** Get the instance of InterruptManager Class 00060 * 00061 * @return the only instance of this class 00062 */ 00063 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00064 "public API of mbed-os and is being removed in the future.") 00065 static InterruptManager* get(); 00066 00067 /** Destroy the current instance of the interrupt manager 00068 */ 00069 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00070 "public API of mbed-os and is being removed in the future.") 00071 static void destroy(); 00072 00073 /** Add a handler for an interrupt at the end of the handler list 00074 * 00075 * @param function the handler to add 00076 * @param irq interrupt number 00077 * 00078 * @returns 00079 * The function object created for 'function' 00080 */ 00081 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00082 "public API of mbed-os and is being removed in the future.") 00083 pFunctionPointer_t add_handler(void (*function)(void), IRQn_Type irq) { 00084 // Underlying call is thread safe 00085 return add_common(function, irq); 00086 } 00087 00088 /** Add a handler for an interrupt at the beginning of the handler list 00089 * 00090 * @param function the handler to add 00091 * @param irq interrupt number 00092 * 00093 * @returns 00094 * The function object created for 'function' 00095 */ 00096 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00097 "public API of mbed-os and is being removed in the future.") 00098 pFunctionPointer_t add_handler_front(void (*function)(void), IRQn_Type irq) { 00099 // Underlying call is thread safe 00100 return add_common(function, irq, true); 00101 } 00102 00103 /** Add a handler for an interrupt at the end of the handler list 00104 * 00105 * @param tptr pointer to the object that has the handler function 00106 * @param mptr pointer to the actual handler function 00107 * @param irq interrupt number 00108 * 00109 * @returns 00110 * The function object created for 'tptr' and 'mptr' 00111 */ 00112 template<typename T> 00113 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00114 "public API of mbed-os and is being removed in the future.") 00115 pFunctionPointer_t add_handler(T* tptr, void (T::*mptr)(void), IRQn_Type irq) { 00116 // Underlying call is thread safe 00117 return add_common(tptr, mptr, irq); 00118 } 00119 00120 /** Add a handler for an interrupt at the beginning of the handler list 00121 * 00122 * @param tptr pointer to the object that has the handler function 00123 * @param mptr pointer to the actual handler function 00124 * @param irq interrupt number 00125 * 00126 * @returns 00127 * The function object created for 'tptr' and 'mptr' 00128 */ 00129 template<typename T> 00130 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00131 "public API of mbed-os and is being removed in the future.") 00132 pFunctionPointer_t add_handler_front(T* tptr, void (T::*mptr)(void), IRQn_Type irq) { 00133 // Underlying call is thread safe 00134 return add_common(tptr, mptr, irq, true); 00135 } 00136 00137 /** Remove a handler from an interrupt 00138 * 00139 * @param handler the function object for the handler to remove 00140 * @param irq the interrupt number 00141 * 00142 * @returns 00143 * true if the handler was found and removed, false otherwise 00144 */ 00145 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the " 00146 "public API of mbed-os and is being removed in the future.") 00147 bool remove_handler(pFunctionPointer_t handler, IRQn_Type irq); 00148 00149 private: 00150 InterruptManager(); 00151 ~InterruptManager(); 00152 00153 void lock(); 00154 void unlock(); 00155 00156 template<typename T> 00157 pFunctionPointer_t add_common(T *tptr, void (T::*mptr)(void), IRQn_Type irq, bool front=false) { 00158 _mutex.lock(); 00159 int irq_pos = get_irq_index(irq); 00160 bool change = must_replace_vector(irq); 00161 00162 pFunctionPointer_t pf = front ? _chains[irq_pos]->add_front(tptr, mptr) : _chains[irq_pos]->add(tptr, mptr); 00163 if (change) 00164 NVIC_SetVector(irq, (uint32_t)&InterruptManager::static_irq_helper); 00165 _mutex.unlock(); 00166 return pf; 00167 } 00168 00169 pFunctionPointer_t add_common(void (*function)(void), IRQn_Type irq, bool front=false); 00170 bool must_replace_vector(IRQn_Type irq); 00171 int get_irq_index(IRQn_Type irq); 00172 void irq_helper(); 00173 void add_helper(void (*function)(void), IRQn_Type irq, bool front=false); 00174 static void static_irq_helper(); 00175 00176 CallChain* _chains[NVIC_NUM_VECTORS]; 00177 static InterruptManager* _instance; 00178 PlatformMutex _mutex; 00179 }; 00180 00181 } // namespace mbed 00182 00183 #endif
Generated on Tue Jul 12 2022 14:48:48 by 1.7.2