Ejemplo n.º 1
0
Archivo: Core.cpp Proyecto: Dzenik/Cosa
void 
USBDevice_::attach()
{
  // Configure hardware and phase-locked-loop and enable 
  _usbConfiguration = 0;
  HW_CONFIG();
  USB_FREEZE();
  PLL_CONFIG();

  // Wait for the phase-locked-loop to lock on
  loop_until_bit_is_set(PLLCSR, PLOCK);

  // Give the host some extra time
  delay(1);

  // Start the usb clock and enable interrupt service
  USB_CONFIG();
  UDCON = 0;
  UDINT = 0;
  UDIEN = _BV(EORSTE) | _BV(SOFE) | _BV(SUSPE);

  // Wait for usb device to connect to host
  TX_RX_LED_INIT;
  while (!_usbConfiguration) delay(200);
}
Ejemplo n.º 2
0
bool
USBDevice_::attach()
{
  // Configure hardware and phase-locked-loop and enable 
  _usbConfiguration = 0;
  HW_CONFIG();
  USB_FREEZE();
  PLL_CONFIG();

  // Wait for the phase-locked-loop to lock on
  loop_until_bit_is_set(PLLCSR, PLOCK);

  // Give the host some extra time
  delay(1);

  // Start the usb clock and enable interrupt service
  USB_CONFIG();
  UDCON = 0;
  UDINT = 0;
  UDIEN = _BV(EORSTE) | _BV(SOFE) | _BV(SUSPE);

  // Wait for usb device to connect to host
  TX_RX_LED_INIT;
  for (uint8_t timeout=10;timeout;timeout--) {   // 2 seconds
    if (_usbConfiguration)
      return (true);
    delay(200);
  }

  // Host didn't connect, disable USB, leave powered
  UDIEN = _BV(DETACH);
  USB_UNCONFIG();

  return (false);
}
Ejemplo n.º 3
0
// initialize USB serial
void usb_init(void)
{
	uint8_t u;

	u = USBCON;
	if ((u & (1<<USBE)) && !(u & (1<<FRZCLK))) return;
	HW_CONFIG();
        USB_FREEZE();				// enable USB
        PLL_CONFIG();				// config PLL
        while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
        USB_CONFIG();				// start USB clock
        UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
	usb_suspended = 0;
	keyboard_report_data[0] = 0;
	keyboard_report_data[1] = 0;
	keyboard_report_data[2] = 0;
	keyboard_report_data[3] = 0;
	keyboard_report_data[4] = 0;
	keyboard_report_data[5] = 0;
	keyboard_report_data[6] = 0;
	keyboard_report_data[7] = 0;
	keyboard_protocol = 1;
	keyboard_idle_config = 125;
	keyboard_idle_count = 0;
	keyboard_leds = 0;
	UDINT = 0;
        UDIEN = (1<<EORSTE)|(1<<SOFE);
	//sei();  // init() in wiring.c does this
}
Ejemplo n.º 4
0
// initialize USB
void usb_init(void) {
	HW_CONFIG();
	USB_FREEZE();				// enable USB
	PLL_CONFIG();				// config PLL
        while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
        USB_CONFIG();				// start USB clock
        UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
        UDIEN = (1<<EORSTE)|(1<<SOFE);
	sei();
}
Ejemplo n.º 5
0
/*! \fn     initUsb(void)
*   \brief  USB controller initialization
*/
void initUsb(void)
{
    HW_CONFIG();                    // enable regulator
    USB_FREEZE();                   // enable USB
    PLL_CONFIG();                   // config PLL
    while (!(PLLCSR & (1<<PLOCK))); // wait for PLL lock
    USB_CONFIG();                   // start USB clock
    UDCON = 0x00;                   // enable attach resistor
    usb_configuration = 0;          // usb not configured by default
    UDIEN = (1<<EORSTE)|(1<<SOFE);  // start USB
}
Ejemplo n.º 6
0
// initialize USB
void usb_init(void) {
  HW_CONFIG();
  USB_FREEZE(); // enable USB
  PLL_CONFIG(); // config PLL
  while (!(PLLCSR & (1 << PLOCK))) { ; }
  USB_CONFIG(); // start USB clock
  //	UDCON = (1<<LSM);			// enable attach resistor - Low Speed USB
  UDCON = 0; // enable attach resistor - Full Speed USB
  usb_configuration = 0;

  // enable End-Of-Reset and Start-Of-Frame interrupts
  UDIEN = (1<<EORSTE)|(1<<SOFE);
}
Ejemplo n.º 7
0
// initialize USB
void usb_init(void)
{
	//volatile int dly;
	//for (dly=0; dly<1000; dly++) ;	// delay before attach
	HW_CONFIG();
	USBCON = (1<<USBE) | (1<<FRZCLK);	// enable USB
	PLL_CONFIG();				// config PLL
        while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
        USB_CONFIG();				// start USB clock
        UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
        UDIEN = (1<<EORSTE)|(1<<SOFE);
	sei();
}
Ejemplo n.º 8
0
// initialize USB serial
void usb_init(void)
{
	uint8_t u;

	u = USBCON;
	if ((u & (1<<USBE)) && !(u & (1<<FRZCLK))) return;
	HW_CONFIG();
        USB_FREEZE();				// enable USB
        PLL_CONFIG();				// config PLL
        while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
        USB_CONFIG();				// start USB clock
        UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
	usb_suspended = 0;
	cdc_line_rtsdtr = 0;
	UDINT = 0;
        UDIEN = (1<<EORSTE)|(1<<SOFE)|(1<<SUSPE);
}
Ejemplo n.º 9
0
// initialize USB serial
void usb_init(void)
{
	uint8_t u;

	u = USBCON;
	if ((u & (1<<USBE)) && !(u & (1<<FRZCLK))) return;
	HW_CONFIG();
        USB_FREEZE();				// enable USB
        PLL_CONFIG();				// config PLL
        while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
        USB_CONFIG();				// start USB clock
        UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
	usb_suspended = 0;
	cdc_line_rtsdtr = 0;
        keyboard_report_data[0] = 0;
        keyboard_report_data[1] = 0;
        keyboard_report_data[2] = 0;
        keyboard_report_data[3] = 0;
        keyboard_report_data[4] = 0;
        keyboard_report_data[5] = 0;
        keyboard_report_data[6] = 0;
        keyboard_report_data[7] = 0;
        keyboard_protocol = 1;
        keyboard_idle_config = 125;
        keyboard_idle_count = 0;
        keyboard_leds = 0;
        mouse_buttons = 0;
        mouse_protocol = 1;
        joystick_report_data[0] = 0;
        joystick_report_data[1] = 0;
        joystick_report_data[2] = 0;
        joystick_report_data[3] = 0;
        joystick_report_data[4] =  0x0F;
        joystick_report_data[5] =  0x20;
        joystick_report_data[6] =  0x80;
        joystick_report_data[7] =  0x00;
        joystick_report_data[8] =  0x02;
        joystick_report_data[9] =  0x08;
        joystick_report_data[10] = 0x20;
        joystick_report_data[11] = 0x80;
	UDINT = 0;
        UDIEN = (1<<EORSTE)|(1<<SOFE)|(1<<SUSPE);
}
Ejemplo n.º 10
0
// initialize USB serial
void usb_init(void)
{
	uint8_t u;

	u = USBCON;
	if ((u & (1<<USBE)) && !(u & (1<<FRZCLK))) return;
	HW_CONFIG();
        USB_FREEZE();				// enable USB
        PLL_CONFIG();				// config PLL
        while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
        USB_CONFIG();				// start USB clock
        UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
	usb_suspended = 0;
	debug_flush_timer = 0;
	UDINT = 0;
        UDIEN = (1<<EORSTE)|(1<<SOFE);
	//sei();  // init() in wiring.c does this
}
Ejemplo n.º 11
0
// initialize USB serial
void usb_init(void)
{
	uint8_t u;

	u = USBCON;
	if ((u & (1<<USBE)) && !(u & (1<<FRZCLK))) {
		media_restart();
		return;
	}
	HW_CONFIG();
	USB_FREEZE();				// enable USB
	PLL_CONFIG();				// config PLL
	while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
	USB_CONFIG();				// start USB clock
	UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
	usb_suspended = 0;
	debug_flush_timer = 0;
	keyboard_modifier_keys = 0;
	keyboard_keys[0] = 0;
	keyboard_keys[1] = 0;
	keyboard_keys[2] = 0;
	keyboard_keys[3] = 0;
	keyboard_keys[4] = 0;
	keyboard_keys[5] = 0;
	keyboard_protocol = 1;
	keyboard_idle_config = 125;
	keyboard_idle_count = 0;
	keyboard_leds = 0;
	ms_state = MS_STATE_IDLE;
	media_lock_state = 0;
	UDINT = 0;
	UDIEN = (1<<EORSTE)|(1<<SOFE);
	//sei();  // init() in wiring.c does this
	media_init();
}
Ejemplo n.º 12
0
/*
 * Set-up the main oscillator, PLL0 and CPU clock (if necessary)
 */
