Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/basic_coding/utils/crc.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ sidebar_position: 8
#include "crc.hpp"

uint8_t packet[5]{1, 2, 3, 4, 0};
LibXR::CRC8::GenerateTable();
packet[4] = LibXR::CRC8::Calculate(packet, 4);

bool valid = LibXR::CRC8::Verify(packet, sizeof(packet));
```

查找表也可以在首次计算时生成。多个上下文可能同时首次使用同一 CRC 类时,初始化阶段先调用 `GenerateTable()`。
查找表在编译期生成,存放在只读数据段,使用前不需要初始化,多个线程或中断同时首次调用也不会互相干扰。查找表可以通过各类的 `tab_` 读取,类型是 `std::array<uintN_t, 256>`。

## 参数

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ sidebar_position: 8
#include "crc.hpp"

uint8_t packet[5]{1, 2, 3, 4, 0};
LibXR::CRC8::GenerateTable();
packet[4] = LibXR::CRC8::Calculate(packet, 4);

bool valid = LibXR::CRC8::Verify(packet, sizeof(packet));
```

Tables are also generated lazily on first calculation. If several contexts can race the first use of one CRC class, generate its table during initialization.
The lookup tables are built at compile time and kept in read-only data. They need no initialization before use, and several threads or interrupts may make the first call at the same time. Each class exposes its table as `tab_`, a `std::array<uintN_t, 256>`.

## Parameters

Expand Down
Loading