Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
crc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Brill Power Ltd.
3 * Copyright (c) 2025 Renesas Electronics Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13
14#ifndef ZEPHYR_INCLUDE_DRIVERS_CRC_H
15#define ZEPHYR_INCLUDE_DRIVERS_CRC_H
16
17#include <zephyr/device.h>
18#include <zephyr/kernel.h>
19#include <zephyr/sys/crc.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
31
38
42#define CRC_FLAG_REVERSE_INPUT BIT(0)
43
47#define CRC_FLAG_REVERSE_OUTPUT BIT(1)
48
50
56
58#define CRC4_INIT_VAL 0x0
59
61#define CRC4_TI_INIT_VAL 0x0
62
64#define CRC7_BE_INIT_VAL 0x0
65
67#define CRC8_INIT_VAL 0x0
68
70#define CRC8_CCITT_INIT_VAL 0xFF
71
73#define CRC8_ROHC_INIT_VAL 0xFF
74
76#define CRC16_INIT_VAL 0x0
77
79#define CRC16_ANSI_INIT_VAL 0x0
80
82#define CRC16_CCITT_INIT_VAL 0x0000
83
85#define CRC16_ITU_T_INIT_VAL 0x0000
86
88#define CRC24_PGP_INIT_VALUE 0x00B704CEU
89
91#define CRC32_IEEE_INIT_VAL 0xFFFFFFFFU
92
94#define CRC32_C_INIT_VAL 0xFFFFFFFFU
95
97
101
108
113
119
124
132
147
152typedef int (*crc_api_begin)(const struct device *dev, struct crc_ctx *ctx);
153
158typedef int (*crc_api_update)(const struct device *dev, struct crc_ctx *ctx, const void *buffer,
159 size_t bufsize);
160
165typedef int (*crc_api_finish)(const struct device *dev, struct crc_ctx *ctx);
166
172
183__syscall int crc_begin(const struct device *dev, struct crc_ctx *ctx);
184
185static inline int z_impl_crc_begin(const struct device *dev, struct crc_ctx *ctx)
186{
187 const struct crc_driver_api *api = (const struct crc_driver_api *)dev->api;
188
189 if (api->begin == NULL) {
190 return -ENOSYS;
191 }
192
193 return api->begin(dev, ctx);
194}
195
208__syscall int crc_update(const struct device *dev, struct crc_ctx *ctx, const void *buffer,
209 size_t bufsize);
210
211static inline int z_impl_crc_update(const struct device *dev, struct crc_ctx *ctx,
212 const void *buffer, size_t bufsize)
213{
214 const struct crc_driver_api *api = (const struct crc_driver_api *)dev->api;
215
216 if (api->update == NULL) {
217 return -ENOSYS;
218 }
219
220 return api->update(dev, ctx, buffer, bufsize);
221}
222
233__syscall int crc_finish(const struct device *dev, struct crc_ctx *ctx);
234
235static inline int z_impl_crc_finish(const struct device *dev, struct crc_ctx *ctx)
236{
237 const struct crc_driver_api *api = (const struct crc_driver_api *)dev->api;
238
239 if (api->finish == NULL) {
240 return -ENOSYS;
241 }
242
243 return api->finish(dev, ctx);
244}
245
256static inline int crc_verify(struct crc_ctx *ctx, crc_result_t expected)
257{
258 if (ctx == NULL) {
259 return -EINVAL;
260 }
261
262 if (ctx->state == CRC_STATE_IN_PROGRESS) {
263 return -EBUSY;
264 }
265
266 if (expected != ctx->result) {
267 return -EPERM;
268 }
269
270 return 0;
271}
272
276
277#ifdef __cplusplus
278}
279#endif
280
281#include <zephyr/syscalls/crc.h>
282
283#endif /* ZEPHYR_INCLUDE_DRIVERS_CRC_H */
uint32_t crc_init_val_t
Provides a type to hold CRC initial seed value.
Definition crc.h:112
uint32_t crc_result_t
Provides a type to hold CRC result value.
Definition crc.h:123
int(* crc_api_update)(const struct device *dev, struct crc_ctx *ctx, const void *buffer, size_t bufsize)
Callback API upon CRC calculation stream update See crc_update() for argument description.
Definition crc.h:158
int(* crc_api_begin)(const struct device *dev, struct crc_ctx *ctx)
Callback API upon CRC calculation begin See crc_begin() for argument description.
Definition crc.h:152
uint32_t crc_poly_t
Provides a type to hold CRC polynomial value.
Definition crc.h:118
int crc_finish(const struct device *dev, struct crc_ctx *ctx)
Finalize CRC calculation.
crc_state
CRC state enumeration.
Definition crc.h:102
int(* crc_api_finish)(const struct device *dev, struct crc_ctx *ctx)
Callback API upon CRC calculation finish See crc_finish() for argument description.
Definition crc.h:165
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:256
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:106
@ CRC_STATE_IDLE
CRC device is in IDLE state.
Definition crc.h:104
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
#define NULL
Definition iar_missing_defs.h:20
Public kernel APIs.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
CRC context structure.
Definition crc.h:133
crc_poly_t polynomial
CRC polynomial.
Definition crc.h:141
enum crc_state state
Current CRC device state.
Definition crc.h:137
crc_init_val_t seed
CRC initial seed value.
Definition crc.h:143
uint32_t reversed
CRC input/output reverse flags.
Definition crc.h:139
crc_result_t result
CRC result.
Definition crc.h:145
enum crc_type type
CRC calculation type.
Definition crc.h:135
Definition crc.h:167
crc_api_finish finish
Definition crc.h:170
crc_api_update update
Definition crc.h:169
crc_api_begin begin
Definition crc.h:168
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
CRC computation function.