Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: telemetry_car_demo telemetry_demo_FRDM-TFC telemetry_example_01 telemetry_indexed_data_demo ... more
c_api/crc16.cpp
- Committer:
- Overdrivr
- Date:
- 2016-02-22
- Revision:
- 4:8e3de1a314e1
- Parent:
- 3:37d2d127bc83
File content as of revision 4:8e3de1a314e1:
#include "crc16.h"
uint16_t crc16(uint8_t* data, uint32_t len)
{
uint16_t rem = 0;
for(uint16_t i = 0 ; i < len ; i++)
{
rem = crc16_recursive(data[i],rem);
}
return rem;
}
uint16_t crc16_recursive(uint8_t byte, uint16_t remainder)
{
uint16_t n = 16;
remainder = remainder ^ (byte << (n-8));
for(uint16_t j = 1 ; j < 8 ; j++)
{
if(remainder & 0x8000)
{
remainder = (remainder << 1) ^ 0x1021;
}
else
{
remainder = remainder << 1;
}
remainder &= 0xffff;
}
return remainder;
}