libs/libc/crc16: Separate implementation of crc16xmodem from crc16

keep default crc16 catalogue for CRC-16/XMODEM

Mapping crc16 implement to crc16xmodem

crc16     -> crc16xmodem
crc16part -> crc16xmodempart

- CRC-16/ACORN, CRC-16/LTE, CRC-16/V-41-MSB, XMODEM, ZMODEM
poly: 0x1021 initial seed: 0x0000, xor output: 0x0000

: width=16
: poly=0x1021
: init=0x0000
: refin=false
: refout=false
: xorout=0x0000
: check=0x31c3
: residue=0x0000
: name="CRC-16/XMODEM"

https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-xmodem

Signed-off-by: chao an <anchao.archer@bytedance.com>
This commit is contained in:
chao an 2025-04-07 12:42:05 +08:00 committed by Xiang Xiao
parent ac12971ac9
commit 69cb2e89e9
4 changed files with 14 additions and 14 deletions

View file

@ -173,7 +173,7 @@ static int ymodem_recv_packet(FAR struct ymodem_ctx_s *ctx)
recv_crc = (ctx->data[ctx->packet_size] << 8) +
ctx->data[ctx->packet_size + 1];
cal_crc = crc16(ctx->data, ctx->packet_size);
cal_crc = crc16xmodem(ctx->data, ctx->packet_size);
if (cal_crc != recv_crc)
{
ymodem_debug("recv_packet: EBADMSG rcev:cal=0x%x 0x%x\n",
@ -373,7 +373,7 @@ send_start:
ctx->header[1] = 0x00;
ctx->header[2] = 0xff;
ctx->packet_size = YMODEM_PACKET_SIZE;
crc = crc16(ctx->data, ctx->packet_size);
crc = crc16xmodem(ctx->data, ctx->packet_size);
ctx->data[ctx->packet_size] = crc >> 8;
ctx->data[ctx->packet_size + 1] = crc;
@ -438,7 +438,7 @@ send_packet:
return ret;
}
crc = crc16(ctx->data, ctx->packet_size);
crc = crc16xmodem(ctx->data, ctx->packet_size);
ctx->data[ctx->packet_size] = crc >> 8;
ctx->data[ctx->packet_size + 1] = crc;
send_packet_again:
@ -512,7 +512,7 @@ send_last:
ctx->packet_type = YMODEM_DATA_PACKET;
ctx->packet_size = YMODEM_PACKET_SIZE;
memset(ctx->data, 0, YMODEM_PACKET_SIZE);
crc = crc16(ctx->data, ctx->packet_size);
crc = crc16xmodem(ctx->data, ctx->packet_size);
ctx->data[ctx->packet_size] = crc >> 8;
ctx->data[ctx->packet_size + 1] = crc;
send_last_again:

View file

@ -191,7 +191,7 @@ int zm_senddata(FAR struct zm_state_s *pzm, FAR const uint8_t *buffer,
{
if (zbin == ZBIN)
{
crc = (uint32_t)crc16part(buffer, 1, (uint16_t)crc);
crc = (uint32_t)crc16xmodempart(buffer, 1, (uint16_t)crc);
}
else /* zbin = ZBIN32 */
{
@ -209,7 +209,7 @@ int zm_senddata(FAR struct zm_state_s *pzm, FAR const uint8_t *buffer,
if (zbin == ZBIN)
{
crc = crc16part((FAR const uint8_t *)&term, 1, crc);
crc = crc16xmodempart((FAR const uint8_t *)&term, 1, crc);
}
else
{
@ -283,12 +283,12 @@ int zm_sendhexhdr(FAR struct zm_state_s *pzm, int type,
/* type */
crc = crc16part((FAR const uint8_t *)&type, 1, 0);
crc = crc16xmodempart((FAR const uint8_t *)&type, 1, 0);
ptr = zm_puthex8(ptr, type);
/* f3/p0 f2/p1 f1/p2 f0/p3 */
crc = crc16part(buffer, 4, crc);
crc = crc16xmodempart(buffer, 4, crc);
for (i = 0; i < 4; i++)
{
ptr = zm_puthex8(ptr, *buffer++);
@ -359,12 +359,12 @@ int zm_sendbin16hdr(FAR struct zm_state_s *pzm, int type,
/* type */
crc = crc16part((FAR const uint8_t *)&type, 1, 0);
crc = crc16xmodempart((FAR const uint8_t *)&type, 1, 0);
ptr = zm_putzdle(pzm, ptr, type);
/* f3/p0 f2/p1 f1/p2 f0/p3 */
crc = crc16part(buffer, 4, crc);
crc = crc16xmodempart(buffer, 4, crc);
for (i = 0; i < 4; i++)
{
ptr = zm_putzdle(pzm, ptr, *buffer++);

View file

@ -993,7 +993,7 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm)
#endif
if (!bcrc32)
{
crc = (uint32_t)crc16part(&ch, 1, (uint16_t)crc);
crc = (uint32_t)crc16xmodempart(&ch, 1, (uint16_t)crc);
}
else
{
@ -1049,7 +1049,7 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm)
if (!bcrc32)
{
crc = (uint32_t)crc16part(&type, 1, (uint16_t)crc);
crc = (uint32_t)crc16xmodempart(&type, 1, (uint16_t)crc);
}
else
{

View file

@ -201,7 +201,7 @@ static int zm_hdrevent(FAR struct zm_state_s *pzm)
* The header type, 4 data bytes, plus 2 CRC bytes
*/
crc = crc16part(pzm->hdrdata, 7, 0);
crc = crc16xmodempart(pzm->hdrdata, 7, 0);
if (crc != 0)
{
zmdbg("ERROR: ZBIN/ZHEX CRC16 failure: %04x vs 0000\n", crc);
@ -258,7 +258,7 @@ static int zm_dataevent(FAR struct zm_state_s *pzm)
{
uint16_t crc;
crc = crc16part(pzm->pktbuf, pzm->pktlen, 0);
crc = crc16xmodempart(pzm->pktbuf, pzm->pktlen, 0);
if (crc != 0)
{
zmdbg("ERROR: ZBIN/ZHEX CRC16 failure: %04x vs 0000\n", crc);