示例#1
0
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;
}
示例#2
0
int main(){
	int c;
//hci_ctx_t	hci;



	ubertooth_init();
//	hci_init(&hci);
	usb_ioa_init(vendor_request_handler);

    BTAPP_Initialise(&gpsBTAPP);

	/*
	 * for each character received over USB serial connection, echo the
	 * character back over USB serial and toggle USRLED
	 */
	while (1) {
		c = VCOM_getchar();
		if (c != EOF) {
			/* toggle USRLED */
			if (USRLED)
				USRLED_CLR;
			else
				USRLED_SET;
//			hci_update(&hci, c);
//			VCOM_putchar(c);
		}
	}
}
示例#3
0
int usb_serial_read(unsigned subdevice, char *buf, unsigned int count)
{
  int avail;
  int i;

  if (count == 0) return 0;

  avail = fifo_avail(&rxfifo);
  if (avail == 0) return 0;

  if (count > avail)
    count = avail;

  for (i = 0; i < count; i++)
    *buf++ = VCOM_getchar();

  return count;
}
示例#4
0
int getkey()
{
#ifdef STANDALONE
    while (!kbhit())
        ;
    // return the next character from the console input device
    return U0RBR;
#else
#ifdef VCOM
    int c;
    while ((c = VCOM_getchar()) == -1)
	;
    return c;
#else
     return getc0();
#endif
#endif
}
示例#5
0
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 );
        }
    }
}
示例#6
0
/*************************************************************************
	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;
}
void vCommandConsoleTask( void *pvParameters )
{
int8_t cRxedChar, cInputIndex = 0, *pcOutputString;
static int8_t cInputString[ cmdMAX_INPUT_SIZE ];
portBASE_TYPE xReturned;
//Peripheral_Descriptor_t xConsoleUART;

	( void ) pvParameters;

	/* Obtain the address of the output buffer.  Note there is no mutual
	exclusion on this buffer as it is assumed only one command console
	interface will be used at any one time. */
	pcOutputString = FreeRTOS_CLIGetOutputBuffer();

	/* Open the UART port used for console input.  The second parameter
	(ulFlags) is not used in this case.  The default board rate is set by the
	boardDEFAULT_UART_BAUD parameter.  The baud rate can be changed using a
	FreeRTOS_ioctl() call with the ioctlSET_SPEED command. */

//	xConsoleUART = FreeRTOS_open( boardCOMMAND_CONSOLE_UART, ( uint32_t ) cmdPARAMTER_NOT_USED );
//	configASSERT( xConsoleUART );

	/* Change the Tx usage model from straight polled mode to use zero copy
	buffers with interrupts.  In this mode, the UART will transmit characters
	directly from the buffer passed to the FreeRTOS_write()	function. */
//	xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_ZERO_COPY_TX, cmdPARAMTER_NOT_USED );
	configASSERT( xReturned );//

	/* Change the Rx usage model from straight polled mode to use a character
	queue.  Character queue reception is appropriate in this case as characters
	can only be received as quickly as they can be typed, and need to be parsed
	character by character. */
//	xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_CHARACTER_QUEUE_RX, ( void * ) cmdMAX_INPUT_SIZE );
//	configASSERT( xReturned );

	/* By default, the UART interrupt priority will have been set to the lowest
	possible.  It must be kept at or below configMAX_LIBRARY_INTERRUPT_PRIORITY,
	but	can be raised above its default priority using a FreeRTOS_ioctl() call
	with the ioctlSET_INTERRUPT_PRIORITY command. */
//	xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlSET_INTERRUPT_PRIORITY, ( void * ) ( configMIN_LIBRARY_INTERRUPT_PRIORITY - 1 ) );
//	configASSERT( xReturned );

	/* Send the welcome message. */
/*	if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS )
	{
		FreeRTOS_write( xConsoleUART, pcWelcomeMessage, strlen( ( char * ) pcWelcomeMessage ) );
	}
*/
	for( ;; )
	{
		/* Only interested in reading one character at a time. */
		cRxedChar = VCOM_getchar();

		if( cRxedChar == '\n' )
		{
			/* The input command string is complete.  Ensure the previous
			UART transmission has finished before sending any more data.
			This task will be held in the Blocked state while the Tx completes,
			if it has not already done so, so no CPU time will be wasted by
			polling. */
			/*if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS )
			{
				// Start to transmit a line separator, just to make the output
				//easier to read.
				FreeRTOS_write( xConsoleUART, pcNewLine, strlen( ( char * ) pcNewLine ) );
			}
			*/
			VCOM_puts("\r\n>");
			/* Pass the received command to the command interpreter.  The
			command interpreter is called repeatedly until it returns
			pdFALSE as it might generate more than one string. */
			do
			{
				/* Once again, just check to ensure the UART has completed
				sending whatever it was sending last.  This task will be held
				in the Blocked state while the Tx completes, if it has not
				already done so, so no CPU time	is wasted polling. */
				//xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms );
				
				if( xReturned == pdPASS )
				{
					/* Get the string to write to the UART from the command
					interpreter. */
					xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );

					/* Write the generated string to the UART. */
					//FreeRTOS_write( xConsoleUART, pcOutputString, strlen( ( char * ) pcOutputString ) );
					VCOM_puts(pcOutputString);
				}

			} while( xReturned != pdFALSE );

			/* All the strings generated by the input command have been sent.
			Clear the input	string ready to receive the next command. */
			cInputIndex = 0;
			memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );

			/* Ensure the last string to be transmitted has completed. */
			//if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS )
			{
				/* Start to transmit a line separator, just to make the output
				easier to read. */
				//FreeRTOS_write( xConsoleUART, "\r\n>", strlen( "\r\n>" ) );
				VCOM_puts("\r\n>");
			}
		}
		else
		{
			if( cRxedChar == '\r' )
			{
				/* Ignore the character. */
			}
			else if( cRxedChar == '\b' )
			{
				/* Backspace was pressed.  Erase the last character in the
				string - if any. */
				if( cInputIndex > 0 )
				{
					cInputIndex--;
					cInputString[ cInputIndex ] = '\0';
				}
			}
			else
			{
				/* A character was entered.  Add it to the string
				entered so far.  When a \n is entered the complete
				string will be passed to the command interpreter. */
				if( cInputIndex < cmdMAX_INPUT_SIZE )
				{
					cInputString[ cInputIndex ] = cRxedChar;
					cInputIndex++;
				}
			}
		}
	}
}