int main( void ) { unsigned char inc; unsigned int rx_time=0, tx_time=0; mcu_init(); sys_time_init(); led_init(); VCOM_allow_linecoding(1); #ifdef USE_USB_SERIAL VCOM_init(); #endif mcu_int_enable(); LED_ON(3); #ifdef USE_UART0 while(1) { if (T0TC > (rx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(1); if (T0TC > (tx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(2); if (uart_char_available(&uart0) && VCOM_check_free_space(1)) { LED_ON(1); rx_time = T0TC; inc = uart_getch(&uart0); VCOM_putchar(inc); } if (VCOM_check_available() && uart_check_free_space(&uart0, 1)) { LED_ON(2); tx_time = T0TC; inc = VCOM_getchar(); uart_transmit(&uart0, inc); } } #else while(1) { if (T0TC > (rx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(1); if (T0TC > (tx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(2); if (uart_char_available(&uart1) && VCOM_check_free_space(1)) { LED_ON(1); rx_time = T0TC; inc = uart_getch(&uart1); VCOM_putchar(inc); } if (VCOM_check_available() && uart_check_free_space(&uart1, 1)) { LED_ON(2); tx_time = T0TC; inc = VCOM_getchar(); uart_transmit(&uart1, inc); } } #endif return 0; }
void raw_putchar(char c) { #ifdef STANDALONE while (!(U0LSR & 0x20)); return (U0THR = ch); #else #ifdef VCOM VCOM_putchar((int)c); #else putc_serial0((int)c); #endif #endif }
int usb_serial_write(unsigned subdevice, char *buf, unsigned int count) { int room; int i; if (count == 0) return 0; room = fifo_free(&txfifo); if (room == 0) return 0; if (count > room) count = room; for (i = 0; i < count; i++) VCOM_putchar(*buf++); return count; }
void vUSBTask( void *pvParameters ) { int c; /* Just to prevent compiler warnings about the unused parameter. */ ( void ) pvParameters; DBG("Initialising USB stack\n"); xRxedChars = xQueueCreate( usbBUFFER_LEN, sizeof( char ) ); xCharsForTx = xQueueCreate( usbBUFFER_LEN, sizeof( char ) ); if( ( xRxedChars == NULL ) || ( xCharsForTx == NULL ) ) { /* Not enough heap available to create the buffer queues, can't do anything so just delete ourselves. */ vTaskDelete( NULL ); } // initialise stack USBInit(); // register descriptors USBRegisterDescriptors(abDescriptors); // register class request handler USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData); // register endpoint handlers USBHwRegisterEPIntHandler(INT_IN_EP, NULL); USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn); USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut); // register frame handler USBHwRegisterFrameHandler(USBFrameHandler); // enable bulk-in interrupts on NAKs USBHwNakIntEnable(INACK_BI); DBG("Starting USB communication\n"); NVIC_SetPriority( USB_IRQn, configUSB_INTERRUPT_PRIORITY ); NVIC_EnableIRQ( USB_IRQn ); // connect to bus DBG("Connecting to USB bus\n"); USBHwConnect(TRUE); // echo any character received (do USB stuff in interrupt) for( ;; ) { c = VCOM_getchar(); if (c != EOF) { // Echo character back with INCREMENT_ECHO_BY offset, so for example if // INCREMENT_ECHO_BY is 1 and 'A' is received, 'B' will be echoed back. VCOM_putchar(c + INCREMENT_ECHO_BY ); } } }
/************************************************************************* main ==== **************************************************************************/ bool USBStart(void) { int c; // initialise stack USBInit(); // register descriptors USBRegisterDescriptors(abDescriptors); // register class request handler USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData); // register endpoint handlers USBHwRegisterEPIntHandler(INT_IN_EP, NULL); USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn); USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut); // register frame handler USBHwRegisterFrameHandler(USBFrameHandler); // register device event handler USBHwRegisterDevIntHandler(USBDevIntHandler); // initialise VCOM VCOM_init(); VICVectCntl22 = 0x01; VICVectAddr22 = (int)USBIntHandler; // set up USB interrupt VICIntSelect &= ~(1<<22); // select IRQ for USB VICIntEnable |= (1<<22); // connect to bus USBHwConnect(TRUE); #if TCM // echo any character received (do USB stuff in interrupt) while (1) { c = VCOM_getchar(); if (c != EOF) { // show on console if ((c == 9) || (c == 10) || (c == 13) || ((c >= 32) && (c <= 126))) { DBG("%c", c); } else { DBG("."); } VCOM_putchar(c); } } return 0; #endif return true; }