/******************************************************************************* * Function Name: CFG_EEPROM_StartWrite ******************************************************************************** * * Summary: * Starts a write of a row (16 bytes) of data to the EEPROM. * 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 that the * write has completed. Until CFG_EEPROM_Query() detects that * the write is complete, the SPC is marked as locked to prevent another * SPC operation from being performed. For a reliable write procedure to occur * you should call CFG_EEPROM_UpdateTemperature() API if the temperature * of the silicon has changed for more than 10C since component was started. * * Parameters: * rowData: The address of the data to write to the EEPROM. * rowNumber: The row number to write. * * Return: * CYRET_STARTED, if the SPC command to write was successfully started. * CYRET_BAD_PARAM, if the parameter rowNumber 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_StartWrite(const uint8 * rowData, uint8 rowNumber) \ { cystatus status; CySpcStart(); if(rowNumber < (uint8) CY_EEPROM_NUMBER_ROWS) { /* See if we can get SPC. */ if(CySpcLock() == CYRET_SUCCESS) { /* Plan for failure */ status = CYRET_UNKNOWN; /* Command to load a row of data */ if(CySpcLoadRow(CY_SPC_FIRST_EE_ARRAYID, rowData, 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 and program the row. */ if(status == CYRET_SUCCESS) { if(CySpcWriteRow(CY_SPC_FIRST_EE_ARRAYID, (uint16)rowNumber, dieTemperature[0u], dieTemperature[1u]) == CYRET_STARTED) { status = CYRET_STARTED; } else { status = CYRET_UNKNOWN; } } else { status = CYRET_UNKNOWN; } } } else { status = CYRET_LOCKED; } } else { status = CYRET_BAD_PARAM; } return(status); }
/******************************************************************************* * Function Name: CyWriteRowFull ******************************************************************************** * Summary: * Sends a command to the SPC to load and program a row of data in flash. * rowData array is expected to contain Flash and ECC data if needed. * * Parameters: * arrayId: FLASH or EEPROM array id. * rowData: pointer to a row of data to write. * rowNumber: Zero based number of the row. * rowSize: Size of the row. * * Return: * CYRET_SUCCESS if successful. * CYRET_LOCKED if the SPC is already in use. * CYRET_CANCELED if command not accepted * CYRET_UNKNOWN if there was an SPC error. * *******************************************************************************/ cystatus CyWriteRowFull(uint8 arrayId, uint16 rowNumber, const uint8* rowData, uint16 rowSize) \ { cystatus status; if(CySpcLock() == CYRET_SUCCESS) { /* Load row data into SPC internal latch */ status = CySpcLoadRow(arrayId, rowData, rowSize); if(CYRET_STARTED == status) { while(CY_SPC_BUSY) { /* Wait for SPC to finish and get SPC status */ CyDelayUs(1u); } /* Hide SPC status */ if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS) { status = CYRET_SUCCESS; } else { status = CYRET_UNKNOWN; } if(CYRET_SUCCESS == status) { /* Erase and program flash with the data from SPC interval latch */ status = CySpcWriteRow(arrayId, rowNumber, dieTemperature[0u], dieTemperature[1u]); if(CYRET_STARTED == status) { while(CY_SPC_BUSY) { /* Wait for SPC to finish and get SPC status */ CyDelayUs(1u); } /* Hide SPC status */ if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS) { status = CYRET_SUCCESS; } else { status = CYRET_UNKNOWN; } } } } CySpcUnlock(); } else { status = CYRET_LOCKED; } return(status); }
/******************************************************************************* * 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); }