Skip to content

Commit 6c65c7a

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 6fc3c97 commit 6c65c7a

File tree

3 files changed

+162
-1
lines changed

3 files changed

+162
-1
lines changed

zephyr/ra/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
add_subdirectory(ra_cfg)
4-
zephyr_include_directories(portable)
4+
zephyr_include_directories(
5+
portable
6+
portable/inc
7+
)
8+
9+
# Optional build base on feature configuration
10+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_CRC
11+
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
+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
* @addtogroup CRC
30+
* @{
31+
**********************************************************************************************************************/
32+
33+
/***********************************************************************************************************************
34+
* Functions
35+
**********************************************************************************************************************/
36+
37+
/*******************************************************************************************************************//**
38+
* Reconfigure the CRC driver module
39+
*
40+
* Initialize the driver control block according to the passed-in
41+
* configuration structure.
42+
*
43+
* @retval FSP_SUCCESS Configuration was successful.
44+
* @retval FSP_ERR_ASSERTION p_ctrl or p_cfg is NULL.
45+
* @retval FSP_ERR_ALREADY_OPEN Module already open
46+
* @retval FSP_ERR_UNSUPPORTED Hardware not support this feature.
47+
**********************************************************************************************************************/
48+
fsp_err_t RP_CRC_Reconfigure (crc_ctrl_t * const p_ctrl, crc_cfg_t const * const p_cfg)
49+
{
50+
crc_instance_ctrl_t * p_instance_ctrl = (crc_instance_ctrl_t *) p_ctrl;
51+
52+
#if CRC_CFG_PARAM_CHECKING_ENABLE
53+
FSP_ASSERT(p_ctrl);
54+
55+
/* Verify the configuration parameters are valid */
56+
fsp_err_t err = r_crc_open_cfg_check(p_cfg);
57+
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
58+
59+
/* Verify the control block has not already been initialized. */
60+
FSP_ERROR_RETURN(CRC_OPEN != p_instance_ctrl->open, FSP_ERR_ALREADY_OPEN);
61+
#endif
62+
63+
/* Save the configuration */
64+
p_instance_ctrl->p_cfg = p_cfg;
65+
66+
/* Power on CRC */
67+
R_BSP_MODULE_START(FSP_IP_CRC, 0);
68+
69+
uint8_t crccr0 = 0;
70+
#if BSP_FEATURE_CRC_HAS_CRCCR0_LMS
71+
72+
/* Set bit order value */
73+
crccr0 = (uint8_t) (p_instance_ctrl->p_cfg->bit_order << R_CRC_CRCCR0_LMS_Pos);
74+
#endif
75+
76+
/* Set CRC polynomial */
77+
crccr0 |= (uint8_t) (p_instance_ctrl->p_cfg->polynomial << R_CRC_CRCCR0_GPS_Pos);
78+
79+
/* Set DORCLR to clear CRCDOR */
80+
crccr0 |= (uint8_t) (1 << R_CRC_CRCCR0_DORCLR_Pos);
81+
82+
R_CRC->CRCCR0 = crccr0;
83+
84+
#if BSP_FEATURE_CRC_HAS_SNOOP
85+
86+
/* Disable snooping */
87+
R_CRC->CRCCR1 = 0;
88+
#endif
89+
90+
return FSP_SUCCESS;
91+
}
92+
93+
#if CRC_CFG_PARAM_CHECKING_ENABLE
94+
95+
/*******************************************************************************************************************//**
96+
* Validates the configuration arguments for illegal combinations or options.
97+
*
98+
* @param[in] p_cfg Pointer to configuration structure
99+
*
100+
* @retval FSP_SUCCESS No configuration errors detected
101+
* @retval FSP_ERR_ASSERTION An input argument is invalid.
102+
* @retval FSP_ERR_UNSUPPORTED Hardware not support this feature.
103+
**********************************************************************************************************************/
104+
static fsp_err_t r_crc_open_cfg_check (crc_cfg_t const * const p_cfg)
105+
{
106+
FSP_ASSERT(NULL != p_cfg);
107+
108+
#if !BSP_FEATURE_CRC_HAS_CRCCR0_LMS
109+
110+
/* Verify the configuration bit order */
111+
FSP_ERROR_RETURN(CRC_BIT_ORDER_LMS_LSB == p_cfg->bit_order, FSP_ERR_UNSUPPORTED);
112+
#endif
113+
114+
/* Verify the configuration polynomial */
115+
FSP_ERROR_RETURN((1 << p_cfg->polynomial) & BSP_FEATURE_CRC_POLYNOMIAL_MASK, FSP_ERR_UNSUPPORTED);
116+
117+
return FSP_SUCCESS;
118+
}
119+
120+
#endif

0 commit comments

Comments
 (0)