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

Committer:
Overdrivr
Date:
Wed Mar 09 12:15:13 2016 +0000
Revision:
5:cd94bb58e096
Release 1.0.3. See changelog here https://github.com/Overdrivr/Telemetry/releases/tag/1.0.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Overdrivr 5:cd94bb58e096 1 #include "crc16.h"
Overdrivr 5:cd94bb58e096 2
Overdrivr 5:cd94bb58e096 3 uint16_t crc16(uint8_t* data, uint32_t len)
Overdrivr 5:cd94bb58e096 4 {
Overdrivr 5:cd94bb58e096 5 uint16_t rem = 0;
Overdrivr 5:cd94bb58e096 6 uint16_t i=0;
Overdrivr 5:cd94bb58e096 7 for(i = 0 ; i < len ; i++)
Overdrivr 5:cd94bb58e096 8 {
Overdrivr 5:cd94bb58e096 9 rem = crc16_recursive(data[i],rem);
Overdrivr 5:cd94bb58e096 10 }
Overdrivr 5:cd94bb58e096 11 return rem;
Overdrivr 5:cd94bb58e096 12 }
Overdrivr 5:cd94bb58e096 13
Overdrivr 5:cd94bb58e096 14 uint16_t crc16_recursive(uint8_t byte, uint16_t remainder)
Overdrivr 5:cd94bb58e096 15 {
Overdrivr 5:cd94bb58e096 16 uint16_t n = 16;
Overdrivr 5:cd94bb58e096 17
Overdrivr 5:cd94bb58e096 18 remainder = remainder ^ (byte << (n-8));
Overdrivr 5:cd94bb58e096 19 uint16_t j = 0;
Overdrivr 5:cd94bb58e096 20 for(j = 1 ; j < 8 ; j++)
Overdrivr 5:cd94bb58e096 21 {
Overdrivr 5:cd94bb58e096 22 if(remainder & 0x8000)
Overdrivr 5:cd94bb58e096 23 {
Overdrivr 5:cd94bb58e096 24 remainder = (remainder << 1) ^ 0x1021;
Overdrivr 5:cd94bb58e096 25 }
Overdrivr 5:cd94bb58e096 26 else
Overdrivr 5:cd94bb58e096 27 {
Overdrivr 5:cd94bb58e096 28 remainder = remainder << 1;
Overdrivr 5:cd94bb58e096 29 }
Overdrivr 5:cd94bb58e096 30 remainder &= 0xffff;
Overdrivr 5:cd94bb58e096 31 }
Overdrivr 5:cd94bb58e096 32
Overdrivr 5:cd94bb58e096 33 return remainder;
Overdrivr 5:cd94bb58e096 34 }