游戏王对战板,目前code还是空的

Committer:
WFKnight
Date:
Thu Jun 21 13:51:43 2018 +0000
Revision:
0:9b3d4731edbb
UART, RTOS, LED

Who changed what in which revision?

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