USBHostLite Read/Write calls

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

USBHostLite Read/Write calls

317 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tybls on Fri Jul 08 07:11:32 MST 2011
Previous posts on the subject.

http://knowledgebase.nxp.com/showthread.php?t=2064&highlight=USBHostLite

With the USBHostLite example I am a little confused on the
Main_Write (void)
Main_Read (void)
calls, Main_Write says "This function is used by the user to write data to disk" and Main_Read says "This function is used by the user to read data from the disk"

It is a little confusing because the function reads data from the flash drive (or whatever mass storage device you are using) and puts it in the UserBuffer.(correct me if I am wrong please). So in turn Main_Write should data from the UserBuffer to the flash drive(to my understanding from the description).

Then why does Main_Write call the the same functions as Main_Read?? It seems to me that in main() if you call Main_Read and then Wain_Write it should perform the same task(roughly) at Main_copy.

I am sure I just don't understanding the purpose of the Main_read/Main_Write functions as they are not doing do what I expected. Can anyone clear it up? Thanks!
0 Kudos
Reply
2 Replies

305 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tybls on Fri Jul 08 10:18:09 MST 2011
I had a feeling that the write function was not working properly as there is no reason to be opening the read file for a pure write command. Thanks zero.
0 Kudos
Reply

305 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Jul 08 08:17:59 MST 2011

Quote: tybls

I am sure I just don't understanding the purpose of the Main_read/Main_Write functions as they are not doing do what I expected. Can anyone clear it up? Thanks!



1. Main_Read is used to read your read file (FILENAME_R) to UserBuffer

2. Main_Copy is used to read your read file (FILENAME_R) to UserBuffer and then write UserBuffer to write file (FILENAME_W)

3. Main_Write is used to check if we have understood this and are able to reduce this nonsense to something working like:

void  Main_Write (unsigned char * string_to_write, int bytes_to_write)
{
 USB_INT32S  fdw;
 USB_INT32U  tot_bytes_written;
 USB_INT32U  bytes_written;

  fdw = FILE_Open(FILENAME_W, RDWR);
  if (fdw > 0)
  {
   tot_bytes_written = 0;
   PRINT_Log("Writing to %s...\n", FILENAME_W);
   bytes_written = FILE_Write(fdw, string_to_write, bytes_to_write);
   FILE_Close(fdw);
   PRINT_Log("Write completed\n");
  }
  else
  {
   PRINT_Log("Could not open file %s\n", FILENAME_W);
   return;
  }
}
0 Kudos
Reply