static void clock_setup(void)
{
#ifndef CONFIG_LPC178X_SYS_CLK_IRC
	/*
	 * Enable external oscillator and wait for it to become ready
	 */
	LPC178X_SCC->scs |=
#if CONFIG_LPC178X_EXTOSC_RATE > 15000000
		LPC178X_SCC_SCS_OSCRANGE_MSK |
#endif
		LPC178X_SCC_SCS_OSCEN_MSK;
	while (!(LPC178X_SCC->scs & LPC178X_SCC_SCS_OSCSTAT_MSK));

	/*
	 * Switch PLL0 and SYSCLK to the external oscillator.
	 * Only one bit used in CLKSRCSEL register, therefore not using |=
	 */
	LPC178X_SCC->clksrcsel = LPC178X_SCC_CLKSRCSEL_CLKSRC_MSK;
#endif /* !CONFIG_LPC178X_SYS_CLK_IRC */

#ifdef CONFIG_LPC178X_PLL0_ENABLE
	PLL_CONFIG(0);
#endif /* CONFIG_LPC178X_PLL0_ENABLE */

#ifdef CONFIG_LPC178X_PLL1_ENABLE
	/*
	 * PLL1 is necessary for USB
	 */
	PLL_CONFIG(1);
#endif /* CONFIG_LPC178X_PLL1_ENABLE */

	/*
	 * CPU clock
	 */
	LPC178X_SCC->cclksel =
#ifdef CONFIG_LPC178X_PLL0_FOR_CPU
		LPC178X_SCC_CCLKSEL_CCLKSEL_MSK |
#endif
		(CONFIG_LPC178X_CPU_DIV << LPC178X_SCC_CCLKSEL_CCLKDIV_BITS);

	/*
	 * Peripheral clock (used for UARTs, etc)
	 *
	 * Only PCLKDIV bit group used in PCLKSEL, therefore not using |=
	 */
	LPC178X_SCC->pclksel =
		(CONFIG_LPC178X_PCLK_DIV << LPC178X_SCC_PCLKSEL_PCLKDIV_BITS);

#ifdef CONFIG_NR_DRAM_BANKS
	/*
	 * EMC clock
	 */
#ifdef CONFIG_LPC178X_EMC_HALFCPU
	LPC178X_SCC->emcclksel = LPC178X_SCC_EMCCLKSEL_HALFCPU_MSK;
#else /* CONFIG_LPC178X_EMC_HALFCPU */
	LPC178X_SCC->emcclksel = 0;
#endif /* CONFIG_LPC178X_EMC_HALFCPU */
#endif /* CONFIG_NR_DRAM_BANKS */

#ifdef CONFIG_LPC178X_USB_DIV
	/*
	 * USB clock
	 */
	LPC178X_SCC->usbclksel =
		(CONFIG_LPC178X_USB_DIV << LPC178X_SCC_USBCLKSEL_USBDIV_BITS) |
		LPC178X_SCC_USBCLKSEL_USBSEL_PLL1_MSK;
#endif /* CONFIG_LPC178X_USB_DIV */
}