Esempio n. 1
0
Retcode
usb_install_keyboard_driver(Environ *e, Package *pkg, USB_self *usb,
		usb_device_descriptor_t *dev, usb_config_descriptor_t *cfg,
		usb_interface_descriptor_t *ifc)
{
	Retcode ret;
	Byte name[STR_SIZE];

	DPRINTF(("usb_install_keyboard_driver: addr=%d interface=%d\n",
			usb->addr, usb->interface));

	ret = prop_set_str(pkg->props, "device_type", CSTR, "keyboard", CSTR);

	if (ret == NO_ERROR)
		ret = init_entries(e, pkg->dict, usb_kbd_methods);


	/* make keyboard aliases if none already exist */
	if (ret == NO_ERROR)
		(void)get_device_name(e, pkg, name);

	if (ret == NO_ERROR &&
			find_table(e->aliases->props, "keyboard", CSTR) == NULL)
		ret = make_devalias(e, "keyboard", CSTR, name, CSTR);

	if (ret == NO_ERROR &&
			find_table(e->aliases->props, "usbkeyboard", CSTR) == NULL)
		ret = make_devalias(e, "usbkeyboard", CSTR, name, CSTR);


	/* set config descriptor 0 to turn on keyboard */
	ret = usb_setup(e, usb, usb->addr, USB_CONTROL_ENDPOINT,
			UT_WRITE_DEVICE, UR_SET_CONFIG,
			0, cfg->configuration_value, 0, 0, NULL);

	/* set keyboard to boot protocol (0) */
	if (ret == NO_ERROR)
		ret = usb_setup(e, usb, usb->addr, USB_CONTROL_ENDPOINT,
				UT_WRITE_CLASS_INTERFACE, UR_SET_PROTOCOL,
				0, 0, usb->interface, 0, NULL);

	if (ret == NO_ERROR)
		ret = usb_setup(e, usb, usb->addr, USB_CONTROL_ENDPOINT,
				UT_WRITE_CLASS_INTERFACE, UR_SET_IDLE,
				0, 0, usb->interface, 0, NULL);

	return ret;
}
Esempio n. 2
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();
}
Esempio n. 3
0
int main(void)
{
	clock_setup();
	gpio_setup();
	tim_setup();
	spi_setup();
	dac_setup();
	dma_setup();
	usb_setup();

	/* Attach the device to USB. */
	syscfg_enable_usb_pullup();

	/* Clear interrupt. */
	usbdevfs_clear_interrupt(USBDEVFS_ALL_INTERRUPT);

	/* Enable interrupt. */
	usbdevfs_enable_interrupt(USBDEVFS_CORRECT_TRANSFER | USBDEVFS_ERROR |
				  USBDEVFS_RESET | USBDEVFS_SOF);

	/* Wait forever and do nothing. */
	while (1)
		__asm__ ("nop");

	return 0;
}
Esempio n. 4
0
void setup_usb(void)
{
  uip_ipaddr_t hostaddr, netmask, defrouter;
  
  uip_ipaddr(&hostaddr, 10,0,0,2);
  uip_ipaddr(&netmask, 255,0,0,0);
  uip_ipaddr(&defrouter, 10,0,0,1);
  
  uip_sethostaddr(&hostaddr);
  uip_setnetmask(&netmask);
  uip_setdraddr(&defrouter);
  /*
    uip_over_mesh_set_net(&hostaddr, &netmask);
    uip_fw_register(&slipif);
    uip_over_mesh_set_gateway_netif(&slipif);
    uip_fw_default(&meshif);
    uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
  */
  printf("uIP started with IP address %d.%d.%d.%d\n",
         uip_ipaddr_to_quad(&hostaddr));

#ifdef WITH_USB
  printf("Setting up USB\n");
  usb_setup();
  printf("usb setup done\n");
  usb_cdc_eth_set_ifaddr(&hostaddr);
  usb_cdc_eth_setup();
#endif
  printf("cdc_eth setup done\n");
}
Esempio n. 5
0
void system_setup(void)
{
    clock_setup();
    mco_setup();
    usb_setup();
    systick_setup();
    rng_setup();
    battery_setup();

    speaker_setup();
    jack_setup();
    // setup pad and screen
    interface_setup();

    // setup and reset SAM2695
    sam2695_setup();
    wait_ms(100);
    sam2695_reset();

    usbmidi_setup();

    // init gfx and fill screen
    gfx_init(ssd1306_drawpixel, SSD1306_WIDTH, SSD1306_HEIGHT, GFX_FONT_SMALL);
    gfx_setRotation(GFX_ROT_180);
    gfx_fillScreen(OLED_BLACK);
    gfx_setTextColor(OLED_WHITE, OLED_BLACK);
//    gfx_setTextWrap(1);
    gfx_setTextSize(1);
    ssd1306_display();
}
Esempio n. 6
0
Retcode
usb_set_leds(Environ *e, USB_self *usb, uByte lock)
{
	return usb_setup(e, usb, usb->addr, USB_CONTROL_ENDPOINT,
			UT_WRITE_CLASS_INTERFACE, UR_SET_REPORT,
			UHID_OUTPUT_REPORT, 0, usb->interface,
			1, &lock);
}
Esempio n. 7
0
void usbtest_usb_setup(void)
{
    usb_setup(&config);
    printf("appending interfaces\n");
    usb_append_interface_lowspeed(if_descriptor_lowspeed, sizeof(if_descriptor_lowspeed));
    usb_append_interface_highspeed(if_descriptor_lowspeed, sizeof(if_descriptor_lowspeed));
    usbc_setup_endpoint(1, USB_OUT, 64, USB_BULK);
    usbc_setup_endpoint(1, USB_IN, 64, USB_BULK);
}
Esempio n. 8
0
void acm_start()
{
	task_init(&acm_parse_task, "ACM");

	usb_setup(acm_enumerate, acm_started);
	usb_install_ep_handler(ACM_EP_SEND, USBIn, acm_sent, 0);
	usb_install_ep_handler(ACM_EP_RECV, USBOut, acm_received, 0);
	usb_install_setup_handler(acm_setup);
}
Esempio n. 9
0
static void startUSB()
{
	usb_setup();
	usb_install_ep_handler(4, USBOut, controlReceived, 0);
	usb_install_ep_handler(2, USBOut, dataReceived, 0);
	usb_install_ep_handler(3, USBIn, controlSent, 0);
	usb_install_ep_handler(1, USBIn, dataSent, 0);
	usb_start(enumerateHandler, startHandler);
}
Esempio n. 10
0
// Initialize hardware devices
void
device_hardware_setup(void)
{
    usb_setup();
    ps2port_setup();
    block_setup();
    lpt_setup();
    serial_setup();
    cbfs_payload_setup();
}
Esempio n. 11
0
void acm_start()
{
	task_init(&acm_parse_task, "ACM", TASK_DEFAULT_STACK_SIZE);

	usb_setup(acm_enumerate, acm_started);
	usb_install_ep_handler(ACM_EP_SEND, USBIn, acm_sent, 0);
	usb_install_ep_handler(ACM_EP_RECV, USBOut, acm_received, 0);
	usb_install_setup_handler(acm_setup);

	acm_prev_printf_handler = addPrintfHandler(acm_buffer_notify);
}
Esempio n. 12
0
File: usb.c Progetto: 0xBADCA7/lk
void target_usb_setup(void)
{
    usb_setup(&config);

    append_usb_interfaces();

    usb_add_string("LK", 1);
    usb_add_string("LK Industries", 2);

    usb_start();
}
Esempio n. 13
0
static
void
do_other_wait(void)
{
    int rv;
    struct setup setup;
    byte configuration[18];
    
    do {
        sleep_poll();
        delay(1000);

        // get the configuration descriptor
        usb_setup(1, SETUP_TYPE_STANDARD, SETUP_RECIP_DEVICE, REQUEST_GET_DESCRIPTOR, (CONFIGURATION_DESCRIPTOR<<8)|0, 0, sizeof(configuration), &setup);
        rv = usb_control_transfer(&setup, configuration, sizeof(configuration));
    } while (rv > 0);
}
Esempio n. 14
0
// Initialize hardware devices
static void
init_hw(void)
{
    usb_setup();
    ps2port_setup();
    lpt_setup();
    serial_setup();

    floppy_setup();
    ata_setup();
    ahci_setup();
    cbfs_payload_setup();
    ramdisk_setup();
    virtio_blk_setup();
    virtio_scsi_setup();
    lsi_scsi_setup();
}
Esempio n. 15
0
void configure_system() {
	    
	kill_interrupts();	// turn off interrupts just in case

	turn_analog_inputs_off();	// kill those pesky analogue inputs
	
	#ifdef USB_SERIAL_DEBUG 
		serial_setup(BRGH_HIGH_SPEED, SPBRG_57600);
	#endif
	
	usb_cdc_setup();

	usb_setup();
	
	turn_usb_ints_on();
	turn_peripheral_ints_on();
	turn_global_ints_on();
}
Esempio n. 16
0
int main(void)
{
	cm_disable_interrupts();
	clk_tree_setup();
	mco_setup();
	clock_setup();
	usb_setup();
	cli_setup();
	pwm_init();
	led_setup();
	button_setup();
	ncn_setup();
	cm_enable_interrupts();

	while (1) {
		__WFI();
	}

	return 0;
}
Esempio n. 17
0
// Initialize hardware devices
void
device_hardware_setup(void)
{
    usb_setup();
    ps2port_setup();
    lpt_setup();
    serial_setup();

    floppy_setup();
    ata_setup();
    ahci_setup();
    cbfs_payload_setup();
    ramdisk_setup();
    virtio_blk_setup();
    virtio_scsi_setup();
    lsi_scsi_setup();
    esp_scsi_setup();
    megasas_setup();
    pvscsi_setup();
}
Esempio n. 18
0
void setup() {

	Serial.begin(115200);

	Notify(PSTR("initializing WiFi\n"));
	wifi_init();

	Notify(PSTR("waiting for connection\n"));
	wifi_connect();

	Notify(PSTR("setting up USB\n"));
	usb_setup();

	hokuyo_data = (char*) malloc(HOKUYO_DATA_LENGTH);
	if (hokuyo_data) {
		Notify(PSTR("hokuyo_data allocated\n"));
	}

	hokuyo_on();
	Notify(PSTR("hokuyo on\n"));

	Wire.begin(I2C_MASTER_ADDRESS);
	Wire.onReceive(receive);
}
Esempio n. 19
0
static int setup_devices() {
	// Basic prerequisites for everything else
	miu_setup();
	power_setup();
	clock_setup();

	// Need interrupts for everything afterwards
	interrupt_setup();

	gpio_setup();

	// For scheduling/sleeping niceties
	timer_setup();
	event_setup();

	// Other devices
	usb_shutdown();
	uart_setup();

	dma_setup();
	usb_setup();

	return 0;
}
Esempio n. 20
0
static void handle_data(void){
    #ifdef USE_STTERM
    unsigned char tmp_c;
    #endif

    uint32_t tmp=0;
    char crc=0;

    #ifdef USE_STTERM
    if(stlinky_rx_ready()){
        scanf("%c", &tmp_c);
        INPUT[k] = tmp_c;
        gpio_toggle(GPIOD, GPIO15);
    #else
    if(usart_has_data()){
        INPUT[k] = usart_read();
    #endif
    k++;
    if(k==1 && INPUT[0]!=0x53){ // 'S'
        #ifdef DEBUG
        printf("ERROR AT START-BYTE %d\r\n",INPUT[0]);
        #endif
        k=0;
    }
    if(k==10 && INPUT[9]!=0x45){ // 'E'
        #ifdef DEBUG
        printf("ERROR AT END-BYTE %d\r\n",INPUT[8]);
        #endif
        k=0;
    }
    if(k==11){
        #ifdef DEBUG
        printf("Package: ");
        for(tmp=0;tmp<10;tmp++) printf("%d ",INPUT[tmp]);
        printf("\n");
        #endif
        for(tmp=0;tmp<8;tmp++) KEYS[tmp] = INPUT[tmp+1];
        crc = getCRC(KEYS,8);
        if(crc==INPUT[10]){
            #ifdef DEBUG
            printf("INPUT OK!\r\n");
                #endif
                if(usb_ready == 3) usb_send_packet(KEYS, 8);
            }else{
                #ifdef DEBUG
                printf("ERROR AT CRC-BYTE %d vs %d\r\n",INPUT[10],crc);
                #endif
            }
            k=0;
        }
    }
}
void tim3_isr(void){
    if(timer_get_flag(TIM3, TIM_SR_UIF)){
        handle_data();
        timer_clear_flag(TIM3, TIM_SR_UIF);
    }
}

void tim4_isr(void){
    if(timer_get_flag(TIM4, TIM_SR_UIF)){
        if(usb_ready==3){
            gpio_toggle(GPIOD,GPIO14);
            KEYS[0]=0;
            KEYS[1]=0;
            KEYS[3]=0;
            KEYS[4]=0;
            KEYS[5]=0;
            KEYS[6]=0;
            KEYS[7]=0;

            KEYS[2]=0x04;
            usb_send_packet(KEYS, 8);
            KEYS[2]=0x00;
            usb_send_packet(KEYS, 8);
            KEYS[2]=0x05;
            usb_send_packet(KEYS, 8);
            KEYS[2]=0x00;
            usb_send_packet(KEYS, 8);
        }
        timer_clear_flag(TIM4, TIM_SR_UIF);
    }
}

void tim5_isr(void){
    if(timer_get_flag(TIM5, TIM_SR_UIF)){
        gpio_toggle(GPIOD, GPIO15);
        timer_clear_flag(TIM5, TIM_SR_UIF);
    }
}

int main(void) {
    iwdg_reset();
    iwdg_set_period_ms(5);
    iwdg_start();

    rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]);
    rcc_periph_clock_enable(RCC_GPIOD);
    systick_setup();

    gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12 | GPIO13 | GPIO14 | GPIO15);
    gpio_clear(GPIOD, GPIO12 | GPIO13 | GPIO14 | GPIO15);

    iwdg_set_period_ms(500);
    iwdg_reset();
    msleep(400);
    iwdg_set_period_ms(5);
    iwdg_reset();

    gpio_set(GPIOD, GPIO15);

