/*******************************************************************************
*
*
* File:         hal_crc.h
* Description:  hal crc ͷ�ļ�
* Version:      V0.1
* Date:         2023-07-27
* Author:       zzf
 *******************************************************************************/
#ifndef __HAL_CRC_H
#define __HAL_CRC_H

#ifdef __cplusplus
extern "C" {
#endif

/*******************************************************************************
* 1.Included files
*******************************************************************************/
#include "tau_device_datatype.h"
#include "tau_common.h"

/*******************************************************************************
* 2.Exported constant and macro definitions
*******************************************************************************/

/*******************************************************************************
* 3.Exported structures, unions and enumerations
*******************************************************************************/
/**
* @brief crc calculation unit structure
*/
typedef struct
{
    uint32_t             polynomial_value;
    uint32_t             initial_seed_value;
    crc_protocol_type_e  crc_protocol;
    crc_fxor_function_e  crc_foxr;
    crc_reversal_type_e  crc_reversal_in;
    crc_reversal_type_e  crc_reversal_out;
} crc_ctrl_handle_t;

/**
* @brief crc dma callback function define
*/
typedef void (*crc_dma_callback)(uint32_t crc_result);

/*******************************************************************************
* 4.Exported variable declarations
*******************************************************************************/

/*******************************************************************************
* 5.Exported function declarations
*******************************************************************************/
/**
* @brief The initialization for CRC calculation unit
* @param  crc_ctrl_handle: configuration parameters in initialization
* @retval true or false
**/
bool hal_crc_init(const crc_ctrl_handle_t *crc_ctrl_handle);

/**
* @brief The initialization for CRC calculation unit
* @param  None
* @retval true or false
**/
bool hal_crc_deinit(void);

/**
* @brief Reset CRC calculation unit and DR to CRCR_INIT value
* @param  None
* @retval true or false
**/
bool hal_crc_reset(void);

/**
* @brief  Get the result of CRC calculation uint
* @param  buffer_address: 16-bit or 32-bit crc calculate buffer address
* @param  buffer_length: the length of buffer
* @retval 32-bit crc calculate result
**/
uint32_t hal_crc_cal(const void *buffer_address, uint32_t buffer_length);

/**
* @brief  initial DMA transfer
* @param  crc_ctrl_handle: configuration parameters in initialization
* @param  buffer_address: 16-bit or 32-bit crc calculate buffer address
* @param  buffer_length: the length of buffer(0~65535)
* @param  cb_func: dma interrupt callback function to get the result of crc calculation
* @retval true or false
**/
bool hal_crc_dma_init(const crc_ctrl_handle_t *crc_ctrl_handle, crc_dma_callback cb_func, const void *buffer_address, uint16_t buffer_length);

/**
* @brief  deinitial DMA transfer
* @param  None
* @retval true or false
**/
bool hal_crc_dma_deinit(void);

/**
* @brief  start DMA transfer
* @param  None
* @retval true or false
**/
bool hal_crc_dma_start(void);

#ifdef __cplusplus
}
#endif

#endif /* __HAL_CRC_H */

/***************** (C) COPYRIGHT ISP Systems (R) END OF FILE ******************/
