/****************************************************************************** * * Title : textBuffersHandler.c * Version 0.0 * * Description: text buffers handler routines. * Related files: * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include #include "textBuffersHandler.h" #include "globalDefinitions.h" #include "comRegDfns.h" #include "errorHandler.h" #include "hostUtility.h" #include "uirUtility.h" #include "mainUir.h" #include "vmeHpiUtility.h" #define I_AM_MASTER_DSP #undef IDREGS_BASE #include "memoryPartitions.h" //dspf: TXT_BFR_SZ => use memory map. //dpsf: Also use new text buffs (no handshake required, wraps at end). #undef I_AM_MASTER_DSP /****************************************************************************** * Static Function Declarations * ******************************************************************************/ static ERROR_ID readTextBuffer(struct HOST *host, int textBuffType, char textBuff[TXT_BUFF_SIZE], UINT32 buffHpiAddr, UINT32 *byteCount); static textBuffProcessing(struct HOST *host, int textBuffType, char textBuff[TXT_BUFF_SIZE], UINT32 byteCount); /****************************************************************************** * Global functions * ******************************************************************************/ /*============================================================================= * textBufferHandler() *============================================================================= * * * */ ERROR_ID textBufferHandler(struct HOST *host, int textBuffType, UINT32 buffHpiAddr){ TEXTBUFF_HANDLER_STATE *state=&host->textBuffHandlerState[textBuffType]; int srReadRqBit=SR_TXT_BUFF_NE(textBuffType); int crBuffReadRqstBit=CR_TXT_BUFF_RR(textBuffType); volatile int txtBuffReadRqOption=host->option.textBuffReadRq[textBuffType]; int controlId; static double timeoutStart[MAXRODS][N_TXT_BUFFS]; static char textBuff[TXT_BUFF_SIZE]; /* local txtBuffer */ UINT32 byteCount; char errorMessage[200]; int status; ERROR_ID errorId=SUCCESS; UINT8 hostIndex=HOST_INDEX(host->slotNumber); switch(*state){ case TEXT_BUFF_IDLE: if((txtBuffReadRqOption==0)||(READ_BIT(host->rodStatusReg[0], srReadRqBit)==0)){ break; } /* setRDrequest */ errorId=setVmeCommandRegBit(host->slotNumber, &host->vmeCommandReg[0], crBuffReadRqstBit); if(errorId!=SUCCESS){ hostError(__FILE__, __LINE__, errorId, host, "setVmeCommandRegBit()"); /* disable ROD ? */ break; } *state=READ_RQ_SET; timeoutStart[hostIndex][textBuffType]=Timer(); break; case READ_RQ_SET: if((READ_BIT(host->rodStatusReg[0], srReadRqBit)==1)){ if((Timer() - (timeoutStart[hostIndex][textBuffType]))>global.textBuffTimeout){ errorId=TIMEOUT_ERROR; hostError(__FILE__, __LINE__, errorId, host, "READ_RQ_SET timeout"); displayVmeCommandReg0(host); timeoutStart[hostIndex][textBuffType]=Timer(); } break; } /* read out */ errorId=readTextBuffer(host, textBuffType, textBuff, buffHpiAddr, &byteCount); if(errorId!=SUCCESS){ hostError(__FILE__, __LINE__, errorId, host, "readErrorBuffer()"); //disable rod break; } errorId=clearVmeCommandRegBit(host->slotNumber, &host->vmeCommandReg[0], crBuffReadRqstBit); if(errorId!=SUCCESS){ hostError(__FILE__, __LINE__, errorId, host, "clearVmeCommandRegBit(crBuffReadRqstBit)"); //disable rod } if(global.option.displayRefresh==REFRESH_RUNTIME){ displayVmeCommandReg0(host); } /* process text */ errorId=textBuffProcessing(host, textBuffType, textBuff, byteCount); HOST_ERROR_CHECK(errorId, host, textBuffProcessing()); *state=TEXT_BUFF_IDLE; break; default: errorId=HOST_ERROR; sprintf(errorMessage,"Host error - non known textBuffsHandlerState(#%d).", *state); hostError(__FILE__, __LINE__, errorId, host, errorMessage); } return(errorId); } /****************************************************************************** * Static functions * ******************************************************************************/ /*============================================================================= * readTextBuffer() *============================================================================= * * * */ static ERROR_ID readTextBuffer(struct HOST *host, int textBuffType, char textBuff[TXT_BUFF_SIZE], UINT32 buffHpiAddr, UINT32 *byteCount){ ERROR_ID errorId=SUCCESS; char errorMessage[200]; struct TXTBUFFER txtBuffStruct; UINT32 byteCountTemp; /* read buff struct */ errorId=RWmaster(READ, host->slotNumber, host->txtBuffStructHpiAddr[textBuffType], (UINT32*)&txtBuffStruct, sizeof(struct TXTBUFFER)/4, HPIA_AUTOINCREMENT, 0); if (errorId!=SUCCESS){ hostError(__FILE__, __LINE__, errorId, host, "RWmaster(READ textBuffStruct)."); return(errorId); } if(txtBuffStruct.overflow == TXT_BFR_OVERFLOW){ hostError(__FILE__, __LINE__, TEXT_BUFFER_OVERFLOW, host, "Text buffer overflow!"); } if((UINT32)txtBuffStruct.data!=buffHpiAddr){ hostError(__FILE__, __LINE__, TEXT_BUFFER_ERROR, host, "masterStruct->data!=txtBuffBase!"); return(errorId); } if((txtBuffStruct.dataEnd+1)!=TXT_BUFF_SIZE){ errorId=TEXT_BUFFER_ERROR; hostError(__FILE__, __LINE__, errorId, host, "buffEnd-buffStart!=txtBuffSize!"); return(errorId); } if(!((txtBuffStruct.overflow == TXT_BFR_OVERFLOW)&&(txtBuffStruct.mode==RINGBUFF))){ if(txtBuffStruct.readIndxTXT_BUFF_SIZE){ errorId=TEXT_BUFFER_ERROR; hostError(__FILE__, __LINE__, errorId, host, "byteCount>txtBuffSize!"); return(errorId); } if(byteCountTemp%4!=0){ /* check alignment on 32bit boundary */ hostError(__FILE__, __LINE__, TEXT_BUFFER_ERROR, host, "byteCount%4!=0!"); /* no break - read anyway */ } errorId=RWmaster(READ, host->slotNumber, txtBuffStruct.readIndx+buffHpiAddr, (UINT32*)textBuff, byteCountTemp/4, HPIA_AUTOINCREMENT, 0); if (errorId!=SUCCESS){ hostError(__FILE__, __LINE__, errorId, host, "RWmaster(READ textBuff)."); return(errorId); } *byteCount=byteCountTemp; } else { if((txtBuffStruct.readIndx==0)&&(txtBuffStruct.writeIndx==0)){ hostError(__FILE__, __LINE__, TEXT_BUFFER_ERROR, host, "NOOVERFLOW: readIndx==0&&writeIndx==0!"); } byteCountTemp=TXT_BUFF_SIZE - txtBuffStruct.readIndx; if(byteCountTemp>TXT_BUFF_SIZE){ errorId=TEXT_BUFFER_ERROR; hostError(__FILE__, __LINE__, errorId, host, "byteCount>txtBuffSize!"); return(errorId); } if(byteCountTemp%4!=0){ /* check alignment on 32bit boundary */ hostError(__FILE__, __LINE__, TEXT_BUFFER_ERROR, host, "byteCount%4!=0!"); /* no break - read anyway */ } errorId=RWmaster(READ, host->slotNumber, txtBuffStruct.readIndx+buffHpiAddr, (UINT32*)textBuff, byteCountTemp/4, HPIA_AUTOINCREMENT, 0); if (errorId!=SUCCESS){ hostError(__FILE__, __LINE__, errorId, host, "RWmaster(READ textBuff)."); return(errorId); } *byteCount=byteCountTemp; byteCountTemp=(UINT32) txtBuffStruct.writeIndx; if(byteCountTemp>(TXT_BUFF_SIZE - (*byteCount))){ errorId=TEXT_BUFFER_ERROR; hostError(__FILE__, __LINE__, errorId, host, "byteCount>(txtBuffSize- masterStruct->writeIndx)!"); return(errorId); } if(byteCountTemp%4!=0){ /* check alignment on 32bit boundary */ hostError(__FILE__, __LINE__, TEXT_BUFFER_ERROR, host, "byteCount%4!=0!"); /* no break - read anyway */ } errorId=RWmaster(READ, host->slotNumber, buffHpiAddr, (UINT32*)(textBuff+byteCountTemp), byteCountTemp/4, HPIA_AUTOINCREMENT, 0); if (errorId!=SUCCESS){ hostError(__FILE__, __LINE__, errorId, host, "RWmaster(READ textBuff)."); return(errorId); } *byteCount+=byteCountTemp; } } else { /* OVERFLOW and RINGBUF */ byteCountTemp=TXT_BUFF_SIZE - txtBuffStruct.writeIndx; if(byteCountTemp>TXT_BUFF_SIZE){ errorId=TEXT_BUFFER_ERROR; hostError(__FILE__, __LINE__, errorId, host, "byteCount%4!=0!"); return(errorId); } if(byteCountTemp%4!=0){ /* check alignment on 32bit boundary */ hostError(__FILE__, __LINE__, TEXT_BUFFER_ERROR, host, "byteCount>txtBuffSize!"); /* no break - read anyway */ } errorId=RWmaster(READ, host->slotNumber, (UINT32) txtBuffStruct.writeIndx+buffHpiAddr, (UINT32*)textBuff, byteCountTemp/4, HPIA_AUTOINCREMENT, 0); if (errorId!=SUCCESS){ hostError(__FILE__, __LINE__, errorId, host, "RWmaster(READ textBuff)."); return(errorId); } errorId=RWmaster(READ, host->slotNumber, buffHpiAddr, (UINT32*) (textBuff+byteCountTemp), (TXT_BUFF_SIZE-byteCountTemp)/4, HPIA_AUTOINCREMENT, 0); if (errorId!=SUCCESS){ hostError(__FILE__, __LINE__, errorId, host, "RWmaster(READ textBuff)."); return(errorId); } *byteCount=TXT_BUFF_SIZE; } return(errorId); } /*============================================================================= * textBuffProcessing() *============================================================================= * * * */ static textBuffProcessing(struct HOST *host, int textBuffType, char textBuff[TXT_BUFF_SIZE], UINT32 byteCount){ unsigned int i, stringLength; int status, line; char string[2000]; char *dataString; int panelHandle=host->panel.txtBuff[textBuffType]; ERROR_ID errorId=SUCCESS; int updateDisplayOption; sprintf(string,"\n=================================================================\n Date:%s, Time:%s; CurrentHostListIndex:0x%X\n=================================================================\n", DateStr(), TimeStr(), host->listIndex); /* write header to file */ errorId=writeToTextFile(host->txtBuffFileName[textBuffType], 1, string, strlen(string)+1); ERROR_CHECK(errorId, writeToTextFile(textBuff)); /* display message in the window */ SetCtrlVal(panelHandle, TEXT_PANEL_TEXTBOX, string); for(i=0; i1){ SetCtrlVal(panelHandle, TEXT_PANEL_TEXTBOX, dataString); } } /* save message to file */ errorId=writeToTextFile(host->txtBuffFileName[textBuffType], 1, textBuff, byteCount); ERROR_CHECK(errorId, writeToBinFile(textBuff)); /* clear buffer */ memset(textBuff, 0, TXT_BUFF_SIZE); return(errorId); } /******************************************************************************/