First class data visualization and communication library with embedded devices. Code is maintained at github.com/Overdrivr/Telemetry

Dependents:   telemetry_car_demo telemetry_demo_FRDM-TFC telemetry_example_01 telemetry_indexed_data_demo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers crc16.cpp Source File

crc16.cpp

00001 #include "crc16.h"
00002 
00003 uint16_t crc16(uint8_t* data, uint32_t len)
00004 {
00005     uint16_t rem  = 0;
00006     uint16_t i=0;
00007     for(i = 0 ; i < len ; i++)
00008     {
00009         rem = crc16_recursive(data[i],rem);
00010     }
00011   return rem;
00012  }
00013 
00014 uint16_t crc16_recursive(uint8_t byte, uint16_t remainder)
00015 {
00016     uint16_t n = 16;
00017 
00018     remainder  = remainder ^ (byte << (n-8));
00019     uint16_t j = 0;
00020     for(j = 1 ; j < 8 ; j++)
00021     {
00022         if(remainder & 0x8000)
00023         {
00024             remainder  = (remainder << 1) ^ 0x1021;
00025         }
00026         else
00027         {
00028             remainder  = remainder << 1;
00029         }
00030         remainder &= 0xffff;
00031     }
00032 
00033     return remainder;
00034 }