コード例 #1
0
ファイル: usb_serial.c プロジェクト: MotionReality/picpack
void process_rx() {
	
	uns8 len,	// length of string
		 rec;	// received character
	uns8 first_char;
	
	rec = usb_cdc_getc();	// get the character from the fifo
	
	usb_cdc_putc(rec);	// print it out so we can see what we typed

	if (rec == '\r') {	// did we press return?
		first_char = serial_buffer[0];
		switch (first_char) {
			case 'a':
				do_task = 1;
				break;
		    case 'x':
				do_task = 2;
				break;
			case 'u':
				do_task = 3;
				break;
			case 'n':
				do_task = 4;
				break;
			default:
				// More complicated example
				// Let's set a variable based on input
				// You can type:
				// s05
				// And press enter, it will set "send_to" to this (in hex)
				if ((first_char == 's') && (strlen(serial_buffer)==3)) {
					send_to = atoui_hex(&serial_buffer[1]);
					usb_cdc_print_str(" Set send_to to ");
					usb_cdc_print_int(send_to);	// Of course, this could be anything
					usb_cdc_putc('\n');
				};
		}		
		serial_buffer[0] = '\0';	// clear the buffer
        usb_cdc_putc('\n');	// print new line
        usb_cdc_putc('>');	// print the prompt
	} else {
		len = strlen(serial_buffer);	// add the character to our line input
		serial_buffer[len] = rec;
		serial_buffer[len+1] = '\0';
	}

}
コード例 #2
0
ファイル: printf-retarget.c プロジェクト: elsingc/LPC11U68
void __putchar(const char c)
{
  #if defined(CFG_USB) && defined(CFG_PRINTF_USBCDC)
    if (usb_isConfigured())
    {
      while(usb_cdc_isConnected() && !usb_cdc_putc(c) ) // blocking
      {
        ASM("nop");
      }
    }
  #endif

  #ifdef CFG_PRINTF_UART
    uartSendByte(c);
  #endif

  /* Handle PRINTF_DEBUG redirection for Crossworks for ARM */
  #ifdef __CROSSWORKS_ARM
    #ifdef CFG_PRINTF_DEBUG
      #if defined CFG_MCU_FAMILY_LPC13UXX
        /* On the M3 we can check if a debugger is connected */
        if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)==CoreDebug_DHCSR_C_DEBUGEN_Msk)
        {
          debug_putchar(c);
        }
      #else
        /* On the M0 the processor doesn't have access to CoreDebug, so this
         * will cause problems if no debugger is connected! */
        debug_putchar(c);
      #endif
    #endif
  #endif
}
コード例 #3
0
ファイル: ex_usb_serial.c プロジェクト: Sel2016/microchip
void main(void) {
   char c;

   LED_OFF(LED1);
   LED_OFF(LED2);
   LED_OFF(LED3);

   printf("\r\n\nCCS CDC (Virtual RS232) Example\r\n");

  #ifdef __PCH__
   printf("PCH: v");
   printf(__PCH__);
  #else
   printf("PCM: v");
   printf(__PCM__);
  #endif
   printf("\r\n");

   usb_init();

  #if !(__USB_PIC_PERIF__)
   printf("USBN: 0x%X", usbn_get_version());
   printf("\r\n\n");
  #endif


   while (TRUE) {
      usb_task();
      usb_debug_task();

      if (kbhit()) {
         c=getc();
         if (c=='\n') {usb_cdc_putc('\r'); usb_cdc_putc('\n');}
         if (c=='\r') {usb_cdc_putc('\r'); usb_cdc_putc('\n');}
         else {usb_cdc_putc(c);}
      }
      if (usb_cdc_kbhit()) {
         c=usb_cdc_getc();
         if (c=='\n') {putc('\r'); putc('\n');}
         if (c=='\r') {putc('\r'); putc('\n');}
         else {putc(c);}
      }
   }
}
コード例 #4
0
uint16_t usb_cdc_send(uint8_t* buffer, uint16_t count)
{
  uint16_t i=0;

  ASSERT(buffer && count, 0);

  while (i < count && usb_cdc_putc(buffer[i]) )
  {
    i++;
  }

  return i;
}
コード例 #5
0
ファイル: usb_serial.c プロジェクト: MotionReality/picpack
void main() {

uns16 tick_marker = 0;
uns16 test_tick;

		
	configure_system();
	delay_ms(100);
    #ifdef USB_SERIAL_DEBUG
		serial_print_str("USB here we go...");
    #endif
    delay_ms(100);
	usb_enable_module();
	while (usb_configured == 0) {
		#ifdef USB_SERIAL_DEBUG
			serial_print_str("<wait>");
		#endif
		delay_ms(250);
		delay_ms(250);
		delay_ms(250);
		delay_ms(250);
	}
	#ifdef USB_SERIAL_DEBUG
		serial_print_str("\nGreat! Now trying to print\n");
	#endif
	usb_cdc_print_str("\n\nPIC USB Serial demo\n");
	usb_cdc_print_str( "\n<");
	usb_cdc_print_str(__TIME__);
	usb_cdc_putc(' ');
	usb_cdc_print_str(__DATE__);
	usb_cdc_print_str(">\n");

	usb_cdc_print_str("Commands: a attach to USB bus\n");
	

	while(1) {

		if (usb_cdc_rx_avail()) {
			process_rx();
		}
		handle_tasks();	
		
	}	// while (1)
	// main
}
コード例 #6
0
ファイル: usb_cdc_class.c プロジェクト: MotionReality/picpack
void usb_cdc_print_str(char *str) {

uns8 count;
buffer_descriptor *bd;

	for(count = 0 ; str[count] != 0; count++)
    {
        usb_cdc_putc(str[count]);
    }
    
    // This will give possibly quicker send:
    
    //bd = ep_in_bd_location[CDC_DATA_ENDPOINT];
    //if (!test_bit(bd->stat, UOWN)) {
    //	usb_cdc_handle_tx();
    //}	
    // otherwise we wait for the SOF interrupt to send
}    
コード例 #7
0
ファイル: usb_cdc_class.c プロジェクト: MotionReality/picpack
void usb_cdc_print_int(uns16 i) {

char buffer[6];	// up to 5 characters plus \0
uns8 count = 5;
	buffer[5] = '\0';
	do {
		count--;
		buffer[count] = '0' + i % 10;
		i = i / 10;
	} while (i > 0);	
	while (buffer[count]) {
        usb_cdc_putc(buffer[count]);
        count++;
    }  
	//serial_print_str(&buffer[count]);	//	print it out 
//	for(count = 0 ; str[count] != 0; count++)
 //   {
 //   }

}	
コード例 #8
0
ファイル: ZentralEinheit v1 Main.c プロジェクト: kuesta/Thin
// schreibe Char in USB-Transmitt-Buffer
void usb_putc(char cc) // printf(usb_putc,...)
{
  	while(!usb_cdc_putready());
	delay_ms(1);
	usb_cdc_putc(cc);
}
コード例 #9
0
extern "C" void interpreter_putchar(char c) {
	usb_cdc_putc(c);
}
コード例 #10
0
void load_program(void)
{
  int1  do_ACKLOD, done=FALSE;
  int8  checksum, line_type;
  int16 l_addr,h_addr=0;
  int8 to;
  int32 addr;
  int8  dataidx, i, count;
  int8  data[32];
  int  buffidx;
  char buffer[BUFFER_LEN_LOD];
   
  while (!done)  // Loop until the entire program is downloaded
  {
    usb_task();

    if(!usb_cdc_kbhit())
      continue;
         
    buffidx = 0;  // Read into the buffer until 0x0D ('\r') is received or the buffer is full
    to = 250;   //250 milliseconds
    do 
    {
      if(!usb_cdc_kbhit())
      {
	delay_ms(1);
	to--;
	if(!to)
	  break;
      }
      else
	to = 250;
      i = usb_cdc_getc();
      buffer[buffidx++] = i;
    }while((i != 0x0D) && (i != 0x0A) && (buffidx <= BUFFER_LEN_LOD));
            
    if(!to)
      continue;

    usb_cdc_putc(XOFF);  // Suspend sender

    do_ACKLOD = TRUE;

    // Only process data blocks that start with ':'
    if(buffer[0] == ':')
    {
      count = atoi_b16 (&buffer[1]);  // Get the number of bytes from the buffer

      // Get the lower 16 bits of address
      l_addr = make16(atoi_b16(&buffer[3]),atoi_b16(&buffer[5]));

      line_type = atoi_b16 (&buffer[7]);

      addr = make32(h_addr,l_addr);

      // If the line type is 1, then data is done being sent
      if(line_type == 1) 
      {
	done = TRUE;
      }
      else if((addr >= (int32)APPLICATION_START) && (addr < ((int32)0x300000)))
      {
	checksum = 0;  // Sum the bytes to find the check sum value
	for(i=1; i<(buffidx-3); i+=2)
	  checksum += atoi_b16 (&buffer[i]);
	checksum = 0xFF - checksum + 1;

	if(checksum != atoi_b16 (&buffer[buffidx-3]))
	  do_ACKLOD = FALSE;
	else   
	{
	  if(line_type == 0) {
	    // Loops through all of the data and stores it in data
	    // The last 2 bytes are the check sum, hence buffidx-3
	    for(i = 9,dataidx=0; i < buffidx-3; i += 2)
	      data[dataidx++]=atoi_b16(&buffer[i]);
                    
	    rom_w(addr, data, count);
	  }
	  else if(line_type == 4)
	    h_addr = make16(atoi_b16(&buffer[9]), atoi_b16(&buffer[11]));
	}
      }
    }

    if(do_ACKLOD)
      usb_cdc_putc (ACKLOD);

    usb_cdc_putc(XON);
  }

  usb_cdc_putc(ACKLOD);
  usb_cdc_putc(XON);
  delay_ms(2000);   //give time for packet to flush
  reset_cpu();
}