11.07.2015 Views

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ICCV8 <strong>for</strong> AVR – C Compiler <strong>for</strong> Atmel AVRCRC GenerationYou can have ICCV8 <strong>for</strong> AVR compute <strong>the</strong> CRC of your flash image <strong>and</strong> <strong>the</strong>nprogrammatically verify it in your program. ICCV8 <strong>for</strong> AVR calculates a 16-bit CRCusing a common algorithm (as a reference, please check <strong>the</strong> Wikipedia entry <strong>for</strong>“CRC16”). The AVR routine uses a table of 512 bytes <strong>and</strong> takes about 80 bytes ofcode. You may possibly reduce <strong>the</strong> total memory consumption by replacing <strong>the</strong> codethat does not use a table, but this will result in a slower running time.To use, specify in <strong>the</strong> Build Options - Target CRC edit box. The linkerstores <strong>the</strong> 4-byte CRC structure in :unsigned address;unsigned crc16; must not be used <strong>for</strong> o<strong>the</strong>r purpose. Typically you would specify <strong>the</strong>address 4 bytes be<strong>for</strong>e <strong>the</strong> end of <strong>the</strong> flash memory.CRC is computed from location 0 to .In your code, write#include ...__flash unsigned char *p = (__flash unsigned char *)0x????;unsigned int crc16;...crc16 = calc_crc16((__flash unsigned char *)0, p[0]);if (crc16 != p[1])// CRC mismatched0x???? is <strong>the</strong> same as in <strong>the</strong> -crc switch. The header file crc.hcontains <strong>the</strong> declaration <strong>for</strong> <strong>the</strong> calc_crc16 routine. Thus p[0] contains <strong>the</strong> address<strong>and</strong> p[1] contains <strong>the</strong> crc value calculated by <strong>the</strong> linker.Obviously CRC is not foolproof since any flash memory corruption means that <strong>the</strong>CRC checking code may not operate correctly. Never<strong>the</strong>less, CRC can be part of aquality assurance workflow.116

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!