Skip to content

Commit cde6ea7

Browse files
Duy Vothenguyenyf
Duy Vo
authored andcommitted
portable: rp_crc: add runtime reconfigure for CRC
Add runtime configure for CRC driver Signed-off-by: Duy Vo <[email protected]>
1 parent 5dead02 commit cde6ea7

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed

zephyr/ra/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ zephyr_include_directories(
55
portable
66
portable/inc)
77

8+
# Optional build base on feature configuration
89
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_AGT
910
portable/src/rp_agt/rp_agt.c)
11+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_CRC
12+
portable/src/rp_crc/rp_crc.c)

zephyr/ra/portable/inc/rp_crc.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
/*******************************************************************************************************************//**
7+
* @addtogroup CRC
8+
* @{
9+
**********************************************************************************************************************/
10+
#ifndef RP_CRC_H
11+
#define RP_CRC_H
12+
/***********************************************************************************************************************
13+
* Includes
14+
**********************************************************************************************************************/
15+
#include "r_crc.h"
16+
17+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER
18+
* macro at the end of this file. */
19+
FSP_HEADER
20+
21+
/***********************************************************************************************************************
22+
* Public APIs
23+
**********************************************************************************************************************/
24+
fsp_err_t RP_CRC_Reconfigure(crc_ctrl_t *const p_ctrl, crc_cfg_t const *const p_cfg);
25+
26+
/*******************************************************************************************************************//**
27+
* @} (end defgroup CRC)
28+
**********************************************************************************************************************/
29+
30+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER
31+
* macro at the top of this file. */
32+
FSP_FOOTER
33+
34+
#endif
+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/***********************************************************************************************************************
8+
* Includes
9+
**********************************************************************************************************************/
10+
#include "rp_crc.h"
11+
12+
/***********************************************************************************************************************
13+
* Macro definitions
14+
**********************************************************************************************************************/
15+
16+
/* "CRC" in ASCII, used to determine if channel is open. */
17+
#define CRC_OPEN (0x00435243ULL)
18+
19+
/***********************************************************************************************************************
20+
* Private function prototypes
21+
**********************************************************************************************************************/
22+
23+
#if CRC_CFG_PARAM_CHECKING_ENABLE
24+
static fsp_err_t r_crc_open_cfg_check(crc_cfg_t const * const p_cfg);
25+
26+
#endif
27+
28+
/***********************************************************************************************************************
29+
* Functions
30+
**********************************************************************************************************************/
31+
32+
/*******************************************************************************************************************//**
33+
* Reconfigure the CRC driver module
34+
*
35+
* Initialize the driver control block according to the passed-in
36+
* configuration structure.
37+
*
38+
* @retval FSP_SUCCESS Configuration was successful.
39+
* @retval FSP_ERR_ASSERTION p_ctrl or p_cfg is NULL.
40+
* @retval FSP_ERR_ALREADY_OPEN Module already open
41+
* @retval FSP_ERR_UNSUPPORTED Hardware not support this feature.
42+
**********************************************************************************************************************/
43+
fsp_err_t RP_CRC_Reconfigure (crc_ctrl_t * const p_ctrl, crc_cfg_t const * const p_cfg)
44+
{
45+
crc_instance_ctrl_t * p_instance_ctrl = (crc_instance_ctrl_t *) p_ctrl;
46+
47+
#if CRC_CFG_PARAM_CHECKING_ENABLE
48+
FSP_ASSERT(p_ctrl);
49+
50+
/* Verify the configuration parameters are valid */
51+
fsp_err_t err = r_crc_open_cfg_check(p_cfg);
52+
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
53+
54+
/* Verify the control block has not already been initialized. */
55+
FSP_ERROR_RETURN(CRC_OPEN != p_instance_ctrl->open, FSP_ERR_ALREADY_OPEN);
56+
#endif
57+
58+
/* Save the configuration */
59+
p_instance_ctrl->p_cfg = p_cfg;
60+
61+
uint8_t crccr0 = 0;
62+
#if BSP_FEATURE_CRC_HAS_CRCCR0_LMS
63+
64+
/* Set bit order value */
65+
crccr0 = (uint8_t) (p_instance_ctrl->p_cfg->bit_order << R_CRC_CRCCR0_LMS_Pos);
66+
#endif
67+
68+
/* Set CRC polynomial */
69+
crccr0 |= (uint8_t) (p_instance_ctrl->p_cfg->polynomial << R_CRC_CRCCR0_GPS_Pos);
70+
71+
/* Set DORCLR to clear CRCDOR */
72+
crccr0 |= (uint8_t) (1 << R_CRC_CRCCR0_DORCLR_Pos);
73+
74+
R_CRC->CRCCR0 = crccr0;
75+
76+
#if BSP_FEATURE_CRC_HAS_SNOOP
77+
78+
/* Disable snooping */
79+
R_CRC->CRCCR1 = 0;
80+
#endif
81+
82+
return FSP_SUCCESS;
83+
}
84+
85+
#if CRC_CFG_PARAM_CHECKING_ENABLE
86+
87+
/*******************************************************************************************************************//**
88+
* Validates the configuration arguments for illegal combinations or options.
89+
*
90+
* @param[in] p_cfg Pointer to configuration structure
91+
*
92+
* @retval FSP_SUCCESS No configuration errors detected
93+
* @retval FSP_ERR_ASSERTION An input argument is invalid.
94+
* @retval FSP_ERR_UNSUPPORTED Hardware not support this feature.
95+
**********************************************************************************************************************/
96+
static fsp_err_t r_crc_open_cfg_check (crc_cfg_t const * const p_cfg)
97+
{
98+
FSP_ASSERT(NULL != p_cfg);
99+
100+
#if !BSP_FEATURE_CRC_HAS_CRCCR0_LMS
101+
102+
/* Verify the configuration bit order */
103+
FSP_ERROR_RETURN(CRC_BIT_ORDER_LMS_LSB == p_cfg->bit_order, FSP_ERR_UNSUPPORTED);
104+
#endif
105+
106+
/* Verify the configuration polynomial */
107+
FSP_ERROR_RETURN((1 << p_cfg->polynomial) & BSP_FEATURE_CRC_POLYNOMIAL_MASK, FSP_ERR_UNSUPPORTED);
108+
109+
return FSP_SUCCESS;
110+
}
111+
112+
#endif

0 commit comments

Comments
 (0)