Ejemplo n.º 1
0
//! usb_read_packet.
//!
//! This function moves the data stored in the selected endpoint fifo to
//! the address specified by *rbuf.
//!
//!
//! @param ep_num       number of the addressed endpoint
//! @param *rbuf        aaddress of the first data to write with the USB data
//! @param data_length  number of bytes to read
//!
//! @return address of the next U8 to send.
//!
//! Example:
//! while(!(Usb_rx_complete));                      // wait new packet received
//! usb_read_packet(4,&first_data,usb_get_nb_byte); // read packet from ep 4
//! Usb_clear_rx();                                 // acknowledge the transmit
//!
//! Note:
//! rbuf is incremented of 'data_length'.
//!
U8 usb_read_packet(U8 ep_num, U8* rbuf, U8  data_length)
{
U8 remaining_length;

   remaining_length = data_length;
   Usb_select_endpoint(ep_num);

   while(Is_usb_read_enabled() && (0 != remaining_length))
   {
      *rbuf = Usb_read_byte();
      remaining_length--;
      rbuf++;
   }
   return remaining_length;
}
Ejemplo n.º 2
0
//! usb_read_packet.
//!
//! This function moves the data stored in the selected endpoint fifo to
//! the address specified by *rbuf.
//!
//! @warning Code:xx bytes (function code length)
//!
//! @param ep_num       number of the addressed endpoint
//! @param *rbuf        aaddress of the first data to write with the USB data
//! @param data_length  number of bytes to read
//!
//! @return address of the next uint8_t to send.
//!
//! Example:
//! while(!(Usb_rx_complete));                      // wait new packet received
//! usb_read_packet(4,&first_data,usb_get_nb_byte); // read packet from ep 4
//! Usb_clear_rx();                                 // acknowledge the transmit
//!
//! Note:
//! rbuf is incremented of 'data_length'.
//!
uint8_t usb_read_packet(uint8_t ep_num, uint8_t* rbuf, uint8_t  data_length)
{
uint8_t remaining_length;

   remaining_length = data_length;
   Usb_select_endpoint(ep_num);

   while(Is_usb_read_enabled() && (0 != remaining_length))
   {
      *rbuf = Usb_read_byte();
      remaining_length--;
      rbuf++;
   }
   return remaining_length;
}
Ejemplo n.º 3
0
uint8_t
cdc_ecm_process(void) {
	static uint8_t doInit = 1;
	
	Usb_select_endpoint(RX_EP);

	if(!Is_usb_endpoint_enabled()) {
		return 0;
	}

	if (doInit) {
#ifdef USB_ETH_HOOK_INIT
		USB_ETH_HOOK_INIT();
#endif
		cdc_ecm_notify_network_connection(1);
		cdc_ecm_notify_connection_speed_change(250000,250000);
		doInit = 0;
		if(usb_ecm_packet_filter & PACKET_TYPE_PROMISCUOUS) {
#if RF230BB
			rf230_set_promiscuous_mode(true);
#else		
			radio_set_trx_state(RX_ON);
#endif
		}

		// Select again, just to make sure.
		Usb_select_endpoint(RX_EP);
	}

	if(!usb_eth_is_active) {
		// If we aren't active, just eat the packets.
		if(Is_usb_read_enabled()) {
			Usb_ack_receive_out();
		}
		return 0;
	}

	//Connected!
	Led0_on();

	if(Is_usb_read_enabled()) {
		uint16_t bytecounter;
		uint16_t bytes_received = 0;
		U8 * buffer = uip_buf;

		if(!usb_eth_ready_for_next_packet()) {
			// Since we aren't ready for a packet yet,
			// just return.
			goto bail;
		}

#ifdef USB_ETH_HOOK_RX_START
		USB_ETH_HOOK_RX_START();
#endif

		while((bytecounter=Usb_byte_counter_8())==CDC_ECM_DATA_ENDPOINT_SIZE) {
			while((bytes_received<USB_ETH_MTU) && (bytecounter--)) {
				*buffer++ = Usb_read_byte();
				bytes_received++;
			}
			bytes_received+=bytecounter+1;

			//ACK previous data
			Usb_ack_receive_out();

			//Wait for new data
			if(usb_endpoint_wait_for_read_enabled()!=0) {
				USB_ETH_HOOK_RX_ERROR("Timeout: read enabled");
				goto bail;
			}
		}
		bytecounter = Usb_byte_counter_8();
		while((bytes_received<USB_ETH_MTU) && (bytecounter--)) {
			*buffer++ = Usb_read_byte();
			bytes_received++;
		}
		bytes_received+=bytecounter+1;
		
		//Ack final data packet
		Usb_ack_receive_out();

		//PRINTF_P(PSTR("cdc_ecm: Got packet %d bytes long\n"),bytes_received);

#ifdef USB_ETH_HOOK_RX_END
		USB_ETH_HOOK_RX_END();
#endif
		
		//Send data over RF or to local stack
		if(bytes_received<=USB_ETH_MTU) {

			USB_ETH_HOOK_HANDLE_INBOUND_PACKET(uip_buf,bytes_received);
		} else {
			USB_ETH_HOOK_RX_ERROR("Oversized packet");
		}
	}
bail:
	return 1;
}
Ejemplo n.º 4
0
uint8_t usb_eth_packet_is_available() {
	Usb_select_endpoint(RX_EP);
	return Is_usb_read_enabled();
}