mcu/drv/fsl_flash_driver_c90tfs.c
/*FUNCTION**********************************************************************
 *
 * Function Name : FlashCheckSum
 * Description   : Performs 32 bit sum of each byte data over a specified Flash
 * memory range without carry which provides rapid method for checking data integrity.
 * The callback time period of this API is determined via FLASH_CALLBACK_CS macro in the
 * SSD_FTFx_Common.h which is used as a counter value for the CallBack() function calling in
 * this API. This value can be changed as per the user requirement. User can change this value
 * to obtain the maximum permissible callback time period.
 * This API always returns FTFx_OK if size provided by user is zero regardless of the input
 * validation.
 *
 * Implements    : FlashCheckSum_Activity
 *END**************************************************************************/
FUNCTION

Function Name : FlashCheckSum
Description   : Performs 32 bit sum of each byte data over a specified Flash
memory range without carry which provides rapid method for checking data integrity.
The callback time period of this API is determined via FLASH_CALLBACK_CS macro in the
SSD_FTFx_Common.h which is used as a counter value for the CallBack() function calling in
this API. This value can be changed as per the user requirement. User can change this value
to obtain the maximum permissible callback time period.
This API always returns FTFx_OK if size provided by user is zero regardless of the input
validation.

Implements    : FlashCheckSum_Activity
END
FUNCTION Function Name : FlashCheckSum Description : Performs 32 bit sum of each byte data over a specified Flash memory range without carry which provides rapid method for checking data integrity . The callback time period of this API is determined via FLASH_CALLBACK_CS macro in the SSD_FTFx_Common . h which is used as a counter value for the CallBack () function calling in this API . This value can be changed as per the user requirement . User can change this value to obtain the maximum permissible callback time period . This API always returns FTFx_OK if size provided by user is zero regardless of the input validation . Implements : FlashCheckSum_Activity END
flash_drv_status_t FlashCheckSum(const flash_ssd_config_t * pSSDConfig, \
                                 uint32_t dest, \
                                 uint32_t size, \
                                 uint32_t* pSum)
{
#ifdef DEV_ERROR_DETECT
    DEV_ASSERT(pSSDConfig != NULL);
    DEV_ASSERT(pSum != NULL);
#endif
    flash_drv_status_t ret = FTFx_OK;   
    uint32_t counter = 0U;              
    uint32_t data;                      
    uint32_t endAddress;                
    uint32_t tempSize = size;           
    endAddress = dest + tempSize;
    if ((dest < pSSDConfig->PFlashBase) || (endAddress > (pSSDConfig->PFlashBase + pSSDConfig->PFlashSize)))
    {
    #if FSL_FEATURE_FLS_HAS_FLEX_NVM
        if ((dest < pSSDConfig->DFlashBase) || (endAddress > (pSSDConfig->DFlashBase + pSSDConfig->DFlashSize)))
        {
    #endif
            ret = FTFx_ERR_RANGE;
            tempSize = 0U;
    #if FSL_FEATURE_FLS_HAS_FLEX_NVM
        }
    #endif 
    }
    *pSum = 0U;
    while (tempSize > 0U)
    {
        data = *(uint8_t *)(dest);
        *pSum += data;
        dest += 1U;
        tempSize -= 1U;
        ++counter;
        if (counter >= FLASH_CALLBACK_CS)
        {
            if (NULL_CALLBACK != pSSDConfig->CallBack)
            {
                pSSDConfig->CallBack();
            }
            counter = 0U;
        }
    }
    return (ret);
}
flash_drv_status_t FlashCheckSum ( const flash_ssd_config_t * pSSDConfig , uint32_t dest , uint32_t size , uint32_t * pSum ) { #ifdef DEV_ERROR_DETECT DEV_ASSERT ( pSSDConfig != NULL ) ; DEV_ASSERT ( pSum != NULL ) ; #endif flash_drv_status_t ret = FTFx_OK ; uint32_t counter = 0U ; uint32_t data ; uint32_t endAddress ; uint32_t tempSize = size ; endAddress = dest + tempSize ; if ( ( dest < pSSDConfig -> PFlashBase ) || ( endAddress > ( pSSDConfig -> PFlashBase + pSSDConfig -> PFlashSize ) ) ) { #if FSL_FEATURE_FLS_HAS_FLEX_NVM if ( ( dest < pSSDConfig -> DFlashBase ) || ( endAddress > ( pSSDConfig -> DFlashBase + pSSDConfig -> DFlashSize ) ) ) { #endif 
            ret = FTFx_ERR_RANGE;
 tempSize = 0U ; #if FSL_FEATURE_FLS_HAS_FLEX_NVM } #endif } * pSum = 0U ; while ( tempSize > 0U ) { data = * ( uint8_t * ) ( dest ) ; * pSum += data ; dest += 1U ; tempSize -= 1U ; ++ counter ; if ( counter >= FLASH_CALLBACK_CS ) { if ( NULL_CALLBACK != pSSDConfig -> CallBack ) { pSSDConfig -> CallBack ( ) ; } counter = 0U ; } } return ( ret ) ; }
FUNCTION
FUNCTION
/* Return code variable           */ /* Counter for callback operation */ /* Data read from Flash address   */ /* PFlash end address             */ /* Temporary of size variation    */ /* Calculating Flash end address */ /* Check for valid range of the target addresses */ /* End of if FSL_FEATURE_FLS_HAS_FLEX_NVM */ /* Doing sum operation */ /* Check if need to serve callback function */ /* Serve callback function if counter reaches limitation */ /* Reset counter */