Dependencies:   mbed

Committer:
iva2k
Date:
Thu Jan 21 01:15:42 2010 +0000
Revision:
0:1802fb31b938

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iva2k 0:1802fb31b938 1 #include "mbed.h"
iva2k 0:1802fb31b938 2 #include "usbhost_inc.h"
iva2k 0:1802fb31b938 3
iva2k 0:1802fb31b938 4 void print_clock()
iva2k 0:1802fb31b938 5 {
iva2k 0:1802fb31b938 6 int Fin = 12000000; // 12MHz XTAL
iva2k 0:1802fb31b938 7
iva2k 0:1802fb31b938 8 printf("PLL Registers:\r\n");
iva2k 0:1802fb31b938 9 printf(" - PLL0STAT = 0x%08X\r\n", LPC_SC->PLL0STAT);
iva2k 0:1802fb31b938 10 printf(" - CLKCFG = 0x%08X\r\n", LPC_SC->CCLKCFG);
iva2k 0:1802fb31b938 11 printf(" - USBCLKCFG = 0x%08X\r\n", LPC_SC->USBCLKCFG);
iva2k 0:1802fb31b938 12
iva2k 0:1802fb31b938 13 int M = (LPC_SC->PLL0STAT & 0x7FFF) + 1;
iva2k 0:1802fb31b938 14 int N = ((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1;
iva2k 0:1802fb31b938 15 int CCLKDIV = LPC_SC->CCLKCFG + 1;
iva2k 0:1802fb31b938 16 int USBDIV = LPC_SC->USBCLKCFG + 1;
iva2k 0:1802fb31b938 17
iva2k 0:1802fb31b938 18 printf("Clock Variables:\r\n");
iva2k 0:1802fb31b938 19 printf(" - Fin = %d\r\n", Fin);
iva2k 0:1802fb31b938 20 printf(" - M = %d\r\n", M);
iva2k 0:1802fb31b938 21 printf(" - N = %d\r\n", N);
iva2k 0:1802fb31b938 22 printf(" - CCLKDIV = %d\r\n", CCLKDIV);
iva2k 0:1802fb31b938 23 printf(" - USBCLKDIV = %d\r\n", USBDIV);
iva2k 0:1802fb31b938 24
iva2k 0:1802fb31b938 25 int Fcco = (2 * M * 12000000) / N;
iva2k 0:1802fb31b938 26 int CCLK = Fcco / CCLKDIV;
iva2k 0:1802fb31b938 27
iva2k 0:1802fb31b938 28 printf("Clock Results:\r\n");
iva2k 0:1802fb31b938 29 printf(" - Fcco = %d\r\n", Fcco);
iva2k 0:1802fb31b938 30 printf(" - CCLK = %d\r\n", CCLK);
iva2k 0:1802fb31b938 31 printf(" - USB Clock = %d\r\n", Fcco / USBDIV);
iva2k 0:1802fb31b938 32 printf("System clock: %d\r\n", SystemCoreClock);
iva2k 0:1802fb31b938 33 }
iva2k 0:1802fb31b938 34
iva2k 0:1802fb31b938 35 /*
iva2k 0:1802fb31b938 36 **************************************************************************************************************
iva2k 0:1802fb31b938 37 * COPYING A FILE
iva2k 0:1802fb31b938 38 *
iva2k 0:1802fb31b938 39 * Description: This function is used by the user to copy a file
iva2k 0:1802fb31b938 40 *
iva2k 0:1802fb31b938 41 * Arguments : None
iva2k 0:1802fb31b938 42 *
iva2k 0:1802fb31b938 43 * Returns : None
iva2k 0:1802fb31b938 44 *
iva2k 0:1802fb31b938 45 **************************************************************************************************************
iva2k 0:1802fb31b938 46 */
iva2k 0:1802fb31b938 47
iva2k 0:1802fb31b938 48 #define FILENAME_R "input.txt"
iva2k 0:1802fb31b938 49 #define FILENAME_W "output.txt"
iva2k 0:1802fb31b938 50 #define MAX_BUFFER_SIZE (4000)
iva2k 0:1802fb31b938 51 void Main_Copy (void)
iva2k 0:1802fb31b938 52 {
iva2k 0:1802fb31b938 53 USB_INT32S fdr;
iva2k 0:1802fb31b938 54 USB_INT32S fdw;
iva2k 0:1802fb31b938 55 USB_INT32U bytes_read;
iva2k 0:1802fb31b938 56
iva2k 0:1802fb31b938 57
iva2k 0:1802fb31b938 58 fdr = FILE_Open((char *)FILENAME_R, RDONLY);
iva2k 0:1802fb31b938 59 if (fdr > 0) {
iva2k 0:1802fb31b938 60 fdw = FILE_Open((char *)FILENAME_W, RDWR);
iva2k 0:1802fb31b938 61 if (fdw > 0) {
iva2k 0:1802fb31b938 62 PRINT_Log("Copying from %s to %s...\r\n", FILENAME_R, FILENAME_W);
iva2k 0:1802fb31b938 63 do {
iva2k 0:1802fb31b938 64 bytes_read = FILE_Read(fdr, UserBuffer, MAX_BUFFER_SIZE);
iva2k 0:1802fb31b938 65 FILE_Write(fdw, UserBuffer, bytes_read);
iva2k 0:1802fb31b938 66 PRINT_Log(".");
iva2k 0:1802fb31b938 67 } while (bytes_read);
iva2k 0:1802fb31b938 68 PRINT_Log("\r\n");
iva2k 0:1802fb31b938 69 FILE_Close(fdw);
iva2k 0:1802fb31b938 70 } else {
iva2k 0:1802fb31b938 71 PRINT_Log("Could not open file %s\r\n", FILENAME_W);
iva2k 0:1802fb31b938 72 return;
iva2k 0:1802fb31b938 73 }
iva2k 0:1802fb31b938 74 FILE_Close(fdr);
iva2k 0:1802fb31b938 75 PRINT_Log("Copy completed\r\n");
iva2k 0:1802fb31b938 76 } else {
iva2k 0:1802fb31b938 77 PRINT_Log("Could not open file %s\r\n", FILENAME_R);
iva2k 0:1802fb31b938 78 return;
iva2k 0:1802fb31b938 79 }
iva2k 0:1802fb31b938 80 }
iva2k 0:1802fb31b938 81
iva2k 0:1802fb31b938 82 int main()
iva2k 0:1802fb31b938 83 {
iva2k 0:1802fb31b938 84 USB_INT32S rc;
iva2k 0:1802fb31b938 85 USB_INT32U numBlks, blkSize;
iva2k 0:1802fb31b938 86 USB_INT08U inquiryResult[INQUIRY_LENGTH];
iva2k 0:1802fb31b938 87
iva2k 0:1802fb31b938 88 print_clock();
iva2k 0:1802fb31b938 89 // UART_Init(115200); /* Initialize the serial port to view the log messages */
iva2k 0:1802fb31b938 90 Host_Init(); /* Initialize the host controller */
iva2k 0:1802fb31b938 91 rc = Host_EnumDev(); /* Enumerate the device connected */
iva2k 0:1802fb31b938 92 if (rc == OK) {
iva2k 0:1802fb31b938 93 /* Initialize the mass storage and scsi interfaces */
iva2k 0:1802fb31b938 94 rc = MS_Init( &blkSize, &numBlks, inquiryResult );
iva2k 0:1802fb31b938 95 if (rc == OK) {
iva2k 0:1802fb31b938 96 rc = FAT_Init(); /* Initialize the FAT16 file system */
iva2k 0:1802fb31b938 97 if (rc == OK) {
iva2k 0:1802fb31b938 98 Main_Copy(); /* Call the application */
iva2k 0:1802fb31b938 99 } else {
iva2k 0:1802fb31b938 100 printf("ERROR %d in FAT_Init()\r\n", rc);
iva2k 0:1802fb31b938 101 while ( 1 );
iva2k 0:1802fb31b938 102 // return (0);
iva2k 0:1802fb31b938 103 }
iva2k 0:1802fb31b938 104 printf("All OK in main()\r\n");
iva2k 0:1802fb31b938 105 } else {
iva2k 0:1802fb31b938 106 printf("ERROR %d in MS_Init()\r\n", rc);
iva2k 0:1802fb31b938 107 while ( 1 );
iva2k 0:1802fb31b938 108 // return (0);
iva2k 0:1802fb31b938 109 }
iva2k 0:1802fb31b938 110 } else {
iva2k 0:1802fb31b938 111 printf("ERROR %d in Host_EnumDev()\r\n", rc);
iva2k 0:1802fb31b938 112 while ( 1 );
iva2k 0:1802fb31b938 113 // return (0);
iva2k 0:1802fb31b938 114 }
iva2k 0:1802fb31b938 115 while(1);
iva2k 0:1802fb31b938 116 }