Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of gr-peach-opencv-project-sd-card by
CircBufferHostSerial.h
00001 /* mbed USBHost Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef CIRCBUFFERHOSTSERIAL_H 00018 #define CIRCBUFFERHOSTSERIAL_H 00019 00020 #include "stdint.h" 00021 00022 template<typename T, int size> 00023 class CircBufferHostSerial { 00024 public: 00025 00026 CircBufferHostSerial() { 00027 write = 0; 00028 read = 0; 00029 } 00030 00031 bool isFull() { 00032 return (((write + 1) % size) == read); 00033 } 00034 00035 bool isEmpty() { 00036 return (read == write); 00037 } 00038 00039 void flush() { 00040 write = 0; 00041 read = 0; 00042 } 00043 00044 bool queue(T k) { 00045 if (isFull()) { 00046 return false; 00047 } 00048 buf[write] = k; 00049 write = (write + 1) % size; 00050 return true; 00051 } 00052 00053 uint32_t available() { 00054 uint32_t a = (write >= read) ? (write - read) : (size - read + write); 00055 return a; 00056 } 00057 00058 bool dequeue(T * c) { 00059 if (isEmpty()) { 00060 return false; 00061 } 00062 *c = buf[read]; 00063 read = (read + 1) % size; 00064 return true; 00065 } 00066 00067 private: 00068 volatile uint32_t write; 00069 volatile uint32_t read; 00070 volatile T buf[size]; 00071 }; 00072 00073 #endif 00074
Generated on Tue Jul 12 2022 14:46:08 by
1.7.2
