| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
Generation Checking Program Memory Supports AVR® Controllers with Inst
Top Searches for this datasheetAVR236: Check Program Memory Generation Checking Program Memory Supports AVR® Controllers with Instruction Compact Code Size, Words (CRC Generation Checking) Requirement Checksum Stored EEPROM Execution Time: (AT90S8515 MHz) Bits Implementation, Easily Modified Bits Supports CRC-16 Standard, Easily Modified CRC-CCITT, CRC-32 8-bit RISC Microcontroller Application Note Introduction This application note describes (Cyclic Redundancy Check) theory implementation detect errors program memory Atmel microcontroller. widely used method detecting errors messages transmitted over noisy channels. standards secure microcontroller applications introduced method detecting errors Program memory microcontrollers. preferable implement calculation compact code with requirement data storage memory since frees resources actual application. implementation used this application note optimized minimum code size register usage. Figure Checking Program Memory Using 16-bit Divisor BYTE ADDRESS CODE 0011011 10011100 10000101 1011 ADDRESS 1FFF DIVISOR 10000000 00000101 Rev. 1143B-AVR-04/02 Theory Operation Checksums originally used communication through noisy channels. number (the checksum) computed function transmitted message. Receiver uses same function compute checksum, compares computed value with value received from transmitting side. this application note checksum constructed function code, stored internal EEPROM. microcontroller later same function calculate checksum code compare with appended checksum. Example: Checksum calculated summing numbers code: Code: Code with checksum: This checksum simply numbers code. second byte code corrupted from error will detected when original checksum compared with computed checksum. Original code with checksum: Code with error: Wrong first byte code corrupted from second byte corrupted from checksum will detect errors. Original code with checksum: Code with error: 39-> Correct problem with this checksum that simple. detect errors multiple bytes code detect errors checksum itself. This example shows that addition sufficient detect errors. calculations division instead addition calculate checksum code. principles similar, using division multiple errors burst errors will detected. algorithm treat Program memory enormous binary number, which divided another fixed binary number. remainder this division checksum. microcontroller will later perform same division compare remainder with calculated checksum. Note that division uses polynomial (modulo-2) arithmetic, which similar regular binary arithmetic, except uses carry. addition numbers with polynomial arithmetic simply XOR'ing data. Example: Addition polynomial arithmetic: 1011 0110 1101 0011 0110 0101 addition equal XOR'ing numbers. Lets define some properties polynomial arithmetic: M(x) G(x) R(x) k-bit number (the code checked). (n+1) number (the divisor polynom). n-bit number such that (the remainder checksum). R(x) M(x)*2 Q(x) Where Q(x) quotient G(x) G(x) AVR236 1143B-AVR-04/02 AVR236 Q(x) described M(x)*2 R(x) Q(x) M(x) equals adding zeros code G(x) M(x)*2 replaced last equation G(x) R(x) R(x) M(x)*2 +R(x) -=Q(x) Q(x)+ -G(x) G(x) G(x) Which equal Q(x) since divisor remainder same number, adding itself same XORing which results zero. Example Division hexadecimal number which binary number 0110 1010, divided with divisor 1001 hex). checksum will remainder operation 0110 1010 divided with 1001. First append zeros original message (where width divisor). 011010100000 1001 01100 0000 1101 1001 1000 1001 0011 0000 0110 0000 1100 1001 1010 1001 0110 0000 1100 1001 0101 Remainder Checksum Quotient Ignored checksum added original code. resulting code will 6A5. When this code checked, code checksum divided divisor. remainder this division zero errors occurred, non-zero otherwise. 1143B-AVR-04/02 Several standards used today detection. characteristics divisor vary from bits, ability detect errors varies with width divisor used. Some commonly used divisors are: CRC-16 1000 0000 0000 0101= 8005(hex) CRC-CCITT 0001 0000 0010 0001= 1021 (hex) CRC-32 0000 0100 1100 0001 0001 1101 1011 0111 04C11DB7 (hex) Observe that bits divisors, actual numbers bits bits divisor number bits always Software Description Main Program main program supplied show operation both generation checking. checksum generated stored internal EEPROM, read back before checking performed. most applications, checksum will generated programmer placed last address Program memory. Figure Flowchart Main Program START INITIALIZATION UNIT STACK POINTER PORTS STATUS CRC_GEN GENERATE CHECKSUM STORE CHECKSUM EEPROM STATUS LOAD CHECKSUM FROM EEPROM CRC_GEN CHECK CHECKSUM OUTPUT CHECKSUM AVR236 1143B-AVR-04/02 AVR236 main program call routine CRC_gen with Status Register 0x00 after reset generate checksum code. generated checksum stored EEPROM. Register 0xFF, value different from 0x00. Checksum Generation operation based principle rotating entire Program memory bit. shifted into Carry Flag. Carry Flag (one), word XOR'ed with divisor. Note that Program memory which shifted into Carry Flag also XOR'ed with divisor. Since they both result will always zero division ignored. Program memory zeros appended code. checksum resulting value complete operation. Checksum Checking same principles applied generation, generated checksum appended code, replacing zeros. result calculation including appended checksum zero errors occurred, non-zero otherwise. checksum included Program code, only checking part computation needs done Program code. same routine used both generation checking. Global Register Status loaded with 0x00 function call perform generation. Status Register loaded with value different from 0x00 function call, function performs checksum checking. flowchart shows flow crc_gen routine which includes both generation checking. flowcharts Figure Figure describes operation crc_gen subroutine. 1143B-AVR-04/02 Figure CRC_gen Subroutine START LOAD DIVISOR VALUE LOAD INITIAL VALUE LOAD BYTES CODE ROTATE WORD ROUTINE STATUS APPEND ZEROS APPEND CHECKSUM ROUTINE WORD ROUTINE RETURN AVR236 1143B-AVR-04/02 AVR236 Figure Rotate Subroutine START LOAD COUNTER (HEX) DECREMENT COUNTER COUNTER SHIFT DATA LEFT CARRY CODE DIVISOR RETURN Modifications code example implements 16-bit checksum CRC-16 computation. code easily modified support 32-bit checksum increasing size code buffer from bits, increasing size divisor from bits. checksum generated programmer placed last memory location, only code checking checksum needs included program. code "end" section routine removed. Please comments code. Some CRC-algorithms requires data register have initial value different from 0x00. other values used, initial values loaded into registers, replacing first instructions. comments code more information. algorithm reflected, which means that bytes shifted first instead MSB, routine support this replacing (Logical Shift Left) (Rotate Left) instructions with (Logical Shift Right) (Rotate Right) instructions. Other implementations computation exists with higher speed, most them lookup table increase speed operation. requirements such application makes them suitable more complex systems. 1143B-AVR-04/02 Resources Table Memory Usage Function main Code Size words Cycles Register Usage R16, R22, R23, R24, R17, R18, R19, R20, R21, R22, R30, R16, R23, R24, Interrupt Description Initialization Example Program Generate Check Checksum Write Checksum EEPROM Read Checksum from EEPROM CRC_gen words 700.000 (approx.) EEwrite words cycles EERread TOTAL words words cycles R16, R23, R24, Table Peripheral Usage Peripheral Bytes EEPROM Pins Description Storing Value Output Byte LEDs References Fred Halsall "Data Communication, Computer Networks Open Systems" 1992 Addison-Wesley Publishers Ross Williams "The Painless Guide Error Detection Algorithms" AVR236 1143B-AVR-04/02 AVR236 1143B-AVR-04/02 Atmel Headquarters Corporate Headquarters 2325 Orchard Parkway Jose, 95131 1(408) 441-0311 1(408) 487-2600 Atmel Operations Memory Atmel Corporate 2325 Orchard Parkway Jose, 95131 1(408) 436-4270 1(408) 436-4314 RF/Automotive Atmel Heilbronn Theresienstrasse Postfach 3535 74025 Heilbronn, Germany (49) 71-31-67-0 (49) 71-31-67-2340 Atmel Colorado Springs 1150 East Cheyenne Mtn. Blvd. Colorado Springs, 80906 1(719) 576-3300 1(719) 540-1759 Europe Atmel SarL Route Arsenaux Casa Postale CH-1705 Fribourg Switzerland (41) 26-426-5555 (41) 26-426-5500 Microcontrollers Atmel Corporate 2325 Orchard Parkway Jose, 95131 1(408) 436-4270 1(408) 436-4314 Atmel Nantes Chantrerie 70602 44306 Nantes Cedex France (33) 2-40-18-18-18 (33) 2-40-18-19-60 Asia Atmel Asia, Ltd. Room 1219 Chinachem Golden Plaza Mody Road Tsimhatsui East Kowloon Hong Kong (852) 2721-9778 (852) 2722-1369 Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom Atmel Grenoble Avenue Rochepleine 38521 Saint-Egreve Cedex, France (33) 4-76-58-30-00 (33) 4-76-58-34-80 ASIC/ASSP/Smart Cards Atmel Rousset Zone Industrielle 13106 Rousset Cedex, France (33) 4-42-53-60-00 (33) 4-42-53-60-01 Atmel Colorado Springs 1150 East Cheyenne Mtn. Blvd. Colorado Springs, 80906 1(719) 576-3300 1(719) 540-1759 Atmel Smart Card Scottish Enterprise Technology Park Maxwell Building East Kilbride 0QR, Scotland (44) 1355-803-000 (44) 1355-242-743 Japan Atmel Japan K.K. Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan (81) 3-3523-3551 (81) 3-3523-7581 literature@atmel.com Site http://www.atmel.com Atmel Corporation 2002. Atmel Corporation makes warranty products, other than those expressly contained Company's standard warranty which detailed Atmel's Terms Conditions located Company's site. Company assumes responsibility errors which appear this document, reserves right change devices specifications detailed herein time without notice, does make commitment update information contained herein. licenses patents other intellectual property Atmel granted Company connection with sale Atmel products, expressly implication. Atmel's products authorized critical components life support devices systems. ATMEL AVR® registered trademarks Atmel. Other terms product names trademarks others. Printed recycled paper. 1143B-AVR-04/02 Other recent searchesSPB-9605RWG - SPB-9605RWG SPB-9605RWG Datasheet QC962 - QC962 QC962 Datasheet OPA655 - OPA655 OPA655 Datasheet MSM85C154HVS - MSM85C154HVS MSM85C154HVS Datasheet MSM83C154S - MSM83C154S MSM83C154S Datasheet KSN-1827A+ - KSN-1827A+ KSN-1827A+ Datasheet CP-01021-1 - CP-01021-1 CP-01021-1 Datasheet
Privacy Policy | Disclaimer |