void __attribute__((noreturn)) usb_recv_task(struct vcom * vcom) { struct serial_dev * serial = vcom->serial; usb_cdc_class_t * cdc = vcom->cdc; uint8_t buf[VCOM_BUF_SIZE]; int len; DCC_LOG1(LOG_TRACE, "[%d] started.", thinkos_thread_self()); DCC_LOG2(LOG_TRACE, "vcom->%p, cdc->%p", vcom, cdc); for (;;) { len = usb_cdc_read(cdc, buf, VCOM_BUF_SIZE, 1000); if (vcom->mode == VCOM_MODE_CONVERTER) { if (len > 0) { led_flash(LED_RED, 50); serial_write(serial, buf, len); #if RAW_TRACE if (len == 1) DCC_LOG1(LOG_TRACE, "TX: %02x", buf[0]); else if (len == 2) DCC_LOG2(LOG_TRACE, "TX: %02x %02x", buf[0], buf[1]); else if (len == 3) DCC_LOG3(LOG_TRACE, "TX: %02x %02x %02x", buf[0], buf[1], buf[2]); else if (len == 4) DCC_LOG4(LOG_TRACE, "TX: %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3]); else if (len == 5) DCC_LOG5(LOG_TRACE, "TX: %02x %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3], buf[4]); else if (len == 6) DCC_LOG6(LOG_TRACE, "TX: %02x %02x %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); else if (len == 7) DCC_LOG7(LOG_TRACE, "TX: %02x %02x %02x %02x %02x %02x %02x ", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); else DCC_LOG8(LOG_TRACE, "TX: %02x %02x %02x %02x %02x %02x " "%02x %02x ...", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); #endif #if SDU_TRACE TX(buf, len); #endif // dbg_write(buf, len); } } else { // forward to service input vcom_service_input(vcom, buf, len); } } }
int usb_recv_task(struct vcom * vcom) { struct serial_dev * serial = vcom->serial; struct usb_cdc_class * usb = vcom->usb; char buf[VCOM_BUF_SIZE]; int len; DCC_LOG1(LOG_TRACE, "[%d] started.", thinkos_thread_self()); for (;;) { len = usb_cdc_read(usb, buf, VCOM_BUF_SIZE, 100); if (len > 0) serial_write(serial, buf, len); } return 0; }
void cdc_control_poll(void) { // flush out queue every now and then if(flush_timer && CheckTimer(flush_timer)) { cdc_control_flush(); flush_timer = 0; } // low level usb handling happens inside usb_cdc_poll if(usb_cdc_poll()) { uint16_t read, i; char data[AT91C_EP_OUT_SIZE]; // check for user input if((read = usb_cdc_read(data, AT91C_EP_OUT_SIZE)) != 0) { switch(tos_get_cdc_control_redirect()) { case CDC_REDIRECT_RS232: iprintf("RS232 forward:\n"); hexdump(data, read, 0); user_io_serial_tx(data, read); break; case CDC_REDIRECT_CONTROL: for(i=0;i<read;i++) { // force lower case if((data[i] >= 'A') && (data[i] <= 'Z')) data[i] = data[i] - 'A' + 'a'; switch(data[i]) { case '\r': cdc_puts("\n\033[7m <<< MIST board controller >>> \033[0m"); cdc_puts("Firmware version ATH" VDATE); cdc_puts("Commands:"); cdc_puts("\033[7mR\033[0meset"); cdc_puts("\033[7mC\033[0moldreset"); cdc_puts("\033[7mD\033[0mebug output redirect"); cdc_puts("R\033[7mS\033[0m232 redirect"); cdc_puts("\033[7mP\033[0marallel redirect"); cdc_puts("\033[7mM\033[0mIDI redirect"); cdc_puts(""); break; case 'r': cdc_puts("Reset ..."); tos_reset(0); break; case 'c': cdc_puts("Coldreset ..."); tos_reset(1); break; case 'd': cdc_puts("Debug output redirect enabled"); tos_set_cdc_control_redirect(CDC_REDIRECT_DEBUG); break; case 's': cdc_puts("RS232 redirect enabled"); tos_set_cdc_control_redirect(CDC_REDIRECT_RS232); break; case 'p': cdc_puts("Parallel redirect enabled"); tos_set_cdc_control_redirect(CDC_REDIRECT_PARALLEL); break; case 'm': cdc_puts("MIDI redirect enabled"); tos_set_cdc_control_redirect(CDC_REDIRECT_MIDI); break; } break; } default: break; } } } }