|
| 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 |
0 commit comments