/*============================================================================= Name: drvMpsLinkNode.c Abs: Driver support for LCLS MPS Link Node module (Arcturus Coldfire 5282 processor with Xilinx FPGA) Refs: See list of docs under the heading "" on page: http://www.slac.stanford.edu/grp/lcls/controls/global/subsystems/llrf Compiler Flags: DEBUGPRINT - SCANIO - should only be undefined if you use ASYN to scan I/O Intr via callbacks Auth: 01-feb-2008, Dayle Kotturi (dayle): -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) DD-MMM-YYYY, My Name: Changed such and such to so and so. etc. etc. =============================================================================*/ #include #include #include #include #include #include #include #include /* for DEBUGPRINT */ #include #include #include #include #include #include /*#include "sqlite3.h" */ #include "mpsLinkNodeMacros.h" #include "drvMpsLinkNode.h" /* Ref: www.freescale.com Chapter 12. Chip Select Module Base address of the Freescale registers */ #define IPSBAR (0x40000000) /* Memory mapped bus location of the chip selects as set up by J. Olsen These have nothing to do with IPSBAR above */ #define CSAR1 (IPSBAR+0x00008C) /* 2 bytes */ #define CSMR1 (IPSBAR+0x000090) /* 4 bytes */ #define CSCR1 (IPSBAR+0x000096) /* 2 bytes */ #define EPPAR (IPSBAR+0x00130001) /* Two bytes. Big endian. 0=bits 15-8, 1=bits 7-0 */ #define EPDDR (IPSBAR+0x00130002) /* EPORT Data Direction Register */ #define EPIER (IPSBAR+0x00130003) /* EPORT Interrupt Enable Register */ #define EPDR (IPSBAR+0x00130004) /* EPORT Data Register */ #define EPPDR (IPSBAR+0x00130005) /* EPORT Pin Data Register */ #define EPFR (IPSBAR+0x00130006) /* EPORT Flag Register */ #define GPTSCR1A (IPSBAR+0x001A0006) /* GPT System Control Register */ #define GPTPORTA (IPSBAR+0x001A001D) /* GPT Port Data Register */ #define GPTDDRA (IPSBAR+0x001A001E) /* GPT Port Data Direction Register */ /* MPS Node Memory Mapped I/O Registers (Chip Select 1) */ #define MPS_BASE_ADDR (0x80000000) #define LATCHED_REG_ADDR0 (MPS_BASE_ADDR+0x0000) /* Register 00 */ #define LATCHED_REG_ADDR1 (MPS_BASE_ADDR+0x0004) /* Register 01 */ #define LATCHED_REG_ADDR2 (MPS_BASE_ADDR+0x0008) /* Register 02 */ #define FILTERED_REG_ADDR0 (MPS_BASE_ADDR+0x000C) /* Register 03 */ #define FILTERED_REG_ADDR1 (MPS_BASE_ADDR+0x0010) /* Register 04 */ #define FILTERED_REG_ADDR2 (MPS_BASE_ADDR+0x0014) /* Register 05 */ #define OUTPUT_REG_CNTL_ADDR (MPS_BASE_ADDR+0x0018) /* Register 06 */ /* not used */ #define OUTPUT_REG_STATUS_ADDR (MPS_BASE_ADDR+0x001C) /* Register 07 */ #define INPUT_DEBOUNCE_ADDR0 (MPS_BASE_ADDR+0x0020) /* Register 08 */ #define INPUT_DEBOUNCE_ADDR1 (MPS_BASE_ADDR+0x0024) /* Register 09 */ #define INPUT_DEBOUNCE_ADDR2 (MPS_BASE_ADDR+0x0028) /* Register 10 */ #define INPUT_DEBOUNCE_ADDR3 (MPS_BASE_ADDR+0x002C) /* Register 11 */ #define INPUT_DEBOUNCE_ADDR4 (MPS_BASE_ADDR+0x0030) /* Register 12 */ #define INPUT_DEBOUNCE_ADDR5 (MPS_BASE_ADDR+0x0034) /* Register 13 */ #define INPUT_DEBOUNCE_ADDR6 (MPS_BASE_ADDR+0x0038) /* Register 14 */ #define INPUT_DEBOUNCE_ADDR7 (MPS_BASE_ADDR+0x003C) /* Register 15 */ #define INPUT_DEBOUNCE_ADDR8 (MPS_BASE_ADDR+0x0040) /* Register 16 */ #define INPUT_DEBOUNCE_ADDR9 (MPS_BASE_ADDR+0x0044) /* Register 17 */ #define INPUT_DEBOUNCE_ADDR10 (MPS_BASE_ADDR+0x0048) /* Register 18 */ #define INPUT_DEBOUNCE_ADDR11 (MPS_BASE_ADDR+0x004C) /* Register 19 */ /* not used */ #define INPUT_POL_CNTL_ADDR0 (MPS_BASE_ADDR+0x0050) /* Register 20 */ /* not used */ #define INPUT_POL_CNTL_ADDR1 (MPS_BASE_ADDR+0x0054) /* Register 21 */ /* not used */ #define INPUT_POL_CNTL_ADDR2 (MPS_BASE_ADDR+0x0058) /* Register 22 */ /* not used */ #define TIME_SLOT_ADDR (MPS_BASE_ADDR+0x005C) /* Register 23 */ /* not used */ #define TIME_STAMP_SEC_ADDR (MPS_BASE_ADDR+0x0060) /* Register 24 */ /* not used */ #define TIME_STAMP_NSEC_ADDR (MPS_BASE_ADDR+0x0064) /* Register 25 */ #define VERSION (MPS_BASE_ADDR+0x0068) /* Register 26 */ #define LINK_NODE_CONTROL (MPS_BASE_ADDR+0x006C) /* Register 27 */ #define EVENT_COUNTER_ADDR (MPS_BASE_ADDR+0x0070) /* Register 28 */ /* not used */ #define IP_TYPE (MPS_BASE_ADDR+0x0074) /* Register 29 */ /* not used */ #define IP_INTERFACE_CONFIG (MPS_BASE_ADDR+0x0078) /* Register 30 */ /* not used */ #define IP_HIGH_ADDRESS (MPS_BASE_ADDR+0x007C) /* Register 31 */ /* not used */ #define FAULT_COUNT_ADDR (MPS_BASE_ADDR+0x0080) /* Register 32 */ /* not used */ #define FAULT_MEM_DATA_ADDR (MPS_BASE_ADDR+0x0084) /* Register 33 */ /* not used */ #define FIBER_OPTIC_SFP_CTL (MPS_BASE_ADDR+0x0088) /* Register 34 */ /* 1/21/9: used by BLM link node only */ #define FIDUCIAL_DELAY (MPS_BASE_ADDR+0x008C) /* Register 35 */ #define FIDUCIAL_WIDTH (MPS_BASE_ADDR+0x0090) /* Register 36 */ #define FIDUCIAL_DCM_PHASE (MPS_BASE_ADDR+0x0094) /* Register 37 */ #define VIRTUAL_INPUT_CARD_STS (MPS_BASE_ADDR+0x0098) /* Register 38 */ /* not used. See unnamed Mem 0x1828-0x1820 ByKick Thresholds 16Bit */ #define BY_KICK_ADC_DELAY (MPS_BASE_ADDR+0x009C) /* Register 39 */ /* not used. See unnamed Mem 0x1828-0x1820 ByKick Thresholds 16Bit */ #define BY_KICK_ADC_WIDTH (MPS_BASE_ADDR+0x00A0) /* Register 40 */ /* not used. See unnamed Mem 0x1828-0x1820 ByKick Thresholds 16Bit */ #define LED_MASK_ADDR0 (MPS_BASE_ADDR+0x00A4) /* Register 41 */ /* not used */ #define LED_MASK_ADDR1 (MPS_BASE_ADDR+0x00A8) /* Register 42 */ /* not used */ #define LED_MASK_ADDR2 (MPS_BASE_ADDR+0x00AC) /* Register 43 */ #define DEADMAN_ADDR0 (MPS_BASE_ADDR+0x00B0) /* Register 44 */ #define DEADMAN_ADDR1 (MPS_BASE_ADDR+0x00B4) /* Register 45 */ #define DEADMAN_ADDR2 (MPS_BASE_ADDR+0x00B8) /* Register 46 */ #define MPS_CONFIGURATION (MPS_BASE_ADDR+0x00BC) /* Register 47 */ /* not used */ #define BLM_THLD_FAULTS (MPS_BASE_ADDR+0x00C0) /* Register 48 */ #define PIC_SELECT (MPS_BASE_ADDR+0x00C4) /* Register 49 */ /* 1/14/9 Likely wrong. Ref s/b IP_QINT_ADC_SW_Prog_Guide... */ #define PIC_INTEG_DOSE_MON_ADDR1 (MPS_BASE_ADDR+0x0200) #define PIC_INTEG_DOSE_MON_ADDR2 (MPS_BASE_ADDR+0x0204) #define PIC_INTEG_DOSE_MON_ADDR3 (MPS_BASE_ADDR+0x0208) #define PIC_INTEG_DOSE_MON_ADDR4 (MPS_BASE_ADDR+0x020C) #define PIC_INTEG_DOSE_MON_ADDR5 (MPS_BASE_ADDR+0x0210) #define PIC_INTEG_DOSE_MON_ADDR6 (MPS_BASE_ADDR+0x0214) #define PIC_INTEG_DOSE_MON_ADDR7 (MPS_BASE_ADDR+0x0218) #define PIC_INTEG_DOSE_MON_ADDR8 (MPS_BASE_ADDR+0x021C) /******************************************************************/ /* MPS Node Memory. See table on page 5 of MPSNode_Reg_.pdf */ /******************************************************************/ /* Mem0 0x1000-0x10FF 256 Bytes of Fiber 0 Transceiver Address A0h Read as 64-4 byte/words 32Bit */ /* Mem1 0x11FF-0x1100 256 Bytes of Fiber 0 Transceiver Address A2h Read as 64-4 byte/words 32Bit */ /* Mem2 0x12FF-0x1200 256 Bytes of Fiber 1 Transceiver Address A0h Read as 64-4 byte/words 32Bit */ /* Mem3 0x13FF-0x1300 256 Bytes of Fiber 1 Transceiver Address A2h Read as 64-4 byte/words 32Bit See AVAGO Datasheet */ /* Mem4 0x1400-0x1414 ADC Data 32Bit */ #define XILINX_TEMP_ADDR (MPS_BASE_ADDR+0x1400) #define P24VMON_ADDR (MPS_BASE_ADDR+0x1404) #define P12VMON_ADDR (MPS_BASE_ADDR+0x1408) #define P5VMON_ADDR (MPS_BASE_ADDR+0x140C) #define P3D3VMON_ADDR (MPS_BASE_ADDR+0x1410) #define BOARD_TEMP_ADDR (MPS_BASE_ADDR+0x1414) /* unnamed Mem 0x181E-0x1800 BLM Thresholds 16Bit */ #define BLM_HV_THRESHOLD_BASE (MPS_BASE_ADDR+0x1800) /* unnamed Mem 0x1828-0x1820 ByKick Thresholds 16Bit */ #define BYKIK_THLD_LO_ADDR (MPS_BASE_ADDR+0x1820) #define BYKIK_THLD_HI_ADDR (MPS_BASE_ADDR+0x1822) #define BYKIK_ADC_DLY_ADDR (MPS_BASE_ADDR+0x1824) #define BYKIK_ADC_NSAMP_ADDR (MPS_BASE_ADDR+0x1826) #define BYKIK_ADC_NPSAMP_ADDR (MPS_BASE_ADDR+0x1828) /* Mem5 0x207F-0x2000 IP Board 0 16Bit QADC ID space */ #define PIC0_ID_SPACE_ADDR (MPS_BASE_ADDR+0x2000) #define BLM_ID_SPACE_ADDR (MPS_BASE_ADDR+0x2000) #define BLM_FPGA_VER_ADDR (MPS_BASE_ADDR+0x201C) /* Mem6 0x20FF-0x2080 IP Board 1 16Bit IP330 ADC/PIC1 ID space */ #define PIC1_ID_SPACE_ADDR (MPS_BASE_ADDR+0x2080) /* Mem7 0x20FF-0x2080 IP Board 1 16Bit IP330 ADC/PIC1 ID space */ #define PIC2_ID_SPACE_ADDR (MPS_BASE_ADDR+0x2100) /* Mem8 0x21FF-0x2180 IP Board 3 16Bit SPARE/PIC3 ID space */ #define PIC3_ID_SPACE_ADDR (MPS_BASE_ADDR+0x2180) /* Mem9 0x227F-0x2200 IP Board 0 16Bit QADC/PIC0 IO space */ #define QADC_IO_SPACE_BASE (MPS_BASE_ADDR+0x2200) /* QADC/PIC0 IO space. IP Board 0 */ #define QADC_CSR1_ADDR (MPS_BASE_ADDR+0x2200) /* CSR1 /Control & Status Register 1 */ #define QADC_CSR2_ADDR (MPS_BASE_ADDR+0x2202) /* CSR2 /Control & Status Register 2 */ #define QADC_CSR3_ADDR (MPS_BASE_ADDR+0x2204) /* CSR3 /Control & Status Register 3 */ #define QADC_TRIG_DELAY_ADDR (MPS_BASE_ADDR+0x2206) /* Trigger Delay */ #define QADC_TRIG_ERR_CNT_ADDR (MPS_BASE_ADDR+0x2208) /* Trigger Error Count */ #define QADC_TEST_PUL_DLY_ADDR (MPS_BASE_ADDR+0x220A) /* Trigger Pulse Delay */ #define QADC_TEST_PUL_WID_ADDR (MPS_BASE_ADDR+0x220C) /* Trigger Pulse Width */ #define QADC_GATE_DLY_ADDR (MPS_BASE_ADDR+0x220E) /* Gate Delay */ #define QADC_GATE_WID_ADDR (MPS_BASE_ADDR+0x2210) /* Gate Width */ #define QADC_SYNC_OUT_DLY_ADDR (MPS_BASE_ADDR+0x2212) /* Sync Out Delay */ #define QADC_SYNC_OUT_WID_ADDR (MPS_BASE_ADDR+0x2214) /* Sync Out Width */ #define QADC_GPIO_CTRL_ADDR (MPS_BASE_ADDR+0x2216) /* GPIO Control */ #define QADC_GATE_ADC_DLY_ADDR (MPS_BASE_ADDR+0x2218) /* Gate ADC Delay */ #define QADC_BEAM2TEST_DLY_ADDR (MPS_BASE_ADDR+0x221A) /* Beam to test delay */ #define QADC_TEST2BASE_DLY_ADDR (MPS_BASE_ADDR+0x221C) /* Test to base delay */ #define QADC_GATE_PED_ADC_DLY_ADDR (MPS_BASE_ADDR+0x221E) /* Gate PED ADC delay */ /* fault status area */ #define QADC_EGATE_DLY_ADDR (MPS_BASE_ADDR+0x2248) /* EGate Delay */ #define QADC_EGATE_WIDTH_L_ADDR (MPS_BASE_ADDR+0x224A) /* EGate Width Low */ #define QADC_EGATE_WIDTH_H_ADDR (MPS_BASE_ADDR+0x224C) /* EGate Width High */ #define QADC_EGATE_ADC_DLY_ADDR (MPS_BASE_ADDR+0x224E) /* EGate ADC Delay */ #define QADC_ACQ_CNT_L_ADDR (MPS_BASE_ADDR+0x2250) /* Acq Counter Low */ #define QADC_ACQ_CNT_H_ADDR (MPS_BASE_ADDR+0x2252) /* Acq Counter High */ /* Mem10 0x22FF-0x2280 IP Board 1 16Bit IP330 ADC/PIC1 IO space */ #define BLM_HV_MON_BASE (MPS_BASE_ADDR+0x22C0) /* Mem11 0x237F-0x2300 IP Board 2 16Bit IP231 DAC/PIC2 IO space */ #define BLM_HV_CTL_BASE (MPS_BASE_ADDR+0x2300) /* These are all the same place, contents depend on the mode of the link node */ #define BLM_MEMORY_BASE (MPS_BASE_ADDR+0x2400) #define BYK_MEMORY_BASE (MPS_BASE_ADDR+0x2400) /* w FPGA V4002: Need SyncReadReq */ #define PIC_MEMORY_BASE (MPS_BASE_ADDR+0x2400) #define BLM_ADC_MEMORY_BASE (BLM_MEMORY_BASE+0x5730) #define BLM_QADC_DOSE_MEMORY_BASE (BLM_MEMORY_BASE+0x5000) /* For Dose data (0x5n00-0x5n19), need SyncReadReq; for Threshold data (0x5n1A-0x5n25), don't need SyncReadReq p.11 BLM_MpsNode.pdf */ #define PIC_THRESHOLD_BASE (PIC_MEMORY_BASE + 0x500) /* Register descriptions Latched input values Register 0000 (R) HSB LSB xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx [31..00] latched input values 0 to 31 Latched input values Register 0001 (R) HSB LSB xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx [31..00] latched input values 32 to 63 Latched input values Register 0002 (R) HSB LSB xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx [31..00] latched input values 64 to 95 Filtered input values Register 0003 (R) HSB LSB xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx [31..00] latched input values 0 to 31 Filtered input values Register 0004 (R) HSB LSB xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx [31..00] latched input values 32 to 63 Filtered input values Register 0005 (R) HSB LSB xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx [31..00] latched input values 64 to 95 Output control Register 0006 (R) HSB LSB |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| xxxxxxxx [07..00] 00000000 read only |||||||| |||||||| xxxxxxxx |||||||| [15..08] output control outputs 4,5,6,7 set or clear output 00000000=Do not change 00000001=Set output low 00000010=Set output high 00000011=Do not change |||||||| ||||xxxx |||||||| |||||||| [19..16] 0000 read only |||||||| xxxx|||| |||||||| |||||||| [23..20] trigger 2 and 3 output control 0000=Do not change 0001=Set output low 0010=Set output high 0011=Do not change ||||xxxx |||||||| |||||||| |||||||| [27..24] trigger input latch clear 0=Do not change; 1=Clear xxxx|||| |||||||| |||||||| |||||||| [31..28] unused Output status Register 0007 (R) xxxxxxxx xxxx|||| |||||||| |||||||| [31..20] unused |||||||| ||||xxxx |||||||| |||||||| [19..16] trigger input latch status |||||||| |||||||| xxxx|||| |||||||| [15..12] trigger input status |||||||| |||||||| ||||xx|| |||||||| [11..10] CPU trigger output status |||||||| |||||||| ||||||xx |||||||| [09..08] Glink trigger output status |||||||| |||||||| |||||||| xxxx|||| [07..04] CPU output status |||||||| |||||||| |||||||| ||||xxxx [03..00] Glink output status Lookup table for debounce register 0008-0013 contents CREATE TABLE ZDEBOUNCETIME( Z_PK INTEGER PRIMARY KEY, ZENUM INTEGER, ZTIMEINMICROSECONDS INTEGER, ZNAME VARCHAR ); INSERT INTO "ZDEBOUNCETIME" VALUES(1, 0, 10, '10 us'); INSERT INTO "ZDEBOUNCETIME" VALUES(2, 1, 100, '100 us'); INSERT INTO "ZDEBOUNCETIME" VALUES(3, 2, 1000, '1 ms'); INSERT INTO "ZDEBOUNCETIME" VALUES(4, 3, 10000, '10 ms'); INSERT INTO "ZDEBOUNCETIME" VALUES(5, 4, 100000, '100 ms'); INSERT INTO "ZDEBOUNCETIME" VALUES(6, 5, 500000, '500 ms'); INSERT INTO "ZDEBOUNCETIME" VALUES(7, 6, 1000000, '1 s'); INSERT INTO "ZDEBOUNCETIME" VALUES(8, 7, 5000000, '5 s'); Input debounce select Register 0008 (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 07 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 06 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 05 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 04 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 03 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 02 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 01 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 00 Input debounce select Register 0009 (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 15 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 14 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 13 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 12 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 11 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 10 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 09 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 08 Input debounce select Register 000A (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 23 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 22 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 21 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 20 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 19 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 18 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 17 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 16 Input debounce select Register 000B (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 31 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 30 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 29 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 28 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 27 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 26 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 25 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 24 Input debounce select Register 000C (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 39 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 38 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 37 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 36 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 35 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 34 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 33 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 32 Input debounce select Register 000D (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 47 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 46 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 45 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 44 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 43 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 42 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 41 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 40 Input debounce select Register 000E (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 55 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 54 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 53 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 52 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 51 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 50 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 49 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 48 Input debounce select Register 000F (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 63 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 62 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 61 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 60 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 59 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 58 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 57 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 56 Input debounce select Register 0010 (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 71 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 70 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 69 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 68 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 67 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 66 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 65 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 64 Input debounce select Register 0011 (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 79 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 78 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 77 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 76 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 75 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 74 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 73 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 72 Input debounce select Register 0012 (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 87 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 86 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 85 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 84 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 83 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 82 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 81 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 80 Input debounce select Register 0013 (R/W) xxxxxxxx |||||||| |||||||| |||||||| [31..24] unused |||||||| xxx||||| |||||||| |||||||| [23..21] debounce select input 95 |||||||| |||xxx|| |||||||| |||||||| [20..18] debounce select input 94 |||||||| ||||||xx x||||||| |||||||| [17..15] debounce select input 93 |||||||| |||||||| |xxx|||| |||||||| [14..12] debounce select input 92 |||||||| |||||||| ||||xxx| |||||||| [11..09] debounce select input 91 |||||||| |||||||| |||||||x xx|||||| [08..06] debounce select input 90 |||||||| |||||||| |||||||| ||xxx||| [05..03] debounce select input 89 |||||||| |||||||| |||||||| |||||xxx [02..00] debounce select input 88 Time slot Register 0014 (R) xxxxxxxx xxxxxxxx xxxxxxxx |||||||| [31..08] unused |||||||| xxx||||| |||||||| |||||||| [07..00] timeslot Time stamp seconds Register 0015 (R) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx [31..00] timestamp Time stamp nanoseconds Register 0016 (R) xxxxxxxx xxxxxxxx x||||||| |||||||| [31..15] timestamp |||||||| |||||||| | xxxxxx xxxxxxxx [14..00] pulse id Lookup table for polarity "0" = low true "1" = high true Input Polarity Register 0017 (R/W) x||||||| |||||||| |||||||| |||||||| [31] polarity for input 31 |x|||||| |||||||| |||||||| |||||||| [30] polarity for input 30 ||x||||| |||||||| |||||||| |||||||| [29] polarity for input 29 |||x|||| |||||||| |||||||| |||||||| [28] polarity for input 28 xxxxxxxxxxxxxxxxxxxxxxxxxxx |||||||| |||||||| |||||||| ||||x||| [03] polarity for input 03 |||||||| |||||||| |||||||| |||||x|| [02] polarity for input 02 |||||||| |||||||| |||||||| ||||||x| [01] polarity for input 01 |||||||| |||||||| |||||||| |||||||x [00] polarity for input 00 Input Polarity Register 0018 (R/W) x||||||| |||||||| |||||||| |||||||| [31] polarity for input 63 |x|||||| |||||||| |||||||| |||||||| [30] polarity for input 62 ||x||||| |||||||| |||||||| |||||||| [29] polarity for input 61 |||x|||| |||||||| |||||||| |||||||| [28] polarity for input 60 xxxxxxxxxxxxxxxxxxxxxxxxxxx |||||||| |||||||| |||||||| ||||x||| [03] polarity for input 35 |||||||| |||||||| |||||||| |||||x|| [02] polarity for input 34 |||||||| |||||||| |||||||| ||||||x| [01] polarity for input 33 |||||||| |||||||| |||||||| |||||||x [00] polarity for input 32 Input Polarity Register 0019 (R/W) x||||||| |||||||| |||||||| |||||||| [31] polarity for input 95 |x|||||| |||||||| |||||||| |||||||| [30] polarity for input 94 ||x||||| |||||||| |||||||| |||||||| [29] polarity for input 93 |||x|||| |||||||| |||||||| |||||||| [28] polarity for input 92 xxxxxxxxxxxxxxxxxxxxxxxxxxx |||||||| |||||||| |||||||| ||||x||| [03] polarity for input 67 |||||||| |||||||| |||||||| |||||x|| [02] polarity for input 66 |||||||| |||||||| |||||||| ||||||x| [01] polarity for input 65 |||||||| |||||||| |||||||| |||||||x [00] polarity for input 64 Version Register 001A (R) xxxxxxxx xxxxxxxx |||||||| |||||||| [31..16] unused |||||||| |||||||| xxxxxxxx |||||||| [15..08] board ID switch |||||||| |||||||| |||||||| xxxxxxxx [07..00] version number Boot Prom Control 001B xxxxxxxx xxxxxxxx xxxxxxx| |||||||| [31..09] unused |||||||| |||||||| |||||||x |||||||| [08] reboot XILINX |||||||| |||||||| |||||||| xxxx|||| [07..04] unused |||||||| |||||||| |||||||| ||||x||| [03] TDO from PROM |||||||| |||||||| |||||||| |||||x|| [02] TCK from PROM |||||||| |||||||| |||||||| ||||||x| [01] TDI from PROM |||||||| |||||||| |||||||| |||||||x [00] TMS from PROM Lookup table for IO Type 0x0 = unused 0x1 = main MPS 0x2 = output card SLAC 384-202-02 (in slot 0) 0x3 = input card SLAC 384-202-01 (in slots 1-6) 0xf-0x4 = undefined IO Type Register 001C xxxx|||| |||||||| |||||||| |||||||| [31..28] board type in slot 6 ||||xxxx |||||||| |||||||| |||||||| [27..24] board type in slot 5 |||||||| xxxx|||| |||||||| |||||||| [23..20] board type in slot 4 |||||||| ||||xxxx |||||||| |||||||| [19..16] board type in slot 3 |||||||| |||||||| xxxx|||| |||||||| [15..12] board type in slot 2 |||||||| |||||||| ||||xxxx |||||||| [11..08] board type in slot 1 |||||||| |||||||| |||||||| xxxx|||| [07..04] board type in slot 0 |||||||| |||||||| |||||||| ||||xxxx [03..00] main board type IP Type Register 001D IP Config Register 001E IP High Address Register 001F ... */ #define MPS_MAX_NUM_PIC_MODULES (4) #define MPS_BENVVAR_LONG_STRING (50) #define MPS_BENVVAR_SHORT_STRING (8) #define MPS_MAX_INT (2147483647) /* 4 byte int */ typedef struct benvVar_s { char factory[MPS_BENVVAR_LONG_STRING]; char revision[MPS_BENVVAR_LONG_STRING]; char serialNumber[MPS_BENVVAR_LONG_STRING]; char console[MPS_BENVVAR_LONG_STRING]; char kernel[MPS_BENVVAR_LONG_STRING]; char kernelArgs[MPS_BENVVAR_LONG_STRING]; char hwAddr0[MPS_BENVVAR_LONG_STRING]; char firmware[MPS_BENVVAR_LONG_STRING]; char startPoint[MPS_BENVVAR_LONG_STRING]; char ramImage[MPS_BENVVAR_SHORT_STRING]; char cache[MPS_BENVVAR_SHORT_STRING]; char bootpEnable[MPS_BENVVAR_SHORT_STRING]; int autobootTime; } benvVar_t; benvVar_t benvVars; struct drvet drvMpsLinkNode = { 2, (DRVSUPFUN) mpsReport, /* subroutine defined in this file */ (DRVSUPFUN) mpsInitialise /* subroutine defined in this file */ }; epicsExportAddress(drvet, drvMpsLinkNode); /* NB: Must use global strings to be able to pass them to Cexp shell. Cexp can see all the globals in the symbol table. Note that RTEMS could be configured to also put all static vars in the symbol table, but then it would be very big. mpsGetLinkNodeLOCA and mpsGetLinkNodeUNIT have local pointers to these strings */ char *primaries[50]={"-1","0","1","2","3","4","5","6","7","9", "EIOC","EIOC","EIOC","EIOC","EIOC","EIOC","EIOC","EIOC","EIOC","EIOC", "EIOC","EIOC","EIOC","EIOC","EIOC","EIOC","EIOC","EIOC","EIOC","EIOC", "EIOC","EIOC","BLM","BLM","EIOC","BLM","BLM","BLM","EIOC","EIOC", "EIOC", "EIOC", "EIOC","EIOC","EIOC","EIOC","EIOC","EIOC","EIOC"}; char *LOCATIONS[50]={"-1","0","1","2","3","4","5","6","7","9", "LI20","IN20","LI21","LI22","LI23","LI24","LI24","LI25","LI26","LI27", "LI28","LI29","LI30","BSY0","MCC0","MCC0","MCC0","LTU1","LTU1","LTU1", "UND1","UND1","UND1","UND1","UND1","UND1","UND1","UND1","NEH","NEH", "FEH", "FEH", "SPAR","SPAR","SPAR","SPAR","SPAR","SPAR","SPAR"}; char *locations[50]={"-1","0","1","2","3","4","5","6","7","9", "li20","in20","li21","li22","li23","li24","li24","li25","li26","li27", "li28","li29","li30","bsy0","mcc0","mcc0","mcc0","ltu1","ltu1","ltu1", "und1","und1","und1","und1","und1","und1","und1","und1","neh","neh", "feh", "feh", "spar","spar","spar","spar","spar","spar","spar"}; char *UNITS[50]={"-1","0","1","2","3","4","5","6","7","9", "MP01","MP11","MP01","MP01","MP01","MP01","MP11","MP01","MP01","MP01", "MP01","MP01","MP01","MP01","MP01","MP11","MP12","MP01","MP11","MP21", "MP01","MP02","MP03","MP04","MP11","MP12","MP13","MP14","MP01","MP02", "MP01","MP02","MP01","MP02","MP03","MP04","MP05","MP06","MP07"}; char *units[50]={"-1","0","1","2","3","4","5","6","7","9", "mp01","mp11","mp01","mp01","mp01","mp01","mp11","mp01","mp01","mp01", "mp01","mp01","mp01","mp01","mp01","mp11","mp12","mp01","mp11","mp21", "mp01","mp02","mp03","mp04","mp11","mp12","mp13","mp14","mp01","mp02", "mp01","mp02","mp01","mp02","mp03","mp04","mp05","mp06","mp07"}; /* int debounceTimes[MPS_DEBOUNCE_ENUMS]; 12/19/8 no longer hold contents of SQL table ZDEBOUNCETIME Now, init all vals to -1 in mpsInitialise and fill in as you mpsParseChannels. Figure out what to do if you encounter a mapping that doesn't match */ /* On 12/19/8, testing with LinkNodeChannel.csv showed that, after parsing, debounceTimes ends up with: mpsParseChannelsConfig: debounceTimes={10,-1,-1,-1,-1,-1,-1,-1,-1,-1} QUICK AND DIRTY BUT BAD IF DEFINTION CHANGES OPTION: */ int debounceTimes[MPS_DEBOUNCE_ENUMS]={10, 100, 1000, 10000, 100000, 500000, 1000000, 5000000}; mpsNode_t thisNode; mpsNode_t* pNode = &thisNode; int mpsInitialised = 0; int num_signals = 0; /* print this @ Cexp> to see if semaphore is updating */ #ifdef WAIT_FOR_DATA_READY int num_wait_beam_pedestal = 0; int num_wait_beam_ped_3d3 = 0; int num_wait_beam_ped_2d5 = 0; int num_wait_beam_ped_1d2 = 0; int num_wait_beam_ped_gnd = 0; int num_wait_test_pedestal = 0; int num_wait_test_ped_3d3 = 0; int num_wait_test_ped_2d5 = 0; int num_wait_test_ped_1d2 = 0; int num_wait_test_ped_gnd = 0; #endif int MPS_PIC_ARRAY[MPS_MAX_NUM_PIC_MODULES]; int mpsNumPICs = 0; epicsThreadId drvMpsSyncReadThread; epicsEventId data_ready; #ifdef DEBUG_PRINT int drvMpsFlag = 0; int drvMpsInitialiseFlag = 4; int drvMpsLinkNodeTypeFlag = 0; int drvMpsParseSQLFlag = 0; int drvMpsParseXMLFlag = 0; int drvMpsGetDebounceFlag = 0; int drvMpsSetDebounceTimeRegFlag = 0; int drvMpsGetADCFlag = 0; int drvMpsSetBLMHVFlag = 0; int drvMpsGetBLMHVFlag = 0; int drvMpsGetPICFlag = 0; int drvMpsSetDebounceFlag = 0; int drvMpsSetDeadManFlag = 0; int drvMpsSetDeadManRegFlag = 0; int drvMpsGetDeadManRegFlag = 0; int drvMpsClrDeadManFlag = 0; int drvMpsSetLatchedFlag = 0; int drvMpsClrLatchedFlag = 0; int drvMpsGetLatchedFlag = 0; int drvMpsGetLatchedRegFlag = 0; int drvMpsGetStateRegFlag = 0; int drvMpsParseDebounceConfigFlag = 0; int drvMpsParseNodeConfigFlag = 0; int drvMpsParseChannelsConfigFlag = 0; int drvMpsSetCardFlag = 0; int drvMpsSetCardChannelFlag = 0; int drvMpsSetBYKThresholdFlag = 0; int drvMpsSetBLMHVThresholdFlag = 0; int drvMpsGetBLMHVThresholdFlag = 0; int drvMpsGetQADCFaultFlag = 0; int drvMpsSetQADCThresholdFlag = 0; int drvMpsQADCCSRFlag = 0; int drvMpsQADCReadoutFlag = 0; int drvMpsSyncReadRequestFlag = 0; int drvMpsSyncReadStatusFlag = 0; int drvMpsFiducialFlag = 0; int drvMpsGetADCDiagnosticFlag = 0; int drvMpsGetQADCBeamDoseFlag = 0; int drvMpsGetQADCTestDoseFlag = 0; int drvMpsAssembleDoseFlag = 0; int drvMpsGetBeamDoseFromMemFlag = 0; int drvMpsSetQADCBaseThresholdFlag = 0; int drvMpsSetQADCTestThresholdFlag = 0; int drvMpsSetQADCBeamThresholdFlag = 0; int drvMpsCSR1Flag = 0; int drvMpsCSR2Flag = 0; int drvMpsCSR3Flag = 0; int drvMpsRegistersFlag = 0; int drvMpsBYKFaultFlag = 0; int drvMpsBYKADCFlag = 0; int drvMpsPICHVFlag = 0; #endif /* LOCAL is defined in mpsLinkNodeMacros.h */ LOCAL volatile short *csar1 = (short *)CSAR1; LOCAL volatile unsigned short *cscr1 = (unsigned short *)CSCR1; LOCAL volatile unsigned long *csmr1 = (unsigned long *)CSMR1; LOCAL volatile short *mpsBaseAddr = (short *) MPS_BASE_ADDR; LOCAL volatile unsigned long *latched_reg_addr0 = (unsigned long *) LATCHED_REG_ADDR0; LOCAL volatile unsigned long *latched_reg_addr1 = (unsigned long *) LATCHED_REG_ADDR1; LOCAL volatile unsigned long *latched_reg_addr2 = (unsigned long *) LATCHED_REG_ADDR2; LOCAL volatile unsigned long *filtered_reg_addr0 = (unsigned long *) FILTERED_REG_ADDR0; LOCAL volatile unsigned long *filtered_reg_addr1 = (unsigned long *) FILTERED_REG_ADDR1; LOCAL volatile unsigned long *filtered_reg_addr2 = (unsigned long *) FILTERED_REG_ADDR2; LOCAL volatile unsigned long *output_reg_cntl_addr = (unsigned long *) OUTPUT_REG_CNTL_ADDR; /*LOCAL volatile unsigned long *output_reg_status_addr = (unsigned long *) OUTPUT_REG_STATUS_ADDR;*/ LOCAL volatile unsigned long *input_debounce_addr0 = (unsigned long *) INPUT_DEBOUNCE_ADDR0; LOCAL volatile unsigned long *input_debounce_addr1 = (unsigned long *) INPUT_DEBOUNCE_ADDR1; LOCAL volatile unsigned long *input_debounce_addr2 = (unsigned long *) INPUT_DEBOUNCE_ADDR2; LOCAL volatile unsigned long *input_debounce_addr3 = (unsigned long *) INPUT_DEBOUNCE_ADDR3; LOCAL volatile unsigned long *input_debounce_addr4 = (unsigned long *) INPUT_DEBOUNCE_ADDR4; LOCAL volatile unsigned long *input_debounce_addr5 = (unsigned long *) INPUT_DEBOUNCE_ADDR5; LOCAL volatile unsigned long *input_debounce_addr6 = (unsigned long *) INPUT_DEBOUNCE_ADDR6; LOCAL volatile unsigned long *input_debounce_addr7 = (unsigned long *) INPUT_DEBOUNCE_ADDR7; LOCAL volatile unsigned long *input_debounce_addr8 = (unsigned long *) INPUT_DEBOUNCE_ADDR8; LOCAL volatile unsigned long *input_debounce_addr9 = (unsigned long *) INPUT_DEBOUNCE_ADDR9; LOCAL volatile unsigned long *input_debounce_addr10 = (unsigned long *) INPUT_DEBOUNCE_ADDR10; LOCAL volatile unsigned long *input_debounce_addr11 = (unsigned long *) INPUT_DEBOUNCE_ADDR11; /* Nothing is done with polarity registers */ /*LOCAL volatile unsigned long *input_pol_cntl_addr0 = (unsigned long *) INPUT_POL_CNTL_ADDR0;*/ /*LOCAL volatile unsigned long *input_pol_cntl_addr1 = (unsigned long *) INPUT_POL_CNTL_ADDR1;*/ /*LOCAL volatile unsigned long *input_pol_cntl_addr2 = (unsigned long *) INPUT_POL_CNTL_ADDR2;*/ /* Nothing is done with time slot registers */ /*LOCAL volatile unsigned long *time_slot_addr = (unsigned long *) TIME_SLOT_ADDR;*/ /*LOCAL volatile unsigned long *time_stamp_sec_addr = (unsigned long *) TIME_STAMP_SEC_ADDR;*/ /*LOCAL volatile unsigned long *time_stamp_nsec_addr = (unsigned long *) TIME_STAMP_NSEC_ADDR;*/ LOCAL volatile unsigned long *version = (unsigned long *) VERSION; LOCAL volatile unsigned long *fiducial_delay = (unsigned long *) FIDUCIAL_DELAY; LOCAL volatile unsigned long *fiducial_width = (unsigned long *) FIDUCIAL_WIDTH; LOCAL volatile unsigned long *fiducial_dcm_phase = (unsigned long *) FIDUCIAL_DCM_PHASE; LOCAL volatile unsigned long *virtual_input_card_sts = (unsigned long *) VIRTUAL_INPUT_CARD_STS; /* Used to update the FPGA image */ LOCAL volatile unsigned long *link_node_control = (unsigned long *) LINK_NODE_CONTROL; LOCAL volatile unsigned long *event_counter_addr = (unsigned long *) EVENT_COUNTER_ADDR; /*LOCAL volatile unsigned long *ip_interface_config = (unsigned long *) IP_INTERFACE_CONFIG;*/ /*LOCAL volatile unsigned long *ip_high_address = (unsigned long *) IP_HIGH_ADDRESS;*/ /* Nothing is done with LED masks */ /*LOCAL volatile unsigned long *led_mask0 = (unsigned long *) LED_MASK_ADDR0;*/ /*LOCAL volatile unsigned long *led_mask1 = (unsigned long *) LED_MASK_ADDR1;*/ /*LOCAL volatile unsigned long *led_mask2 = (unsigned long *) LED_MASK_ADDR2;*/ LOCAL volatile unsigned long *deadman_addr0 = (unsigned long *) DEADMAN_ADDR0; LOCAL volatile unsigned long *deadman_addr1 = (unsigned long *) DEADMAN_ADDR1; LOCAL volatile unsigned long *deadman_addr2 = (unsigned long *) DEADMAN_ADDR2; LOCAL volatile unsigned long *mps_config = (unsigned long *) MPS_CONFIGURATION; LOCAL volatile unsigned long *pic_select = (unsigned long *) PIC_SELECT; LOCAL volatile unsigned long *pic_mon_addr1 = (unsigned long *) PIC_INTEG_DOSE_MON_ADDR1; LOCAL volatile unsigned long *pic_mon_addr2 = (unsigned long *) PIC_INTEG_DOSE_MON_ADDR2; LOCAL volatile unsigned long *pic_mon_addr3 = (unsigned long *) PIC_INTEG_DOSE_MON_ADDR3; LOCAL volatile unsigned long *pic_mon_addr4 = (unsigned long *) PIC_INTEG_DOSE_MON_ADDR4; LOCAL volatile unsigned long *pic_mon_addr5 = (unsigned long *) PIC_INTEG_DOSE_MON_ADDR5; LOCAL volatile unsigned long *pic_mon_addr6 = (unsigned long *) PIC_INTEG_DOSE_MON_ADDR6; LOCAL volatile unsigned long *pic_mon_addr7 = (unsigned long *) PIC_INTEG_DOSE_MON_ADDR7; LOCAL volatile unsigned long *pic_mon_addr8 = (unsigned long *) PIC_INTEG_DOSE_MON_ADDR8; LOCAL volatile unsigned short *bykik_addr = (unsigned short *) BYK_MEMORY_BASE; LOCAL volatile unsigned long *xilinx_temp_address = (unsigned long *) XILINX_TEMP_ADDR; LOCAL volatile unsigned long *p24vmon_address = (unsigned long *) P24VMON_ADDR; LOCAL volatile unsigned long *p12vmon_address = (unsigned long *) P12VMON_ADDR; LOCAL volatile unsigned long *p5vmon_address = (unsigned long *) P5VMON_ADDR; LOCAL volatile unsigned long *p3d3vmon_address = (unsigned long *) P3D3VMON_ADDR; LOCAL volatile unsigned long *board_temp_address = (unsigned long *) BOARD_TEMP_ADDR; LOCAL volatile unsigned short *blm_fpga_ver_addr = (unsigned short *) BLM_FPGA_VER_ADDR; LOCAL volatile unsigned short *qadc_csr1_addr = (unsigned short *) QADC_CSR1_ADDR; LOCAL volatile unsigned short *qadc_csr2_addr = (unsigned short *) QADC_CSR2_ADDR; LOCAL volatile unsigned short *qadc_csr3_addr = (unsigned short *) QADC_CSR3_ADDR; LOCAL volatile unsigned short *qadc_trig_delay_addr = (unsigned short *) QADC_TRIG_DELAY_ADDR; LOCAL volatile unsigned short *qadc_trig_err_cnt_addr = (unsigned short *) QADC_TRIG_ERR_CNT_ADDR; LOCAL volatile unsigned short *qadc_test_pul_dly_addr = (unsigned short *) QADC_TEST_PUL_DLY_ADDR; LOCAL volatile unsigned short *qadc_test_pul_wid_addr = (unsigned short *) QADC_TEST_PUL_WID_ADDR; LOCAL volatile unsigned short *qadc_gate_dly_addr = (unsigned short *) QADC_GATE_DLY_ADDR; LOCAL volatile unsigned short *qadc_gate_wid_addr = (unsigned short *) QADC_GATE_WID_ADDR; LOCAL volatile unsigned short *qadc_sync_out_dly_addr = (unsigned short *) QADC_SYNC_OUT_DLY_ADDR; LOCAL volatile unsigned short *qadc_sync_out_wid_addr = (unsigned short *) QADC_SYNC_OUT_WID_ADDR; LOCAL volatile unsigned short *qadc_gpio_ctrl_addr = (unsigned short *) QADC_GPIO_CTRL_ADDR; LOCAL volatile unsigned short *qadc_gate_adc_dly_addr = (unsigned short *) QADC_GATE_ADC_DLY_ADDR; LOCAL volatile unsigned short *qadc_beam2test_dly_addr = (unsigned short *) QADC_BEAM2TEST_DLY_ADDR; LOCAL volatile unsigned short *qadc_test2base_dly_addr = (unsigned short *) QADC_TEST2BASE_DLY_ADDR; LOCAL volatile unsigned short *qadc_gate_ped_adc_dly_addr = (unsigned short*) QADC_GATE_PED_ADC_DLY_ADDR; LOCAL volatile unsigned short *qadc_egate_dly_addr = (unsigned short *) QADC_EGATE_DLY_ADDR; LOCAL volatile unsigned short *qadc_egate_width_l_addr = (unsigned short *) QADC_EGATE_WIDTH_L_ADDR; LOCAL volatile unsigned short *qadc_egate_width_h_addr = (unsigned short *) QADC_EGATE_WIDTH_H_ADDR; LOCAL volatile unsigned short *qadc_egate_adc_dly_addr = (unsigned short *) QADC_EGATE_ADC_DLY_ADDR; LOCAL volatile unsigned short *qadc_acq_cnt_l = (unsigned short *) QADC_ACQ_CNT_L_ADDR; LOCAL volatile unsigned short *qadc_acq_cnt_h = (unsigned short *) QADC_ACQ_CNT_H_ADDR; /****************************************************************************** Routines just for PIC ******************************************************************************/ /* used in debugging only */ int mpsSetPIC(int pic) { *pic_select = pic; return OK; } /* used by mpsInitialise to determine modules present */ int mpsDetectPICs() { if (*(short*) PIC0_ID_SPACE_ADDR != 0) { MPS_PIC_ARRAY[0]=1; mpsNumPICs++; } else { MPS_PIC_ARRAY[0]=0; } if (*(short*) PIC1_ID_SPACE_ADDR != 0) { MPS_PIC_ARRAY[1]=1; mpsNumPICs++; } else { MPS_PIC_ARRAY[1]=0; } if (*(short*) PIC2_ID_SPACE_ADDR != 0) { MPS_PIC_ARRAY[2]=1; mpsNumPICs++; } else { MPS_PIC_ARRAY[2]=0; } if (*(short*) PIC3_ID_SPACE_ADDR != 0) { MPS_PIC_ARRAY[3]=1; mpsNumPICs++; } else { MPS_PIC_ARRAY[3]=0; } printf ("mpsDetectPICs: found %d PIC modules in slots %d %d %d %d\n", mpsNumPICs, MPS_PIC_ARRAY[0], MPS_PIC_ARRAY[1], MPS_PIC_ARRAY[2], MPS_PIC_ARRAY[3]); return OK; } int mpsSetPICHighVoltage(int val) { int mask; int updated_reg; switch (val) { case 0: /* bits 5,4 are 0 and 0. Unchanged from current state */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsPICHVFlag, ("mpsSetPICHighVoltage: unchanged from current state\n")); #endif break; case 1: /* bits 5,4 are 0 and 1. HVPS ON (OFF goes to 0 before ON goes to 1) */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsPICHVFlag, ("mpsSetPICHighVoltage: turning HVPS on\n")); #endif break; case 2: /* bits 5,4 are 1 and 0. HVPS OFF (ON goes to 0 before OFF goes to 1) */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsPICHVFlag, ("mpsSetPICHighVoltage: turning HVPS off\n")); #endif break; case 3: /* bits 5,4 are 1 and 1. undefined / causes race condition */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsPICHVFlag, ("mpsSetPICHighVoltage: undefined/race condition\n")); #endif break; default: /* unrecognized */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsPICHVFlag, ("mpsSetPICHighVoltage: unrecognized case=%d\n", val)); #endif } /* The on/off is in bits 4 and 5, counting from 0 */ mask = (val << 4); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsPICHVFlag, ("mpsSetPICHighVoltage: mask=%d\n", mask)); #endif /* Wipe out bits 4 and 5 and replace them with val */ updated_reg = (*output_reg_cntl_addr & 0xFFFFFFCF) | mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsPICHVFlag, ("mpsSetPICHighVoltage: updated register contents=%d\n", updated_reg)); #endif *output_reg_cntl_addr = updated_reg; return OK; } int mpsGetPICHighVoltageStatus() { int val; /* PIC HVPS status is in bit 9 of Register 03. See page 8 MpsNode_Reg */ val = (*filtered_reg_addr0 >> 9) & 1; switch (val) { case 0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsPICHVFlag, ("mpsGetPICHighVoltageStatus: ON, register contents: 0x%x\n", (unsigned int) *filtered_reg_addr0)); #endif break; case 1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsPICHVFlag, ("mpsGetPICHighVoltageStatus: OFF, register contents: 0x%x\n",(unsigned int) *filtered_reg_addr0)); #endif break; default: /* unrecognized */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsPICHVFlag, ("mpsGetPICHighVoltageStatus: unrecognized val=%d\n", val)); #endif } return val; } int mpsGetPIC29HighVoltageStatus() { int val; /* PIC LN29 HVPS status is in bit 1 of Register 03. See page 8 MpsNode_Reg */ val = (*filtered_reg_addr0 >> 1) & 1; switch (val) { case 0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsPICHVFlag, ("mpsGetPIC29HighVoltageStatus: ON, register contents: 0x%x\n", (unsigned int) *filtered_reg_addr0)); #endif break; case 1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsPICHVFlag, ("mpsGetPIC29HighVoltageStatus: OFF, register contents: 0x%x\n",(unsigned int) *filtered_reg_addr0)); #endif break; default: /* unrecognized */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsPICHVFlag, ("mpsGetPIC29HighVoltageStatus: unrecognized val=%d\n", val)); #endif } return val; } /****************************************************************************** Routines common to PIC and BLM ******************************************************************************/ /*************************** CSR1 ******************************/ /* bit 0 */ int mpsSetCSR1Reset(int module) { unsigned short mask = 1; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } *qadc_csr1_addr |= mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1Reset: for pic %d\n", module)); #endif return OK; } /* there is no need for mpsGetCSR1Reset() because read always returns 0 */ /* bit 1 */ int mpsSetCSR1DiagnosticModeEnable(int module) { unsigned short mask = 2; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } *qadc_csr1_addr |= mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1DiagnosticModeEnable: for CSR1 for pic %d\n", module)); #endif return OK; } /* bit 2 */ int mpsSetCSR1Arm(int module) { unsigned short mask = 4; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } *qadc_csr1_addr |= mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1Arm: for pic %d\n", module)); #endif return OK; } /* bit 3 */ int mpsSetCSR1Enable(int module) { unsigned short mask = 8; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } *qadc_csr1_addr |= mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1Enable: for pic %d\n", module)); #endif return OK; } /* bits 4 and 5 */ int mpsSetCSR1DiagnosticModeSelect(int module, int val) { unsigned short mask = (val & 3) << 4; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } *qadc_csr1_addr |= mask; switch (val) { case 0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1DiagnosticModeSelect: Single-shot beam mode for pic %d\n", module)); #endif break; case 1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1DiagnosticModeSelect: Single-shot test mode for pic %d\n", module)); #endif break; case 2: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1DiagnosticModeSelect: Single-shot baseline mode for pic %d\n", module)); #endif break; case 3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1DiagnosticModeSelect: Single-step mode for pic %d\n", module)); #endif break; default: return ERROR; } return OK; } /* bits 6 and 7 */ int mpsSetCSR1TriggerSourceSelect(int module, int val) { unsigned short mask = (val & 3) << 6; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } *qadc_csr1_addr |= mask; switch (val) { case 0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1TriggerSourceSelect: External 1 for pic %d\n", module)); #endif break; case 1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1TriggerSourceSelect: External 2 for pic %d\n", module)); #endif break; case 2: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1TriggerSourceSelect: Software for pic %d\n", module)); #endif break; case 3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1TriggerSourceSelect: Reserved for pic %d\n", module)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR1Flag, ("mpsSetCSR1TriggerSourceSelect: Unrecognized case: %d for pi %dc\n", val, module)); #endif return ERROR; } return OK; } /* bit 8 */ int mpsSetCSR1TriggerEdgeSelect(int module, int val) { unsigned short mask = 256; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr1_addr &= ~mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1TriggerEdgeSelect: falling edge for pic %d\n", module)); #endif break; case 1: *qadc_csr1_addr |= mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1TriggerEdgeSelect: rising edge for pic %d\n", module)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR1Flag, ("mpsSetCSR1TriggerEdgeSelect: Unrecognized value: %d (should be 0 or 1) for pic %d\n", val, module)); #endif return ERROR; } return OK; } /* bit 9 */ int mpsSetCSR1MissedTriggerStatus(int module, int val) { unsigned short mask = 512; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr1_addr &= ~mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1MissedTriggerStatus: 0 for pic %d\n", module)); #endif break; case 1: *qadc_csr1_addr |= mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsSetCSR1MissedTriggerStatus: 1 for pic %d\n", module)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR1Flag, ("mpsSetCSR1MissedTriggerStatus: Unrecognized value: %d (not 0 or 1) for pic %d\n", val, module)); #endif return ERROR; } return OK; } /* 4/13/9 The story: In order to get the correct value, QADC readout needs to be called with the PIC module. Once this is done (and no other routine is called in the interim, then this routine can be called - actually the module part is not needed here. */ int mpsGetCSR1MissedTriggerStatus(int module) { int val; unsigned short mask = 512; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr1_addr & mask) >> 9; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsGetCSR1MissedTriggerStatus: module=%d\n", module)); #endif return val; } /* bit 10 */ int mpsSetCSR1SoftwareTrigger(int module, int val) { unsigned short mask = 1024; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR1Flag, ("mpsSetCSR1SoftwareTrigger: Unrecognized value: %d (not 0 or 1)\n", val)); #endif return ERROR; } return OK; } /* bit 11 */ int mpsSetCSR1DataReady(int module, int val) { unsigned short mask = 2048; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR1Flag, ("mpsSetCSR1DataReady: Unrecognized value: %d (should be 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR1DataReady(int module) { int val; unsigned short mask = 2048; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr1_addr & mask) >> 11; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsGetCSR1DataReady: module=%d\n", module)); #endif return val; } /* bit 12 */ int mpsSetCSR1GateGeneratorSelect(int module, int val) { unsigned short mask = 4096; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR1Flag, ("mpsSetCSR1GateGeneratorSelect: Unrecognized value: %d (not 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR1GateGeneratorSelect(int module) { int val; unsigned short mask = 4096; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr1_addr & mask) >> 12; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsGetCSR1GateGeneratorSelect: module=%d\n", module)); #endif return val; } /* bit 13 */ int mpsSetCSR1GateTriggerSelect(int module, int val) { unsigned short mask = 8192; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR1Flag, ("mpsSetCSR1GateTriggerSelect: Unrecognized value: %d (not 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR1GateTriggerSelect(int module) { int val; unsigned short mask = 8192; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr1_addr & mask) >> 13; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsGetCSR1GateTriggerSelect: module=%d\n", module)); #endif return val; } /* bit 14 */ int mpsSetCSR1GatePolarity(int module, int val) { unsigned short mask = 16384; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR1Flag, ("mpsSetCSR1GatePolarity: Unrecognized value: %d (not 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR1GatePolarity(int module) { int val; unsigned short mask = 16384; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr1_addr & mask) >> 14; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsGetCSR1GatePolarity: module=%d\n", module)); #endif return val; } /* bit 15 */ int mpsSetCSR1GateEnable(int module, int val) { unsigned short mask = 32768; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR1Flag, ("mpsSetCSR1GateEnable: Unrecognized value: %d (not 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR1GateEnable(int module) { int val; unsigned short mask = 32768; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr1_addr & mask) >> 15; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR1Flag, ("mpsGetCSR1GateEnable: module=%d\n", module)); #endif return val; } /*************************** CSR2 ******************************/ /* bit 0: gives the lock status of the 20 MHz FPGA Digital Clock Manager, which uses the 80 MHz board clock to generate its 20 MHz clock. The lock bit from the internal PLL. read only, no write */ int mpsGetCSR2D2LStatus(int module) { int val; unsigned short mask = 1; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_csr2_addr & mask; return val; } /* bit 1: gives the lock status of the 40 MHz FPGA Digital Clock Manager, which uses the 80 MHz board clock to generate its 40 MHz clock. The lock bit from the internal PLL. read only, no write */ int mpsGetCSR2D4LStatus(int module) { int val; unsigned short mask = 2; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr2_addr & mask) >> 1; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR2Flag, ("mpsGetCSR2D4LStatus: module=%d\n", module)); #endif return val; } /* bits 2 and 3: unused */ /* bit 4: test pulse enable r/w resets to 0 0x0: test pulse output is disabled 0x1: test pulse output is enabled This bit enables the generation of the output test pulse or heartbeat signal */ int mpsSetCSR2TestPulseEnable (int module, int val) { unsigned short mask = 16; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr2_addr &= ~mask; break; case 1: *qadc_csr2_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR2Flag, ("mpsSetCSR2TestPulseEnable: Unrecognized value: %d (not 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR2TestPulseEnable(int module) { int val; unsigned short mask = 16; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr2_addr & mask) >> 4; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR2Flag, ("mpsGetCSR2TestPulseEnable: module=%d\n", module)); #endif return val; } /* bit 5: test pulse polarity r/w resets to 1 0x0: test pulse signal polarity is Negative-True (low-going pulse) 0x1: test pulse signal polarity is Positive-True (high-going pulse) This bit controls the polarity of teh output test pulse signal. */ int mpsSetCSR2TestPulsePolarity(int module, int val) { unsigned short mask = 32; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr2_addr &= ~mask; break; case 1: *qadc_csr2_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR2Flag, ("mpsSetCSR2TestPulsePolarity: Unrecognized value: %d (not 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR2TestPulsePolarity(int module) { int val; unsigned short mask = 32; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr2_addr & mask) >> 5; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR2Flag, ("mpsGetCSR2TestPulsePolarity: module=%d\n", module)); #endif return val; } /* bit 6: test pulse trigger select r/w resets to 0 0x0: external trigger used 0x1: software trigger used selects which trigger souce the test pulse generator will use. When the external trigger is selected, it will select whichever source the TR_S[1:0] bits are set to. Separate control is provided here for diagnostic purposes. */ int mpsSetCSR2TestPulseTriggerSelect(int module, int val) { unsigned short mask = 64; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr2_addr &= ~mask; break; case 1: *qadc_csr2_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR2Flag, ("mpsSetCSR2TestPulseTriggerSelect: Unrecognized value: %d (not 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR2TestPulseTriggerSelect(int module) { int val; unsigned short mask = 64; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr2_addr & mask) >> 6; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR2Flag, ("mpsGetCSR2TestPulseTriggerSelect: module=%d\n", module)); #endif return val; } /* bit 7: unused */ /* bits 8-15: test acquisition delay control r/w - read returns set status of bits / resets to 0x2E controls the delay time between the assertion of the LED test pulse and this acquisition of the resultant detector output charge. The delay unit step size is 25 ns. The minimum intrinsic delay, when the register is set to 0x0 is 2 counts due to internal logic delays. Therefore, qty = 2 counts must be added to the set value to reflect the actual delay of 1.2 uS. Eg: 46 counts + 2 intrinsic delay = 48 counts at 25 ns This delay is set for the BLM system and accounts for the round-trip delays of the cables and the intrinsic delays of the detector and electronics. */ int mpsSetCSR2TestAcquisitionDelayControl(int module, int val) { unsigned short mask = 0xFF00; int counts; unsigned short intermediary; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } /* val is in ns */ /* convert ns to counts. 1 count = 25 ns */ counts = val/25; /* subtract 2 counts for delays */ counts += 2; intermediary = (counts << 8) & mask; /* don't clobber the lower byte of CSR2 */ *qadc_csr2_addr |= intermediary; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR2Flag, ("mpsSetCSR2TestAcquisitionDelayControl: %d nsec -> %d counts + 2 shifted 8 left and or'ed in: 0x%0x\n", val, (val/25), (unsigned int) intermediary)); #endif return OK; } unsigned int mpsGetCSR2TestAcquisitionDelayControl(int module) { unsigned int val; unsigned short mask = 0xFF00; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr2_addr & mask) >> 8; val -= 2; /* 10/14/09: this was "+=", but that looks wrong, given what section 3.4 of IP_QINT_ADC_SW_Prog_Guide says */ val *= 25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR2Flag, ("mpsGetCSR2TestAcquisitionDelayControl: module=%d\n", module)); #endif return val; } /*************************** CSR3 ******************************/ /* bit 0: controls whether the sync output will be asserted or not */ int mpsSetCSR3SyncOutputEnable(int module, int val) { unsigned short mask = 1; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr3_addr &= ~mask; break; case 1: *qadc_csr3_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputEnable: Unrecognized value: %d (not 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR3SyncOutputEnable(int module) { int val; unsigned short mask = 1; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_csr3_addr & mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputEnable: module=%d\n", module)); #endif return val; } /* bit 1: controls the polarity of the sync signal */ int mpsSetCSR3SyncPulsePolarity(int module, int val) { unsigned short mask = 2; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr3_addr &= ~mask; break; case 1: *qadc_csr3_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR3Flag, ("mpsSetCSR3SyncPulsePolarity: Unrecognized value: %d (not 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR3SyncPulsePolarity(int module) { int val; unsigned short mask = 2; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_csr3_addr & mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncPulsePolarity: module=%d\n", module)); #endif return val; } /* bit 2: controls the output mode of the sync signal */ int mpsSetCSR3SyncOutputMode(int module, int val) { unsigned short mask = 4; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr3_addr &= ~mask; break; case 1: *qadc_csr3_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputMode: Unrecognized value: %d (not 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR3SyncOutputMode(int module) { int val; unsigned short mask = 4; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_csr3_addr & mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputMode: module=%d\n", module)); #endif return val; } /* bit 3: unused */ /* bits 4-7: sync output pulse source selection MUX selects the source of the sync output signals. The selected signal, when asserted, will cause the sync pulse to be output (after the programmed delay). */ int mpsSetCSR3SyncOutputPulseSourceSelectionMUX(int module, int val) { unsigned short mask = (val & 0xF) << 4; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } *qadc_csr1_addr |= mask; switch (val) { case 0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: Trigger (%d)\n", val)); #endif break; case 1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: Gate (%d)\n", val)); #endif break; case 2: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: ADC Acq Go (%d)\n", val)); #endif break; case 3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: Get Beam Data (%d)\n", val)); #endif break; case 4: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: Get Test Data (%d)\n", val)); #endif break; case 5: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: Get Base Data (%d)\n", val)); #endif break; case 6: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: Get Beam Data Done (%d)\n", val)); #endif break; case 7: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: Get Test Data Done (%d)\n", val)); #endif break; case 8: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: Get Base Data Done (%d)\n", val)); #endif break; case 9: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: Sum Fault Beam (%d)\n", val)); #endif break; case 10: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: Sum Fault Test (%d)\n", val)); #endif break; case 11: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: Sum Fault Base (%d)\n", val)); #endif break; case 12: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: S/W Trigger (%d)\n", val)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsSetCSR3SyncOutputPulseSourceSelectionMUX: unrecognized value: %d\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR3SyncOutputPulseSourceSelectionMUX(int module) { unsigned int val; unsigned short mask = 0xF0; mpsQADCReadout(module); /* INVASIVE */ val = (*qadc_csr2_addr & mask) >> 4; switch (val) { case 0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: Trigger (%d)\n", val)); #endif break; case 1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: Gate (%d)\n", val)); #endif break; case 2: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: ADC Acq Go (%d)\n", val)); #endif break; case 3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: Get Beam Data (%d)\n", val)); #endif break; case 4: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: Get Test Data (%d)\n", val)); #endif break; case 5: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: Get Base Data (%d)\n", val)); #endif break; case 6: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: Get Beam Data Done (%d)\n", val)); #endif break; case 7: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: Get Test Data Done (%d)\n", val)); #endif break; case 8: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: Get Base Data Done (%d)\n", val)); #endif break; case 9: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: Sum Fault Beam (%d)\n", val)); #endif break; case 10: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: Sum Fault Test (%d)\n", val)); #endif break; case 11: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: Sum Fault Base (%d)\n", val)); #endif break; case 12: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: S/W Trigger (%d)\n", val)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: unrecognized value: %d\n", val)); #endif return ERROR; } /* ensure range is [0,7] */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3SyncOutputPulseSourceSelectionMUX: module=%d\n", module)); #endif return val; } /* bit 11: 0x0: ADC has +/- 10 V dynamic range 0x1: ADC has +/- 5 V dynamic range controls ADC input voltage dynamic range. Should only be set during initialisation, before the ADC receives a SV reset. When in +/- 5 V range, the ADC has a resolution of 153 uV/count; when in +/-10 V range, the ADC has a resolution of 305 uV/count. The range should be set before SW_RES is issued. */ int mpsSetCSR3ADCRangeControl(int module, int val) { unsigned short mask = 0x800; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr3_addr &= ~mask; break; case 1: *qadc_csr3_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsCSR3Flag, ("mpsGetCSR3ADCRangeControl: unrecognized value: %d\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR3ADCRangeControl(int module) { int val; unsigned short mask = 0x800; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_csr3_addr & mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3ADCRangeControl: module=%d\n", module)); #endif return val; } /* bit 12: unused */ /* bit 13: unused */ /* bit 14: controls whether the baseline correction function is applied. When cleared, the baseline corrector functions normally, applying the baseline correction value calculated on the prev acq cycle to the incoming ADC samples. When this bit is set, the basline corrction holding register is kept in constant clear, essentially subtracting a value of 0x0000 from the incoming ADC samples */ int mpsSetCSR3FBC(int module, int val) { unsigned short mask = 0x4000; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (val) { case 0: *qadc_csr3_addr &= ~mask; break; case 1: *qadc_csr3_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR3FBC(int module) { int val; unsigned short mask = 0x4000; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_csr3_addr & mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3FBC: module=%d\n", module)); #endif return val; } /* bit 15: read only */ int mpsGetCSR3PICMode(int module) { int val; unsigned short mask = 0x8000; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_csr3_addr & mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsCSR3Flag, ("mpsGetCSR3PICMode: module=%d\n", module)); #endif return val; } /***************************************************************************** Registers *****************************************************************************/ /* 3.4 of IP_QINT_ADC_SW_Prog_Guide sets the delay time from the trigger input to actual beginning of the data acquisition cycle. The timing resolution is 25.0 ns per count. Note that there is an intrinsic delay latency of (3) clock cycles; this must be taken into account when setting the delay value R/W resets to 0 / read returns set value 0x0000: minimum delay value = (3) 25 ns clk40 -> 75 ns 0xFFFF: maximum setting (65535 + 3 = 65538 cycles -> 1.63845 ms) */ int mpsSetTriggerDelay(int module, int val) { unsigned short delay; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } /* convert ns to counts. 1 count = 25 ns */ delay = (unsigned short) val/25; if (delay < 3) { delay = 0; } else { delay -= 3; } *qadc_trig_delay_addr = delay; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetTriggerDelay: %d nsec -> %hu delay\n", val, delay)); #endif return OK; } int mpsGetTriggerDelay(int module) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_trig_delay_addr; /* convert to ns */ val = (val + 3)*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetTriggerDelay: (%hu+3)*25=%d nsec\n", *qadc_trig_delay_addr, val)); #endif return (int) val; } /* provides a count of the number of 360Hz triggers that have been missed per trigger cycle. A write to this register clears it to zero and re-arms the counter. This counter is enabled by the ARM bit R/W resets to 0 read returns set value write of any value (using 0 here) clears Write: 0xXXXX = clears counter to 0x0000 and re-arms */ int mpsClrTriggerErrorCounter(int module) { /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } *qadc_trig_err_cnt_addr = 0x00; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsClrTriggerErrorCounter: after clear, contents are: %hu\n", *qadc_trig_err_cnt_addr)); #endif return OK; } int mpsGetTriggerErrorCounter(int module) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_trig_err_cnt_addr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetTriggerErrorCounter:\n")); #endif return (int) val; } /* sets the delay time from trigger to actual assertion of the gate pulse signal. The timing resolution is 25ns per count. There is an intrinsic delay latency of 2 clock cycles. AKA: Test Pulse Assertion Delay */ int mpsSetTestPulseGeneratorDelay(int module, int val) { unsigned short delay; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } /* convert ns to counts. 1 count = 25 ns */ delay = (unsigned short) (val/25); if (delay < 2) { delay = 0; } else { delay -= 2; } *qadc_test_pul_dly_addr = delay; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetTestPulseGeneratorDelay: %d nsec -> %hu counts\n", val, delay)); #endif return OK; } int mpsGetTestPulseGeneratorDelay(int module) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_test_pul_dly_addr; /* convert from counts to ns */ val = (val + 2)*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetTestPulseGeneratorDelay: (%hu+2)*25=%d nsec\n", *qadc_test_pul_dly_addr,val)); #endif return (int) val; } /* sets the width of the test pulse R/W resets to 0x50 (2 us default pulse width 0x0: no output 0x1-0xFFFF: test pulse width in counts */ int mpsSetTestPulseGeneratorWidth(int module, int val) { unsigned short width; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } width = (unsigned short) (val/25); *qadc_test_pul_wid_addr = width; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetTestPulseGeneratorWidth: %hu nsec", width)); #endif return OK; } int mpsGetTestPulseGeneratorWidth(int module ) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_test_pul_wid_addr; /* convert to ns */ val = val*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetTestPulseGeneratorWidth: %hu nsec\n", val)); #endif return (int) val; } /* 3.8 delay latency 2 clock cycles */ int mpsSetGateGeneratorDelay(int module, int val) { unsigned short delay; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } /* convert ns to counts. 1 count = 25 ns */ delay = (unsigned short) val/25; if (delay < 2) { delay = 0; } else { delay -= 2; } *qadc_gate_dly_addr = delay; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetGateGeneratorDelay: %d nsec -> %hu counts\n", val, delay)); #endif return OK; } int mpsGetGateGeneratorDelay(int module ) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_gate_dly_addr; /* convert counts to ns*/ val = (val + 2)*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetGateGeneratorDelay: (%hu+2)*25=%d nsec\n", *qadc_gate_dly_addr, val)); #endif return (int) val; } /* 3.9 sets the width of the gate pulse. Timing resolution is 25 ns per count. The value set reflectts the number of clock cycles the pulse will be asserted for. Note that a setting of 0x0 will product no output (zero width pulse). The default setting for this register is 20 us (800 counts). */ int mpsSetGateGeneratorWidth(int module, int val) { unsigned short width; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } width = (unsigned short) (val/25); *qadc_gate_wid_addr = width; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetGateGeneratorWidth: %hu nsec", width)); #endif return OK; } int mpsGetGateGeneratorWidth(int module ) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ /* read width in counts */ val = *qadc_gate_wid_addr; /* convert from counts to ns */ val = val*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetGateGeneratorWidth: %hu nsec\n", val)); #endif return (int) val; } /* 3.10 delay latency 2 clock cycles */ int mpsSetSyncOutDelay(int module, int val) { unsigned short delay; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } /* convert ns to counts. 1 count = 25 ns */ delay = (unsigned short) (val/25); if (delay < 2) { delay = 0; } else { delay -= 2; } *qadc_sync_out_dly_addr = delay; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetSyncOutDelay: %d nsec -> %hu counts\n", val, delay)); #endif return OK; } int mpsGetSyncOutDelay(int module ) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ /* read delay */ val = *qadc_sync_out_dly_addr; /* convert counts to ns */ val = (val + 2)*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetSyncOutDelay: (%hu+2)*25: %d nsec\n", *qadc_sync_out_dly_addr, val)); #endif return (int) val; } /* 3.11 */ int mpsSetSyncOutWidth(int module, int val) { unsigned short width; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } width = (unsigned short) (val/25); *qadc_sync_out_wid_addr = width; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetSyncOutWidth: %d nsec -> %hu counts\n", val, width)); #endif return OK; } int mpsGetSyncOutWidth(int module ) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ /* read width */ val = *qadc_sync_out_wid_addr; val = val*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetSyncOutWidth: %hu*25=%hu nsec\n", *qadc_sync_out_wid_addr,val)); #endif return (int) val; } /* 3.12 */ int mpsSetGeneralPurposeIOControl(int module, int val) { unsigned short settings; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } settings = (unsigned short) val; *qadc_gpio_ctrl_addr = settings; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetGeneralPurposeIOControl: 0x%4x\n", (unsigned int) settings)); #endif return OK; } int mpsGetGeneralPurposeIOControl(int module ) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ /* read settings */ val = *qadc_gpio_ctrl_addr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetGeneralPurposeIOControl: 0x%04x\n", (unsigned int) val)); #endif return (int) val; } /* 3.13 delay latency 2 clock cycles */ int mpsSetGateADCDelay(int module, int val) { unsigned short delay; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } /* convert ns to counts. 1 count = 25 ns */ delay = (unsigned short) val/25; if (delay < 2) { delay = 0; } else { delay -= 2; } *qadc_gate_adc_dly_addr = delay; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetGateADCDelay: %d nsec -> %hu counts\n", val, delay)); #endif return OK; } int mpsGetGateADCDelay(int module) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_gate_adc_dly_addr; /* convert counts to ns */ val = (val + 2)*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetGateADCDelay: (%hu+2)*25=%d nsec\n", *qadc_gate_adc_dly_addr,val)); #endif return (int) val; } /* 3.14 delay latency of 1 clock cycle */ int mpsSetBeamToTestAcqDelay(int module, int val) { unsigned short delay; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } val = val/25; /* convert ns to counts. 1 count = 25 ns */ delay = (unsigned short) val; if (delay < 1) { delay = 0; } else { delay -= 1; } *qadc_beam2test_dly_addr = delay; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetBeamToTestAcqDelay: %d nsec -> %hu counts\n", val, delay)); #endif return OK; } int mpsGetBeamToTestAcqDelay(int module) { unsigned short val; int delay; mpsQADCReadout(module); /* INVASIVE */ /* read delay in counts */ val = *qadc_beam2test_dly_addr; /* convert counts to ns */ delay = (int) ((val+1)*25); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetBeamToTestAcqDelay: (%hu+1)*25=%d nsec\n", *qadc_beam2test_dly_addr,delay)); #endif return delay; } /* 3.15 delay latency of 1 clock cycle */ int mpsSetTestToBaseAcqDelay(int module, int val) { unsigned short delay; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetTestToBaseAcqDelay: got val %d nsec\n", val)); #endif val = val/25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetTestToBaseAcqDelay: val is now %d counts\n", val)); #endif /* convert ns to counts. 1 count = 25 ns */ delay = (unsigned short) val; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetTestToBaseAcqDelay: delay is now %d counts\n", delay)); #endif if (delay < 1) { delay = 0; } else { delay -= 1; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetTestToBaseAcqDelay: after adj intrinsic, delay is %d counts\n", delay)); #endif *qadc_test2base_dly_addr = delay; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetTestToBaseAcqDelay: %d nsec -> %hu counts\n", val, delay)); #endif return OK; } int mpsGetTestToBaseAcqDelay(int module) { unsigned short val; int delay; mpsQADCReadout(module); /* INVASIVE */ val = *qadc_test2base_dly_addr; /* convert counts to ns */ delay = (int) ((val+1)*25); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetTestToBaseAcqDelay: (%hu+1)*25=%d nsec\n", *qadc_test2base_dly_addr,delay)); #endif return delay; } /* 3.22 */ int mpsSetExtendedGateGeneratorDelay(int module, int val) { unsigned short delay; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } /* convert ns to counts. 1 count = 25 ns */ delay = (unsigned short) (val/25); if (delay < 2) { delay = 0; } else { delay -= 2; } *qadc_egate_dly_addr = delay; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetExtendedGateGeneratorDelay: %d nsec -> %hu counts\n", val, delay)); #endif return OK; } int mpsGetExtendedGateGeneratorDelay(int module ) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ /* read delay in counts */ val = *qadc_egate_dly_addr; /* convert counts to ns */ val = (val + 2)*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetExtendedGateGeneratorDelay: (%hu+2)*25=%d nsec\n", *qadc_egate_dly_addr, val)); #endif return (int) val; } /* 3.23 */ int mpsSetExtendedGateGeneratorWidthLow(int module, unsigned short val) { /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } *qadc_egate_width_l_addr = val; /* NOTE: no conversion here. Already done by mpsSetExtendedGateGeneratorWidth */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetExtendedGateGeneratorWidthLow: %hu\n", val)); #endif return OK; } unsigned short mpsGetExtendedGateGeneratorWidthLow(int module) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ /* read counter */ val = *qadc_egate_width_l_addr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetExtendedGateGeneratorWidthLow: %hu\n", val)); #endif /* NOTE: no conversion yet. Assemble into 4 bytes first */ return val; } /* 3.24 */ int mpsSetExtendedGateGeneratorWidthHigh(int module, unsigned short val) { /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } *qadc_egate_width_h_addr = val; /* NOTE: no conversion here. Already done by mpsSetExtendedGateGeneratorWidth */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetExtendedGateGeneratorWidthHigh: %hu\n", val)); #endif return OK; } unsigned short mpsGetExtendedGateGeneratorWidthHigh(int module ) { unsigned short val; mpsQADCReadout(module); /* INVASIVE */ /* read counter */ val = *qadc_egate_width_h_addr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetExtendedGateGeneratorWidthHigh: %hu\n", val)); #endif /* NOTE: no conversion yet. Assemble into 4 bytes first */ return val; } int mpsGetExtendedGateGeneratorWidth(int module) { int val; unsigned short high; unsigned short low; high = mpsGetExtendedGateGeneratorWidthHigh(module); low = mpsGetExtendedGateGeneratorWidthLow(module); val = (high<<16) | low; /* convert counts to ns */ val = val*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetExtendedGateGeneratorWidth: %d: (%hu<<16 + %hu)*25\n", val, high, low)); #endif return val; } int mpsSetExtendedGateGeneratorWidth(int module, int width) { unsigned short low; unsigned short high; unsigned long width_in_counts; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetExtendedGateGeneratorWidth: %d ns\n", width)); #endif /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } /* convert from ns to counts */ width_in_counts = (unsigned long) (width/25); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetExtendedGateGeneratorWidth: %d counts\n", (int) width_in_counts)); #endif low = (unsigned short) (width_in_counts & 0xFFFF); high = (unsigned short) ((width_in_counts & 0xFFFF0000) >> 16); mpsSetExtendedGateGeneratorWidthLow(module, low); /* 4.13.9 module doesn't HAVE to be passed in for write */ mpsSetExtendedGateGeneratorWidthHigh(module, high); /* 4.13.9 module doesn't HAVE to be passed in for write */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetExtendedGateGeneratorWidth: %lu separated into\n ", width_in_counts)); DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, (" high: %hu and low: %hu\n", high, low)); #endif return OK; } /* 3.25 10/14/09 This was missing. */ int mpsSetExtendedGateADCDelay(int module, int val) { unsigned short delay; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } /* convert ns to counts. 1 count = 25 ns */ delay = (unsigned short) (val/25); if (delay < 2) { delay = 0; } else { delay -= 2; } *qadc_egate_adc_dly_addr = delay; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetExtendedGateADCDeleay: %d nsec -> %hu counts\n", val, delay)); #endif return OK; } int mpsGetExtendedGateADCDelay(int module) { int val; val = *qadc_egate_adc_dly_addr; /* convert counts to ns */ val = (val + 2)*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetExtendedGateADCDelay: (%hu+2)*25=%d nsec\n", *qadc_egate_adc_dly_addr,val)); #endif return val; } /* 3.26 New for V4002 October, 2009 */ int mpsSetGatePEDADCDelay(int module, int val) { unsigned short delay; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } /* convert ns to counts. 1 count = 25 ns */ delay = (unsigned short) (val/25); if (delay < 3) { delay = 0; } else { delay -= 3; } *qadc_gate_ped_adc_dly_addr = delay; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetGatePEDADCDeleay: %d nsec -> %hu counts\n", val, delay)); #endif return OK; } int mpsGetGatePEDADCDelay(int module) { int val; val = *qadc_gate_ped_adc_dly_addr; /* convert counts to ns */ val = (val + 3)*25; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetExtendedGateADCDelay: (%hu+3)*25=%d nsec\n", *qadc_gate_ped_adc_dly_addr,val)); #endif return val; } /* 3.28 New for V4002 October, 2009 This is the heartbeat of the QADC FPGA */ int mpsGetAcquistionCounter() { unsigned int counter; counter = (*qadc_acq_cnt_h << 16 ) | *qadc_acq_cnt_l; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetAcquisitionCounter: %u (upper: %hu, lower: %hu)\n", counter,*qadc_acq_cnt_h, *qadc_acq_cnt_l)); #endif /* the rval that is retrieving this, is signed. This has the potential to return a number < 0 if HSB is on */ return (int) counter; } /* New for V4002 October, 2009 This is the heartbeat of the link node FPGA */ int mpsGetEventCounter() { unsigned int counter; counter = *event_counter_addr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetEventCounter: %u\n", counter)); #endif /* the rval that is retrieving this, is signed. This has the potential to return a number < 0 if HSB is on */ return (int) counter; } /**************************************************************************** End of Registers *****************************************************************************/ /* num indicates which CSR register: 1,2 or 3 */ int mpsSetQADCCSR(int module, int num, unsigned short val) { volatile unsigned short* addr; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (num) { case 1: addr = qadc_csr1_addr; break; case 2: addr = qadc_csr2_addr; break; case 3: addr = qadc_csr3_addr; break; default: return ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetQADCCSR: csr %d addr 0x%08x contains %hd\n", num, (unsigned int) addr, val)); #endif *addr = val; return OK; } /* num indicates which CSR register: 1,2 or 3 */ int mpsGetQADCCSR(int module, int num) { volatile unsigned short* addr; mpsQADCReadout(module); switch (num) { case 1: addr = qadc_csr1_addr; break; case 2: addr = qadc_csr2_addr; break; case 3: addr = qadc_csr3_addr; break; default: return 0; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsGetQADCCSR: csr %d addr 0x%08x contains %hd\n", num, (unsigned int) addr, *addr)); #endif return (int) *addr; } /* used by BLM to configure fiducial */ /* value is entered in nanoseconds. 1 tick = 8.4 nanoseconds convert to ticks and write into register */ int mpsSetFiducialDelay(unsigned long delay) { *fiducial_delay = ((unsigned long) (delay/8.4)) & 0xFFFFF; /* limit to bits 0-19 */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsFiducialFlag, ("mpsSetFiducialDelay: %lu ns -> %lu ticks\n", delay, *fiducial_delay)); #endif return OK; } int mpsGetFiducialDelay() { unsigned long delay; int val; delay = (*fiducial_delay & 0xFFFFF); /* limit to bits 0-19 */ val = delay * 8.4; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsFiducialFlag, ("mpsGetFiducialDelay: %lu ticks -> %d ns\n", delay, val)); #endif return val; } /* value is entered in nanoseconds. 1 tick = 8.4 nanoseconds convert to ticks and write into register */ int mpsSetFiducialWidth(unsigned long width) { *fiducial_width = ((unsigned long) (width/8.4)) & 0xFFFFF; /* limit to bits 0-19 */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsFiducialFlag, ("mpsSetFiducialWidth: %lu ns -> %lu ticks\n", width, *fiducial_width)); #endif return OK; } int mpsGetFiducialWidth() { unsigned long width; int val; width = (*fiducial_width & 0xFFFFF); /* limit to bits 0-19 */ val = width * 8.4; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsFiducialFlag, ("mpsGetFiducialWidth: %lu ticks -> %d ns\n", width, val)); #endif return val; } /* value is entered in counts. write into register */ int mpsSetFiducialDCMPhase(unsigned long dcm_phase) { *fiducial_dcm_phase = dcm_phase & 0xFFFF; /* limit to bits 0-15 */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsFiducialFlag, ("mpsSetFiducialDCMPhase: %lu ns -> %lu ticks\n", dcm_phase, *fiducial_dcm_phase)); #endif return OK; } int mpsGetFiducialDCMPhase() { unsigned long dcm_phase; int val; dcm_phase = (*fiducial_dcm_phase & 0xFFFF); /* limit to bits 0-15 */ val = (int) dcm_phase; /*NO CONVERSION HERE */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsFiducialFlag, ("mpsGetFiducialDCMPhase: %d ticks\n", val)); #endif return val; } /* 10/16/09 No Sync Read needed for thresholds */ int mpsGetQADCBaseThresholdUpperRegister(int module, int channel, int type) { volatile unsigned short* pUpper; unsigned int addrUpper; unsigned short val; /* passed in arg "module" is not used */ if (type == MPS_THLD_HIGH) { addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x30; } else { if (type == MPS_THLD_LOW) { addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x2E; } } pUpper = (volatile unsigned short*) addrUpper; val = *pUpper; return (int) val; } /* 10/16/09 No Sync Read needed for thresholds */ int mpsGetQADCBaseThresholdLowerRegister(int module, int channel, int type) { volatile unsigned short* pLower; unsigned int addrLower; unsigned short val; /* passed in arg "module" is not used */ if (type == MPS_THLD_HIGH) { addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x24; } else { if (type == MPS_THLD_LOW) { addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x22; } } pLower = (volatile unsigned short*) addrLower; val = *pLower; return (int) val; } /* 10/16/09 No Sync Read needed for thresholds */ int mpsGetQADCTestThresholdUpperRegister(int module, int channel, int type) { volatile unsigned short* pUpper; unsigned int addrUpper; unsigned short val; /* passed in arg "module" is not used */ if (type == MPS_THLD_HIGH) { addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x2C; } else { if (type == MPS_THLD_LOW) { addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x2A; } } pUpper = (volatile unsigned short*) addrUpper; val = *pUpper; return (int) val; } /* 10/16/09 No Sync Read needed for thresholds */ int mpsGetQADCTestThresholdLowerRegister(int module, int channel, int type) { volatile unsigned short* pLower; unsigned int addrLower; unsigned short val; /* passed in arg "module" is not used */ if (type == MPS_THLD_HIGH) { addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x20; } else { if (type == MPS_THLD_LOW) { addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x1E; } } pLower = (volatile unsigned short*) addrLower; val = *pLower; return (int) val; } /* 10/16/09 No Sync Read needed for thresholds */ int mpsGetQADCBeamThresholdUpperRegister(int module, int channel, int type) { volatile unsigned short* pUpper; unsigned int addrUpper; unsigned short val; /* passed in arg "module" is not used */ if (type == MPS_THLD_HIGH) { addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x28; } else { if (type == MPS_THLD_LOW) { addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x26; } } pUpper = (volatile unsigned short*) addrUpper; val = *pUpper; return (int) val; } /* 10/16/09 No Sync Read needed for thresholds */ int mpsGetQADCBeamThresholdLowerRegister(int module, int channel, int type) { volatile unsigned short* pLower; unsigned int addrLower; unsigned short val; /* passed in arg "module" is not used */ if (type == MPS_THLD_HIGH) { addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x1C; } else { if (type == MPS_THLD_LOW) { addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x1A; } } pLower = (volatile unsigned short*) addrLower; val = *pLower; return (int) val; } /* threshold is signed. 16-bit */ /* 4/13/9 add module, not because PIC uses this, but to keep consistent with mpsSetQADCBeamThreshold */ /* 7/6/9 now threshold is 32-bit, with upper word and lower words in non-adjacent registers */ int mpsSetQADCBaseThreshold(int module, int channel, int type, long threshold) { volatile unsigned short* pLower; volatile unsigned short* pUpper; unsigned int addrLower; unsigned int addrUpper; /* Hold the two halves of the threshold */ unsigned short threshLower = threshold & 0xFFFF; short threshUpper = (threshold>>16) & 0xFFFF; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } if (type == MPS_THLD_HIGH) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetQADCBaseThresholdFlag, ("mpsSetQADCBaseThreshold: channel: %d setting high threshold to: %ld\n", channel, threshold)); #endif addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x24; pLower = (volatile unsigned short*) addrLower; addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x30; pUpper = (volatile unsigned short*) addrUpper; if (pNode->linknodetype == MPS_BLM_MODE) { pNode->blmChannels[channel].basehighthreshold = threshold; } } else { if (type == MPS_THLD_LOW) { addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x22; pLower = (volatile unsigned short *) addrLower; addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x2E; pUpper = (volatile unsigned short *) addrUpper; if (pNode->linknodetype == MPS_BLM_MODE) { pNode->blmChannels[channel].baselowthreshold = threshold; } } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetQADCBaseThresholdFlag, ("mpsSetQADCBaseThreshold: invalid threshold type: %d\n", type)); #endif return ERROR; } } *pLower = threshLower; *pUpper = threshUpper; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetQADCBaseThresholdFlag, ("mpsSetQADCBaseThreshold: channel: %d addr: 0x%08x gets: %hd;\n", channel, (unsigned int) addrUpper, threshUpper)); DEBUGPRINT(DP_INFO, drvMpsSetQADCBaseThresholdFlag, ("mpsSetQADCBaseThreshold: channel: %d addr: 0x%08x gets: %hd;\n", channel, (unsigned int) addrLower, threshLower)); #endif return OK; } /* threshold is signed. 16-bit */ /* 4/13/9 add module, not because PIC uses this, but to keep consistent with mpsSetQADCBeamThreshold */ int mpsSetQADCTestThreshold(int module, int channel, int type, long threshold) { volatile unsigned short* pLower; volatile unsigned short* pUpper; unsigned int addrLower; unsigned int addrUpper; /* Hold the two halves of the threshold */ unsigned short threshLower = threshold & 0xFFFF; unsigned short threshUpper = (threshold>>16) & 0xFFFF; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } if (type == MPS_THLD_HIGH) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetQADCTestThresholdFlag, ("mpsSetQADCTestThreshold: channel: %d setting high threshold to: %ld\n", channel, threshold)); #endif addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x20; pLower = (volatile unsigned short*) addrLower; addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x2C; pUpper = (volatile unsigned short*) addrUpper; if (pNode->linknodetype == MPS_BLM_MODE) { pNode->blmChannels[channel].testhighthreshold = threshold; } } else { if (type == MPS_THLD_LOW) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetQADCTestThresholdFlag, ("mpsSetQADCTestThreshold: channel: %d setting low threshold to: %ld\n", channel, threshold)); #endif addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x1E; pLower = (volatile unsigned short *) addrLower; addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x2A; pUpper = (volatile unsigned short *) addrUpper; if (pNode->linknodetype == MPS_BLM_MODE) { pNode->blmChannels[channel].testlowthreshold = threshold; } } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetQADCTestThresholdFlag, ("mpsSetQADCTestThreshold: invalid threshold type: %d\n", type)); #endif return ERROR; } } *pLower = threshLower; *pUpper = threshUpper; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetQADCTestThresholdFlag, ("mpsSetQADCTestThreshold: channel: %d addr: 0x%08x gets: %hd;\n", channel, (unsigned int) addrUpper, threshUpper)); DEBUGPRINT(DP_INFO, drvMpsSetQADCTestThresholdFlag, ("mpsSetQADCTestThreshold: channel: %d addr: 0x%08x gets: %hd;\n", channel, (unsigned int) addrLower, threshLower)); #endif return OK; } /* 4/13/9 add module to accommodate PIC */ int mpsSetQADCBeamThreshold(int module, int channel, int type, long threshold) { volatile unsigned short* pLower; volatile unsigned short* pUpper; unsigned int addrLower; unsigned int addrUpper; /* Hold the two halves of the threshold */ unsigned short threshLower = threshold & 0xFFFF; unsigned short threshUpper = (threshold>>16) & 0xFFFF; /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } if (type == MPS_THLD_HIGH) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetQADCBeamThresholdFlag, ("mpsSetQADCBeamThreshold: channel: %d setting high threshold to: %ld\n", channel, threshold)); #endif addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x1C; pLower = (volatile unsigned short*) addrLower; addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x28; pUpper = (volatile unsigned short*) addrUpper; if (pNode->linknodetype == MPS_BLM_MODE) { pNode->blmChannels[channel].beamhighthreshold = threshold; } } else { if (type == MPS_THLD_LOW) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetQADCBeamThresholdFlag, ("mpsSetQADCBeamThreshold: channel: %d setting low threshold to: %ld\n", channel, threshold)); #endif addrLower = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x1A; pLower = (volatile unsigned short *) addrLower; addrUpper = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x26; pUpper = (volatile unsigned short *) addrUpper; if (pNode->linknodetype == MPS_BLM_MODE) { pNode->blmChannels[channel].beamlowthreshold = threshold; } } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetQADCBeamThresholdFlag, ("mpsSetQADCBeamThreshold: invalid threshold type: %d\n", type)); #endif return ERROR; } } *pLower = threshLower; *pUpper = threshUpper; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetQADCBeamThresholdFlag, ("mpsSetQADCBeamThreshold: channel: %d addr: 0x%08x gets: %hd;\n", channel, (unsigned int) addrUpper, threshUpper)); DEBUGPRINT(DP_INFO, drvMpsSetQADCBeamThresholdFlag, ("mpsSetQADCBeamThreshold: channel: %d addr: 0x%08x gets: %hd;\n", channel, (unsigned int) addrLower, threshLower)); #endif return OK; } /* 10/16/09 Sync Read needed for doses */ unsigned short mpsGetQADCBeamDose(int module, int channel, int time, int bytes) { unsigned short dose; volatile unsigned short* dose_base_addr = (volatile unsigned short* ) (BLM_QADC_DOSE_MEMORY_BASE + (channel * 0x100)); /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } switch (time) { case -1: /* baseline */ dose = *dose_base_addr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsGetQADCBeamDoseFlag, ("mpsGetQADCBeamDose: channel: %d at addr: %0x08x baseline: 0x%08x\n", channel, (unsigned int) dose_base_addr, (unsigned int) dose)); #endif break; case 0: /* current beam dose */ dose = *(dose_base_addr + 1 /*0x2*/); break; case 1: /* accumulated 1 second dosage data */ switch (bytes) { case MPS_BYTES_LOW: dose = *(dose_base_addr + 2 /*0x4*/); break; case MPS_BYTES_HIGH: dose = *(dose_base_addr + 3 /*0x6*/); break; } break; case 10: /* accumulated 1/10 second dosage data */ switch (bytes) { case MPS_BYTES_LOW: dose = *(dose_base_addr + 4 /*0x8*/); break; case MPS_BYTES_HIGH: dose = *(dose_base_addr + 5 /*0xA*/); break; } break; case 30: /* accumulated 1/30 second dosage data */ switch (bytes) { case MPS_BYTES_LOW: dose = *(dose_base_addr + 6 /*0xC*/); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetQADCBeamDoseFlag, ("mpsGetQADCBeamDose: ch: %d at addr: 0x%08x 1/30s, low bytes: 0x%08x\n", channel, (unsigned int) (dose_base_addr + 6 /*0xC*/), (unsigned int) dose)); #endif break; case MPS_BYTES_HIGH: dose = *(dose_base_addr + 7 /*0xE*/); break; } break; case 60: /* accumulated 1/60 second dosage data */ switch (bytes) { case MPS_BYTES_LOW: dose = *(dose_base_addr + 8 /*0x10*/); break; case MPS_BYTES_HIGH: dose = *(dose_base_addr + 9 /*0x12*/ ); break; } break; default: /* complain */ return 0; } /* report */ return dose; } /* 10/16/09 Sync Read needed for doses */ unsigned short mpsGetQADCTestDose(int channel, int time, int bytes) { unsigned short dose; volatile unsigned short* base_addr = (volatile unsigned short*) (BLM_QADC_DOSE_MEMORY_BASE + (channel * 0x100)); switch (time) { case 0: /* current beam dose */ dose = *(base_addr + 10 /*0x14*/); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetQADCTestDoseFlag, ("mpsGetQADCTestDose: channel: %d current: 0x%08x\n", channel, (unsigned int) dose)); #endif break; case 1: /* accumulated 1 second dosage data */ switch (bytes) { case MPS_BYTES_LOW: dose = *(base_addr + 11 /*0x16*/); break; case MPS_BYTES_HIGH: dose = *(base_addr + 12 /*0x18*/); break; } break; default: /* complain */ return 0; } /* report */ return dose; } /* 10/16/09: sign extension no longer needed w FPGA V4002 */ long assembleTwoByteDose(unsigned short low) { long dose; dose = (long) low; #ifdef SIGN_EXTENSION_NEEDED if ((dose & 0x8000) == 0x8000) { /* if bit 15 on: 10000000 */ /* extend signed bit to set all bits above the sign bit, which is already on. 11111111 00000000 */ dose = dose | 0xFFFF0000; } #endif #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsAssembleDoseFlag, ("assembleDose: 0x%8x\n", (unsigned int) dose)); #endif return dose; } /* 10/16/09: sign extension no longer needed w FPGA V4002 */ long assembleDose(unsigned short low, unsigned short high) { long dose; #ifdef SIGN_EXTENSION_NEEDED if ((high & 0x200) == 0x200) { /* if bit 25 on: 00000010 00000000*/ /* extend signed bit to set all bits above the sign bit, which is already on. 11111100 00000000 */ high = high | 0xFC00; } #endif dose = (long) ((high << 16) | low); #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsAssembleDoseFlag, ("assembleDose: parts: 0x%4x%4x assembled: 0x%8x\n", (unsigned int) high, (unsigned int) low, (unsigned int) dose)); #endif return dose; } /* 4/13/9 Add module arg to accommodate PIC */ /* 4/15/9 PICs using new routine mpsGetBeamDoseFromMem instead of this */ long mpsAssembleBeamDose(int module, int channel, int time) { long dose; unsigned short low; unsigned short high; switch (time) { case -1: /* "baseline" -> "Beam pedestal" 10/19/09 */ /* Not used by PIC, so doesn't need module */ low = mpsGetQADCBeamDose(module, channel, -1, MPS_BYTES_LOW); dose = assembleTwoByteDose(low); #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsAssembleDoseFlag, ("mpsAssembleBeamDose: channel: %d baseline: 0x%08x\n", channel, (unsigned int) dose)); #endif break; case 0: /* current beam dose */ low = mpsGetQADCBeamDose(module, channel, 0, MPS_BYTES_LOW); /* 4/15/9 add module for PIC */ dose = assembleTwoByteDose(low); break; case 1: /* accumulated 1 second dosage data */ low = mpsGetQADCBeamDose(module, channel, 1, MPS_BYTES_LOW); /* 4/15/9 add module for PIC */ high = mpsGetQADCBeamDose(module, channel, 1, MPS_BYTES_HIGH); /* 4/15/9 add module for PIC */ dose = assembleDose(low,high); /* if (channel == 0) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsLinkNodeDoseFlag, ("mpsAssembleBeamDose: high %hd low %hd. dose %ld\n", high, low, dose)); #endif } */ break; case 10: /* accumulated 1/10 second dosage data */ low = mpsGetQADCBeamDose(module, channel, 10, MPS_BYTES_LOW); /* 4/15/9 add module for PIC */ high = mpsGetQADCBeamDose(module, channel, 10, MPS_BYTES_HIGH); /* 4/15/9 add module for PIC */ dose = assembleDose(low,high); break; case 30: /* accumulated 1/30 second dosage data */ low = mpsGetQADCBeamDose(module, channel, 30, MPS_BYTES_LOW); /* 4/15/9 add module for PIC */ high = mpsGetQADCBeamDose(module, channel, 30, MPS_BYTES_HIGH); /* 4/15/9 add module for PIC */ dose = assembleDose(low,high); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsAssembleDoseFlag, ("mpsAssembleBeamDose: channel: %d 1/30 sec: 0x%08x\n", channel, (unsigned int) dose)); #endif break; case 60: /* accumulated 1/60 second dosage data */ low = mpsGetQADCBeamDose(module, channel, 60, MPS_BYTES_LOW); /* 4/15/9 add module for PIC */ high = mpsGetQADCBeamDose(module, channel, 60, MPS_BYTES_HIGH); /* 4/15/9 add module for PIC */ dose = assembleDose(low,high); break; default: /* complain */ return 0; } /* report */ return dose; } /* 4/15/9 PICs using this new routine instead of mpsAssembleBeamDose */ long mpsGetBeamDoseFromMem(int module, int channel, int time) { long dose; switch (time) { case -1: /* baseline */ /* Not used by PIC, so doesn't need module */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetBeamDoseFromMemFlag, ("mpsGetBeamDoseFromMem: module: %d channel: %d baseline is invalid for PIC\n", module, channel)); #endif break; case 0: /* current beam dose */ dose = pNode->pics[module].picchannels[channel].loss_now; break; case 1: /* accumulated 1 second dosage data */ dose = pNode->pics[module].picchannels[channel].loss_1; break; case 10: /* accumulated 1/10 second dosage data */ dose = pNode->pics[module].picchannels[channel].loss_10; break; case 30: /* accumulated 1/30 second dosage data */ dose = pNode->pics[module].picchannels[channel].loss_30; break; case 60: /* accumulated 1/60 second dosage data */ dose = pNode->pics[module].picchannels[channel].loss_60; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetBeamDoseFromMemFlag, ("mpsGetBeamDoseFromMem: module: %d channel: %d unrecognised time\n", module, channel)); #endif return 0; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetBeamDoseFromMemFlag, ("mpsAssembleBeamDose: module: %d channel: %d time: %d dose is %ld\n", module, channel, time, dose)); #endif return dose; } long mpsAssembleTestDose(int channel, int time) { long dose; short low; short high; switch (time) { case 0: /* current beam dose */ low = mpsGetQADCTestDose(channel, 0, MPS_BYTES_LOW); dose = assembleTwoByteDose(low); break; case 1: /* accumulated 1 second dosage data */ low = mpsGetQADCTestDose(channel, 1, MPS_BYTES_LOW); high = mpsGetQADCTestDose(channel, 1, MPS_BYTES_HIGH); dose = assembleDose(low,high); break; default: /* complain */ return 0; } /* report */ return dose; } /* 4/13/9 add module to accommodate PIC */ short mpsGetADCDiagnostic(int module, int offset) { short val; volatile short* base_addr = (volatile short*) (BLM_ADC_MEMORY_BASE + offset); /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } val = *base_addr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetADCDiagnosticFlag, ("mpsGetADC: add decimal offset: %d to base to get addr: 0x%08x, val is: %hd\n", offset, (unsigned int) base_addr, val)); #endif return val; } double processed_waveform[1000]; /* raw waveform scaled by slope and adjusted by offset for GUI display */ /* helper routine. remove if find math function for coldfire for modulus */ int modulus(int dividend, int divisor) { int rem = dividend; while (rem >= divisor) { rem -= divisor; } return rem; } mpsNode_t* mpsGetNode() { return pNode; } /****************************************************************************** Used by generic startup cmd file to determine which link node database to load Link Node ID is in bits 08-15 of the register "version" *****************************************************************************/ int mpsReadLinkNodeIDRotary() { int linknodeid; linknodeid = (int) ((*version >> 8) & 0xff ); printf("reading link ID from rotary switch setting: 0x%0x\n", linknodeid); return linknodeid; } int mpsGetLinkNodeID() { /* ensure mpsInitialise is done first */ return pNode->linknodeid; } /* Should not be used. A way to override rotary switch setting */ int mpsSetLinkNodeID(int linknodeid) { pNode->linknodeid = linknodeid; return OK; } char* mpsGetLinkNodePRIM() { char *prim; /* TO DO. check mpsIntialised to ensure mpsInitialise is done first */ prim = primaries[pNode->linknodeid]; printf("MPS Link Node PRIM is %s\n", prim); return prim; } char* mpsGetLinkNodeLOCA() { char *loca; /* TO DO. check mpsIntialised to ensure mpsInitialise is done first */ loca = LOCATIONS[pNode->linknodeid]; printf("MPS Link Node LOCA is %s\n", loca); return loca; } char* mpsGetLinkNodeloca() { char *loca; /* TO DO. check mpsIntialised to ensure mpsInitialise is done first */ loca = locations[pNode->linknodeid]; printf("MPS Link Node loca is %s\n", loca); return loca; } char* mpsGetLinkNodeUNIT() { char *unit; /* TO DO. check mpsIntialised to ensure mpsInitialise is done first */ unit = UNITS[pNode->linknodeid]; printf("MPS Link Node UNIT is %s\n", unit); return unit; } char* mpsGetLinkNodeunit() { char *unit; /* TO DO. check mpsIntialised to ensure mpsInitialise is done first */ unit = units[pNode->linknodeid]; printf("MPS Link Node UNIT is %s\n", unit); return unit; } /* 3/13/9 dropped. redund with iocManager int mpsSetRackLocation(char* rack) { strcpy(pNode->rackLocation,rack); return OK; } char* mpsGetRackLocation() { return pNode->rackLocation; } */ int mpsSetRackLocked(int locked) { pNode->rackLocked = locked; return OK; } int mpsGetRackLocked() { return pNode->rackLocked; } /* input arg is pathname (absolute or relative to pwd at boot + filename */ int mpsReadDatabaseVersion(char* current) { FILE *fp; char temp[MPS_LINE_LENGTH]; int indexOfLastChar; int databaseVersionLength; /* get the one line contents into the version */ fp = fopen(current, "r"); /* TODO check fp ok */ fgets(temp, MPS_LINE_LENGTH, fp); printf("mpsReadDatabaseVersion: contents of 'current': '%s'\n", temp); indexOfLastChar = strlen(temp); while (temp[indexOfLastChar]<32) { /* ASCII printing chars begin at decimal 32 */ /*printf("taking off last char '%c'\n", temp[indexOfLastChar]); */ indexOfLastChar--; /*printf("length is now %d chars long\n", indexOfLastChar); */ } databaseVersionLength = indexOfLastChar + 1; strncpy(pNode->databaseVersion, temp, databaseVersionLength); /*printf("temp is '%s'\n", temp); */ printf("mpsReadDatabaseVersion: databaseFile is '%s'\n", pNode->databaseVersion); fclose(fp); return OK; } char* mpsGetDatabaseVersion() { return pNode->databaseVersion; } /* Called by mpsInitialise */ int mpsReadFPGAVersion() { pNode->fpgaVersion = (*version & 0xff); printf("mpsReadFPGAVersion: 0x%08x\n", (unsigned int) (pNode->fpgaVersion)); return OK; } /* Called by Stringin PV that holds FPGA Version */ int mpsGetFPGAVersion() { /* TO DO: compare against contents of register? */ return pNode->fpgaVersion; } int mpsGetBYKOverThresholdFault() { unsigned long reg; int fault; reg = *virtual_input_card_sts >> 6; fault = (int) (reg & 1); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsBYKFaultFlag, ("mpsGetBYKOverThresholdFault: register: 0x%x bit 6: %d\n", (unsigned int) reg, fault)); #endif return fault; } int mpsGetBYKUnderThresholdFault() { unsigned long reg; int fault; reg = *virtual_input_card_sts >> 5; fault = (int) (reg & 1); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsBYKFaultFlag, ("mpsGetBYKUnderThresholdFault: register: 0x%x bit 5: %d\n", (unsigned int) reg, fault)); #endif return fault; } int mpsGetBXKickLatch() { unsigned long reg; int fault; reg = *virtual_input_card_sts >> 4; fault = (int) (reg & 1); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsBYKFaultFlag, ("mpsGetBXKickLatch: register: 0x%x bit 4: %d\n", (unsigned int) reg, fault)); #endif return fault; } int mpsGet30HzStdbyTriggerMissed() { unsigned long reg; int fault; reg = *virtual_input_card_sts >> 3; fault = (int) (reg & 1); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsBYKFaultFlag, ("mpsGet30HzStdbyTriggerMissed: register: 0x%x bit 3: %d\n", (unsigned int) reg, fault)); #endif return fault; } int mpsGet30HzAbortTriggerMissed() { unsigned long reg; int fault; reg = *virtual_input_card_sts >> 2; fault = (int) (reg & 1); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsBYKFaultFlag, ("mpsGet30HzAbortTriggerMissed: register: 0x%x bit 2: %d\n", (unsigned int) reg, fault)); #endif return fault; } int mpsGet120HzStdbyTriggerMissed() { unsigned long reg; int fault; reg = *virtual_input_card_sts >> 1; fault = (int) (reg & 1); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsBYKFaultFlag, ("mpsGet120HzStdbyTriggerMissed: register: 0x%x bit 1: %d\n", (unsigned int) reg, fault)); #endif return fault; } int mpsGet120HzAbortTriggerMissed() { unsigned long reg; int fault; reg = *virtual_input_card_sts; fault = (int) reg & 1; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsBYKFaultFlag, ("mpsGet120HzAbortTriggerMissed: register: 0x%x bit 0: %d\n", (unsigned int) reg, fault)); #endif return fault; } /* Bit 9 is IP_TO, the IP Inteface Timeout waiting for ACK. Write it a 1 to clear */ int mpsClrIPTimeout() { unsigned long mask = 0; mask = (1 << 9); *link_node_control |= mask; return OK; } /* Bit 8 is BLM_TO, the BLM Timeout waiting for ADCs. Write it a 1 to clear */ int mpsClrBLMTimeout() { unsigned long mask = 0; mask = (1 << 8); *link_node_control |= mask; return OK; } /* INVASIVE. Diagnostic only. For testing setting of registers */ int mpsQADCReadout(int module) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCReadoutFlag, ("mpsQADCReadout: top\n")); #endif /* Handle multiple PIC modules, if necessary */ if (pNode->linknodetype == MPS_PIC_MODE) { /* Extra step to access PIC: set module number in reg #49 */ *pic_select = module; } *link_node_control |= 8; /* it takes 20 ms to read out the FPGA @ 8 MHz. the coldfire reads 16 bits at 16 MHz, so hang back a bit */ sleep(0.02); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCReadoutFlag, ("mpsQADCReadout: done\n")); #endif return OK; } int mpsGetQADCReadoutStatus() { unsigned long status; status = (*link_node_control >> 3) & 1; return (int) status; } /* 10/16/09 IN PROGRESS: - mpsInitialise starts new task (or maybe st.cmd does, after iocInit) New task: - every second, request the read (set 4th bit of *link_node_control) - check for 4th bit to be cleared (how?) for when it's done - take a sem and put data into mem - is copy ok for BYK waveform? - give the sem - repeat to top Changes to other routines: - PVs for IP Memory space: QADC doses (0x5n00-5n19), ADC AD41 BYKIK waveform (0x0-7FF), for IP IO space: ADC IP330 ADC Data(0x40-5E), QADC Channel Faults (0x20-46) for Latched BLM Faults (0x1900-1920) no longer access mem, just read from the copy - PV Get routines take a semaphore and give it when done one value and half of the next one. */ /* 10/13/09. Not invasive. New technique (per FPGA V4) is to set the 4th bit and wait for it to be cleared. This is the indicator that it has updated the registers Only call this by one invoker. Give this job to a thread and give a semaphore to interested readers. */ int mpsSyncReadRequest(void* arg) { int num_iters = 0; int num_tries = 0; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSyncReadRequestFlag, ("mpsSyncReadRequest: top\n")); #endif while (1) { num_iters++; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSyncReadRequestFlag, ("mpsSyncReadRequest: %d\n", num_iters)); #endif sleep(1); /* Need to tune this. Maybe too short to copy BYK waveform et al Maybe ok for BLM */ if (mpsGetSyncReadStatus()) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSyncReadRequestFlag, ("mpsSyncReadRequest: bit already set. sleep and try again\n")); #endif continue; } /* request the sync read by setting the fourth bit */ *link_node_control |= 16; /* it takes 20 ms to read out the FPGA @ 8 MHz; the coldfire reads 16 bits at 16 MHz. Wait until clear... */ while (mpsGetSyncReadStatus()) { /* sleep first, since sleeping after always causes one retry */ sleep(0.02); num_tries++; #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSyncReadRequestFlag, ("mpsSyncReadRequest: bit still set. %d attempt(s). sleep and try again\n", num_tries)); #endif /* TO DO: may want to set alarm if num_tries gets big */ } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSyncReadRequestFlag, ("mpsSyncReadRequest: new data ready\n")); #endif num_tries = 0; /* 10/16/09 new */ /* Copy new data into node struct... */ /* It matters what type of node you have. */ if (pNode->linknodetype == MPS_BLM_MODE) { /* Copy fields that require sync read to get their values into pNode */ pNode->blmChannels[0].beampedestal = *(short*)(BLM_ADC_MEMORY_BASE + 48); pNode->blmChannels[1].beampedestal = *(short*)(BLM_ADC_MEMORY_BASE + 50); pNode->blmChannels[2].beampedestal = *(short*)(BLM_ADC_MEMORY_BASE + 52); pNode->blmChannels[3].beampedestal = *(short*)(BLM_ADC_MEMORY_BASE + 54); pNode->beamped3d3 = *(short*)(BLM_ADC_MEMORY_BASE + 56); pNode->beamped2d5 = *(short*)(BLM_ADC_MEMORY_BASE + 58); pNode->blmChannels[4].beampedestal = *(short*)(BLM_ADC_MEMORY_BASE + 60); pNode->blmChannels[5].beampedestal = *(short*)(BLM_ADC_MEMORY_BASE + 62); pNode->blmChannels[6].beampedestal = *(short*)(BLM_ADC_MEMORY_BASE + 64); pNode->blmChannels[7].beampedestal = *(short*)(BLM_ADC_MEMORY_BASE + 66); pNode->beamped1d2 = *(short*)(BLM_ADC_MEMORY_BASE + 68); pNode->beampedgnd = *(short*)(BLM_ADC_MEMORY_BASE + 70); } epicsEventSignal(data_ready); /* 10/20/09 there is only one source of signal and many "waiters" for it. If each "waiter" also "signals" this could get messed up (?). Better to use different event sems and always have 1:1 ratio? */ if (num_signals < MPS_MAX_INT ) { num_signals++; } else { num_signals = 0; } } return OK; } int mpsGetBeamPedestal(int channel) { #ifdef WAIT_FOR_DATA_READY epicsEventWaitStatus waitStatus; waitStatus = epicsEventWait(data_ready); if (waitStatus == epicsEventWaitOK) { if (num_wait_beam_pedestal < MPS_MAX_INT ) { num_wait_beam_pedestal++; } else { num_wait_beam_pedestal = 0; } #endif return (int) (pNode->blmChannels[channel].beampedestal); #ifdef WAIT_FOR_DATA_READY } else { if (waitStatus == epicsEventWaitTimeout) { return OK; /* don't return a negative number */ } else { if (waitStatus == epicsEventWaitError) { return OK; /* don't return a negative number */ } } } return OK; /* don't return a negative number */ #endif } int mpsGetBeamPed3d3() { #ifdef WAIT_FOR_DATA_READY epicsEventWaitStatus waitStatus; waitStatus = epicsEventWait(data_ready); if (waitStatus == epicsEventWaitOK) { if (num_wait_beam_ped_3d3 < MPS_MAX_INT ) { num_wait_beam_ped_3d3++; } else { num_wait_beam_ped_3d3 = 0; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSyncReadRequestFlag, ("mpsGetBeamPed3d3: got new data\n")); #endif #endif return (int) (pNode->beamped3d3); #ifdef WAIT_FOR_DATA_READY } else { if (waitStatus == epicsEventWaitTimeout) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSyncReadRequestFlag, ("mpsGetBeamPed3d3: timeout\n")); #endif return OK; /* don't return a negative number */ } else { if (waitStatus == epicsEventWaitError) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSyncReadRequestFlag, ("mpsGetBeamPed3d3: error\n")); #endif return OK; /* don't return a negative number */ } } } return OK; /* don't return a negative number */ #endif } int mpsGetBeamPed2d5() { #ifdef WAIT_FOR_DATA_READY epicsEventWaitStatus waitStatus; waitStatus = epicsEventWait(data_ready); if (waitStatus == epicsEventWaitOK) { if (num_wait_beam_ped_2d5 < MPS_MAX_INT ) { num_wait_beam_ped_2d5++; } else { num_wait_beam_ped_2d5 = 0; } #endif return (int) (pNode->beamped2d5); #ifdef WAIT_FOR_DATA_READY } else { if (waitStatus == epicsEventWaitTimeout) { return OK; /* don't return a negative number */ } else { if (waitStatus == epicsEventWaitError) { return OK; /* don't return a negative number */ } } } return OK; /* don't return a negative number */ #endif } int mpsGetBeamPed1d2() { #ifdef WAIT_FOR_DATA_READY epicsEventWaitStatus waitStatus; waitStatus = epicsEventWait(data_ready); if (waitStatus == epicsEventWaitOK) { if (num_wait_beam_ped_1d2 < MPS_MAX_INT ) { num_wait_beam_ped_1d2++; } else { num_wait_beam_ped_1d2 = 0; } #endif return (int) (pNode->beamped1d2); #ifdef WAIT_FOR_DATA_READY } else { if (waitStatus == epicsEventWaitTimeout) { return OK; /* don't return a negative number */ } else { if (waitStatus == epicsEventWaitError) { return OK; /* don't return a negative number */ } } } return OK; /* don't return a negative number */ #endif } int mpsGetBeamPedGnd() { #ifdef WAIT_FOR_DATA_READY epicsEventWaitStatus waitStatus; waitStatus = epicsEventWait(data_ready); if (waitStatus == epicsEventWaitOK) { if (num_wait_beam_ped_gnd < MPS_MAX_INT ) { num_wait_beam_ped_gnd++; } else { num_wait_beam_ped_gnd = 0; } #endif return (int) (pNode->beampedgnd); #ifdef WAIT_FOR_DATA_READY } else { if (waitStatus == epicsEventWaitTimeout) { return OK; /* don't return a negative number */ } else { if (waitStatus == epicsEventWaitError) { return OK; /* don't return a negative number */ } } } return OK; /* don't return a negative number */ #endif } int mpsGetSyncReadStatus() { unsigned long status; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSyncReadStatusFlag, ("mpsGetSyncReadStatus: reg contains0x%x\n", (unsigned int) *link_node_control)); #endif status = (*link_node_control >> 4) & 1; return (int) status; } int mpsClrBLMThresholdFaultStatus() { unsigned long mask = 0; mask = (1 << 2); *link_node_control |= mask; return OK; } int mpsGetBLMAcqStartStatus() { unsigned long status; status = (*link_node_control >> 1) & 1; return (int) status; } int mpsGetBLMInitStatus () { int status; status = *link_node_control &= 1; return status; } int mpsSetLinkNodeType(int mode) { /* ensure only lowest byte is set */ mode &= 0xff; #ifdef DEBUG_PRINT switch (mode) { case MPS_MITIGATION_CONTROL_MODE: DEBUGPRINT(DP_INFO, drvMpsLinkNodeTypeFlag, ("mpsSetLinkNodeType: mitigation control mode\n")); break; case MPS_BLM_MODE: DEBUGPRINT(DP_INFO, drvMpsLinkNodeTypeFlag, ("mpsSetLinkNodeType: BLM mode\n")); break; case MPS_BYKIK_MODE: DEBUGPRINT(DP_INFO, drvMpsLinkNodeTypeFlag, ("mpsSetLinkNodeType: BYKIK mode\n")); break; case MPS_MPG_CONTROL_MODE: DEBUGPRINT(DP_INFO, drvMpsLinkNodeTypeFlag, ("mpsSetLinkNodeType: MPG control mode\n")); break; case MPS_PIC_MODE: DEBUGPRINT(DP_INFO, drvMpsLinkNodeTypeFlag, ("mpsSetLinkNodeType: PIC mode\n")); break; default: DEBUGPRINT(DP_ERROR, drvMpsLinkNodeTypeFlag, ("mpsSetLinkNodeType: invalid mode %d\n", mode)); } #endif printf("*****mpsSetLinkNodeType: setting mode %d\n", mode); *mps_config = mode; pNode->linknodetype = mode; printf("*****mpsSetLinkNodeType: setting link node init bit\n"); /* Everytime the mode of the link node changes, set this to initialize the FPGA for this mode. Clobber of whole register ok */ *link_node_control = 1; return OK; } int mpsGetLinkNodeType() { int typeFromMem; int typeFromStruct; typeFromMem = *mps_config & 0xff; typeFromStruct = pNode->linknodetype; if (typeFromMem != typeFromStruct) { /*errlogPrintf("mpsGetLinkNodeType: mismatch: reg %d != struct %d\n", typeFromMem, typeFromStruct);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsLinkNodeTypeFlag, ("mpsGetLinkNodeType: mismatch: reg %d != struct %d\n", typeFromMem, typeFromStruct)); #endif } return typeFromStruct; } int ReadReg(int RegNum) { volatile long unsigned *pDest; unsigned long Value; pDest = (volatile long unsigned *)mpsBaseAddr + RegNum; /*printf("Pointer 0x%8.8lX \n",pDest); */ Value = *pDest; printf("Value 0x%8.8lX \n",Value); return OK; } void jjoReadADC() { volatile long unsigned *pDest; unsigned long iValue1; float XTemp; float p24v; float p12v; float p5v; float p3v; float BTemp; int offset; offset = 0x500; pDest = (volatile long unsigned *)mpsBaseAddr + offset; iValue1 = *pDest; printf("iValue1 is %lu\n", iValue1); XTemp = (((iValue1 / 32.0) -273.15) * 1.8) +32; pDest++; iValue1 = *pDest; p24v = iValue1 / 647.1; pDest++; iValue1 = *pDest; p12v = iValue1 /682.7; pDest++; iValue1 = *pDest; p5v = iValue1 /1637.0; pDest++; iValue1 = *pDest; p3v = iValue1 /1707.0; pDest++; iValue1 = *pDest; BTemp = (((iValue1 / 32.0) -273.15) * 1.8) +32; printf("Xilinx Temp = %2.3f\n", XTemp); printf("Board Temp = %2.3f\n", BTemp); printf("3.3V = %2.3f\n", p3v); printf("5.0V = %2.3f\n", p5v); printf("12V = %2.3f\n", p12v); printf("24V = %2.3f\n", p24v); } void ReadADC() { /*printf("Xilinx Temp = %g\n", mpsGetXilinxTemp());*/ /*printf("Board Temp = %g\n", mpsGetBoardTemp());*/ printf("3.3V = %2.3g\n", (double) mpsGetP3d3V()); printf("5.0V = %2.3g\n", (double) mpsGetP5V()); printf("12V = %2.3g\n", (double) mpsGetP12V()); printf("24V = %2.3g\n", (double) mpsGetP24V()); return; } /* This routine makes use of linear conversion of ai record. The values of ASLO and AOFF determine whether the raw value is converted to degrees Celsius or Fahrenheit */ long mpsGetXilinxTempAnalog() { unsigned long raw; raw = *xilinx_temp_address; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetADCFlag, ("mpsGetXilinxTemp: analog is %lu\n", raw)); #endif return (long) raw; } long mpsGetP24V() { unsigned long raw; raw = *p24vmon_address; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetADCFlag, ("mpsGetP24V: analog is %lu\n", raw)); #endif return (long) raw; } long mpsGetP12V() { unsigned long raw; raw = *p12vmon_address; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetADCFlag, ("mpsGetP12V: analog is %lu\n", raw)); #endif return (long) raw; } long mpsGetP5V() { unsigned long raw; raw = *p5vmon_address; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetADCFlag, ("mpsGetP5V: analog is %lu\n", raw)); #endif return (long) raw; } long mpsGetP3d3V() { unsigned long raw; raw = *p3d3vmon_address; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetADCFlag, ("mpsGetP3d3V: analog is %lu\n", raw)); #endif return (long) raw; } long mpsGetBoardTempAnalog() { unsigned long raw; raw = *board_temp_address; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetADCFlag, ("mpsGetBoardTemp: analog is %lu\n", raw)); #endif return (long) raw; } unsigned short mpsGetBLMHV(int channel) { volatile unsigned short raw; volatile unsigned short* addr; addr = (volatile unsigned short*) (BLM_HV_MON_BASE + (channel * 2)); raw = *addr; /* switch (channel) { case 1: raw = *blm_hv_mon_addr1; break; case 2: raw = *blm_hv_mon_addr2; break; case 3: raw = *blm_hv_mon_addr3; break; case 4: raw = *blm_hv_mon_addr4; break; case 5: raw = *blm_hv_mon_addr5; break; case 6: raw = *blm_hv_mon_addr6; break; case 7: raw = *blm_hv_mon_addr7; break; case 8: raw = *blm_hv_mon_addr8; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetBLMHVFlag, ("mpsGetBLMHv unrecognized ch: %d\n", channel)); #endif } */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetBLMHVFlag, ("mpsGetBLMHv ch: %d: analog is %hu\n", channel, raw)); #endif return raw; } int mpsSetBLMHV(int channel, unsigned short raw) { volatile unsigned short* addr; /* While testing in office, make ADC take value from DAC. In ops, trigger will do this *link_node_control = 2; */ addr = (volatile unsigned short*) (BLM_HV_CTL_BASE + (channel * 2)); *addr = (unsigned short) raw; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetBLMHVFlag, ("mpsSetBLMHV ch: %d: setting addr: 0x%08x to %hu\n", channel, (unsigned int) addr, raw)); #endif return OK; } int mpsSetBLMHVThreshold(int channel, int thld_type, int threshold) { volatile unsigned short *addr; unsigned short val; val = (unsigned short) threshold; /* don't check BLM_MODE. all nodes load all PVs and this causes errors. */ /* check */ if ((channel < 0) || (channel > 7)) { /*errlogPrintf("mpsSetBLMHVThreshold: channel is out of range: %d\n", channel);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetBLMHVThresholdFlag, ("mpsSetBLMHVThreshold: channel is out of range: %d\n", channel)); #endif return ERROR; } /* Now can update the threshold counts. volts not done !!!!!!!!!!*/ if (thld_type == MPS_THLD_HIGH) { addr = (unsigned short *)(BLM_HV_THRESHOLD_BASE + (channel*4) + 2); pNode->blmChannels[channel].hvhighthresholdcounts = threshold; } else { if (thld_type == MPS_THLD_LOW) { addr = (unsigned short *)(BLM_HV_THRESHOLD_BASE + (channel*4)); pNode->blmChannels[channel].hvlowthresholdcounts = threshold; } else { /*errlogPrintf("mpsSetBLMHVThreshold: invalid threshold type: %d\n", thld_type);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetBLMHVThresholdFlag, ("mpsSetBLMHVThreshold: invalid threshold type: %d\n", thld_type)); #endif return ERROR; } } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetBLMHVThresholdFlag, ("mpsSetBLMHVThreshold: ch: %d, type:%d (0=low, 1=high), val:%hu to addr: 0x%08x\n", channel, thld_type, val, (unsigned int) addr)); #endif *addr = val; return OK; } int mpsGetBLMHVThreshold(int channel, int thld_type) { volatile short *addr; short thresholdFromReg; short thresholdFromStruct; /* don't check BLM_MODE. all nodes load all PVs and this causes errors. */ /* check */ if ((channel < 0) || (channel > 7)) { /*errlogPrintf("mpsGetBLMHVThreshold: channel is out of range: %d\n", channel);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetBLMHVThresholdFlag, ("mpsGetBLMHVThreshold: channel is out of range: %d\n", channel)); #endif return ERROR; } if (thld_type == MPS_THLD_HIGH) { addr = (volatile short *)(BLM_HV_THRESHOLD_BASE + (channel*4) + 2); thresholdFromReg = *addr; thresholdFromStruct = pNode->blmChannels[channel].hvhighthresholdcounts; } else { if (thld_type == MPS_THLD_LOW) { addr = (volatile short *)(BLM_HV_THRESHOLD_BASE + (channel*4)); thresholdFromReg = *addr; thresholdFromStruct = pNode->blmChannels[channel].hvlowthresholdcounts; } else { /*errlogPrintf("mpsGetBLMHVThreshold: invalid threshold type: %d\n", thld_type);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetBLMHVThresholdFlag, ("mpsGetBLMHVThreshold: invalid threshold type: %d\n", thld_type)); #endif return ERROR; } } /* Ensure register consistent with structure contents */ if (thresholdFromReg != thresholdFromStruct) { /*errlogPrintf("mpsGetBLMHVThreshold: mismatch threshold in reg has: %d, in struct it's: %d\n", thresholdFromReg, thresholdFromStruct);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetBLMHVThresholdFlag, ("mpsGetBLMHVThreshold: mismatch threshold in reg has: %d, in struct it's: %d\n", thresholdFromReg, thresholdFromStruct)); #endif } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetBLMHVThresholdFlag, ("mpsGetBLMHVThreshold: %hd for ch: %d, type:%d (0=low, 1=high)\n", thresholdFromReg, channel, thld_type)); #endif return OK; } long mpsGetPIC(int channel) { unsigned long raw = 0; switch (channel) { case 1: raw = *pic_mon_addr1; break; case 2: raw = *pic_mon_addr2; break; case 3: raw = *pic_mon_addr3; break; case 4: raw = *pic_mon_addr4; break; case 5: raw = *pic_mon_addr5; break; case 6: raw = *pic_mon_addr6; break; case 7: raw = *pic_mon_addr7; break; case 8: raw = *pic_mon_addr8; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetPICFlag, ("mpsGetPIC unrecognized ch: %d\n", channel)); #endif } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetPICFlag, ("mpsGetPIC ch: %d: analog is %lu\n", channel, raw)); #endif return (long) raw; } /* Note: there is no register here */ int mpsGetAutoRecoverable(int channel) { return pNode->inputchannels[channel].isautorecoverable; } int mpsSetAutoRecoverableReg(int channel, int isautorecoverable) { pNode->inputchannels[channel].isautorecoverable = isautorecoverable; return OK; } /* Given the input channel number, read the bit pattern for debounce time and return the value after conversion to microseconds */ int mpsGetDebounceTime(int channel) { int debounceBits; int debounceTime = 0; int remainder; remainder = modulus(channel,8); /* First, use the input channel number to extract the bits */ switch (channel) { case 7: case 6: case 5: case 4: case 3: case 2: case 1: case 0: debounceBits = ((*input_debounce_addr0) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; case 15: case 14: case 13: case 12: case 11: case 10: case 9: case 8: debounceBits = ((*input_debounce_addr1) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; case 23: case 22: case 21: case 20: case 19: case 18: case 17: case 16: debounceBits = ((*input_debounce_addr2) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; case 31: case 30: case 29: case 28: case 27: case 26: case 25: case 24: debounceBits = ((*input_debounce_addr3) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; case 39: case 38: case 37: case 36: case 35: case 34: case 33: case 32: debounceBits = ((*input_debounce_addr4) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; case 47: case 46: case 45: case 44: case 43: case 42: case 41: case 40: debounceBits = ((*input_debounce_addr5) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; case 55: case 54: case 53: case 52: case 51: case 50: case 49: case 48: debounceBits = ((*input_debounce_addr6) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; case 63: case 62: case 61: case 60: case 59: case 58: case 57: case 56: debounceBits = ((*input_debounce_addr7) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; case 71: case 70: case 69: case 68: case 67: case 66: case 65: case 64: debounceBits = ((*input_debounce_addr8) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; case 79: case 78: case 77: case 76: case 75: case 74: case 73: case 72: debounceBits = ((*input_debounce_addr9) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; case 87: case 86: case 85: case 84: case 83: case 82: case 81: case 80: debounceBits = ((*input_debounce_addr10) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; case 95: case 94: case 93: case 92: case 91: case 90: case 89: case 88: debounceBits = ((*input_debounce_addr11) >> (remainder * 3)); debounceBits &= 7; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDebounceFlag, ("mpsGetDebounceTime: debounce bits for channel %d: %d\n", channel, debounceBits)); #endif break; default: printf("mpsGetDebounceTime: unrecognized input channel: %d\n", channel); return ERROR; } /* Second, determine debounce time in microseconds from bit pattern */ debounceTime = debounceTimes[debounceBits]; return debounceTime; } int mpsSetAutoRecoverable(int channel, int isautorecoverable) { pNode->inputchannels[channel].isautorecoverable = isautorecoverable; mpsSetAutoRecoverableReg(channel, isautorecoverable); return OK; } int mpsSetDebounceTimeReg(int channel, int debounceenum) { unsigned long shiftedDebounceBits; int remainder; remainder = modulus(channel,8); shiftedDebounceBits = (unsigned long) (debounceenum) << (remainder * 3); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: Top. chan=%d, bits=%d, remainder: %d, shifted bits: %lu\n", channel, debounceenum, remainder, shiftedDebounceBits)); #endif /* Second, mask in the bits to the debounce register for this channel */ switch (channel) { case 7: case 6: case 5: case 4: case 3: case 2: case 1: case 0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr0)); #endif *input_debounce_addr0 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr0)); #endif break; case 15: case 14: case 13: case 12: case 11: case 10: case 9: case 8: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr1)); #endif *input_debounce_addr1 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr1)); #endif break; case 23: case 22: case 21: case 20: case 19: case 18: case 17: case 16: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr2)); #endif *input_debounce_addr2 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr2)); #endif break; case 31: case 30: case 29: case 28: case 27: case 26: case 25: case 24: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr3)); #endif *input_debounce_addr3 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr3)); #endif break; case 39: case 38: case 37: case 36: case 35: case 34: case 33: case 32: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %d to channel %d: %lu\n", debounceenum, channel, *input_debounce_addr4)); #endif *input_debounce_addr4 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr4)); #endif break; case 47: case 46: case 45: case 44: case 43: case 42: case 41: case 40: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr5)); #endif *input_debounce_addr5 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr5)); #endif break; case 55: case 54: case 53: case 52: case 51: case 50: case 49: case 48: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr6)); #endif *input_debounce_addr6 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr6)); #endif break; case 63: case 62: case 61: case 60: case 59: case 58: case 57: case 56: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr7)); #endif *input_debounce_addr7 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr7)); #endif break; case 71: case 70: case 69: case 68: case 67: case 66: case 65: case 64: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr8)); #endif *input_debounce_addr8 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr8)); #endif break; case 79: case 78: case 77: case 76: case 75: case 74: case 73: case 72: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr9)); #endif *input_debounce_addr9 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr9)); #endif break; case 87: case 86: case 85: case 84: case 83: case 82: case 81: case 80: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr10)); #endif *input_debounce_addr10 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr10)); #endif break; case 95: case 94: case 93: case 92: case 91: case 90: case 89: case 88: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: before masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr11)); #endif *input_debounce_addr11 = 0xFFFFFFFF & shiftedDebounceBits; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: after masking in %lu to channel %d: %lu\n", shiftedDebounceBits, channel, *input_debounce_addr11)); #endif break; default: /*errlogPrintf("mpsSetDebounceTimeReg: unrecognized input channel: %d\n", channel);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetDebounceTimeRegFlag, ("mpsSetDebounceTimeReg: unrecognized input channel: %d\n", channel)); #endif return ERROR; } return OK; } int mpsSetDebounceEnum(int channel, int debounceenum) { pNode->inputchannels[channel].debounceenum = debounceenum; mpsSetDebounceTimeReg(channel, debounceenum); return OK; } /* 12/19/8: replaces mpsSetDebounceTimeFromEnum since time is now in LinkNodeChannel.csv file (in ADDITION to enum) int mpsSetDebounceTimeFromEnum(int channel, int debounceenum) { pNode->inputchannels[channel].debouncetimemicroseconds = debounceTimes[debounceenum]; mpsSetDebounceTimeReg(channel, debounceenum); return OK; } */ int mpsSetDebounceTime(int channel, int debouncetime) { int ii; int found = 0; pNode->inputchannels[channel].debouncetimemicroseconds = debouncetime; /* Keep enum and register up to date */ for (ii=0; iiinputchannels[channel].debounceenum; } /* out 12/19/8 8/29/8 THIS CAN GO AWAY IF DEBOUNCETIMES ONLY MODIFIABLE VIA SQL Given the input channel number [0..95] and the debounce time as one of 10, 100, 1000, 10000, 100000, 500000, 1000000 or 5000000 microseconds, this rouine writes the appropriate bit pattern into the appropriate location of the 12 input debounce registers int mpsSetDebounceTimeFromUsecs(int channel, int debouncemicroseconds) { int ii; First, convert time to bit pattern. for (ii=0; iiinputchannels[channel].debounceenum = ii; } } mpsSetDebounceTimeReg(channel, pNode->inputchannels[channel].debounceenum); return OK; } */ /* Given the channel number [0..95] this routine sets the appropriate bit in the appropriate location of the deadman register */ int mpsSetDeadManReg(int channel) { unsigned long shiftedDeadManMask; int remainder; remainder = modulus(channel,32); shiftedDeadManMask = 1 << remainder; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDeadManRegFlag, ("mpsSetDeadManReg: setting deadman bit for ch: %d rem: %d mask: %lu\n", channel, remainder, shiftedDeadManMask)); #endif if ((0 <= channel) && (channel<32)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDeadManRegFlag, ("mpsSetDeadManReg: reg 0 before: %lu\n", *deadman_addr0)); #endif *deadman_addr0 |= shiftedDeadManMask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDeadManRegFlag, ("mpsSetDeadManReg: reg 0 after: %lu\n", *deadman_addr0)); #endif } else { if ((32 <= channel) && (channel<64)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDeadManRegFlag, ("mpsSetDeadManReg: reg 1 before: %lu\n", *deadman_addr1)); #endif *deadman_addr1 |= shiftedDeadManMask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDeadManRegFlag, ("mpsSetDeadManReg: reg 1 after: %lu\n", *deadman_addr1)); #endif } else { if ((64 <= channel) && (channel<96)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDeadManRegFlag, ("mpsSetDeadManReg: reg 2 before: %lu\n", *deadman_addr2)); #endif *deadman_addr2 |= shiftedDeadManMask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDeadManRegFlag, ("mpsSetDeadManReg: reg 2 after: %lu\n", *deadman_addr2)); #endif } else { /*errlogPrintf("mpsSetDeadManReg: unrecognized input channel: %d\n", channel);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetDeadManRegFlag, ("mpsSetDeadManReg: unrecognized input channel: %d\n", channel)); #endif return ERROR; } } } return OK; } int mpsGetDeadManReg(int channel) { unsigned long shiftedDeadManMask; int remainder; remainder = modulus(channel,32); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDeadManRegFlag, ("mpsGetDeadManReg: getting deadman bit for ch: %d rem: %d\n", channel, remainder)); #endif if ((0 <= channel) && (channel<32)) { shiftedDeadManMask = 0x1 & (*deadman_addr0 >> remainder); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDeadManRegFlag, ("mpsGetDeadManReg: reg 0 mask: %lu\n", shiftedDeadManMask)); #endif } else { if ((32 <= channel) && (channel<64)) { shiftedDeadManMask = 0x1 & (*deadman_addr1 >> remainder); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDeadManRegFlag, ("mpsGetDeadManReg: reg 1 mask: %lu\n", shiftedDeadManMask)); #endif } else { if ((64 <= channel) && (channel<96)) { shiftedDeadManMask = 0x1 & (*deadman_addr2 >> remainder); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetDeadManRegFlag, ("mpsGetDeadManReg: reg 2 mask: %lu\n", shiftedDeadManMask)); #endif } else { /*errlogPrintf("mpsGetDeadManReg: unrecognized input channel: %d\n", channel);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetDeadManRegFlag, ("mpsGetDeadManReg: unrecognized input channel: %d\n", channel)); #endif return ERROR; } } } return shiftedDeadManMask; } /* Given the input channel number [0..95] this rouine clears the appropriate bit in the appropriate location of the deadman register and update the structure */ int mpsClrDeadManReg(int channel) { unsigned long shiftedDeadManMask; int remainder; remainder = modulus(channel,32); shiftedDeadManMask = 1 << remainder; if ((0 <= channel) && (channel<32)) { *deadman_addr0 &= ~shiftedDeadManMask; } else { if ((32 <= channel) && (channel<64)) { *deadman_addr1 &= ~shiftedDeadManMask; } else { if ((64 <= channel) && (channel<96)) { *deadman_addr2 &= ~shiftedDeadManMask; } else { /*errlogPrintf("mpsClrDeadMan: unrecognized input channel: %d\n", channel);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsClrDeadManFlag, ("mpsClrDeadManReg: unrecognized input channel: %d\n", channel)); #endif return ERROR; } } } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsClrDeadManFlag, ("mpsClrDeadManReg: chan=%d\n", channel)); #endif return OK; } int mpsSetDeadMan(int channel, int flag) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDeadManFlag, ("mpsSetDeadMan: chan: %d to: %d\n", channel, flag)); #endif pNode->inputchannels[channel].deadman = flag; if (flag) { mpsSetDeadManReg(channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDeadManFlag, ("mpsSetDeadMan: chan: %d calling mpsSetDeadManReg\n", channel)); #endif } else { mpsClrDeadManReg(channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetDeadManFlag, ("mpsSetDeadMan: chan: %d calling mpsClrDeadManReg\n", channel)); #endif } return OK; } int mpsGetDeadMan(int channel) { int deadmanFromStruct; int deadmanFromReg; deadmanFromStruct = pNode->inputchannels[channel].deadman; deadmanFromReg = mpsGetDeadManReg(channel); if (deadmanFromStruct != deadmanFromReg) { /*errlogPrintf("mpsGetDeadMan: poss reg corrup of ch: %d deadman: mem has: %d, reg has: %d\n", channel, deadmanFromStruct, deadmanFromReg); */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetDeadManFlag, ("mpsGetDeadMan: poss reg corrup of ch: %d deadman: mem has: %d, reg has: %d\n", channel, deadmanFromStruct, deadmanFromReg)); #endif return ERROR; } return deadmanFromStruct; } /* References: Used http://www.slac.stanford.edu/grp/lcls/controls/global/subsystems/mps/MpsNode_Reg_05dec2008.pdf page 5 to get MPS Node Memory offset from chip select 1 base address to get QADC_IO_SPACE_BASE Used http://www.slac.stanford.edu/grp/lcls/controls/global/subsystems/mps/IP_QINT_ADC_SW_Prog_Guide_V3d0.pdf page 4 to get additional offset to channel, sum of channel, latched channel and sum of latched channel faults. Re: V4002, this area is updated via sync read and so it is not invasive */ int mpsGetQADCFault(int module, int channel, int type) { unsigned short fault; volatile unsigned short* addr = NULL; switch (type) { case MPS_QADC_FAULT_TYPE_CHAN: addr = (volatile unsigned short*) (QADC_IO_SPACE_BASE + 0x20 + (channel * 2)); break; case MPS_QADC_FAULT_TYPE_SUM0: addr = (volatile unsigned short*) (QADC_IO_SPACE_BASE + 0x40); break; case MPS_QADC_FAULT_TYPE_SUM1: addr = (volatile unsigned short*) (QADC_IO_SPACE_BASE + 0x42); break; case MPS_QADC_FAULT_TYPE_CHAN_LATCHED: addr = (volatile unsigned short*) ( QADC_IO_SPACE_BASE + 0x30 + (channel * 2)); break; case MPS_QADC_FAULT_TYPE_SUM0_LATCHED: addr = (volatile unsigned short*) (QADC_IO_SPACE_BASE + 0x44); break; case MPS_QADC_FAULT_TYPE_SUM1_LATCHED: addr = (volatile unsigned short*) (QADC_IO_SPACE_BASE + 0x46); break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetQADCFaultFlag, ("mpsGetQADCFault: unrecognized type: %d for channel: %d\n", channel, type)); #endif } fault = *addr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsGetQADCFaultFlag, ("mpsGetQADCFault: %hd ch: %d, type:%d (0=chan, 1=sum0, 2=sum1, 3=latched chan...)\n", fault, channel, type)); #endif return (int) fault; } int mpsGetLatchedReg(int channel) { unsigned long shiftedLatchedMask; int remainder; remainder = modulus(channel,32); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetLatchedRegFlag, ("mpsGetLatchedReg: getting latched bit for ch: %d rem: %d\n", channel, remainder)); #endif if ((0 <= channel) && (channel<32)) { shiftedLatchedMask = 0x1 & (*latched_reg_addr0 >> remainder); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetLatchedRegFlag, ("mpsGetLatchedReg: reg 0 mask: %lu\n", shiftedLatchedMask)); #endif } else { if ((32 <= channel) && (channel<64)) { shiftedLatchedMask = 0x1 & (*latched_reg_addr1 >> remainder); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetLatchedRegFlag, ("mpsGetLatchedReg: reg 1 mask: %lu\n", shiftedLatchedMask)); #endif } else { if ((64 <= channel) && (channel<96)) { shiftedLatchedMask = 0x1 & (*latched_reg_addr2 >> remainder); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetLatchedRegFlag, ("mpsGetLatchedReg: reg 2 mask: %lu\n", shiftedLatchedMask)); #endif } else { /*errlogPrintf("mpsGetLatchedReg: unrecognized input channel: %d\n", channel);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetLatchedRegFlag, ("mpsGetLatchedReg: unrecognized input channel: %d\n", channel)); #endif /* return ERROR; 4/8/9 don't return -1; it gets into val field which is wrong */ } } } return shiftedLatchedMask; } /* 12/17/8: flipping logic so that reg != struct is the good case CHECK!!!!!!!!!!!*/ int mpsGetLatched(int channel) { int latchedFromStruct; int latchedFromReg; latchedFromStruct = pNode->inputchannels[channel].latched; latchedFromReg = mpsGetLatchedReg(channel); if (latchedFromStruct == latchedFromReg) { /*errlogPrintf("mpsGetLatched: poss reg corrup of ch: %d latched: mem has: %d reg has %d\n", channel, latchedFromStruct, latchedFromReg); */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetLatchedFlag, ("mpsGetLatched: poss reg corrup of ch: %d latched: mem has: %d reg has %d\n", channel, latchedFromStruct, latchedFromReg)); #endif /* return ERROR; 4/8/9 don't return -1; it gets into val field which is wrong */ } return latchedFromStruct; } /* "state" = !filtered */ int mpsGetStateReg(int channel) { unsigned long shiftedStateMask; int remainder; remainder = modulus(channel,32); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetStateRegFlag, ("mpsGetStateReg: getting state bit for ch: %d rem: %d\n", channel, remainder)); #endif if ((0 <= channel) && (channel<32)) { shiftedStateMask = 0x1 & (*filtered_reg_addr0 >> remainder); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetStateRegFlag, ("mpsGetStateReg: reg 0 mask: %lu\n", shiftedStateMask)); #endif } else { if ((32 <= channel) && (channel<64)) { shiftedStateMask = 0x1 & (*filtered_reg_addr1 >> remainder); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetStateRegFlag, ("mpsGetStateReg: reg 1 mask: %lu\n", shiftedStateMask)); #endif } else { if ((64 <= channel) && (channel<96)) { shiftedStateMask = 0x1 & (*filtered_reg_addr2 >> remainder); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetStateRegFlag, ("mpsGetStateReg: reg 2 mask: %lu\n", shiftedStateMask)); #endif } else { /*errlogPrintf("mpsGetStateReg: unrecognized input channel: %d\n", channel);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetStateRegFlag, ("mpsGetStateReg: unrecognized input channel: %d\n", channel)); #endif /* return ERROR; 4/8/9 don't return -1; it gets into val field which is wrong */ } } } return shiftedStateMask; } /* IMPORTANT: State (aka filtered) register is read-only, so setting state means reading the register and setting the global structure to match. This differs from the r/w register set routines. Convention is that "filtered" value indicates a fault if its value is 1, yet "state" indicates good health, so flip the sign */ int mpsSetState(int channel) { int state; state = mpsGetStateReg(channel); if (state) { pNode->inputchannels[channel].state = 0; } else { pNode->inputchannels[channel].state = 1; } return OK; } int mpsGetState(int channel) { int state; state = mpsGetStateReg(channel); /* Compare to what is in struct... consistency check */ return state; } /* BYKIK Low and High Threshold Settings accepts voltage between [-10 V, 10 V] and scales it to 2 byte unsigned offset binary (-10 V -> 0 counts; 0 V -> 32768 counts; 10 V -> 65535 counts) */ int mpsSetBYKThreshold(int threshold_type, double threshold) { volatile unsigned short *addr; unsigned short thld; thld = (unsigned short) (threshold * 65535/20 + 32767); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetBYKThresholdFlag, ("mpsSetBYKThreshold: top. type:%d threshold: %g v [-10,10] = %hu counts [0,65535]\n", threshold_type, threshold, thld)); #endif if (threshold_type == MPS_THLD_LOW) { pNode->BYKThresholdLowVolts = threshold; pNode->BYKThresholdLowVoltsArray[0] = threshold; pNode->BYKThresholdLowVoltsArray[1] = threshold; pNode->BYKThresholdLowCountsArray[0] = thld; pNode->BYKThresholdLowCountsArray[1] = thld; addr = (volatile unsigned short*)BYKIK_THLD_LO_ADDR; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetBYKThresholdFlag, ("mpsSetBYKThreshold: set low threshold volts to: %g\n", pNode->BYKThresholdLowVolts)); DEBUGPRINT(DP_INFO, drvMpsSetBYKThresholdFlag, ("mpsSetBYKThreshold: set low threshold counts to: %d\n", pNode->BYKThresholdLowCountsArray[0])); #endif } else { if (threshold_type == MPS_THLD_HIGH) { pNode->BYKThresholdHighVolts = threshold; pNode->BYKThresholdHighVoltsArray[0] = threshold; pNode->BYKThresholdHighVoltsArray[1] = threshold; pNode->BYKThresholdHighCountsArray[0] = thld; pNode->BYKThresholdHighCountsArray[1] = thld; addr = (volatile unsigned short*)BYKIK_THLD_HI_ADDR; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetBYKThresholdFlag, ("mpsSetBYKThreshold: set high threshold to: %g\n", pNode->BYKThresholdHighVolts)); DEBUGPRINT(DP_INFO, drvMpsSetBYKThresholdFlag, ("mpsSetBYKThreshold: set high threshold counts to: %hd\n", pNode->BYKThresholdHighCountsArray[0])); #endif } else { return ERROR; } } *addr = thld; return OK; } /* 9/24/9: changed all decs from short to unsigned short in this routine */ unsigned short mpsGetBYKThreshold(int threshold_type) { volatile unsigned short *addr; /*errlogPrintf("mpsGetBYKThreshold: invasive to FPGA!!!!\n");*/ if (threshold_type == MPS_THLD_LOW) { addr = (volatile unsigned short*)BYKIK_THLD_LO_ADDR; } else { if (threshold_type == MPS_THLD_HIGH) { addr = (volatile unsigned short*)BYKIK_THLD_HI_ADDR; } else { /* errlogPrintf("mpsGetBYKThreshold: MPS Link Node has bad threshold type: %d\n", threshold_type);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetBYKThresholdFlag, ("mpsSetBYKThreshold: MPS Link Node has bad threshold type: %d\n", threshold_type)); #endif return 0; /* not a good idea to return a -1 in this case */ } } return *addr; } unsigned short* mpsGetBYKThresholdCountsArray(int threshold_type) { /* check */ if (pNode->linknodetype != MPS_BYKIK_MODE) { /* errlogPrintf("mpsGetBYKThresholdCounts: MPS Link Node is wrong type: %d\n", pNode->linknodetype);*/ return 0; } if (threshold_type == MPS_THLD_LOW) { return pNode->BYKThresholdLowCountsArray; } else { if (threshold_type == MPS_THLD_HIGH) { return pNode->BYKThresholdHighCountsArray; } else { /* errlogPrintf("mpsGetBYKThresholdCounts: MPS Link Node has bad threshold type: %d\n", threshold_type);*/ return NULL; } } } /* 9/24/9 Check: maybe this should be unsigned short? */ int mpsSetBYKADCNumPresamples(int number) { volatile short* addr; addr = (volatile short *) BYKIK_ADC_NPSAMP_ADDR; *addr = (short) number; pNode->BYKADCNumPresamples = number; return OK; } /* 9/24/9 Check: maybe this should be unsigned short? */ short mpsGetBYKADCNumPresamples(void) { volatile short* addr; addr = (volatile short *) BYKIK_ADC_NPSAMP_ADDR; return *addr; } /* 9/24/9 Check: maybe this should be unsigned short? */ int mpsSetBYKADCNumSamples(int number) { volatile short* addr; addr = (volatile short *) BYKIK_ADC_NSAMP_ADDR; *addr = (short) number; pNode->BYKADCNumSamples = number; return OK; } /* 9/24/9 Check: maybe this should be unsigned short? */ short mpsGetBYKADCNumSamples() { volatile short* addr; addr = (volatile short *) BYKIK_ADC_NPSAMP_ADDR; return *addr; } /* 9/24/9 Check: maybe this should be unsigned short? */ int mpsSetBYKADCDelay(int number) { volatile short* addr; addr = (volatile short *) BYKIK_ADC_DLY_ADDR; *addr = (short) number; pNode->BYKADCDelay = number; return OK; } /* 9/24/9 Check: maybe this should be unsigned short? */ short mpsGetBYKADCDelay() { volatile short* addr; addr = (volatile short *) BYKIK_ADC_DLY_ADDR; return *addr; } /* 9/28/9 New. Used to draw vertical bar on xygraph to show beginning of sample Read from structure, not from register map Since we want the start of the presamples in absolute ticks, we are adding the ADC Delay/60 to work in MHz ticks. */ short* mpsGetBYKBeginSample() { pNode->BYKADCPresamplesArray[0] = (short) (pNode->BYKADCNumPresamples + (pNode->BYKADCDelay/60)); /* Need an array of two of these numbers */ pNode->BYKADCPresamplesArray[1] = pNode->BYKADCPresamplesArray[0]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsBYKADCFlag, ("mpsGetBYKPresamplesArray: %hd, %hd\n", pNode->BYKADCPresamplesArray[0], pNode->BYKADCPresamplesArray[1])); #endif return pNode->BYKADCPresamplesArray; } /* 9/28/9 New. Used to draw vertical bar on xygraph to show end of sample Read from structure, not from register map Since we want the start of the presamples in absolute ticks, we are adding the ADC Delay/60 to work in MHz ticks. */ short* mpsGetBYKEndSample() { pNode->BYKADCSamplesArray[0] = (short) (pNode->BYKADCNumPresamples + (pNode->BYKADCDelay/60) + pNode->BYKADCNumSamples); /* Need an array of two of these numbers */ pNode->BYKADCSamplesArray[1] = pNode->BYKADCSamplesArray[0]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsBYKADCFlag, ("mpsGetBYKSamplesArray: %hd, %hd\n", pNode->BYKADCSamplesArray[0], pNode->BYKADCSamplesArray[1])); #endif return pNode->BYKADCSamplesArray; } unsigned short mpsGetBLMFPGAVersion() { pNode->blmFpgaVersion = *blm_fpga_ver_addr; return pNode->blmFpgaVersion; } int mpsBLMReport() { int ii; printf("BLM QADC FPGA Version: 0x%x\n", pNode->blmFpgaVersion); printf(" HV Thresholds\n"); printf (" ch HVlow (V) HVlow (cnts) HVhigh (V) HVhigh (cnts)\n"); for (ii = 0; ii < 8; ii++) { printf (" %d %d %d %d %d\n", ii, pNode->blmChannels[ii].hvlowthresholdvolts, pNode->blmChannels[ii].hvlowthresholdcounts, pNode->blmChannels[ii].hvhighthresholdvolts, pNode->blmChannels[ii].hvhighthresholdcounts); } printf(" Dose Thresholds\n"); printf (" ch baselow basehigh testlow testhigh beamlow beamhigh\n"); for (ii = 0; ii < 8; ii++) { printf (" %d %d %d %d %d %d %d\n", ii, pNode->blmChannels[ii].baselowthreshold, pNode->blmChannels[ii].basehighthreshold, pNode->blmChannels[ii].testlowthreshold, pNode->blmChannels[ii].testhighthreshold, pNode->blmChannels[ii].beamlowthreshold, pNode->blmChannels[ii].beamhighthreshold); } printf(" Beam Pedestals \n"); printf (" ch beamPED\n"); printf (" %d %d\n", 0, pNode->blmChannels[0].beampedestal); printf (" %d %d\n", 1, pNode->blmChannels[1].beampedestal); printf (" %d %d\n", 2, pNode->blmChannels[2].beampedestal); printf (" %d %d\n", 3, pNode->blmChannels[3].beampedestal); printf (" - 3.3 V: %d\n", pNode->beamped3d3); printf (" - 2.5 V: %d\n", pNode->beamped2d5); printf (" %d %d\n", 4, pNode->blmChannels[4].beampedestal); printf (" %d %d\n", 5, pNode->blmChannels[5].beampedestal); printf (" %d %d\n", 6, pNode->blmChannels[6].beampedestal); printf (" %d %d\n", 7, pNode->blmChannels[7].beampedestal); printf (" - 1.2 V: %d\n", pNode->beamped1d2); printf (" - GND: %d\n", pNode->beampedgnd); return OK; } int mpsPICReport(int pic) { int ii; printf ("MPS PIC %d Report\n", pic); printf (" ch lowthld highthld loss loss1 loss10 loss30 loss60\n"); for (ii = 0; ii < 8; ii++) { printf (" %d %g %g %ld %ld %ld %ld %ld\n", ii, pNode->pics[pic].picchannels[ii].lowthreshold, pNode->pics[pic].picchannels[ii].highthreshold, pNode->pics[pic].picchannels[ii].loss_now, pNode->pics[pic].picchannels[ii].loss_1, pNode->pics[pic].picchannels[ii].loss_10, pNode->pics[pic].picchannels[ii].loss_30, pNode->pics[pic].picchannels[ii].loss_60); } return OK; } int mpsNodeReport() { int ii; printf ("MPS Link Node Report\n\n"); printf ("MPS Link Node Attributes:\n"); printf (" id = %d\n", pNode->linknodeid); switch (pNode->linknodetype) { case MPS_PIC_MODE: printf (" type = PIC\n"); break; case MPS_MPG_CONTROL_MODE: printf (" type = MPG Control\n"); break; case MPS_BYKIK_MODE: printf (" type = BYKIK\n"); break; case MPS_BLM_MODE: printf (" type = BLM\n"); break; case MPS_MITIGATION_CONTROL_MODE: printf (" type = Mitigation Control\n"); break; } printf (" FPGA version: 0x%08x\n", (unsigned int) pNode->fpgaVersion); printf (" Database version: %s\n", pNode->databaseVersion); printf (" Database loaded: mps%s%s.template\n", locations[pNode->linknodeid], units[pNode->linknodeid]); /* printf (" Rack= %s\n", pNode->rackLocation); 4/9 redund with iocManager */ if (pNode->linknodetype == MPS_BLM_MODE) { mpsBLMReport(); } if (pNode->linknodetype == MPS_PIC_MODE) { printf ("MPS Link Node has 4 PICs\n\n"); for (ii = 0; ii < 4; ii++) { mpsPICReport(ii); } } if (pNode->linknodetype == MPS_BYKIK_MODE) { printf (" BYK high threshold volts: %g\n", pNode->BYKThresholdHighVolts); printf (" BYK low threshold volts: %g\n", pNode->BYKThresholdLowVolts); printf (" BYK ADC num samples: %d\n", pNode->BYKADCNumSamples); printf (" BYK ADC num presamples: %d\n", pNode->BYKADCNumPresamples); printf (" BYK ADC delay: %d\n", pNode->BYKADCDelay); printf (" Used for plots: \n"); printf (" BYK high threshold counts: %hu\n", pNode->BYKThresholdHighCountsArray[0]); printf (" BYK low threshold counts: %hu\n", pNode->BYKThresholdLowCountsArray[0]); printf (" BYK sample starts at x=%hd\n", pNode->BYKADCPresamplesArray[0]); printf (" BYK sample ends at x=%hd\n", pNode->BYKADCSamplesArray[0]); } printf ("MPS Link Node has %d input channels\n\n", MPS_NODE_NUM_CHANS); return OK; } int mpsChannelReport(int channel) { int ii = channel; printf ("MPS Link Node input channel %d Attributes begin at: 0x%08x\n", ii, (unsigned int) &(pNode->inputchannels[ii])); printf (" deadman = %d at: 0x%08x\n", pNode->inputchannels[ii].deadman, (unsigned int) &(pNode->inputchannels[ii].deadman)); printf (" debounce time (us) = %d at: 0x%08x\n", pNode->inputchannels[ii].debouncetimemicroseconds, (unsigned int) &(pNode->inputchannels[ii].debouncetimemicroseconds)); /*printf (" descript = '%s'\n", pNode->inputchannels[ii].descript); */ printf (" inputcard = %d at: 0x%08x\n", pNode->inputchannels[ii].inputcard, (unsigned int) &(pNode->inputchannels[ii].inputcard)); printf (" inputcardchannel = %d at: 0x%08x\n", pNode->inputchannels[ii].inputcardchannel, (unsigned int) &(pNode->inputchannels[ii].inputcardchannel)); printf (" isautorecoverable = %d at: 0x%08x\n", pNode->inputchannels[ii].isautorecoverable, (unsigned int) &(pNode->inputchannels[ii].isautorecoverable)); printf (" latched = %d at: 0x%08x\n", pNode->inputchannels[ii].latched,(unsigned int) &(pNode->inputchannels[ii].latched)); printf (" state = %d at: 0x%08x\n", pNode->inputchannels[ii].state, (unsigned int) &(pNode->inputchannels[ii].state)); /*printf (" location = '%s'\n", pNode->inputchannels[ii]->.location); */ /*printf (" inputname = '%s'\n", pNode->inputchannels[ii]->.inputname); */ /*printf (" pv = '%s'\n", pNode->inputchannels[ii]->.pv); */ /*printf (" state0 = '%s'\n", pNode->inputchannels[ii]->.state0); */ /*printf (" state1 = '%s'\n", pNode->inputchannels[ii]->.state1); */ return OK; } int mpsReport() { int ii; mpsNodeReport(); for (ii = 0; ii < MPS_NODE_NUM_CHANS; ii++) { mpsChannelReport(ii); } printf("\nContents of Flash\n"); printf(" Factory: %s\n", mpsGetFactory()); printf(" Revision: %s\n", mpsGetRevision()); printf(" Serial: %s\n", mpsGetSerial()); printf(" Console: %s\n", mpsGetConsole()); printf(" Kernel: %s\n", mpsGetKernel()); printf(" KernelArgs: %s\n", mpsGetKernelArgs()); printf(" HWAddr0: %s\n", mpsGetHWAddr0()); printf(" Firmware: %s\n", mpsGetFirmware()); printf(" StartPoint: %s\n", mpsGetStartPoint()); printf(" RAMImage: %s\n", mpsGetCache()); printf(" Cache: %d\n", mpsGetAutobootTime()); printf(" Bootp Enable? Y/N: %s\n", mpsGetBootpEnable()); printf("\n"); ReadADC(); return OK; } /* From http://www.sqlite.org/quickstart.html static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int i; for(i=0; i < argc; i++) { printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); } printf("\n"); return 0; } */ #ifdef NEVER #define MAX_QUERY_LENGTH 2048 int sqliteHandler() { sqlite3 *db; char *errMsg; int rc; char mpsDatabasePath[100]; char linkNodeIdString[10]; char query[MAX_QUERY_LENGTH]; strcpy(mpsDatabasePath,"../database/config.sql"); printf("Opening: %s\n", mpsDatabasePath); /* Open database */ rc = sqlite3_open(mpsDatabasePath, &db); if( rc ) { fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); return 2; } printf("Preparing query:\n"); /* Prepare query */ { sprintf(linkNodeIdString, "%d", pNode->linknodeid); /* ENSURE strlen <= MAX_QUERY_LENGTH */ sprintf(query, "SELECT ZPVDEVICETYPE lnPvDeviceType,\ ZPVAREA lnPvArea,\ ZPVPOSITION lnPvPosition,\ ZLINKNODEID linkNodeId\ FROM ZLINKNODE\ WHERE ZLINKNODEID = %ld", strtol(linkNodeIdString, NULL, 10)); rc = sqlite3_exec(db, query, callback, 0, &errMsg); if( rc!=SQLITE_OK ) { fprintf(stderr, "SQL error: %s\n", errMsg); sqlite3_free(errMsg); } /* ENSURE strlen <= MAX_QUERY_LENGTH */ sprintf(query, "select lnic.ZNAME name,\ lnic.ZPVDEVICETYPE pvDeviceType,\ lnic.ZPVAREA pvArea,\ lnic.ZPVPOSITION pvPosition,\ lnic.ZPVATTRIBUTE pvAttribute,\ lnic.ZINPUTCARD card,\ lnic.ZINPUTCARDCHANNEL channel,\ debounce.ZTIMEINMICROSECONDS debounceInMicroSec,\ debounce.ZENUM debounceEnum\ from ZLINKNODEINPUTCHANNEL lnic left outer join ZDEBOUNCETIME debounce\ on lnic.ZDEBOUNCETIME = debounce.Z_PK\ where lnic.ZLINKNODE = (select Z_PK\ from ZLINKNODE\ where ZLINKNODEID = %ld)", strtol(linkNodeIdString, NULL, 10)); } #ifdef NEVER else { /* ENSURE strlen <= MAX_QUERY_LENGTH */ sprintf(query, MAX_QUERY_LENGTH, "SELECT ZPVDEVICETYPE lnPvDeviceType,\ ZPVAREA lnPvArea,\ ZPVPOSITION lnPvPosition,\ ZLINKNODEID linkNodeId\ FROM ZLINKNODE"); } #endif /* Execute query */ rc = sqlite3_exec(db, query, callback, 0, &errMsg); if( rc!=SQLITE_OK ) { fprintf(stderr, "SQL error: %s\n", errMsg); sqlite3_free(errMsg); } /* Close database */ sqlite3_close(db); return 0; } #endif /* Given a line from the xml file in the node object definition, extract which node attribute this is and get its value while we're at it */ int parseNodeAttrAndVal(const char* str, mpsNode_t* pNode) { char node_attributes[MPS_NODE_NUM_ATTRS][MPS_ATTR_LENGTH] ={"zid","linknodeid","pvprefix","rackelevation","racknumber"}; /* char node_relationships[MPS_NODE_NUM_RELS][MPS_ATTR_LENGTH]={"inputchannels","outputchannels"}; */ int ii = 0; int jj = 0; int kk = 0; int index = -1; int fillVal = 0; char strVal[MPS_ATTR_LENGTH]; int found = 0; int done = 0; while (!found && ii < MPS_NODE_NUM_ATTRS) { /*printf("looking for %s in %s\n", node_attributes[ii], str);*/ if (strstr(str, node_attributes[ii]) != NULL) { /* match found. now we know which attr this is */ index = ii; found = 1; printf("parseNodeAttrAndVal: match found for attribute[%d], '%s'\n", index, node_attributes[ii]); } ii++; } /* Cruise through to end of "attribute ...>", saving next chars into temp string until you find '<'. Don't write '>' into the temp string Add a null on the end of temp string */ jj=0; while (!done && jj') { /* next char is start of value */ /*printf ("found '>'\n");*/ fillVal = 1; kk=0; } } } jj++; } printf ("retrieved '%s'\n",strVal); switch(index) { /*case 0: is zid */ case 1: pNode->linknodeid = atoi(strVal); printf("parseNodeAttrAndVal: mps node attribute linknode id set to %d\n", pNode->linknodeid); break; /*case 2: strcpy(pNode->pvprefix,strVal); printf("parseNodeAttrAndVal: mps node attribute pvprefix set to '%s'\n", pNode->pvprefix); break;*/ case 3: pNode->rackelevation = atoi(strVal); printf("parseNodeAttrAndVal: mps node attribute rackelevation set to %d\n", pNode->rackelevation); break; case 4: strcpy(pNode->racknumber,strVal); printf("parseNodeAttrAndVal: mps node attribute racknumber set to '%s'\n", pNode->racknumber); break; default: printf("parseNodeAttrAndVal: Unrecognized index = %d\n", index); } if (index != -1) { return OK; } else { errlogPrintf("parseNodeAttrAndVal: error\n"); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetDebounceFlag, ("parseNodeAttrAndVal: error\n")); #endif return ERROR; } } /* Given a line from the xml file in the node object definition, extract which channel attribute this is and get its value while we're at it */ int parseChanAttrAndVal(const char* str, mpsInputChannel_t* pChan) { char chan_attributes[MPS_CHAN_NUM_ATTRS][MPS_ATTR_LENGTH] ={"zid","debouncetimemicroseconds","descript","inputcard","inputcardchannel","isautorecoverable", "location","inputname","pv","state0","state1"}; int ii = 0; int jj = 0; int kk = 0; int index = -1; int fillVal = 0; char strVal[MPS_ATTR_LENGTH]; int found = 0; int done = 0; while (!found && ii < MPS_CHAN_NUM_ATTRS) { /* printf("looking for %s in %s\n", chan_attributes[ii], str);*/ if (strstr(str, chan_attributes[ii]) != NULL) { /* match found. now we know which attr this is */ index = ii; found = 1; printf("parseChanAttrAndVal: match found for attribute[%d], '%s'\n", index, chan_attributes[ii]); } ii++; } /* Cruise through to end of "attribute ...>", saving next chars into temp string until you find '<'. Don't write '>' into the temp string Add a null on the end of temp string */ jj=0; while (!done && jj') { /* next char is start of value */ /*printf ("found '>'\n");*/ fillVal = 1; kk=0; } } } jj++; } printf ("retrieved '%s'\n",strVal); switch(index) { /*case 0: is zid */ case 1: pChan->debouncetimemicroseconds = atoi(strVal); printf("parseChanAttrAndVal: mps chan attribute debouncetimemicroseconds set to %d\n", pChan->debouncetimemicroseconds); break; case 2: strcpy(pChan->descript,strVal); printf("parseChanAttrAndVal: mps chan attribute descript set to '%s'\n", pChan->descript); break; case 3: pChan->inputcard = atoi(strVal); printf("parseChanAttrAndVal: mps chan attribute inputcard set to %d\n", pChan->inputcard); break; case 4: pChan->inputcardchannel = atoi(strVal); printf("parseChanAttrAndVal: mps chan attribute inputcardchannel set to %d\n", pChan->inputcardchannel); break; case 5: pChan->isautorecoverable = atoi(strVal); printf("parseChanAttrAndVal: mps chan attribute isautorecoverable set to %d\n", pChan->isautorecoverable); break; case 6: strcpy(pChan->location,strVal); printf("parseChanAttrAndVal: mps chan attribute location set to '%s'\n", pChan->location); break; case 7: strcpy(pChan->inputname,strVal); printf("parseChanAttrAndVal: mps chan attribute inputname set to '%s'\n", pChan->inputname); break; case 8: strcpy(pChan->pv,strVal); printf("parseChanAttrAndVal: mps chan attribute pv set to '%s'\n", pChan->pv); break; case 9: strcpy(pChan->state0,strVal); printf("parseChanAttrAndVal: mps chan attribute state0 set to '%s'\n", pChan->state0); break; case 10: strcpy(pChan->state1,strVal); printf("parseChanAttrAndVal: mps chan attribute state1 set to '%s'\n", pChan->state1); break; default: printf("parseChanAttrAndVal: Unrecognized index = %d\n", index); } if (index != -1) { return OK; } else { errlogPrintf("parseChanAttrAndVal: error\n"); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsParseXMLFlag, ("parseChanAttrAndVal: error\n")); #endif return ERROR; } } int fillZid(int* dest, const char* str) { char *token; char *search = "id"; token = strtok((char*)str, search); printf("token is %s\n",token); *dest = 0; /* blah */ return OK; } /*============================================================================= Name: mpsParseDebounceConfig 12/19/8 now that there is no longer a file (sql table) defining these (because they are now given, both enum and time, on a per channel basis, it is harder to fill in the lookup table, debounceTimes, that maps enums to times. i.e. what do you do if you already have the time for a given enum and it is different??? =============================================================================*/ int mpsParseDebounceConfig(char* filename) { FILE *fp; char data[MPS_LINE_LENGTH]; int debounceenum, debouncetimemicroseconds; char debouncetimestring[100]; /* not used */ int ii; if (strlen(filename) == 0) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsParseDebounceConfigFlag, ("filename is NULL\n")); #endif errlogPrintf("mpsParseDebounceConfig: NULL filename\n"); return ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsParseDebounceConfigFlag, ("mpsParseDebounceConfig: parsing %s\n", filename)); #endif fp = fopen(filename, "r"); /*if (fp < 0) errlogPrintf("mpsParseDebounceConfig: fopen returns %s\n", strerror(*fp));*/ if (fp == NULL) { errlogPrintf("mpsParseDebounceConfig: NULL filename\n"); return ERROR; } while (fgets(data, MPS_LINE_LENGTH, fp) != NULL) { /* comments start with '#' */ if (data[0] != '#') { sscanf(data, "%d,%d,%s", &debounceenum, &debouncetimemicroseconds, &(*debouncetimestring)); debounceTimes[debounceenum] = debouncetimemicroseconds; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsParseDebounceConfigFlag, ("mpsParseDebounceConfig: %d %d %s\n", debounceenum, debouncetimemicroseconds, debouncetimestring)); #endif } } fclose(fp); #ifdef DEBUG_PRINT for (ii = 0; ii < 8; ii++ ) { DEBUGPRINT(DP_INFO, drvMpsParseDebounceConfigFlag, ("mpsParseDebounceConfig: debounceTimes[%d] = %d\n", ii, debounceTimes[ii])); } #endif return OK; } /*============================================================================= Name: mpsReportDebounceConfig =============================================================================*/ int mpsReportDebounceConfig() { int ii; printf("Enum\tTime(usec)\n"); for (ii=0; ii<8; ii++) { printf("%d %d\n", ii, debounceTimes[ii]); } return OK; } /*============================================================================= Name: mpsParseNodeConfig We need only one thing from this file. We need the link node type enum for this link node id If there is no entry for this link node id, initialise should fail =============================================================================*/ int mpsParseNodeConfig(char* filename) { FILE *fp; char data[MPS_LINE_LENGTH]; char rest[MPS_LINE_LENGTH]; int faultnumber, isautorecoverable, linknodeid, linknodetypeenum; int found = 0; if (strlen(filename) == 0) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsParseNodeConfigFlag, ("filename is NULL\n")); #endif errlogPrintf("mpsParseNodeConfig: NULL filename\n"); return ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsParseNodeConfigFlag, ("mpsParseNodeConfig: parsing %s\n", filename)); #endif fp = fopen(filename, "r"); /* 12/3/8. behavior for fopen differs from the unix man page. if file was missing read by other, it did NOT set fp to NULL and return (as man page claims. it made pb harder to find. If I make the file unreadable by other, errno is still 0! printf("errno is %d\n", errno); printf("str(errno) is %d\n", strerr(errno)); */ if (fp == NULL) { errlogPrintf("mpsParseNodeConfig: NULL filename\n"); return ERROR; } while ((fgets(data, MPS_LINE_LENGTH, fp) != NULL) && (!found)) { /* comments start with '#' */ if (data[0] != '#') { sscanf(data, "%d,%d,%d,%d,%s", &faultnumber, &isautorecoverable, &linknodeid, &linknodetypeenum, &(*rest)); if (linknodeid == pNode->linknodeid) { /* Set the link node type enum in the node/channel structure and in the register */ printf("mpsParseNodeConfig: call mpsSetLinkNodeType\n"); mpsSetLinkNodeType(linknodetypeenum); found = 1; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsParseNodeConfigFlag, ("mpsParseNodeConfig: link node type enum=%d\n", linknodetypeenum)); #endif #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsParseNodeConfigFlag, ("mpsParseNodeConfig: faultnumber=%d isautorecoverable=%d linknodeid=%d linknodetypeenum=%d\n", faultnumber, isautorecoverable, linknodeid, linknodetypeenum)); #endif } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsParseNodeConfigFlag, ("mpsParseNodeConfig: id read: %d doesn't match this id: %d\n", linknodeid, pNode->linknodeid)); #endif } } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsParseNodeConfigFlag, ("mpsParseNodeConfig: ignoring '%s'\n", data)); #endif } } fclose(fp); if (!found) { errlogPrintf("mpsParseNodeConfig: no type found for this node in config file\n"); return ERROR; } return OK; } /*============================================================================= Name: mpsParseNodeRackConfig We need the rack location and whether it is locked for this link node id If there is no entry for this link node id, initialise should fail =============================================================================*/ int mpsParseNodeRackConfig(char* filename) { FILE *fp; char data[MPS_LINE_LENGTH]; char rack[MPS_LINE_LENGTH]; int linknodeid, locked; int found = 0; if (strlen(filename) == 0) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsParseNodeConfigFlag, ("filename is NULL\n")); #endif errlogPrintf("mpsParseNodeRackConfig: NULL filename\n"); return ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsParseNodeConfigFlag, ("mpsParseNodeRackConfig: parsing %s\n", filename)); #endif fp = fopen(filename, "r"); /* 12/3/8. behavior for fopen differs from the unix man page. if file was missing read by other, it did NOT set fp to NULL and return (as man page claims. it made pb harder to find. If I make the file unreadable by other, errno is still 0! printf("errno is %d\n", errno); printf("str(errno) is %d\n", strerr(errno)); */ if (fp == NULL) { errlogPrintf("mpsParseNodeRackConfig: NULL filename\n"); return ERROR; } while ((fgets(data, MPS_LINE_LENGTH, fp) != NULL) && (!found)) { /* comments start with '#' */ if (data[0] != '#') { sscanf(data, "%d,%d,%s", &linknodeid, &locked, &(*rack)); if (linknodeid == pNode->linknodeid) { /* mpsSetRackLocation(rack); out 3/13/9 */ mpsSetRackLocked(locked); /*mpsSetLinkNodeRackLock(locked);*/ found = 1; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsParseNodeConfigFlag, ("mpsParseNodeRackConfig: link node %d is in rack %s with lock status %d (0=no, 1=yes)\n", linknodeid, rack, locked)); #endif } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsParseNodeConfigFlag, ("mpsParseNodeRackConfig: id read: %d doesn't match this id: %d\n", linknodeid, pNode->linknodeid)); #endif } } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsParseNodeConfigFlag, ("mpsParseNodeRackConfig: ignoring '%s'\n", data)); #endif } } fclose(fp); if (!found) { errlogPrintf("mpsParseNodeRackConfig: no type found for this node in config file\n"); return ERROR; } return OK; } /*============================================================================= Name: mpsSetCard =============================================================================*/ int mpsSetCard(channel,card) { pNode->inputchannels[channel].inputcard = card; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetCardFlag, ("mpsSetCard: node's abs input channel %d has card: %d\n", channel, pNode->inputchannels[channel].inputcard)); #endif return OK; } /*============================================================================= Name: mpsSetCardChannel =============================================================================*/ int mpsSetCardChannel(channel,cardChannel) { pNode->inputchannels[channel].inputcardchannel = cardChannel; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetCardChannelFlag, ("mpsSetCardChannel: node's abs input channel %d has cardChannel: %d\n", channel, pNode->inputchannels[channel].inputcardchannel)); #endif return OK; } /*============================================================================= Name: mpsParseChannelsConfig Abs: Read SQLite txt file and parse out attributes for the link node and its channels NB: mpsInitialize is called by st.cmd prior to iocInit, so this is called by st.cmd after iocInit() to get the values from SQL into the PV vals. =============================================================================*/ int mpsParseChannelsConfig(char* filename) { FILE *fp; char data[MPS_LINE_LENGTH]; int faultnumber, linknodeid, card, cardchannel, isautorecoverable, deadman, debounceenum, debouncetime; int channel; int ii; int jj = 0; if (strlen(filename) == 0) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsParseChannelsConfigFlag, ("filename is NULL\n")); #endif errlogPrintf("mpsParseChannelsConfig: NULL filename\n"); return ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsParseChannelsConfigFlag, ("mpsParseChannelsConfig: parsing %s\n", filename)); #endif fp = fopen(filename, "r"); if (fp == NULL) { errlogPrintf("mpsParseChannelsConfig: NULL filename\n"); return ERROR; } while (fgets(data, MPS_LINE_LENGTH, fp) != NULL) { jj++; /* parse lines that are not comments which start with '#' */ if (data[0] != '#') { sscanf(data, "%d,%d,%d,%d,%d,%d,%d,%d", &faultnumber, &linknodeid, &card, &cardchannel, &isautorecoverable, &deadman, &debounceenum, &debouncetime); if (linknodeid == pNode->linknodeid) { /* link node ID matches. we need this data */ /* Get the values into the node/channel structure */ channel = (card - 1) * 16 + cardchannel - 1; if ((channel < 0 ) || (channel > MPS_NODE_NUM_CHANS)) { errlogPrintf("mpsParseChannelsConfig: out of range channel: %d\n", channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsParseChannelsConfigFlag, ("mpsParseChannelsConfig: out of range channel: %d\n", channel)); DEBUGPRINT(DP_ERROR, drvMpsParseChannelsConfigFlag, ("mpsParseChannelsConfig: for line: %d,%d,%d,%d,%d,%d,%d,%d\n", faultnumber, linknodeid, card, cardchannel, isautorecoverable, deadman, debounceenum, debouncetime)); #endif return ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsParseChannelsConfigFlag, (" %d: LN%d C=%d CH=%d ABS CH=%d AUTOR=%d DEAD=%d DEB_E=%d DEB_T=%d\n", jj, linknodeid, card, cardchannel, channel, isautorecoverable, deadman, debounceenum, debouncetime)); #endif mpsSetAutoRecoverable(channel, isautorecoverable); mpsSetDebounceEnum(channel,debounceenum); mpsSetDebounceTime(channel,debouncetime); mpsSetDeadMan(channel,deadman); mpsSetCard(channel,card); mpsSetCardChannel(channel,cardchannel); /* 12/19/8: NEW. Stopping use of mpsParseDebounce and now filling debounceTimes in from here. First, check for valid enum */ if (debounceenum >= MPS_DEBOUNCE_ENUMS) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsParseChannelsConfigFlag, ("mpsParseChannelsConfig: debounceenum: %d exceeds max. Aborting parse\n", debounceenum)); #endif fclose(fp); return ERROR; } /* Next, see if this enum has a time or if it's still unset */ if (debounceTimes[debounceenum] == -1) { /* unset. just set it */ debounceTimes[debounceenum] = debouncetime; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsParseChannelsConfigFlag, ("mpsParseChannelsConfig: setting debounceTimes[%d]=%d\n", debounceenum, debouncetime)); #endif } else { /* check for consistency. what is set should match debouncetime */ if (debounceTimes[debounceenum] != debouncetime) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsParseChannelsConfigFlag, (" corruption of debounce times? debounceTimes[%d]: %d != %d\n", debounceenum, debounceTimes[debounceenum], debouncetime)); #endif } } } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsParseChannelsConfigFlag, ("mpsParseChannelsConfig: line:%d id read:%d doesn't match:%d\n", jj, linknodeid, pNode->linknodeid)); #endif } } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsParseChannelsConfigFlag, ("mpsParseChannelsConfig: %d: ignoring '%s'\n", jj, data)); #endif } } fclose(fp); /* Check what debounceTimes are now set... */ #ifdef DEBUG_PRINT for (ii=0; iilinknodetype == MPS_PIC_MODE) { mpsDetectPICs(); } mpsInitialised = 1; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsInitialiseFlag, ("mpsInitialise: complete\n")); #endif } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsInitialiseFlag, ("mpsInitialise: already done, returning.\n")); #endif } return OK; } int startSyncReads() { /* Start the task that is going to update the "ACQ" type of acquired data */ drvMpsSyncReadThread = epicsThreadCreate( "syncRead", epicsThreadPriorityScanHigh, epicsThreadGetStackSize(epicsThreadStackMedium), (EPICSTHREADFUNC)mpsSyncReadRequest, (void*)NULL); if (drvMpsSyncReadThread < 0) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsInitialiseFlag, ("mpsInitialise: Unable to create thread 'syncRead'\n")); #endif return ERROR; } /* Create an event semaphore to handle access to the data */ data_ready = epicsEventCreate(0); if ( !data_ready ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsInitialiseFlag, ("mpsInitialise: Unable to create EPICS event\n")); #endif return ERROR; } return OK; } int mpsReadBenvFactory(const char* factoryString) { if (strlen(factoryString)>MPS_BENVVAR_LONG_STRING) { printf("factoryString is too long to store\n"); return ERROR; } printf("factoryString=%s\n", factoryString); strcpy(benvVars.factory,factoryString); return OK; } int mpsReadBenvRevision(const char* revisionString) { if (strlen(revisionString)>MPS_BENVVAR_LONG_STRING) { printf("revisionString is too long to store\n"); return ERROR; } printf("revisionString=%s\n", revisionString); strcpy(benvVars.revision,revisionString); return OK; } int mpsReadBenvSerial(const char* serialString) { if (strlen(serialString)>MPS_BENVVAR_LONG_STRING) { printf("serialString is too long to store\n"); return ERROR; } printf("serialString=%s\n", serialString); strcpy(benvVars.serialNumber,serialString); return OK; } int mpsReadBenvConsole(const char* consoleString) { if (strlen(consoleString)>MPS_BENVVAR_LONG_STRING) { printf("consoleString is too long to store\n"); return ERROR; } printf("consoleString=%s\n", consoleString); strcpy(benvVars.console,consoleString); return OK; } int mpsReadBenvKernel(const char* kernelString) { if (strlen(kernelString)>MPS_BENVVAR_LONG_STRING) { printf("kernelString is too long to store\n"); return ERROR; } printf("kernelString=%s\n", kernelString); strcpy(benvVars.kernel,kernelString); return OK; } int mpsReadBenvKernelArgs(const char* kernelArgsString) { if (strlen(kernelArgsString)>MPS_BENVVAR_LONG_STRING) { printf("kernelString is too long to store\n"); return ERROR; } printf("kernelArgsString=%s\n", kernelArgsString); strcpy(benvVars.kernelArgs,kernelArgsString); return OK; } int mpsReadBenvHWAddr0(const char* HWAddr0String) { if (strlen(HWAddr0String)>MPS_BENVVAR_LONG_STRING) { printf("HWAddr0 is too long to store\n"); return ERROR; } printf("HWAddr0String=%s\n", HWAddr0String); strcpy(benvVars.hwAddr0,HWAddr0String); return OK; } int mpsReadBenvFirmware(const char* FirmwareString) { if (strlen(FirmwareString)>MPS_BENVVAR_LONG_STRING) { printf("FirmwareString is too long to store\n"); return ERROR; } printf("FirmwareString=%s\n", FirmwareString); strcpy(benvVars.firmware,FirmwareString); return OK; } int mpsReadBenvStartPoint(const char* StartPointString) { if (strlen(StartPointString)>MPS_BENVVAR_LONG_STRING) { printf("StartPointString is too long to store\n"); return ERROR; } printf("StartPointString=%s\n", StartPointString); strcpy(benvVars.startPoint,StartPointString); return OK; } int mpsReadBenvRAMImage(const char* RAMImageString) { if (strlen(RAMImageString)>MPS_BENVVAR_LONG_STRING) { printf("RAMImageString is too long to store\n"); return ERROR; } printf("RAMImageString=%s\n", RAMImageString); strcpy(benvVars.ramImage,RAMImageString); return OK; } int mpsReadBenvCache(const char* CacheString) { if (strlen(CacheString)>MPS_BENVVAR_LONG_STRING) { printf("CacheString is too long to store\n"); return ERROR; } printf("CacheString=%s\n", CacheString); strcpy(benvVars.cache,CacheString); return OK; } int mpsReadBenvAutoboot(const char* autobootString) { int autobootTime; printf("autobootString=%s\n", autobootString); sscanf(autobootString, "%d", &autobootTime); benvVars.autobootTime = autobootTime; return OK; } int mpsReadBenvBootpEnable(const char* BootpEnableString) { if (strlen(BootpEnableString)>MPS_BENVVAR_LONG_STRING) { printf("BootpEnableString is too long to store\n"); return ERROR; } printf("BootpEnableString=%s\n", BootpEnableString); strcpy(benvVars.bootpEnable,BootpEnableString); return OK; } char* mpsGetFactory() { return(benvVars.factory); } char* mpsGetRevision() { return(benvVars.revision); } char* mpsGetSerial() { return(benvVars.serialNumber); } char* mpsGetConsole() { return(benvVars.console); } char* mpsGetKernel() { return(benvVars.kernel); } char* mpsGetKernelArgs() { return(benvVars.kernelArgs); } char* mpsGetHWAddr0() { return(benvVars.hwAddr0); } char* mpsGetFirmware() { return(benvVars.firmware); } char* mpsGetStartPoint() { return(benvVars.startPoint); } char* mpsGetRAMImage() { return(benvVars.ramImage); } char* mpsGetCache() { return(benvVars.cache); } int mpsGetAutobootTime() { return(benvVars.autobootTime); } char* mpsGetBootpEnable() { return(benvVars.bootpEnable); } unsigned short* mpsGetRawWaveform() { /* must be unsigned. they are offset binary [0,65535] */ return (unsigned short*) bykik_addr; } double* mpsGetWaveform(int rise, int run, int offset, int num_pts) { int ii; if (num_pts > 1000) { return (double*) NULL; } for (ii=0; ii