Esempio n. 1
0
void usb_task(void)
{
// ---- DUAL-ROLE DEVICE/HOST USB MODE -----------------------------------------
  #if USB_DEVICE_FEATURE == true && USB_HOST_FEATURE == true
  // Depending on current USB mode, launch the correct USB task (device or host)
  switch (g_usb_mode)
  {
  case USB_MODE_DEVICE:
    usb_device_task();
    break;
  case USB_MODE_HOST:
    usb_host_task();
    break;
  case USB_MODE_UNDEFINED:
  default:
    break;
  }
// -----------------------------------------------------------------------------

// ---- DEVICE-ONLY USB MODE ---------------------------------------------------
  #elif USB_DEVICE_FEATURE == true
  usb_device_task();
// -----------------------------------------------------------------------------

// ---- REDUCED-HOST-ONLY USB MODE ---------------------------------------------
  #elif USB_HOST_FEATURE == true
  usb_host_task();
// -----------------------------------------------------------------------------

// ---- ERROR, NO MODE ENABLED -------------------------------------------------
  #else
  #endif
// -----------------------------------------------------------------------------
}
Esempio n. 2
0
/**
 *  @brief Entry point of the USB mamnagement
 *
 *  Depending on the USB mode supported (HOST/DEVICE/DUAL_ROLE) the function
 *  calls the coresponding usb management function.
 *
 *  @param none
 *
 *  @return none
*/
void usb_task(void)
{
// ---- DUAL ROLE DEVICE USB MODE ---------------------------------------------
#if ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == ENABLED))
   if(Is_usb_id_device())
   { g_usb_mode=USB_MODE_DEVICE;}
   else
   { g_usb_mode=USB_MODE_HOST;}
  // TODO !!! ID pin hot state change
  // Preliminary management: HARDWARE RESET !!!
   #if ( ID_PIN_CHANGE_GENERATE_RESET == ENABLE)
     // Hot ID transition generates wdt reset
      if((g_old_usb_mode!=g_usb_mode))
      #ifndef  AVRGCC
         {Wdt_change_16ms(); while(1);   LOG_STR_CODE(log_id_change);}
      #else
         {Wdt_change_enable(); while(1); LOG_STR_CODE(log_id_change);}
      #endif

   #endif
  g_old_usb_mode=g_usb_mode;   // Store current usb mode, for mode change detection
  // Depending on current usb mode, launch the correct usb task (device or host)
   switch(g_usb_mode)
   {
      case USB_MODE_DEVICE:
         usb_device_task();
         break;
      case USB_MODE_HOST:
         usb_host_task();
         break;
      case USB_MODE_UNDEFINED:  // No break !
      default:
         break;
  }
// -----------------------------------------------------------------------------

// ---- DEVICE ONLY USB MODE ---------------------------------------------------
#elif ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == DISABLE))
   usb_device_task();
// -----------------------------------------------------------------------------

// ---- REDUCED HOST ONLY USB MODE ---------------------------------------------
#elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == ENABLED))
   usb_host_task();
// -----------------------------------------------------------------------------

//! ---- ERROR, NO MODE ENABLED -------------------------------------------------
#elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == DISABLE))
   #error  at least one of USB_DEVICE_FEATURE or USB_HOST_FEATURE should be enabled
   #error  otherwise the usb task has nothing to do ...
#endif
// -----------------------------------------------------------------------------

}
Esempio n. 3
0
void usb_task(void)
{
// ---- DUAL-ROLE DEVICE/HOST USB MODE -----------------------------------------
  #if USB_DEVICE_FEATURE == true && USB_HOST_FEATURE == true
    if (g_old_usb_mode != g_usb_mode)
    {
      if (Is_usb_id_device())
    {
      usb_device_task_init();
    }else{
      private_sof_counter = 0;
      usb_host_task_init();
    }
      g_old_usb_mode = g_usb_mode;  // Store current USB mode, for mode change detection
      Usb_enable_id_interrupt();
      Enable_global_interrupt();
    }

  // Depending on current USB mode, launch the correct USB task (device or host)
  switch (g_old_usb_mode)
  {
  case USB_MODE_DEVICE:
    usb_device_task();
    break;
  case USB_MODE_HOST:
    usb_host_task();
    break;
  case USB_MODE_UNDEFINED:
  default:
    break;
  }
// -----------------------------------------------------------------------------

// ---- DEVICE-ONLY USB MODE ---------------------------------------------------
  #elif USB_DEVICE_FEATURE == true
  usb_device_task();
// -----------------------------------------------------------------------------

// ---- REDUCED-HOST-ONLY USB MODE ---------------------------------------------
  #elif USB_HOST_FEATURE == true
  usb_host_task();
// -----------------------------------------------------------------------------

// ---- ERROR, NO MODE true -------------------------------------------------
  #else
    #error At least one of USB_DEVICE_FEATURE and USB_HOST_FEATURE must be enabled
  #endif
// -----------------------------------------------------------------------------
}
Esempio n. 4
0
void cdc_receiving(void) {		// return: Anzahl empfangener Bytes im Fifo
  int bytes_rx, bytes_left;
#if USB_DEVICE_FEATURE == ENABLED && USB_HOST_FEATURE == ENABLED
   usb_task();
#elif USB_DEVICE_FEATURE == ENABLED
   usb_device_task();
#elif USB_HOST_FEATURE == ENABLED
   usb_host_task();
#endif
  if ( usb_connected && Is_usb_out_received(RX_EP) ) {
    bytes_rx = Usb_byte_count(RX_EP);
    if ((bytes_rx > 0)&&(bytes_rx < cdc_rxleft)) {
      bytes_left = CDC_RXBUFFERSIZE-cdc_wrpos;
      Usb_reset_endpoint_fifo_access(RX_EP);
      if (bytes_rx <= bytes_left) {	// Normalfall: kein Wrap
        usb_read_ep_rxpacket(RX_EP, (void *)cdc_rxbuffer+cdc_wrpos, bytes_rx, NULL);
      } else {
        usb_read_ep_rxpacket(RX_EP, (void *)cdc_rxbuffer+cdc_wrpos, bytes_left, NULL);
        usb_read_ep_rxpacket(RX_EP, (void *)cdc_rxbuffer, bytes_rx-bytes_left, NULL);
      }
      cdc_wrpos = (cdc_wrpos+bytes_rx)%CDC_RXBUFFERSIZE;
      // End copy in own fifo
      cdc_rxidle_pos = cdc_sof_counter + cdc_timeoutval;
      cdc_timeout_enabled = (cdc_timeoutval>0)&&(cdc_timeout_fct!=NULL);
    } // fi copy received
    Usb_ack_out_received_free(RX_EP);	// moved outside of if-con
  } else if (cdc_timeout_enabled) {
    if ((int)(cdc_sof_counter - cdc_rxidle_pos) >= 0) {
      cdc_timeout_fct(cdc_rxlen);
      cdc_timeout_enabled = FALSE;
    }
  } // esle fi to
  // chain-tx (>64 byte):
  if (cdc_txbuffer_len > 0) {
    cdc_transmit(cdc_txbuffer, cdc_txbuffer_len);
  } // fi
}
Esempio n. 5
0
/**
 *  @brief Entry point of the USB mamnagement
 *
 *  Depending on the USB mode supported (HOST/DEVICE/DUAL_ROLE) the function
 *  calls the coresponding usb management function.
 *
 *  @param none
 *
 *  @return none
*/
void usb_task(void)
{
// ---- DUAL ROLE DEVICE USB MODE ---------------------------------------------
#if ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == ENABLED))
   if(Is_usb_id_device())
   { g_usb_mode=USB_MODE_DEVICE;}
   else
   { g_usb_mode=USB_MODE_HOST;}

   if( g_old_usb_mode != g_usb_mode )
   {
      // ID pin hot state change
#if ( ID_PIN_CHANGE_GENERATE_RESET == ENABLE)
      // Hot ID transition generates wdt reset
      wdtdrv_enable(WDTO_16MS);
      while(1);
#else
      // Hot ID transition reset USB mode      
      Usb_ack_id_transition(); // REQUIRED
      if (Is_usb_id_host())
      {
         Usb_disable_resume_interrupt();
         Usb_disable_wake_up_interrupt();
         Usb_disable_suspend_interrupt();
         Usb_disable_reset_interrupt();
         Usb_detach();
         Usb_disable();
         usb_host_task_init();
      }
      else
      { 
         Host_disable_device_disconnection_interrupt();
         Host_disable_sof_interrupt();
         Host_disable_sof();
         Usb_disable_vbus();
         Usb_disable_manual_vbus();
         Usb_freeze_clock();
         Usb_disable();
         usb_device_task_init();
      }
#endif
   }
   
   // Store current usb mode, for mode change detection
   g_old_usb_mode=g_usb_mode;

   // Depending on current usb mode, launch the correct usb task (device or host)
   switch(g_usb_mode)
   {
      case USB_MODE_DEVICE:
      usb_device_task();
      break;
      
      case USB_MODE_HOST:
      usb_host_task();
      break;
      
      case USB_MODE_UNDEFINED:  // No break !
      default:
      break;
  }
// -----------------------------------------------------------------------------

// ---- DEVICE ONLY USB MODE ---------------------------------------------------
#elif ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == DISABLE))
   usb_device_task();
// -----------------------------------------------------------------------------

// ---- REDUCED HOST ONLY USB MODE ---------------------------------------------
#elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == ENABLED))
   usb_host_task();
// -----------------------------------------------------------------------------

//! ---- ERROR, NO MODE ENABLED -------------------------------------------------
#elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == DISABLE))
   #error  at least one of USB_DEVICE_FEATURE or USB_HOST_FEATURE should be enabled
   #error  otherwise the usb task has nothing to do ...
#endif
// -----------------------------------------------------------------------------

}