Skip to content

Commit d55b7be

Browse files
kartbennashif
authored andcommitted
doc: services: crc: add CRC doc page
Add a page for documenting CRC services Signed-off-by: Benjamin Cabé <[email protected]>
1 parent 4a52afd commit d55b7be

File tree

5 files changed

+69
-10
lines changed

5 files changed

+69
-10
lines changed

MAINTAINERS.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ CRC:
907907
- subsys/crc/
908908
- tests/subsys/crc/
909909
- doc/hardware/peripherals/crc.rst
910+
- doc/services/crc/index.rst
910911
labels:
911912
- "area: CRC"
912913

doc/services/crc/index.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.. _crc:
2+
3+
CRC
4+
###
5+
6+
Overview
7+
********
8+
9+
The CRC subsystem provides software implementations of various Cyclic Redundancy Check algorithms
10+
for data integrity verification.
11+
CRCs are commonly used to detect accidental changes to data in storage and communication systems.
12+
13+
The subsystem offers a comprehensive set of CRC algorithms including CRC-4, CRC-7, CRC-8, CRC-16,
14+
CRC-24, and CRC-32 variants, and provides optional hardware acceleration support when available.
15+
16+
.. note::
17+
This library is distinct from the :ref:`CRC hardware driver API <crc_api>`, which provides an
18+
interface to hardware CRC acceleration peripherals.
19+
20+
When a hardware CRC unit is available and the ``zephyr,crc`` property has been set in the
21+
``/chosen`` node in Devicetree, the library functions will default to using hardware
22+
acceleration for improved performance (can be disabled by setting
23+
:kconfig:option:`CONFIG_CRC_HW_HANDLER` to ``n``).
24+
25+
Usage
26+
=====
27+
28+
To compute a CRC, include the appropriate header and call the desired function:
29+
30+
.. code-block:: c
31+
32+
#include <zephyr/sys/crc.h>
33+
34+
uint8_t data[] = {0x01, 0x02, 0x03, 0x04};
35+
uint32_t checksum = crc32_ieee(data, sizeof(data));
36+
37+
For streaming data processed in chunks, use the "update" variants:
38+
39+
.. code-block:: c
40+
41+
uint32_t crc = 0;
42+
crc = crc32_ieee_update(crc, chunk1, len1);
43+
crc = crc32_ieee_update(crc, chunk2, len2);
44+
/* Final CRC value is in 'crc' */
45+
46+
The generic :c:func:`crc_by_type` function provides a unified interface to select the CRC algorithm
47+
at runtime.
48+
49+
Configuration
50+
*************
51+
52+
Related configuration options:
53+
54+
* :kconfig:option:`CONFIG_CRC` - Enable CRC support
55+
* :kconfig:option:`CONFIG_CRC_HW_HANDLER` - Enable hardware CRC acceleration
56+
* :kconfig:option:`CONFIG_CRC_SHELL` - Enable CRC shell commands
57+
* :kconfig:option-regex:`CONFIG_CRC[0-9].*` - Enable software implementations of specific CRC
58+
algorithms
59+
60+
API Reference
61+
*************
62+
63+
.. doxygengroup:: crc

doc/services/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ OS Services
1010
console.rst
1111
cpu_freq/index.rst
1212
cpu_load/index.rst
13+
crc/index.rst
1314
crypto/index
1415
debugging/index.rst
1516
device_mgmt/index

doc/services/misc.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ Miscellaneous
88
.. doxygengroup:: checksum
99
.. doxygengroup:: structured_data
1010
11-
Checksum APIs
12-
*************
13-
14-
CRC
15-
=====
16-
17-
.. doxygengroup:: crc
18-
1911
Structured Data APIs
2012
********************
2113

samples/subsys/crc/README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.. zephyr:code-sample:: crc_subsys
22
:name: Cyclic Redundancy Check Subsystem (CRC Subsys)
3+
:relevant-api: crc
34

45
Compute and verify a CRC computation using the CRC subsys API.
56

@@ -13,8 +14,9 @@ Configuration Options
1314

1415
This sample uses the following Kconfig options:
1516

16-
- ``CONFIG_CRC``: Enable CRC functionality.
17-
- ``CONFIG_CRC*``: Use software-based CRC if a chosen node is present; otherwise, hardware acceleration is used.
17+
- :kconfig:option:`CONFIG_CRC`: Enable CRC functionality.
18+
- :kconfig:option-regex:`CONFIG_CRC[0-9].*`: Force software-based CRC if a ``zephyr,crc`` property
19+
has been set in the ``/chosen`` node in Devicetree; otherwise, hardware acceleration is used.
1820

1921
These options can be modified in the project's ``prj.conf`` file or passed via CMake arguments.
2022

0 commit comments

Comments
 (0)