USBMSD test for GR-PEACH
Dependencies: USBDevice USBMSD_SD mbed
Fork of USBMSD_SD_HelloWorld_Mbed by
USBDevice/USBSERIAL/CBuffer.h@2:27a7e7f8d399, 2011-11-11 (annotated)
- Committer:
- samux
- Date:
- Fri Nov 11 15:22:53 2011 +0000
- Revision:
- 2:27a7e7f8d399
we have 2MB with the sdcard!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux |
2:27a7e7f8d399 | 1 | #ifndef CBUFFER_H |
samux |
2:27a7e7f8d399 | 2 | #define CBUFFER_H |
samux |
2:27a7e7f8d399 | 3 | |
samux |
2:27a7e7f8d399 | 4 | #define MAX_BUF 128 |
samux |
2:27a7e7f8d399 | 5 | |
samux |
2:27a7e7f8d399 | 6 | class CBuffer { |
samux |
2:27a7e7f8d399 | 7 | public: |
samux |
2:27a7e7f8d399 | 8 | CBuffer() { |
samux |
2:27a7e7f8d399 | 9 | write = 0; |
samux |
2:27a7e7f8d399 | 10 | read = 0; |
samux |
2:27a7e7f8d399 | 11 | size = MAX_BUF + 1; |
samux |
2:27a7e7f8d399 | 12 | }; |
samux |
2:27a7e7f8d399 | 13 | |
samux |
2:27a7e7f8d399 | 14 | bool isFull() { |
samux |
2:27a7e7f8d399 | 15 | return ((write + 1) % size == read); |
samux |
2:27a7e7f8d399 | 16 | }; |
samux |
2:27a7e7f8d399 | 17 | |
samux |
2:27a7e7f8d399 | 18 | bool isEmpty() { |
samux |
2:27a7e7f8d399 | 19 | return (read == write); |
samux |
2:27a7e7f8d399 | 20 | }; |
samux |
2:27a7e7f8d399 | 21 | |
samux |
2:27a7e7f8d399 | 22 | void queue(uint8_t k) { |
samux |
2:27a7e7f8d399 | 23 | if (isFull()) { |
samux |
2:27a7e7f8d399 | 24 | read++; |
samux |
2:27a7e7f8d399 | 25 | read %= size; |
samux |
2:27a7e7f8d399 | 26 | } |
samux |
2:27a7e7f8d399 | 27 | buf[write++] = k; |
samux |
2:27a7e7f8d399 | 28 | write %= size; |
samux |
2:27a7e7f8d399 | 29 | } |
samux |
2:27a7e7f8d399 | 30 | |
samux |
2:27a7e7f8d399 | 31 | uint16_t available() { |
samux |
2:27a7e7f8d399 | 32 | return (write >= read) ? write - read : size - read + write; |
samux |
2:27a7e7f8d399 | 33 | }; |
samux |
2:27a7e7f8d399 | 34 | |
samux |
2:27a7e7f8d399 | 35 | bool dequeue(uint8_t * c) { |
samux |
2:27a7e7f8d399 | 36 | if (!isEmpty()) { |
samux |
2:27a7e7f8d399 | 37 | *c = buf[read++]; |
samux |
2:27a7e7f8d399 | 38 | read %= size; |
samux |
2:27a7e7f8d399 | 39 | } |
samux |
2:27a7e7f8d399 | 40 | return(isEmpty()); |
samux |
2:27a7e7f8d399 | 41 | }; |
samux |
2:27a7e7f8d399 | 42 | |
samux |
2:27a7e7f8d399 | 43 | |
samux |
2:27a7e7f8d399 | 44 | private: |
samux |
2:27a7e7f8d399 | 45 | volatile uint16_t write; |
samux |
2:27a7e7f8d399 | 46 | volatile uint16_t read; |
samux |
2:27a7e7f8d399 | 47 | uint16_t size; |
samux |
2:27a7e7f8d399 | 48 | uint8_t buf[MAX_BUF + 1]; |
samux |
2:27a7e7f8d399 | 49 | }; |
samux |
2:27a7e7f8d399 | 50 | |
samux |
2:27a7e7f8d399 | 51 | #endif |