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