Skip to content

Commit 5dead02

Browse files
Duy Vothenguyenyf
Duy Vo
authored andcommitted
hal: renesas: ra: initial support for CRC driver
Initial support for CRC driver Signed-off-by: Duy Vo <[email protected]>
1 parent c1ca209 commit 5dead02

File tree

5 files changed

+726
-0
lines changed

5 files changed

+726
-0
lines changed

drivers/ra/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,6 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_ETHER_PHY
143143

144144
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_ETHER
145145
fsp/src/r_ether/r_ether.c)
146+
147+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_CRC
148+
fsp/src/r_crc/r_crc.c)

drivers/ra/fsp/inc/api/r_crc_api.h

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef R_CRC_API_H
8+
#define R_CRC_API_H
9+
10+
/*******************************************************************************************************************//**
11+
* @defgroup CRC_API CRC Interface
12+
* @ingroup RENESAS_MONITORING_INTERFACES
13+
*
14+
* @brief Interface for cyclic redundancy checking.
15+
*
16+
* @section CRC_API_SUMMARY Summary
17+
* The CRC (Cyclic Redundancy Check) calculator generates CRC codes using five different polynomials including 8 bit,
18+
* 16 bit, and 32 bit variations. Calculation can be performed by sending data to the block using the CPU or by snooping
19+
* on read or write activity on one of SCI channels.
20+
*
21+
*
22+
* @{
23+
**********************************************************************************************************************/
24+
25+
/***********************************************************************************************************************
26+
* Includes
27+
**********************************************************************************************************************/
28+
29+
/* Register definitions, common services and error codes. */
30+
#include "bsp_api.h"
31+
32+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
33+
FSP_HEADER
34+
35+
/**********************************************************************************************************************
36+
* Macro definitions
37+
**********************************************************************************************************************/
38+
39+
/**********************************************************************************************************************
40+
* Typedef definitions
41+
**********************************************************************************************************************/
42+
43+
/** CRC Generating Polynomial Switching (GPS). */
44+
typedef enum e_crc_polynomial
45+
{
46+
CRC_POLYNOMIAL_CRC_8 = 1, ///< 8-bit CRC-8 (X^8 + X^2 + X + 1)
47+
CRC_POLYNOMIAL_CRC_16, ///< 16-bit CRC-16 (X^16 + X^15 + X^2 + 1)
48+
CRC_POLYNOMIAL_CRC_CCITT, ///< 16-bit CRC-CCITT (X^16 + X^12 + X^5 + 1)
49+
50+
/** 32-bit CRC-32 (X^32 + X^26 + X^23 + X^22 + X^16 + X^12 + X^11 + X^10 + X^8 + X^7 + X^5 + X^4 + X^2 + X + 1) */
51+
CRC_POLYNOMIAL_CRC_32,
52+
53+
/** 32-bit CRC-32C (X^32 + X^28 + X^27 + X^26 + X^25 + X^23 + X^22 + X^20 + X^19 + X^18 + X^14 + X^13 + X^11 + X^10 + X^9 + X^8 +
54+
* X^6 + 1) */
55+
CRC_POLYNOMIAL_CRC_32C,
56+
} crc_polynomial_t;
57+
58+
/** CRC Calculation Switching (LMS) */
59+
typedef enum e_crc_bit_order
60+
{
61+
CRC_BIT_ORDER_LMS_LSB = 0, ///< Generates CRC for LSB first communication
62+
CRC_BIT_ORDER_LMS_MSB, ///< Generates CRC for MSB first communication
63+
} crc_bit_order_t;
64+
65+
/** Snoop-On-Write/Read Switch (CRCSWR) */
66+
typedef enum e_crc_snoop_direction
67+
{
68+
CRC_SNOOP_DIRECTION_RECEIVE = 0, ///< Snoop-on-read
69+
CRC_SNOOP_DIRECTION_TRANSMIT, ///< Snoop-on-write
70+
} crc_snoop_direction_t;
71+
72+
/** Structure for CRC inputs */
73+
typedef struct st_crc_input_t
74+
{
75+
uint32_t num_bytes; ///< Length of input buffer. It must be 4-byte aligned when a 32-bit CRC polynomial function is used.
76+
uint32_t crc_seed; ///< CRC seed value
77+
const void * p_input_buffer; ///< Pointer to input buffer
78+
} crc_input_t;
79+
80+
/** CRC control block. Allocate an instance specific control block to pass into the CRC API calls.
81+
*/
82+
typedef void crc_ctrl_t;
83+
84+
/** User configuration structure, used in open function */
85+
typedef struct st_crc_cfg
86+
{
87+
uint8_t channel; ///< Channel number
88+
crc_polynomial_t polynomial; ///< CRC Generating Polynomial Switching (GPS)
89+
crc_bit_order_t bit_order; ///< CRC Calculation Switching (LMS)
90+
uint32_t snoop_address; ///< Register Snoop Address (CRCSA)
91+
void const * p_extend; ///< CRC Hardware Dependent Configuration
92+
} crc_cfg_t;
93+
94+
/** CRC driver structure. General CRC functions implemented at the HAL layer will follow this API. */
95+
typedef struct st_crc_api
96+
{
97+
/** Open the CRC driver module.
98+
*
99+
* @param[in] p_ctrl Pointer to CRC device handle.
100+
* @param[in] p_cfg Pointer to a configuration structure.
101+
**/
102+
fsp_err_t (* open)(crc_ctrl_t * const p_ctrl, crc_cfg_t const * const p_cfg);
103+
104+
/** Close the CRC module driver
105+
*
106+
* @param[in] p_ctrl Pointer to CRC device handle
107+
* @retval FSP_SUCCESS Configuration was successful.
108+
**/
109+
fsp_err_t (* close)(crc_ctrl_t * const p_ctrl);
110+
111+
/** Return the current calculated value.
112+
*
113+
* @param[in] p_ctrl Pointer to CRC device handle.
114+
* @param[out] crc_result The calculated value from the last CRC calculation.
115+
**/
116+
fsp_err_t (* crcResultGet)(crc_ctrl_t * const p_ctrl, uint32_t * crc_result);
117+
118+
/** Configure and Enable snooping.
119+
*
120+
* @param[in] p_ctrl Pointer to CRC device handle.
121+
* @param[in] crc_seed CRC seed.
122+
**/
123+
fsp_err_t (* snoopEnable)(crc_ctrl_t * const p_ctrl, uint32_t crc_seed);
124+
125+
/** Disable snooping.
126+
*
127+
* @param[in] p_ctrl Pointer to CRC device handle.
128+
**/
129+
fsp_err_t (* snoopDisable)(crc_ctrl_t * const p_ctrl);
130+
131+
/** Perform a CRC calculation on a block of data.
132+
*
133+
* @param[in] p_ctrl Pointer to CRC device handle.
134+
* @param[in] p_crc_input A pointer to structure for CRC inputs
135+
* @param[out] crc_result The calculated value of the CRC calculation.
136+
**/
137+
fsp_err_t (* calculate)(crc_ctrl_t * const p_ctrl, crc_input_t * const p_crc_input, uint32_t * p_crc_result);
138+
} crc_api_t;
139+
140+
/** This structure encompasses everything that is needed to use an instance of this interface. */
141+
typedef struct st_crc_instance
142+
{
143+
crc_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
144+
crc_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance
145+
crc_api_t const * p_api; ///< Pointer to the API structure for this instance
146+
} crc_instance_t;
147+
148+
/*******************************************************************************************************************//**
149+
* @} (end defgroup CRC_API)
150+
**********************************************************************************************************************/
151+
152+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
153+
FSP_FOOTER
154+
155+
#endif

