コード例 #1
0
ファイル: pcsensor.c プロジェクト: longjos/temper
/**
 * Initialize all Temper Devices currently attached to the system
 * @return pcsensor_devices*
 */
pcsensor_devices* setup_libusb_access() {
    static pcsensor_devices *available_devices;

    if (debug) {
        usb_set_debug(255);
    } else {
        usb_set_debug(0);
    }

    usb_init();
    usb_find_busses();
    usb_find_devices();

    // Get an array of MAX_SENSORS
    available_devices = find_lvr_winusb();

    if (available_devices->sensor_count == 0) {
        if (debug) {
            printf("Couldn't find the USB device, Exiting\n");
        }
        return NULL;
    }
    int i;

    for (i = 0; i < available_devices->sensor_count; i++) {
        usb_dev_handle *lvr_winusb = available_devices->sensors[i];

        usb_detach(lvr_winusb, INTERFACE1);

        usb_detach(lvr_winusb, INTERFACE2);


        if (usb_set_configuration(lvr_winusb, 0x01) < 0) {
            if (debug) {
                printf("Could not set configuration 1\n");
            }
            return NULL;
        }

        // Microdia tiene 2 interfaces
        if (usb_claim_interface(lvr_winusb, INTERFACE1) < 0) {
            if (debug) {
                printf("Could not claim interface\n");
            }
            return NULL;
        }

        if (usb_claim_interface(lvr_winusb, INTERFACE2) < 0) {
            if (debug) {
                printf("Could not claim interface\n");
            }
            return NULL;
        }
    }
    return available_devices;
}
コード例 #2
0
ファイル: pcsensor.c プロジェクト: raff/temper
static usb_dev_handle* setup_libusb_access() {
	usb_dev_handle *lvr_winusb;

	if(debug) {
		usb_set_debug(255);
	} else {
		usb_set_debug(0);
	}
	usb_init();
	usb_find_busses();
	usb_find_devices();

 
	if(!(lvr_winusb = find_lvr_winusb())) {
		if(debug){
			printf("Couldn't find the USB device, Exiting\n");
		}
		return NULL;
	}
        
        
	usb_detach(lvr_winusb, INTERFACE1);
        

	usb_detach(lvr_winusb, INTERFACE2);
        
 
	if (usb_set_configuration(lvr_winusb, 0x01) < 0) {
		if(debug){
			printf("Could not set configuration 1\n");
		}
		return NULL;
	}
 

	// Microdia tiene 2 interfaces
	if (usb_claim_interface(lvr_winusb, INTERFACE1) < 0) {
		if(debug){
			printf("Could not claim interface\n");
		}
		return NULL;
	}
 
	if (usb_claim_interface(lvr_winusb, INTERFACE2) < 0) {
		if(debug){
			printf("Could not claim interface\n");
		}
		return NULL;
	}
 
	return lvr_winusb;
}
コード例 #3
0
ファイル: main.c プロジェクト: Gozhack/firmware
void bootloader_main() {
	SystemInit();
	spiflash_reinit();
	CGU_Init();

	hw_digital_output(LED1);
	hw_digital_output(LED2);
	hw_digital_output(CC3K_CONN_LED);
	hw_digital_output(CC3K_ERR_LED);
	hw_digital_write(CC3K_CONN_LED, 0);
	hw_digital_write(CC3K_ERR_LED, 0);

	init_systick();

	__enable_irq();

	usb_init();
	usb_set_speed(USB_SPEED_FULL);
	usb_attach();

	while(!exit_and_jump) {
		led_task();
		__WFI(); /* conserve power */
	}

	delay_ms(25);

	usb_detach();

	delay_ms(100);

	if (dfu_target == TARGET_RAM) {
		jump_to_flash(DFU_DEST_BASE, 0);
	}
}
コード例 #4
0
ファイル: pic18_usb.c プロジェクト: J1M/PSGradePIC
// see usb_hw_layer.h for documentation
void usb_task(void) 
{
   if (usb_attached()) 
   {
      if (UCON_USBEN==0) 
      {
         usb_attach();
      }
   }
   else 
   {
      if (UCON_USBEN==1)  
      {
         usb_detach();
      }
   }

   if ((usb_state == USB_STATE_ATTACHED)&&(!UCON_SE0)) 
   {
      UIR=0;
      UIE=0;
      //enable_interrupts(INT_USB);
      //enable_interrupts(GLOBAL);
      UIE=__USB_UIF_IDLE | __USB_UIF_RESET;  //enable IDLE and RESET USB ISR
      usb_state=USB_STATE_POWERED;
   }
}
コード例 #5
0
ファイル: core.c プロジェクト: PKUCloud/qemu-1.2.2-replay
void usb_port_reset(USBPort *port)
{
    USBDevice *dev = port->dev;

    assert(dev != NULL);
    usb_detach(port);
    usb_attach(port);
    usb_device_reset(dev);
}
コード例 #6
0
ファイル: usb.c プロジェクト: 3a9LL/panda
void usb_reset(USBPort *port)
{
    USBDevice *dev = port->dev;

    assert(dev != NULL);
    usb_detach(port);
    usb_attach(port);
    usb_send_msg(dev, USB_MSG_RESET);
}
コード例 #7
0
ファイル: USBTest.c プロジェクト: Cliveburr/AutoHome
void main(void)
{
   int i;

   set_tris_b(0x10000000);
   
   output_high(PIN_B0);
   delay_ms(500);
   output_low(PIN_B0);
   
   fprintf(A, "rs232 init...\n\r");
   
   usb_init_cs();

   while(1)
   {
      if(input(PIN_B7))
      {
         output_high(PIN_B0);

         usb_task();

         while(input(PIN_B7))
         {
            if (usb_enumerated())
            {
               if (usb_kbhit(1))
               {
                  receive_msg();
                  //usb_get_packet(1, rdata, 1);
               
                  //fprintf(A, "%u", rdata[0]);
                  //switch(rdata[0])
                  //{
                  //   case 0x01: output_high(PIN_B0); break;
                  //   case 0x02: output_low(PIN_B0); break;
                  //}
               }
            }
         }
      
         usb_detach();
         
         output_low(PIN_B0);
      }
   }
}
コード例 #8
0
ファイル: pic18_usb.c プロジェクト: Leboefi/Pinguino-JACSS
// see usb_hw_layer.h for documentation
void usb_task(void) 
{
  #if defined(USB_ISR_POLLING)
   if (interrupt_active(INT_USB))
   {
      usb_isr();
   }
  #endif

   if (usb_attached()) 
   {
      if (UCON_USBEN==0) 
      {
         debug_usb(debug_putc, "\r\n\nUSB TASK: ATTACH");
         usb_attach();
      }
   }
   else 
   {
      if (UCON_USBEN==1)  
      {
         debug_usb(debug_putc, "\r\n\nUSB TASK: DE-ATTACH");
         usb_detach();
      }
   }

   if ((usb_state == USB_STATE_ATTACHED)&&(!UCON_SE0)) 
   {
      UIR=0;
      UIE=0;
     #if !defined(USB_ISR_POLLING)
      enable_interrupts(INT_USB);
      enable_interrupts(GLOBAL);
     #endif
      UIE=__USB_UIF_IDLE | __USB_UIF_RESET;  //enable IDLE and RESET USB ISR
      usb_state=USB_STATE_POWERED;
      debug_usb(debug_putc, "\r\n\nUSB TASK: POWERED");
   }
}
コード例 #9
0
// ****************************************************************************
void HAL_service(void)
{
#ifndef NODEBUG
    #define CANARY 0xcafebabe

    /*
    There is an issue if we initialize the last_found static variable with
    _stacktop at compile time. For some reason it does not contain the proper
    value.
    We therefore initialize it with 0 and check for that. If we enounter 0 we
    load the _stacktop address and everything works well.

    Worst case the program hangs when last_found is not aligned to 4 bytes, as
    a hard fault is raised.
    */

    static uint32_t *last_found;
    uint32_t *now;

    if (last_found == NULL) {
        last_found = (uint32_t *)&_stacktop;
    }

    now = last_found;

    while (*now != CANARY  &&  now > (uint32_t *)&_ram) {
        --now;
    }

    if (now < last_found) {
        last_found = now;
        fprintf(STDOUT_DEBUG, "Stack down to 0x%08x\n", (uint32_t)now);
    }
#endif

    if (start_bootloader) {
        uint32_t end = milliseconds + 50;

        fprintf(STDOUT_DEBUG, "REBOOTING INTO BOOTLOADER\n");

        // Wait a short while ...
        while (milliseconds < end);

        usb_detach();

        // Place a special value into a certain RAM location that is detected
        // by the bootloader, so that it enters firmware upgrade mode
        *magic_value = BOOTLOADER_MAGIC;

        // Disable the interrupts as they are apparently not cleared by a
        // system reset.
        NVIC_DisableIRQ(UART_SERCOM_IRQN);
        NVIC_DisableIRQ(USB_IRQn);
        NVIC_DisableIRQ(TCC0_IRQn);

        NVIC_SystemReset();
    }

    // Status LED handling: Light up if initializing, blink if no signal,
    // otherwise off
    if (global_flags.initializing) {
        HAL_gpio_set(HAL_GPIO_LED);
        HAL_gpio_set(HAL_GPIO_LED2);
    }
    else if (global_flags.no_signal) {
        HAL_gpio_write(HAL_GPIO_LED, global_flags.blink_flag);
        HAL_gpio_write(HAL_GPIO_LED2, global_flags.blink_flag);
    }
    else {
        HAL_gpio_clear(HAL_GPIO_LED);
        HAL_gpio_clear(HAL_GPIO_LED2);
    }


    // If we have data to send via USB serial, and USB serial is available to
    // send, then do it
    if (send_buffer_index) {
        if (!test_interface_is_write_busy()) {
            test_interface_write(send_buffer, send_buffer_index);
            send_buffer_index = 0;
        }
    }
}
コード例 #10
0
ファイル: pic18_usb.c プロジェクト: J1M/PSGradePIC
// see usb_hw_layer.h for documentation
void usb_init_cs(void)
{
   usb_detach();
}