forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation is based on the section 6.1 of the RFC 4880. Signed-off-by: Adrien Ricciardi <[email protected]>
- Loading branch information
1 parent
62fa3f7
commit 863f6af
Showing
4 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
zephyr_sources_ifdef(CONFIG_CRC | ||
crc32c_sw.c | ||
crc32_sw.c | ||
crc24_sw.c | ||
crc16_sw.c | ||
crc8_sw.c | ||
crc7_sw.c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2024 BayLibre. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/sys/crc.h> | ||
|
||
#define CRC24_PGP_POLY 0x01864cfbU | ||
|
||
uint32_t crc24_pgp(const uint8_t *data, size_t len) | ||
{ | ||
return crc24_pgp_update(CRC24_PGP_INITIAL_VALUE, data, len) & CRC24_FINAL_VALUE_MASK; | ||
} | ||
|
||
/* CRC-24 implementation from the section 6.1 of the RFC 4880 */ | ||
uint32_t crc24_pgp_update(uint32_t crc, const uint8_t *data, size_t len) | ||
{ | ||
int i; | ||
|
||
while (len--) { | ||
crc ^= (*data++) << 16; | ||
for (i = 0; i < 8; i++) { | ||
crc <<= 1; | ||
if (crc & 0x01000000) | ||
crc ^= CRC24_PGP_POLY; | ||
} | ||
} | ||
|
||
return crc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters