int unmount_sdcard() { _mqx_uint param; _mqx_int error_code; boolean readonly = FALSE; char filesystem_name[] = "a:"; char partman_name[] = "pm:"; printf("unmounte sd card +\n"); _lwsem_wait(&SD_MFS_IO_SEM); if( ! sd_mounted) { _lwsem_post(&SD_MFS_IO_SEM); return 0; } /* Close the filesystem */ if (MQX_OK != fclose (filesystem_handle)) { printf("Error closing filesystem.\n"); _task_block(); } filesystem_handle = NULL; /* Uninstall MFS */ error_code = _io_dev_uninstall(filesystem_name); if (error_code != MFS_NO_ERROR) { printf("Error uninstalling filesystem.\n"); _task_block(); } /* Close partition manager */ if (MQX_OK != fclose (partman_handle)) { printf("Unable to close partition manager.\n"); _task_block(); } partman_handle = NULL; /* Uninstall partition manager */ error_code = _io_dev_uninstall(partman_name); if (error_code != MFS_NO_ERROR) { printf("Error uninstalling partition manager.\n"); _task_block(); } /* Close the SD card device */ if (MQX_OK != fclose (sdcard_handle)) { printf("Unable to close SD card device.\n"); _task_block(); } sdcard_handle = NULL; sd_mounted = 0; printf("unmounted sd card -\n"); _lwsem_post(&SD_MFS_IO_SEM); return 0; }
/*TASK*----------------------------------------------------------------- * * Function Name : sdcard_task * Returned Value : void * Comments : * *END------------------------------------------------------------------*/ void sdcard_task(uint_32 temp) { boolean inserted = TRUE, readonly = FALSE, last = FALSE; _mqx_int error_code; _mqx_uint param; MQX_FILE_PTR com_handle, sdcard_handle, filesystem_handle, partman_handle; char filesystem_name[] = "a:";// 文件系统 名字 char partman_name[] = "pm:";// 分区管理 名字 #if defined BSP_SDCARD_GPIO_DETECT #if ! BSP_SDCARD_GPIO_DETECT_INT LWGPIO_STRUCT sd_detect; #else LWGPIO_STRUCT sd_detect; /************************dx 20121210********************************************** */ GPIO_PIN_STRUCT sd_detect_int[] = { BSP_SDCARD_GPIO_DETECT | GPIO_PIN_IRQ_FALLING | GPIO_PIN_IRQ_RISING, GPIO_LIST_END }; MQX_FILE_PTR port_file_sd_detect_int; /***********************************************************************************/ #endif #endif #if defined BSP_SDCARD_GPIO_PROTECT LWGPIO_STRUCT sd_protect; #endif #ifdef BSP_SDCARD_GPIO_CS LWGPIO_STRUCT sd_cs; SPI_CS_CALLBACK_STRUCT callback; #endif /* Open low level communication device */ com_handle = fopen (SDCARD_COM_CHANNEL, NULL);// 打开"esdhc:"模块底层驱动 if (NULL == com_handle) { printf("Error installing communication handle.\n"); _task_block(); } #ifdef BSP_SDCARD_GPIO_CS /* Open GPIO file for SPI CS signal emulation */ error_code = lwgpio_init(&sd_cs, BSP_SDCARD_GPIO_CS, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE);// 安装简单引脚用于spi片选 if (!error_code) { printf("Initializing GPIO with associated pins failed.\n"); _task_block(); } lwgpio_set_functionality(&sd_cs,BSP_SDCARD_CS_MUX_GPIO); lwgpio_set_attribute(&sd_cs, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); /* Set CS callback */ callback.MASK = BSP_SDCARD_SPI_CS; callback.CALLBACK = set_CS; callback.USERDATA = &sd_cs; if (SPI_OK != ioctl (com_handle, IO_IOCTL_SPI_SET_CS_CALLBACK, &callback)) { printf ("Setting CS callback failed.\n"); _task_block(); } #endif #if defined BSP_SDCARD_GPIO_DETECT #if ! BSP_SDCARD_GPIO_DETECT_INT /* Init GPIO pins for other SD card signals */ error_code = lwgpio_init(&sd_detect, BSP_SDCARD_GPIO_DETECT, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);// 安装简单引脚用于插入检测 if (!error_code) { printf("Initializing GPIO with sdcard detect pin failed.\n"); _task_block(); } /*Set detect and protect pins as GPIO Function */ lwgpio_set_functionality(&sd_detect,BSP_SDCARD_DETECT_MUX_GPIO); lwgpio_set_attribute(&sd_detect, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #else /******************dx 20121210***********************************************/ if (NULL == (port_file_sd_detect_int = fopen("gpio:read", (char_ptr) &sd_detect_int ))) { printf("Opening port_file_sd_detect_int GPIO with associated button1_int failed.\n"); _task_block(); } ioctl(port_file_sd_detect_int, GPIO_IOCTL_SET_IRQ_FUNCTION, (pointer)sd_detect_int__callback); _lwevent_create(&SD_Event,0); // 创建轻量级事件用于检测SD插入 /****************************************************************************/ #endif #endif #if defined BSP_SDCARD_GPIO_PROTECT /* Init GPIO pins for other SD card signals */ error_code = lwgpio_init(&sd_protect, BSP_SDCARD_GPIO_PROTECT, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);// 安装简单引脚用于只读检测 if (!error_code) { printf("Initializing GPIO with sdcard protect pin failed.\n"); _task_block(); } /*Set detect and protect pins as GPIO Function */ lwgpio_set_functionality(&sd_protect,BSP_SDCARD_PROTECT_MUX_GPIO); lwgpio_set_attribute(&sd_protect, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #endif /* Install SD card device */ error_code = _io_sdcard_install("sdcard:", (pointer)&_bsp_sdcard0_init, com_handle);// 安装SD卡驱动,基于"esdhc:"模块 if ( error_code != MQX_OK ) { printf("Error installing SD card device (0x%x)\n", error_code); _task_block(); } /*使用内部IOCTL命令测试SD卡是否已经插入 dx20121223*/ uint_32 sd_param; sd_param = 0; if (ESDHC_OK != ioctl (com_handle, IO_IOCTL_ESDHC_GET_CARD, &sd_param)) { printf("Error get SD card device type.\n"); _task_block(); } if (ESDHC_CARD_NONE != sd_param) { inserted = TRUE; // 已插入SD卡 printf("inserted = 1 -> %d\n",(int)sd_param); }else { inserted = FALSE; // 无SD卡 printf("inserted = 0 -> %d\n",(int)sd_param); } for (;;)/////////////////////////////////////////////////////////////////////////////循环 { #if defined BSP_SDCARD_GPIO_PROTECT /* Get value of protect pin */ readonly = lwgpio_get_value(&sd_protect);// 检测磁盘是否只读//////////////////////////////////////// #endif #ifdef BSP_MPC8308RDB /* Set function as SD_CD which indicate that card is present in Present State Register */ lwgpio_set_functionality(&sd_detect,BSP_SDCARD_DETECT_MUX_SD_CD); lwgpio_set_attribute(&sd_detect, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #endif if (last != inserted) { if (inserted)// 插入磁盘 { // _time_delay (200);// 将活动的任务挂起指定的毫秒数 /* Open the device which MFS will be installed on */ sdcard_handle = fopen("sdcard:", 0);// 打开SD卡层驱动 if ( sdcard_handle == NULL ) { printf("Unable to open SD card device.\n"); _task_block(); } /* Set read only flag as needed */ param = 0; if (readonly) { param = IO_O_RDONLY; } if (IO_OK != ioctl(sdcard_handle, IO_IOCTL_SET_FLAGS, (char_ptr) ¶m)) { printf("Setting device read only failed.\n"); _task_block(); } /* Install partition manager over SD card driver */ error_code = _io_part_mgr_install(sdcard_handle, partman_name, 0);// 分区管理 if (error_code != MFS_NO_ERROR) { printf("Error installing partition manager: %s\n", MFS_Error_text((uint_32)error_code)); _task_block(); } /* Open partition manager */ partman_handle = fopen(partman_name, NULL);// 打开分区 if (partman_handle == NULL) { error_code = ferror(partman_handle); printf("Error opening partition manager: %s\n", MFS_Error_text((uint_32)error_code)); _task_block(); } /* Validate partition 1 */ param = 1; error_code = _io_ioctl(partman_handle, IO_IOCTL_VAL_PART, ¶m);// 控制分区 if (error_code == MQX_OK) { /* Install MFS over partition 1 */ error_code = _io_mfs_install(partman_handle, filesystem_name, param);/////安装文件系统,基于分区 if (error_code != MFS_NO_ERROR) { printf("Error initializing MFS over partition: %s\n", MFS_Error_text((uint_32)error_code)); _task_block(); } } else { /* Install MFS over SD card driver */ error_code = _io_mfs_install(sdcard_handle, filesystem_name, (_file_size)0);////////安装文件系统,无分区 if (error_code != MFS_NO_ERROR) { printf("Error initializing MFS: %s\n", MFS_Error_text((uint_32)error_code)); _task_block(); } } /* Open file system */ filesystem_handle = fopen(filesystem_name, NULL);// 打开文件系统 error_code = ferror (filesystem_handle); if ((error_code != MFS_NO_ERROR) && (error_code != MFS_NOT_A_DOS_DISK)) { printf("Error opening filesystem: %s\n", MFS_Error_text((uint_32)error_code)); _task_block(); } if ( error_code == MFS_NOT_A_DOS_DISK ) { printf("NOT A DOS DISK! You must format to continue.\n"); } printf ("SD card installed to %s\n", filesystem_name); if (readonly) { printf ("SD card is locked (read only).\n"); } } else // 拔出磁盘 { /* Close the filesystem */ if (MQX_OK != fclose (filesystem_handle)) { printf("Error closing filesystem.\n"); _task_block(); } filesystem_handle = NULL; /* Uninstall MFS */ error_code = _io_dev_uninstall(filesystem_name); if (error_code != MFS_NO_ERROR) { printf("Error uninstalling filesystem.\n"); _task_block(); } /* Close partition manager */ if (MQX_OK != fclose (partman_handle)) { printf("Unable to close partition manager.\n"); _task_block(); } partman_handle = NULL; /* Uninstall partition manager */ error_code = _io_dev_uninstall(partman_name); if (error_code != MFS_NO_ERROR) { printf("Error uninstalling partition manager.\n"); _task_block(); } /* Close the SD card device */ if (MQX_OK != fclose (sdcard_handle)) { printf("Unable to close SD card device.\n"); _task_block(); } sdcard_handle = NULL; printf ("SD card uninstalled.\n"); printf ("sd unOK dx.\n");/////////////////////////dx } } last = inserted; // _time_delay (200);// 将活动的任务挂起指定的毫秒数 // #if defined BSP_SDCARD_GPIO_DETECT // #if BSP_SDCARD_GPIO_DETECT_INT // /****************dx 20121211************************************************************/ // _lwevent_wait_ticks(&SD_Event,SD_EVENT_DETECT,FALSE,0);///////////等待事件USB_EVENT // _lwevent_clear(&SD_Event,SD_EVENT_DETECT); // /****************************************************************************************/ // #endif // #endif /*使用SD外部端口测试SD卡是否已经插入*/ #if defined BSP_SDCARD_GPIO_DETECT #ifdef BSP_MPC8308RDB /* Set function as GPIO to detect sdcard */ lwgpio_set_functionality(&sd_detect,BSP_SDCARD_DETECT_MUX_GPIO); lwgpio_set_attribute(&sd_detect, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #endif #if ! BSP_SDCARD_GPIO_DETECT_INT inserted = !lwgpio_get_value(&sd_detect);// 检测磁盘是否插入///////////////////////////////////////// #else /****************dx 20121211************************************************************/ _lwevent_wait_ticks(&SD_Event,SD_EVENT_DETECT,FALSE,0);///////////等待事件USB_EVENT _lwevent_clear(&SD_Event,SD_EVENT_DETECT); ioctl(port_file_sd_detect_int, GPIO_IOCTL_READ, (char_ptr) &sd_detect_int); inserted = !( sd_detect_int[0] & GPIO_PIN_STATUS); /****************************************************************************************/ #endif #endif }/////////////////////////////////////////////////////////////////////////////循环 }
void usb_filesystem_uninstall( USB_FILESYSTEM_STRUCT_PTR usb_fs_ptr) { int_32 error_code; uint_32 mfs_status; if (usb_fs_ptr == NULL) { return; } _int_disable(); printf("\nDevice removed, starting device cleanup"); printf("\n--->Closing MFS"); if (usb_fs_ptr->FS_FD_PTR) { error_code = fclose(usb_fs_ptr->FS_FD_PTR); if ( error_code != IO_OK ) { printf("\nError closing MFS device: 0x%X.", error_code); } } printf("\n--->Uninstalling %s",usb_fs_ptr->FS_NAME); if (usb_fs_ptr->FS_NAME) { mfs_status = _io_mfs_uninstall(usb_fs_ptr->FS_NAME); if ((mfs_status != MFS_NO_ERROR) && (mfs_status !=IO_DEVICE_DOES_NOT_EXIST)) { printf("\nError while uninstalling MFS on device"); } } if (usb_fs_ptr->PM_FD_PTR != NULL) { /* Close partition device */ printf("\n--->Closing partition"); error_code = fclose(usb_fs_ptr->PM_FD_PTR); if ( error_code != IO_OK ) { printf("\nError closing Partition device %s: 0x%X.", usb_fs_ptr->PM_NAME, error_code); } } if (usb_fs_ptr->PM_NAME) { /* Uninstall the partition manager */ printf("\n--->Uninstalling PM"); error_code = _io_part_mgr_uninstall(usb_fs_ptr->PM_NAME); if (( error_code != IO_OK ) && (mfs_status !=IO_DEVICE_DOES_NOT_EXIST)) { printf("\nError uninstalling Partition device %s: 0x%X.", usb_fs_ptr->PM_NAME, error_code); } } /* USB mass storage link device */ if (usb_fs_ptr->DEV_FD_PTR) { printf("\n--->Closing disk"); error_code = fclose(usb_fs_ptr->DEV_FD_PTR); if ( error_code != IO_OK ) { printf("\nError closing disk (0x%X)", error_code); } } _int_enable(); if (usb_fs_ptr->DEV_NAME) { printf("\n--->Closing USB MFS"); _io_dev_uninstall(usb_fs_ptr->DEV_NAME); } _mem_free(usb_fs_ptr); }
/*TASK*----------------------------------------------------------------- * * Function Name : sdcard_task * Returned Value : void * Comments : * *END------------------------------------------------------------------*/ void sdcard_task(uint_32 temp) { boolean inserted = TRUE, readonly = FALSE, last = FALSE; _mqx_int error_code; _mqx_uint param; MQX_FILE_PTR com_handle, sdcard_handle, filesystem_handle, partition_handle; char filesystem_name[] = "a:"; char partman_name[] = "pm:"; char partition_name[] = "pm:1"; #if defined BSP_SDCARD_GPIO_DETECT LWGPIO_STRUCT sd_detect; #endif #if defined BSP_SDCARD_GPIO_PROTECT LWGPIO_STRUCT sd_protect; #endif #ifdef BSP_SDCARD_GPIO_CS LWGPIO_STRUCT sd_cs; SPI_CS_CALLBACK_STRUCT callback; #endif /* Open low level communication device */ com_handle = fopen(SDCARD_COM_CHANNEL, (void *)(SPI_FLAG_FULL_DUPLEX)); if (NULL == com_handle) { printf("Error opening communication handle %s, check your user_config.h.\n", SDCARD_COM_CHANNEL); _task_block(); } #ifdef BSP_SDCARD_GPIO_CS /* Open GPIO file for SPI CS signal emulation */ error_code = lwgpio_init(&sd_cs, BSP_SDCARD_GPIO_CS, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE); if (!error_code) { printf("Initializing GPIO with associated pins failed.\n"); _task_block(); } lwgpio_set_functionality(&sd_cs,BSP_SDCARD_CS_MUX_GPIO); lwgpio_set_attribute(&sd_cs, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); /* Set CS callback */ callback.MASK = BSP_SDCARD_SPI_CS; callback.CALLBACK = set_CS; callback.USERDATA = &sd_cs; if (SPI_OK != ioctl(com_handle, IO_IOCTL_SPI_SET_CS_CALLBACK, &callback)) { printf ("Setting CS callback failed.\n"); _task_block(); } #endif #if defined BSP_SDCARD_GPIO_DETECT /* Init GPIO pins for other SD card signals */ error_code = lwgpio_init(&sd_detect, BSP_SDCARD_GPIO_DETECT, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE); if (!error_code) { printf("Initializing GPIO with sdcard detect pin failed.\n"); _task_block(); } /*Set detect and protect pins as GPIO Function */ lwgpio_set_functionality(&sd_detect,BSP_SDCARD_DETECT_MUX_GPIO); lwgpio_set_attribute(&sd_detect, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #endif #if defined BSP_SDCARD_GPIO_PROTECT /* Init GPIO pins for other SD card signals */ error_code = lwgpio_init(&sd_protect, BSP_SDCARD_GPIO_PROTECT, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE); if (!error_code) { printf("Initializing GPIO with sdcard protect pin failed.\n"); _task_block(); } /*Set detect and protect pins as GPIO Function */ lwgpio_set_functionality(&sd_protect,BSP_SDCARD_PROTECT_MUX_GPIO); lwgpio_set_attribute(&sd_protect, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #endif /* Install SD card device */ error_code = _io_sdcard_install("sdcard:", (pointer)&_bsp_sdcard0_init, com_handle); if ( error_code != MQX_OK ) { printf("Error installing SD card device (0x%x)\n", error_code); _task_block(); } for (;;) { #if defined BSP_SDCARD_GPIO_DETECT #ifdef BSP_MPC8308RDB /* Set function as GPIO to detect sdcard */ lwgpio_set_functionality(&sd_detect,BSP_SDCARD_DETECT_MUX_GPIO); lwgpio_set_attribute(&sd_detect, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #endif inserted = !lwgpio_get_value(&sd_detect); #endif #if defined BSP_SDCARD_GPIO_PROTECT /* Get value of protect pin */ readonly = lwgpio_get_value(&sd_protect); #endif #ifdef BSP_MPC8308RDB /* Set function as SD_CD which indicate that card is present in Present State Register */ lwgpio_set_functionality(&sd_detect,BSP_SDCARD_DETECT_MUX_SD_CD); lwgpio_set_attribute(&sd_detect, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #endif if (last != inserted) { last = inserted; if (inserted) { _time_delay (200); /* Open the device which MFS will be installed on */ sdcard_handle = fopen("sdcard:", 0); if (sdcard_handle == NULL) { printf("Unable to open SD card device.\n"); continue; } /* Set read only flag as needed */ param = 0; if (readonly) { param = IO_O_RDONLY; } if (IO_OK != ioctl(sdcard_handle, IO_IOCTL_SET_FLAGS, (char_ptr) ¶m)) { printf("Setting device read only failed.\n"); continue; } /* Install partition manager over SD card driver */ error_code = _io_part_mgr_install(sdcard_handle, partman_name, 0); if (error_code != MFS_NO_ERROR) { printf("Error installing partition manager: %s\n", MFS_Error_text((uint_32)error_code)); continue; } /* Open partition */ partition_handle = fopen(partition_name, NULL); if (partition_handle != NULL) { printf("Installing MFS over partition...\n"); /* Validate partition */ error_code = _io_ioctl(partition_handle, IO_IOCTL_VAL_PART, NULL); if (error_code != MFS_NO_ERROR) { printf("Error validating partition: %s\n", MFS_Error_text((uint_32)error_code)); printf("Not installing MFS.\n"); continue; } /* Install MFS over partition */ error_code = _io_mfs_install(partition_handle, filesystem_name, 0); if (error_code != MFS_NO_ERROR) { printf("Error initializing MFS over partition: %s\n", MFS_Error_text((uint_32)error_code)); } } else { printf("Installing MFS over SD card driver...\n"); /* Install MFS over SD card driver */ error_code = _io_mfs_install(sdcard_handle, filesystem_name, (_file_size)0); if (error_code != MFS_NO_ERROR) { printf("Error initializing MFS: %s\n", MFS_Error_text((uint_32)error_code)); } } /* Open file system */ if (error_code == MFS_NO_ERROR) { filesystem_handle = fopen(filesystem_name, NULL); error_code = ferror(filesystem_handle); if (error_code == MFS_NOT_A_DOS_DISK) { printf("NOT A DOS DISK! You must format to continue.\n"); } else if (error_code != MFS_NO_ERROR) { printf("Error opening filesystem: %s\n", MFS_Error_text((uint_32)error_code)); continue; } printf ("SD card installed to %s\n", filesystem_name); if (readonly) { printf ("SD card is locked (read only).\n"); } } } else { /* Close the filesystem */ if ((filesystem_handle != NULL) && (MQX_OK != fclose(filesystem_handle))) { printf("Error closing filesystem.\n"); } filesystem_handle = NULL; /* Uninstall MFS */ error_code = _io_dev_uninstall(filesystem_name); if (error_code != MFS_NO_ERROR) { printf("Error uninstalling filesystem.\n"); } /* Close partition */ if ((partition_handle != NULL) && (MQX_OK != fclose(partition_handle))) { printf("Error closing partition.\n"); } partition_handle = NULL; /* Uninstall partition manager */ error_code = _io_dev_uninstall(partman_name); if (error_code != MFS_NO_ERROR) { printf("Error uninstalling partition manager.\n"); } /* Close the SD card device */ if ((sdcard_handle != NULL) && (MQX_OK != fclose(sdcard_handle))) { printf("Unable to close SD card device.\n"); } sdcard_handle = NULL; printf ("SD card uninstalled.\n"); } } _time_delay (200); } }
static void usb_filesystem_cancel_install( USB_FILESYSTEM_STRUCT_PTR usb_fs_ptr,int cancel_flag) { int_32 error_code; if (usb_fs_ptr == NULL) { return; } _int_disable(); switch (cancel_flag) { case USB_DEV_OPEN_FAIL: goto Uninstall_USB_device; case PARTITION_INIT_FAIL: goto Close_USB_device; case PARTITION_OPEN_FAIL: goto Uninstall_partition_manager; case PARTITION_VALIDATE_FAIL: goto Close_partition; //Uninstall_partition_manager; case MFS_INIT_FAIL: goto Uninstall_MFS; case MFS_OPEN_FAIL: goto Close_the_filesystem; default: printf("error cancel flag\n"); } Close_the_filesystem: /* Close the filesystem */ if ((usb_fs_ptr->FS_FD_PTR != NULL) && (MQX_OK != fclose(usb_fs_ptr->FS_FD_PTR))) { printf("Error while closing filesystem.\n"); } Uninstall_MFS: /* Uninstall MFS */ error_code = _io_dev_uninstall(usb_fs_ptr->FS_NAME); if (error_code != MFS_NO_ERROR) { printf("Error while uninstalling filesystem.\n"); } Close_partition: /* Close partition */ if ((usb_fs_ptr->PM_FD_PTR != NULL) && (MQX_OK != fclose(usb_fs_ptr->PM_FD_PTR))) { printf("Error while closing partition.\n"); } Uninstall_partition_manager: /* Uninstall partition manager */ error_code = _io_dev_uninstall(usb_fs_ptr->PM_NAME); if (error_code != MFS_NO_ERROR) { printf("Error while uninstalling partition manager.\n"); } Close_USB_device: /* Close USB device */ if ((usb_fs_ptr->DEV_FD_PTR != NULL) && (MQX_OK != fclose(usb_fs_ptr->DEV_FD_PTR))) { printf("Unable to close USB device.\n"); } Uninstall_USB_device: /* Uninstall USB device */ error_code = _io_dev_uninstall(usb_fs_ptr->DEV_NAME); if (error_code != MQX_OK) { printf("Error while uninstalling USB device.\n"); } _mem_free(usb_fs_ptr); _int_enable(); printf("USB device removed.\n"); }
void usb_filesystem_uninstall( USB_FILESYSTEM_STRUCT_PTR usb_fs_ptr) { int_32 error_code; if (usb_fs_ptr == NULL) { return; } _int_disable(); /* Close the filesystem */ #if 1 printf("1"); error_code = fclose(usb_fs_ptr->FS_FD_PTR); if ((usb_fs_ptr->FS_FD_PTR != NULL) && (MQX_OK != error_code)) { printf("Error while closing filesystem %d.\n",error_code); } #else if (usb_fs_ptr->FS_FD_PTR != NULL) { printf("\r\n\r\nWaiting for tasks to close all files.\r\n"); error_code = fclose(usb_fs_ptr->FS_FD_PTR); /* while */if (error_code == MFS_SHARING_VIOLATION) { /* * Filesystem could not be closed. There are probably still some files opened preventing it. * Wait for a while (give other tasks a chance to finish their job) and try again. */ printf("-"); //_int_enable(); _time_delay(200); //_int_disable(); printf("."); error_code = fclose(usb_fs_ptr->FS_FD_PTR); } if (error_code != MQX_OK) { printf("Error while closing filesystem.\r\n"); } } #endif /* Uninstall MFS */ error_code = _io_dev_uninstall(usb_fs_ptr->FS_NAME); if (error_code != MFS_NO_ERROR) { printf("Error while uninstalling filesystem.\n"); } /* Close partition */ if ((usb_fs_ptr->PM_FD_PTR != NULL) && (MQX_OK != fclose(usb_fs_ptr->PM_FD_PTR))) { printf("Error while closing partition.\n"); } /* Uninstall partition manager */ error_code = _io_dev_uninstall(usb_fs_ptr->PM_NAME); if (error_code != MFS_NO_ERROR) { printf("Error while uninstalling partition manager.\n"); } /* Close USB device */ if ((usb_fs_ptr->DEV_FD_PTR != NULL) && (MQX_OK != fclose(usb_fs_ptr->DEV_FD_PTR))) { printf("Unable to close USB device.\n"); } _int_enable(); /* Uninstall USB device */ error_code = _io_dev_uninstall(usb_fs_ptr->DEV_NAME); if (error_code != MQX_OK) { printf("Error while uninstalling USB device.\n"); } _mem_free(usb_fs_ptr); printf("USB device removed.\n"); }