void ihx_readline(char line[]) { char c; uint8_t len; // Wait for start of record while (usb_getchar() != ':') {} line[0] = ':'; // Read until newline len = 1; while (len < (IHX_MAX_LEN*2)+13 && (c = usb_getchar()) != '\n') { line[len++] = c; } line[len+1] = 0; }
BYTE ReadStringUART(BYTE *Dest, BYTE BufferLen) { BYTE c; BYTE count = 0; if(BufferLen == 0) return 0; while(BufferLen--) { *Dest = '\0'; while(!usb_haschar()) { #ifndef USB_INTERRUPT USBDeviceTasks(); // Interrupt or polling method. If using polling, must call #endif USBProcessIO(); } c = usb_getchar(); if(c == '\r' || c == '\n') break; count++; *Dest++ = c; } return count; }
// USB/USART combined get char int _user_getc(void) { #ifdef USE_USART if (DataRdy1USART()) { return getc1USART(); } #endif return usb_getchar(); }
unsigned int ReadUART2(void) { #ifndef USB_INTERRUPT USBDeviceTasks(); // Interrupt or polling method. If using polling, must call #endif USBProcessIO(); return usb_getchar(); }
int usb_getchar_scanf(FILE *stream) { uint8_t u8Data; // Wait for byte to be received u8Data=usb_getchar(); //echo input data usb_putchar_printf(u8Data,stream); // Return received data return u8Data; }
/********************************************************************* * Function: BYTE ConsoleGet(void) * * PreCondition: none * * Input: none * * Output: one byte received by UART * * Side Effects: none * * Overview: This function will receive one byte from UART * * Note: Do not power down the microcontroller until * the transmission is complete or the last * transmission of the string can be corrupted. ********************************************************************/ BYTE ConsoleGet(void) { #if defined(ENABLE_CONSOLE) int Temp; while(1) { Temp = usb_getchar(); if (Temp!=-1) break; USBProcessIO(); } return (BYTE)(Temp&0xFF); #else return 0; #endif }
unsigned int getsUART2(unsigned int length,unsigned int *buffer,unsigned int uart_data_wait) { unsigned short remaining = length; char* ptr = (char*)&buffer; signed int read; do{ read = usb_getchar(); if(read != -1) { remaining--; ptr ++; } }while(remaining && (uart_data_wait || read != -1)); return length - remaining; }
int usb_get_line(char * data) { char aux; int i=0; int end=0; while(end==0) { aux=usb_getchar(); if (aux==0x0D) { data[i]=0; end=1; } else { data[i]=aux; } i+=1; } return 1;//USART_SUCCESS; }
int usb_read_line(char * data) { char aux; int i=0; int end=0; int timeout = 0; while(end==0) { timeout = 0; while(1) { if(usb_is_rx_ready()) { break; } if(timeout>MAX_TIMEOUT) { data[i]=0; return 0;//USART_FAILURE; } delay_ms(1); timeout ++; } aux=usb_getchar(); if (aux==0x0D) { data[i]=0; end=1; } else { data[i]=aux; } i+=1; } return 1;//USART_SUCCESS; }
uint8_t serial_rx_byte() { // return (uint8_t) usb_getc( ); char c = usb_getchar( ); return (uint8_t) c; }
void srvrxpeek() { uint8_t length; uint8_t in_byte; char nibbles[2]; int bytes_to_read; if (rxstate != Urxing){ return; } GREEN=1; dprint("start of reading ---- "); nibbles[0] = usb_getchar(); if(nibbles[0] == 1){ dprint("info request\n"); usb_putchar(1); dprint("flush\n"); usb_flush(); rxstate = Uready; GREEN = 0; return; } GREEN=0; dprint("%c ", nibbles[0]); nibbles[1] = usb_getchar(); dprint("%c ", nibbles[1]); in_byte = hex8(&nibbles[0]); dprint("(%x) ", in_byte); if (nrx == 0) { if (in_byte == 0) { dprint("getting 0 size. error\n"); while (1) {;} rxstate = Uready; flag &= ~Frxcall; return; } if (in_byte == 0xff) { dprint("radio reset\n"); rxstate = Uready; flag &= ~Frxcall; return; } // if the index is still at 0, here is the length rxcall[nrx++] = in_byte; } length = rxcall[0]; while (nrx < length) { nibbles[0] = usb_getchar(); dprint("%c ", nibbles[0]); nibbles[1] = usb_getchar(); dprint("%c ", nibbles[1]); in_byte = hex8(&nibbles[0]); dprint("(%x) ", in_byte); rxcall[nrx++] = in_byte; if(nrx == sizeof rxcall) panic("usb: rxcall overrun"); } if (nrx == length) { rxstate = Uidle; flag |= Frxcall; dprint(" ---- read %d\n", length); } else { // if we didn't read everything, let's let // WD take over here dprint(" ---- only read %d out of %d\n", nrx, length); while (1) {;} } }