Skip to content

Commit ea2d785

Browse files
ndrs-pstaescolar
authored andcommitted
modem: cmux: replace crc8 with crc8_rohc for FCS calculation
To improve performance in FCS calculation, this commit replaces the usage of the generic `crc8` function with the specific `crc8_rohc` function in `modem_cmux.c`. The `crc8_rohc` function utilizes a small table approach, enhancing the efficiency of CRC-8/ROHC variant calculations while optimizing memory usage. Signed-off-by: Pisit Sawangvonganan <[email protected]>
1 parent d6024c5 commit ea2d785

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

subsys/modem/modem_cmux.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,13 @@ static uint16_t modem_cmux_transmit_frame(struct modem_cmux *cmux,
295295
}
296296

297297
/* Compute FCS for the header (exclude SOF) */
298-
fcs = crc8(&buf[1], (buf_idx - 1), MODEM_CMUX_FCS_POLYNOMIAL, MODEM_CMUX_FCS_INIT_VALUE,
299-
true);
298+
fcs = crc8_rohc(MODEM_CMUX_FCS_INIT_VALUE, &buf[1], (buf_idx - 1));
300299

301300
/* FCS final */
302301
if (frame->type == MODEM_CMUX_FRAME_TYPE_UIH) {
303302
fcs = 0xFF - fcs;
304303
} else {
305-
fcs = 0xFF - crc8(frame->data, data_len, MODEM_CMUX_FCS_POLYNOMIAL, fcs, true);
304+
fcs = 0xFF - crc8_rohc(fcs, frame->data, data_len);
306305
}
307306

308307
/* Frame header */
@@ -845,16 +844,12 @@ static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t by
845844
}
846845

847846
/* Compute FCS */
847+
fcs = crc8_rohc(MODEM_CMUX_FCS_INIT_VALUE, cmux->frame_header,
848+
cmux->frame_header_len);
848849
if (cmux->frame.type == MODEM_CMUX_FRAME_TYPE_UIH) {
849-
fcs = 0xFF - crc8(cmux->frame_header, cmux->frame_header_len,
850-
MODEM_CMUX_FCS_POLYNOMIAL, MODEM_CMUX_FCS_INIT_VALUE,
851-
true);
850+
fcs = 0xFF - fcs;
852851
} else {
853-
fcs = crc8(cmux->frame_header, cmux->frame_header_len,
854-
MODEM_CMUX_FCS_POLYNOMIAL, MODEM_CMUX_FCS_INIT_VALUE, true);
855-
856-
fcs = 0xFF - crc8(cmux->frame.data, cmux->frame.data_len,
857-
MODEM_CMUX_FCS_POLYNOMIAL, fcs, true);
852+
fcs = 0xFF - crc8_rohc(fcs, cmux->frame.data, cmux->frame.data_len);
858853
}
859854

860855
/* Validate FCS */

0 commit comments

Comments
 (0)