mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #1044 from porkybrain/master
Changed CircBuffer to take its size as a template parameters for efficientcy.pull/1066/head
commit
7c4831f300
|
@ -135,10 +135,10 @@ bool USBMSD::connect(bool blocking) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBMSD::disconnect() {
|
void USBMSD::disconnect() {
|
||||||
|
USBDevice::disconnect();
|
||||||
//De-allocate MSD page size:
|
//De-allocate MSD page size:
|
||||||
free(page);
|
free(page);
|
||||||
page = NULL;
|
page = NULL;
|
||||||
USBDevice::disconnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBMSD::reset() {
|
void USBMSD::reset() {
|
||||||
|
|
|
@ -19,20 +19,10 @@
|
||||||
#ifndef CIRCBUFFER_H
|
#ifndef CIRCBUFFER_H
|
||||||
#define CIRCBUFFER_H
|
#define CIRCBUFFER_H
|
||||||
|
|
||||||
template <class T>
|
template <class T, int Size>
|
||||||
class CircBuffer {
|
class CircBuffer {
|
||||||
public:
|
public:
|
||||||
CircBuffer(int length) {
|
CircBuffer():write(0), read(0){}
|
||||||
write = 0;
|
|
||||||
read = 0;
|
|
||||||
size = length + 1;
|
|
||||||
buf = (T *)malloc(size * sizeof(T));
|
|
||||||
};
|
|
||||||
|
|
||||||
~CircBuffer() {
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isFull() {
|
bool isFull() {
|
||||||
return ((write + 1) % size == read);
|
return ((write + 1) % size == read);
|
||||||
};
|
};
|
||||||
|
@ -66,8 +56,8 @@ public:
|
||||||
private:
|
private:
|
||||||
volatile uint16_t write;
|
volatile uint16_t write;
|
||||||
volatile uint16_t read;
|
volatile uint16_t read;
|
||||||
uint16_t size;
|
static const int size = Size+1; //a modern optimizer should be able to remove this so it uses no ram.
|
||||||
T * buf;
|
T buf[Size];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -56,7 +56,7 @@ public:
|
||||||
* @param connect_blocking define if the connection must be blocked if USB not plugged in
|
* @param connect_blocking define if the connection must be blocked if USB not plugged in
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001, bool connect_blocking = true): USBCDC(vendor_id, product_id, product_release, connect_blocking), buf(128){
|
USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001, bool connect_blocking = true): USBCDC(vendor_id, product_id, product_release, connect_blocking){
|
||||||
settingsChangedCallback = 0;
|
settingsChangedCallback = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FunctionPointer rx;
|
FunctionPointer rx;
|
||||||
CircBuffer<uint8_t> buf;
|
CircBuffer<uint8_t,128> buf;
|
||||||
void (*settingsChangedCallback)(int baud, int bits, int parity, int stop);
|
void (*settingsChangedCallback)(int baud, int bits, int parity, int stop);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue