/* ============================================================= Abs: Crate Verifier Diagnostic Functions Name: CVTest.c Message: -------- CV_SendMessage - send camac request message to queue Test Read/Write Functions: ------------------------- CV_RdData - read data register CV_RdId - read id register CV_RdVoltage - read analog voltage register CV_WtData - set data register CV_RW - read write line test #1,2,3 & 4 (RW1-24) CV_RW2 - read write line test #5,6,7 & 7 (RW1-16) Send Read/Write Message to Queue: --------------------------------- CV_RdDataMsg - send msg request to read data register CV_RdIdMsg - send msg request to read id register CV_RdVoltageMsg - send msg request to read crate voltages CV_RdCrateStatusMsg - send msg request to read crate voltages CV_WtDataMsg - send msg request to set data register Utilities: ------------- blockWordSwap - Swap word data read in a camac word block transfer CV_RWDataGet - Save the read-write line word data and check for errors Note: * indicates static functions Proto: CVTest_proto.h Auth: 23-May-2010, K. Luchini (LUCHINI) Rev : dd-mmm-yyyy, Reviewer's Name (USERNAME) ------------------------------------------------------------- Mod: dd-mmm-yyyy, First Lastname (USERNAME): comment ============================================================= */ /* Header files */ #include "drvPSCDLib.h" #include "slc_macros.h" /* for vmsstat_t */ #include "cam_proto.h" /* for camalo,camalo_reset,camadd,camio,camgo */ #include "devCV.h" #include "drvCV_proto.h" #include "CVTest_proto.h" int CV_TEST_DEBUG=0; /*==================================================== Abs: Set the Data Register Name: CV_WtData Args: branch Camac Branch Type: integer Note: ignored Use: short Acc: read-only Mech: By value crate Camac Crate Number Type: integer Use: short Acc: read-only Mech: By value slot Camac Crate Slot Number Type: integer Use: short Acc: read-only Mech: By value data_p Data register data Type: pointer Note: optional argument Use: unsigned long If set to NULL the default Acc: read-write data pattern CV_DATA_PATTERN Mech: By reference will be output. Rem: The purpose of this funciton is to set the data regiser with the value specified in the data_p argument. If the data_p argument is not supplied (i.e. NULL) the the default pattern CV_DATA_PATTERN will be output to the data register. A readback of the register is done to verify that the output has latched. Side: None Ret: vmsstat_t CRAT_OKOK - Successfully completed CRAT_INITFAIL - Write failed, output data did not latch CAM_READ_MISMATCH - Read does not match setpoint Otherwise, see return codes from camio() =======================================================*/ vmsstat_t CV_WtData( short branch, short crate, short slot, unsigned long *data_p ) { vmsstat_t iss = CRAT_OKOK; /* return status */ unsigned int ctlw = 0; /* Camac control word */ unsigned short emask = 0xF3F3; /* return on NOX and NOQ */ unsigned short bcnt = sizeof(long); /* byte counte of data */ statd_4u_ts wt_statd_s = {0,CV_DATA_PATTERN}; /* output data to data register */ statd_4u_ts rbk_statd_s = {0,0}; /* readback data register */ if (data_p) wt_statd_s.data = *data_p & CV_DATA_MASK; ctlw = (crate << CCTLW__C_shc) | (slot << CCTLW__M_shc) | F20A0 | CCTLW__P24; iss = camio (&ctlw, &wt_statd_s.data, &bcnt, &wt_statd_s.stat, &emask); if (!SUCCESS(iss)) printf("CV[%hd %hd %hd]: Failed to write 0x%8.8lx to Data Register - stat=0x%8.8lX\n", branch,crate,slot,wt_statd_s.data,iss); else { ctlw = (crate << CCTLW__C_shc) | (slot << CCTLW__M_shc) | F4A0 | CCTLW__P24; iss = camio (&ctlw, &rbk_statd_s, &bcnt, &rbk_statd_s.stat, &emask); if (!SUCCESS(iss)) printf("CV[%hd %hd %hd]: Failed to Read Data Register - stat=0x%8.8lX\n",branch,crate,slot,iss); else { if ( rbk_statd_s.data!=wt_statd_s.data ) iss = CRAT_INITFAIL; else iss = CRAT_OKOK; rbk_statd_s.data = rbk_statd_s.data & CV_DATA_MASK; printf("CV[%hd %hd %hd]: Data Register failed to latch, wt=0x%8.8lx rbk=0x%8.8lx\n", branch,crate,slot, wt_statd_s.data, rbk_statd_s.data); } } return(iss); } /*==================================================== Abs: Read Data Register Name: CV_RdData Args: branch Camac Branch Type: integer Note: ignored Use: short Acc: read-only Mech: By value crate Camac Crate Number Type: integer Use: short Acc: read-only Mech: By value slot Camac Crate Slot Number Type: integer Use: short Acc: read-only Mech: By value data_p Data register data Type: pointer Note: optional argument Use: unsigned long if set to NULL Acc: read-write Mech: By reference Rem: The purpose of this to read the data register of the speficied crate verifier module and the data if the argument data_p has been supplied (not NULL). Side: None Ret: vmsstat_t CRAT_OKOK - Successfully completed CRAT_VERDATA1 - Data does not match expected pattern Otherwise, see return codes from camio() =======================================================*/ vmsstat_t CV_RdData( short branch, short crate, short slot, unsigned long *data_p ) { vmsstat_t iss = CRAT_OKOK; /* return status */ unsigned int ctlw = 0; /* Camac control word */ unsigned short emask = 0xF000; /* return on NOX and NOQ */ unsigned short bcnt = sizeof(long); /* byte counte of data */ statd_4u_ts statd_s = {0,0}; /* Camac status-data */ if (data_p) *data_p=0; ctlw = (crate << CCTLW__C_shc) | (slot << CCTLW__M_shc) | (CCTLW__F4 | CCTLW__P24); iss = camio (&ctlw, &statd_s.data, &bcnt, &statd_s.stat, &emask); if (!SUCCESS(iss)) printf("CV[%hd %hd %hd]: Failed to read Data Register - stat=0x%8.8lX\n",branch,crate,slot,iss); else { if (statd_s.data != CV_DATA_PATTERN) { iss = CRAT_VERDAT1; printf("CV[%hd %hd %hd]: Failed to read Data Register - data=0x%4.4lX stat=0x%8.8lX\n", branch,crate,slot,statd_s.data,iss); } else { iss = CRAT_OKOK; statd_s.data = statd_s.data & CV_DATA_MASK; if (data_p) *data_p = statd_s.data; printf("CV[%hd %hd %hd]: Data Register 0x%4.4lX\n",branch,crate,slot,statd_s.data); } } return(iss); } /*==================================================== Abs: Read Identification Register Name: CV_RdId Args: branch Camac Branch Type: integer Note: ignored Use: short Acc: read-only Mech: By value crate Camac Crate Number Type: integer Use: short Acc: read-only Mech: By value slot Camac Crate Slot Number Type: integer Use: short Acc: read-only Mech: By value data_p Module id Type: pointer Note: optional argument Use: unsigned long if set to NULL Acc: read-write Mech: By reference Rem: The purpose of this to read the module id register of the specified crate verifier modules and return the data if the data_p argument has been supplied (not NULL). It is a requirment that the crate verifier id register, which is set by switches on the front panel, match the crate number specified by the Serial Crate Controller module within the crate. The Serial Crate Controller module crate number is set by a thumb wheel on the front panel. Side: None Ret: vmsstat_t CRAT_OKOK - Successfully completed CAM_INV_MODID - Invalid module id Otherwise, see return codes from camio() =======================================================*/ vmsstat_t CV_RdId( short branch, short crate, short slot, unsigned long *data_p ) { vmsstat_t iss = CRAT_OKOK; /* return status */ unsigned int ctlw = 0; /* Camac control word */ unsigned short emask = 0xF2F2; /* return on NOX, expect Q=0 */ unsigned short bcnt = sizeof(long); /* byte counte of data */ statd_4u_ts statd_s = {0,0}; /* Camac status-data */ if (data_p) *data_p=0; ctlw = (crate << CCTLW__C_shc) | (slot << CCTLW__M_shc) | (CCTLW__F4 | CCTLW__A3) | CCTLW__P24; iss = camio (&ctlw, &statd_s.data, &bcnt, &statd_s.stat, &emask); if (!SUCCESS(iss)) printf("CV[%hd %hd %hd]: Failed to read ID Register - stat=0x%8.8lX\n",branch,crate,slot,iss); else { statd_s.data = statd_s.data & CV_ID_MASK; if (statd_s.data != crate) { iss = CAM_INV_MODID; printf("CV[%hd %hd %hd]: Warning ID (%ld) does not match crate number\n",branch,crate,slot,statd_s.data); } else { iss = CRAT_OKOK; printf("CV[%hd %hd %hd]: ID=%ld\n",branch,crate,slot,statd_s.data); } if (data_p) *data_p = statd_s.data; } return(iss); } /*==================================================== Abs: Read Analog Register Name: CV_RdVoltage Args: branch Camac Branch Type: integer Note: ignored Use: short Acc: read-only Mech: By value crate Camac Crate Number Type: integer Use: short Acc: read-only Mech: By value slot Camac Crate Slot Number Type: integer Use: short Acc: read-only Mech: By value Rem: The purpose of this to read the analog voltage register of the specified crate verifier modules. If the data_a argument is supplied (not NULL) then the raw data requested by the argument first_chan and nchans is returned Side: None Ret: vmsstat_t CAM_OKOK - Successfully completed CAM_BAD_A - Number of channels requested is illegal, bad subaddress. Otherwise, see return codes from camio() =======================================================*/ vmsstat_t CV_RdVoltage( short branch, short crate, short slot ) { CV_VOLT_MULT; vmsstat_t iss = CAM_OKOK; /* return status */ unsigned int ctlw = 0; /* Camac control word */ unsigned short emask = 0xF000; /* return on NOX and NOQ */ unsigned short bcnt = sizeof(short); /* byte counte of data */ unsigned long subadr = 0; /* index counter */ short rdata = 0; float fdata = 0.0; float zero = CV_ANLG_ZERO; float slope = CV_ANLG_SLOPE; statd_2_ts statd_s; /* status data */ printf("\t\tCrate Voltages & Temperature:\n"); for (subadr=0; (subadrmsgQId_ps) { CV_ClrMsgStatus( msg_s.mstat_ps ); status = epicsMessageQueueTrySend(module_ps->msgQId_ps,&msg_s,sizeof(CV_REQUEST)); } } return(status); } /*==================================================== Abs: Send a request message to read the id register Name: CV_RdIdMsg Args: branch Camac Branch Type: integer Note: ignored Use: short Acc: read-only Mech: By value crate Camac Crate Number Type: integer Use: short Acc: read-only Mech: By value slot Camac Crate Slot Number Type: integer Use: short Acc: read-only Mech: By value Rem: The purpose of this function is to send a camac function request to the message queue to read the id register. Side: None Ret: long OK - Successfully completed Otherwise - Operations failed. See return error returns from: CV_SendMsg() =======================================================*/ long CV_RdIdMsg(short b,short c,short n) { return(CV_SendMsg(b,c,n,CAMAC_RD_ID)); } /*==================================================== Abs: Send a request message to read the analog register Name: CV_RdVoltageMsg Args: branch Camac Branch Type: integer Note: ignored Use: short Acc: read-only Mech: By value crate Camac Crate Number Type: integer Use: short Acc: read-only Mech: By value slot Camac Crate Slot Number Type: integer Use: short Acc: read-only Mech: By value Rem: The purpose of this function is to send a camac function request to the message queue to read the analog register. Side: None Ret: long OK - Successfully completed Otherwise - Operations failed. See return error returns from: CV_SendMsg() =======================================================*/ long CV_RdVoltageMsg(short b,short c,short n) { return(CV_SendMsg(b,c,n,CAMAC_RD_VOLTS)); } /*==================================================== Abs: Send a request message to read the data register Name: CV_RdDataMsg Args: branch Camac Branch Type: integer Note: ignored Use: short Acc: read-only Mech: By value crate Camac Crate Number Type: integer Use: short Acc: read-only Mech: By value slot Camac Crate Slot Number Type: integer Use: short Acc: read-only Mech: By value Rem: The purpose of this function is to send a camac function request to the message queue to read the data register. This register should contain a data pattern written during boot. Side: None Ret: long OK - Successfully completed Otherwise - Operations failed. See return error returns from: CV_SendMsg() =======================================================*/ long CV_RdDataMsg(short b,short c,short n) { return(CV_SendMsg(b,c,n,CAMAC_RD_DATA)); } /*==================================================== Name: CV_RdCrateStatusMsg Args: branch Camac Branch Type: integer Note: ignored Use: short Acc: read-only Mech: By value crate Camac Crate Number Type: integer Use: short Acc: read-only Mech: By value slot Camac Crate Slot Number Type: integer Use: short Acc: read-only Mech: By value Rem: The purpose of this function is to send a camac function request to the message queue to read the data register, which should contain a pattern written to this register during startup. Side: None Ret: long OK - Successfully completed Otherwise - Operations failed. See return error returns from: CV_SendMsg() =======================================================*/ long CV_RdCrateStatusMsg(short b,short c,short n) { return(CV_SendMsg(b,c,n,CAMAC_RD_CRATE_STATUS)); } /*==================================================== Abs: Send a request message to set the data register Name: CV_WtDataMsg Args: branch Camac Branch Type: integer Note: ignored Use: short Acc: read-only Mech: By value crate Camac Crate Number Type: integer Use: short Acc: read-only Mech: By value slot Camac Crate Slot Number Type: integer Use: short Acc: read-only Mech: By value Rem: The purpose of this function is to send a camac function request to the message queue to write the default pattern to the data register. Side: None Ret: long OK - Successfully completed Otherwise - Operations failed. See return error returns from: CV_SendMsg() =======================================================*/ long CV_WtDataMsg(short b,short c,short n) { return(CV_SendMsg(b,c,n,CAMAC_WT_DATA)); } /*==================================================== Abs: Word swap data in the buffer provided. Name: CV_blockWordSwap Args: buf_p Pointer to a data array Type: integer Use: void * const Acc: read-write Mech: By reference num_words Number of words in the array Type: integer Use: unsigned int Acc: read-only Mech: By value Rem: The purpose of this function is to swap the words in the array provided. If numwords is odd we don't swap the last word Side: Code copied from Bob Sass's blockPIOP.c Ret: void =======================================================*/ void blockWordSwap(void * const buf_p, unsigned int num_words) { unsigned short *data_p = buf_p; unsigned short temp; /* Temporary data for swapping */ unsigned int i; /* index counter */ for (i=0; i