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:
166:3a9487d57a5c
project opencv 3.1 on GR PEACH board, no use SD card.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 166:3a9487d57a5c 1 /* mbed USBHost Library
thedo 166:3a9487d57a5c 2 * Copyright (c) 2006-2013 ARM Limited
thedo 166:3a9487d57a5c 3 *
thedo 166:3a9487d57a5c 4 * Licensed under the Apache License, Version 2.0 (the "License");
thedo 166:3a9487d57a5c 5 * you may not use this file except in compliance with the License.
thedo 166:3a9487d57a5c 6 * You may obtain a copy of the License at
thedo 166:3a9487d57a5c 7 *
thedo 166:3a9487d57a5c 8 * http://www.apache.org/licenses/LICENSE-2.0
thedo 166:3a9487d57a5c 9 *
thedo 166:3a9487d57a5c 10 * Unless required by applicable law or agreed to in writing, software
thedo 166:3a9487d57a5c 11 * distributed under the License is distributed on an "AS IS" BASIS,
thedo 166:3a9487d57a5c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
thedo 166:3a9487d57a5c 13 * See the License for the specific language governing permissions and
thedo 166:3a9487d57a5c 14 * limitations under the License.
thedo 166:3a9487d57a5c 15 */
thedo 166:3a9487d57a5c 16
thedo 166:3a9487d57a5c 17 #ifndef MTXCIRCBUFFER_H
thedo 166:3a9487d57a5c 18 #define MTXCIRCBUFFER_H
thedo 166:3a9487d57a5c 19
thedo 166:3a9487d57a5c 20 #include "stdint.h"
thedo 166:3a9487d57a5c 21
thedo 166:3a9487d57a5c 22 //Mutex protected circular buffer
thedo 166:3a9487d57a5c 23 template<typename T, int size>
thedo 166:3a9487d57a5c 24 class MtxCircBuffer {
thedo 166:3a9487d57a5c 25 public:
thedo 166:3a9487d57a5c 26
thedo 166:3a9487d57a5c 27 MtxCircBuffer() {
thedo 166:3a9487d57a5c 28 write = 0;
thedo 166:3a9487d57a5c 29 read = 0;
thedo 166:3a9487d57a5c 30 }
thedo 166:3a9487d57a5c 31
thedo 166:3a9487d57a5c 32 bool isFull() {
thedo 166:3a9487d57a5c 33 return (((write + 1) % size) == read);
thedo 166:3a9487d57a5c 34 }
thedo 166:3a9487d57a5c 35
thedo 166:3a9487d57a5c 36 bool isEmpty() {
thedo 166:3a9487d57a5c 37 return (read == write);
thedo 166:3a9487d57a5c 38 }
thedo 166:3a9487d57a5c 39
thedo 166:3a9487d57a5c 40 void flush() {
thedo 166:3a9487d57a5c 41 write = 0;
thedo 166:3a9487d57a5c 42 read = 0;
thedo 166:3a9487d57a5c 43 }
thedo 166:3a9487d57a5c 44
thedo 166:3a9487d57a5c 45 bool queue(T k) {
thedo 166:3a9487d57a5c 46 if (isFull()) {
thedo 166:3a9487d57a5c 47 return false;
thedo 166:3a9487d57a5c 48 }
thedo 166:3a9487d57a5c 49 buf[write] = k;
thedo 166:3a9487d57a5c 50 write = (write + 1) % size;
thedo 166:3a9487d57a5c 51 return true;
thedo 166:3a9487d57a5c 52 }
thedo 166:3a9487d57a5c 53
thedo 166:3a9487d57a5c 54 uint32_t available() {
thedo 166:3a9487d57a5c 55 uint32_t a = (write >= read) ? (write - read) : (size - read + write);
thedo 166:3a9487d57a5c 56 return a;
thedo 166:3a9487d57a5c 57 }
thedo 166:3a9487d57a5c 58
thedo 166:3a9487d57a5c 59 bool dequeue(T * c) {
thedo 166:3a9487d57a5c 60 if (isEmpty()) {
thedo 166:3a9487d57a5c 61 return false;
thedo 166:3a9487d57a5c 62 }
thedo 166:3a9487d57a5c 63 *c = buf[read];
thedo 166:3a9487d57a5c 64 read = (read + 1) % size;
thedo 166:3a9487d57a5c 65 return true;
thedo 166:3a9487d57a5c 66 }
thedo 166:3a9487d57a5c 67
thedo 166:3a9487d57a5c 68 private:
thedo 166:3a9487d57a5c 69 volatile uint32_t write;
thedo 166:3a9487d57a5c 70 volatile uint32_t read;
thedo 166:3a9487d57a5c 71 volatile T buf[size];
thedo 166:3a9487d57a5c 72 };
thedo 166:3a9487d57a5c 73
thedo 166:3a9487d57a5c 74 #endif
thedo 166:3a9487d57a5c 75