/****************************************************************************** * * Title : commandFunc_readWriteSlave.c * Version 0.0 * * Description: Reads/writes data from/to Slave DSP memory space. * * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include #include "commandListDefinitions.h" #include "commandFunc_readWriteSlave.h" #include "commandParamsUir.h" #include "globalDefinitions.h" #include "uirUtility.h" #include "mainUir.h" #include "vmeHpiUtility.h" #include "commandStatusMessage.h" #include "RWlists.h" /****************************************************************************** * Global functions * ******************************************************************************/ /*============================================================================= * commandFunction_readWriteMaster() *============================================================================= * * * */ ERROR_ID commandFunction_readWriteSlave(COMMAND_FUNC_OPTION funcOption, struct COMMAND *command, UINT8 slotNumber, FILE *file){ struct HOST *host; const int panel=global.panel.commandEdit[RW_SLAVE_COMMAND_ID]; struct RW_SLAVE_PARAMS *RWSlave=&command->params.readWriteSlave; int status; ERROR_ID errorId=SUCCESS; long fileSize; int option; UINT32 *buffer=NULL; char subdir[PATHNAME_LENGTH]; char inputText[500]; switch(funcOption){ case COMMAND_TO_LIST: GetCtrlVal(panel, RW_SLAVEP_SLAVE_NUMBER, &RWSlave->slaveNumber); GetCtrlVal(panel, RW_SLAVEP_READ_NOT_WRITE, &RWSlave->readNotWrite); GetCtrlVal(panel, RW_SLAVEP_START_ADDR, &RWSlave->startAddress); GetCtrlVal(panel, RW_SLAVEP_LENGTH, &RWSlave->length); if(RWSlave->length==0) { status = MessagePopup ("WARNING", "DataLength==0!!"); UIR_STATUS_CHECK(status, MessagePopup()); return(PROGRAM_WARNING); } if(RWSlave->readNotWrite==0){ /* write */ GetCtrlVal(panel, RW_SLAVEP_INP_OPTION, &RWSlave->write.dataNotFile); if(RWSlave->write.dataNotFile){ /* one word */ GetCtrlVal(panel, RW_SLAVEP_INPUT_DATA, &RWSlave->write.data); }else{ /* from file */ GetCtrlVal(panel, RW_SLAVEP_INP_FILE, RWSlave->write.fileName); if(RWSlave->write.fileName[0]==0) { status = MessagePopup ("WARNING", "No InputDataFile selected!!"); UIR_STATUS_CHECK(status, MessagePopup()); return(PROGRAM_WARNING); } } }else{ /* read */ GetCtrlVal(panel, RW_SLAVEP_OUTPUT_OPT, &option); if(option){ GetCtrlVal(panel, RW_SLAVEP_WRITE_OR_APPEND, &RWSlave->read.appendNotWrite); GetCtrlVal(panel, RW_SLAVEP_OUT_FILE, RWSlave->read.fileName); } else { RWSlave->read.fileName[0]=0; } GetCtrlVal(panel, RW_SLAVEP_COMP_OPTION, &RWSlave->read.compareWithData); GetCtrlVal(panel, RW_SLAVEP_COMP_DATA, &RWSlave->read.compData); } break; case LIST_TO_COMMAND: SetCtrlVal(panel, RW_SLAVEP_SLAVE_NUMBER, RWSlave->slaveNumber); SetCtrlVal(panel, RW_SLAVEP_READ_NOT_WRITE, RWSlave->readNotWrite); SetCtrlVal(panel, RW_SLAVEP_START_ADDR, RWSlave->startAddress); SetCtrlVal(panel, RW_SLAVEP_LENGTH, RWSlave->length); if(RWSlave->readNotWrite==0){ /* write */ status=SetCtrlAttribute(panel, RW_SLAVEP_LENGTH, ATTR_CTRL_MODE, VAL_INDICATOR); UIR_STATUS_CHECK(status, SetCtrlAttribute()); status=SetCtrlAttribute(panel, RW_SLAVEP_LENGTH, ATTR_FRAME_COLOR, VAL_LT_GRAY); UIR_STATUS_CHECK(status, SetCtrlAttribute()); SetCtrlVal(panel, RW_SLAVEP_INP_OPTION, RWSlave->write.dataNotFile); status=SetInputMode(panel, RW_SLAVEP_INP_OPTION, 1); UIR_STATUS_CHECK(status, SetInputMode()); if(RWSlave->write.dataNotFile){ /* one word */ SetCtrlVal(panel, RW_SLAVEP_INPUT_DATA, RWSlave->write.data); status=SetInputMode(panel, RW_SLAVEP_INPUT_DATA, 1); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(panel, RW_SLAVEP_INP_FILE, 0); UIR_STATUS_CHECK(status, SetInputMode()); }else{ /* from file */ SetCtrlVal(panel, RW_SLAVEP_INP_FILE, RWSlave->write.fileName); status=SetInputMode(panel, RW_SLAVEP_INP_FILE, 1); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(panel, RW_SLAVEP_INPUT_DATA, 0); UIR_STATUS_CHECK(status, SetInputMode()); } status=SetInputMode(panel, RW_SLAVEP_OUTPUT_OPT, 0); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(panel, RW_SLAVEP_WRITE_OR_APPEND, 0); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(panel, RW_SLAVEP_OUT_FILE, 0); UIR_STATUS_CHECK(status, SetInputMode()); SetCtrlVal(panel, RW_SLAVEP_COMP_DATA, 0); status=SetInputMode(panel, RW_SLAVEP_COMP_OPTION, 0); UIR_STATUS_CHECK(status, SetInputMode()); SetCtrlVal(panel, RW_SLAVEP_COMP_DATA, 0); status=SetInputMode(panel, RW_SLAVEP_COMP_DATA, 0); UIR_STATUS_CHECK(status, SetInputMode()); }else{ /* read */ status=SetCtrlAttribute(panel, RW_SLAVEP_LENGTH, ATTR_FRAME_COLOR, 0xCC9966); UIR_STATUS_CHECK(status, SetCtrlAttribute()); status=SetCtrlAttribute(panel, RW_SLAVEP_LENGTH, ATTR_CTRL_MODE, VAL_NORMAL); UIR_STATUS_CHECK(status, SetCtrlAttribute()); SetCtrlVal(panel, RW_SLAVEP_WRITE_OR_APPEND, RWSlave->read.appendNotWrite); status=SetInputMode(panel, RW_SLAVEP_INPUT_DATA, 0); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(panel, RW_SLAVEP_INP_FILE, 0); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(panel, RW_SLAVEP_INP_OPTION, 0); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(panel, RW_SLAVEP_WRITE_OR_APPEND, 1); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(panel, RW_SLAVEP_OUTPUT_OPT, 1); UIR_STATUS_CHECK(status, SetInputMode()); SetCtrlVal(panel, RW_SLAVEP_OUT_FILE, RWSlave->read.fileName); if(RWSlave->read.fileName[0]==0){ SetCtrlVal(panel, RW_SLAVEP_OUTPUT_OPT, 0); status=SetInputMode(panel, RW_SLAVEP_OUT_FILE, 0); UIR_STATUS_CHECK(status, SetInputMode()); }else{ SetCtrlVal(panel, RW_SLAVEP_OUTPUT_OPT, 1); status=SetInputMode(panel, RW_SLAVEP_OUT_FILE, 1); UIR_STATUS_CHECK(status, SetInputMode()); } SetCtrlVal(panel, RW_SLAVEP_COMP_OPTION, RWSlave->read.compareWithData); status=SetInputMode(panel, RW_SLAVEP_COMP_OPTION, (RWSlave->length<=4)); UIR_STATUS_CHECK(status, SetInputMode()); SetCtrlVal(panel, RW_SLAVEP_COMP_DATA, RWSlave->read.compData); status=SetInputMode(panel, RW_SLAVEP_COMP_DATA, RWSlave->read.compareWithData); UIR_STATUS_CHECK(status, SetInputMode()); } break; case COMMAND_EXECUTION: host=global.host[HOST_INDEX(slotNumber)]; errorId=setHpicMaster(host->slotNumber); HOST_ERROR_CHECK(errorId, host, setHpicMaster()); if(errorId!=SUCCESS) return(COMMAND_ERROR); errorId=setHpicSlave(host->slotNumber, RWSlave->slaveNumber); HOST_ERROR_CHECK(errorId, host, setHpicMaster()); if(errorId!=SUCCESS) return(COMMAND_ERROR); if(RWSlave->readNotWrite){ /* read */ buffer=malloc(RWSlave->length); if(buffer==NULL){ HOST_ERROR_CHECK(PROGRAM_ERROR, host, malloc()); return(COMMAND_ERROR); } errorId=RWslave(READ, host->slotNumber, RWSlave->slaveNumber, RWSlave->startAddress, buffer, RWSlave->length/4, 0); HOST_ERROR_CHECK(errorId, host, RWslave()); if(errorId!=SUCCESS){ free(buffer); return(COMMAND_ERROR); } if(RWSlave->read.fileName[0]!=0){ strcpy(subdir, host->dataDir); strcat(subdir, RWSlave->read.fileName); errorId=writeToBinFile(subdir, RWSlave->read.appendNotWrite, buffer, RWSlave->length); HOST_ERROR_CHECK(errorId, host, writeToBinFile()); if(errorId!=SUCCESS){ free(buffer); return(COMMAND_ERROR); } } if(RWSlave->read.compareWithData){ /* compare data */ if(*buffer!=RWSlave->read.compData){ sprintf(inputText,"##READ SLAVE DATA COMPARISON(@addr:0x%X, slave#%d) - read(0x%X) and comp(0x%X) data are NOT equal!!\n", RWSlave->startAddress, RWSlave->slaveNumber, *buffer, RWSlave->read.compData); errorId=commandStatusMessage(host, host->commandStatusFile, inputText); HOST_ERROR_CHECK(errorId, host, commandStatusMessage()); free(buffer); return(COMMAND_ERROR); } } }else{ /* write */ if(RWSlave->write.dataNotFile){ errorId=RWslave(WRITE, host->slotNumber, RWSlave->slaveNumber, RWSlave->startAddress, &RWSlave->write.data, RWSlave->length/4, 0); HOST_ERROR_CHECK(errorId, host, RWslave()); if(errorId!=SUCCESS) return(COMMAND_ERROR); }else{ buffer=malloc(RWSlave->length); if(buffer==NULL){ HOST_ERROR_CHECK(PROGRAM_ERROR, host, malloc()); return(COMMAND_ERROR); } errorId=readFromBinFile(RWSlave->write.fileName, buffer, RWSlave->length); HOST_ERROR_CHECK(errorId, host, readFromBinFile()); if(errorId!=SUCCESS){ free(buffer); return(COMMAND_ERROR); } errorId=RWslave(WRITE, host->slotNumber, RWSlave->slaveNumber, RWSlave->startAddress, buffer, RWSlave->length/4, 0); HOST_ERROR_CHECK(errorId, host, RWslave()); if(errorId!=SUCCESS){ free(buffer); return(COMMAND_ERROR); } } } if(buffer!=NULL) free(buffer); /* !!! */ break; case SAVE_CMD_TO_FILE: fprintf(file, "slaveNumber= %d, readNotWrite= %d, startAddress= 0x%X, length= 0x%X\n", RWSlave->slaveNumber, RWSlave->readNotWrite, RWSlave->startAddress, RWSlave->length); if(RWSlave->readNotWrite==0){ /* write */ fprintf(file, "dataNotFile= %d, data= 0x%X\n", RWSlave->write.dataNotFile, RWSlave->write.data); fprintf(file, "fileName[]= %s\n", RWSlave->write.fileName); }else{ /* read */ fprintf(file, "compareWithData= %d, compData= 0x%X, appendNotWrite= %d\n", RWSlave->read.compareWithData, RWSlave->read.compData, RWSlave->read.appendNotWrite); fprintf(file, "fileName[]= %s\n", RWSlave->read.fileName); } break; case LOAD_CMD_FROM_FILE: status=fscanf(file, "slaveNumber= %d, readNotWrite= %d, startAddress= 0x%X, length= 0x%X\n", (int*)&RWSlave->slaveNumber, &RWSlave->readNotWrite, &RWSlave->startAddress, &RWSlave->length); if(status==-1) {ERROR_CHECK(FATAL_ERROR, Read from cmd file error!); return(FATAL_ERROR);} if(RWSlave->readNotWrite==0){ /* write */ status=fscanf(file, "dataNotFile= %d, data= 0x%X\n", &RWSlave->write.dataNotFile, &RWSlave->write.data); if(status==-1) {ERROR_CHECK(FATAL_ERROR, Read from cmd file error!); return(FATAL_ERROR);} status=readLineFromIndex(file, strlen("fileName[]= "), PATHNAME_LENGTH, RWSlave->write.fileName); if(status!=0) {ERROR_CHECK(FATAL_ERROR, Read from cmd file error!); return(FATAL_ERROR);} }else{ /* read */ status=fscanf(file, "compareWithData= %d, compData= 0x%X, appendNotWrite= %d\n", &RWSlave->read.compareWithData, &RWSlave->read.compData, &RWSlave->read.appendNotWrite); if(status==-1) {ERROR_CHECK(FATAL_ERROR, Read from cmd file error!); return(FATAL_ERROR);} status=readLineFromIndex(file, strlen("fileName[]= "), PATHNAME_LENGTH, RWSlave->read.fileName); if(status!=0) {ERROR_CHECK(FATAL_ERROR, Read from cmd file error!); return(FATAL_ERROR);} } break; default: ; } return(SUCCESS); } /******************************************************************************/