コード例 #1
0
ファイル: usbb_device.c プロジェクト: 12019/USB-Rubber-Ducky
void udd_enable(void)
{
	irqflags_t flags;
	sysclk_enable_usb();

	flags = cpu_irq_save();

	//** Enable USB hardware
	otg_disable();
	(void)Is_otg_enabled();
#ifdef OTG
	// Check UID pin state before enter in USB device mode
	if (!Is_otg_id_device())
		return FALSE;
#else
	// Here, only the Device mode is possible, then link USBB interrupt to UDD interrupt
	irq_register_handler(udd_interrupt, AVR32_USBB_IRQ, UDD_USB_INT_LEVEL);
	otg_force_device_mode();
#endif
	otg_disable_pad();
	otg_enable_pad();
	otg_enable();
	otg_unfreeze_clock();
	(void)Is_otg_clock_frozen();
#if UC3A3
	// For parts with high speed feature, the "USABLE" clock is the UTMI clock,
	// and the UTMI clock is disabled in suspend mode. Thereby, the utmi clock
	// can't be checked when USB line is not attached or in suspend mode 
#else
	// Check USB clock
	while( !Is_clock_usable() );
#endif

	// Reset internal variables
#if (0!=USB_DEVICE_MAX_EP)
	udd_ep_job_table_reset();
#endif

	// Set the USB speed requested by configuration file
#ifdef USB_DEVICE_LOW_SPEED
	udd_low_speed_enable();
#else
	udd_low_speed_disable();
#  ifdef USB_DEVICE_HS_SUPPORT
	udd_high_speed_enable();
#  else
	udd_high_speed_disable();
#  endif
#endif
	udd_enable_vbus_interrupt();
	otg_freeze_clock();
	// Always authorize asynchrone USB interrupts to exit of sleep mode
	AVR32_PM.AWEN.usb_waken = 1;

#ifndef UDD_NO_SLEEP_MGR
	// Initialize the sleep mode authorized for the USB suspend mode
	udd_b_idle = false;
	sleepmgr_lock_mode(USBB_SLEEP_MODE_USB_SUSPEND);
#endif

	cpu_irq_restore(flags);
}
コード例 #2
0
void udd_enable(void)
{
	irqflags_t flags;
	sysclk_enable_usb();

	flags = cpu_irq_save();

	//** Enable USB hardware
	otg_disable();
	(void)Is_otg_enabled();
#ifdef OTG
	// Check UID pin state before enter in USB device mode
	if (!Is_otg_id_device())
#warning returning bool but the function is void
		return FALSE;
#else
	// Here, only the Device mode is possible, then link USBC interrupt to UDD interrupt
	irq_register_handler(udd_interrupt, AVR32_USBC_IRQ, UDD_USB_INT_LEVEL);
	otg_force_device_mode();
#endif
	otg_disable_pad();
	otg_enable_pad();
	otg_enable();
	otg_unfreeze_clock();
	(void)Is_otg_clock_frozen();
#if 0
	// For parts with high speed feature, the "USABLE" clock is the UTMI clock,
	// and the UTMI clock is disabled in suspend mode. Thereby, the utmi clock
	// can't be checked when USB line is not attached or in suspend mode 
#else
	// Check USB clock
	while( !Is_clock_usable() );
#endif
	memset((uint8_t *) udd_g_ep_table, 0, sizeof(udd_g_ep_table));
	Usb_set_desc_tab_addr_reg(udd_g_ep_table);

	// Reset internal variables
#if (0!=USB_DEVICE_MAX_EP)
	{
		uint8_t i;
		for (i = 0; i < USB_DEVICE_MAX_EP; i++) {
			udd_ep_job[i].busy = false;
		}
	}
#endif

	// Set the USB speed requested by configuration file
#ifdef USB_DEVICE_LOW_SPEED
	udd_low_speed_enable();
#else
	udd_low_speed_disable();
#endif
#  ifdef USB_DEVICE_HS_SUPPORT
	udd_high_speed_enable();
#  else
	udd_high_speed_disable();
#  endif
	udd_enable_vbus_interrupt();
	otg_freeze_clock();
   // Always authorize asynchronous USB interrupts to exit from sleep mode
#if(!defined AVR32_PM_WITHOUT_AWEN)
	AVR32_PM.awen |= AVR32_PM_AWEN_USBCWEN_MASK;
#endif

#ifndef UDD_NO_SLEEP_MGR
	// Initialize the sleep mode authorized for the USB suspend mode
	udd_b_idle = false;
	sleepmgr_lock_mode(USBC_SLEEP_MODE_USB_SUSPEND);
#endif

	cpu_irq_restore(flags);
}