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.
Dependents: F401RE-USBHostMIDI_RecieveExample
Fork of F401RE-USBHost by
Diff: USBHostMIDI/CircBuffer.h
- Revision:
- 24:5281ea9f6e68
- Parent:
- 23:9c1d09c6a2b6
- Child:
- 25:c4fdd0b4e643
diff -r 9c1d09c6a2b6 -r 5281ea9f6e68 USBHostMIDI/CircBuffer.h
--- a/USBHostMIDI/CircBuffer.h Wed Sep 17 14:29:11 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/* USBHostMidi library
- * Originaled by k.shoji
- * porting by Takuya Urakawa
- */
-
-/* mbed USBHost Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CIRCBUFFER_H
-#define CIRCBUFFER_H
-
-#include "stdint.h"
-
-//circular buffer
-template<typename T, int size>
-class CircBuffer {
-public:
-
- CircBuffer() {
- write = 0;
- read = 0;
- }
-
- bool isFull() {
- bool r = (((write + 1) % size) == read);
- return r;
- }
-
- bool isEmpty() {
- bool r = (read == write);
- return r;
- }
-
- void flush() {
- write = 0;
- read = 0;
- }
-
- void queue(T k) {
- while (((write + 1) % size) == read) {
- wait_ms(10);
- }
- buf[write++] = k;
- write %= size;
- }
-
- uint16_t available() {
- uint16_t a = (write >= read) ? (write - read) : (size - read + write);
- return a;
- }
-
- bool dequeue(T * c) {
- bool empty = (read == write);
- if (!empty) {
- *c = buf[read++];
- read %= size;
- }
- return (!empty);
- }
-
-private:
- volatile uint16_t write;
- volatile uint16_t read;
- volatile T buf[size];
-};
-
-#endif
