Ika Shouyu Poppoyaki - LPC82x supported

Dependencies:   MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Revision:
41:74b9ff21098f
Parent:
39:f68f9fa1e88e
--- a/isp.cpp	Sun Sep 29 03:57:02 2013 +0000
+++ b/isp.cpp	Tue Nov 19 23:53:20 2013 +0000
@@ -10,6 +10,8 @@
 #include    "isp.h"
 #include    "_user_settings.h"
 
+#define     CRP_WORD_OFFSET     0x2FC
+
 
 BusOut          leds( LED4, LED3, LED2, LED1 );
 Ticker          success;
@@ -46,22 +48,26 @@
     }
 
     data_size   = file_size( fp );
-    
+
     if ( !data_size )
         return ( ERROR_DATA_SIZE_ZERO );
-        
+
     last_sector = (data_size - 1) / tpp->sector_size;
 
-    if ( crp_check( fp ) ) {
-        printf( "  the CRP is enabled in the data source file\r\n" );
+    if ( data_size < (CRP_WORD_OFFSET + sizeof( unsigned int )) ) {
+        printf( "  CRP check is not performed because data size is less than 0x300(768) bytes\r\n" );
+    } else {
+        if ( crp_check( fp ) ) {
+            printf( "  the CRP is enabled in the data source file\r\n" );
 
 #ifdef CHECK_CRP_CODE
-        printf( "  aborting execution by CRP warning\r\n" );
+            printf( "  aborting execution by CRP warning\r\n" );
 
-        return ( WARNING_CRP_CODE_DETECTED );
+            return ( WARNING_CRP_CODE_DETECTED );
 #else
-        printf( "  this program continues to write the CRP enabled binary into the target flash\r\n" );
+            printf( "  this program continues to write the CRP enabled binary into the target flash\r\n" );
 #endif
+        }
     }
 
     printf( "  data size = %d bytes, it takes %d secotrs in flash area\r\n", data_size, last_sector + 1 );
@@ -110,7 +116,7 @@
     int     size;
 
     fseek( fp, 0, SEEK_END ); // seek to end of file
-    size    = ftell( fp );       // get current file pointer
+    size    = ftell( fp );    // get current file pointer
     fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
 
     return size;
@@ -138,7 +144,7 @@
             crp = 0x0;  //  no CRP code detected
             break;
     }
-    
+
     return ( crp );
 }
 
@@ -147,7 +153,7 @@
 {
     unsigned int    crp;
 
-    fseek( fp, 0x2FC, SEEK_SET ); // seek back to beginning of file
+    fseek( fp, CRP_WORD_OFFSET, SEEK_SET ); // seek to 0x2FC (764th byte)
 
     if ( 1 != fread( &crp, sizeof( crp ), 1, fp ) )
         return ( CRP_CHECK_ERROR );