Skip to content

Commit 62de0e2

Browse files
author
Roman Vasilyev
committed
cleaned bug about 129 char
1 parent afdffa2 commit 62de0e2

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

usb_serial.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "serial.h"
3030
#include "motion_control.h"
3131
#include "protocol.h"
32+
#include "print.h"
3233

3334
#define GET_STATUS 0
3435
#define CLEAR_FEATURE 1
@@ -303,15 +304,23 @@ static uint8_t cdc_line_rtsdtr=0;
303304
void
304305
serial_init()
305306
{
307+
usb_configuration = 0;
308+
cdc_line_rtsdtr = 0;
309+
#if 1
306310
HW_CONFIG();
307311
USB_FREEZE(); // enable USB
308312
PLL_CONFIG(); // config PLL, 16 MHz xtal
309313
while (!(PLLCSR & (1<<PLOCK))) ; // wait for PLL lock
310314
USB_CONFIG(); // start USB clock
311-
UDCON = 0; // enable attach resistor
315+
#else
316+
UHWCON = (1 << UVREGE);
317+
USBCON = (1 << USBE);
318+
PLLCSR = (1 << PINDIV)|(1 << PLLE)|(1 << PLOCK);
319+
UECONX = (1 << STALLRQ)|(1 << EPEN);
320+
USBCON = (1 << USBE)|(1<<OTGPADE);
321+
#endif
312322

313-
usb_configuration = 0;
314-
cdc_line_rtsdtr = 0;
323+
UDCON = 0; // enable attach resistor
315324
UDIEN = (1<<EORSTE)|(1<<SOFE);
316325
}
317326

@@ -398,26 +407,20 @@ uint8_t
398407
serial_read()
399408
{
400409
uint8_t intr_state, ret = 0;
401-
volatile uint8_t c;
402410

403411
if (!usb_configuration)
404412
return ret;
405413

406414
intr_state = SREG;
407415
UENUM = CDC_RX_ENDPOINT;
408416

409-
while (!((c = UEINTX) & (1<<RWAL)) ) {
410-
if (!(c & (1<<RXOUTI)))
411-
goto exit;
412-
413-
// no data in buffer
417+
if (UEBCLX<=0) {
414418
UEINTX = 0x6B;
419+
goto exit;
415420
}
416421

417422
// take one byte out of the buffer
418-
ret = UEDATX;
419-
// if buffer completely used, release it
420-
if (!(UEINTX & (1<<RWAL))) UEINTX = 0x6B;
423+
ret = UEDATX; // Read 8byte
421424
exit:
422425
SREG = intr_state;
423426
return ret;

0 commit comments

Comments
 (0)