/*FUNCTION*------------------------------------------------------------------- * * Function Name : ReadUARTN * Returned Value : * Comments : * This function reads N bytes on the SCI1 console input * *END*----------------------------------------------------------------------*/ UARTError ReadUARTN(void* bytes, unsigned long length) { int i; char *dst = (char*)bytes; for(i = 0; i< length; i++) { *dst++ = TERMIO_GetChar(); } return kUARTNoError; }
int fgetc(FILE *f) { return (int)TERMIO_GetChar(); }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : CDC_Task * Returned Value : none * Comments : * Execution starts here * *END*--------------------------------------------------------------------*/ void CDC_Task () { /* Body */ USB_STATUS status = USB_OK; uint_32 i = 0; static uint_32 char_to_recv = 0; /* due to the fact that uart driver blocks task, we will check if char is available and then we read it */ /* write them to USB */ if(USB_EVENT_NOT_SET == _usb_event_wait_ticks(&device_registered, 0x01, TRUE, 0)) return; if (0 == check_open) { _io_cdc_serial_open(f_usb, device_name, (char *)&usb_open_param); check_open = 1; } else { #ifdef MCU_mcf51jf128 /* todo AI: change this for MCU_mcf51jf128 */ char temp; temp = TERMIO_GetChar(); if(temp) { buff_index = 1; buff[0] = temp; } #endif /* MCU_mcf51jf128 */ /* Read data from UART */ #if 0 /* << EST */ DisableInterrupts; uart2usb_num = buff_index; for (i = 0; i < buff_index; i++) { uart2usb[i] = buff[i]; } buff_index = 0; EnableInterrupts; #endif #if 0 /* << EST */ /* Write data to USB */ if (uart2usb_num) { num_done = _io_cdc_serial_write(f_usb, uart2usb, (int_32)(sizeof(uart2usb[0]) * uart2usb_num)); if(num_done > 0) { for (i = (uint_32)num_done; i < uart2usb_num; i++) /* move buffer data, remove the written ones */ uart2usb[i - num_done] = uart2usb[i]; uart2usb_num -= num_done; char_to_recv += num_done; } } #endif /* Read data from USB */ if(char_to_recv > 0) { num_done = _io_cdc_serial_read(f_usb, usb2uart + usb2uart_num, (int_32)(sizeof(uart2usb) / sizeof(uart2usb[0]) - usb2uart_num)); if(num_done > 0) { usb2uart_num += num_done; if(char_to_recv >= num_done) { char_to_recv -= num_done; } else { char_to_recv = 0; } } else { char_to_recv = 0; } } /* write them to UART */ if (usb2uart_num > 0) { #if 0 /* << EST */ for (i = 0; i < usb2uart_num; i++) { #ifdef MCU_mcf51jf128 printf(" --received--> %%c\n\r",usb2uart[i]); #else sci2_PutChar(usb2uart[i]); #endif } #endif usb2uart_num = 0; } } } /* Endbody */