Lely core libraries  2.2.5
crc.c File Reference

This file is part of the CANopen library; it contains the implementation of the Cyclic Redundancy Check (CRC) function. More...

#include "co.h"
#include <lely/co/crc.h>
Include dependency graph for crc.c:

Go to the source code of this file.

Functions

uint_least16_t co_crc (uint_least16_t crc, const uint_least8_t *bp, size_t n)
 Computes a CRC-16 checksum. More...
 

Detailed Description

This file is part of the CANopen library; it contains the implementation of the Cyclic Redundancy Check (CRC) function.

See also
lely/co/crc.h
Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file crc.c.

Function Documentation

◆ co_crc()

uint_least16_t co_crc ( uint_least16_t  crc,
const uint_least8_t *  bp,
size_t  n 
)

Computes a CRC-16 checksum.

This is an implementation of the CRC16-CCITT specification based on the 0x1021 generator polynomial. It uses a table with precomputed values for efficiency.

As per section 7.2.4.3.16 in CiA 301 version 4.2.0, the CRC of "123456789" (with an initial value of 0x0000) is 0x31c3.

Parameters
crcthe initial value.
bpa pointer to the bytes to be hashed.
nthe number of bytes to hash.
Returns
the updated CRC.

Definition at line 28 of file crc.c.