14#ifndef ZEPHYR_INCLUDE_DRIVERS_CRC_H
15#define ZEPHYR_INCLUDE_DRIVERS_CRC_H
42#define CRC_FLAG_REVERSE_INPUT BIT(0)
47#define CRC_FLAG_REVERSE_OUTPUT BIT(1)
58#define CRC4_INIT_VAL 0x0
61#define CRC4_TI_INIT_VAL 0x0
64#define CRC7_BE_INIT_VAL 0x0
67#define CRC8_INIT_VAL 0x0
70#define CRC8_CCITT_INIT_VAL 0xFF
73#define CRC8_ROHC_INIT_VAL 0xFF
76#define CRC16_INIT_VAL 0x0
79#define CRC16_ANSI_INIT_VAL 0x0
82#define CRC16_CCITT_INIT_VAL 0x0000
85#define CRC16_ITU_T_INIT_VAL 0x0000
88#define CRC24_PGP_INIT_VALUE 0x00B704CEU
91#define CRC32_C_INIT_VAL 0xFFFFFFFFU
94#define CRC32_IEEE_INIT_VAL 0xFFFFFFFFU
97#define CRC32_K_4_2_INIT_VAL 0xFFFFFFFFU
100#define CRC32_MPEG2_INIT_VAL 0xFFFFFFFFU
208static inline int z_impl_crc_begin(
const struct device *dev,
struct crc_ctx *ctx)
212 if (api->
begin == NULL) {
216 return api->
begin(dev, ctx);
234static inline int z_impl_crc_update(
const struct device *dev,
struct crc_ctx *ctx,
235 const void *buffer,
size_t bufsize)
239 if (api->
update == NULL) {
243 return api->
update(dev, ctx, buffer, bufsize);
258static inline int z_impl_crc_finish(
const struct device *dev,
struct crc_ctx *ctx)
262 if (api->
finish == NULL) {
266 return api->
finish(dev, ctx);
289 if (expected != ctx->
result) {
304#include <zephyr/syscalls/crc.h>
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
int(* crc_api_update)(const struct device *dev, struct crc_ctx *ctx, const void *buffer, size_t bufsize)
Callback API to feed data into an in-progress CRC calculation.
Definition crc.h:172
int(* crc_api_begin)(const struct device *dev, struct crc_ctx *ctx)
Callback API to configure the CRC unit for calculation.
Definition crc.h:165
int(* crc_api_finish)(const struct device *dev, struct crc_ctx *ctx)
Callback API to finalize CRC calculation.
Definition crc.h:180
uint32_t crc_init_val_t
Provides a type to hold CRC initial seed value.
Definition crc.h:118
uint32_t crc_result_t
Provides a type to hold CRC result value.
Definition crc.h:129
uint32_t crc_poly_t
Provides a type to hold CRC polynomial value.
Definition crc.h:124
int crc_finish(const struct device *dev, struct crc_ctx *ctx)
Finalize CRC calculation.
crc_state
CRC state enumeration.
Definition crc.h:108
int crc_begin(const struct device *dev, struct crc_ctx *ctx)
Configure CRC unit for calculation.
static int crc_verify(struct crc_ctx *ctx, crc_result_t expected)
Verify CRC result.
Definition crc.h:279
int crc_update(const struct device *dev, struct crc_ctx *ctx, const void *buffer, size_t bufsize)
Perform CRC calculation on the provided data buffer and retrieve result.
@ CRC_STATE_IN_PROGRESS
CRC calculation is in-progress.
Definition crc.h:112
@ CRC_STATE_IDLE
CRC device is in IDLE state.
Definition crc.h:110
crc_type
CRC algorithm enumeration.
Definition crc.h:104
#define EINVAL
Invalid argument.
Definition errno.h:60
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define EBUSY
Mount device busy.
Definition errno.h:54
#define EPERM
Not owner.
Definition errno.h:39
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
CRC context structure.
Definition crc.h:139
crc_poly_t polynomial
CRC polynomial.
Definition crc.h:147
enum crc_state state
Current CRC device state.
Definition crc.h:143
crc_init_val_t seed
CRC initial seed value.
Definition crc.h:149
uint32_t reversed
CRC input/output reverse flags.
Definition crc.h:145
crc_result_t result
CRC result.
Definition crc.h:151
enum crc_type type
CRC calculation type.
Definition crc.h:141
<span class="mlabel">Driver Operations</span> CRC driver operations
Definition crc.h:185
crc_api_finish finish
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition crc.h:191
crc_api_update update
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition crc.h:189
crc_api_begin begin
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition crc.h:187
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
CRC computation function.