/*FUNCTION*---------------------------------------------------------------- * * Function Name : DriveShutdown * Returned Value : SUCCESS or ERROR * - SUCCESS * - ERROR_DDI_LDL_LDRIVE_INVALID_DRIVE_NUMBER * - ERROR_DDI_LDL_LDRIVE_NOT_INITIALIZED * - Other errors from shutdown API * Comments : * DriveFlush and if allowed shutdown the logical data drive. * *END*--------------------------------------------------------------------*/ RtStatus_t DriveShutdown ( /* [IN] Unique drive tag */ DriveTag_t tag ) { /* Body */ /* Flush the drive before shutting down. */ RtStatus_t RetValue = DriveFlush(tag); if (RetValue != SUCCESS) { return RetValue; } /* Endif */ /* Look up the drive by tag and perform sanity checks. */ LogicalDrive * drive = DriveGetDriveFromTag(tag); if (!drive) { return ERROR_DDI_LDL_LDRIVE_INVALID_DRIVE_NUMBER; } else if (!drive->isInitialized() ) { return ERROR_DDI_LDL_LDRIVE_NOT_INITIALIZED; } /* Endif */ /* Invoke the API. */ return drive->shutdown(); } /* Endbody */
void _reentrant USBInsertionMonitorTask(void) { USHORT usStatus; BOOL bInserted = FALSE; WORD i,j; WORD iWaitCount; // Check for USB disconnect while(1) { usb_device_get_status(USB_STATUS_CONNECTION,&usStatus); switch(usStatus) { case USB_CONNECTED: bInserted=TRUE; break; default: if(bInserted)//if we've been inserted, and now we're not, lets shut down { // #ifdef DEVICE_3410 // 3410 still has power when removed from usb. #ifdef CHKDSK UsbMscCheckDiskAll(); #endif // #endif // TODO - put this back in later if needed // Clear the display // ClearDisplay(); // We need to immediately pull Write Protect low to protect the NANDs and // to reset the Renesas part (same line). HW_GPFLASH_CSR1R.B.WP0 = 0; // We need to clean up any media transactions that may be hanging // As best we can :) // stmp4770 and stmp4795, Remove drive flush on USB disconnect for NAND devices. // Drive flush still necessary for MMC media, to properly close multi-writes // that may be pending between SCSI commands. for(i=0;i<g_wUsbMscNumDevices;i++) { for(j=0;j<UsbMscDevice[i].wNumLunsSupported;j++) { if(UsbMscDevice[i].Lun[j].bMediaIsRemovable == TRUE) { DriveFlush(UsbMscDevice[i].Lun[j].wFileSystemDriveNumber); } } } //Do not leave. Wait for 5V to be removed. //Monitor D+/- and reset if it returns. HW_USBCSR.B.PLUGGEDIN_EN = 1; iWaitCount = 0; //ensure 5V Disconnect IRQ is enabled SysSetIrqLevel(HW_SR_IM_L2_SETMASK); while(HW_USBCSR.B.VBUSSENSE) { //if USB is plugged-in. Break loop and reset to return to USBMSC. if(HW_USBCSR.B.PLUGGEDIN) { break; } //wait a bit SysWait(200); if(iWaitCount > 10) { break; // if we waited a couple secs, time to break } else { iWaitCount++; //increment wait count } } SysWait(200); // Shut down SystemShutdown(); // Reset the device SystemReset(); } } SysWait(USB_WATCH_CALL_BACK_DELAY); } }