@@ -149,9 +149,8 @@ size_t USBSerial::write(uint8_t ch) {
149
149
CDC_disable_TIM_Interrupt ();
150
150
151
151
if (((UserTxBufPtrIn + 1 ) % APP_TX_DATA_SIZE) == UserTxBufPtrOut)
152
- {
153
- // Buffer full!!! Force a flush to not loose data and go on
154
- CDC_flush ();
152
+ {
153
+ CDC_flush (); // Buffer full!!! Force a flush to not loose data and go on
155
154
}
156
155
UserTxBufferFS[UserTxBufPtrIn] = ch;
157
156
UserTxBufPtrIn = ((UserTxBufPtrIn + 1 ) % APP_TX_DATA_SIZE);
@@ -162,28 +161,21 @@ size_t USBSerial::write(uint8_t ch) {
162
161
}
163
162
164
163
int USBSerial::available (void ) {
165
- int ret;
166
-
167
- CDC_disable_TIM_Interrupt ();
168
- ret = ((APP_RX_DATA_SIZE + (UserRxBufPtrIn - UserRxBufPtrOut)) % APP_RX_DATA_SIZE);
169
- CDC_enable_TIM_Interrupt ();
170
-
171
- return ret;
164
+ return ((APP_RX_DATA_SIZE + (UserRxBufPtrIn - UserRxBufPtrOut)) % APP_RX_DATA_SIZE);
172
165
}
173
166
174
- int USBSerial::read (void ) {
175
- /* UserTxBufPtrOut can be modified by TIM ISR, so in order to be sure that the */
176
- /* value that we read is correct, we need to disable TIM Interrupt. */
177
- CDC_disable_TIM_Interrupt ();
167
+ int USBSerial::read (void )
168
+ {
178
169
if (UserRxBufPtrOut == UserRxBufPtrIn)
179
170
{
180
- CDC_enable_TIM_Interrupt ();
181
171
return -1 ;
182
- } else
172
+ }
173
+ else
183
174
{
184
175
unsigned char c = UserRxBufferFS[UserRxBufPtrOut];
185
176
UserRxBufPtrOut = ((UserRxBufPtrOut + 1 ) % APP_RX_DATA_SIZE);
186
- CDC_enable_TIM_Interrupt ();
177
+
178
+ CDC_resume_receive ();
187
179
return c;
188
180
}
189
181
}
@@ -192,15 +184,12 @@ int USBSerial::peek(void)
192
184
{
193
185
/* UserTxBufPtrOut can be modified by TIM ISR, so in order to be sure that the */
194
186
/* value that we read is correct, we need to disable TIM Interrupt. */
195
- CDC_disable_TIM_Interrupt ();
196
187
if (UserRxBufPtrOut == UserRxBufPtrIn)
197
188
{
198
- CDC_enable_TIM_Interrupt ();
199
189
return -1 ;
200
190
} else
201
191
{
202
192
unsigned char c = UserRxBufferFS[UserRxBufPtrOut];
203
- CDC_enable_TIM_Interrupt ();
204
193
return c;
205
194
}
206
195
}
0 commit comments