|
@@ -56,12 +56,10 @@ public:
|
56
|
56
|
return buffer_size - available();
|
57
|
57
|
}
|
58
|
58
|
T read() volatile {
|
59
|
|
- if(index_write != index_read) {
|
60
|
|
- T val = buffer[buffer_mask & index_read];
|
61
|
|
- ++index_read;
|
62
|
|
- return val;
|
63
|
|
- }
|
64
|
|
- return T(0);
|
|
59
|
+ if((buffer_mask & index_read) == (buffer_mask & index_write)) return T(-1);
|
|
60
|
+ T val = buffer[buffer_mask & index_read];
|
|
61
|
+ ++index_read;
|
|
62
|
+ return val;
|
65
|
63
|
}
|
66
|
64
|
bool write( T value) volatile {
|
67
|
65
|
uint32_t next_head = buffer_mask & (index_write + 1);
|
|
@@ -73,10 +71,10 @@ public:
|
73
|
71
|
return false;
|
74
|
72
|
}
|
75
|
73
|
bool empty() volatile {
|
76
|
|
- return index_read == index_write;
|
|
74
|
+ return (buffer_mask & index_read) == (buffer_mask & index_write);
|
77
|
75
|
}
|
78
|
76
|
bool full() volatile {
|
79
|
|
- return index_read == index_write + 1;
|
|
77
|
+ return index_read == buffer_mask & (index_write + 1);
|
80
|
78
|
}
|
81
|
79
|
void clear() volatile {
|
82
|
80
|
index_read = index_write = 0;
|
|
@@ -100,7 +98,6 @@ public:
|
100
|
98
|
}
|
101
|
99
|
|
102
|
100
|
char read() {
|
103
|
|
- if(receive_buffer.empty()) return -1;
|
104
|
101
|
return (char)receive_buffer.read();
|
105
|
102
|
}
|
106
|
103
|
|
|
@@ -110,7 +107,7 @@ public:
|
110
|
107
|
}
|
111
|
108
|
|
112
|
109
|
operator bool() {
|
113
|
|
- return true;
|
|
110
|
+ return host_connected;
|
114
|
111
|
}
|
115
|
112
|
|
116
|
113
|
uint16_t available() {
|