drivers/ra/fsp/inc/instances/r_crc.h

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef R_CRC_H
8+
#define R_CRC_H
9+
10+
/*******************************************************************************************************************//**
11+
* @addtogroup CRC
12+
* @{
13+
**********************************************************************************************************************/
14+
15+
/***********************************************************************************************************************
16+
* Includes
17+
**********************************************************************************************************************/
18+
#include "bsp_api.h"
19+
#include "r_crc_cfg.h"
20+
#include "r_crc_api.h"
21+
22+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
23+
FSP_HEADER
24+
25+
/***********************************************************************************************************************
26+
* Macro definitions
27+
**********************************************************************************************************************/
28+
29+
/***********************************************************************************************************************
30+
* Typedef definitions
31+
**********************************************************************************************************************/
32+
33+
/** Driver instance control structure. */
34+
typedef struct st_crc_instance_ctrl
35+
{
36+
uint32_t open;
37+
const crc_cfg_t * p_cfg; // Pointer to initial configurations
38+
} crc_instance_ctrl_t;
39+
40+
/**********************************************************************************************************************
41+
* Exported global variables
42+
**********************************************************************************************************************/
43+
44+
/** @cond INC_HEADER_DEFS_SEC */
45+
/** Filled in Interface API structure for this Instance. */
46+
extern const crc_api_t g_crc_on_crc;
47+
48+
/** @endcond */
49+
50+
/***********************************************************************************************************************
51+
* Public APIs
52+
**********************************************************************************************************************/
53+
fsp_err_t R_CRC_Open(crc_ctrl_t * const p_ctrl, crc_cfg_t const * const p_cfg);
54+
fsp_err_t R_CRC_Close(crc_ctrl_t * const p_ctrl);
55+
fsp_err_t R_CRC_Calculate(crc_ctrl_t * const p_ctrl, crc_input_t * const p_crc_input, uint32_t * calculatedValue);
56+
fsp_err_t R_CRC_CalculatedValueGet(crc_ctrl_t * const p_ctrl, uint32_t * calculatedValue);
57+
fsp_err_t R_CRC_SnoopEnable(crc_ctrl_t * const p_ctrl, uint32_t crc_seed);
58+
fsp_err_t R_CRC_SnoopDisable(crc_ctrl_t * const p_ctrl);
59+
60+
/*******************************************************************************************************************//**
61+
* @} (end defgroup CRC)
62+
**********************************************************************************************************************/
63+
64+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
65+
FSP_FOOTER
66+
67+
#endif

0 commit comments

Comments
 (0)