//    msleep(100000); /* SLEEEEEEEEEEEEEEEEEEEEEEP */

    #ifdef USE_STTERM
    stlinky_init();
    #else
    usart_setup();
    #endif

    timer2_setup(100);

    usb_setup();

    //timer4_setup(1);
    timer3_setup(100);
    timer5_setup(2);

//    gpio_set(GPIOD, GPIO12 | GPIO13 | GPIO14 | GPIO15);

    while(1) {
        iwdg_reset();
    }

    return 0;
}
Esempio n. 21
0
File: usb.c Progetto: bluefix/picsdr
// ----------------------------------------------------------------------
// Inspect an incoming packet.
// ----------------------------------------------------------------------
static	void	usb_receive ( byte_t* data, byte_t rx_len )
{
	byte_t	len;
	byte_t	type;
	byte_t	limit;

	usb_tx_state = TX_STATE_RAM;
	len = 0;
	if	( usb_rx_token == USB_PID_SETUP )
	{
		limit = data[6];
		if	( data[7] )
		{
			limit = 255;
		}
		type = data[0] & 0x60;
		if	( type == 0x00 )
		{	// Standard request
			if	( data[1] == 0 )	// GET_STATUS
			{
				len = 2;
#if	USBTINY_MAX_POWER == 0
				data[0] = (data[0] == 0x80);
#else
				data[0] = 0;
#endif
				data[1] = 0;
			}
			else if	( data[1] == 5 )	// SET_ADDRESS
			{
				new_address = data[2];
			}
			else if	( data[1] == 6 )	// GET_DESCRIPTOR
			{
				usb_tx_state = TX_STATE_ROM;
				if	( data[3] == 1 )
				{	// DEVICE
					data = (byte_t*) &descr_device;
					len = sizeof(descr_device);
				}
				else if	( data[3] == 2 )
				{	// CONFIGURATION
					data = (byte_t*) &descr_config;
					len = sizeof(descr_config);
					// If we got this far, there's a good chance everything is OK with enumeration so turn on the OK led
					PORTD = _BV(5);

				}
#if	VENDOR_NAME_ID || DEVICE_NAME_ID || SERIAL_ID
				else if	( data[3] == 3 )
				{	// STRING
					if	( data[2] == 0 )
					{
						data = (byte_t*) &string_langid;
						len = sizeof(string_langid);
					}
#if	VENDOR_NAME_ID
					else if	( data[2] == VENDOR_NAME_ID )
					{
						data = (byte_t*) &string_vendor;
						len = sizeof(string_vendor);
					}
#endif
#if	DEVICE_NAME_ID
					else if ( data[2] == DEVICE_NAME_ID )
					{
						data = (byte_t*) &string_device;
						len = sizeof(string_device);
					}
#endif
#if	SERIAL_ID
					else if ( data[2] == SERIAL_ID )
					{
						data = (byte_t*) &string_serial;
						len = sizeof(string_serial);
					}
#endif
				}
#endif
			}
			else if	( data[1] == 8 )	// GET_CONFIGURATION
			{
				data[0] = 1;		// return bConfigurationValue
				len = 1;
			}
			else if	( data[1] == 10 )	// GET_INTERFACE
			{
				data[0] = 0;
				len = 1;
			}
		}
		else
		{	// Class or Vendor request
			len = usb_setup( data );
#if	USBTINY_CALLBACK_IN
			if	( len == 0xff )
			{
				usb_tx_state = TX_STATE_CALLBACK;
			}
#endif
		}
		if	( len > limit )
		{
			len = limit;
		}
		usb_tx_data = data;
	}
#if	USBTINY_CALLBACK_OUT
	else if	( rx_len > 0 )
	{	// usb_rx_token == USB_PID_OUT
		usb_out( data, rx_len );
	}
#endif
	usb_tx_total  = len;
	usb_tx_buf[0] = USB_PID_DATA0;	// next data packet will be DATA1
}
Esempio n. 22
0
PROCESS_THREAD(gateway_process, ev , data)
{
  static struct etimer timer;
  PROCESS_BEGIN();
  usb_set_user_process(process_current);
  usb_setup();
  usb_cdc_acm_setup();

  uip_fw_default(&slipif);
  uip_over_mesh_set_gateway_netif(&slipif);

  process_start(&slip_process, NULL);

  set_gateway();
  
  while(ev != PROCESS_EVENT_EXIT) {
    PROCESS_WAIT_EVENT();
    if (ev == PROCESS_EVENT_TIMER) {
      leds_toggle(LEDS_YELLOW);
      /* printf("FIFOP: %d\n", FIFOP_IS_1); */
      etimer_restart(&timer);
    } else if (ev == PROCESS_EVENT_MSG) {
      const struct usb_user_msg * const msg = data;
      switch(msg->type) {
      case USB_USER_MSG_TYPE_CONFIG:
	printf("User config\n");
	if (msg->data.config != 0) {
	  usb_setup_bulk_endpoint(DEV_TO_HOST,
				  input_buffer, sizeof(input_buffer));
	  usb_setup_bulk_endpoint(HOST_TO_DEV,
				  output_buffer, sizeof(output_buffer));
	  usb_setup_interrupt_endpoint(0x83,interrupt_buffer,
				       sizeof(interrupt_buffer));
	  etimer_set(&timer, CLOCK_SECOND);
	} else {
	  etimer_stop(&timer);
	  usb_disable_endpoint(DEV_TO_HOST);
	  usb_disable_endpoint(HOST_TO_DEV);
	  usb_disable_endpoint(0x83);

	}
	break;
      case USB_USER_MSG_TYPE_EP_OUT(2):
	{
	  /*unsigned int len = msg->data.length; 
	    printf("Received %d:\n", len);  */
	  {
	    unsigned char ch;
	    unsigned int xfer;
	    while((xfer = usb_recv_data(HOST_TO_DEV, &ch, 1)) > 0) {
	      /* printf(" %02x",ch); */
	      if (slip_input_byte(ch)) break;
	    }
	    /* printf("\n"); */
	  }
	}
	break;
      }
      
    }
  }
  printf("USB test process exited\n");
  PROCESS_END();
}
Esempio n. 23
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();
}
Esempio n. 24
0
void cdcacm_target_init(void)
{
	rcc_clock_setup_hsi(&rcc_hsi_8mhz[RCC_CLOCK_48MHZ]);

	usb_setup();
}
Esempio n. 25
0
PROCESS_THREAD(eriks_process, ev , data)
{
  static struct etimer timer;
  uip_ipaddr_t myaddr;
  uip_ipaddr_t hostaddr;
  uip_ipaddr_t netmask;
#if 0
  struct dhcps_client_lease dhleases[3];
  struct dhcps_config dhconfig;
#endif
  PROCESS_BEGIN();
  printf("Eriks super process\n\r");

  uip_init();

#if 0
  dhconfig.leases = &dhleases[0];
  dhconfig.num_leases = 3;
  dhconfig.default_lease_time = 3600;
  uip_ipaddr(&dhconfig.netmask, 255,255,255,255);
  uip_ipaddr(&dhconfig.dnsaddr, 1,2,3,4);
  uip_ipaddr(&dhconfig.dnsaddr, 1,0,0,1);
  dhconfig.flags = DHCP_CONF_NETMASK | DHCP_CONF_DEFAULT_ROUTER;
#endif
  /* usb_set_user_process(process_current); */

  uip_ipaddr(&myaddr, 10,0,0,2);
  uip_sethostaddr(&hostaddr);

  uip_ipaddr(&netmask, 255,0,0,0);
  uip_sethostaddr(&hostaddr);

  uip_ipaddr(&myaddr, 10,0,0,1);
  uip_ipaddr(&netmask, 255,255,0,0);

  usb_setup();
#if 0
  usb_cdc_eth_set_ifaddr(&myaddr);
  usb_cdc_eth_setup();
  
  dhcps_init(&dhconfig);
    
  while(ev != PROCESS_EVENT_EXIT) {
    PROCESS_WAIT_EVENT();
    printf("EVENT\n\r");
  }

#else
  usb_cdc_acm_setup();

  while(ev != PROCESS_EVENT_EXIT) {
    PROCESS_WAIT_EVENT();
    if (ev == PROCESS_EVENT_TIMER) {
      leds_toggle(LEDS_YELLOW);
      /* printf("FIFOP: %d\n", FIFOP_IS_1); */
      etimer_restart(&timer);
    } else if (ev == PROCESS_EVENT_MSG) {
      const struct usb_user_msg * const msg = data;
      switch(msg->type) {
      case USB_USER_MSG_TYPE_CONFIG:
        printf("User config\n");
        if (msg->data.config != 0) {
#if 0
          usb_setup_bulk_endpoint(DEV_TO_HOST,
                                  input_buffer, sizeof(input_buffer));
          usb_setup_bulk_endpoint(HOST_TO_DEV,
                                  output_buffer, sizeof(output_buffer));
          usb_setup_interrupt_endpoint(0x83,interrupt_buffer,
                                       sizeof(interrupt_buffer));
          etimer_set(&timer, CLOCK_SECOND);
#endif
        } else {
#if 0
          etimer_stop(&timer);
          usb_disable_endpoint(DEV_TO_HOST);
          usb_disable_endpoint(HOST_TO_DEV);
          usb_disable_endpoint(0x83);
#endif	  
        }
        break;
      case USB_USER_MSG_TYPE_EP_OUT(2):
        {
#if 0
          /*unsigned int len = msg->data.length; 
            printf("Received %d:\n", len);  */
          {
            unsigned char ch;
            unsigned int xfer;
	    /*
            while((xfer = usb_recv_data(HOST_TO_DEV, &ch, 1)) > 0) {
              printf(" %02x",ch);
	    */
              /* if (slip_input_byte(ch)) break; */

            }
#endif
            /* printf("\n"); */
        }
        break;
      }
    }
  }

#endif
  printf("Exiting USB process\n\r");
  PROCESS_END();
}
Esempio n. 26
0
// ----------------------------------------------------------------------
// Inspect an incoming packet.
// ----------------------------------------------------------------------
static	void	usb_receive ( byte_t* data, byte_t rx_len )
{
	byte_t	len;
	byte_t	type;
	txlen_t	limit;

	usb_tx_state = TX_STATE_RAM;
	len = 0;
	limit = 0;
	if	( usb_rx_token == USB_PID_SETUP )
	{
#if	USBTINY_CALLBACK_IN == 2
		limit = * (uint_t*) & data[6];
#else
		limit = data[6];
		if	( data[7] )
		{
			limit = 255;
		}
#endif
		type = data[0] & 0x60;
		if	( type == 0x00 )
		{	// Standard request
			if	( data[1] == 0 )	// GET_STATUS
			{
				len = 2;
#if	USBTINY_MAX_POWER == 0
				data[0] = (data[0] == 0x80);
#else
				data[0] = 0;
#endif
				data[1] = 0;
			}
			else if	( data[1] == 5 )	// SET_ADDRESS
			{
				usb_new_address = data[2];
#ifdef	USBTINY_USB_OK_LED
				SET(USBTINY_USB_OK_LED);// LED on
#endif
			}
			else if	( data[1] == 6 )	// GET_DESCRIPTOR
			{
				usb_tx_state = TX_STATE_ROM;
				if	( data[3] == 1 )
				{	// DEVICE
					data = (byte_t*) &descr_device;
					len = sizeof(descr_device);
				}
				else if	( data[3] == 2 )
				{	// CONFIGURATION
					data = (byte_t*) &descr_config;
					len = sizeof(descr_config);
				}
#if	VENDOR_NAME_ID || DEVICE_NAME_ID || SERIAL_ID
				else if	( data[3] == 3 )
				{	// STRING
					if	( data[2] == 0 )
					{
						data = (byte_t*) &string_langid;
						len = sizeof(string_langid);
					}
#if	VENDOR_NAME_ID
					else if	( data[2] == VENDOR_NAME_ID )
					{
						data = (byte_t*) &string_vendor;
						len = sizeof(string_vendor);
					}
#endif
#if	DEVICE_NAME_ID
					else if ( data[2] == DEVICE_NAME_ID )
					{
						data = (byte_t*) &string_device;
						len = sizeof(string_device);
					}
#endif
#if	SERIAL_ID
					else if ( data[2] == SERIAL_ID )
					{
						data = (byte_t*) &string_serial;
						len = sizeof(string_serial);
					}
#endif
				}
#endif
			}
			else if	( data[1] == 8 )	// GET_CONFIGURATION
			{
				data[0] = 1;		// return bConfigurationValue
				len = 1;
			}
			else if	( data[1] == 10 )	// GET_INTERFACE
			{
				data[0] = 0;
				len = 1;
			}
		}
		else
		{	// Class or Vendor request
			len = usb_setup( data );
#if	USBTINY_CALLBACK_IN
			if	( len == 0xff )
			{
				usb_tx_state = TX_STATE_CALLBACK;
			}
#endif
		}
		if	(  len < limit
#if	USBTINY_CALLBACK_IN == 2
			&& len != 0xff
#endif
			)
		{
			limit = len;
		}
		usb_tx_data = data;
	}
#if	USBTINY_CALLBACK_OUT
	else if	( rx_len > 0 )
	{	// usb_rx_token == USB_PID_OUT
		usb_out( data, rx_len );
	}
#endif
	usb_tx_total  = limit;
	usb_tx_buf[0] = USB_PID_DATA0;	// next data packet will be DATA1
}
Esempio n. 27
0
static void usb_control(uint32_t stat)
{
	bdt_t *b;
	uint32_t pid, size;
	uint8_t *buf;
	const uint8_t *data;

	b = stat2bufferdescriptor(stat);
	pid = BDT_PID(b->desc);
	//count = b->desc >> 16;
	buf = b->addr;
	//serial_print("pid:");
	//serial_phex(pid);
	//serial_print(", count:");
	//serial_phex(count);
	//serial_print("\n");

	switch (pid) {
	case 0x0D: // Setup received from host
		//serial_print("PID=Setup\n");
		//if (count != 8) ; // panic?
		// grab the 8 byte setup info
		setup.word1 = *(uint32_t *)(buf);
		setup.word2 = *(uint32_t *)(buf + 4);

		// give the buffer back
		b->desc = BDT_DESC(EP0_SIZE, DATA1);
		//table[index(0, RX, EVEN)].desc = BDT_DESC(EP0_SIZE, 1);
		//table[index(0, RX, ODD)].desc = BDT_DESC(EP0_SIZE, 1);

		// clear any leftover pending IN transactions
		ep0_tx_ptr = NULL;
		if (ep0_tx_data_toggle) {
		}
		//if (table[index(0, TX, EVEN)].desc & 0x80) {
			//serial_print("leftover tx even\n");
		//}
		//if (table[index(0, TX, ODD)].desc & 0x80) {
			//serial_print("leftover tx odd\n");
		//}
		table[index(0, TX, EVEN)].desc = 0;
		table[index(0, TX, ODD)].desc = 0;
		// first IN after Setup is always DATA1
		ep0_tx_data_toggle = 1;

#if 0
		serial_print("bmRequestType:");
		serial_phex(setup.bmRequestType);
		serial_print(", bRequest:");
		serial_phex(setup.bRequest);
		serial_print(", wValue:");
		serial_phex16(setup.wValue);
		serial_print(", wIndex:");
		serial_phex16(setup.wIndex);
		serial_print(", len:");
		serial_phex16(setup.wLength);
		serial_print("\n");
#endif
		// actually "do" the setup request
		usb_setup();
		// unfreeze the USB, now that we're ready
		USB0_CTL = USB_CTL_USBENSOFEN; // clear TXSUSPENDTOKENBUSY bit
		break;
	case 0x01:  // OUT transaction received from host
	case 0x02:
		//serial_print("PID=OUT\n");
#ifdef CDC_STATUS_INTERFACE
		if (setup.wRequestAndType == 0x2021 /*CDC_SET_LINE_CODING*/) {
			int i;
			uint8_t *dst = usb_cdc_line_coding;
			//serial_print("set line coding ");
			for (i=0; i<7; i++) {
				//serial_phex(*buf);
				*dst++ = *buf++;
			}
			//serial_phex32(*(uint32_t *)usb_cdc_line_coding);
			//serial_print("\n");
			if (*(uint32_t *)usb_cdc_line_coding == 134) usb_reboot_timer = 15;
			endpoint0_transmit(NULL, 0);
		}
#endif
#ifdef KEYBOARD_INTERFACE
		if (setup.word1 == 0x02000921 && setup.word2 == ((1<<16)|KEYBOARD_INTERFACE)) {
			keyboard_leds = buf[0];
			endpoint0_transmit(NULL, 0);
		}
#endif
#ifdef SEREMU_INTERFACE
		if (setup.word1 == 0x03000921 && setup.word2 == ((4<<16)|SEREMU_INTERFACE)
		  && buf[0] == 0xA9 && buf[1] == 0x45 && buf[2] == 0xC2 && buf[3] == 0x6B) {
			usb_reboot_timer = 5;
			endpoint0_transmit(NULL, 0);
		}
#endif
		// give the buffer back
		b->desc = BDT_DESC(EP0_SIZE, DATA1);
		break;

	case 0x09: // IN transaction completed to host
		//serial_print("PID=IN:");
		//serial_phex(stat);
		//serial_print("\n");

		// send remaining data, if any...
		data = ep0_tx_ptr;
		if (data) {
			size = ep0_tx_len;
			if (size > EP0_SIZE) size = EP0_SIZE;
			endpoint0_transmit(data, size);
			data += size;
			ep0_tx_len -= size;
			ep0_tx_ptr = (ep0_tx_len > 0 || size == EP0_SIZE) ? data : NULL;
		}

		if (setup.bRequest == 5 && setup.bmRequestType == 0) {
			setup.bRequest = 0;
			//serial_print("set address: ");
			//serial_phex16(setup.wValue);
			//serial_print("\n");
			USB0_ADDR = setup.wValue;
		}

		break;
	//default:
		//serial_print("PID=unknown:");
		//serial_phex(pid);
		//serial_print("\n");
	}
	USB0_CTL = USB_CTL_USBENSOFEN; // clear TXSUSPENDTOKENBUSY bit
}
Esempio n. 28
0
static void startUSB()
{
	usb_setup(enumerateHandler, startHandler);
}