Exemplo n.º 1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(usb_serial_process, ev, data)
{

  PROCESS_BEGIN();

  set_serial_number();

  usb_setup();
  usb_cdc_acm_setup();
  usb_set_global_event_process(&usb_serial_process);
  usb_cdc_acm_set_event_process(&usb_serial_process);
  usb_set_ep_event_process(EPIN, &usb_serial_process);
  usb_set_ep_event_process(EPOUT, &usb_serial_process);

  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == PROCESS_EVENT_EXIT) {
      break;
    }
    if(ev == PROCESS_EVENT_POLL) {
      do_work();
    }
  }

  PROCESS_END();
}
Exemplo n.º 2
0
void
usb_setup(void)
{
  usb_arch_setup();
  process_start(&usb_process, NULL);
  usb_arch_set_global_event_process(&usb_process);
  usb_set_ep_event_process(0, &usb_process);

  usb_register_request_handler(&standard_request_hook);
}
Exemplo n.º 3
0
PROCESS_THREAD(usb_eth_process, ev , data)
{
    PROCESS_BEGIN();
    usb_register_request_handler(&cdc_eth_request_hook);
    usb_setup();
    usb_set_ep_event_process(DATA_OUT, process_current);
    usb_set_global_event_process(process_current);
    uip_fw_default(&usbethif);
    uip_setethaddr(default_uip_ethaddr);
    uip_arp_init();

    while(1) {
        PROCESS_WAIT_EVENT();
        if (ev == PROCESS_EVENT_EXIT) break;
        if (ev == PROCESS_EVENT_POLL) {
            unsigned int events = usb_get_global_events();
            if (events) {
                if (events & USB_EVENT_CONFIG) {
                    if (usb_get_current_configuration() != 0) {
                        printf("Configured\n");
                        usb_setup_bulk_endpoint(DATA_IN);
                        usb_setup_bulk_endpoint(DATA_OUT);
                        usb_setup_interrupt_endpoint(INTERRUPT_IN);
                        init_recv_buffer();
                        usb_submit_recv_buffer(DATA_OUT, &recv_buffer);
#if 0
                        {
                            static const uint8_t foo[4] = {0x12,0x34,0x56,0x78};
                            xmit_buffer[0].next = NULL;
                            xmit_buffer[0].left = sizeof(foo);
                            xmit_buffer[0].flags = USB_BUFFER_SHORT_END;
                            xmit_buffer[0].data = &foo;

                            usb_submit_xmit_buffer(DATA_IN, &xmit_buffer[0]);
                        }
#endif
                    } else {
                        usb_disable_endpoint(DATA_IN);
                        usb_disable_endpoint(DATA_OUT);
                        usb_disable_endpoint(INTERRUPT_IN);
                    }
                }
            }
            events = usb_get_ep_events(DATA_OUT);
            if (events & USB_EP_EVENT_NOTIFICATION) {
                uip_len = sizeof(recv_data) - recv_buffer.left;
                /* printf("Received: %d bytes\n", uip_len);  */
                memcpy(uip_buf, recv_data, uip_len);
#if UIP_CONF_IPV6
                if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) {
                    uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src);
                    tcpip_input();
                } else
#endif /* UIP_CONF_IPV6 */
                    if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) {
                        uip_len -= sizeof(struct uip_eth_hdr);
                        tcpip_input();
                    } else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) {
                        uip_arp_arpin();
                        /* If the above function invocation resulted in data that
                           should be sent out on the network, the global variable
                           uip_len is set to a value > 0. */
                        if (uip_len > 0) {
                            memcpy(xmit_data, uip_buf, uip_len);
                            xmit_buffer[0].next = NULL;
                            xmit_buffer[0].data = xmit_data;
                            xmit_buffer[0].left = uip_len;
                            xmit_buffer[0].flags = USB_BUFFER_SHORT_END;

                            usb_submit_xmit_buffer(DATA_IN, &xmit_buffer[0]);
                            /* printf("Sent: %d bytes\n", uip_len); */
                        }
                    }

                init_recv_buffer();
                usb_submit_recv_buffer(DATA_OUT, &recv_buffer);
            }
        }
    }
    PROCESS_END();
}