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.
Dependencies: mbed USBMSD_SD USBDevice
USBDevice/USBSERIAL/CBuffer.h
- Committer:
- samux
- Date:
- 2011-11-11
- Revision:
- 2:27a7e7f8d399
File content as of revision 2:27a7e7f8d399:
#ifndef CBUFFER_H
#define CBUFFER_H
#define MAX_BUF 128
class CBuffer {
public:
CBuffer() {
write = 0;
read = 0;
size = MAX_BUF + 1;
};
bool isFull() {
return ((write + 1) % size == read);
};
bool isEmpty() {
return (read == write);
};
void queue(uint8_t k) {
if (isFull()) {
read++;
read %= size;
}
buf[write++] = k;
write %= size;
}
uint16_t available() {
return (write >= read) ? write - read : size - read + write;
};
bool dequeue(uint8_t * c) {
if (!isEmpty()) {
*c = buf[read++];
read %= size;
}
return(isEmpty());
};
private:
volatile uint16_t write;
volatile uint16_t read;
uint16_t size;
uint8_t buf[MAX_BUF + 1];
};
#endif