Example #1
0
//------------------------------------------------------------------------------
/// Initializes the USB process
/// Depending on the mode supported (HOST/DEVICE/DUAL_ROLE) the function calls
/// the coresponding USB mode initialization function
//------------------------------------------------------------------------------
void usb_task_init(void)
{
    // DUAL ROLE DEVICE USB MODE
    Otg_message_task_init();       // OTG program needs to display event messages to the user
    b_uut_device_state = B_IDLE;   // init state machines variables
    device_state = DEVICE_UNATTACHED;
    otg_device_nb_hnp_retry = BDEV_HNP_NB_RETRY;
    Clear_all_user_request();
    Usb_enable_uid_pin();

    g_usb_mode=USB_MODE_UNDEFINED;

    if(Is_usb_id_device()) {
        g_usb_mode=USB_MODE_DEVICE;
#ifdef MSD_PROJECT
        MSDDriver_Initialize(luns, numMedias);
#else
        // HID
        HIDDMouseDriver_Initialize();
#endif
        id_changed_to_host_event = DISABLE;
    }
    else {
        Usb_send_event(EVT_USB_HOST_FUNCTION);
        g_usb_mode=USB_MODE_HOST;
        // Startup with ID=0, Ack ID pin transistion (default hwd start up is device mode)
        Usb_ack_id_transition(); 
        Usb_enable_id_interrupt();
        usb_host_task_init();
        id_changed_to_host_event = ENABLE;
    }
    // Store current usb mode, for mode change detection
    g_old_usb_mode = g_usb_mode;
}
Example #2
0
/**
 * \brief usb_massstorage Application entry point.
 *
 * Configures UART,
 * Configures TC0, USB MSD Driver and run it.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main( void )
{
    sSdCard *pSd = 0;
 
    /* Disable watchdog */
    WDT_Disable( WDT ) ;
        
    SCB_EnableICache();
    SCB_EnableDCache();

#if defined LUN_RAMDISK
     /* Enable SDRAM */
    BOARD_ConfigureSdram();
#endif

    TRACE_INFO("-- USB Device Mass Storage Example %s --\n\r", SOFTPACK_VERSION);
    TRACE_INFO("-- %s\n\r", BOARD_NAME);
    TRACE_INFO("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    /* If they are present, configure Vbus & Wake-up pins */
    PIO_InitializeInterrupts(0);

    /* Initialize all USB power (off) */
    _ConfigureUotghs();
    /* Initialize PIO pins */
    _ConfigurePIOs();

    /* Initialize drivers */
    _ConfigureDrivers();

    _MemoriesInitialize(pSd);
    
    /* BOT driver initialization */
    MSDDriver_Initialize(&msdDriverDescriptors, luns, MAX_LUNS);

    /* connect if needed */
    USBD_Connect();
    while (1) {

        /* Mass storage state machine */
        if (USBD_GetState() < USBD_STATE_CONFIGURED){}
        else 
        {
          MSDDriver_StateMachine();
          
          if (msdRefresh)
          {
              msdRefresh = 0;

              if (msdWriteTotal < 50 * 1000)
              {
                  /* Flush Disk Media */
              }
              msdWriteTotal = 0;
          }
        }
    }
}