changeset 69:cf9eb08b8b23

CRC a word at a time rather than the whole block (since we are reading/writing a word at a time).
author Daniel O'Connor <darius@dons.net.au>
date Sun, 14 Apr 2013 22:52:21 +0930
parents cc998b0b2bae
children aaf0603d7f88
files flash.c
diffstat 1 files changed, 15 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/flash.c	Sun Apr 14 16:07:29 2013 +0930
+++ b/flash.c	Sun Apr 14 22:52:21 2013 +0930
@@ -346,8 +346,10 @@
     assert(len % 4 == 0);
 
     flashstartread(addr);
+   CRC_ResetDR();
     for (int i = len; i > 0; i--) {
 	*data = flashreadbyte();
+	CRC_CalcCRC(*data);
 	data++;
     }
 
@@ -358,16 +360,13 @@
 
     flashstopread();
 
-   /* Calculate CRC */
-   CRC_ResetDR();
-   ramcrc = CRC_CalcBlockCRC((uint32_t *)_data, len / 4);
-
-   /* printf("RAM CRC 0x%08x Flash CRC 0x%08x\r\n", (uint)ramcrc, (uint)flashcrc); */
-   
-   if (ramcrc == flashcrc)
-       return 1;
-   else
-       return 0;
+    ramcrc = CRC_GetCRC();
+    
+    /* printf("RAM CRC 0x%08x Flash CRC 0x%08x\r\n", (uint)ramcrc, (uint)flashcrc); */
+    if (ramcrc == flashcrc)
+	return 1;
+    else
+	return 0;
 }
 
 void
@@ -392,20 +391,22 @@
     /* Erase sector */
     flash4kerase(addr);
  
+   CRC_ResetDR();
+
     /* Write data */
    for (uint i = 0; i < len / 2; i++) {
 	if (i == 0)
 	    flashstartwrite(addr, *data);
 	else
 	    flashwriteword(*data);
+	CRC_CalcCRC(*data);
 	data++;
     }
 
    /* Calculate CRC */
-   CRC_ResetDR();
-   crc = CRC_CalcBlockCRC((uint32_t *)_data, len / 4);
-	
-   printf("CRC is 0x%08x\r\n", (uint)crc);
+   crc = CRC_GetCRC();
+   
+   //printf("CRC is 0x%08x\r\n", (uint)crc);
    
    /* Write CRC */
    flashwriteword(crc);