Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
167:1657b442184c
project opencv 3.1 on GR PEACH board, no use SD card.

Who changed what in which revision?

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