Skip to content
Snippets Groups Projects
Commit ecb57f69 authored by Stefan Roese's avatar Stefan Roese Committed by Tom Rini
Browse files

lib/crc16.c: Rename cyg_crc16() to crc16_ccitt() and add crc start value


The original name of this function is unclear. This patch renames this
CRC16 function to crc16_ccitt() matching its name with its
implementation.

To make the usage of this function more flexible, lets add the CRC start
value as parameter to this function. This way it can be used by other
functions requiring different start values than 0 as well.

Signed-off-by: default avatarStefan Roese <sr@denx.de>
Reviewed-by: default avatarTom Rini <trini@konsulko.com>
parent 7109157f
No related branches found
No related tags found
No related merge requests found
...@@ -446,7 +446,7 @@ xyzModem_get_hdr (void) ...@@ -446,7 +446,7 @@ xyzModem_get_hdr (void)
/* Verify checksum/CRC */ /* Verify checksum/CRC */
if (xyz.crc_mode) if (xyz.crc_mode)
{ {
cksum = cyg_crc16 (xyz.pkt, xyz.len); cksum = crc16_ccitt(0, xyz.pkt, xyz.len);
if (cksum != ((xyz.crc1 << 8) | xyz.crc2)) if (cksum != ((xyz.crc1 << 8) | xyz.crc2))
{ {
ZM_DEBUG (zm_dprintf ("CRC error - recvd: %02x%02x, computed: %x\n", ZM_DEBUG (zm_dprintf ("CRC error - recvd: %02x%02x, computed: %x\n",
......
...@@ -91,7 +91,7 @@ static uint mmc_spi_readdata(struct mmc *mmc, void *xbuf, ...@@ -91,7 +91,7 @@ static uint mmc_spi_readdata(struct mmc *mmc, void *xbuf,
spi_xfer(spi, bsize * 8, NULL, buf, 0); spi_xfer(spi, bsize * 8, NULL, buf, 0);
spi_xfer(spi, 2 * 8, NULL, &crc, 0); spi_xfer(spi, 2 * 8, NULL, &crc, 0);
#ifdef CONFIG_MMC_SPI_CRC_ON #ifdef CONFIG_MMC_SPI_CRC_ON
if (be_to_cpu16(cyg_crc16(buf, bsize)) != crc) { if (be_to_cpu16(crc16_ccitt(0, buf, bsize)) != crc) {
debug("%s: CRC error\n", mmc->cfg->name); debug("%s: CRC error\n", mmc->cfg->name);
r1 = R1_SPI_COM_CRC; r1 = R1_SPI_COM_CRC;
break; break;
...@@ -120,7 +120,7 @@ static uint mmc_spi_writedata(struct mmc *mmc, const void *xbuf, ...@@ -120,7 +120,7 @@ static uint mmc_spi_writedata(struct mmc *mmc, const void *xbuf,
tok[1] = multi ? SPI_TOKEN_MULTI_WRITE : SPI_TOKEN_SINGLE; tok[1] = multi ? SPI_TOKEN_MULTI_WRITE : SPI_TOKEN_SINGLE;
while (bcnt--) { while (bcnt--) {
#ifdef CONFIG_MMC_SPI_CRC_ON #ifdef CONFIG_MMC_SPI_CRC_ON
crc = cpu_to_be16(cyg_crc16((u8 *)buf, bsize)); crc = cpu_to_be16(crc16_ccitt(0, (u8 *)buf, bsize));
#endif #endif
spi_xfer(spi, 2 * 8, tok, NULL, 0); spi_xfer(spi, 2 * 8, tok, NULL, 0);
spi_xfer(spi, bsize * 8, buf, NULL, 0); spi_xfer(spi, bsize * 8, buf, NULL, 0);
......
...@@ -62,8 +62,8 @@ cyg_ether_crc32(unsigned char *s, int len); ...@@ -62,8 +62,8 @@ cyg_ether_crc32(unsigned char *s, int len);
extern uint32_t extern uint32_t
cyg_ether_crc32_accumulate(uint32_t crc, unsigned char *s, int len); cyg_ether_crc32_accumulate(uint32_t crc, unsigned char *s, int len);
/* 16 bit CRC with polynomial x^16+x^12+x^5+1 */ /* 16 bit CRC with polynomial x^16+x^12+x^5+1 (CRC-CCITT) */
extern uint16_t cyg_crc16(unsigned char *s, int len); uint16_t crc16_ccitt(uint16_t crc_start, unsigned char *s, int len);
#endif /* _SERVICES_CRC_CRC_H_ */ #endif /* _SERVICES_CRC_CRC_H_ */
...@@ -61,12 +61,12 @@ static const uint16_t crc16_tab[] = { ...@@ -61,12 +61,12 @@ static const uint16_t crc16_tab[] = {
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
}; };
uint16_t cyg_crc16(unsigned char *buf, int len) uint16_t crc16_ccitt(uint16_t crc_start, unsigned char *buf, int len)
{ {
int i; int i;
uint16_t cksum; uint16_t cksum;
cksum = 0; cksum = crc_start;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
cksum = crc16_tab[((cksum>>8) ^ *buf++) & 0xff] ^ (cksum << 8); cksum = crc16_tab[((cksum>>8) ^ *buf++) & 0xff] ^ (cksum << 8);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment