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

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.