Matthew Shoemaker / Mbed 2 deprecated USBHostLite

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usbhost_main.c Source File

usbhost_main.c

00001 /*
00002 **************************************************************************************************************
00003 *                                                 NXP USB Host Stack
00004 *
00005 *                                     (c) Copyright 2008, NXP SemiConductors
00006 *                                     (c) Copyright 2008, OnChip  Technologies LLC
00007 *                                                 All Rights Reserved
00008 *
00009 *                                                  www.nxp.com
00010 *                                               www.onchiptech.com
00011 *
00012 * File           : usbhost_main.c
00013 * Programmer(s)  : Ravikanth.P
00014 * Version        :
00015 *
00016 **************************************************************************************************************
00017 */
00018 
00019 /*
00020 **************************************************************************************************************
00021 *                                       INCLUDE HEADER FILES
00022 **************************************************************************************************************
00023 */
00024 
00025 #include  "usbhost_main.h"
00026 
00027 /*
00028 **************************************************************************************************************
00029 *                                          MAIN FUNCTION
00030 *
00031 * Description: This function is the main function where the execution begins
00032 *
00033 * Arguments  : None
00034 *
00035 * Returns    : 
00036 *
00037 **************************************************************************************************************
00038 */
00039 
00040 int main()
00041 {
00042     USB_INT32S  rc;
00043     USB_INT32U  numBlks, blkSize;
00044     USB_INT08U  inquiryResult[INQUIRY_LENGTH];
00045 
00046     SystemInit();                               /* initialize clocks */
00047  
00048     UART_Init(115200);         /* Initialize the serial port to view the log messages                       */
00049     Host_Init();               /* Initialize the lpc17xx host controller                                    */
00050     rc = Host_EnumDev();       /* Enumerate the device connected                                            */
00051     if (rc == OK) {
00052         /* Initialize the mass storage and scsi interfaces */
00053         rc = MS_Init( &blkSize, &numBlks, inquiryResult );
00054         if (rc == OK) {
00055             rc = FAT_Init();   /* Initialize the FAT16 file system                                          */
00056             if (rc == OK) {
00057                 Main_Copy();   /* Call the application                                                      */
00058             } else {
00059                 return (0);
00060             }
00061         } else {
00062             return (0);
00063         }
00064     } else {                            
00065         return (0);
00066     }
00067     while(1);
00068 }
00069 
00070 /*
00071 **************************************************************************************************************
00072 *                                      READ DATA FROM DISK
00073 *
00074 * Description: This function is used by the user to read data from the disk
00075 *
00076 * Arguments  : None
00077 *
00078 * Returns    : None
00079 *
00080 **************************************************************************************************************
00081 */
00082 
00083 void  Main_Read (void)
00084 {
00085     USB_INT32S  fdr;
00086     USB_INT32U  bytes_read;
00087     
00088 
00089     fdr = FILE_Open((char *)FILENAME_R, RDONLY);
00090     if (fdr > 0) {
00091         PRINT_Log("Reading from %s...\n", FILENAME_R);
00092         do {
00093             bytes_read = FILE_Read(fdr, UserBuffer, MAX_BUFFER_SIZE);
00094         } while (bytes_read);
00095 
00096         FILE_Close(fdr);
00097         PRINT_Log("Read Complete\n");
00098     } else {
00099         PRINT_Log("Could not open file %s\n", FILENAME_R);
00100         return;
00101     }
00102 }
00103 
00104 /*
00105 **************************************************************************************************************
00106 *                                      WRITE DATA TO DISK
00107 *
00108 * Description: This function is used by the user to write data to disk
00109 *
00110 * Arguments  : None
00111 *
00112 * Returns    : None
00113 *
00114 **************************************************************************************************************
00115 */
00116 
00117 void  Main_Write (void)
00118 {
00119     USB_INT32S  fdw;
00120     USB_INT32S  fdr;
00121     USB_INT32U  tot_bytes_written;
00122     USB_INT32U  bytes_written;
00123 
00124 
00125     fdr = FILE_Open((char *)FILENAME_R, RDONLY);
00126     if (fdr > 0) {
00127         FILE_Read(fdr, UserBuffer, MAX_BUFFER_SIZE);
00128         fdw = FILE_Open((char *)FILENAME_W, RDWR);
00129         if (fdw > 0) {
00130             tot_bytes_written = 0;
00131             PRINT_Log("Writing to %s...\n", FILENAME_W);
00132             do {
00133                 bytes_written = FILE_Write(fdw, UserBuffer, MAX_BUFFER_SIZE);
00134                 tot_bytes_written += bytes_written;
00135             } while (tot_bytes_written < WRITE_SIZE);
00136             FILE_Close(fdw);
00137             PRINT_Log("Write completed\n");
00138         } else {
00139             PRINT_Log("Could not open file %s\n", FILENAME_W);
00140             return;
00141         }
00142         FILE_Close(fdr);
00143     } else {
00144         PRINT_Log("Could not open file %s\n", FILENAME_R);
00145         return;
00146     }
00147 }
00148 
00149 /*
00150 **************************************************************************************************************
00151 *                                    COPYING A FILE
00152 *
00153 * Description: This function is used by the user to copy a file
00154 *
00155 * Arguments  : None
00156 *
00157 * Returns    : None
00158 *
00159 **************************************************************************************************************
00160 */
00161 
00162 void  Main_Copy (void)
00163 {
00164     USB_INT32S  fdr;
00165     USB_INT32S  fdw;
00166     USB_INT32U  bytes_read;
00167 
00168 
00169     fdr = FILE_Open((char *)FILENAME_R, RDONLY);
00170     if (fdr > 0) {
00171         fdw = FILE_Open((char *)FILENAME_W, RDWR);
00172         if (fdw > 0) {
00173             PRINT_Log("Copying from %s to %s...\n", FILENAME_R, FILENAME_W);
00174             do {
00175                 bytes_read = FILE_Read(fdr, UserBuffer, MAX_BUFFER_SIZE);
00176                 FILE_Write(fdw, UserBuffer, bytes_read);
00177             } while (bytes_read);
00178             FILE_Close(fdw);
00179         } else {
00180             PRINT_Log("Could not open file %s\n", FILENAME_W);
00181             return;
00182         }
00183         FILE_Close(fdr);
00184         PRINT_Log("Copy completed\n");
00185     } else {
00186         PRINT_Log("Could not open file %s\n", FILENAME_R);
00187         return;
00188     }
00189 }