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_CAN_H
thedo 167:1657b442184c 17 #define MBED_CAN_H
thedo 167:1657b442184c 18
thedo 167:1657b442184c 19 #include "platform/platform.h"
thedo 167:1657b442184c 20
thedo 167:1657b442184c 21 #if defined (DEVICE_CAN) || defined(DOXYGEN_ONLY)
thedo 167:1657b442184c 22
thedo 167:1657b442184c 23 #include "hal/can_api.h"
thedo 167:1657b442184c 24 #include "platform/Callback.h"
thedo 167:1657b442184c 25 #include "platform/PlatformMutex.h"
thedo 167:1657b442184c 26
thedo 167:1657b442184c 27 namespace mbed {
thedo 167:1657b442184c 28 /** \addtogroup drivers */
thedo 167:1657b442184c 29
thedo 167:1657b442184c 30 /** CANMessage class
thedo 167:1657b442184c 31 *
thedo 167:1657b442184c 32 * @note Synchronization level: Thread safe
thedo 167:1657b442184c 33 * @ingroup drivers
thedo 167:1657b442184c 34 */
thedo 167:1657b442184c 35 class CANMessage : public CAN_Message {
thedo 167:1657b442184c 36
thedo 167:1657b442184c 37 public:
thedo 167:1657b442184c 38 /** Creates empty CAN message.
thedo 167:1657b442184c 39 */
thedo 167:1657b442184c 40 CANMessage() : CAN_Message() {
thedo 167:1657b442184c 41 len = 8;
thedo 167:1657b442184c 42 type = CANData;
thedo 167:1657b442184c 43 format = CANStandard;
thedo 167:1657b442184c 44 id = 0;
thedo 167:1657b442184c 45 memset(data, 0, 8);
thedo 167:1657b442184c 46 }
thedo 167:1657b442184c 47
thedo 167:1657b442184c 48 /** Creates CAN message with specific content.
thedo 167:1657b442184c 49 */
thedo 167:1657b442184c 50 CANMessage(int _id, const char *_data, char _len = 8, CANType _type = CANData, CANFormat _format = CANStandard) {
thedo 167:1657b442184c 51 len = _len & 0xF;
thedo 167:1657b442184c 52 type = _type;
thedo 167:1657b442184c 53 format = _format;
thedo 167:1657b442184c 54 id = _id;
thedo 167:1657b442184c 55 memcpy(data, _data, _len);
thedo 167:1657b442184c 56 }
thedo 167:1657b442184c 57
thedo 167:1657b442184c 58 /** Creates CAN remote message.
thedo 167:1657b442184c 59 */
thedo 167:1657b442184c 60 CANMessage(int _id, CANFormat _format = CANStandard) {
thedo 167:1657b442184c 61 len = 0;
thedo 167:1657b442184c 62 type = CANRemote;
thedo 167:1657b442184c 63 format = _format;
thedo 167:1657b442184c 64 id = _id;
thedo 167:1657b442184c 65 memset(data, 0, 8);
thedo 167:1657b442184c 66 }
thedo 167:1657b442184c 67 };
thedo 167:1657b442184c 68
thedo 167:1657b442184c 69 /** A can bus client, used for communicating with can devices
thedo 167:1657b442184c 70 * @ingroup drivers
thedo 167:1657b442184c 71 */
thedo 167:1657b442184c 72 class CAN {
thedo 167:1657b442184c 73
thedo 167:1657b442184c 74 public:
thedo 167:1657b442184c 75 /** Creates an CAN interface connected to specific pins.
thedo 167:1657b442184c 76 *
thedo 167:1657b442184c 77 * @param rd read from transmitter
thedo 167:1657b442184c 78 * @param td transmit to transmitter
thedo 167:1657b442184c 79 *
thedo 167:1657b442184c 80 * Example:
thedo 167:1657b442184c 81 * @code
thedo 167:1657b442184c 82 * #include "mbed.h"
thedo 167:1657b442184c 83 *
thedo 167:1657b442184c 84 * Ticker ticker;
thedo 167:1657b442184c 85 * DigitalOut led1(LED1);
thedo 167:1657b442184c 86 * DigitalOut led2(LED2);
thedo 167:1657b442184c 87 * CAN can1(p9, p10);
thedo 167:1657b442184c 88 * CAN can2(p30, p29);
thedo 167:1657b442184c 89 *
thedo 167:1657b442184c 90 * char counter = 0;
thedo 167:1657b442184c 91 *
thedo 167:1657b442184c 92 * void send() {
thedo 167:1657b442184c 93 * if(can1.write(CANMessage(1337, &counter, 1))) {
thedo 167:1657b442184c 94 * printf("Message sent: %d\n", counter);
thedo 167:1657b442184c 95 * counter++;
thedo 167:1657b442184c 96 * }
thedo 167:1657b442184c 97 * led1 = !led1;
thedo 167:1657b442184c 98 * }
thedo 167:1657b442184c 99 *
thedo 167:1657b442184c 100 * int main() {
thedo 167:1657b442184c 101 * ticker.attach(&send, 1);
thedo 167:1657b442184c 102 * CANMessage msg;
thedo 167:1657b442184c 103 * while(1) {
thedo 167:1657b442184c 104 * if(can2.read(msg)) {
thedo 167:1657b442184c 105 * printf("Message received: %d\n\n", msg.data[0]);
thedo 167:1657b442184c 106 * led2 = !led2;
thedo 167:1657b442184c 107 * }
thedo 167:1657b442184c 108 * wait(0.2);
thedo 167:1657b442184c 109 * }
thedo 167:1657b442184c 110 * }
thedo 167:1657b442184c 111 * @endcode
thedo 167:1657b442184c 112 */
thedo 167:1657b442184c 113 CAN(PinName rd, PinName td);
thedo 167:1657b442184c 114
thedo 167:1657b442184c 115 /** Initialize CAN interface and set the frequency
thedo 167:1657b442184c 116 *
thedo 167:1657b442184c 117 * @param rd the rd pin
thedo 167:1657b442184c 118 * @param td the td pin
thedo 167:1657b442184c 119 * @param hz the bus frequency in hertz
thedo 167:1657b442184c 120 */
thedo 167:1657b442184c 121 CAN(PinName rd, PinName td, int hz);
thedo 167:1657b442184c 122
thedo 167:1657b442184c 123 virtual ~CAN();
thedo 167:1657b442184c 124
thedo 167:1657b442184c 125 /** Set the frequency of the CAN interface
thedo 167:1657b442184c 126 *
thedo 167:1657b442184c 127 * @param hz The bus frequency in hertz
thedo 167:1657b442184c 128 *
thedo 167:1657b442184c 129 * @returns
thedo 167:1657b442184c 130 * 1 if successful,
thedo 167:1657b442184c 131 * 0 otherwise
thedo 167:1657b442184c 132 */
thedo 167:1657b442184c 133 int frequency(int hz);
thedo 167:1657b442184c 134
thedo 167:1657b442184c 135 /** Write a CANMessage to the bus.
thedo 167:1657b442184c 136 *
thedo 167:1657b442184c 137 * @param msg The CANMessage to write.
thedo 167:1657b442184c 138 *
thedo 167:1657b442184c 139 * @returns
thedo 167:1657b442184c 140 * 0 if write failed,
thedo 167:1657b442184c 141 * 1 if write was successful
thedo 167:1657b442184c 142 */
thedo 167:1657b442184c 143 int write(CANMessage msg);
thedo 167:1657b442184c 144
thedo 167:1657b442184c 145 /** Read a CANMessage from the bus.
thedo 167:1657b442184c 146 *
thedo 167:1657b442184c 147 * @param msg A CANMessage to read to.
thedo 167:1657b442184c 148 * @param handle message filter handle (0 for any message)
thedo 167:1657b442184c 149 *
thedo 167:1657b442184c 150 * @returns
thedo 167:1657b442184c 151 * 0 if no message arrived,
thedo 167:1657b442184c 152 * 1 if message arrived
thedo 167:1657b442184c 153 */
thedo 167:1657b442184c 154 int read(CANMessage &msg, int handle = 0);
thedo 167:1657b442184c 155
thedo 167:1657b442184c 156 /** Reset CAN interface.
thedo 167:1657b442184c 157 *
thedo 167:1657b442184c 158 * To use after error overflow.
thedo 167:1657b442184c 159 */
thedo 167:1657b442184c 160 void reset();
thedo 167:1657b442184c 161
thedo 167:1657b442184c 162 /** Puts or removes the CAN interface into silent monitoring mode
thedo 167:1657b442184c 163 *
thedo 167:1657b442184c 164 * @param silent boolean indicating whether to go into silent mode or not
thedo 167:1657b442184c 165 */
thedo 167:1657b442184c 166 void monitor(bool silent);
thedo 167:1657b442184c 167
thedo 167:1657b442184c 168 enum Mode {
thedo 167:1657b442184c 169 Reset = 0,
thedo 167:1657b442184c 170 Normal,
thedo 167:1657b442184c 171 Silent,
thedo 167:1657b442184c 172 LocalTest,
thedo 167:1657b442184c 173 GlobalTest,
thedo 167:1657b442184c 174 SilentTest
thedo 167:1657b442184c 175 };
thedo 167:1657b442184c 176
thedo 167:1657b442184c 177 /** Change CAN operation to the specified mode
thedo 167:1657b442184c 178 *
thedo 167:1657b442184c 179 * @param mode The new operation mode (CAN::Normal, CAN::Silent, CAN::LocalTest, CAN::GlobalTest, CAN::SilentTest)
thedo 167:1657b442184c 180 *
thedo 167:1657b442184c 181 * @returns
thedo 167:1657b442184c 182 * 0 if mode change failed or unsupported,
thedo 167:1657b442184c 183 * 1 if mode change was successful
thedo 167:1657b442184c 184 */
thedo 167:1657b442184c 185 int mode(Mode mode);
thedo 167:1657b442184c 186
thedo 167:1657b442184c 187 /** Filter out incomming messages
thedo 167:1657b442184c 188 *
thedo 167:1657b442184c 189 * @param id the id to filter on
thedo 167:1657b442184c 190 * @param mask the mask applied to the id
thedo 167:1657b442184c 191 * @param format format to filter on (Default CANAny)
thedo 167:1657b442184c 192 * @param handle message filter handle (Optional)
thedo 167:1657b442184c 193 *
thedo 167:1657b442184c 194 * @returns
thedo 167:1657b442184c 195 * 0 if filter change failed or unsupported,
thedo 167:1657b442184c 196 * new filter handle if successful
thedo 167:1657b442184c 197 */
thedo 167:1657b442184c 198 int filter(unsigned int id, unsigned int mask, CANFormat format = CANAny, int handle = 0);
thedo 167:1657b442184c 199
thedo 167:1657b442184c 200 /** Returns number of read errors to detect read overflow errors.
thedo 167:1657b442184c 201 */
thedo 167:1657b442184c 202 unsigned char rderror();
thedo 167:1657b442184c 203
thedo 167:1657b442184c 204 /** Returns number of write errors to detect write overflow errors.
thedo 167:1657b442184c 205 */
thedo 167:1657b442184c 206 unsigned char tderror();
thedo 167:1657b442184c 207
thedo 167:1657b442184c 208 enum IrqType {
thedo 167:1657b442184c 209 RxIrq = 0,
thedo 167:1657b442184c 210 TxIrq,
thedo 167:1657b442184c 211 EwIrq,
thedo 167:1657b442184c 212 DoIrq,
thedo 167:1657b442184c 213 WuIrq,
thedo 167:1657b442184c 214 EpIrq,
thedo 167:1657b442184c 215 AlIrq,
thedo 167:1657b442184c 216 BeIrq,
thedo 167:1657b442184c 217 IdIrq,
thedo 167:1657b442184c 218
thedo 167:1657b442184c 219 IrqCnt
thedo 167:1657b442184c 220 };
thedo 167:1657b442184c 221
thedo 167:1657b442184c 222 /** Attach a function to call whenever a CAN frame received interrupt is
thedo 167:1657b442184c 223 * generated.
thedo 167:1657b442184c 224 *
thedo 167:1657b442184c 225 * @param func A pointer to a void function, or 0 to set as none
thedo 167:1657b442184c 226 * @param type Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, CAN::TxIrq for transmitted or aborted, CAN::EwIrq for error warning, CAN::DoIrq for data overrun, CAN::WuIrq for wake-up, CAN::EpIrq for error passive, CAN::AlIrq for arbitration lost, CAN::BeIrq for bus error)
thedo 167:1657b442184c 227 */
thedo 167:1657b442184c 228 void attach(Callback<void()> func, IrqType type=RxIrq);
thedo 167:1657b442184c 229
thedo 167:1657b442184c 230 /** Attach a member function to call whenever a CAN frame received interrupt
thedo 167:1657b442184c 231 * is generated.
thedo 167:1657b442184c 232 *
thedo 167:1657b442184c 233 * @param obj pointer to the object to call the member function on
thedo 167:1657b442184c 234 * @param method pointer to the member function to be called
thedo 167:1657b442184c 235 * @param type Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error)
thedo 167:1657b442184c 236 * @deprecated
thedo 167:1657b442184c 237 * The attach function does not support cv-qualifiers. Replaced by
thedo 167:1657b442184c 238 * attach(callback(obj, method), type).
thedo 167:1657b442184c 239 */
thedo 167:1657b442184c 240 template<typename T>
thedo 167:1657b442184c 241 MBED_DEPRECATED_SINCE("mbed-os-5.1",
thedo 167:1657b442184c 242 "The attach function does not support cv-qualifiers. Replaced by "
thedo 167:1657b442184c 243 "attach(callback(obj, method), type).")
thedo 167:1657b442184c 244 void attach(T* obj, void (T::*method)(), IrqType type=RxIrq) {
thedo 167:1657b442184c 245 // Underlying call thread safe
thedo 167:1657b442184c 246 attach(callback(obj, method), type);
thedo 167:1657b442184c 247 }
thedo 167:1657b442184c 248
thedo 167:1657b442184c 249 /** Attach a member function to call whenever a CAN frame received interrupt
thedo 167:1657b442184c 250 * is generated.
thedo 167:1657b442184c 251 *
thedo 167:1657b442184c 252 * @param obj pointer to the object to call the member function on
thedo 167:1657b442184c 253 * @param method pointer to the member function to be called
thedo 167:1657b442184c 254 * @param type Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error)
thedo 167:1657b442184c 255 * @deprecated
thedo 167:1657b442184c 256 * The attach function does not support cv-qualifiers. Replaced by
thedo 167:1657b442184c 257 * attach(callback(obj, method), type).
thedo 167:1657b442184c 258 */
thedo 167:1657b442184c 259 template<typename T>
thedo 167:1657b442184c 260 MBED_DEPRECATED_SINCE("mbed-os-5.1",
thedo 167:1657b442184c 261 "The attach function does not support cv-qualifiers. Replaced by "
thedo 167:1657b442184c 262 "attach(callback(obj, method), type).")
thedo 167:1657b442184c 263 void attach(T* obj, void (*method)(T*), IrqType type=RxIrq) {
thedo 167:1657b442184c 264 // Underlying call thread safe
thedo 167:1657b442184c 265 attach(callback(obj, method), type);
thedo 167:1657b442184c 266 }
thedo 167:1657b442184c 267
thedo 167:1657b442184c 268 static void _irq_handler(uint32_t id, CanIrqType type);
thedo 167:1657b442184c 269
thedo 167:1657b442184c 270 protected:
thedo 167:1657b442184c 271 virtual void lock();
thedo 167:1657b442184c 272 virtual void unlock();
thedo 167:1657b442184c 273 can_t _can;
thedo 167:1657b442184c 274 Callback<void()> _irq[IrqCnt];
thedo 167:1657b442184c 275 PlatformMutex _mutex;
thedo 167:1657b442184c 276 };
thedo 167:1657b442184c 277
thedo 167:1657b442184c 278 } // namespace mbed
thedo 167:1657b442184c 279
thedo 167:1657b442184c 280 #endif
thedo 167:1657b442184c 281
thedo 167:1657b442184c 282 #endif // MBED_CAN_H
thedo 167:1657b442184c 283
thedo 167:1657b442184c 284