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_SERIALBASE_H
thedo 167:1657b442184c 17 #define MBED_SERIALBASE_H
thedo 167:1657b442184c 18
thedo 167:1657b442184c 19 #include "platform/platform.h"
thedo 167:1657b442184c 20
thedo 167:1657b442184c 21 #if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY)
thedo 167:1657b442184c 22
thedo 167:1657b442184c 23 #include "Callback.h"
thedo 167:1657b442184c 24 #include "serial_api.h"
thedo 167:1657b442184c 25 #include "mbed_toolchain.h"
thedo 167:1657b442184c 26
thedo 167:1657b442184c 27 #if DEVICE_SERIAL_ASYNCH
thedo 167:1657b442184c 28 #include "CThunk.h"
thedo 167:1657b442184c 29 #include "dma_api.h"
thedo 167:1657b442184c 30 #endif
thedo 167:1657b442184c 31
thedo 167:1657b442184c 32 namespace mbed {
thedo 167:1657b442184c 33 /** \addtogroup drivers */
thedo 167:1657b442184c 34
thedo 167:1657b442184c 35 /** A base class for serial port implementations
thedo 167:1657b442184c 36 * Can't be instantiated directly (use Serial or RawSerial)
thedo 167:1657b442184c 37 *
thedo 167:1657b442184c 38 * @note Synchronization level: Set by subclass
thedo 167:1657b442184c 39 * @ingroup drivers
thedo 167:1657b442184c 40 */
thedo 167:1657b442184c 41 class SerialBase {
thedo 167:1657b442184c 42
thedo 167:1657b442184c 43 public:
thedo 167:1657b442184c 44 /** Set the baud rate of the serial port
thedo 167:1657b442184c 45 *
thedo 167:1657b442184c 46 * @param baudrate The baudrate of the serial port (default = 9600).
thedo 167:1657b442184c 47 */
thedo 167:1657b442184c 48 void baud(int baudrate);
thedo 167:1657b442184c 49
thedo 167:1657b442184c 50 enum Parity {
thedo 167:1657b442184c 51 None = 0,
thedo 167:1657b442184c 52 Odd,
thedo 167:1657b442184c 53 Even,
thedo 167:1657b442184c 54 Forced1,
thedo 167:1657b442184c 55 Forced0
thedo 167:1657b442184c 56 };
thedo 167:1657b442184c 57
thedo 167:1657b442184c 58 enum IrqType {
thedo 167:1657b442184c 59 RxIrq = 0,
thedo 167:1657b442184c 60 TxIrq,
thedo 167:1657b442184c 61
thedo 167:1657b442184c 62 IrqCnt
thedo 167:1657b442184c 63 };
thedo 167:1657b442184c 64
thedo 167:1657b442184c 65 enum Flow {
thedo 167:1657b442184c 66 Disabled = 0,
thedo 167:1657b442184c 67 RTS,
thedo 167:1657b442184c 68 CTS,
thedo 167:1657b442184c 69 RTSCTS
thedo 167:1657b442184c 70 };
thedo 167:1657b442184c 71
thedo 167:1657b442184c 72 /** Set the transmission format used by the serial port
thedo 167:1657b442184c 73 *
thedo 167:1657b442184c 74 * @param bits The number of bits in a word (5-8; default = 8)
thedo 167:1657b442184c 75 * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
thedo 167:1657b442184c 76 * @param stop_bits The number of stop bits (1 or 2; default = 1)
thedo 167:1657b442184c 77 */
thedo 167:1657b442184c 78 void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1);
thedo 167:1657b442184c 79
thedo 167:1657b442184c 80 /** Determine if there is a character available to read
thedo 167:1657b442184c 81 *
thedo 167:1657b442184c 82 * @returns
thedo 167:1657b442184c 83 * 1 if there is a character available to read,
thedo 167:1657b442184c 84 * 0 otherwise
thedo 167:1657b442184c 85 */
thedo 167:1657b442184c 86 int readable();
thedo 167:1657b442184c 87
thedo 167:1657b442184c 88 /** Determine if there is space available to write a character
thedo 167:1657b442184c 89 *
thedo 167:1657b442184c 90 * @returns
thedo 167:1657b442184c 91 * 1 if there is space to write a character,
thedo 167:1657b442184c 92 * 0 otherwise
thedo 167:1657b442184c 93 */
thedo 167:1657b442184c 94 int writeable();
thedo 167:1657b442184c 95
thedo 167:1657b442184c 96 /** Attach a function to call whenever a serial interrupt is generated
thedo 167:1657b442184c 97 *
thedo 167:1657b442184c 98 * @param func A pointer to a void function, or 0 to set as none
thedo 167:1657b442184c 99 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
thedo 167:1657b442184c 100 */
thedo 167:1657b442184c 101 void attach(Callback<void()> func, IrqType type=RxIrq);
thedo 167:1657b442184c 102
thedo 167:1657b442184c 103 /** Attach a member function to call whenever a serial interrupt is generated
thedo 167:1657b442184c 104 *
thedo 167:1657b442184c 105 * @param obj pointer to the object to call the member function on
thedo 167:1657b442184c 106 * @param method pointer to the member function to be called
thedo 167:1657b442184c 107 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
thedo 167:1657b442184c 108 * @deprecated
thedo 167:1657b442184c 109 * The attach function does not support cv-qualifiers. Replaced by
thedo 167:1657b442184c 110 * attach(callback(obj, method), type).
thedo 167:1657b442184c 111 */
thedo 167:1657b442184c 112 template<typename T>
thedo 167:1657b442184c 113 MBED_DEPRECATED_SINCE("mbed-os-5.1",
thedo 167:1657b442184c 114 "The attach function does not support cv-qualifiers. Replaced by "
thedo 167:1657b442184c 115 "attach(callback(obj, method), type).")
thedo 167:1657b442184c 116 void attach(T *obj, void (T::*method)(), IrqType type=RxIrq) {
thedo 167:1657b442184c 117 attach(callback(obj, method), type);
thedo 167:1657b442184c 118 }
thedo 167:1657b442184c 119
thedo 167:1657b442184c 120 /** Attach a member function to call whenever a serial interrupt is generated
thedo 167:1657b442184c 121 *
thedo 167:1657b442184c 122 * @param obj pointer to the object to call the member function on
thedo 167:1657b442184c 123 * @param method pointer to the member function to be called
thedo 167:1657b442184c 124 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
thedo 167:1657b442184c 125 * @deprecated
thedo 167:1657b442184c 126 * The attach function does not support cv-qualifiers. Replaced by
thedo 167:1657b442184c 127 * attach(callback(obj, method), type).
thedo 167:1657b442184c 128 */
thedo 167:1657b442184c 129 template<typename T>
thedo 167:1657b442184c 130 MBED_DEPRECATED_SINCE("mbed-os-5.1",
thedo 167:1657b442184c 131 "The attach function does not support cv-qualifiers. Replaced by "
thedo 167:1657b442184c 132 "attach(callback(obj, method), type).")
thedo 167:1657b442184c 133 void attach(T *obj, void (*method)(T*), IrqType type=RxIrq) {
thedo 167:1657b442184c 134 attach(callback(obj, method), type);
thedo 167:1657b442184c 135 }
thedo 167:1657b442184c 136
thedo 167:1657b442184c 137 /** Generate a break condition on the serial line
thedo 167:1657b442184c 138 */
thedo 167:1657b442184c 139 void send_break();
thedo 167:1657b442184c 140
thedo 167:1657b442184c 141 protected:
thedo 167:1657b442184c 142
thedo 167:1657b442184c 143 /** Acquire exclusive access to this serial port
thedo 167:1657b442184c 144 */
thedo 167:1657b442184c 145 virtual void lock(void);
thedo 167:1657b442184c 146
thedo 167:1657b442184c 147 /** Release exclusive access to this serial port
thedo 167:1657b442184c 148 */
thedo 167:1657b442184c 149 virtual void unlock(void);
thedo 167:1657b442184c 150
thedo 167:1657b442184c 151 public:
thedo 167:1657b442184c 152
thedo 167:1657b442184c 153 #if DEVICE_SERIAL_FC
thedo 167:1657b442184c 154 /** Set the flow control type on the serial port
thedo 167:1657b442184c 155 *
thedo 167:1657b442184c 156 * @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
thedo 167:1657b442184c 157 * @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
thedo 167:1657b442184c 158 * @param flow2 the second flow control pin (CTS for RTSCTS)
thedo 167:1657b442184c 159 */
thedo 167:1657b442184c 160 void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
thedo 167:1657b442184c 161 #endif
thedo 167:1657b442184c 162
thedo 167:1657b442184c 163 static void _irq_handler(uint32_t id, SerialIrq irq_type);
thedo 167:1657b442184c 164
thedo 167:1657b442184c 165 #if DEVICE_SERIAL_ASYNCH
thedo 167:1657b442184c 166
thedo 167:1657b442184c 167 /** Begin asynchronous write using 8bit buffer. The completition invokes registered TX event callback
thedo 167:1657b442184c 168 *
thedo 167:1657b442184c 169 * @param buffer The buffer where received data will be stored
thedo 167:1657b442184c 170 * @param length The buffer length in bytes
thedo 167:1657b442184c 171 * @param callback The event callback function
thedo 167:1657b442184c 172 * @param event The logical OR of TX events
thedo 167:1657b442184c 173 */
thedo 167:1657b442184c 174 int write(const uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
thedo 167:1657b442184c 175
thedo 167:1657b442184c 176 /** Begin asynchronous write using 16bit buffer. The completition invokes registered TX event callback
thedo 167:1657b442184c 177 *
thedo 167:1657b442184c 178 * @param buffer The buffer where received data will be stored
thedo 167:1657b442184c 179 * @param length The buffer length in bytes
thedo 167:1657b442184c 180 * @param callback The event callback function
thedo 167:1657b442184c 181 * @param event The logical OR of TX events
thedo 167:1657b442184c 182 */
thedo 167:1657b442184c 183 int write(const uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
thedo 167:1657b442184c 184
thedo 167:1657b442184c 185 /** Abort the on-going write transfer
thedo 167:1657b442184c 186 */
thedo 167:1657b442184c 187 void abort_write();
thedo 167:1657b442184c 188
thedo 167:1657b442184c 189 /** Begin asynchronous reading using 8bit buffer. The completition invokes registred RX event callback.
thedo 167:1657b442184c 190 *
thedo 167:1657b442184c 191 * @param buffer The buffer where received data will be stored
thedo 167:1657b442184c 192 * @param length The buffer length in bytes
thedo 167:1657b442184c 193 * @param callback The event callback function
thedo 167:1657b442184c 194 * @param event The logical OR of RX events
thedo 167:1657b442184c 195 * @param char_match The matching character
thedo 167:1657b442184c 196 */
thedo 167:1657b442184c 197 int read(uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH);
thedo 167:1657b442184c 198
thedo 167:1657b442184c 199 /** Begin asynchronous reading using 16bit buffer. The completition invokes registred RX event callback.
thedo 167:1657b442184c 200 *
thedo 167:1657b442184c 201 * @param buffer The buffer where received data will be stored
thedo 167:1657b442184c 202 * @param length The buffer length in bytes
thedo 167:1657b442184c 203 * @param callback The event callback function
thedo 167:1657b442184c 204 * @param event The logical OR of RX events
thedo 167:1657b442184c 205 * @param char_match The matching character
thedo 167:1657b442184c 206 */
thedo 167:1657b442184c 207 int read(uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH);
thedo 167:1657b442184c 208
thedo 167:1657b442184c 209 /** Abort the on-going read transfer
thedo 167:1657b442184c 210 */
thedo 167:1657b442184c 211 void abort_read();
thedo 167:1657b442184c 212
thedo 167:1657b442184c 213 /** Configure DMA usage suggestion for non-blocking TX transfers
thedo 167:1657b442184c 214 *
thedo 167:1657b442184c 215 * @param usage The usage DMA hint for peripheral
thedo 167:1657b442184c 216 * @return Zero if the usage was set, -1 if a transaction is on-going
thedo 167:1657b442184c 217 */
thedo 167:1657b442184c 218 int set_dma_usage_tx(DMAUsage usage);
thedo 167:1657b442184c 219
thedo 167:1657b442184c 220 /** Configure DMA usage suggestion for non-blocking RX transfers
thedo 167:1657b442184c 221 *
thedo 167:1657b442184c 222 * @param usage The usage DMA hint for peripheral
thedo 167:1657b442184c 223 * @return Zero if the usage was set, -1 if a transaction is on-going
thedo 167:1657b442184c 224 */
thedo 167:1657b442184c 225 int set_dma_usage_rx(DMAUsage usage);
thedo 167:1657b442184c 226
thedo 167:1657b442184c 227 protected:
thedo 167:1657b442184c 228 void start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match);
thedo 167:1657b442184c 229 void start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event);
thedo 167:1657b442184c 230 void interrupt_handler_asynch(void);
thedo 167:1657b442184c 231 #endif
thedo 167:1657b442184c 232
thedo 167:1657b442184c 233 protected:
thedo 167:1657b442184c 234 SerialBase(PinName tx, PinName rx, int baud);
thedo 167:1657b442184c 235 virtual ~SerialBase() {
thedo 167:1657b442184c 236 }
thedo 167:1657b442184c 237
thedo 167:1657b442184c 238 int _base_getc();
thedo 167:1657b442184c 239 int _base_putc(int c);
thedo 167:1657b442184c 240
thedo 167:1657b442184c 241 #if DEVICE_SERIAL_ASYNCH
thedo 167:1657b442184c 242 CThunk<SerialBase> _thunk_irq;
thedo 167:1657b442184c 243 event_callback_t _tx_callback;
thedo 167:1657b442184c 244 event_callback_t _rx_callback;
thedo 167:1657b442184c 245 DMAUsage _tx_usage;
thedo 167:1657b442184c 246 DMAUsage _rx_usage;
thedo 167:1657b442184c 247 #endif
thedo 167:1657b442184c 248
thedo 167:1657b442184c 249 serial_t _serial;
thedo 167:1657b442184c 250 Callback<void()> _irq[IrqCnt];
thedo 167:1657b442184c 251 int _baud;
thedo 167:1657b442184c 252
thedo 167:1657b442184c 253 };
thedo 167:1657b442184c 254
thedo 167:1657b442184c 255 } // namespace mbed
thedo 167:1657b442184c 256
thedo 167:1657b442184c 257 #endif
thedo 167:1657b442184c 258
thedo 167:1657b442184c 259 #endif
thedo 167:1657b442184c 260