How to use IO_IOCTL_FIND_FIRST_FILE AND IO_IOCTL_FIND_NEXT_FILE to find files in a USB STICK

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use IO_IOCTL_FIND_FIRST_FILE AND IO_IOCTL_FIND_NEXT_FILE to find files in a USB STICK

740 Views
oliviachristyva
Contributor III

Hi guys,

Can anyone explain me how to use this IO_IOCTL_FIND_FIRST_FILE and IO_IOCTL_FIND_NEXT_FILE effectively to find files in a USB stick . The code I wrote with this is not working. This is the first time I am using this so I dont know how it works.

while ((len = _io_mfs_dir_read(dir_ptr, buffer, 100))>0){
strcpy(USB_Files,buffer);
//printf(USB_Files);

//List all files and subdirectories in a directory.


error_code = _io_ioctl(mfs_fd_ptr, IO_IOCTL_FIND_FIRST_FILE,
&search);
if (error_code != MQX_OK) {
return error_code;
printf("\n\rFile read unsuccessful");
}
else
printf("\r\nReading Files Successful");
error_code = _io_ioctl(mfs_fd_ptr, IO_IOCTL_FIND_NEXT_FILE,
&search_data);

}
}
_io_mfs_dir_close(dir_ptr);

Please help

Regards,

Olivia

0 Kudos
Reply
3 Replies

499 Views
oliviachristyva
Contributor III

Hi Daniel,

Thank you for your reply. But I cannot use that because I cannot use an sgtl5000 card. Now I am working with TWR-K65f180m .All I have is an SD card and an SDRAM. I need to write the audio file from the SDcard to the SDRAM and read it from it. My audio file size is 68KB . Is it possible to allocate a buffer to save this file??? . I mean is the file size a problem???.( WaveFile[686876];) . When I tried to save this file from USB directly to a buffer of size 686876 the code is not working. If this is wrong is there any other way to save it to a buffer. ??

Regards,

OLIVIA

0 Kudos
Reply

499 Views
oliviachristyva
Contributor III

Hi guys,

I found the solution and its working.

int error_code = MFS_NO_ERROR;
MFS_SEARCH_DATA search_data;
MFS_SEARCH_PARAM search;
char filepath [6]= "*.*";
MQX_FILE_PTR fs_ptr ;

fs_ptr = _io_get_first_valid_fs();

search.ATTRIBUTE = MFS_SEARCH_ANY;
search.WILDCARD = filepath;
search.SEARCH_DATA_PTR = &search_data;

error_code = _io_ioctl(fs_ptr, IO_IOCTL_FIND_FIRST_FILE,(uint_32*)&search);
while (error_code == MFS_NO_ERROR)
{
printf ("%-12.12s %6lu %02lu-%02lu-%04lu %02lu:%02lu:%02lu\n",
search_data.NAME,
search_data.FILE_SIZE,
(uint_32)(search_data.DATE & MFS_MASK_MONTH) >>MFS_SHIFT_MONTH,
(uint_32)(search_data.DATE & MFS_MASK_DAY) >>MFS_SHIFT_DAY,
(uint_32)((search_data.DATE & MFS_MASK_YEAR) >>MFS_SHIFT_YEAR) + 1980,
(uint_32)(search_data.TIME & MFS_MASK_HOURS) >>MFS_SHIFT_HOURS,
(uint_32)(search_data.TIME & MFS_MASK_MINUTES) >>MFS_SHIFT_MINUTES,
(uint_32)(search_data.TIME & MFS_MASK_SECONDS) << 1);
error_code = _io_ioctl(fs_ptr, IO_IOCTL_FIND_NEXT_FILE,(uint_32*)&search_data);
}
if( search_data.FILE_SIZE == 686876)
{
printf("\r\nFound Wave File : %-12.12s",search_data.NAME);

}

This gives me the required file name I need from a USB Stick.Hope it will help someone.

Now I need to read this wave file and save it to a buffer and pass it to the DMA buffer from which the audio goes to the DAC output . If anybody have ideas on this please help.

Regards,

Olivia

0 Kudos
Reply

499 Views
danielchen
NXP TechSupport
NXP TechSupport

HI Oliva:

Thank you for your sharing.

Regarding the wav file, I suggest you take a look at the sai_dma_demo , it may be help.

C:\Freescale\Freescale_MQX_4_2\mqx\examples\sai_dma_demo

Regards

Daniel

0 Kudos
Reply