/************************************************************************
*
*  Function Name    : PFlashSetProtection.c
*  Description      : This function sets the P-Flash protection to the 
*                     intended protection status 
*  Arguments        : PFLASH_SSD_CONFIG, UINT32
*  Return Value     : UINT32
*
*************************************************************************/
UINT32 PFlashSetProtection(PFLASH_SSD_CONFIG pSSDConfig, \
                                      UINT32 protectStatus)
{
    UINT8 reg0, reg1, reg2, reg3;
    UINT32 ret;
    ret = FTFx_OK;
    reg0 = GET_BIT_24_31(protectStatus);
    reg1 = GET_BIT_16_23(protectStatus);
    reg2 = GET_BIT_8_15(protectStatus);
    reg3 = GET_BIT_0_7(protectStatus);
    
     
    REG_WRITE(pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT0_OFFSET, reg0);
    REG_WRITE(pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT1_OFFSET, reg1);
    REG_WRITE(pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT2_OFFSET, reg2);
    REG_WRITE(pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT3_OFFSET, reg3);
  
    /* Read the value of FPPROT registers */
    if ((REG_READ(pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT0_OFFSET) != reg0) ||\
        (REG_READ(pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT1_OFFSET) != reg1) ||\
        (REG_READ(pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT2_OFFSET) != reg2) ||\
        (REG_READ(pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT3_OFFSET) != reg3))    
    {
        ret = FTFx_ERR_CHANGEPROT; 
    }

    /* Enter Debug state if enabled */
     if (TRUE == (pSSDConfig->DebugEnable))
    {
        ENTER_DEBUG_MODE;
    }

    return(ret);
}
uint32_t SIZE_OPTIMIZATION PFlashSetProtection(PFLASH_SSD_CONFIG pSSDConfig, \
                                      uint32_t protectStatus)
{
    uint32_t ret = FTFx_OK;
    uint32_t addr;
    uint32_t temp0, temp1, temp2, temp3;
    uint8_t reg0, reg1, reg2, reg3;

    reg0 = GET_BIT_24_31(protectStatus);
    reg1 = GET_BIT_16_23(protectStatus);
    reg2 = GET_BIT_8_15(protectStatus);
    reg3 = GET_BIT_0_7(protectStatus);

    addr = pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT0_OFFSET;
    REG_WRITE(addr, reg0);
    temp0 = REG_READ(addr);
    addr = pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT1_OFFSET;
    REG_WRITE(addr, reg1);
    temp1 = REG_READ(addr);
    addr = pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT2_OFFSET;
    REG_WRITE(addr, reg2);
    temp2 = REG_READ(addr);
    addr = pSSDConfig->ftfxRegBase + FTFx_SSD_FPROT3_OFFSET;
    REG_WRITE(addr, reg3);
    temp3 = REG_READ(addr);

    /* Read the value of FPPROT registers */
    if ((temp0 != reg0) || (temp1 != reg1) || (temp2 != reg2) || (temp3 != reg3))
    {
        ret = FTFx_ERR_CHANGEPROT;
    }

#if C90TFS_ENABLE_DEBUG
    /* Enter Debug state if enabled */
    if (TRUE == (pSSDConfig->DebugEnable))
    {
        ENTER_DEBUG_MODE;
    }
#endif

    return(ret);
}