|
这两天将FileX的基础常用API都先测试下,方便我写教程:
下面是文件浏览功能实现:
- /*
- *********************************************************************************************************
- * 函 数 名: ViewRootDir
- * 功能说明: 显示SD卡根目录下的文件名
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- extern SD_HandleTypeDef uSdHandle;
- static void ViewRootDir(void)
- {
- UINT status;
- UINT attributes;
- ULONG size;
- UINT year;
- UINT month;
- UINT day;
- UINT hour;
- UINT minute;
- UINT second;
- UINT cnt;
- ULONG64 available_bytes;
-
-
- /* 挂载SD卡 */
- status = fx_media_open(&sdio_disk, "STM32_SDIO_DISK", _fx_stm32_sdio_driver, 0, media_memory, sizeof(media_memory));
- if (status != FX_SUCCESS)
- {
- printf("挂载文件系统失败 -- %d\r\n", status);
- return;
- }
-
-
- printf("属性 | 文件大小 | 短文件名 | 长文件名\r\n");
- for (cnt = 0; ;cnt++)
- {
- /* 读取目录项,索引会自动下移 */
- status = fx_directory_next_full_entry_find(&sdio_disk,
- entry_name,
- &attributes,
- &size,
- &year, &month, &day,
- &hour, &minute, &second);
-
- if (status != FX_SUCCESS || entry_name[0] == 0)
- {
- break;
- }
- if (entry_name[0] == '.')
- {
- continue;
- }
- /* 判断是文件还是子目录 */
- if (attributes & FX_DIRECTORY)
- {
- printf("目录 ");
- }
- else
- {
- printf("文件 ");
- }
- /* 打印文件大小, 最大4G */
- printf(" %10d", (int)size);
- printf(" %s\r\n", (char *)entry_name); /* 长文件名 */
- }
-
- /* 打印卡速度信息 */
- if(uSdHandle.SdCard.CardSpeed == CARD_NORMAL_SPEED)
- {
- printf("Normal Speed Card <12.5MB/S, MAX Clock < 25MHz, Spec Version 1.01\r\n");
- }
- else if (uSdHandle.SdCard.CardSpeed == CARD_HIGH_SPEED)
- {
- printf("High Speed Card <25MB/s, MAX Clock < 50MHz, Spec Version 2.00\r\n");
- }
- else if (uSdHandle.SdCard.CardSpeed == CARD_ULTRA_HIGH_SPEED)
- {
- printf("UHS-I SD Card <50MB/S for SDR50, DDR50 Cards, MAX Clock < 50MHz OR 100MHz\r\n");
- printf("UHS-I SD Card <104MB/S for SDR104, MAX Clock < 108MHz, Spec version 3.01\r\n");
- }
- /* SD卡剩余容量大小 */
- status = fx_media_extended_space_available(&sdio_disk, &available_bytes);
- if (status == FX_SUCCESS)
- {
- printf("SD卡剩余容量大小 -- %lldMB\r\n", available_bytes/1024/1024);
- }
-
- /* 卸载SD卡 */
- status = fx_media_close(&sdio_disk);
- if (status != FX_SUCCESS)
- {
- printf("卸载文件系统卸载失败 -- %d\r\n", status);
- }
- }
复制代码
|
|