comparison flash.c @ 70:aaf0603d7f88

Add routine to CRC a block of flash. Use it to verify a flash block write.
author Daniel O'Connor <darius@dons.net.au>
date Sun, 14 Apr 2013 22:53:50 +0930
parents cf9eb08b8b23
children 778adff8b569
comparison
equal deleted inserted replaced
69:cf9eb08b8b23 70:aaf0603d7f88
367 return 1; 367 return 1;
368 else 368 else
369 return 0; 369 return 0;
370 } 370 }
371 371
372 void 372 uint32_t
373 flashcrcblock(uint32_t addr, uint32_t len) {
374 assert(len % 4 == 0);
375
376 CRC_ResetDR();
377
378 flashstartread(addr);
379 for (int i = len; i > 0; i--)
380 CRC_CalcCRC(flashreadbyte());
381
382 flashstopread();
383
384 return CRC_GetCRC();
385 }
386
387 int
373 flashwriteblock(uint32_t addr, uint32_t len, void *_data) { 388 flashwriteblock(uint32_t addr, uint32_t len, void *_data) {
374 uint16_t *data = _data; 389 uint16_t *data = _data;
375 uint32_t crc; 390 uint32_t crc, vcrc;
376 391
377 printf("Writing %u bytes to 0x%06x\r\n", (uint)len, (uint)addr); 392 printf("Writing %u bytes to 0x%06x\r\n", (uint)len, (uint)addr);
378 393
379 /* Ensure data is 394 /* Ensure data is
380 * - 16 bit aligned 395 * - 16 bit aligned
411 /* Write CRC */ 426 /* Write CRC */
412 flashwriteword(crc); 427 flashwriteword(crc);
413 flashwriteword(crc >> 16); 428 flashwriteword(crc >> 16);
414 429
415 flashstopwrite(); 430 flashstopwrite();
416 } 431
432 /* Read back and check CRC */
433 vcrc = flashcrcblock(addr, len);
434 if (vcrc != crc)
435 return 1;
436 else
437 return 0;
438 }