Esempio n. 1
0
// Start PLL and enable clock
void
UsbStartPLL(void)
{
  UsbSetPLL_XTAL_Frequency();
  UsbEnablePLL();
  UsbWaitPLL_Locked();
  UsbEnableClock();
}
void hcdi_init()
{ 
 /* register virtual root hub driver */
  usb_register_driver(&at90usb1287_roothub);

  /* enable regulator */
  UHWCON |= (1<<UVREGE); 
  /* force host mode */
  UHWCON &= ~(1<<UIDE);
  UHWCON &= ~(1<<UIMOD);

  /* pll sart */
  UsbSetPLL_CPU_Frequency();
  UsbEnablePLL();
  UsbWaitPLL_Locked();

  /* Usb_disable */
  USBCON &= ~(1<<USBE);
  
  /* Usb_enable */
  USBCON |= (1<<USBE);
  
  /* unfreeze clock */
  UsbEnableClock();

  /* usb attach */
  UDCON   &= ~(1<<DETACH);

  /* enable uconv pin */
  UsbDisableUVCON_PinControl();
  UsbEnableUID_ModeSelection();

  /* select host */
  USBCON  |=  (1<<HOST);

  /* disable vbus hw control */
  OTGCON  |=  (1<<VBUSHWC);

  // 4
  /* enable vbus */
  OTGCON  |=  (1<<VBUSREQ);
  
  UHIEN |= (1<<DDISCE);
  UHIEN |= (1<<DCONNE);

  UHIEN = 0xff;
 
 }
/**
 * This function is called periodical, to notice
 * port changes after an hub
 */
void at90usb1287_roothub_check()
{
  //USART_WriteHex(UHINT);
  //UHINT = 0x00;
  // disconnect 
  if(UHINT & 0x02) {
    device_on_downstream=NULL;
    #if DEBUG
    core.stdout("Device: Removed!\r\n");
    #endif
    //UHINT &= ~(1<<DDISCI);
  } else {
    // if connect 
    if(device_on_downstream!=NULL) {
      // normal transfer check for interrupt and isochonous endpoints
      //USART_WriteHex(0x88);
    } 
    // check if device is connected 
    else {
      if(UHINT & 0x01) {
	// found new device
	#if DEBUG
	core.stdout("Device: Found new one!\r\n");
	#endif

	if((USBSTA &   (1<<SPEED)) &&(USBSTA &   (1<<SPEED))){
	  // fullspeed
	  #if DEBUG
	  core.stdout("FS\r\n");
	  #endif
	} else {
	  //lowspeed
	  #if DEBUG
	  core.stdout("LS\r\n");
	  #endif
	  // mark device as low speed
	}
	
	//UHCON = (1<<SOFEN); /* host generate for FS SOF, and for LS keep-alive! */
	//UHCON = (1<<RESET);

	// SOF on etx
	device_on_downstream = 1;	
	//device_on_downstream = usb_add_device();	
	//UHINT &= ~(1<<DCONNI);
      }
      else {
	// wenn geraet nicht aktiviert ist das immer aufrufen! 
      //USART_WriteHex(0x55);
      }
    }
  }
  UHINT = 0x00;
	/* Usb_disable */
	USBCON &= ~(1<<USBE);
	/* Usb_enable */
	USBCON |= (1<<USBE);
	/* unfreeze clock */
	UsbEnableClock();
	/* usb attach */
	UDCON   &= ~(1<<DETACH);
	/* select host */
	USBCON  |=  (1<<HOST);
	/* disable vbus hw control */
	OTGCON  |=  (1<<VBUSHWC);
	/* enable vbus */
	OTGCON  |=  (1<<VBUSREQ);

 }