/****************************************************************************** * * Title : rodMemoryUir.c * Version 0.0 * * Description: callback functions (rod memory access). * Related files: rodMemoryUir.uir * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include #include "rodMemoryUir.h" #include "uirUtility.h" #include "vmeAddressMap.h" #include "vmeHpiUtility.h" #include "globalDefinitions.h" #include "fileUtility.h" #include "hostUtility.h" #include "threadUtility.h" #include "mainUir.h" #include /****************************************************************************** * LW_CVI callback functions * ******************************************************************************/ /*============================================================================= * vmeMemButtons() *============================================================================= * * * */ int CVICALLBACK vmeMemButtons (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ static unsigned int readAddress; static unsigned int writeAddress; static int previousControl; unsigned int tableAddress; static unsigned int lastReadAddress; static unsigned int firstReadAddress; static unsigned int lastWriteAddress; static unsigned int firstWriteAddress; static UINT32 findReadAddr= 0, findWriteAddr= 0; UINT32 tableNewAddr; static unsigned int readBytes; static unsigned int writeBytes; static unsigned char slotNumber; UINT32 defaultValue; UINT32 *dataPointer=NULL; ERROR_ID errorId; int rowIndex, columnIndex; /* table indexes */ static unsigned int tableReadLines; static unsigned int tableWriteLines; unsigned int slideValue; int dataIndex; int dimmed; int value, elementSize; int status; unsigned int wordAddress; unsigned int dataWord; unsigned int cellAddress; Point point; UINT32 addr, size; UINT32 i; char message[200]; static char fileName[260]; static unsigned int fileSize; int access; if(panel==global.panel.writeBuffVme){ if(event==EVENT_COMMIT){ switch(control){ case WRBUFF_VME_CANCEL: status=RemovePopup(0); if(status!=0){ programError(__FILE__, __LINE__, PROGRAM_ERROR, "RemovePopup()", status, ""); } break; case WRBUFF_VME_OK: status=RemovePopup(0); if(status!=0){ programError(__FILE__, __LINE__, PROGRAM_ERROR, "RemovePopup()", status, ""); } GetCtrlVal(panel, WRBUFF_VME_REL_ADDRESS, &writeAddress); writeAddress&=0xFFFFFFFC; SetCtrlVal(global.panel.vmeMemory, VME_MEM_WRITE_ADDRESS, writeAddress); if(previousControl==VME_MEM_NEW_BUFFER){ GetCtrlVal(panel, WRBUFF_VME_BYTES, &writeBytes); GetCtrlVal(panel, WRBUFF_VME_DEFAULT_VALUE, &defaultValue); } if(previousControl==VME_MEM_LOAD_FILE){ writeBytes=fileSize; } writeBytes&=0xFFFFFFFC; SetCtrlVal(global.panel.vmeMemory, VME_MEM_WRITE_BYTES, writeBytes); if(global.vmeMemoryWrite!=NULL){ /* if buffer already allocated, free it */ free(global.vmeMemoryWrite); // NEZAPOMEN VYNULOVAT PRI UKONCENI!!!!!!!!!!!!!!!!!!!! global.vmeMemoryWrite=NULL; } global.vmeMemoryWrite=calloc(writeBytes, sizeof(UINT8)); /* allocate and clear memory for data buffer */ if(global.vmeMemoryWrite==NULL){ ERROR_CHECK(PROGRAM_ERROR, calloc()); return(PROGRAM_ERROR); } if(previousControl==VME_MEM_LOAD_FILE){ errorId=readFromBinFile(fileName, global.vmeMemoryWrite, writeBytes); ERROR_CHECK(errorId, readFromBinFile()); if(errorId!=SUCCESS) return(errorId); }else{ for(i=0; i=writeAddress)&&(tableAddress<=lastWriteAddress)){ status = SetTableCellAttribute (global.panel.vmeMemory, VME_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); status = SetTableCellVal (global.panel.vmeMemory, VME_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), *dataPointer); ++dataPointer; } else { status = SetTableCellAttribute (global.panel.vmeMemory, VME_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } break; } } return(0); } if(event==EVENT_COMMIT){ GetCtrlVal(panel, VME_MEM_SLOT_NUMBER, &slotNumber); GetCtrlVal(panel, VME_MEM_VME_ACCESS, &elementSize); switch(control){ case VME_MEM_READ_MEMORY: status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); GetCtrlVal(panel, VME_MEM_READ_ADDRESS, &readAddress); readAddress&=0xFFFFFFFE; SetCtrlVal(panel, VME_MEM_READ_ADDRESS, readAddress); GetCtrlVal(panel, VME_MEM_READ_BYTES, &readBytes); readBytes&=0xFFFFFFFE; SetCtrlVal(panel, VME_MEM_READ_BYTES, readBytes); if(global.vmeMemoryRead!=NULL){ /* if buffer already allocated, free it */ free(global.vmeMemoryRead); global.vmeMemoryRead=NULL; } global.vmeMemoryRead=calloc(readBytes, elementSize); /* allocate and clear memory for data buffer */ if(global.vmeMemoryRead==NULL){ errorId=PROGRAM_ERROR; programError(__FILE__,__LINE__, errorId, "calloc(readDataBuffer)", errorId, ""); } /* read data block from VME */ if(slotNumber==TIM_SLOT_NUMBER) access=NO_BLOCK_ACCESS; else access=BLOCK_ACCESS; SetCtrlVal(panel, VME_MEM_VME_BUSY, 1); errorId=RWvmeBlock(READ, BASE_ADDRESS(slotNumber)+readAddress, (UINT32*)global.vmeMemoryRead, (UINT32)(readBytes/elementSize), elementSize, VME_ADDR_AUTOINCREMENT, access, 0); SetCtrlVal(panel, VME_MEM_VME_BUSY, 0); ERROR_CHECK(errorId, RWvmeBlock()); if (errorId!=SUCCESS){ status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; } /* fill table */ firstReadAddress=readAddress&0xFFFFFFF0; tableAddress=firstReadAddress; dataPointer=global.vmeMemoryRead; lastReadAddress=readAddress+readBytes-1; tableReadLines=(lastReadAddress-firstReadAddress)/16; status = SetCtrlAttribute (panel, VME_MEM_READ_TABLE_SLIDE, ATTR_MAX_VALUE, tableReadLines); status = SetCtrlAttribute (panel, VME_MEM_READ_TABLE_SLIDE, ATTR_INCR_VALUE, 16); SetCtrlVal(panel, VME_MEM_READ_TABLE_SLIDE, tableReadLines); SetCtrlVal(global.panel.vmeMemory, VME_MEM_READ_TABLE_ADDR, firstReadAddress); for(rowIndex=1; rowIndex<=16;++rowIndex){ /* fill address */ status = SetTableCellVal (panel, VME_MEM_READ_TABLE, MakePoint(1, rowIndex), tableAddress); for(columnIndex=2; columnIndex<=5; ++columnIndex, tableAddress+=0x4){ if((tableAddress>=readAddress)&&(tableAddress<=lastReadAddress)){ status = SetTableCellAttribute (panel, VME_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); status = SetTableCellVal(panel, VME_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), *(unsigned int*)dataPointer); ++dataPointer; } else { status = SetTableCellAttribute (panel, VME_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; case VME_MEM_SAVE_READ_TABLE: //dataBuffer readWords_32b status = FileSelectPopup (global.commonDataDir, "*.bin", "*.bin","Save read table to file", VAL_SAVE_BUTTON, 0, 0, 1, 0,fileName); switch(status){ case 0: /* no file selected */ break; case 1: /* existing file selected */ // no break here case 2: /* new file selected */ status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); errorId=writeToBinFile(fileName, 0, global.vmeMemoryRead, readBytes); ERROR_CHECK(errorId, writeToBinFile()); status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; default: // error break; } break; case VME_MEM_EXTERNAL_VIEWER: strcpy(fileName, global.mainDir); strcat(fileName, TEMPORARY_DATA_SUBDIR"vmeMemRead.tmp"); status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); errorId=writeToBinFile(fileName, 0, global.vmeMemoryRead, readBytes); ERROR_CHECK(errorId, writeToBinFile()); errorId=viewBinFile(fileName); ERROR_CHECK(errorId, viewBinFile()); status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; case VME_MEM_SAVE_WRITE_TABLE: status = FileSelectPopup (global.commonDataDir, "*.bin", "*.bin","Save write table to file",VAL_SAVE_BUTTON, 0, 0, 1, 0, fileName); switch(status){ case 0: /* no file selected */ break; case 1: /* existing file selected */ // no break here case 2: /* new file selected */ status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); errorId=writeToBinFile(fileName, 0, global.vmeMemoryWrite, writeBytes); ERROR_CHECK(errorId, writeToBinFile()); status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; default: // error break; } break; case VME_MEM_WRITE_TO_MEMORY: if(global.vmeMemoryWrite==NULL){ break; } status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); if(slotNumber==TIM_SLOT_NUMBER) access=NO_BLOCK_ACCESS; else access=BLOCK_ACCESS; SetCtrlVal(panel, VME_MEM_VME_BUSY, 1); errorId=RWvmeBlock(WRITE, BASE_ADDRESS(slotNumber)+writeAddress, (UINT32*)global.vmeMemoryWrite, (UINT32)writeBytes/elementSize, elementSize, VME_ADDR_AUTOINCREMENT, access, 0); SetCtrlVal(panel, VME_MEM_VME_BUSY, 0); ERROR_CHECK(errorId,RWvmeBlock()); status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; case VME_MEM_WRITE_WORD: GetCtrlVal(panel, VME_MEM_VME_ACCESS, &elementSize); GetCtrlVal(panel, VME_MEM_WORD_ADDRESS, &wordAddress); dataWord=0; //presunout do init GetCtrlVal(panel, VME_MEM_WRITE_DATA_WORD, &dataWord); SetCtrlVal(panel, VME_MEM_VME_BUSY, 1); errorId=vmeWriteElement((UINT32) dataWord,BASE_ADDRESS(slotNumber)+wordAddress, elementSize); SetCtrlVal(panel, VME_MEM_VME_BUSY, 0); ERROR_CHECK(errorId, vmeWriteElement()); break; case VME_MEM_READ_WORD: if(slotNumberlastReadAddress){ findReadAddr=lastReadAddress; } slideValue=(lastReadAddress-(findReadAddr&0xFFFFFFF0))/16; SetCtrlVal(panel, VME_MEM_READ_TABLE_SLIDE, slideValue); /* no break */ case VME_MEM_READ_TABLE_SLIDE: if(global.vmeMemoryRead==NULL){ break; } if(control==VME_MEM_READ_TABLE_SLIDE){ GetCtrlVal(panel, control, &slideValue); } tableAddress=(firstReadAddress+(tableReadLines-slideValue)*16)&0xFFFFFFF0; SetCtrlVal(panel, VME_MEM_READ_TABLE_ADDR, tableAddress); tableNewAddr=tableAddress; if(tableAddress>readAddress){ dataIndex=(tableAddress-readAddress)/4; } else { dataIndex=0; } dataPointer=&global.vmeMemoryRead[dataIndex]; for(rowIndex=1; rowIndex<=16;++rowIndex){ /* fill address */ status = SetTableCellVal (panel, VME_MEM_READ_TABLE, MakePoint(1, rowIndex), tableAddress); for(columnIndex=2; columnIndex<=5; ++columnIndex, tableAddress+=0x4){ status = GetTableCellAttribute (panel, VME_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, &dimmed); if((tableAddress>=readAddress)&&(tableAddress<=lastReadAddress)){ if(dimmed){ status = SetTableCellAttribute (panel, VME_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); } status = SetTableCellVal (panel, VME_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), *dataPointer); ++dataPointer; } else { if(dimmed==0){ status = SetTableCellAttribute (panel, VME_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } } if(control==VME_MEM_READ_TABLE_ADDR){ SetActiveCtrl (panel,VME_MEM_READ_TABLE); status = SetActiveTableCell (panel, VME_MEM_READ_TABLE, MakePoint((findReadAddr-tableNewAddr)/4+2,1)); } break; case VME_MEM_WRITE_TABLE_ADDR: GetCtrlVal(panel, control, &findWriteAddr); if(findWriteAddrlastWriteAddress){ findWriteAddr=lastWriteAddress; } slideValue=(lastWriteAddress-(findWriteAddr&0xFFFFFFF0))/16; SetCtrlVal(panel, VME_MEM_WRITE_TABLE_SLIDE, slideValue); /* no break */ case VME_MEM_WRITE_TABLE_SLIDE: if(global.vmeMemoryWrite==NULL){ break; } if(control==VME_MEM_WRITE_TABLE_SLIDE){ GetCtrlVal(panel, control, &slideValue); } tableAddress=(firstWriteAddress+(tableWriteLines-slideValue)*16)&0xFFFFFFF0; SetCtrlVal(panel, VME_MEM_WRITE_TABLE_ADDR, tableAddress); tableNewAddr=tableAddress; if(tableAddress>writeAddress){ dataIndex=(tableAddress-writeAddress)/4; } else { dataIndex=0; } dataPointer=&global.vmeMemoryWrite[dataIndex]; for(rowIndex=1; rowIndex<=16;++rowIndex){ /* fill address */ status = SetTableCellVal (panel, VME_MEM_WRITE_TABLE, MakePoint(1, rowIndex), tableAddress); for(columnIndex=2; columnIndex<=5; ++columnIndex, tableAddress+=0x4){ status = GetTableCellAttribute (panel, VME_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, &dimmed); if((tableAddress>=writeAddress)&&(tableAddress<=lastWriteAddress)){ if(dimmed){ status = SetTableCellAttribute (panel, VME_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); } status = SetTableCellVal (panel, VME_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), *dataPointer); ++dataPointer; } else { if(dimmed==0){ status = SetTableCellAttribute (panel, VME_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } } if(control==VME_MEM_WRITE_TABLE_ADDR){ SetActiveCtrl (panel,VME_MEM_WRITE_TABLE); status = SetActiveTableCell (panel, VME_MEM_WRITE_TABLE, MakePoint((findWriteAddr-tableNewAddr)/4+2,1)); } break; case VME_MEM_VME_ACCESS: GetCtrlVal(panel, control, &value); switch(value){ case 1: SetCtrlAttribute (panel, VME_MEM_WORD_ADDRESS, ATTR_INCR_VALUE, 1); SetCtrlAttribute (panel, VME_MEM_WRITE_DATA_WORD, ATTR_PADDING, 2); SetCtrlAttribute (panel, VME_MEM_WRITE_DATA_WORD, ATTR_MAX_VALUE, 0xFF); SetCtrlAttribute(panel, VME_MEM_READ_DATA_WORD, ATTR_PADDING,2); SetCtrlAttribute (panel, VME_MEM_WRITE_DATA_WORD, ATTR_MAX_VALUE, 0xFF); break; case 2: SetCtrlAttribute (panel, VME_MEM_WORD_ADDRESS, ATTR_INCR_VALUE, 2); SetCtrlAttribute (panel, VME_MEM_WRITE_DATA_WORD, ATTR_PADDING,4); SetCtrlAttribute (panel, VME_MEM_WRITE_DATA_WORD, ATTR_MAX_VALUE, 0xFFFF); SetCtrlAttribute(panel, VME_MEM_READ_DATA_WORD, ATTR_PADDING,4); SetCtrlAttribute (panel, VME_MEM_WRITE_DATA_WORD, ATTR_MAX_VALUE, 0xFFFF); break; case 4: SetCtrlAttribute (panel, VME_MEM_WORD_ADDRESS, ATTR_INCR_VALUE, 4); SetCtrlAttribute (panel, VME_MEM_WRITE_DATA_WORD, ATTR_PADDING,8); SetCtrlAttribute (panel, VME_MEM_WRITE_DATA_WORD, ATTR_MAX_VALUE, 0xFFFFFFFF); SetCtrlAttribute(panel, VME_MEM_READ_DATA_WORD, ATTR_PADDING,8); SetCtrlAttribute (panel, VME_MEM_WRITE_DATA_WORD, ATTR_MAX_VALUE, 0xFFFFFFFF); break; } break; } }else{ if((event==EVENT_LEFT_CLICK)||(event==EVENT_LEFT_DOUBLE_CLICK)){ switch(control){ case VME_MEM_ADDRESS_TABLE_TIM: /* no break here */ case VME_MEM_ADDRESS_TABLE: status=GetActiveTableCell (panel, control, &point); status = GetTableCellVal (panel, control,MakePoint(1, point.y),&addr); status = GetTableCellVal (panel, control,MakePoint(2, point.y),&size); SetCtrlVal(panel, VME_MEM_READ_ADDRESS, addr); //SetCtrlVal(panel, VME_MEM_WORD_ADDRESS, addr); SetCtrlVal(panel, VME_MEM_READ_BYTES, size); SetCtrlVal(global.panel.writeBuffVme, WRBUFF_VME_REL_ADDRESS, addr); SetCtrlVal(global.panel.writeBuffVme, WRBUFF_VME_BYTES, size); break; } } } } return 0; } /*============================================================================= * masterMemButtons() *============================================================================= * * * */ int CVICALLBACK masterMemButtons (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ static unsigned int readAddress; static unsigned int writeAddress; static int previousControl; unsigned int tableAddress; static unsigned int lastReadAddress; static unsigned int firstReadAddress; static unsigned int lastWriteAddress; static unsigned int firstWriteAddress; static unsigned int readBytes; static unsigned int writeBytes; static unsigned char slotNumber; UINT32 *dataPointer=NULL; ERROR_ID errorId; int rowIndex, columnIndex; /* table indexes */ static unsigned int tableReadLines; static unsigned int tableWriteLines; unsigned int slideValue; int dataIndex; int dimmed; int value, elementSize; int status; unsigned int wordAddress; unsigned int dataWord; unsigned int cellAddress; Point point; Rect rect; char textMessage[50]; unsigned int addr, size; UINT32 hpicVmeAddr, hpic; UINT32 defaultValue; UINT32 i, j, repetitions; char message[200]; UINT32 findReadAddr= 0, findWriteAddr= 0, tableNewAddr; int counterOn; static char fileName[260]; static unsigned int fileSize; int blockAccess; int pio; UINT32 delay; double timeStart; if(panel==global.panel.writeBuffMaster){ if(event==EVENT_COMMIT){ switch(control){ case WRBUFF_M_CANCEL: status=RemovePopup(0); if(status!=0){ programError(__FILE__, __LINE__, PROGRAM_ERROR, "RemovePopup()", status, ""); } break; case WRBUFF_M_OK: status=RemovePopup(0); if(status!=0){ programError(__FILE__, __LINE__, PROGRAM_ERROR, "RemovePopup()", status, ""); } GetCtrlVal(panel, WRBUFF_M_ADDRESS, &writeAddress); writeAddress&=0xFFFFFFFC; SetCtrlVal(global.panel.masterDspMemory, MASTER_MEM_WRITE_ADDRESS, writeAddress); if(previousControl==MASTER_MEM_NEW_BUFFER){ GetCtrlVal(panel, WRBUFF_M_BYTES, &writeBytes); GetCtrlVal(panel, WRBUFF_M_DEFAULT_VALUE, &defaultValue); } if(previousControl==MASTER_MEM_LOAD_FILE){ writeBytes=fileSize; } writeBytes&=0xFFFFFFFC; SetCtrlVal(global.panel.masterDspMemory, MASTER_MEM_WRITE_BYTES, writeBytes); if(global.masterMemoryWrite!=NULL){ /* if buffer already allocated, free it */ free(global.masterMemoryWrite); // NEZAPOMEN VYNULOVAT PRI UKONCENI!!!!!!!!!!!!!!!!!!!! global.masterMemoryWrite=NULL; } global.masterMemoryWrite=calloc(writeBytes, sizeof(UINT8)); /* allocate and clear memory for data buffer */ if(global.masterMemoryWrite==NULL){ ERROR_CHECK(PROGRAM_ERROR, calloc()); return(PROGRAM_ERROR); } if(previousControl==MASTER_MEM_LOAD_FILE){ errorId=readFromBinFile(fileName, global.masterMemoryWrite, writeBytes); ERROR_CHECK(errorId, readFromBinFile()); if(errorId!=SUCCESS) return(errorId); }else{ for(i=0; i=writeAddress)&&(tableAddress<=lastWriteAddress)){ status = SetTableCellAttribute (global.panel.masterDspMemory, MASTER_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); status = SetTableCellVal (global.panel.masterDspMemory, MASTER_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), *(unsigned int*)dataPointer); ++dataPointer; } else { status = SetTableCellAttribute (global.panel.masterDspMemory, MASTER_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } break; } } return(0); } if(event==EVENT_COMMIT){ GetCtrlVal(panel, MASTER_MEM_SLOT_NUMBER, &slotNumber); switch(control){ case MASTER_MEM_READ_MEMORY: /* set little endian */ errorId=setHpicMaster(slotNumber); ERROR_CHECK(errorId, setHpic()); if(errorId!=SUCCESS) return(errorId); status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); GetCtrlVal(panel, MASTER_MEM_READ_ADDRESS, &readAddress); readAddress&=0xFFFFFFFC; SetCtrlVal(panel, MASTER_MEM_READ_ADDRESS, readAddress); GetCtrlVal(panel, MASTER_MEM_READ_BYTES, &readBytes); readBytes&=0xFFFFFFFC; SetCtrlVal(panel, MASTER_MEM_READ_BYTES, readBytes); if(global.masterMemoryRead!=NULL){ /* if buffer already allocated, free it */ free(global.masterMemoryRead); // NEZAPOMEN VYNULOVAT PRI UKONCENI!!!!!!!!!!!!!!!!!!!! global.masterMemoryRead=NULL; } global.masterMemoryRead=calloc(readBytes, sizeof(UINT8)); /* allocate and clear memory for data buffer */ if(global.masterMemoryRead==NULL){ errorId=PROGRAM_ERROR; programError(__FILE__,__LINE__, errorId, "calloc(readDataBuffer)", errorId, ""); break; } /* read data block from MasterDSP memory via HPI */ SetCtrlVal(panel, MASTER_MEM_VME_BUSY, 1); GetCtrlVal(panel, MASTER_MEM_REPEAT, &repetitions); GetCtrlVal(panel, MASTER_MEM_COUNTER_ON, &counterOn); GetCtrlVal(panel, MASTER_MEM_BLOCK_ACCESS, &blockAccess); GetCtrlVal(panel, MASTER_MEM_DELAY, &delay); GetCtrlVal(panel, MASTER_MEM_PIO, &pio); timeStart=Timer(); for(i=0; i<=repetitions; ++i){ if(blockAccess){ errorId=RWmaster(READ, slotNumber, readAddress, global.masterMemoryRead, (UINT32)(readBytes/4), HPIA_AUTOINCREMENT, !pio); ERROR_CHECK(errorId, RWmaster()); }else{ for(j=0; j<(readBytes/4); ++j){ Sleep(delay); errorId=RWmaster(READ, slotNumber, readAddress+4*j, global.masterMemoryRead+j, 1, NO_HPIA_AUTOINCREMENT, 0); ERROR_CHECK(errorId, RWmaster()); if(errorId!=SUCCESS) return(-1); } } if (errorId!=SUCCESS){ status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); SetCtrlVal(panel,MASTER_MEM_REPEAT_COUNTER, i); break; } if(counterOn) SetCtrlVal(panel,MASTER_MEM_REPEAT_COUNTER, i); } SetCtrlVal(panel, MASTER_MEM_TIMER, (Timer() - timeStart)); SetCtrlVal(panel, MASTER_MEM_VME_BUSY, 0); // vratit zpet nahoru /* fill table */ firstReadAddress=readAddress&0xFFFFFFF0; tableAddress=firstReadAddress; dataPointer=(UINT32*)global.masterMemoryRead; lastReadAddress=readAddress+readBytes-1; tableReadLines=(lastReadAddress-firstReadAddress)/16; status = SetCtrlAttribute (panel, MASTER_MEM_READ_TABLE_SLIDE, ATTR_MAX_VALUE, tableReadLines); UIR_STATUS_CHECK(status, SetCtrlAttribute()); status = SetCtrlAttribute (panel, MASTER_MEM_READ_TABLE_SLIDE, ATTR_INCR_VALUE, 16); UIR_STATUS_CHECK(status, SetCtrlAttribute()); SetCtrlVal(panel, MASTER_MEM_READ_TABLE_SLIDE, tableReadLines); SetCtrlVal(panel, MASTER_MEM_READ_TABLE_ADDR, firstReadAddress); for(rowIndex=1; rowIndex<=16;++rowIndex){ /* fill address */ status = SetTableCellVal (panel, MASTER_MEM_READ_TABLE, MakePoint(1, rowIndex), tableAddress); for(columnIndex=2; columnIndex<=5; ++columnIndex, tableAddress+=0x4){ if((tableAddress>=readAddress)&&(tableAddress<=lastReadAddress)){ status = SetTableCellAttribute (panel, MASTER_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); status = SetTableCellVal(panel, MASTER_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), *(unsigned int*)dataPointer); ++dataPointer; } else { status = SetTableCellAttribute (panel, MASTER_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; case MASTER_MEM_SAVE_READ_TABLE: //dataBuffer readWords_32b status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); status = FileSelectPopup (global.commonDataDir, "*.bin", "*.bin","Save read table to file", VAL_SAVE_BUTTON, 0, 0, 1, 0,fileName); switch(status){ case 0: /* no file selected */ break; case 1: /* existing file selected */ // no break here case 2: /* new file selected */ errorId=writeToBinFile(fileName, 0, global.masterMemoryRead, readBytes); ERROR_CHECK(errorId, writeToBinFile()); break; default: // error break; } status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; case MASTER_MEM_EXTERNAL_VIEWER: strcpy(fileName, global.mainDir); strcat(fileName, TEMPORARY_DATA_SUBDIR"masterMemRead.tmp"); status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); errorId=writeToBinFile(fileName, 0, global.masterMemoryRead, readBytes); ERROR_CHECK(errorId, writeToBinFile()); errorId=viewBinFile(fileName); ERROR_CHECK(errorId, viewBinFile()); status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; case MASTER_MEM_SAVE_WRITE_TABLE: status = FileSelectPopup (global.commonDataDir, "*.bin", "*.bin","Save write table to file",VAL_SAVE_BUTTON, 0, 0, 1, 0, fileName); switch(status){ case 0: /* no file selected */ break; case 1: /* existing file selected */ // no break here case 2: /* new file selected */ status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); errorId=writeToBinFile(fileName, 0, global.masterMemoryWrite, writeBytes); ERROR_CHECK(errorId, writeToBinFile()); status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; default: // error break; } break; case MASTER_MEM_WRITE_TO_MEMORY: if(global.masterMemoryRead==NULL){ break; } /* set little endian */ errorId=setHpicMaster(slotNumber); ERROR_CHECK(errorId, setHpic()); if(errorId!=SUCCESS) return(errorId); status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); SetCtrlVal(panel, MASTER_MEM_VME_BUSY, 1); GetCtrlVal(panel, MASTER_MEM_BLOCK_ACCESS, &blockAccess); GetCtrlVal(panel, MASTER_MEM_DELAY, &delay); GetCtrlVal(panel, MASTER_MEM_PIO, &pio); if(blockAccess){ timeStart=Timer(); errorId=RWmaster(WRITE, slotNumber, writeAddress, global.masterMemoryWrite, (UINT32) (writeBytes/4), HPIA_AUTOINCREMENT, !pio); ERROR_CHECK(errorId,RWmaster()); SetCtrlVal(panel, MASTER_MEM_TIMER, (Timer() - timeStart)); }else{ for(i=0; i<(writeBytes/4); ++i){ Sleep(delay); errorId=RWmaster(WRITE, slotNumber, writeAddress+4*i, global.masterMemoryWrite+i, 1, NO_HPIA_AUTOINCREMENT, 0); ERROR_CHECK(errorId,RWmasterDma()); if(errorId!=SUCCESS) break; } } SetCtrlVal(panel, MASTER_MEM_VME_BUSY, 0); status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); ERROR_CHECK(errorId,hpiWrite()); if(errorId!=SUCCESS) return(errorId); break; case MASTER_MEM_NEW_BUFFER: status=SetInputMode(global.panel.writeBuffMaster, WRBUFF_M_BYTES, 1); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(global.panel.writeBuffMaster, WRBUFF_M_DEFAULT_VALUE, 1); UIR_STATUS_CHECK(status, SetInputMode()); status=InstallPopup(global.panel.writeBuffMaster); UIR_STATUS_CHECK(status, InstallPopup()); previousControl=control; break; case MASTER_MEM_LOAD_FILE: status=FileSelectPopup(global.commonDataDir, "*.bin","*.bin","Pick file", VAL_SELECT_BUTTON,0,0,1,1,fileName); if(status==VAL_NO_FILE_SELECTED){ break; } errorId=getFileSize (fileName, &fileSize); ERROR_CHECK(errorId, getFileSize()); if(errorId!=SUCCESS) return(errorId); if(fileSize%4){ ERROR_CHECK(PROGRAM_ERROR, wrong file size!!); return(PROGRAM_ERROR); } status=SetInputMode(global.panel.writeBuffMaster, WRBUFF_M_BYTES, 0); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(global.panel.writeBuffMaster, WRBUFF_M_DEFAULT_VALUE, 0); UIR_STATUS_CHECK(status, SetInputMode()); status=InstallPopup(global.panel.writeBuffMaster); UIR_STATUS_CHECK(status, InstallPopup()); previousControl=control; break; case MASTER_MEM_WRITE_WORD: /* set little endian */ errorId=setHpicMaster(slotNumber); ERROR_CHECK(errorId, setHpic()); if(errorId!=SUCCESS) return(errorId); GetCtrlVal(panel, MASTER_MEM_WORD_ADDRESS, &wordAddress); dataWord=0; //presunout do init GetCtrlVal(panel, MASTER_MEM_WRITE_DATA_WORD, &dataWord); SetCtrlVal(panel, MASTER_MEM_VME_BUSY, 1); errorId=RWmaster(WRITE, slotNumber, wordAddress, &dataWord, 1, NO_HPIA_AUTOINCREMENT, 0); ERROR_CHECK(errorId, RWmaster()); SetCtrlVal(panel, MASTER_MEM_VME_BUSY, 0); break; case MASTER_MEM_READ_WORD: /* set little endian */ errorId=setHpicMaster(slotNumber); ERROR_CHECK(errorId, setHpic()); if(errorId!=SUCCESS) return(errorId); GetCtrlVal(panel, MASTER_MEM_WORD_ADDRESS, &wordAddress); // predelat jmeno na word addr!! dataWord=0; //presunout do init SetCtrlVal(panel, MASTER_MEM_VME_BUSY, 1); errorId=RWmaster(READ, slotNumber, wordAddress, &dataWord, 1, NO_HPIA_AUTOINCREMENT, 0); ERROR_CHECK(errorId, RWmaster()); SetCtrlVal(panel, MASTER_MEM_VME_BUSY, 0); SetCtrlVal(panel, MASTER_MEM_READ_DATA_WORD, dataWord); break; case MASTER_MEM_COMPARE_BUFFS: memset(message, 0, 200); if(readBytes!=writeBytes){ sprintf(message, "The buffers are not the same size!!\n\nReadBuffLength:0x%X, WriteBuffLength:0x%X", readBytes, writeBytes); status = MessagePopup ("READ/WRITE BUFFS COMPARISON", message); UIR_STATUS_CHECK(status, MessagePopup()); break; } if(readAddress!=writeAddress){ sprintf(message, "The start addresses are not the same!!\n\n ReadAddr:0x%X WriteAddr:0x%X\n\n", readAddress, writeAddress); } for(i=0; ilastReadAddress){ findReadAddr=lastReadAddress; } slideValue=(lastReadAddress-(findReadAddr&0xFFFFFFF0))/16; SetCtrlVal(panel, MASTER_MEM_READ_TABLE_SLIDE, slideValue); /* no break */ case MASTER_MEM_READ_TABLE_SLIDE: if(global.masterMemoryRead==NULL){ break; } if(control==MASTER_MEM_READ_TABLE_SLIDE){ GetCtrlVal(panel, control, &slideValue); } tableAddress=(firstReadAddress+(tableReadLines-slideValue)*16)&0xFFFFFFF0; SetCtrlVal(panel, MASTER_MEM_READ_TABLE_ADDR, tableAddress); tableNewAddr=tableAddress; if(tableAddress>readAddress){ dataIndex=(tableAddress-readAddress)/4; } else { dataIndex=0; } dataPointer=&global.masterMemoryRead[dataIndex]; for(rowIndex=1; rowIndex<=16;++rowIndex){ /* fill address */ status = SetTableCellVal (panel, MASTER_MEM_READ_TABLE, MakePoint(1, rowIndex), tableAddress); for(columnIndex=2; columnIndex<=5; ++columnIndex, tableAddress+=0x4){ status = GetTableCellAttribute (panel, MASTER_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, &dimmed); if((tableAddress>=readAddress)&&(tableAddress<=lastReadAddress)){ if(dimmed){ status = SetTableCellAttribute (panel, MASTER_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); } status = SetTableCellVal (panel, MASTER_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), *(unsigned int*)dataPointer); ++dataPointer; } else { if(dimmed==0){ status = SetTableCellAttribute (panel, MASTER_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } } if(control==MASTER_MEM_READ_TABLE_ADDR){ SetActiveCtrl (panel,MASTER_MEM_READ_TABLE); status = SetActiveTableCell (panel, MASTER_MEM_READ_TABLE, MakePoint((findReadAddr-tableNewAddr)/4+2,1)); } break; case MASTER_MEM_WRITE_TABLE_ADDR: GetCtrlVal(panel, control, &findWriteAddr); if(findWriteAddrlastWriteAddress){ findWriteAddr=lastWriteAddress; } slideValue=(lastWriteAddress-(findWriteAddr&0xFFFFFFF0))/16; SetCtrlVal(panel, MASTER_MEM_WRITE_TABLE_SLIDE, slideValue); /* no break */ case MASTER_MEM_WRITE_TABLE_SLIDE: if(global.masterMemoryWrite==NULL){ break; } if(control==MASTER_MEM_WRITE_TABLE_SLIDE){ GetCtrlVal(panel, control, &slideValue); } tableAddress=(firstWriteAddress+(tableWriteLines-slideValue)*16)&0xFFFFFFF0; SetCtrlVal(panel, MASTER_MEM_WRITE_TABLE_ADDR, tableAddress); tableNewAddr=tableAddress; if(tableAddress>writeAddress){ dataIndex=(tableAddress-writeAddress)/4; } else { dataIndex=0; } dataPointer=&global.masterMemoryWrite[dataIndex]; for(rowIndex=1; rowIndex<=16;++rowIndex){ /* fill address */ status = SetTableCellVal (panel, MASTER_MEM_WRITE_TABLE, MakePoint(1, rowIndex), tableAddress); for(columnIndex=2; columnIndex<=5; ++columnIndex, tableAddress+=0x4){ status = GetTableCellAttribute (panel, MASTER_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, &dimmed); if((tableAddress>=writeAddress)&&(tableAddress<=lastWriteAddress)){ if(dimmed){ status = SetTableCellAttribute (panel, MASTER_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); } status = SetTableCellVal (panel, MASTER_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), *(unsigned int*)dataPointer); ++dataPointer; } else { if(dimmed==0){ status = SetTableCellAttribute (panel, MASTER_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } } if(control==MASTER_MEM_WRITE_TABLE_ADDR){ SetActiveCtrl (panel,MASTER_MEM_WRITE_TABLE); status = SetActiveTableCell (panel, MASTER_MEM_WRITE_TABLE, MakePoint((findWriteAddr-tableNewAddr)/4+2,1)); } break; } }else{ if((event==EVENT_LEFT_CLICK)||(event==EVENT_LEFT_DOUBLE_CLICK)){ switch(control){ case MASTER_MEM_ADDRESS_TABLE: status=GetTableSelection(panel, control, &rect); status = GetActiveTableCell (panel, control, &point); status = GetTableCellVal (panel, control,MakePoint(1, point.y),&addr); status = GetTableCellVal (panel, control,MakePoint(2, point.y),&size); SetCtrlVal(panel, MASTER_MEM_READ_ADDRESS, addr); //SetCtrlVal(panel, MASTER_MEM_WORD_ADDRESS, addr); SetCtrlVal(panel, MASTER_MEM_READ_BYTES, size); SetCtrlVal(global.panel.writeBuffMaster, WRBUFF_M_ADDRESS, addr); SetCtrlVal(global.panel.writeBuffMaster, WRBUFF_M_BYTES, size); break; } } } } return 0; } /*============================================================================= * slaveMemButtons() *============================================================================= * * * */ int CVICALLBACK slaveMemButtons (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ static unsigned int readAddress; static unsigned int writeAddress; static int previousControl; unsigned int tableAddress; static unsigned int lastReadAddress; static unsigned int firstReadAddress; static unsigned int lastWriteAddress; static unsigned int firstWriteAddress; static unsigned int readBytes; static unsigned int writeBytes; static unsigned char slotNumber; static unsigned char slaveNumber; UINT32 *dataPointer=NULL; ERROR_ID errorId; int rowIndex, columnIndex; /* table indexes */ static unsigned int tableReadLines; static unsigned int tableWriteLines; unsigned int slideValue; int dataIndex; int dimmed; int value, elementSize; int status; unsigned int wordAddress; unsigned int dataWord; unsigned int cellAddress; Point point; Rect rect; char textMessage[50]; unsigned int addr, size; UINT32 hpicVmeAddr, hpic; UINT32 defaultValue; UINT32 i, repetitions; char message[200]; UINT32 findReadAddr= 0, findWriteAddr= 0, tableNewAddr; double timeStart; int counterOn; int pio; static char fileName[260]; static unsigned int fileSize; struct HOST *host; if(panel==global.panel.writeBuffSlave){ if(event==EVENT_COMMIT){ switch(control){ case WRBUFF_S_CANCEL: status=RemovePopup(0); if(status!=0){ programError(__FILE__, __LINE__, PROGRAM_ERROR, "RemovePopup()", status, ""); } break; case WRBUFF_S_OK: status=RemovePopup(0); if(status!=0){ programError(__FILE__, __LINE__, PROGRAM_ERROR, "RemovePopup()", status, ""); } GetCtrlVal(panel, WRBUFF_S_ADDRESS, &writeAddress); writeAddress&=0xFFFFFFFC; SetCtrlVal(global.panel.slaveDspMemory, SLAVE_MEM_WRITE_ADDRESS, writeAddress); if(previousControl==SLAVE_MEM_NEW_BUFFER){ GetCtrlVal(panel, WRBUFF_S_BYTES, &writeBytes); GetCtrlVal(panel, WRBUFF_S_DEFAULT_VALUE, &defaultValue); } if(previousControl==SLAVE_MEM_LOAD_FILE){ writeBytes=fileSize; } writeBytes&=0xFFFFFFFC; SetCtrlVal(global.panel.slaveDspMemory, SLAVE_MEM_WRITE_BYTES, writeBytes); if(global.slaveMemoryWrite!=NULL){ /* if buffer already allocated, free it */ free(global.slaveMemoryWrite); // NEZAPOMEN VYNULOVAT PRI UKONCENI!!!!!!!!!!!!!!!!!!!! global.slaveMemoryWrite=NULL; } global.slaveMemoryWrite=calloc(writeBytes, sizeof(UINT8)); /* allocate and clear memory for data buffer */ if(global.slaveMemoryWrite==NULL){ ERROR_CHECK(PROGRAM_ERROR, calloc()); return(PROGRAM_ERROR); } if(previousControl==SLAVE_MEM_LOAD_FILE){ errorId=readFromBinFile(fileName, global.slaveMemoryWrite, writeBytes); ERROR_CHECK(errorId, readFromBinFile()); if(errorId!=SUCCESS) return(errorId); }else{ for(i=0; i=writeAddress)&&(tableAddress<=lastWriteAddress)){ status = SetTableCellAttribute (global.panel.slaveDspMemory, SLAVE_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); status = SetTableCellVal (global.panel.slaveDspMemory, SLAVE_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), *(unsigned int*)dataPointer); ++dataPointer; } else { status = SetTableCellAttribute (global.panel.slaveDspMemory, SLAVE_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } break; } } return(0); } if(event==EVENT_COMMIT){ GetCtrlVal(panel, SLAVE_MEM_SLOT_NUMBER, &slotNumber); GetCtrlVal(panel, SLAVE_MEM_SLAVE_NUMBER, &slaveNumber); host=global.host[slotNumber-FIRST_ROD_VME_SLOT]; switch(control){ case SLAVE_MEM_READ_MEMORY: status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); GetCtrlVal(panel, SLAVE_MEM_READ_ADDRESS, &readAddress); readAddress&=0xFFFFFFFC; SetCtrlVal(panel, SLAVE_MEM_READ_ADDRESS, readAddress); GetCtrlVal(panel, SLAVE_MEM_READ_BYTES, &readBytes); readBytes&=0xFFFFFFFC; SetCtrlVal(panel, SLAVE_MEM_READ_BYTES, readBytes); GetCtrlVal(panel, SLAVE_MEM_PIO, &pio); if(global.slaveMemoryRead!=NULL){ /* if buffer already allocated, free it */ free(global.slaveMemoryRead); global.slaveMemoryRead=NULL; } global.slaveMemoryRead=calloc(readBytes, sizeof(UINT8)); /* allocate and clear memory for data buffer */ if(global.slaveMemoryRead==NULL){ status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); errorId=PROGRAM_ERROR; programError(__FILE__,__LINE__, errorId, "calloc(readDataBuffer)", errorId, ""); break; } /* read data block from SlaveDSP memory via HPI */ SetCtrlVal(panel, SLAVE_MEM_VME_BUSY, 1); timeStart=Timer(); errorId=RWslave(READ, slotNumber, slaveNumber, readAddress, global.slaveMemoryRead, (UINT32)(readBytes/4), !pio); SetCtrlVal(panel, SLAVE_MEM_TIMER, (Timer() - timeStart)); SetCtrlVal(panel, SLAVE_MEM_VME_BUSY, 0); ERROR_CHECK(errorId, RWslave()); if (errorId!=SUCCESS){ status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; } /* fill table */ firstReadAddress=readAddress&0xFFFFFFF0; tableAddress=firstReadAddress; dataPointer=(UINT32*)global.slaveMemoryRead; lastReadAddress=readAddress+readBytes-1; tableReadLines=(lastReadAddress-firstReadAddress)/16; status = SetCtrlAttribute (panel, SLAVE_MEM_READ_TABLE_SLIDE, ATTR_MAX_VALUE, tableReadLines); UIR_STATUS_CHECK(status, SetCtrlAttribute()); status = SetCtrlAttribute (panel, SLAVE_MEM_READ_TABLE_SLIDE, ATTR_INCR_VALUE, 16); UIR_STATUS_CHECK(status, SetCtrlAttribute()); SetCtrlVal(panel, SLAVE_MEM_READ_TABLE_SLIDE, tableReadLines); SetCtrlVal(panel, SLAVE_MEM_READ_TABLE_ADDR, firstReadAddress); for(rowIndex=1; rowIndex<=16;++rowIndex){ /* fill address */ status = SetTableCellVal (panel, SLAVE_MEM_READ_TABLE, MakePoint(1, rowIndex), tableAddress); for(columnIndex=2; columnIndex<=5; ++columnIndex, tableAddress+=0x4){ if((tableAddress>=readAddress)&&(tableAddress<=lastReadAddress)){ status = SetTableCellAttribute (panel, SLAVE_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); status = SetTableCellVal(panel, SLAVE_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), *(unsigned int*)dataPointer); ++dataPointer; } else { status = SetTableCellAttribute (panel, SLAVE_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; case SLAVE_MEM_SAVE_READ_TABLE: //dataBuffer readWords_32b status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); status = FileSelectPopup (global.commonDataDir, "*.bin", "*.bin","Save read table to file", VAL_SAVE_BUTTON, 0, 0, 1, 0,fileName); switch(status){ case 0: /* no file selected */ break; case 1: /* existing file selected */ // no break here case 2: /* new file selected */ errorId=writeToBinFile(fileName, 0, global.slaveMemoryRead, readBytes); ERROR_CHECK(errorId, writeToBinFile()); break; default: // error break; } status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; case SLAVE_MEM_EXTERNAL_VIEWER: strcpy(fileName, global.mainDir); strcat(fileName, TEMPORARY_DATA_SUBDIR"slaveMemRead.tmp"); status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); errorId=writeToBinFile(fileName, 0, global.slaveMemoryRead, readBytes); ERROR_CHECK(errorId, writeToBinFile()); errorId=viewBinFile(fileName); ERROR_CHECK(errorId, viewBinFile()); status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; case SLAVE_MEM_SAVE_WRITE_TABLE: status = FileSelectPopup (global.commonDataDir, "*.bin", "*.bin","Save write table to file",VAL_SAVE_BUTTON, 0, 0, 1, 0, fileName); switch(status){ case 0: /* no file selected */ break; case 1: /* existing file selected */ // no break here case 2: /* new file selected */ status=SetInputMode(panel, control, 0); UIR_STATUS_CHECK(status, SetInputMode()); errorId=writeToBinFile(fileName, 0, global.slaveMemoryWrite, writeBytes); ERROR_CHECK(errorId, writeToBinFile()); status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; default: // error break; } break; case SLAVE_MEM_WRITE_TO_MEMORY: if(global.slaveMemoryWrite==NULL){ break; } GetCtrlVal(panel, SLAVE_MEM_PIO, &pio); status=SetInputMode(panel, SLAVE_MEM_WRITE_TO_MEMORY, 0); UIR_STATUS_CHECK(status, SetInputMode()); SetCtrlVal(panel, SLAVE_MEM_VME_BUSY, 1); timeStart=Timer(); errorId=RWslave(WRITE, slotNumber, slaveNumber, writeAddress, global.slaveMemoryWrite, (UINT32)(writeBytes/4), !pio); SetCtrlVal(panel, SLAVE_MEM_TIMER, (Timer() - timeStart)); SetCtrlVal(panel, SLAVE_MEM_VME_BUSY, 0); ERROR_CHECK(errorId,RWslave()); status=SetInputMode(panel, control, 1); UIR_STATUS_CHECK(status, SetInputMode()); break; case SLAVE_MEM_NEW_BUFFER: status=SetInputMode(global.panel.writeBuffSlave, WRBUFF_S_BYTES, 1); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(global.panel.writeBuffSlave, WRBUFF_S_DEFAULT_VALUE, 1); UIR_STATUS_CHECK(status, SetInputMode()); status=InstallPopup(global.panel.writeBuffSlave); UIR_STATUS_CHECK(status, InstallPopup()); previousControl=control; break; case SLAVE_MEM_LOAD_FILE: status=FileSelectPopup(global.commonDataDir, "*.bin","*.bin","Pick file", VAL_SELECT_BUTTON,0,0,1,1,fileName); if(status==VAL_NO_FILE_SELECTED){ break; } errorId=getFileSize (fileName, &fileSize); ERROR_CHECK(errorId, getFileSize()); if(errorId!=SUCCESS) return(errorId); if(fileSize%4){ ERROR_CHECK(PROGRAM_ERROR, wrong file size!!); return(PROGRAM_ERROR); } status=SetInputMode(global.panel.writeBuffSlave, WRBUFF_S_BYTES, 0); UIR_STATUS_CHECK(status, SetInputMode()); status=SetInputMode(global.panel.writeBuffSlave, WRBUFF_S_DEFAULT_VALUE, 0); UIR_STATUS_CHECK(status, SetInputMode()); status=InstallPopup(global.panel.writeBuffSlave); UIR_STATUS_CHECK(status, InstallPopup()); previousControl=control; break; case SLAVE_MEM_WRITE_WORD: GetCtrlVal(panel, SLAVE_MEM_WORD_ADDRESS, &wordAddress); dataWord=0; //presunout do init GetCtrlVal(panel, SLAVE_MEM_WRITE_DATA_WORD, &dataWord); SetCtrlVal(panel, SLAVE_MEM_VME_BUSY, 1); errorId=RWslave(WRITE, slotNumber, slaveNumber, wordAddress, &dataWord, 1, 0); SetCtrlVal(panel, SLAVE_MEM_VME_BUSY, 0); ERROR_CHECK(errorId, RWslave()); break; case SLAVE_MEM_READ_WORD: GetCtrlVal(panel, SLAVE_MEM_WORD_ADDRESS, &wordAddress); // predelat jmeno na word addr!! dataWord=0; SetCtrlVal(panel, SLAVE_MEM_VME_BUSY, 1); errorId=RWslave(READ, slotNumber, slaveNumber, wordAddress, &dataWord, 1, 0); SetCtrlVal(panel, SLAVE_MEM_VME_BUSY, 0); ERROR_CHECK(errorId, RWslave()); SetCtrlVal(panel, SLAVE_MEM_READ_DATA_WORD, dataWord); break; case SLAVE_MEM_COMPARE_BUFFS: memset(message, 0, 200); if(readBytes!=writeBytes){ sprintf(message, "The buffers are not the same size!!\n\nReadBuffLength:0x%X, WriteBuffLength:0x%X", readBytes, writeBytes); status = MessagePopup ("READ/WRITE BUFFS COMPARISON", message); UIR_STATUS_CHECK(status, MessagePopup()); break; } if(readAddress!=writeAddress){ sprintf(message, "The start addresses are not the same!!\n\n ReadAddr:0x%X WriteAddr:0x%X\n\n", readAddress, writeAddress); } for(i=0; ilastReadAddress){ findReadAddr=lastReadAddress; } slideValue=(lastReadAddress-(findReadAddr&0xFFFFFFF0))/16; SetCtrlVal(panel, SLAVE_MEM_READ_TABLE_SLIDE, slideValue); /* no break */ case SLAVE_MEM_READ_TABLE_SLIDE: if(global.slaveMemoryRead==NULL){ break; } if(control==SLAVE_MEM_READ_TABLE_SLIDE){ GetCtrlVal(panel, control, &slideValue); } tableAddress=(firstReadAddress+(tableReadLines-slideValue)*16)&0xFFFFFFF0; SetCtrlVal(panel, SLAVE_MEM_READ_TABLE_ADDR, tableAddress); tableNewAddr=tableAddress; if(tableAddress>readAddress){ dataIndex=(tableAddress-readAddress)/4; } else { dataIndex=0; } dataPointer=&global.slaveMemoryRead[dataIndex]; for(rowIndex=1; rowIndex<=16;++rowIndex){ /* fill address */ status = SetTableCellVal (panel, SLAVE_MEM_READ_TABLE, MakePoint(1, rowIndex), tableAddress); for(columnIndex=2; columnIndex<=5; ++columnIndex, tableAddress+=0x4){ status = GetTableCellAttribute (panel, SLAVE_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, &dimmed); if((tableAddress>=readAddress)&&(tableAddress<=lastReadAddress)){ if(dimmed){ status = SetTableCellAttribute (panel, SLAVE_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); } status = SetTableCellVal (panel, SLAVE_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), *(unsigned int*)dataPointer); ++dataPointer; } else { if(dimmed==0){ status = SetTableCellAttribute (panel, SLAVE_MEM_READ_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } } if(control==SLAVE_MEM_READ_TABLE_ADDR){ SetActiveCtrl (panel,SLAVE_MEM_READ_TABLE); status = SetActiveTableCell (panel, SLAVE_MEM_READ_TABLE, MakePoint((findReadAddr-tableNewAddr)/4+2,1)); } break; case SLAVE_MEM_WRITE_TABLE_ADDR: GetCtrlVal(panel, control, &findWriteAddr); if(findWriteAddrlastWriteAddress){ findWriteAddr=lastWriteAddress; } slideValue=(lastWriteAddress-(findWriteAddr&0xFFFFFFF0))/16; SetCtrlVal(panel, SLAVE_MEM_WRITE_TABLE_SLIDE, slideValue); /* no break */ case SLAVE_MEM_WRITE_TABLE_SLIDE: if(global.slaveMemoryWrite==NULL){ break; } if(control==SLAVE_MEM_WRITE_TABLE_SLIDE){ GetCtrlVal(panel, control, &slideValue); } tableAddress=(firstWriteAddress+(tableWriteLines-slideValue)*16)&0xFFFFFFF0; SetCtrlVal(panel, SLAVE_MEM_WRITE_TABLE_ADDR, tableAddress); tableNewAddr=tableAddress; if(tableAddress>writeAddress){ dataIndex=(tableAddress-writeAddress)/4; } else { dataIndex=0; } dataPointer=&global.slaveMemoryWrite[dataIndex]; for(rowIndex=1; rowIndex<=16;++rowIndex){ /* fill address */ status = SetTableCellVal (panel, SLAVE_MEM_WRITE_TABLE, MakePoint(1, rowIndex), tableAddress); for(columnIndex=2; columnIndex<=5; ++columnIndex, tableAddress+=0x4){ status = GetTableCellAttribute (panel, SLAVE_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, &dimmed); if((tableAddress>=writeAddress)&&(tableAddress<=lastWriteAddress)){ if(dimmed){ status = SetTableCellAttribute (panel, SLAVE_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 0); } status = SetTableCellVal (panel, SLAVE_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), *(unsigned int*)dataPointer); ++dataPointer; } else { if(dimmed==0){ status = SetTableCellAttribute (panel, SLAVE_MEM_WRITE_TABLE, MakePoint(columnIndex, rowIndex), ATTR_CELL_DIMMED, 1); } } } } if(control==SLAVE_MEM_WRITE_TABLE_ADDR){ SetActiveCtrl (panel,SLAVE_MEM_WRITE_TABLE); status = SetActiveTableCell (panel, SLAVE_MEM_WRITE_TABLE, MakePoint((findWriteAddr-tableNewAddr)/4+2,1)); } break; } }else{ if((event==EVENT_LEFT_CLICK)||(event==EVENT_LEFT_DOUBLE_CLICK)){ switch(control){ case SLAVE_MEM_ADDRESS_TABLE: status=GetTableSelection(panel, control, &rect); status = GetActiveTableCell (panel, control, &point); status = GetTableCellVal (panel, control,MakePoint(1, point.y),&addr); status = GetTableCellVal (panel, control,MakePoint(2, point.y),&size); SetCtrlVal(panel, SLAVE_MEM_READ_ADDRESS, addr); //SetCtrlVal(panel, SLAVE_MEM_WORD_ADDRESS, addr); SetCtrlVal(panel, SLAVE_MEM_READ_BYTES, size); SetCtrlVal(global.panel.writeBuffSlave, WRBUFF_S_ADDRESS, addr); SetCtrlVal(global.panel.writeBuffSlave, WRBUFF_S_BYTES, size); break; } } } } return 0; } /*============================================================================= * memMenu() *============================================================================= * * * */ void CVICALLBACK rodMemMenu (int menuBar, int menuItem, void *callbackData, int panel){ int status; ERROR_ID errorId; char fileName[PATHNAME_LENGTH]; switch(menuItem){ case ROD_MEM_GOTO_MAIN: status=SetActivePanel(global.panel.main); UIR_STATUS_CHECK(status, HidePanel()); break; case ROD_MEM_VIEW_BIN_FILE: status=FileSelectPopup(global.commonDataDir, "*.bin","*.bin","Pick file", VAL_SELECT_BUTTON,0,0,1,1,fileName); if(status==VAL_NO_FILE_SELECTED){ break; } errorId=viewBinFile(fileName); ERROR_CHECK(errorId, viewBinFile()); break; case ROD_MEM_CLOSE_WINDOW: status=HidePanel(panel); UIR_STATUS_CHECK(status, HidePanel()); break; } } /*============================================================================= * wordBoundary() *============================================================================= * * Rounds 32b. address to word boundary. * */ int CVICALLBACK wordBoundary (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { unsigned int value; int status; if(event==EVENT_VAL_CHANGED){ GetCtrlVal(panel, control, &value); SetCtrlVal(panel, control, value&0xFFFFFFFC); } return 0; } /******************************************************************************/