diff options
Diffstat (limited to 'protocol/lufa/midi/bytequeue/bytequeue.h')
| -rwxr-xr-x | protocol/lufa/midi/bytequeue/bytequeue.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/protocol/lufa/midi/bytequeue/bytequeue.h b/protocol/lufa/midi/bytequeue/bytequeue.h new file mode 100755 index 000000000..e4a286134 --- /dev/null +++ b/protocol/lufa/midi/bytequeue/bytequeue.h | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | //this is a single reader [maybe multiple writer?] byte queue | ||
| 2 | //Copyright 2008 Alex Norman | ||
| 3 | //writen by Alex Norman | ||
| 4 | // | ||
| 5 | //This file is part of avr-bytequeue. | ||
| 6 | // | ||
| 7 | //avr-bytequeue is free software: you can redistribute it and/or modify | ||
| 8 | //it under the terms of the GNU General Public License as published by | ||
| 9 | //the Free Software Foundation, either version 3 of the License, or | ||
| 10 | //(at your option) any later version. | ||
| 11 | // | ||
| 12 | //avr-bytequeue is distributed in the hope that it will be useful, | ||
| 13 | //but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | //GNU General Public License for more details. | ||
| 16 | // | ||
| 17 | //You should have received a copy of the GNU General Public License | ||
| 18 | //along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | #ifndef BYTEQUEUE_H | ||
| 21 | #define BYTEQUEUE_H | ||
| 22 | |||
| 23 | #ifdef __cplusplus | ||
| 24 | extern "C" { | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #include <inttypes.h> | ||
| 28 | #include <stdbool.h> | ||
| 29 | |||
| 30 | typedef uint8_t byteQueueIndex_t; | ||
| 31 | |||
| 32 | typedef struct { | ||
| 33 | byteQueueIndex_t start; | ||
| 34 | byteQueueIndex_t end; | ||
| 35 | byteQueueIndex_t length; | ||
| 36 | uint8_t * data; | ||
| 37 | } byteQueue_t; | ||
| 38 | |||
| 39 | //you must have a queue, an array of data which the queue will use, and the length of that array | ||
| 40 | void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen); | ||
| 41 | |||
| 42 | //add an item to the queue, returns false if the queue is full | ||
| 43 | bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item); | ||
| 44 | |||
| 45 | //get the length of the queue | ||
| 46 | byteQueueIndex_t bytequeue_length(byteQueue_t * queue); | ||
| 47 | |||
| 48 | //this grabs data at the index given [starting at queue->start] | ||
| 49 | uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index); | ||
| 50 | |||
| 51 | //update the index in the queue to reflect data that has been dealt with | ||
| 52 | void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove); | ||
| 53 | |||
| 54 | #ifdef __cplusplus | ||
| 55 | } | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #endif | ||
| 59 | |||
