/****************************************************************************** * * Title : hostDefinitions.c * Version 0.0 * * Description: Host[n] specific variables (host[n] is part of the program, which is responsible and communicate only with Rod[n]). * Related files: all files in rcc.prj * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ #ifndef HOST_DEFINITIONS_H /* multiple-inclusion protection */ #define HOST_DEFINITIONS_H /****************************************************************************** * Header files * ******************************************************************************/ #include #include "processor.h" #include "memoryPartitions.h" #include "txtBuffer.h" #include "errorCodes.h" #include "smSendTxtBuff.h" #include "vmeAddressMap.h" #include "commandListDefinitions.h" #include "primListTableDefinitions.h" /****************************************************************************** * Definitions * ******************************************************************************/ #define LIST_FIFO_SIZE 10 /* defines how many primitiveLists can be prepared in advance, ie. how many can wait in queue before they are built by buildingThread and than sent to Rod for execution */ /* * Buffer sizes. * For MasterMemoryTest (MEMORY_TEST primitive) define MASTER_MEMORY_TEST in * compiler defines - this version will work with master DSP MemoryTest executable. */ #ifndef MASTER_MEMORY_TEST #define PRIM_BUFF_SIZE HOST_PRM_BFR_SZ #define REP_BUFF_SIZE HOST_REP_BFR_SZ #define TXT_BUFF_SIZE TXT_BFR_SZ #define PRIM_BUFF_BASE HOST_PRM_BFR_BASE #define REP_BUFF_BASE HOST_REP_BFR_BASE #define ERR_BUFF_BASE ERR_BFR_BASE #define DIAG_BUFF_BASE DIAG_BFR_BASE #define INFO_BUFF_BASE INFO_BFR_BASE #define XFER_BUFF_BASE XFER_BFR_BASE #else #define PRIM_BUFF_SIZE PRM_BFR_SZ_MEM #define REP_BUFF_SIZE REP_BFR_SZ_MEM #define TXT_BUFF_SIZE TXT_BFR_SZ_MEM #define PRIM_BUFF_BASE PRM_BFR_BASE_MEM #define REP_BUFF_BASE REP_BFR_BASE_MEM #define ERR_BUFF_BASE ERR_BFR_BASE_MEM #define DIAG_BUFF_BASE DIAG_BFR_BASE_MEM #define INFO_BUFF_BASE INFO_BFR_BASE_MEM #define XFER_BUFF_BASE XFER_BFR_BASE_MEM #endif /****************************************************************************** * Type definitions * ******************************************************************************/ /*------------------------ CONTROL_THREAD_OPTIONS ----------------------------*/ typedef enum { CONTROL_IDLE=0, ROD_INIT=1, RUN_COMMAND_LIST=2, }CONTROL_THREAD_STATE; /*-------------------------- LIST_HANDLER_STATE ------------------------------*/ typedef enum{ LIST_HANDL_IDLE=0, WRITE_PRIM_LIST=1, POLL_DspAck_CLEAR=2, POLL_DspAck_SET=3, READ_REP_LIST=4, LIST_HANDL_ERROR=5, }LIST_HANDLER_STATE; /*------------------------ PRIMLIST_BUILD_STATE ------------------------------*/ typedef enum{ BUILD_IDLE=0, BUILD_BUSY=1, PRIM_LIST_BUILT=2, BUILD_ERROR=3, } PRIMLIST_BUILD_STATE; /*------------------------ REPLIST_PROCESS_STATE -----------------------------*/ typedef enum{ REP_IDLE=0, REP_BUSY=1, REP_ERROR=2 } REPLIST_PROCESS_STATE; /*------------------------ TEXTBUFF_HANDLER_STATE ----------------------------*/ typedef enum { TEXT_BUFF_IDLE=0, READ_RQ_SET=1, BUFFER_READOUT=2, TEXT_BUFF_ERROR=3 } TEXTBUFF_HANDLER_STATE; /*-------------------------- struct PANEL_HANDLES ----------------------------*/ /* *labWindows UIR panel handles */ struct PANEL_HANDLES { int parent; /* main window */ int statusControl; /* statusControl window */ int commandListStatus; /* commandList window */ int txtBuff[N_TXT_BUFFS]; /* txtBuffer windows */ }; /*--------------------------- struct THREAD_INFO -----------------------------*/ /* thread info struct */ struct THREAD_INFO { HANDLE handle; /* thread handle */ DWORD id; /* thread id */ int priority; /* thread priority */ }; /*------------------- struct HOST_PROGRAM_OPTIONS ----------------------------*/ /* * HostStatusControl program options (some used only for debugging) */ struct HOST_PROGRAM_OPTIONS{ volatile BOOLEAN rodEnabled; /* access to VME on/off */ volatile BOOLEAN hostExit; /* exit host menu variable */ volatile BOOLEAN checksum; /* calc. primList and repList checksum*/ volatile BOOLEAN saveLists; /* save last primList and repList to file */ volatile BOOLEAN listOverlap; /* allow exec. of the next primList immediatelly after previous one was transferred from Rod to Host - before repList processing */ volatile int repeatExecNotBuild; /* if !=0 repeat only execution of the primList, ie. build and send primList only for the 1st time - after then (if primListRepetitions>0) set only inListReady bit in commandReg */ volatile unsigned int primListRepetitions; /* repeat primList x times - 0 means execute once */ volatile unsigned int commandListRepetitions; /* repeat commandList x times - 0 means execute once */ volatile unsigned int commandRepetitions; /* repeat command in commandList x times - 0 means execute once */ /* text buffs read requests allowed yes/no */ volatile BOOLEAN textBuffReadRq[N_TXT_BUFFS]; /* display on/off options */ volatile BOOLEAN showThreadStatus; volatile BOOLEAN showTxtBuffStatus; volatile BOOLEAN showComReg0; volatile BOOLEAN showComReg1; volatile BOOLEAN showPrimListRepCounter; volatile BOOLEAN showCommand; volatile BOOLEAN showPrimListFifo; }; /*------------------------ struct TEXT_BUFFER_INFO ---------------------------*/ /* * Text buff. info struct common for all text buffs - error, info, diag */ struct TEXT_BUFFER_INFO { UINT32 masterStruct_hpiAddr; /* masterStruct hpiAddress - init in rodInit.c */ UINT32 byteCount; /* dataLength in local "mirror" buffer */ struct TXTBUFFER masterStruct; /* see txtBuffer.h */ }; /*--------------------------- struct LIST_FIFO -------------------------------*/ /* * Queue of primLists in form of listTables waiting for building and sending to Rod; * listTable contains all info necessary for building and repListProcessing. * Fifo is implemented as a circular buffer of constant size(no dynamic memory alloc.) * Note: listCounter must be 0 when readIndex is equal to writeIndex. */ struct LIST_FIFO{ volatile long listCounter; /* number of waiting lists */ unsigned int readIndex; unsigned int writeIndex; struct LIST_TABLE listTable[LIST_FIFO_SIZE]; /* listTable buffer */ }; /*------------------------ struct LIST_SHIFT_BUFF ---------------------------*/ /* * First list in ListFifo is moved to this "shift buffer" when primListBuilding * thread is idle(listBuild is a "matrix" for primList). After building and sending * to Rod is listBuild shifted to next position(listExec) and when recieved repList * from Rod to the last(listProcess) place in the buffer. ListProcess is a matrix * for processing. * Host must always remember up to 3 listTables, since in overlapMode one list * can be builded, one executed in Rod and one processed in one moment. So shift * buffer size is 3. In non overlapMode next list cannot be executed when previous * one is still processed, so overlap is max 2. */ struct LIST_SHIFT_BUFF{ struct LIST_TABLE *listBuilt; struct LIST_TABLE *listExec; struct LIST_TABLE *listProcess; struct LIST_TABLE listTable[3]; }; /*=============================== struct HOST ===============================*/ /* * Struct which store all info specific for Host/Rod[n] */ struct HOST{ unsigned char slotNumber; /* = arrayIndex+FIRST_ROD_SLOT, where global->host[arrayIndex] */ volatile BOOLEAN rodInitialized; /* init flag */ volatile BOOLEAN interrupt; /* interrupt asserted */ /* * Host "mirror" picture of Rod buffers */ UINT32 primBuff[PRIM_BUFF_SIZE/4]; /* local primBuffer */ UINT32 replyBuff[REP_BUFF_SIZE/4]; /* local replyBuffer */ char txtBuff[N_TXT_BUFFS][TXT_BUFF_SIZE]; /* local errorBuffer */ /* primBuff and repBuff starting hpi address - * defined in memoryPartitions.h and init. in loadExitHost.c */ /* text buffers info */ struct TEXT_BUFFER_INFO textBuffInfo[N_TXT_BUFFS]; struct LIST_FIFO listFifo; /* listTable fifo info */ struct LIST_SHIFT_BUFF listShiftBuff; /* listShiftBuffer info */ struct COMMAND_LIST commandList; /* commandList to be executed in hostControl thread */ struct HOST_PROGRAM_OPTIONS option; /* program ControlWindow options*/ /* * Host copies of CommunicationRegisters */ #define NUMBER_OF_ROD_STAT_REGS 3 #define NUMBER_OF_VME_COMMAND_REGS 2 UINT32 rodStatusReg[NUMBER_OF_ROD_STAT_REGS]; UINT32 vmeCommandReg[NUMBER_OF_VME_COMMAND_REGS]; /* Pointer to primListIndex - read access */ const UINT32 *primListIndex; /* * Pointers to threads local state variables - only read access (const *) */ const PRIMLIST_BUILD_STATE *primListBuildState; const REPLIST_PROCESS_STATE *repListProcessState; LIST_HANDLER_STATE listHandlerState; TEXTBUFF_HANDLER_STATE textBuffHandlerState[N_TXT_BUFFS]; volatile CONTROL_THREAD_STATE controlThreadState; /* controlThread state */ char *commandStatusFile; /* pointer to command status file name stored in hostControl thread */ char cListFile[PATHNAME_LENGTH]; /* used in command status printout, used only as a message */ /* * Shared handshake variables - used for synchronization between threads */ volatile BOOLEAN primListBuilt; /* between primListBuilding and ListHandler */ volatile BOOLEAN repListProcessBusy; /* between repListProcessing and ListHandler */ volatile BOOLEAN textBufferProcessBusy[N_TXT_BUFFS];/* between textBuffHandl and TextBuffProcess */ volatile BOOLEAN controlThreadBusy; /* */ volatile BOOLEAN lastRepetition; /* last primListRepetition */ volatile unsigned int primListRepCounter; /* primList repetition counter */ /* * goToIdle state orders - needed only in error conditions */ volatile BOOLEAN listHandlerGoToIdle; volatile BOOLEAN textBuffHandlerGoToIdle[N_TXT_BUFFS]; /* * Threads info */ struct THREAD_INFO primListBuildThread; struct THREAD_INFO repListProcessThread; struct THREAD_INFO hostControlThread; struct THREAD_INFO textBuffsProcessThread; /* * Interthread synchronization events */ HANDLE listFifoNotEmpty_event; /* between mainThread or controlThread and primListBuild */ HANDLE repListProcess_event; /* between repListProcessing and ListHandler */ HANDLE textBuffProcess_event;/* between err, info, diagBuffHandl and TextBuffProcess */ HANDLE primListDone_event; /* */ /* goToIdle events (woke up thread from sleep state)- for synchronization */ HANDLE primListBuildGoToIdle_event; HANDLE repListProcessGoToIdle_event; struct PANEL_HANDLES panel; /* LabWindowsGUI host panels info */ char *dataDir; /* pointer to host data directory name */ }; /******************************************************************************/ #endif /* HOST_DEFINITIONS_H */