This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push: new 69cb2e89e libs/libc/crc16: Separate implementation of crc16xmodem from crc16 69cb2e89e is described below commit 69cb2e89e93c426fa2ddd345d34b440bec03b4a9 Author: chao an <anchao.arc...@bytedance.com> AuthorDate: Mon Apr 7 12:42:05 2025 +0800 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.arc...@bytedance.com> --- system/ymodem/ymodem.c | 8 ++++---- system/zmodem/zm_proto.c | 12 ++++++------ system/zmodem/zm_send.c | 4 ++-- system/zmodem/zm_state.c | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/system/ymodem/ymodem.c b/system/ymodem/ymodem.c index 48d1320dc..79c131f37 100644 --- a/system/ymodem/ymodem.c +++ b/system/ymodem/ymodem.c @@ -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: diff --git a/system/zmodem/zm_proto.c b/system/zmodem/zm_proto.c index c5600de62..83e8887f2 100644 --- a/system/zmodem/zm_proto.c +++ b/system/zmodem/zm_proto.c @@ -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++); diff --git a/system/zmodem/zm_send.c b/system/zmodem/zm_send.c index 059a7d14a..51ab25a0e 100644 --- a/system/zmodem/zm_send.c +++ b/system/zmodem/zm_send.c @@ -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 { diff --git a/system/zmodem/zm_state.c b/system/zmodem/zm_state.c index d3add1c6e..2a8bc7fa5 100644 --- a/system/zmodem/zm_state.c +++ b/system/zmodem/zm_state.c @@ -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);