/****************************************************************************** * * Title : commandFunc_readWriteMDSPFlash.c * Version 0.0 * * Description: Writes data to master DSP flash. * Note: You can use command RW_MASTER_MEMORY to read data back. * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include #include "commandListDefinitions.h" #include "commandFunc_writeMDSPFlash.h" #include "commandParamsUir.h" #include "globalDefinitions.h" #include "uirUtility.h" #include "mainUir.h" #include "vmeHpiUtility.h" #include "commandStatusMessage.h" #include "flashUtility.h" #include "RWlists.h" #define I_AM_MASTER_DSP #undef IDREGS_BASE #include "memoryPartitions.h" //dspf: BOOT_ROM_BASE => use memory map. #undef I_AM_MASTER_DSP /****************************************************************************** * Global functions * ******************************************************************************/ /*============================================================================= * commandFunction_writeMDSPFlash() *============================================================================= * * * */ ERROR_ID commandFunction_writeMDSPFlash(COMMAND_FUNC_OPTION funcOption, struct COMMAND *command, UINT8 slotNumber, FILE *file){ struct HOST *host; const int panel=global.panel.commandEdit[WRITE_MDSP_FLASH_ID]; struct W_MDSP_FLASH_PARAMS *writeMDSPFlash=&command->params.writeMDSPFlash; int status; ERROR_ID errorId=SUCCESS; unsigned int fileSize; UINT8 *buffer; char subdir[PATHNAME_LENGTH]; int sector, endSector; UINT32 flashBottomRelAddress; UINT32 sourceVmeAddr; switch(funcOption){ case COMMAND_TO_LIST: GetCtrlVal(panel, W_MDSPF_SIZE, &writeMDSPFlash->size); if(writeMDSPFlash->size == 0) { status= MessagePopup("WARNING", "DataSize==0!!"); UIR_STATUS_CHECK(status, MessagePopup()); return(PROGRAM_WARNING); } GetCtrlVal(panel, W_MDSPF_INP_FILE, writeMDSPFlash->inputFileName); if(writeMDSPFlash->inputFileName[0] == 0) { status= MessagePopup("WARNING", "No InputDataFile selected!!"); UIR_STATUS_CHECK(status, MessagePopup()); return(PROGRAM_WARNING); } break; case LIST_TO_COMMAND: SetCtrlVal(panel, W_MDSPF_SIZE, writeMDSPFlash->size); SetCtrlVal(panel, W_MDSPF_INP_FILE, writeMDSPFlash->inputFileName); break; case COMMAND_EXECUTION: host=global.host[HOST_INDEX(slotNumber)]; /* set little endian */ errorId= setHpicMaster(host->slotNumber); ERROR_CHECK(errorId, setHpic()); errorId= getFileSize (writeMDSPFlash->inputFileName, &fileSize); ERROR_CHECK(errorId, getFileSize()); if(errorId != SUCCESS) return(errorId); buffer= malloc(fileSize); if(buffer == NULL){ HOST_ERROR_CHECK(PROGRAM_ERROR, host, malloc()); return(COMMAND_ERROR); } errorId= readFromBinFile(writeMDSPFlash->inputFileName, buffer, fileSize); HOST_ERROR_CHECK(errorId, host, readFromBinFile()); if(errorId != SUCCESS){ free(buffer); return(COMMAND_ERROR); } /* write data */ errorId= writeBlockToFlashHpi(host->slotNumber, MDSP_FLASH_BOTTOM_REL_ADDR, buffer, fileSize); ERROR_CHECK(errorId, writeBlockToFlash()); if(errorId != SUCCESS){ free(buffer); return(COMMAND_ERROR); } free(buffer); /* !!! */ break; case SAVE_CMD_TO_FILE: fprintf(file, "size= 0x%X\n", writeMDSPFlash->size); fprintf(file, "inputFileName[]= %s\n", writeMDSPFlash->inputFileName); break; case LOAD_CMD_FROM_FILE: status= fscanf(file, "size= 0x%X\n", &writeMDSPFlash->size); if(status == -1) {ERROR_CHECK(FATAL_ERROR, Read from cmd file error!); return(FATAL_ERROR);} status= readLineFromIndex(file, strlen("inputFileName[]= "), PATHNAME_LENGTH, writeMDSPFlash->inputFileName); if(status != 0) {ERROR_CHECK(FATAL_ERROR, Read from cmd file error!); return(FATAL_ERROR);} break; default: ; } return(SUCCESS); } /******************************************************************************/