void `$INSTANCE_NAME`_WriteByte(uint8 value, uint16 address) { uint8 row, offset; cystatus status; if(address < `$INSTANCE_NAME`_EEPROM_SIZE) { // calculate the row, and offset within the row row = address / `$INSTANCE_NAME`_EEPROM_ROW_SIZE; offset = address - ((uint16)row*(uint16)`$INSTANCE_NAME`_EEPROM_ROW_SIZE); // Turn on the SPC CySpcStart(); // lock the spc to prevent some other process from using it CySpcLock(); // loads a byte of data into the temporary SPC write buffer. Write the byte into the proper offset // in the temporary SPC buffer. The offset is an artifact of the "row" oriented write operations of // our EEPROM and flash. The load multibyte SPC function loads the temporary "row" with the data we intend // to write. later, this temporary row is written into the proper "row" with another function call. // to place the byte where we want it, we have to calculate the destination row, and offset within that // row. if(CySpcLoadMultiByte(CY_SPC_FIRST_EE_ARRAYID, offset, &value, `$INSTANCE_NAME`_SPC_BYTE_WRITE_SIZE) == CYRET_STARTED) { while(CY_SPC_BUSY) { /* Wait until SPC becomes idle */ } // this is where we tell the SPC to write the write the temporary row into the EEPROM. if(CySpcWriteRow(CY_SPC_FIRST_EE_ARRAYID, row, dieTemperature[0], dieTemperature[1]) == CYRET_STARTED) { while(CY_SPC_BUSY) { /* Wait until SPC becomes idle */ } } } /* Unlock the SPC so someone else can use it. */ CySpcUnlock(); // turn off the SPC CySpcStop(); } }
/******************************************************************************* * Function Name: CFG_EEPROM_ByteWritePos ******************************************************************************** * * Summary: * Writes a byte of data to the EEPROM. This is a blocking call. It will not * return until the write operation succeeds or fails. * * Parameters: * dataByte: The byte of data to write to the EEPROM. * rowNumber: The EEPROM row number to program. * byteNumber: The byte number within the row to program. * * Return: * CYRET_SUCCESS, if the operation was successful. * CYRET_BAD_PARAM, if the parameter rowNumber or byteNumber is out of range. * CYRET_LOCKED, if the SPC is being used. * CYRET_UNKNOWN, if there was an SPC error. * *******************************************************************************/ cystatus CFG_EEPROM_ByteWritePos(uint8 dataByte, uint8 rowNumber, uint8 byteNumber) \ { cystatus status; /* Start SPC */ CySpcStart(); if((rowNumber < (uint8) CY_EEPROM_NUMBER_ROWS) && (byteNumber < (uint8) SIZEOF_EEPROM_ROW)) { /* See if we can get SPC. */ if(CySpcLock() == CYRET_SUCCESS) { /* Plan for failure */ status = CYRET_UNKNOWN; /* Command to load byte of data */ if(CySpcLoadMultiByte(CY_SPC_FIRST_EE_ARRAYID, (uint16)byteNumber, &dataByte,\ CFG_EEPROM_SPC_BYTE_WRITE_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) { /* 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; } } 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); }
/******************************************************************************* * Function Name: CFG_EEPROM_WriteByte ******************************************************************************** * * Summary: * Writes a byte of data to the EEPROM. This function blocks until * the function is complete. For a reliable write procedure to occur you should * call CFG_EEPROM_UpdateTemperature() function if the temperature of the * silicon has been changed for more than 10C since the component was started. * * Parameters: * dataByte: The byte of data to write to the EEPROM * address: The address of data to be written. The maximum address is dependent * on the EEPROM size. * * 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_WriteByte(uint8 dataByte, uint16 address) { cystatus status; uint16 rowNumber; uint16 byteNumber; CySpcStart(); if (address < CY_EEPROM_SIZE) { rowNumber = address/(uint16)CY_EEPROM_SIZEOF_ROW; byteNumber = address - (rowNumber * ((uint16)CY_EEPROM_SIZEOF_ROW)); if(CYRET_SUCCESS == CySpcLock()) { status = CySpcLoadMultiByte(CY_SPC_FIRST_EE_ARRAYID, byteNumber, &dataByte, \ CFG_EEPROM_SPC_BYTE_WRITE_SIZE); if (CYRET_STARTED == status) { /* Plan for failure */ status = CYRET_UNKNOWN; while(CY_SPC_BUSY) { /* Wait until SPC becomes idle */ } if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS) { status = CYRET_SUCCESS; } /* Command to erase and program the row. */ if(CYRET_SUCCESS == status) { if(CySpcWriteRow(CY_SPC_FIRST_EE_ARRAYID, (uint16)rowNumber, dieTemperature[0u], dieTemperature[1u]) == 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; } } else { status = CYRET_UNKNOWN; } } else { if (CYRET_BAD_PARAM != status) { status = CYRET_UNKNOWN; } } CySpcUnlock(); } else { status = CYRET_LOCKED; } } else { status = CYRET_BAD_PARAM; } return (status); }