Dependencies:   mbed

Revision:
7:d0f98d61ec4c
Parent:
6:fab999f0e93b
--- a/ISP.cpp	Fri Sep 30 12:03:31 2011 +0000
+++ b/ISP.cpp	Fri Sep 30 14:55:11 2011 +0000
@@ -13,19 +13,17 @@
     int sector[30] = {4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768};
     int startadd[30] = {0x0, 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0x7000, 0x8000, 0x9000, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, 0x10000, 0x18000, 0x20000, 0x28000, 0x30000, 0x38000, 0x40000, 0x48000, 0x50000, 0x58000, 0x60000, 0x68000, 0x70000, 0x78000};
     
-    pc.printf("**** LPCxxxx Flash Bootloader ****\n\n\r");
+    pc.printf("\n\r**** LPCxxxx Flash Bootloader ****\n\r");
     if(CheckTargetPresent()==0) {
         pc.printf("ERROR: Communication failed with board. Ensure board reset and P2.10 pulled low before running mbed program! If the setup is correct, try lowering the baud rate, set in main.cpp.\r\n\n");  
         exit(0);
     }
     
-    sprintf(strRAM, "W %d 1024", RAM);
-    
-    DIR *d = opendir("/fs");               // Opens the root directory of the local file system
+    DIR *d = opendir("/fs"); //Opens the root directory of the local file system
     struct dirent *p;
     
     fname[0] = 0;
-    while((p = readdir(d)) != NULL) {         // Print the names of the files in the local file system
+    while((p = readdir(d)) != NULL) { //Print the names of the files in the local file system
         if ( strcmp(p->d_name+strlen(p->d_name)-3,"LPC") == 0 )
         {
             strcpy(fname,"/fs/");
@@ -41,6 +39,7 @@
     } 
     else pc.printf("%s opened successfully\n\n\r", fname);
     
+    sprintf(strRAM, "W %d 1024", RAM);
     TargetSendStringAndCR(strRAM);
     readBytes(buf, 3);
     if ( strncmp(buf,str0, 1) != 0 )
@@ -171,17 +170,13 @@
     readBytes(buf, 3);
     if (strncmp(buf,str0,1) != 0 )
         return 0;
-    readBytes(buf, 12);
     
-    int length;
-    for (length=0; length<12; length++) {
-        if (buf[length]==0x0D)
-            break; 
+    readBytes(buf,1);    
+    while(buf[0]!=0x0D) {
+        id = (id*10)+buf[0]-'0';
+        readBytes(buf,1);
     }
-    
-    for (int i=0; i<length; i++)
-        id = (id*10)+buf[i]-'0';
-    //pc.printf("%d\n\r", id);
+    readBytes(buf,1);
     
     int finish = IDCheck(id);
     pc.printf("Chip to bootload: %s\n\r", strChipType);
@@ -204,6 +199,6 @@
     if ( strncmp(buf,str0,1) != 0 )
         return 0;
 
-    pc.printf("Ready to write to chip...\n\r");
+    pc.printf("Ready to write to chip\n\r");
     return 1;
 }
\ No newline at end of file