Support Isochronous transfer additionally

Dependents:   USBHostC270_example_GR-PEACH USBHostDac_example USBHostDac_Audio_in_out

Fork of USBHost_custom by Renesas

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MtxCircBuffer.h Source File

MtxCircBuffer.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 MTXCIRCBUFFER_H
00018 #define MTXCIRCBUFFER_H
00019 
00020 #include "stdint.h"
00021 
00022 //Mutex protected circular buffer
00023 template<typename T, int size>
00024 class MtxCircBuffer {
00025 public:
00026 
00027     MtxCircBuffer() {
00028         write = 0;
00029         read = 0;
00030     }
00031 
00032     bool isFull() {
00033         return (((write + 1) % size) == read);
00034     }
00035 
00036     bool isEmpty() {
00037         return (read == write);
00038     }
00039 
00040     void flush() {
00041         write = 0;
00042         read = 0;
00043     }
00044 
00045     bool queue(T k) {
00046         if (isFull()) {
00047             return false;
00048         }
00049         buf[write] = k;
00050         write = (write + 1) % size;
00051         return true;
00052     }
00053 
00054     uint32_t available() {
00055         uint32_t a = (write >= read) ? (write - read) : (size - read + write);
00056         return a;
00057     }
00058 
00059     bool dequeue(T * c) {
00060         if (isEmpty()) {
00061             return false;
00062         }
00063         *c = buf[read];
00064         read = (read + 1) % size;
00065         return true;
00066     }
00067 
00068 private:
00069     volatile uint32_t write;
00070     volatile uint32_t read;
00071     volatile T buf[size];
00072 };
00073 
00074 #endif
00075