sitara_depot/components/free_rtos/ethernet_ip/eth_ip_checksum.c

22 lines
404 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* eth_ip_checksum.c
*
* Created on: 14 мар. 2023 г.
* Author: sychev
*/
#include "eth_ip_checksum.h"
#include "free_rtos/base/swap.h"
uint16_t eth_ip_calcChecksum(uint16_t * const data, uint32_t length)
{
uint32_t i, crc = 0;
for (i = 0 ; i < length; ++i ) {
crc += BASE_SWAP16(data[i]);
}
crc = (crc & 0xffff) + (crc >> 16);
return (uint16_t) (~crc);
}