Skip to content

Commit 69cb2e8

Browse files
anchaoxiaoxiang781216
authored andcommitted
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 <[email protected]>
1 parent ac12971 commit 69cb2e8

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

Diff for: system/ymodem/ymodem.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static int ymodem_recv_packet(FAR struct ymodem_ctx_s *ctx)
173173

174174
recv_crc = (ctx->data[ctx->packet_size] << 8) +
175175
ctx->data[ctx->packet_size + 1];
176-
cal_crc = crc16(ctx->data, ctx->packet_size);
176+
cal_crc = crc16xmodem(ctx->data, ctx->packet_size);
177177
if (cal_crc != recv_crc)
178178
{
179179
ymodem_debug("recv_packet: EBADMSG rcev:cal=0x%x 0x%x\n",
@@ -373,7 +373,7 @@ static int ymodem_send_file(FAR struct ymodem_ctx_s *ctx)
373373
ctx->header[1] = 0x00;
374374
ctx->header[2] = 0xff;
375375
ctx->packet_size = YMODEM_PACKET_SIZE;
376-
crc = crc16(ctx->data, ctx->packet_size);
376+
crc = crc16xmodem(ctx->data, ctx->packet_size);
377377
ctx->data[ctx->packet_size] = crc >> 8;
378378
ctx->data[ctx->packet_size + 1] = crc;
379379

@@ -438,7 +438,7 @@ static int ymodem_send_file(FAR struct ymodem_ctx_s *ctx)
438438
return ret;
439439
}
440440

441-
crc = crc16(ctx->data, ctx->packet_size);
441+
crc = crc16xmodem(ctx->data, ctx->packet_size);
442442
ctx->data[ctx->packet_size] = crc >> 8;
443443
ctx->data[ctx->packet_size + 1] = crc;
444444
send_packet_again:
@@ -512,7 +512,7 @@ static int ymodem_send_file(FAR struct ymodem_ctx_s *ctx)
512512
ctx->packet_type = YMODEM_DATA_PACKET;
513513
ctx->packet_size = YMODEM_PACKET_SIZE;
514514
memset(ctx->data, 0, YMODEM_PACKET_SIZE);
515-
crc = crc16(ctx->data, ctx->packet_size);
515+
crc = crc16xmodem(ctx->data, ctx->packet_size);
516516
ctx->data[ctx->packet_size] = crc >> 8;
517517
ctx->data[ctx->packet_size + 1] = crc;
518518
send_last_again:

Diff for: system/zmodem/zm_proto.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ int zm_senddata(FAR struct zm_state_s *pzm, FAR const uint8_t *buffer,
191191
{
192192
if (zbin == ZBIN)
193193
{
194-
crc = (uint32_t)crc16part(buffer, 1, (uint16_t)crc);
194+
crc = (uint32_t)crc16xmodempart(buffer, 1, (uint16_t)crc);
195195
}
196196
else /* zbin = ZBIN32 */
197197
{
@@ -209,7 +209,7 @@ int zm_senddata(FAR struct zm_state_s *pzm, FAR const uint8_t *buffer,
209209

210210
if (zbin == ZBIN)
211211
{
212-
crc = crc16part((FAR const uint8_t *)&term, 1, crc);
212+
crc = crc16xmodempart((FAR const uint8_t *)&term, 1, crc);
213213
}
214214
else
215215
{
@@ -283,12 +283,12 @@ int zm_sendhexhdr(FAR struct zm_state_s *pzm, int type,
283283

284284
/* type */
285285

286-
crc = crc16part((FAR const uint8_t *)&type, 1, 0);
286+
crc = crc16xmodempart((FAR const uint8_t *)&type, 1, 0);
287287
ptr = zm_puthex8(ptr, type);
288288

289289
/* f3/p0 f2/p1 f1/p2 f0/p3 */
290290

291-
crc = crc16part(buffer, 4, crc);
291+
crc = crc16xmodempart(buffer, 4, crc);
292292
for (i = 0; i < 4; i++)
293293
{
294294
ptr = zm_puthex8(ptr, *buffer++);
@@ -359,12 +359,12 @@ int zm_sendbin16hdr(FAR struct zm_state_s *pzm, int type,
359359

360360
/* type */
361361

362-
crc = crc16part((FAR const uint8_t *)&type, 1, 0);
362+
crc = crc16xmodempart((FAR const uint8_t *)&type, 1, 0);
363363
ptr = zm_putzdle(pzm, ptr, type);
364364

365365
/* f3/p0 f2/p1 f1/p2 f0/p3 */
366366

367-
crc = crc16part(buffer, 4, crc);
367+
crc = crc16xmodempart(buffer, 4, crc);
368368
for (i = 0; i < 4; i++)
369369
{
370370
ptr = zm_putzdle(pzm, ptr, *buffer++);

Diff for: system/zmodem/zm_send.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm)
993993
#endif
994994
if (!bcrc32)
995995
{
996-
crc = (uint32_t)crc16part(&ch, 1, (uint16_t)crc);
996+
crc = (uint32_t)crc16xmodempart(&ch, 1, (uint16_t)crc);
997997
}
998998
else
999999
{
@@ -1049,7 +1049,7 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm)
10491049

10501050
if (!bcrc32)
10511051
{
1052-
crc = (uint32_t)crc16part(&type, 1, (uint16_t)crc);
1052+
crc = (uint32_t)crc16xmodempart(&type, 1, (uint16_t)crc);
10531053
}
10541054
else
10551055
{

Diff for: system/zmodem/zm_state.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static int zm_hdrevent(FAR struct zm_state_s *pzm)
201201
* The header type, 4 data bytes, plus 2 CRC bytes
202202
*/
203203

204-
crc = crc16part(pzm->hdrdata, 7, 0);
204+
crc = crc16xmodempart(pzm->hdrdata, 7, 0);
205205
if (crc != 0)
206206
{
207207
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)
258258
{
259259
uint16_t crc;
260260

261-
crc = crc16part(pzm->pktbuf, pzm->pktlen, 0);
261+
crc = crc16xmodempart(pzm->pktbuf, pzm->pktlen, 0);
262262
if (crc != 0)
263263
{
264264
zmdbg("ERROR: ZBIN/ZHEX CRC16 failure: %04x vs 0000\n", crc);

0 commit comments

Comments
 (0)