Ejemplo n.º 1
0
/** 
  * @brief This function reads one byte from the USB bus
  *
  * If one byte is present in the USB fifo, this byte is returned. If no data
  * is present in the USB fifo, this function waits for USB data.
  * 
  * @return U8 byte received
  */
char uart_usb_getchar(void)
{
  register Uchar data_rx;

  // Preserve the currently selected endpoint
  uint8_t uenum = Usb_get_selected_endpoint();
  
  Usb_select_endpoint(VCP_RX_EP);
  if (!rx_counter) while (!uart_usb_test_hit());
  data_rx=Usb_read_byte();
  rx_counter--;
  if (!rx_counter) Usb_ack_receive_out();
  
#if USB_CDC_ACM_CONF_LOCAL_ECHO
  //Local echo
  uart_usb_putchar(data_rx);
#endif

  USB_CDC_ACM_HOOK_RX(data_rx);
  
  // Restore previously selected endpoint
  UENUM = uenum;

  return data_rx;
}
Ejemplo n.º 2
0
void cdc_task(void)
{
    if(Is_device_enumerated()) //Enumeration processs OK ?
    {
        if(cpt_sof>=NB_MS_BEFORE_FLUSH && tx_counter!=0 )  //Flush buffer in Timeout
        {
            cpt_sof=0;
            uart_usb_flush();
        }

        if ( waiting_to_start && uart_usb_test_hit())   // Something received from the USB ?
        {
            waiting_to_start = 0;
            timer_init();
            adc_init();
        }

        if( !waiting_to_start )
        {
            READING r;
            if( cb_pop( &r ) )
            {
                uart_usb_putchar( (r.voltage >> 8) & 0xFF );
                uart_usb_putchar( r.voltage & 0xFF );
                uart_usb_putchar( (r.current >> 8) & 0xFF  );
                uart_usb_putchar( r.current & 0xFF );

                uint16 checksum = r.voltage ^ r.current;
                uart_usb_putchar( (checksum >> 8) & 0xFF  );
                uart_usb_putchar( checksum & 0xFF );
            }
        }
/** 
  * @brief This function reads one byte from the USB bus
  *
  * If one byte is present in the USB fifo, this byte is returned. If no data
  * is present in the USB fifo, this function waits for USB data.
  * 
  * @return U8 byte received
  */
char uart_usb_getchar(void)
{
  register Uchar data_rx;

  Usb_select_endpoint(RX_EP);
  if (!rx_counter) while (!uart_usb_test_hit());
  data_rx=Usb_read_byte();
  rx_counter--;
  if (!rx_counter) Usb_ack_receive_out();
  return data_rx;
}
Ejemplo n.º 4
0
char uart_usb_getchar(void)
{
  register char data_rx;

  while( !uart_usb_test_hit() );
  data_rx=Usb_read_endpoint_data(RX_EP, 8);
  if( 0==Usb_byte_count(RX_EP) ) {
      Usb_ack_out_received_free(RX_EP);
      b_rx_new = TRUE;
  }
  return data_rx;
}
Ejemplo n.º 5
0
/**
 * \brief Communication Data Class (CDC) Process
 *
 *   This is the link between USB and the "good stuff". In this routine data
 *   is received and processed by CDC-ACM Class
 */
PROCESS_THREAD(cdc_process, ev, data_proc)
{

	PROCESS_BEGIN();
	uart_usb_init();

	while(1) {
      

	    // turn off LED's if necessary
		if (led3_timer) led3_timer--;
		else			Led3_off();

 		if(Is_device_enumerated() && (usb_mode == rndis_debug) && rndis_state && (!usb_busy)) {

			if (justenumerated) {

				//If we have serial port, set it as output
			    if (usb_mode == rndis_debug) {
					uart_usb_set_stdout();
					menu_print();
				}
				justenumerated = 0;
			}

			//Flush buffer if timeout
	        if(timer >= 4 && tx_counter!=0 ){
	            timer = 0;
	            uart_usb_flush();
	        } else {
				timer++;
			}

			while (uart_usb_test_hit()){
  		  	   menu_process(uart_usb_getchar());   // See what they want
            }


		}//if (Is_device_enumerated())


		if (usb_mode == rndis_debug) {
			etimer_set(&et, CLOCK_SECOND/80);
		} else {
			etimer_set(&et, CLOCK_SECOND);
		}

		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));	
		
	} // while(1)

	PROCESS_END();
}
Ejemplo n.º 6
0
/**
 * \brief Communication Data Class (CDC) Process
 *
 *   This is the link between USB and the "good stuff". In this routine data
 *   is received and processed by CDC-ACM Class
 */
PROCESS_THREAD(cdc_process, ev, data_proc)
{
	PROCESS_BEGIN();

#if USB_CONF_RS232
	static FILE *rs232_stdout,*usb_stdout;
	rs232_stdout=stdout;
#endif

	while(1) {
	    // turn off LED's if necessary
		if (led3_timer) led3_timer--;
		else			Led3_off();
		
 		if(Is_device_enumerated()) {
			// If the configuration is different than the last time we checked...
			if((uart_usb_get_control_line_state()&1)!=previous_uart_usb_control_line_state) {
				previous_uart_usb_control_line_state = uart_usb_get_control_line_state()&1;
				static FILE* previous_stdout;
				
				if(previous_uart_usb_control_line_state&1) {
					previous_stdout = stdout;
					uart_usb_init();
					uart_usb_set_stdout();
				//	menu_print(); do this later
				} else {
					stdout = previous_stdout;
				}
#if USB_CONF_RS232
				usb_stdout=stdout;
#endif
			}

			//Flush buffer if timeout
	        if(timer >= 4 && tx_counter!=0 ){
	            timer = 0;
	            uart_usb_flush();
	        } else {
				timer++;
			}

#if USB_CONF_RS232
			stdout=usb_stdout;
#endif
			while (uart_usb_test_hit()){
  		  	   menu_process(uart_usb_getchar());   // See what they want
            }
#if USB_CONF_RS232
            if (usbstick_mode.debugOn) {
			  stdout=rs232_stdout;
			} else {
			  stdout=NULL;
			}
#endif
		}//if (Is_device_enumerated())



		if (USB_CONFIG_HAS_DEBUG_PORT(usb_configuration_nb)) {
			etimer_set(&et, CLOCK_SECOND/80);
		} else {
			etimer_set(&et, CLOCK_SECOND);
		}

		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));	
		
	} // while(1)

	PROCESS_END();
}