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 #include "drivers/RawSerial.h"
thedo 167:1657b442184c 17 #include "platform/mbed_wait_api.h"
thedo 167:1657b442184c 18 #include <stdio.h>
thedo 167:1657b442184c 19 #include <cstdarg>
thedo 167:1657b442184c 20
thedo 167:1657b442184c 21
thedo 167:1657b442184c 22 #if DEVICE_SERIAL
thedo 167:1657b442184c 23
thedo 167:1657b442184c 24 #define STRING_STACK_LIMIT 120
thedo 167:1657b442184c 25
thedo 167:1657b442184c 26 namespace mbed {
thedo 167:1657b442184c 27
thedo 167:1657b442184c 28 RawSerial::RawSerial(PinName tx, PinName rx, int baud) : SerialBase(tx, rx, baud) {
thedo 167:1657b442184c 29 // No lock needed in the constructor
thedo 167:1657b442184c 30 }
thedo 167:1657b442184c 31
thedo 167:1657b442184c 32 int RawSerial::getc() {
thedo 167:1657b442184c 33 lock();
thedo 167:1657b442184c 34 int ret = _base_getc();
thedo 167:1657b442184c 35 unlock();
thedo 167:1657b442184c 36 return ret;
thedo 167:1657b442184c 37 }
thedo 167:1657b442184c 38
thedo 167:1657b442184c 39 int RawSerial::putc(int c) {
thedo 167:1657b442184c 40 lock();
thedo 167:1657b442184c 41 int ret = _base_putc(c);
thedo 167:1657b442184c 42 unlock();
thedo 167:1657b442184c 43 return ret;
thedo 167:1657b442184c 44 }
thedo 167:1657b442184c 45
thedo 167:1657b442184c 46 int RawSerial::puts(const char *str) {
thedo 167:1657b442184c 47 lock();
thedo 167:1657b442184c 48 while (*str)
thedo 167:1657b442184c 49 putc(*str ++);
thedo 167:1657b442184c 50 unlock();
thedo 167:1657b442184c 51 return 0;
thedo 167:1657b442184c 52 }
thedo 167:1657b442184c 53
thedo 167:1657b442184c 54 // Experimental support for printf in RawSerial. No Stream inheritance
thedo 167:1657b442184c 55 // means we can't call printf() directly, so we use sprintf() instead.
thedo 167:1657b442184c 56 // We only call malloc() for the sprintf() buffer if the buffer
thedo 167:1657b442184c 57 // length is above a certain threshold, otherwise we use just the stack.
thedo 167:1657b442184c 58 int RawSerial::printf(const char *format, ...) {
thedo 167:1657b442184c 59 lock();
thedo 167:1657b442184c 60 std::va_list arg;
thedo 167:1657b442184c 61 va_start(arg, format);
thedo 167:1657b442184c 62 // ARMCC microlib does not properly handle a size of 0.
thedo 167:1657b442184c 63 // As a workaround supply a dummy buffer with a size of 1.
thedo 167:1657b442184c 64 char dummy_buf[1];
thedo 167:1657b442184c 65 int len = vsnprintf(dummy_buf, sizeof(dummy_buf), format, arg);
thedo 167:1657b442184c 66 if (len < STRING_STACK_LIMIT) {
thedo 167:1657b442184c 67 char temp[STRING_STACK_LIMIT];
thedo 167:1657b442184c 68 vsprintf(temp, format, arg);
thedo 167:1657b442184c 69 puts(temp);
thedo 167:1657b442184c 70 } else {
thedo 167:1657b442184c 71 char *temp = new char[len + 1];
thedo 167:1657b442184c 72 vsprintf(temp, format, arg);
thedo 167:1657b442184c 73 puts(temp);
thedo 167:1657b442184c 74 delete[] temp;
thedo 167:1657b442184c 75 }
thedo 167:1657b442184c 76 va_end(arg);
thedo 167:1657b442184c 77 unlock();
thedo 167:1657b442184c 78 return len;
thedo 167:1657b442184c 79 }
thedo 167:1657b442184c 80
thedo 167:1657b442184c 81 /** Acquire exclusive access to this serial port
thedo 167:1657b442184c 82 */
thedo 167:1657b442184c 83 void RawSerial::lock() {
thedo 167:1657b442184c 84 // No lock used - external synchronization required
thedo 167:1657b442184c 85 }
thedo 167:1657b442184c 86
thedo 167:1657b442184c 87 /** Release exclusive access to this serial port
thedo 167:1657b442184c 88 */
thedo 167:1657b442184c 89 void RawSerial::unlock() {
thedo 167:1657b442184c 90 // No lock used - external synchronization required
thedo 167:1657b442184c 91 }
thedo 167:1657b442184c 92
thedo 167:1657b442184c 93 } // namespace mbed
thedo 167:1657b442184c 94
thedo 167:1657b442184c 95 #endif
thedo 167:1657b442184c 96