USB Host Lite downloaded from NXP web site. Untested! Compiled, dropped on MBED, booted up, and get the console message that it is initializing the stack. I however do not have the ability to connect a USB Memory device to test it.

Dependencies:   mbed

Committer:
mshoemaker
Date:
Wed Jan 13 01:29:30 2010 +0000
Revision:
0:0826fcc5d020

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mshoemaker 0:0826fcc5d020 1 /*
mshoemaker 0:0826fcc5d020 2 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 3 * NXP USB Host Stack
mshoemaker 0:0826fcc5d020 4 *
mshoemaker 0:0826fcc5d020 5 * (c) Copyright 2008, NXP SemiConductors
mshoemaker 0:0826fcc5d020 6 * (c) Copyright 2008, OnChip Technologies LLC
mshoemaker 0:0826fcc5d020 7 * All Rights Reserved
mshoemaker 0:0826fcc5d020 8 *
mshoemaker 0:0826fcc5d020 9 * www.nxp.com
mshoemaker 0:0826fcc5d020 10 * www.onchiptech.com
mshoemaker 0:0826fcc5d020 11 *
mshoemaker 0:0826fcc5d020 12 * File : usbhost_main.c
mshoemaker 0:0826fcc5d020 13 * Programmer(s) : Ravikanth.P
mshoemaker 0:0826fcc5d020 14 * Version :
mshoemaker 0:0826fcc5d020 15 *
mshoemaker 0:0826fcc5d020 16 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 17 */
mshoemaker 0:0826fcc5d020 18
mshoemaker 0:0826fcc5d020 19 /*
mshoemaker 0:0826fcc5d020 20 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 21 * INCLUDE HEADER FILES
mshoemaker 0:0826fcc5d020 22 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 23 */
mshoemaker 0:0826fcc5d020 24
mshoemaker 0:0826fcc5d020 25 #include "usbhost_main.h"
mshoemaker 0:0826fcc5d020 26
mshoemaker 0:0826fcc5d020 27 /*
mshoemaker 0:0826fcc5d020 28 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 29 * MAIN FUNCTION
mshoemaker 0:0826fcc5d020 30 *
mshoemaker 0:0826fcc5d020 31 * Description: This function is the main function where the execution begins
mshoemaker 0:0826fcc5d020 32 *
mshoemaker 0:0826fcc5d020 33 * Arguments : None
mshoemaker 0:0826fcc5d020 34 *
mshoemaker 0:0826fcc5d020 35 * Returns :
mshoemaker 0:0826fcc5d020 36 *
mshoemaker 0:0826fcc5d020 37 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 38 */
mshoemaker 0:0826fcc5d020 39
mshoemaker 0:0826fcc5d020 40 int main()
mshoemaker 0:0826fcc5d020 41 {
mshoemaker 0:0826fcc5d020 42 USB_INT32S rc;
mshoemaker 0:0826fcc5d020 43 USB_INT32U numBlks, blkSize;
mshoemaker 0:0826fcc5d020 44 USB_INT08U inquiryResult[INQUIRY_LENGTH];
mshoemaker 0:0826fcc5d020 45
mshoemaker 0:0826fcc5d020 46 SystemInit(); /* initialize clocks */
mshoemaker 0:0826fcc5d020 47
mshoemaker 0:0826fcc5d020 48 UART_Init(115200); /* Initialize the serial port to view the log messages */
mshoemaker 0:0826fcc5d020 49 Host_Init(); /* Initialize the lpc17xx host controller */
mshoemaker 0:0826fcc5d020 50 rc = Host_EnumDev(); /* Enumerate the device connected */
mshoemaker 0:0826fcc5d020 51 if (rc == OK) {
mshoemaker 0:0826fcc5d020 52 /* Initialize the mass storage and scsi interfaces */
mshoemaker 0:0826fcc5d020 53 rc = MS_Init( &blkSize, &numBlks, inquiryResult );
mshoemaker 0:0826fcc5d020 54 if (rc == OK) {
mshoemaker 0:0826fcc5d020 55 rc = FAT_Init(); /* Initialize the FAT16 file system */
mshoemaker 0:0826fcc5d020 56 if (rc == OK) {
mshoemaker 0:0826fcc5d020 57 Main_Copy(); /* Call the application */
mshoemaker 0:0826fcc5d020 58 } else {
mshoemaker 0:0826fcc5d020 59 return (0);
mshoemaker 0:0826fcc5d020 60 }
mshoemaker 0:0826fcc5d020 61 } else {
mshoemaker 0:0826fcc5d020 62 return (0);
mshoemaker 0:0826fcc5d020 63 }
mshoemaker 0:0826fcc5d020 64 } else {
mshoemaker 0:0826fcc5d020 65 return (0);
mshoemaker 0:0826fcc5d020 66 }
mshoemaker 0:0826fcc5d020 67 while(1);
mshoemaker 0:0826fcc5d020 68 }
mshoemaker 0:0826fcc5d020 69
mshoemaker 0:0826fcc5d020 70 /*
mshoemaker 0:0826fcc5d020 71 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 72 * READ DATA FROM DISK
mshoemaker 0:0826fcc5d020 73 *
mshoemaker 0:0826fcc5d020 74 * Description: This function is used by the user to read data from the disk
mshoemaker 0:0826fcc5d020 75 *
mshoemaker 0:0826fcc5d020 76 * Arguments : None
mshoemaker 0:0826fcc5d020 77 *
mshoemaker 0:0826fcc5d020 78 * Returns : None
mshoemaker 0:0826fcc5d020 79 *
mshoemaker 0:0826fcc5d020 80 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 81 */
mshoemaker 0:0826fcc5d020 82
mshoemaker 0:0826fcc5d020 83 void Main_Read (void)
mshoemaker 0:0826fcc5d020 84 {
mshoemaker 0:0826fcc5d020 85 USB_INT32S fdr;
mshoemaker 0:0826fcc5d020 86 USB_INT32U bytes_read;
mshoemaker 0:0826fcc5d020 87
mshoemaker 0:0826fcc5d020 88
mshoemaker 0:0826fcc5d020 89 fdr = FILE_Open((char *)FILENAME_R, RDONLY);
mshoemaker 0:0826fcc5d020 90 if (fdr > 0) {
mshoemaker 0:0826fcc5d020 91 PRINT_Log("Reading from %s...\n", FILENAME_R);
mshoemaker 0:0826fcc5d020 92 do {
mshoemaker 0:0826fcc5d020 93 bytes_read = FILE_Read(fdr, UserBuffer, MAX_BUFFER_SIZE);
mshoemaker 0:0826fcc5d020 94 } while (bytes_read);
mshoemaker 0:0826fcc5d020 95
mshoemaker 0:0826fcc5d020 96 FILE_Close(fdr);
mshoemaker 0:0826fcc5d020 97 PRINT_Log("Read Complete\n");
mshoemaker 0:0826fcc5d020 98 } else {
mshoemaker 0:0826fcc5d020 99 PRINT_Log("Could not open file %s\n", FILENAME_R);
mshoemaker 0:0826fcc5d020 100 return;
mshoemaker 0:0826fcc5d020 101 }
mshoemaker 0:0826fcc5d020 102 }
mshoemaker 0:0826fcc5d020 103
mshoemaker 0:0826fcc5d020 104 /*
mshoemaker 0:0826fcc5d020 105 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 106 * WRITE DATA TO DISK
mshoemaker 0:0826fcc5d020 107 *
mshoemaker 0:0826fcc5d020 108 * Description: This function is used by the user to write data to disk
mshoemaker 0:0826fcc5d020 109 *
mshoemaker 0:0826fcc5d020 110 * Arguments : None
mshoemaker 0:0826fcc5d020 111 *
mshoemaker 0:0826fcc5d020 112 * Returns : None
mshoemaker 0:0826fcc5d020 113 *
mshoemaker 0:0826fcc5d020 114 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 115 */
mshoemaker 0:0826fcc5d020 116
mshoemaker 0:0826fcc5d020 117 void Main_Write (void)
mshoemaker 0:0826fcc5d020 118 {
mshoemaker 0:0826fcc5d020 119 USB_INT32S fdw;
mshoemaker 0:0826fcc5d020 120 USB_INT32S fdr;
mshoemaker 0:0826fcc5d020 121 USB_INT32U tot_bytes_written;
mshoemaker 0:0826fcc5d020 122 USB_INT32U bytes_written;
mshoemaker 0:0826fcc5d020 123
mshoemaker 0:0826fcc5d020 124
mshoemaker 0:0826fcc5d020 125 fdr = FILE_Open((char *)FILENAME_R, RDONLY);
mshoemaker 0:0826fcc5d020 126 if (fdr > 0) {
mshoemaker 0:0826fcc5d020 127 FILE_Read(fdr, UserBuffer, MAX_BUFFER_SIZE);
mshoemaker 0:0826fcc5d020 128 fdw = FILE_Open((char *)FILENAME_W, RDWR);
mshoemaker 0:0826fcc5d020 129 if (fdw > 0) {
mshoemaker 0:0826fcc5d020 130 tot_bytes_written = 0;
mshoemaker 0:0826fcc5d020 131 PRINT_Log("Writing to %s...\n", FILENAME_W);
mshoemaker 0:0826fcc5d020 132 do {
mshoemaker 0:0826fcc5d020 133 bytes_written = FILE_Write(fdw, UserBuffer, MAX_BUFFER_SIZE);
mshoemaker 0:0826fcc5d020 134 tot_bytes_written += bytes_written;
mshoemaker 0:0826fcc5d020 135 } while (tot_bytes_written < WRITE_SIZE);
mshoemaker 0:0826fcc5d020 136 FILE_Close(fdw);
mshoemaker 0:0826fcc5d020 137 PRINT_Log("Write completed\n");
mshoemaker 0:0826fcc5d020 138 } else {
mshoemaker 0:0826fcc5d020 139 PRINT_Log("Could not open file %s\n", FILENAME_W);
mshoemaker 0:0826fcc5d020 140 return;
mshoemaker 0:0826fcc5d020 141 }
mshoemaker 0:0826fcc5d020 142 FILE_Close(fdr);
mshoemaker 0:0826fcc5d020 143 } else {
mshoemaker 0:0826fcc5d020 144 PRINT_Log("Could not open file %s\n", FILENAME_R);
mshoemaker 0:0826fcc5d020 145 return;
mshoemaker 0:0826fcc5d020 146 }
mshoemaker 0:0826fcc5d020 147 }
mshoemaker 0:0826fcc5d020 148
mshoemaker 0:0826fcc5d020 149 /*
mshoemaker 0:0826fcc5d020 150 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 151 * COPYING A FILE
mshoemaker 0:0826fcc5d020 152 *
mshoemaker 0:0826fcc5d020 153 * Description: This function is used by the user to copy a file
mshoemaker 0:0826fcc5d020 154 *
mshoemaker 0:0826fcc5d020 155 * Arguments : None
mshoemaker 0:0826fcc5d020 156 *
mshoemaker 0:0826fcc5d020 157 * Returns : None
mshoemaker 0:0826fcc5d020 158 *
mshoemaker 0:0826fcc5d020 159 **************************************************************************************************************
mshoemaker 0:0826fcc5d020 160 */
mshoemaker 0:0826fcc5d020 161
mshoemaker 0:0826fcc5d020 162 void Main_Copy (void)
mshoemaker 0:0826fcc5d020 163 {
mshoemaker 0:0826fcc5d020 164 USB_INT32S fdr;
mshoemaker 0:0826fcc5d020 165 USB_INT32S fdw;
mshoemaker 0:0826fcc5d020 166 USB_INT32U bytes_read;
mshoemaker 0:0826fcc5d020 167
mshoemaker 0:0826fcc5d020 168
mshoemaker 0:0826fcc5d020 169 fdr = FILE_Open((char *)FILENAME_R, RDONLY);
mshoemaker 0:0826fcc5d020 170 if (fdr > 0) {
mshoemaker 0:0826fcc5d020 171 fdw = FILE_Open((char *)FILENAME_W, RDWR);
mshoemaker 0:0826fcc5d020 172 if (fdw > 0) {
mshoemaker 0:0826fcc5d020 173 PRINT_Log("Copying from %s to %s...\n", FILENAME_R, FILENAME_W);
mshoemaker 0:0826fcc5d020 174 do {
mshoemaker 0:0826fcc5d020 175 bytes_read = FILE_Read(fdr, UserBuffer, MAX_BUFFER_SIZE);
mshoemaker 0:0826fcc5d020 176 FILE_Write(fdw, UserBuffer, bytes_read);
mshoemaker 0:0826fcc5d020 177 } while (bytes_read);
mshoemaker 0:0826fcc5d020 178 FILE_Close(fdw);
mshoemaker 0:0826fcc5d020 179 } else {
mshoemaker 0:0826fcc5d020 180 PRINT_Log("Could not open file %s\n", FILENAME_W);
mshoemaker 0:0826fcc5d020 181 return;
mshoemaker 0:0826fcc5d020 182 }
mshoemaker 0:0826fcc5d020 183 FILE_Close(fdr);
mshoemaker 0:0826fcc5d020 184 PRINT_Log("Copy completed\n");
mshoemaker 0:0826fcc5d020 185 } else {
mshoemaker 0:0826fcc5d020 186 PRINT_Log("Could not open file %s\n", FILENAME_R);
mshoemaker 0:0826fcc5d020 187 return;
mshoemaker 0:0826fcc5d020 188 }
mshoemaker 0:0826fcc5d020 189 }