|
| 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