_mqx_int _io_apcflash_close ( /* [IN] the file handle for the device being closed */ FILE_DEVICE_STRUCT_PTR fd_ptr ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr = fd_ptr->DEV_PTR; IO_PCFLASH_STRUCT_PTR info_ptr = (IO_PCFLASH_STRUCT_PTR)io_dev_ptr->DRIVER_INIT_PTR; /* power down card */ _io_ioctl(info_ptr->PCCARD_STREAM, APCCARD_IOCTL_POWERDOWN_CARD, NULL); _io_ioctl(info_ptr->PCCARD_STREAM, APCCARD_IOCTL_FREE_ADDR_SPACE, (uint_32_ptr)&info_ptr->ATA_DATA_PTR); _io_ioctl(info_ptr->PCCARD_STREAM, APCCARD_IOCTL_FREE_ADDR_SPACE, (pointer)&info_ptr->ATA_REG_PTR); _mem_free((pointer)info_ptr->TEMP_BUFF_PTR); info_ptr->TEMP_BUFF_PTR = NULL; return(MQX_OK); } /* Endbody */
_mqx_int _io_dun_ioctl ( /* [IN] the file handle for the device */ MQX_FILE_PTR fd_ptr, /* [IN] the ioctl command */ _mqx_uint cmd, /* [IN] the ioctl parameters */ pointer param_ptr ) { /* Body */ IODUN_STRUCT_PTR ras_ptr = fd_ptr->DEV_DATA_PTR; return _io_ioctl(ras_ptr->F_PTR, cmd, param_ptr); } /* Endbody */
int_32 Shell_di(int_32 argc, char_ptr argv[] ) { /* Body */ boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; int_32 offset; MQX_FILE_PTR fd, fs; uint_32 backup=0; uchar_ptr buffer=NULL; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if ((argc < 2 ) || (argc > 3)) { printf("Invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else if ( !Shell_parse_uint_32(argv[1], (uint_32_ptr) &offset )) { printf("Error, invalid length\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else { buffer = _mem_alloc(SECTOR_SIZE); if (buffer==NULL) { printf("Error, unable to allocate sector buffer\n"); return SHELL_EXIT_ERROR; } if (argc==3) { fd = fopen(argv[2], "b"); } else { fs = Shell_get_current_filesystem(argv); _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd); } if (fd) { if (fseek(fd, offset, IO_SEEK_SET) == IO_ERROR) { printf("Error, unable to seek to sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) { printf("Error, unable to read sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } if (return_code == SHELL_EXIT_SUCCESS) { printf("\n"); backup = print_bpb(buffer); if (backup) { if (fseek(fd, backup, IO_SEEK_SET) == IO_ERROR) { printf("Error, unable to seek to sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) { printf("Error, unable to read sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } if (return_code == SHELL_EXIT_SUCCESS) { printf("\n"); print_bpb(buffer); } } } if (fseek(fd, 1, IO_SEEK_SET) == IO_ERROR) { printf("Error, unable to seek to sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) { printf("Error, unable to read sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } if (return_code == SHELL_EXIT_SUCCESS) { printf("\n"); print_fsi(buffer); } if (argc==3) { fclose(fd); } } _mem_free(buffer); } } if (print_usage) { if (shorthelp) { printf("%s <sector> [<device>]\n", argv[0]); } else { printf("Usage: %s <sector> [<device>]\n", argv[0]); printf(" <sector> = sector number\n"); printf(" <device> = low level device\n"); } } return return_code; } /* Endbody */
int_32 Shell_dirent(int_32 argc, char_ptr argv[] ) { /* Body */ boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; uint_32 sector,num_sectors; int_32 offset; MQX_FILE_PTR fd, fs; uint_32 e; uchar_ptr buffer; MFS_DIR_ENTRY_PTR dirents; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if ((argc < 2) || (argc > 4)) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else if ( !Shell_parse_uint_32(argv[1], (uint_32_ptr) &offset )) { printf("Error, invalid length\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else { num_sectors = 1; if (argc >= 3) { if ( !Shell_parse_uint_32(argv[2], (uint_32_ptr) &num_sectors )) { num_sectors = 1; } } if (argc == 4) { fd = fopen(argv[3], "r"); if (!fd) { printf("Error, unable to open file %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } } else { fs = Shell_get_current_filesystem(argv); _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd); } if (fd) { buffer = _mem_alloc(SECTOR_SIZE); if (buffer) { for(sector=0;sector<num_sectors;sector++) { if (fseek(fd, offset+sector, IO_SEEK_SET) == IO_ERROR) { printf("Error, unable to seek to sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (_io_read(fd, (char_ptr) buffer, 1) !=1) { printf("Error, unable to read sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (!is_zero(buffer, SECTOR_SIZE)) { printf("\nEntry # %d",offset+sector); dirents = (MFS_DIR_ENTRY_PTR) buffer; for (e=0;e<DIRENTS_PER_SECTOR;e++) { print_dirent(&dirents[e]); } printf("\n"); } } _mem_free(buffer); } else { printf("Error, unable to allocate sector buffer.\n" ); return_code = SHELL_EXIT_ERROR; } if (argc >= 4) { fclose(fd); } } } } if (print_usage) { if (shorthelp) { printf("%s <sector> [<device>]\n", argv[0]); } else { printf("Usage: %s <sector> [<device>]\n", argv[0]); printf(" <sector> = sector number\n"); printf(" <device> = low level device\n"); } } return return_code; } /* Endbody */
/*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 }/////////////////////////////////////////////////////////////////////////////循环 }
int_32 MFS_Close_Device ( MQX_FILE_PTR fd_ptr /* [IN] the MFS file handle for the device being closed */ ) { MFS_DRIVE_STRUCT_PTR drive_ptr; FILESYSTEM_INFO_DISK_PTR fsinfo_ptr; int_32 result = MFS_NO_ERROR; #if !MFSCFG_READ_ONLY #if MFSCFG_READ_ONLY_CHECK if (MFS_is_read_only (fd_ptr, NULL)) { result = MFS_DISK_IS_WRITE_PROTECTED; } #endif if (result != MFS_DISK_IS_WRITE_PROTECTED) { result = _io_ioctl(fd_ptr, IO_IOCTL_FLUSH_OUTPUT, NULL); } #endif MFS_lock(fd_ptr, &drive_ptr); #if !MFSCFG_READ_ONLY if (result != MFS_DISK_IS_WRITE_PROTECTED) { MFS_Flush_caches(drive_ptr); } #endif if ( _queue_is_empty(&drive_ptr->HANDLE_LIST) ) { if ( drive_ptr->FAT_TYPE == MFS_FAT32 ) { #if !MFSCFG_READ_ONLY if (result != MFS_DISK_IS_WRITE_PROTECTED) { fsinfo_ptr = (FILESYSTEM_INFO_DISK_PTR)drive_ptr->DATA_SECTOR_PTR; if ( fsinfo_ptr != NULL ) { htodl(fsinfo_ptr->LEAD_SIG, FSI_LEADSIG); htodl(fsinfo_ptr->STRUCT_SIG, FSI_STRUCTSIG); htodl(fsinfo_ptr->FREE_COUNT, drive_ptr->FREE_COUNT); htodl(fsinfo_ptr->NEXT_FREE, drive_ptr->NEXT_FREE_CLUSTER); htodl(fsinfo_ptr->TRAIL_SIG, FSI_TRAILSIG); MFS_Write_device_sector(drive_ptr, FSINFO_SECTOR, (char_ptr)fsinfo_ptr); } } #endif } MFS_free_drive_data(drive_ptr, TRUE); drive_ptr->MFS_FILE_PTR = NULL; result = MFS_NO_ERROR; } else { /* liutest add for get unclose handle */ MFS_HANDLE_PTR next_handle; next_handle = (MFS_HANDLE_PTR) _queue_head(&drive_ptr->HANDLE_LIST); while ( next_handle ) { printf("unclose handle 0x%X\n",(uint_32)next_handle); next_handle = (MFS_HANDLE_PTR) _queue_next(&drive_ptr->HANDLE_LIST, (QUEUE_ELEMENT_STRUCT_PTR) next_handle); } result = MFS_SHARING_VIOLATION; /* MFS_free_drive_data(drive_ptr, TRUE); drive_ptr->MFS_FILE_PTR = NULL; result = MFS_NO_ERROR;*/ } MFS_unlock(drive_ptr,FALSE); return result; }
pointer usb_filesystem_install( pointer usb_handle, char_ptr block_device_name, char_ptr partition_manager_name, char_ptr file_system_name ) { uint_32 partition_number; uchar_ptr dev_info; int_32 error_code; uint_32 mfs_status; USB_FILESYSTEM_STRUCT_PTR usb_fs_ptr; usb_fs_ptr = _mem_alloc_system_zero(sizeof(USB_FILESYSTEM_STRUCT)); if (usb_fs_ptr==NULL) { return NULL; } _io_usb_mfs_install(block_device_name, 0, (pointer)usb_handle); usb_fs_ptr->DEV_NAME = block_device_name; /* Open the USB mass storage device */ _time_delay(500); usb_fs_ptr->DEV_FD_PTR = fopen(block_device_name, (char_ptr) 0); if (usb_fs_ptr->DEV_FD_PTR == NULL) { printf("\nUnable to open USB disk"); usb_filesystem_uninstall(usb_fs_ptr); return NULL; } _io_ioctl(usb_fs_ptr->DEV_FD_PTR, IO_IOCTL_SET_BLOCK_MODE, NULL); /* get the vendor information and display it */ printf("\n************************************************************************"); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, IO_IOCTL_GET_VENDOR_INFO, &dev_info); printf("\nVendor Information: %-1.8s Mass Storage Device",dev_info); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, IO_IOCTL_GET_PRODUCT_ID, &dev_info); printf("\nProduct Identification: %-1.16s",dev_info); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, IO_IOCTL_GET_PRODUCT_REV, &dev_info); printf("\nProduct Revision Level: %-1.4s",dev_info); printf("\n************************************************************************"); /* Try Installing a the partition manager */ error_code = _io_part_mgr_install(usb_fs_ptr->DEV_FD_PTR, partition_manager_name, 0); if (error_code != MFS_NO_ERROR) { printf("\nError while initializing (%s)", MFS_Error_text((uint_32)error_code)); usb_filesystem_uninstall(usb_fs_ptr); return NULL; } usb_fs_ptr->PM_NAME = partition_manager_name; usb_fs_ptr->PM_FD_PTR = fopen(partition_manager_name, NULL); if (usb_fs_ptr->PM_FD_PTR == NULL) { error_code = ferror(usb_fs_ptr->PM_FD_PTR); printf("\nError while opening partition (%s)", MFS_Error_text((uint_32)error_code)); usb_filesystem_uninstall(usb_fs_ptr); return NULL; } printf("\n--->USB Mass storage device opened"); partition_number = 1; error_code = _io_ioctl(usb_fs_ptr->PM_FD_PTR, IO_IOCTL_VAL_PART, &partition_number); if (error_code == PMGR_INVALID_PARTITION) { printf("\n--->No partition available on this device"); /* uninitialize */ fclose(usb_fs_ptr->PM_FD_PTR); usb_fs_ptr->PM_FD_PTR = NULL; _io_part_mgr_uninstall(usb_fs_ptr->PM_NAME); usb_fs_ptr->PM_NAME = NULL; /* install MFS without partition */ mfs_status = _io_mfs_install(usb_fs_ptr->DEV_FD_PTR, file_system_name, 0); } else { printf("\n--->Partition Manager installed"); /* Install MFS on the partition #1 */ mfs_status = _io_mfs_install(usb_fs_ptr->PM_FD_PTR, file_system_name, partition_number); } if (mfs_status != MFS_NO_ERROR) { printf("\nError initializing MFS (%s)", MFS_Error_text((uint_32)mfs_status)); /* uninitialize and exit */ usb_filesystem_uninstall(usb_fs_ptr); return NULL; } printf("\n--->File System installed"); usb_fs_ptr->FS_NAME = file_system_name; usb_fs_ptr->FS_FD_PTR = fopen(file_system_name, 0); if (usb_fs_ptr->FS_FD_PTR==NULL) { usb_filesystem_uninstall(usb_fs_ptr); return NULL; } printf("\n--->File System opened"); return (pointer) usb_fs_ptr; }
_mfs_error _mfs_validate_device ( #if MQX_USE_IO_OLD MQX_FILE_PTR dev_fd, /* [IN] the file handle for the lower layer device */ #else int dev_fd, /* [IN] the file handle for the lower layer device */ #endif uint32_t *sector_size_ptr, /* [OUT] Pointer to where the sector size is to be stored */ bool *block_mode_ptr /* [OUT] Pointer to where the block mode is to be stored */ ) { _mfs_error error_code; #ifdef IO_DEV_ATTR_BLOCK_MODE uint32_t id_array[3]; id_array[0] = id_array[1] = id_array[2] = 0; /* ** Issue the id command. Block mode drivers must support this command but ** other drivers can support it also */ #if MQX_USE_IO_OLD error_code = _io_ioctl(dev_fd, IO_IOCTL_DEVICE_IDENTIFY, id_array); if ( error_code == IO_OK ) { /* ** The identify command is supported. Check to see if it is a block mode ** driver */ if ( id_array[MFS_IOCTL_ID_ATTR_ELEMENT] & IO_DEV_ATTR_BLOCK_MODE ) { *block_mode_ptr = TRUE; } else { *block_mode_ptr = FALSE; } } else if ( error_code == IO_ERROR_INVALID_IOCTL_CMD ) { /* ** The ID command is not supported by the lower layer. It is not a block ** mode driver */ *block_mode_ptr = FALSE; } else { /* Something bad happened at the lower layer */ return( error_code ); } #else //MQX_USE_IO_OLD error_code = ioctl(dev_fd, IO_IOCTL_DEVICE_IDENTIFY, id_array); if ( 0 >= error_code ) { /* ** The identify command is supported. Check to see if it is a block mode ** driver */ if ( id_array[MFS_IOCTL_ID_ATTR_ELEMENT] & IO_DEV_ATTR_BLOCK_MODE ) { *block_mode_ptr = TRUE; } else { *block_mode_ptr = FALSE; } } else { *block_mode_ptr = FALSE; } #endif //MQX_USE_IO_OLD #else *block_mode_ptr = FALSE; #endif *sector_size_ptr = MFS_DEFAULT_SECTOR_SIZE; error_code = ioctl(dev_fd, IO_IOCTL_GET_BLOCK_SIZE, sector_size_ptr); #if MQX_USE_IO_OLD if ( error_code == IO_ERROR_INVALID_IOCTL_CMD ) #else if ( error_code == -1 && errno == EINVAL ) #endif { /* ** The command is not supported. This is OK as long as it isn't a block ** mode driver. */ if ( *block_mode_ptr ) { /* MFS needs to know the block size for block mode drivers */ error_code = MFS_INVALID_DEVICE; } else { /* ** It doesn't matter that we can't tell the actual block size. MFS ** will be doing byte accesses anyway since it isn't a block mode ** driver. */ *sector_size_ptr = MFS_DEFAULT_SECTOR_SIZE; error_code = MFS_NO_ERROR; } } else if ( error_code == MFS_OK ) { /* Check to see if the sector or block size is suitable for MFS */ if ( !((*sector_size_ptr == 512) || (*sector_size_ptr == 1024) || (*sector_size_ptr == 2048) || (*sector_size_ptr == 4096)) ) { /* ** The block size isn't compatible. This may still be OK as long as we ** are not dealing with a block mode driver otherwise MFS won't be ** able to work with it */ if ( *block_mode_ptr ) { error_code = MFS_INVALID_DEVICE; } } } return(error_code); }
int32_t Shell_disect(int32_t argc, char *argv[] ) { /* Body */ int32_t return_code = SHELL_EXIT_SUCCESS; bool print_usage, shorthelp = FALSE; uint32_t sector,num_sectors; int32_t offset=0; MQX_FILE_PTR fd, fs; uint32_t e,i; unsigned char *buffer; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if ((argc < 2) || (argc > 5)) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else if ( !Shell_parse_uint_32(argv[1], (uint32_t *) &offset )) { printf("Error, invalid length\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else { num_sectors = 1; if (argc >= 3) { if ( !Shell_parse_uint_32(argv[2], (uint32_t *) &num_sectors )) { num_sectors = 1; } } if (argc >= 4) { fd = fopen(argv[3], "r"); if (!fd) { printf("Error, unable to open file %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } } else { fs = Shell_get_current_filesystem(argv); _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd); } if (fd) { buffer = _mem_alloc(SECTOR_SIZE); if (buffer) { for(sector=0;sector<num_sectors;sector++) { if (fseek(fd, offset+sector, IO_SEEK_SET) == IO_ERROR) { printf("Error, unable to seek to sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (_io_read(fd, (char *) buffer, 1) != 1) { printf("Error, unable to read sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else { printf("\nSector # %d\n",offset+sector); for (e=0;e<16;e++) { for (i=0;i<32;i++) { printf("%02x ",(uint32_t) buffer[e*32+i]); } printf("\n"); } } } _mem_free(buffer); } } printf("\n"); if (argc >= 4) { fclose(fd); } } } if (print_usage) { if (shorthelp) { printf("%s <sector> [<device>]\n", argv[0]); } else { printf("Usage: %s <sector> [<device>]\n", argv[0]); printf(" <sector> = sector number\n"); printf(" <device> = low level device\n"); } } return return_code; } /* Endbody */
_mqx_int _io_apcflash_open ( /* [IN] the file handle for the device being opened */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the remaining portion of the name of the device */ char _PTR_ open_name_ptr, /* [IN] the flags to be used during operation */ char _PTR_ flags ) { /* Body */ APCCARD_ADDR_INFO_STRUCT addr_info; IO_DEVICE_STRUCT_PTR io_dev_ptr = fd_ptr->DEV_PTR; IO_PCFLASH_STRUCT_PTR info_ptr = (IO_PCFLASH_STRUCT_PTR)io_dev_ptr->DRIVER_INIT_PTR; ATA_IDENTIFY_DEVICE_STRUCT_PTR identify_ptr; MQX_FILE_PTR pccard_stream = (MQX_FILE_PTR)flags; uint_32_ptr temp_ptr; uchar_ptr temp8_ptr; uint_32 temp; uint_32 error; int_32 io_error; uint_32 num_sectors; uchar end_defn[] = {2, 0}; #if MQX_CHECK_ERRORS if (pccard_stream == NULL) { /* No PCCARD device open */ return(IO_ERROR); } /* Endif */ #endif /* ** Allocate a ram buffer the size of one sector to be used when ** reading/writing partial sectors -- this buffer is also used in this ** function for the identify info */ temp_ptr = (uint_32_ptr)_mem_alloc_system_zero(info_ptr->SECTOR_SIZE); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (temp_ptr == NULL) { return(MQX_OUT_OF_MEMORY); } /* Endif */ #endif _mem_set_type(temp_ptr,MEM_TYPE_IO_SECTOR_BUFFER); #if MQX_CHECK_ERRORS /* Is the lower layer compatible? */ io_error = _io_ioctl(pccard_stream, IO_IOCTL_DEVICE_IDENTIFY, temp_ptr); if ((io_error != MQX_OK) || (temp_ptr[0] != IO_DEV_TYPE_PHYS_ADV_PCCARD)) { _mem_free(temp_ptr); if (io_error == MQX_OK) { io_error = IO_ERROR_DEVICE_INVALID; }/* Endif */ return(io_error); } /* Endif */ #endif /* Is there a card present? */ _io_ioctl(pccard_stream, APCCARD_IOCTL_IS_CARD_INSERTED, &temp); if ((boolean)temp == FALSE) { _mem_free(temp_ptr); return(IO_ERROR); } /* Endif */ /* Wait for card to power up. This will apply Vcc and also Vpp if needed */ _io_ioctl(pccard_stream, APCCARD_IOCTL_WAIT_TILL_READY, NULL); /* Make sure card is an ATA flash card */ /* Read CISTPL_FUNCID tuple */ temp_ptr[0] = IO_APCCARD_TUPLE_CISTPL_FUNCID; _io_ioctl(pccard_stream, APCCARD_IOCTL_READ_TUPLE, temp_ptr); temp8_ptr = (uchar_ptr)(temp_ptr + 1); if (temp8_ptr[0] != 0x4) { /* This is not a flash disk */ _mem_free(temp_ptr); return(IO_ERROR_DEVICE_INVALID); } /* Endif */ info_ptr->TEMP_BUFF_PTR = (uchar_ptr)temp_ptr; /* Save the PCCard stream */ info_ptr->PCCARD_STREAM = pccard_stream; /* Get memory locations of the flash card */ /* Register memory */ addr_info.OFFSET = ATA_REG_BASE; addr_info.TYPE = APCCARD_COMMON_SPACE; addr_info.BANK_SIZE = 16; addr_info.PORT_SIZE = 8; _io_ioctl(pccard_stream, APCCARD_IOCTL_GET_ADDR_SPACE, (pointer)&addr_info); info_ptr->ATA_REG_PTR = (uchar_ptr)addr_info.ADDRESS; /* Data memory */ addr_info.OFFSET = ATA_REG_BASE + ATA_DATA_BUF; addr_info.TYPE = APCCARD_COMMON_SPACE; addr_info.BANK_SIZE = 0x400; addr_info.PORT_SIZE = 16; _io_ioctl(pccard_stream, APCCARD_IOCTL_GET_ADDR_SPACE, (pointer)&addr_info); info_ptr->ATA_DATA_PTR = (uint_16_ptr)addr_info.ADDRESS; /* Perform a soft reset on the device */ error = _io_apcflash_reset(info_ptr); if (error != PCFLASH_NO_ERROR) { _io_ioctl(info_ptr->PCCARD_STREAM, APCCARD_IOCTL_POWERDOWN_CARD, NULL); _io_ioctl(pccard_stream, APCCARD_IOCTL_FREE_ADDR_SPACE, (pointer)info_ptr->ATA_REG_PTR); _io_ioctl(pccard_stream, APCCARD_IOCTL_FREE_ADDR_SPACE, (pointer)info_ptr->ATA_DATA_PTR); _mem_free(temp_ptr); return(IO_ERROR); } /* Endif */ /* Get information about the device */ identify_ptr = (ATA_IDENTIFY_DEVICE_STRUCT_PTR)((pointer)temp_ptr); _io_apcflash_identify_device(info_ptr, (uchar_ptr)identify_ptr); /* Store the info in the state structure */ #if (PSP_ENDIAN == MQX_BIG_ENDIAN) _mem_swap_endian((uchar_ptr)end_defn, &(identify_ptr->NUMBER_CYLINDERS)); _mem_swap_endian((uchar_ptr)end_defn, &(identify_ptr->SECTORS_PER_TRACK)); _mem_swap_endian((uchar_ptr)end_defn, &(identify_ptr->NUMBER_HEADS)); #endif num_sectors = identify_ptr->NUMBER_CYLINDERS * identify_ptr->SECTORS_PER_TRACK * identify_ptr->NUMBER_HEADS; info_ptr->NUM_SECTORS = num_sectors; info_ptr->SIZE = num_sectors * info_ptr->SECTOR_SIZE; info_ptr->NUMBER_OF_HEADS = (uint_32)identify_ptr->NUMBER_HEADS; info_ptr->NUMBER_OF_TRACKS = (uint_32)identify_ptr->NUMBER_CYLINDERS; info_ptr->SECTORS_PER_TRACK = (uint_32)identify_ptr->SECTORS_PER_TRACK; return(MQX_OK); } /* Endbody */
_mqx_int _io_apcflash_ioctl ( /* [IN] the file handle for the device */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the ioctl command */ _mqx_uint cmd, /* [IN] the ioctl parameters */ pointer input_param_ptr ) { /* Body */ PCFLASH_DRIVE_INFO_STRUCT_PTR drive_info_ptr; IO_DEVICE_STRUCT_PTR io_dev_ptr = fd_ptr->DEV_PTR; IO_PCFLASH_STRUCT_PTR info_ptr = (IO_PCFLASH_STRUCT_PTR)io_dev_ptr->DRIVER_INIT_PTR; int_32 result = MQX_OK; uint_32_ptr param_ptr = input_param_ptr; switch (cmd) { case PCFLASH_IOCTL_IS_CARD_INSERTED: _lwsem_wait(&info_ptr->LWSEM); /* Is there a card present? (TRUE/FALSE) */ _io_ioctl(info_ptr->PCCARD_STREAM, APCCARD_IOCTL_IS_CARD_INSERTED, param_ptr); _lwsem_post(&info_ptr->LWSEM); break; case PCFLASH_IOCTL_GET_NUM_SECTORS: *param_ptr = info_ptr->NUM_SECTORS; break; /* Start CR 812 */ case IO_IOCTL_GET_BLOCK_SIZE: /* End CR 812 */ case PCFLASH_IOCTL_GET_SECTOR_SIZE: *param_ptr = info_ptr->SECTOR_SIZE; break; case IO_IOCTL_DEVICE_IDENTIFY: param_ptr[0] = IO_DEV_TYPE_PHYS_PCFLASH; param_ptr[1] = IO_DEV_TYPE_LOGICAL_MFS; param_ptr[2] = IO_DEV_ATTR_ERASE | IO_DEV_ATTR_POLL | IO_DEV_ATTR_READ | IO_DEV_ATTR_REMOVE | IO_DEV_ATTR_SEEK | IO_DEV_ATTR_WRITE; /* Start CR 812 */ if (info_ptr->BLOCK_MODE) { param_ptr[2] |= IO_DEV_ATTR_BLOCK_MODE; } /* Endif */ /* End CR 812 */ break; case PCFLASH_IOCTL_GET_DRIVE_PARAMS: drive_info_ptr = (PCFLASH_DRIVE_INFO_STRUCT_PTR)((pointer)param_ptr); drive_info_ptr->NUMBER_OF_HEADS = info_ptr->NUMBER_OF_HEADS; drive_info_ptr->NUMBER_OF_TRACKS = info_ptr->NUMBER_OF_TRACKS; drive_info_ptr->SECTORS_PER_TRACK = info_ptr->SECTORS_PER_TRACK; break; /* Start CR 812 */ case PCFLASH_IOCTL_SET_BLOCK_MODE: info_ptr->BLOCK_MODE = TRUE; break; /* End CR 812 */ default: result = IO_ERROR_INVALID_IOCTL_CMD; break; } /* Endswitch */ return(result); } /* Endbody */
_mqx_int _io_apcflash_write ( /* [IN] the file handle for the device */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] where the outgoing data is store */ char_ptr data_ptr, /* [IN] the number of bytes to output */ _mqx_int num ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr = fd_ptr->DEV_PTR; IO_PCFLASH_STRUCT_PTR info_ptr = (IO_PCFLASH_STRUCT_PTR)io_dev_ptr->DRIVER_INIT_PTR; uint_32 total_size; uint_32 sector_size; uchar_ptr src_ptr; int_32 results; uint_32 temp_num1; uint_32 start_sector; uint_32 end_sector; uint_32 offset; uint_32 remains; uint_32 num_sectors; uint_32 sectors_to_write; uint_32 i; uint_32 temp; _lwsem_wait(&info_ptr->LWSEM); /* Is there a card present? */ _io_ioctl(info_ptr->PCCARD_STREAM, APCCARD_IOCTL_IS_CARD_INSERTED, &temp); if ((boolean)temp == FALSE) { fd_ptr->ERROR = IO_ERROR_READ_ACCESS; _lwsem_post(&info_ptr->LWSEM); return(IO_ERROR); } /* Endif */ /* Start CR 812 */ if (info_ptr->BLOCK_MODE) { results = _io_apcflash_read_write_blocks(fd_ptr, info_ptr, data_ptr, num, TRUE); _lwsem_post(&info_ptr->LWSEM); return results; } /* Endif */ /* End CR 82 */ total_size = info_ptr->SIZE; sector_size = info_ptr->SECTOR_SIZE; if (fd_ptr->LOCATION > total_size) { fd_ptr->ERROR = IO_ERROR_WRITE_ACCESS; _lwsem_post(&info_ptr->LWSEM); return(IO_ERROR); } else { if ((num + fd_ptr->LOCATION) > total_size) { fd_ptr->ERROR = IO_ERROR_WRITE_ACCESS; num = (int_32)(total_size - fd_ptr->LOCATION + 1); } /* Endif */ start_sector = fd_ptr->LOCATION / info_ptr->SECTOR_SIZE; end_sector = (fd_ptr->LOCATION + num - 1) / info_ptr->SECTOR_SIZE; num_sectors = end_sector - start_sector + 1; temp_num1 = num; src_ptr = (uchar_ptr)data_ptr; /* ** We have three conditions: ** 1. The write is contained in one PCflash sector ** 2. The write is contained in two adjacent PCflash sectors ** 3. The write spans many PCflash sectors ** ** In case 1, it is possible to have a partial PCflash sector. ** In case 2, it is possible that both the end and the start are only ** partial PCflash sectors. ** In case 3(really a subset of case 2), the start and end maybe partial ** but the others will all be complete PCflash sectors. */ offset = fd_ptr->LOCATION - info_ptr->SECTOR_SIZE * start_sector; if (offset > 0) { num_sectors--; remains = info_ptr->SECTOR_SIZE - offset; if (remains > temp_num1) { remains = temp_num1; }/* Endif */ results = _io_apcflash_write_partial_sector(fd_ptr, start_sector, offset, remains, src_ptr); if (results == IO_ERROR) { fd_ptr->ERROR = IO_ERROR_WRITE; _lwsem_post(&info_ptr->LWSEM); return(results); } else { fd_ptr->LOCATION += results; src_ptr = (uchar_ptr)data_ptr + results; temp_num1 -= results; start_sector++; } /* Endif */ } /* Endif */ if (num_sectors > 1) { /* ** Write the middle flash sectors (if any ) */ /* Calculate number of sectors to write but do not include last one */ sectors_to_write = num_sectors - 1; /* Calculate the number of bytes need to write in this case */ for (i = 0; i < sectors_to_write; i++) { if (_io_apcflash_write_sector(info_ptr, start_sector + i, src_ptr) == PCFLASH_NO_ERROR) { results += sector_size; fd_ptr->LOCATION += sector_size; num_sectors--; src_ptr += sector_size; temp_num1 -= sector_size; } else { fd_ptr->ERROR = IO_ERROR_WRITE; _lwsem_post(&info_ptr->LWSEM); return(IO_ERROR); } /* Endif */ } /* Endfor */ } /* Endif */ if (num_sectors) { /* Write the last flash sector */ offset = 0; remains = temp_num1; results = _io_apcflash_write_partial_sector(fd_ptr, end_sector, offset, remains, src_ptr); if (results == IO_ERROR) { fd_ptr->ERROR = IO_ERROR_WRITE; _lwsem_post(&info_ptr->LWSEM); return(results); } else { fd_ptr->LOCATION += results; } /* Endif */ } /* Endif */ } /* Endif */ _lwsem_post(&info_ptr->LWSEM); return(num); } /* Endbody */
/*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); } }
/*TASK*----------------------------------------------------------------- * * Function Name : CF_filesystem_install * Returned Value : void * Comments : Install filesystem on given pccard file pointer * *END------------------------------------------------------------------*/ FS_STRUCT_PTR CF_filesystem_install( MQX_FILE_PTR pccard_fp, char_ptr partition_manager_name, char_ptr file_system_name ) { uint_32 partition_number; int_32 error_code; uint_32 mfs_status; FS_STRUCT_PTR fs_ptr; fs_ptr = _mem_alloc_system_zero(sizeof(FS_STRUCT)); if (fs_ptr==NULL) { return NULL; } /* Open flash device */ fs_ptr->DEV_FD_PTR = fopen("pcflasha:", (char_ptr) pccard_fp); if ( fs_ptr->DEV_FD_PTR == NULL ) { printf("\nOpen flash device failed\n"); return NULL; } /* Endif */ error_code = ioctl(fs_ptr->DEV_FD_PTR, PCFLASH_IOCTL_SET_BLOCK_MODE, NULL); if (error_code == IO_OK) { // printf("\nBlock mode enabled."); } else { printf("\nBlock mode not enabled. Running in byte mode.\n"); } /* Endif */ /* Try Installing a the partition manager */ error_code = _io_part_mgr_install(fs_ptr->DEV_FD_PTR, partition_manager_name, 0); if (error_code != MFS_NO_ERROR) { printf("\nError while initializing (%s)", MFS_Error_text((uint_32)error_code)); CF_filesystem_uninstall(fs_ptr); return NULL; } fs_ptr->PM_NAME = partition_manager_name; fs_ptr->PM_FD_PTR = fopen(partition_manager_name, NULL); if (fs_ptr->PM_FD_PTR == NULL) { error_code = ferror(fs_ptr->PM_FD_PTR); printf("\nError while opening partition (%s)", MFS_Error_text((uint_32)error_code)); CF_filesystem_uninstall(fs_ptr); return NULL; } printf("\n--->Compact Flash device opened"); partition_number = 1; error_code = _io_ioctl(fs_ptr->PM_FD_PTR, IO_IOCTL_VAL_PART, &partition_number); if (error_code == PMGR_INVALID_PARTITION) { printf("\n--->No partition available on this device"); /* uninitialize */ fclose(fs_ptr->PM_FD_PTR); fs_ptr->PM_FD_PTR = NULL; _io_part_mgr_uninstall(fs_ptr->PM_NAME); fs_ptr->PM_NAME = NULL; /* install MFS without partition */ mfs_status = _io_mfs_install(fs_ptr->DEV_FD_PTR, file_system_name, 0); } else { printf("\n--->Partition Manager installed"); /* Install MFS on the partition #1 */ mfs_status = _io_mfs_install(fs_ptr->PM_FD_PTR, file_system_name, partition_number); } if (mfs_status != MFS_NO_ERROR) { printf("\nError initializing MFS (%s)", MFS_Error_text((uint_32)mfs_status)); /* uninitialize and exit */ CF_filesystem_uninstall(fs_ptr); return NULL; } fs_ptr->FS_NAME = file_system_name; fs_ptr->FS_FD_PTR = fopen(file_system_name, 0); if (fs_ptr->FS_FD_PTR==NULL) { CF_filesystem_uninstall(fs_ptr); return NULL; } printf("\n--->File System opened as : %s\n",fs_ptr->FS_NAME); return (pointer) fs_ptr; }
/*TASK*----------------------------------------------------- * * Task Name : main_task * Comments : * This task does nothing * *END*-----------------------------------------------------*/ void main_task ( uint_32 initial_data ) { MQX_FILE_PTR flash_file; uint_32 val; FLEXNVM_PROG_PART_STRUCT part_param; _mqx_int result; uint_8 *byte_ptr = (uint_8*) BSP_INTERNAL_FLEXRAM_BASE; uint_16 *half_ptr = (uint_16*) BSP_INTERNAL_FLEXRAM_BASE + 1; uint_32 *word_ptr = (uint_32*) BSP_INTERNAL_FLEXRAM_BASE + 1; _int_install_unexpected_isr(); printf("\n\nMQX FlexNVM example"); /* Open the flash device */ flash_file = fopen("flashx:flexram0", NULL); if (NULL == flash_file) { _task_block(); } /* read partition code to check FlexNVM settings */ result = _io_ioctl(flash_file, FLEXNVM_IOCTL_GET_PARTITION_CODE, &part_param); if (IO_OK != result) { printf("\nError when reading FlexNVM configuration."); _task_block(); } /* check FlexNVM partition settings */ if (FLEXNVM_PART_CODE_NOPART == part_param.FLEXNVM_PART_CODE) { printf("\n\nEnabling FlexEEPROM - partition memory."); /* set FlexNVM partition and EEPROM size */ part_param.EE_DATA_SIZE_CODE = (FLEXNVM_EE_SPLIT_1_1 | FLEXNVM_EE_SIZE_4096); part_param.FLEXNVM_PART_CODE = FLEXNVM_PART_CODE_DATA128_EE128; _io_ioctl(flash_file, FLEXNVM_IOCTL_SET_PARTITION_CODE, &part_param); /* switch FlexRAM to EEPROM mode */ val = FLEXNVM_FLEXRAM_EE; _io_ioctl(flash_file, FLEXNVM_IOCTL_SET_FLEXRAM_FN, &val); } else printf("\nDevice has FlexEEPROM already enabled."); printf("\n\nReading actual memory values:\n"); printf("byte: 0x%p = 0x%x\n", byte_ptr, *byte_ptr); printf("half: 0x%p = 0x%x\n", half_ptr, *half_ptr); printf("word: 0x%p = 0x%x\n", word_ptr, *word_ptr); printf("\n\nWriting new values to memory:\n"); /* wait for FlexEEPROM ready */ _io_ioctl(flash_file, FLEXNVM_IOCTL_WAIT_EERDY, NULL); *byte_ptr += 1; /* wait for FlexEEPROM ready - after write */ _io_ioctl(flash_file, FLEXNVM_IOCTL_WAIT_EERDY, NULL); *half_ptr += 2; /* wait for FlexEEPROM ready - after write */ _io_ioctl(flash_file, FLEXNVM_IOCTL_WAIT_EERDY, NULL); *word_ptr += 3; /* wait for FlexEEPROM ready - after write */ _io_ioctl(flash_file, FLEXNVM_IOCTL_WAIT_EERDY, NULL); printf("\n\nReading new memory values:\n"); printf("byte: 0x%p = 0x%x\n", byte_ptr, *byte_ptr); printf("half: 0x%p = 0x%x\n", half_ptr, *half_ptr); printf("word: 0x%p = 0x%x\n", word_ptr, *word_ptr); printf("\nProgram finshed, you can try restart !"); fclose(flash_file); _task_block(); }
void Main_task(uint_32 initial_data) { TCHRES_INSTALL_PARAM_STRUCT install_params; FILE_PTR tchscr_dev; TCHRES_POSITION_STRUCT position; _mqx_int result; printf("\nTCHRES demo application\n"); printf("This demo application requires TWR-LCD board.\n"); #if (defined BSP_TCHRES_ADC_XPLUS_DEVICE) && (defined BSP_TCHRES_ADC_YPLUS_DEVICE) printf("Opening ADC device for XPLUS electrode ... " BSP_TCHRES_ADC_XPLUS_DEVICE " "); if (fopen(BSP_TCHRES_ADC_XPLUS_DEVICE, (const char*)&adc_init) == NULL) { printf("failed\n"); _task_block(); } else { install_params.ADC_XPLUS_DEVICE = BSP_TCHRES_ADC_XPLUS_DEVICE; printf("done\n"); } printf("Opening ADC device for YPLUS electrode ... " BSP_TCHRES_ADC_YPLUS_DEVICE " "); if (fopen(BSP_TCHRES_ADC_YPLUS_DEVICE, (const char*)&adc_init) == NULL) { printf("failed\n"); _task_block(); } else { install_params.ADC_YPLUS_DEVICE = BSP_TCHRES_ADC_YPLUS_DEVICE; printf("done\n"); } #elif (defined BSP_TCHRES_ADC_DEVICE) printf("Opening ADC device for XPLUS and YPLUS electrodes ... " BSP_TCHRES_ADC_DEVICE " "); if (fopen(BSP_TCHRES_ADC_DEVICE, (const char*)&adc_init) == NULL) { printf("failed\n"); _task_block(); } else { install_params.ADC_XPLUS_DEVICE = install_params.ADC_YPLUS_DEVICE = BSP_TCHRES_ADC_DEVICE; printf("done\n"); } #else printf("This demo application requires ADC devices for TCHRES to be defined!\n"); _task_block(); #endif printf("Installing TCHRES device ... "); _io_tchres_install("tchscr:", &_bsp_tchscr_resisitve_init, &install_params); printf("done\n"); printf("Opening TCHRES device ..."); if ((tchscr_dev = fopen("tchscr:", NULL)) == NULL) { printf("failed\n"); _task_block(); } else { printf("done\n"); } for (;;) { if ((result = _io_ioctl(tchscr_dev, IO_IOCTL_TCHSCR_GET_POSITION_RAW, &position)) == TCHRES_OK) { printf("Touch detected in raw ADC values (X,Y) = (%d, %d)\n", position.X, position.Y); } else { printf("No touch detected ...\n"); } _time_delay(100); } }
/*TASK*----------------------------------------------------- * * Task Name : mem_flash_app * Comments : * This task finds a string at 'the end' of flash memory * then it tries to rewrite it. The successfull rewrite * can be proved by re-executing this example application. * *END*-----------------------------------------------------*/ void mem_flash_app ( uint_32 initial_data ) { ///////////////////////////////////////////////////////////// Flashx mfs demo =0x00060000~0x00080000#dx 20130103 #define FLASH_NAME_B "flashx:" //FLASH_NAME char flashx_filesystem_name[] = "f:",flashx_partman_name[]="pmb:";///////////////////安装盘符 MQX_FILE_PTR flashx_handle,flashx_file_handle,flashx_partman_handle; _mqx_uint param; uint_32 error; printf("\nMQX Flash Task."); /* wk --> open flash device */ flashx_handle = fopen(FLASH_NAME_B, NULL); // "flashx:bank0" /*wk@130330 --> test mfs function */ uchar result; // char pathname[261]; // ioctl(mfs_fs_ptr, IO_IOCTL_GET_CURRENT_DIR,(uint_32_ptr) pathname); // printf("The current directory is: %s\n", pathname); if (flashx_handle == NULL) { printf("\nUnable to open file %s", FLASH_NAME_B); _task_block(); } else { printf("\nFlash file %s opened", FLASH_NAME_B); } ioctl(flashx_handle, FLASH_IOCTL_ENABLE_SECTOR_CACHE, NULL);/////////////////////重要 // int len; // len = write(flashx_handle, "world",strlen("world")); // fseek(flashx_handle, 0, IO_SEEK_SET); // // fseek(flashx_handle, -32, IO_SEEK_END); // len = write(flashx_handle, "hello",strlen("hello")); /* wk --> 安装分区 */ error = _io_part_mgr_install(flashx_handle, flashx_partman_name, 0);// 分区管理 if (error!= MFS_NO_ERROR) { printf("\nError installing partition manager: %s", MFS_Error_text((uint_32)error)); _task_block(); } /* Open partition manager */ flashx_partman_handle = fopen(flashx_partman_name, NULL);// 打开分区 if (flashx_partman_handle == NULL) { error = ferror(flashx_partman_handle); printf("\nError opening partition manager: %s", MFS_Error_text((uint_32)error)); _task_block(); } /* Validate partition 1 */ param = 1; error = _io_ioctl(flashx_partman_handle, IO_IOCTL_VAL_PART, ¶m);// 控制分区 if (error == MQX_OK) { /* Install MFS over Flashx driver */ error = _io_mfs_install(flashx_partman_handle, flashx_filesystem_name, param);// 安装文件系统,基于分区 if (error != MFS_NO_ERROR) { printf("\nError initializing MFS: %s", MFS_Error_text((uint_32)error)); _task_block(); } } else { /* Install MFS over SD card driver */ error = _io_mfs_install(flashx_handle, flashx_filesystem_name, (_file_size)0);// 安装文件系统,无分区 if (error != MFS_NO_ERROR) { printf("\nError initializing MFS: %s", MFS_Error_text((uint_32)error)); _task_block(); } } /* Open file system */ flashx_file_handle = fopen(flashx_filesystem_name, NULL);// 打开文件系统 error = ferror (flashx_file_handle); if ((error != MFS_NO_ERROR) && (error != MFS_NOT_A_DOS_DISK)) { printf("\nError opening filesystem: %s", MFS_Error_text((uint_32)error)); _task_block(); } if ( error == MFS_NOT_A_DOS_DISK )////////////////// { printf("\nNOT A DOS DISK! You must format to continue."); } printf ("\nFlashx installed to %s", flashx_filesystem_name); ////////////////////////////////////////////////////////////////#dx 20130103 _task_block(); //_task_destroy(_task_get_id()); }
int mount_sdcard() { _mqx_uint param; _mqx_int error_code; //MQX_FILE_PTR com_handle, sdcard_handle, filesystem_handle, partman_handle; boolean readonly = /*FALSE*/TRUE; // char filesystem_name[] = "a:"; // char partman_name[] = "pm:"; printf("mounte sd card +\n"); _lwsem_wait(&SD_MFS_IO_SEM); if(sd_mounted) { _lwsem_post(&SD_MFS_IO_SEM); return 0; } do { /* 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 2.\n"); //_task_block(); continue; /* retry it */ } /* 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(); continue; /* retry it */ } /* Open partition manager */ partman_handle = fopen(partman_name, NULL); if (partman_handle == NULL) { error_code = ferror(partman_handle); printf("Error opening partition manager sd: %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(); continue; /* retry it */ } if ( error_code == MFS_NOT_A_DOS_DISK ) { printf("NOT A DOS DISK! You must format to continue.\n"); } printf ("\n SD card installed to \"%s\"\n", filesystem_name); if (readonly) { printf ("SD card is locked (read only).\n"); } mfs_dir_reset(); } while(0); sd_mounted = 1; printf("mounted sd card -\n"); _lwsem_post(&SD_MFS_IO_SEM); return 0; }
_mqx_int _io_pcb_mqxa_ioctl ( /* [IN] the file handle for the device */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the ioctl command */ _mqx_uint cmd, /* [IN] the ioctl parameters */ pointer param_ptr ) { /* Body */ TASK_TEMPLATE_STRUCT input_tt = { 0, _io_pcb_mqxa_read_task, IO_PCB_MQXA_STACK_SIZE, 0, "io_pcb_mqxa_read_task", 0, 0, 0}; TASK_TEMPLATE_STRUCT output_tt = { 0, _io_pcb_mqxa_write_task, IO_PCB_MQXA_STACK_SIZE, 0, "io_pcb_mqxa_write_task", 0, 0, 0}; IO_PCB_MQXA_INFO_STRUCT_PTR info_ptr; IO_PCB_STRUCT_PTR pcb_ptr; _mqx_uint result = MQX_OK; _psp_code_addr old_value; _psp_code_addr_ptr pc_ptr = (_psp_code_addr_ptr)param_ptr; _psp_data_addr_ptr pd_ptr = (_psp_data_addr_ptr)param_ptr; boolean _PTR_ bool_param_ptr; info_ptr = (IO_PCB_MQXA_INFO_STRUCT_PTR)fd_ptr->DEV_DATA_PTR; switch (cmd) { case IO_PCB_IOCTL_ENQUEUE_READQ: pcb_ptr = (IO_PCB_STRUCT_PTR)*pd_ptr; _queue_enqueue((QUEUE_STRUCT_PTR)&info_ptr->READ_QUEUE, (QUEUE_ELEMENT_STRUCT_PTR)&pcb_ptr->QUEUE); _lwsem_post(&info_ptr->READ_LWSEM); break; case IO_PCB_IOCTL_READ_CALLBACK_SET: old_value = (_psp_code_addr)info_ptr->READ_CALLBACK_FUNCTION; /* Start CR 398 */ info_ptr->CALLBACK_FD = fd_ptr; /* End CR */ info_ptr->READ_CALLBACK_FUNCTION = (void (_CODE_PTR_)( FILE_DEVICE_STRUCT_PTR, IO_PCB_STRUCT_PTR))*pc_ptr; *pc_ptr = old_value; break; case IO_PCB_IOCTL_SET_INPUT_POOL: old_value = (_psp_code_addr)info_ptr->READ_PCB_POOL; info_ptr->READ_PCB_POOL = (_io_pcb_pool_id)*pc_ptr; *pc_ptr = old_value; break; case IO_PCB_IOCTL_START: if (info_ptr->INPUT_TASK == MQX_NULL_TASK_ID) { input_tt.TASK_PRIORITY = info_ptr->INIT.INPUT_TASK_PRIORITY; input_tt.CREATION_PARAMETER = (uint_32)info_ptr; output_tt.TASK_PRIORITY = info_ptr->INIT.OUTPUT_TASK_PRIORITY; output_tt.CREATION_PARAMETER = (uint_32)info_ptr; info_ptr->INPUT_TASK = _task_create(0, 0, (uint_32)&input_tt); if (info_ptr->INPUT_TASK == MQX_NULL_TASK_ID){ return(_task_get_error()); } /* Endif */ info_ptr->OUTPUT_TASK = _task_create(0, 0, (uint_32)&output_tt); if (info_ptr->OUTPUT_TASK == MQX_NULL_TASK_ID){ return(_task_get_error()); } /* Endif */ }/* Endif */ break; case IO_PCB_IOCTL_UNPACKED_ONLY: bool_param_ptr = (boolean _PTR_)param_ptr; *bool_param_ptr = TRUE; break; default: result = _io_ioctl(info_ptr->FD, cmd, param_ptr); break; } /* Endswitch */ return result; } /* Endbody */
pointer usb_filesystem_install( pointer usb_handle, char_ptr block_device_name, char_ptr partition_manager_name, char_ptr file_system_name ) { uint_32 partition_number; uchar_ptr dev_info; int_32 error_code; USB_FILESYSTEM_STRUCT_PTR usb_fs_ptr; usb_fs_ptr = _mem_alloc_system_zero(sizeof(USB_FILESYSTEM_STRUCT)); if (usb_fs_ptr==NULL) { return NULL; } /* Install USB device */ error_code = _io_usb_mfs_install(block_device_name, 0, (pointer)usb_handle); if (error_code != MQX_OK) { printf("Error while installing USB device (0x%X)\n", error_code); return NULL; } usb_fs_ptr->DEV_NAME = block_device_name; /* Open the USB mass storage device */ _time_delay(500); // printf("open msd dev\n"); usb_fs_ptr->DEV_FD_PTR = fopen(block_device_name, 0); if (usb_fs_ptr->DEV_FD_PTR == NULL) { printf("Unable to open USB device\n"); /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,USB_DEV_OPEN_FAIL); return NULL; } _io_ioctl(usb_fs_ptr->DEV_FD_PTR, IO_IOCTL_SET_BLOCK_MODE, NULL); /* Get the vendor information and display it */ printf("\n************************************************************************\n"); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, USB_MFS_IOCTL_GET_VENDOR_INFO, &dev_info); printf("Vendor Information: %-1.8s Mass Storage Device\n",dev_info); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, USB_MFS_IOCTL_GET_PRODUCT_ID, &dev_info); printf("Product Identification: %-1.16s\n",dev_info); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, USB_MFS_IOCTL_GET_PRODUCT_REV, &dev_info); printf("Product Revision Level: %-1.4s\n",dev_info); printf("************************************************************************\n"); /* Try to install the partition manager */ // printf("_io_part_mgr_install\n"); error_code = _io_part_mgr_install(usb_fs_ptr->DEV_FD_PTR, partition_manager_name, 0); if (error_code != MFS_NO_ERROR) { printf("Error while initializing partition manager: %s\n", MFS_Error_text((uint_32)error_code)); /* usb_filesystem_uninstall */usb_filesystem_cancel_install(usb_fs_ptr,PARTITION_INIT_FAIL); return NULL; } usb_fs_ptr->PM_NAME = partition_manager_name; /* Open partition manager */ // printf("fopen partition\n"); usb_fs_ptr->PM_FD_PTR = fopen(partition_manager_name, NULL); if (usb_fs_ptr->PM_FD_PTR == NULL) { error_code = ferror(usb_fs_ptr->PM_FD_PTR); printf("Error while opening partition manager: %s\n", MFS_Error_text((uint_32)error_code)); /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,PARTITION_OPEN_FAIL); return NULL; } /* Select partition */ partition_number = 1; // printf("select partition\n"); error_code = _io_ioctl(usb_fs_ptr->PM_FD_PTR, IO_IOCTL_SEL_PART, &partition_number); if (error_code == MFS_NO_ERROR) { printf("Installing MFS over partition...\n"); /* Validate partition */ // printf("Validate partition\n"); error_code = _io_ioctl(usb_fs_ptr->PM_FD_PTR, IO_IOCTL_VAL_PART, NULL); if (error_code != MFS_NO_ERROR) { printf("Error while validating partition: %s\n", MFS_Error_text((uint32_t)error_code)); printf("Not installing MFS.\n"); /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,PARTITION_VALIDATE_FAIL); return NULL; } /* Install MFS over partition */ //printf("Install MFS over partition\n"); error_code = _io_mfs_install(usb_fs_ptr->PM_FD_PTR, file_system_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 USB device...\n"); /* Install MFS over USB device driver */ //printf("Install MFS over USB device driver\n"); error_code = _io_mfs_install(usb_fs_ptr->DEV_FD_PTR, file_system_name, 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) { usb_fs_ptr->FS_NAME = file_system_name; //printf("Open file system\n"); usb_fs_ptr->FS_FD_PTR = fopen(file_system_name, NULL); error_code = ferror(usb_fs_ptr->FS_FD_PTR); 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)); /* usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,MFS_OPEN_FAIL); return NULL; } printf("USB device installed to %s\n", file_system_name); } else { /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,MFS_INIT_FAIL); return NULL; } return (pointer)usb_fs_ptr; }