/******************************************************************************* * Function Name: CyWriteRowData ******************************************************************************** * * Summary: * Sends a command to the SPC to load and program a row of data in flash. * * Parameters: * arrayID : ID of the array to write. * rowAddress : rowAddress of flash row to program. * rowData : Array of bytes to write. * * Return: * status: * 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 CyWriteRowData(uint8 arrayId, uint16 rowAddress, const uint8 * rowData) { uint8 i; uint32 offset; uint16 rowSize; cystatus status; rowSize = (arrayId > CY_SPC_LAST_FLASH_ARRAYID) ? \ CYDEV_EEPROM_ROW_SIZE : \ (CYDEV_FLS_ROW_SIZE + CYDEV_ECC_ROW_SIZE); if(rowSize != CYDEV_EEPROM_ROW_SIZE) { /* Save the ECC area. */ offset = CYDEV_ECC_BASE + ((uint32) arrayId * CYDEV_ECC_SECTOR_SIZE) + ((uint32) rowAddress * CYDEV_ECC_ROW_SIZE); for (i = 0u; i < CYDEV_ECC_ROW_SIZE; i++) { *(rowBuffer + CYDEV_FLS_ROW_SIZE + i) = CY_GET_XTND_REG8((void CYFAR *)(offset + i)); } } /* Copy the rowdata to the temporary buffer. */ #if(CY_PSOC3) (void) memcpy((void *) rowBuffer, (void *)((uint32) rowData), (int16) CYDEV_FLS_ROW_SIZE); #else (void) memcpy((void *) rowBuffer, (const void *) rowData, CYDEV_FLS_ROW_SIZE); #endif /* (CY_PSOC3) */ status = CyWriteRowFull(arrayId, rowAddress, rowBuffer, rowSize); return(status); }
/******************************************************************************* * Function Name: CyWriteRowConfig ******************************************************************************** * * Summary: * Sends a command to the SPC to load and program a row of config data in flash. * This function is only valid for Flash array IDs (not for EEPROM). * * Parameters: * arrayId: * ID of the array to write * rowAddress: * Address of the sector to erase. * rowECC: * Array of bytes to write. * * Return: * status: * 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 CyWriteRowConfig(uint8 arrayId, uint16 rowAddress, const uint8 * rowECC) { uint32 offset; uint16 i; cystatus status; /* Read the existing flash data. */ offset = ((uint32) arrayId * CYDEV_FLS_SECTOR_SIZE) + ((uint32) rowAddress * CYDEV_FLS_ROW_SIZE); #if (CYDEV_FLS_BASE != 0u) offset += CYDEV_FLS_BASE; #endif for (i = 0u; i < CYDEV_FLS_ROW_SIZE; i++) { rowBuffer[i] = CY_GET_XTND_REG8((void CYFAR *)(offset + i)); } #if(CY_PSOC3) (void) memcpy((void *) &rowBuffer[CYDEV_FLS_ROW_SIZE], (void *)((uint32)rowECC), (int16) CYDEV_ECC_ROW_SIZE); #else (void) memcpy((void *) &rowBuffer[CYDEV_FLS_ROW_SIZE], (const void *) rowECC, CYDEV_ECC_ROW_SIZE); #endif /* (CY_PSOC3) */ status = CyWriteRowFull(arrayId, rowAddress, rowBuffer, CYDEV_FLS_ROW_SIZE + CYDEV_ECC_ROW_SIZE); return (status); }
/******************************************************************************* * Function Name: CyWriteRowConfig ******************************************************************************** * * Summary: * Sends a command to the SPC to load and program a row of config data in the * Flash. This function is only valid for Flash array IDs (not for EEPROM). * * Parameters: * arrayId: ID of the array to write * The arrays in the part are sequential starting at the first ID for the * specific memory type. The array ID for the Flash memory lasts * from 0x00 to 0x3F. * rowAddress: The address of the sector to erase. * rowECC: The array of bytes to write. * * Return: * status: * 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 CyWriteRowConfig(uint8 arrayId, uint16 rowAddress, const uint8 * rowECC)\ { cystatus status; status = CyWriteRowFull(arrayId, rowAddress, rowECC, CYDEV_ECC_ROW_SIZE); return (status); }
/******************************************************************************* * Function Name: CyWriteRowData ******************************************************************************** * * Summary: * Sends a command to the SPC to load and program a row of data in flash. * * Parameters: * arrayID: * ID of the array to write. * rowAddress: * rowAddress of flash row to program. * rowData: * Array of bytes to write. * * Return: * status: * 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 CyWriteRowData(uint8 arrayId, uint16 rowAddress, const uint8 * rowData) { uint16 rowSize; cystatus status; rowSize = (arrayId > CY_SPC_LAST_FLASH_ARRAYID) ? CYDEV_EEPROM_ROW_SIZE : CYDEV_FLS_ROW_SIZE; status = CyWriteRowFull(arrayId, rowAddress, rowData, rowSize); return(status); }
/******************************************************************************* * Function Name: CyWriteRowData ******************************************************************************** * * Summary: * Sends a command to the SPC to load and program a row of data in * Flash or EEPROM. * * Parameters: * arrayID : ID of the array to write. * The type of write, Flash or EEPROM, is determined from the array ID. * The arrays in the part are sequential starting at the first ID for the * specific memory type. The array ID for the Flash memory lasts from 0x00 to * 0x3F and for the EEPROM memory it lasts from 0x40 to 0x7F. * rowAddress : rowAddress of flash row to program. * rowData : Array of bytes to write. * * Return: * status: * 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 CyWriteRowData(uint8 arrayId, uint16 rowAddress, const uint8 * rowData) { uint8 i; uint32 offset; uint16 rowSize; cystatus status; /* Check whether rowBuffer pointer has been initialized by CySetFlashEEBuffer() */ if(NULL != rowBuffer) { if(arrayId > CY_SPC_LAST_FLASH_ARRAYID) { rowSize = CYDEV_EEPROM_ROW_SIZE; } else { rowSize = CYDEV_FLS_ROW_SIZE + CYDEV_ECC_ROW_SIZE; /* Save ECC area. */ offset = CYDEV_ECC_BASE + ((uint32)arrayId * CYDEV_ECC_SECTOR_SIZE) + ((uint32)rowAddress * CYDEV_ECC_ROW_SIZE); for(i = 0u; i < CYDEV_ECC_ROW_SIZE; i++) { *(rowBuffer + CYDEV_FLS_ROW_SIZE + i) = CY_GET_XTND_REG8((void CYFAR *)(offset + i)); } } /* Copy rowdata to temporary buffer. */ #if(CY_PSOC3) (void) memcpy((void *) rowBuffer, (void *)((uint32) rowData), (int16) CYDEV_FLS_ROW_SIZE); #else (void) memcpy((void *) rowBuffer, (const void *) rowData, CYDEV_FLS_ROW_SIZE); #endif /* (CY_PSOC3) */ status = CyWriteRowFull(arrayId, rowAddress, rowBuffer, rowSize); } else { status = CYRET_UNKNOWN; } return(status); }
/******************************************************************************* * Function Name: CyWriteRowConfig ******************************************************************************** * * Summary: * Sends a command to the SPC to load and program a row of config data in the Flash. * This function is only valid for Flash array IDs (not for EEPROM). * * Parameters: * arrayId: ID of the array to write * The arrays in the part are sequential starting at the first ID for the * specific memory type. The array ID for the Flash memory lasts * from 0x00 to 0x3F. * rowAddress: The address of the sector to erase. * rowECC: The array of bytes to write. * * Return: * status: * 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 CyWriteRowConfig(uint8 arrayId, uint16 rowAddress, const uint8 * rowECC)\ { uint32 offset; uint16 i; cystatus status; /* Check whether rowBuffer pointer has been initialized by CySetFlashEEBuffer() */ if(NULL != rowBuffer) { /* Read existing flash data. */ offset = ((uint32)arrayId * CYDEV_FLS_SECTOR_SIZE) + ((uint32)rowAddress * CYDEV_FLS_ROW_SIZE); #if (CYDEV_FLS_BASE != 0u) offset += CYDEV_FLS_BASE; #endif /* (CYDEV_FLS_BASE != 0u) */ for (i = 0u; i < CYDEV_FLS_ROW_SIZE; i++) { rowBuffer[i] = CY_GET_XTND_REG8((void CYFAR *)(offset + i)); } #if(CY_PSOC3) (void) memcpy((void *)&rowBuffer[CYDEV_FLS_ROW_SIZE], (void *)(uint32)rowECC, (int16)CYDEV_ECC_ROW_SIZE); #else (void) memcpy((void *)&rowBuffer[CYDEV_FLS_ROW_SIZE], (const void *)rowECC, CYDEV_ECC_ROW_SIZE); #endif /* (CY_PSOC3) */ status = CyWriteRowFull(arrayId, rowAddress, rowBuffer, CYDEV_FLS_ROW_SIZE + CYDEV_ECC_ROW_SIZE); } else { status = CYRET_UNKNOWN; } return (status); }
int CyBtldr_SD_Bootload(char * file){ char cyacd_header[10]; char cyacd_line[589]; unsigned char cyacd_arrayId; uint16 cyacd_rowAddress; char cyacd_rowData[288]; uint16 cyacd_rowSize; unsigned char cyacd_checksum; unsigned long siliconId; unsigned char siliconRev; int err=CYRET_SUCCESS; int Flash_err=CYRET_SUCCESS; /*Initialize Flash Write Mechanism*/ if(!INIT_FLASH_WRITE){ /*If the Flash Write wasnt initialized successfully, fire a software reset and hope things will work out.*/ CYBTLDR_SW_RESET; } /*Initialize the emFile FS*/ FS_Init(); /*Open the File for reading */ dataFile = FS_FOpen(file, "r"); /*File Opened*/ if (NULL != dataFile && FS_FEof(dataFile)!=1){ err=FS_Read(dataFile,cyacd_header,10); /* Read the Header line from the CYACD file.*/ if (err!=0){ /* Send the file pointer ahead by 4,setting it to the start of the first row */ err=FS_FSeek( dataFile,4, FS_SEEK_CUR); /*Parse the header for SiliconID and SiliconRev*/ err=CyBtldr_ParseHeader(10,cyacd_header,&siliconId,&siliconRev); /*Heres where you should check the SiliconID and Rev.*/ /* if(CYSWAP_ENDIAN32(CYDEV_CHIP_JTAG_ID)==siliconID && CYDEV_CHIP_REV_EXPECT==siliconRev){ }else{ }*/ }else{ /*We have EOF or a NULL dataFile FS structure.*/ err = CYRET_ERR_EOF; return err; } /*Lets get to the real stuff.*/ while(1){ /*Read the First Line after the header.*/ err=CyBtldr_ReadLine(cyacd_line); /*Check if the line was read successfully.*/ if(err!=CYRET_SUCCESS){ break; } /*Parse the line to get Row Address,Row Data,Row Size and the Checksum Byte*/ err=CyBtldr_ParseRowData(589,cyacd_line,&cyacd_arrayId,&cyacd_rowAddress,&cyacd_rowData,&cyacd_rowSize,&cyacd_checksum); /*Check if the data was parsed successfully.*/ if(err!=CYRET_SUCCESS){ break; } /*Write the Row Data to flash*/ CyWriteRowFull(cyacd_arrayId,cyacd_rowAddress,cyacd_rowData,cyacd_rowSize); } /*Close the File*/ err=FS_FClose(dataFile); /*Fire a software reset.*/ CYBTLDR_SW_RESET; return err; } return err; }