コード例 #1
0
ファイル: CFG_EEPROM.c プロジェクト: fhgwright/SCSI2SD
/*******************************************************************************
* Function Name: CFG_EEPROM_StartErase
********************************************************************************
*
* Summary:
*  Starts the EEPROM sector erase. This function does not block.
*  The function returns once the SPC has begun writing the data. This function
*  must be used in combination with CFG_EEPROM_Query().
*  CFG_EEPROM_Query() must be called until it returns a status
*  other than CYRET_STARTED. That indicates the erase has been completed.
*  Until CFG_EEPROM_Query() detects that the erase is
*  complete, the SPC is marked as locked to prevent another SPC operation
*  from being performed.
*
* Parameters:
*  sectorNumber:  The sector number to erase.
*
* Return:
*  CYRET_STARTED, if the SPC command to erase was successfully started.
*  CYRET_BAD_PARAM, if the parameter sectorNumber is out of range.
*  CYRET_LOCKED, if the SPC is being used.
*  CYRET_UNKNOWN, if there was an SPC error.
*
* Side effects:
*  After calling this API, the device should not be powered down, reset or switched
*  to low power modes until EEPROM operation is complete.
*  Ignoring this recommendation may lead to data corruption or silicon
*  unexpected behavior.
*
*******************************************************************************/
cystatus CFG_EEPROM_StartErase(uint8 sectorNumber) 
{
    cystatus status;
    
    CySpcStart();

    if(sectorNumber < (uint8) CY_EEPROM_NUMBER_ARRAYS)
    {
        /* See if we can get SPC. */
        if(CySpcLock() == CYRET_SUCCESS)
        {
            /* Plan for failure */
            status = CYRET_UNKNOWN;

            /* Command to load a row of data */
            if(CySpcEraseSector(CY_SPC_FIRST_EE_ARRAYID, sectorNumber) == CYRET_STARTED)
            {
                status = CYRET_SUCCESS;
            }
        }
        else
        {
            status = CYRET_LOCKED;
        }
    }
    else
    {
        status = CYRET_BAD_PARAM;
    }

    return(status);
}
コード例 #2
0
ファイル: CFG_EEPROM.c プロジェクト: fhgwright/SCSI2SD
/*******************************************************************************
* Function Name: CFG_EEPROM_EraseSector
********************************************************************************
*
* Summary:
*  Erase an EEPROM sector (64 rows). This function blocks until the erase
*  operation is complete. Using this API helps to erase the EEPROM sector at
*  a time. This is faster than using individual writes but affects a cycle
*  recourse of the whole EEPROM row.
*
* Parameters:
*  sectorNumber:  The sector number to erase.
*
* Return:
*  CYRET_SUCCESS, if the operation was successful.
*  CYRET_BAD_PARAM, if the parameter sectorNumber is out of range.
*  CYRET_LOCKED, if the SPC is being used.
*  CYRET_UNKNOWN, if there was an SPC error.
*
*******************************************************************************/
cystatus CFG_EEPROM_EraseSector(uint8 sectorNumber) 
{
    cystatus status;
    
    CySpcStart();

    if(sectorNumber < (uint8) CFG_EEPROM_SECTORS_NUMBER)
    {
        /* See if we can get SPC. */
        if(CySpcLock() == CYRET_SUCCESS)
        {
            if(CySpcEraseSector(CY_SPC_FIRST_EE_ARRAYID, sectorNumber) == CYRET_STARTED)
            {
                /* Plan for failure */
                status = CYRET_UNKNOWN;

                while(CY_SPC_BUSY)
                {
                    /* Wait until SPC becomes idle */
                }

                /* SPC is idle now */
                if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
                {
                    status = CYRET_SUCCESS;
                }
            }
            else
            {
                status = CYRET_UNKNOWN;
            }

            /* Unlock SPC so that someone else can use it. */
            CySpcUnlock();
        }
        else
        {
            status = CYRET_LOCKED;
        }
    }
    else
    {
        status = CYRET_BAD_PARAM;
    }

    return(status);
}
コード例 #3
0
/*******************************************************************************
* Function Name: EEPROM_Real_EraseSector
********************************************************************************
*
* Summary:
*  Erases a sector of memory. This function blocks until the operation is
*  complete.
*
* Parameters:
*  sectorNumber:  Sector number to erase.
*
* Return:
*  CYRET_SUCCESS, if the operation was successful.
*  CYRET_BAD_PARAM, if the parameter sectorNumber out of range.
*  CYRET_LOCKED, if the spc is being used.
*  CYRET_UNKNOWN, if there was an SPC error.
*
*******************************************************************************/
cystatus EEPROM_Real_EraseSector(uint8 sectorNumber) 
{
    cystatus status;

    /* Start the SPC */
    CySpcStart();

    if(sectorNumber < (uint8) CY_EEPROM_NUMBER_ARRAYS)
    {
        /* See if we can get the SPC. */
        if(CySpcLock() == CYRET_SUCCESS)
        {
            #if(CY_PSOC5A)

                /* Plan for failure */
                status = CYRET_UNKNOWN;

                /* Command to load a row of data */
                if(CySpcLoadRow(CY_SPC_FIRST_EE_ARRAYID, 0, CYDEV_EEPROM_ROW_SIZE) == CYRET_STARTED)
                {
                    while(CY_SPC_BUSY)
                    {
                        /* Wait until SPC becomes idle */
                    }

                    /* SPC is idle now */
                    if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
                    {
                        status = CYRET_SUCCESS;
                    }
                }

                /* Command to erase a sector */
                if(status == CYRET_SUCCESS)
                {

            #endif /* (CY_PSOC5A) */

                    if(CySpcEraseSector(CY_SPC_FIRST_EE_ARRAYID, sectorNumber) == CYRET_STARTED)
                    {
                        /* Plan for failure */
                        status = CYRET_UNKNOWN;

                        while(CY_SPC_BUSY)
                        {
                            /* Wait until SPC becomes idle */
                        }

                        /* SPC is idle now */
                        if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
                        {
                            status = CYRET_SUCCESS;
                        }
                    }
                    else
                    {
                        status = CYRET_UNKNOWN;
                    }

            #if(CY_PSOC5A)

                }
                else
                {
                    status = CYRET_UNKNOWN;
                }

            #endif /* (CY_PSOC5A) */

                /* Unlock the SPC so someone else can use it. */
                CySpcUnlock();
        }
        else
        {
            status = CYRET_LOCKED;
        }
    }
    else
    {
        status = CYRET_BAD_PARAM;
    }

    return(status);
}