/*============================================================================= 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 "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 */ /* not used */ #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 */ /* not used */ #define IO_TYPE (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 */ #define BY_KICK_ADC_DELAY (MPS_BASE_ADDR+0x009C) /* Register 39 */ /* not used */ #define BY_KICK_ADC_WIDTH (MPS_BASE_ADDR+0x00A0) /* Register 40 */ /* not used */ #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/PIC0 ID space */ /* Mem6 0x20FF-0x2080 IP Board 1 16Bit IP330 ADC/PIC1 ID space */ /* Mem7 0x20FF-0x2080 IP Board 1 16Bit IP330 ADC/PIC1 ID space */ /* Mem8 0x21FF-0x2180 IP Board 3 16Bit SPARE/PIC3 ID space */ /* 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 */ /* 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 */ /* 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 BLM_QADC_DOSE_MEMORY_BASE (BLM_MEMORY_BASE+0x5000) #define BLM_ADC_MEMORY_BASE (BLM_MEMORY_BASE+0x5730) #define PIC_MEMORY_BASE (MPS_BASE_ADDR+0x2400) #define BYK_MEMORY_BASE (MPS_BASE_ADDR+0x2400) #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_BENVVAR_LONG_STRING (50) #define MPS_BENVVAR_SHORT_STRING (8) 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; #ifdef DEBUG_PRINT int drvMpsFlag = 0; 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 drvMpsSetPICThresholdFlag = 0; int drvMpsGetPICThresholdFlag = 0; int drvMpsSetBYKThresholdFlag = 0; int drvMpsSetBLMThresholdFlag = 0; int drvMpsGetBLMThresholdFlag = 0; int drvMpsGetQADCFaultFlag = 0; int drvMpsSetQADCThresholdFlag = 0; int drvMpsQADCCSRFlag = 0; int drvMpsFiducialFlag = 0; int drvMpsGetADCDiagnosticFlag = 0; int drvMpsGetQADCBeamDoseFlag = 0; int drvMpsGetQADCTestDoseFlag = 0; int drvMpsAssembleDoseFlag = 0; int drvMpsSetQADCBaseThresholdFlag = 0; int drvMpsSetQADCTestThresholdFlag = 0; int drvMpsSetQADCBeamThresholdFlag = 0; int drvMpsCSR1Flag = 0; int drvMpsCSR2Flag = 0; int drvMpsCSR3Flag = 0; int drvMpsRegistersFlag = 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; LOCAL volatile unsigned long *input_debounce_addr12 = (unsigned long *) INPUT_POL_CNTL_ADDR0; /* Nothing is done with polarity registers */ 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 *ip_type = (unsigned long *) IP_TYPE; 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 *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_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; /****************************************************************************** Routines common to PIC and BLM ******************************************************************************/ /*************************** CSR1 ******************************/ /* bit 0 */ int mpsSetCSR1Reset() { unsigned short mask = 1; *qadc_csr1_addr |= mask; return OK; } /* there is no need for mpsGetCSR1Reset() because read always returns 0 */ /* bit 1 */ int mpsSetCSR1DiagnosticModeEnable() { unsigned short mask = 2; *qadc_csr1_addr |= mask; return OK; } /* bit 2 */ int mpsSetCSR1Arm() { unsigned short mask = 4; *qadc_csr1_addr |= mask; return OK; } /* bit 3 */ int mpsSetCSR1Enable() { unsigned short mask = 8; *qadc_csr1_addr |= mask; return OK; } /* bits 4 and 5 */ int mpsSetCSR1DiagnosticModeSelect(int val) { unsigned short mask = (val & 3) << 4; *qadc_csr1_addr |= mask; switch (val) { case 0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1DiagnosticModeSelect: Single-shot beam mode \n")); #endif break; case 1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1DiagnosticModeSelect: Single-shot test mode \n")); #endif break; case 2: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1DiagnosticModeSelect: Single-shot baseline mode \n")); #endif break; case 3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1DiagnosticModeSelect: Single-step mode \n")); #endif break; default: return ERROR; } return OK; } /* bits 6 and 7 */ int mpsSetCSR1TriggerSourceSelect(int val) { unsigned short mask = (val & 3) << 6; *qadc_csr1_addr |= mask; switch (val) { case 0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1TriggerSourceSelect: External Trigger 1\n")); #endif break; case 1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1TriggerSourceSelect: External Trigger 2\n")); #endif break; case 2: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1TriggerSourceSelect: Software Trigger\n")); #endif break; case 3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1TriggerSourceSelect: Reserved\n")); #endif break; default: return ERROR; } return OK; } /* bit 8 */ int mpsSetCSR1TriggerEdgeSelect(int val) { unsigned short mask = 256; switch (val) { case 0: *qadc_csr1_addr &= ~mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1TriggerEdgeSelect: Using falling edge of source trigger\n")); #endif break; case 1: *qadc_csr1_addr |= mask; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1TriggerEdgeSelect: Using rising edge of source trigger\n")); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1TriggerEdgeSelect: Unrecognized value: %d (should be 0 or 1)\n", val)); #endif return ERROR; } return OK; } /* bit 9 */ int mpsSetCSR1MissedTriggerStatus(int val) { unsigned short mask = 512; switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1MissedTriggerStatus: Unrecognized value: %d (should be 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR1MissedTriggerStatus() { int val; unsigned short mask = 512; val = (*qadc_csr1_addr & mask) >> 9; return val; } /* bit 10 */ int mpsSetCSR1SoftwareTrigger(int val) { unsigned short mask = 1024; switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1SoftwareTrigger: Unrecognized value: %d (should be 0 or 1)\n", val)); #endif return ERROR; } return OK; } /* bit 11 */ int mpsSetCSR1DataReady(int val) { unsigned short mask = 2048; switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsQADCCSRFlag, ("mpsSetCSR1DataReady: Unrecognized value: %d (should be 0 or 1)\n", val)); #endif return ERROR; } return OK; } int mpsGetCSR1DataReady() { int val; unsigned short mask = 2048; val = (*qadc_csr1_addr & mask) >> 11; return val; } /* bit 12 */ int mpsSetCSR1GateGeneratorSelect(int val) { unsigned short mask = 4096; switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR1GateGeneratorSelect() { int val; unsigned short mask = 4096; val = (*qadc_csr1_addr & mask) >> 12; return val; } /* bit 13 */ int mpsSetCSR1GateTriggerSelect(int val) { unsigned short mask = 8192; switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR1GateTriggerSelect() { int val; unsigned short mask = 8192; val = (*qadc_csr1_addr & mask) >> 13; return val; } /* bit 14 */ int mpsSetCSR1GatePolarity(int val) { unsigned short mask = 16384; switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR1GatePolarity() { int val; unsigned short mask = 16384; val = (*qadc_csr1_addr & mask) >> 14; return val; } /* bit 15 */ int mpsSetCSR1GateEnable(int val) { unsigned short mask = 32768; switch (val) { case 0: *qadc_csr1_addr &= ~mask; break; case 1: *qadc_csr1_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR1GateEnable() { int val; unsigned short mask = 32768; val = (*qadc_csr1_addr & mask) >> 15; 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 val; unsigned short mask = 1; 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 val; unsigned short mask = 2; val = (*qadc_csr2_addr & mask) >> 1; 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 val) { unsigned short mask = 16; switch (val) { case 0: *qadc_csr2_addr &= ~mask; break; case 1: *qadc_csr2_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR2TestPulseEnable () { int val; unsigned short mask = 16; val = (*qadc_csr2_addr & mask) >> 4; 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 val) { unsigned short mask = 32; switch (val) { case 0: *qadc_csr2_addr &= ~mask; break; case 1: *qadc_csr2_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR2TestPulsePolarity () { int val; unsigned short mask = 32; val = (*qadc_csr2_addr & mask) >> 5; 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 val) { unsigned short mask = 64; switch (val) { case 0: *qadc_csr2_addr &= ~mask; break; case 1: *qadc_csr2_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR2TestPulseTriggerSelect () { int val; unsigned short mask = 64; val = (*qadc_csr2_addr & mask) >> 6; 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 val) { unsigned short mask = 0xFF00; int counts; unsigned short intermediary; /* val is in ns */ /* convert ns to counts. 1 count = 25 ns */ counts = val/25; /* add 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() { unsigned int val; unsigned short mask = 0xFF00; val = (*qadc_csr2_addr & mask) >> 8; val += 2; val *= 25; return val; } /*************************** CSR3 ******************************/ /* bit 0: controls whether the sync output will be asserted or not */ int mpsSetCSR3SyncOutputEnable(int val) { unsigned short mask = 1; switch (val) { case 0: *qadc_csr3_addr &= ~mask; break; case 1: *qadc_csr3_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR3SyncOutputEnable() { int val; unsigned short mask = 1; val = *qadc_csr3_addr & mask; return val; } /* bit 1: controls the polarity of the sync signal */ int mpsSetCSR3SyncPulsePolarity(int val) { unsigned short mask = 2; switch (val) { case 0: *qadc_csr3_addr &= ~mask; break; case 1: *qadc_csr3_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR3SyncPulsePolarity() { int val; unsigned short mask = 2; val = *qadc_csr3_addr & mask; return val; } /* bit 2: controls the output mode of the sync signal */ int mpsSetCSR3SyncOutputMode(int val) { unsigned short mask = 4; switch (val) { case 0: *qadc_csr3_addr &= ~mask; break; case 1: *qadc_csr3_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR3SyncOutputMode() { int val; unsigned short mask = 4; val = *qadc_csr3_addr & mask; 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 val) { unsigned short mask = (val & 0xF) << 4; *qadc_csr1_addr |= mask; /* add dbg */ switch (val) { case 0: break; case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; case 8: break; case 9: break; case 10: break; case 11: break; case 12: break; case 13: break; case 14: break; case 15: break; default: return ERROR; } return OK; } int mpsGetCSR3SyncOutputPulseSourceSelectionMUX() { unsigned int val; unsigned short mask = 0xF0; val = (*qadc_csr2_addr & mask) >> 4; /* add dbg */ switch (val) { case 0: break; case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; case 8: break; case 9: break; case 10: break; case 11: break; case 12: break; case 13: break; case 14: break; case 15: break; /* default: complain */ } /* ensure range is [0,7] */ 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 val) { unsigned short mask = 0x800; switch (val) { case 0: *qadc_csr3_addr &= ~mask; break; case 1: *qadc_csr3_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR3ADCRangeControl() { int val; unsigned short mask = 0x800; val = *qadc_csr3_addr & mask; 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 val) { unsigned short mask = 0x4000; switch (val) { case 0: *qadc_csr3_addr &= ~mask; break; case 1: *qadc_csr3_addr |= mask; break; default: return ERROR; } return OK; } int mpsGetCSR3FBC() { int val; unsigned short mask = 0x4000; val = *qadc_csr3_addr & mask; return val; } /* bit 15: read only */ int mpsGetCSR3PICMode() { int val; unsigned short mask = 0x8000; val = *qadc_csr3_addr & mask; return val; } /***************************************************************************** Registers *****************************************************************************/ /* 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 val) { unsigned short delay; /* 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() { unsigned short val; /* read delay */ 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() { *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() { unsigned short val; /* read counter */ val = *qadc_trig_err_cnt_addr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsGetTriggerErrorCounter: %hu\n", val)); #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 val) { unsigned short delay; /* 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() { unsigned short val; /* read delay in counts */ 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 val) { unsigned short width; 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() { unsigned short val; /* read width in counts */ 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 val) { unsigned short delay; /* 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() { unsigned short val; /* read delay */ 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 val) { unsigned short width; 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() { unsigned short val; /* 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 val) { unsigned short delay; /* 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() { unsigned short val; /* 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 val) { unsigned short width; 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() { unsigned short val; /* 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 val) { unsigned short settings; 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() { unsigned short val; /* 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 val) { unsigned short delay; /* 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() { unsigned short val; /* read delay in counts */ 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 val) { unsigned short delay; 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() { unsigned short val; int delay; /* 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 val) { unsigned short delay; #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() { unsigned short val; int delay; /* read delay in counts */ 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 val) { unsigned short delay; /* 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() { unsigned short val; /* 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(unsigned short val) { *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() { unsigned short val; /* 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(unsigned short val) { *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() { unsigned short val; /* 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; } unsigned int mpsGetExtendedGateGeneratorWidth() { unsigned int val; unsigned short high; unsigned short low; high = mpsGetExtendedGateGeneratorWidthHigh(); low = mpsGetExtendedGateGeneratorWidthLow(); 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(unsigned int width) { unsigned short low; unsigned short high; /* convert from ns to counts */ width = width/25; low = (unsigned short) (width & 0xFFFF); high = (unsigned short) ((width & 0xFFFF0000) >> 16); mpsSetExtendedGateGeneratorWidthLow(low); mpsSetExtendedGateGeneratorWidthHigh(high); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, ("mpsSetExtendedGateGeneratorWidth: %d separated into\n ", width)); DEBUGPRINT(DP_INFO, drvMpsRegistersFlag, (" high: %hu and low: %hu\n", high, low)); #endif return OK; } /**************************************************************************** End of Registers *****************************************************************************/ /* num indicates which CSR register: 1,2 or 3 */ int mpsSetQADCCSR(int num, unsigned short val) { volatile unsigned short* addr; 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 num) { volatile unsigned short* addr; 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; } /* threshold is signed. 16-bit */ int mpsSetQADCBaseThreshold(int channel, int type, short threshold) { volatile short* pVal; unsigned int addr; /* don't check BLM_MODE. all nodes load all PVs. */ if (type == MPS_THLD_HIGH) { addr = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x24; pVal = (volatile short*) addr; /*TO DO pNode->blmChannels[channel].qadc.basehighthreshold = threshold;*/ } else { if (type == MPS_THLD_LOW) { addr = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x22; pVal = (volatile short *) addr; /*TO DO pNode->blmChannels[channel].qadc.baselowthreshold = threshold;*/ } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetQADCThresholdFlag, ("mpsSetQADCThreshold: invalid threshold type: %d\n", type)); #endif return ERROR; } } *pVal = threshold; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsSetQADCBaseThresholdFlag, ("mpsSetQADCBaseThreshold: channel: %d at addr: 0x%08x thld: %hd\n", channel, (unsigned int) addr, threshold)); #endif return OK; } /* threshold is signed. 16-bit */ int mpsSetQADCTestThreshold(int channel, int type, short threshold) { volatile short* pVal; unsigned int addr; /* don't check BLM_MODE. all nodes load all PVs. */ if (type == MPS_THLD_HIGH) { addr = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x20; pVal = (volatile short *) addr; /*TO DO pNode->blmChannels[channel].qadc.testhighthreshold = threshold;*/ } else { if (type == MPS_THLD_LOW) { addr = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x1E; pVal = (volatile short *) addr; /*TO DO pNode->blmChannels[channel].qadc.testlowthreshold = threshold;*/ } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetQADCTestThresholdFlag, ("mpsSetQADCThreshold: invalid threshold type: %d\n", type)); #endif return ERROR; } } *pVal = threshold; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvMpsSetQADCTestThresholdFlag, ("mpsSetQADCTestThreshold: channel: %d at addr: 0x%08x thld: %hd\n", channel, (unsigned int) addr, threshold)); #endif return OK; } int mpsSetQADCBeamThreshold(int channel, int type, short threshold) { volatile short* pVal; unsigned int addr; /* don't check BLM_MODE. all nodes load all PVs. */ if (type == MPS_THLD_HIGH) { addr = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x1C; pVal = (volatile short *) addr; /*TO DO pNode->blmChannels[channel].qadc.beamhighthreshold = threshold;*/ } else { if (type == MPS_THLD_LOW) { addr = BLM_QADC_DOSE_MEMORY_BASE + (channel*0x100) + 0x1A; pVal = (volatile short *) addr; /*TO DO pNode->blmChannels[channel].qadc.beamlowthreshold = threshold;*/ } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetQADCThresholdFlag, ("mpsSetQADCThreshold: invalid threshold type: %d\n", type)); #endif return ERROR; } } *pVal = threshold; return OK; } unsigned short mpsGetQADCBeamDose(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)); 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; } 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; } long assembleTwoByteDose(unsigned short low) { long dose; dose = (long) low; 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; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsAssembleDoseFlag, ("assembleDose: 0x%8x\n", (unsigned int) dose)); #endif return dose; } long assembleDose(unsigned short low, unsigned short high) { long dose; /* OLD WAY dose = (high << 16) | low; */ /* NEW WAY: */ 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; } 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; } long mpsAssembleBeamDose(int channel, int time) { long dose; unsigned short low; unsigned short high; switch (time) { case -1: /* baseline */ low = mpsGetQADCBeamDose(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(channel, 0, MPS_BYTES_LOW); dose = assembleTwoByteDose(low); break; case 1: /* accumulated 1 second dosage data */ low = mpsGetQADCBeamDose(channel, 1, MPS_BYTES_LOW); high = mpsGetQADCBeamDose(channel, 1, MPS_BYTES_HIGH); 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(channel, 10, MPS_BYTES_LOW); high = mpsGetQADCBeamDose(channel, 10, MPS_BYTES_HIGH); dose = assembleDose(low,high); break; case 30: /* accumulated 1/30 second dosage data */ low = mpsGetQADCBeamDose(channel, 30, MPS_BYTES_LOW); high = mpsGetQADCBeamDose(channel, 30, MPS_BYTES_HIGH); 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(channel, 60, MPS_BYTES_LOW); high = mpsGetQADCBeamDose(channel, 60, MPS_BYTES_HIGH); dose = assembleDose(low,high); break; default: /* complain */ return 0; } /* report */ 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; } short mpsGetADCDiagnostic(int offset) { short val; volatile short* base_addr = (volatile short*) (BLM_ADC_MEMORY_BASE + offset); 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; } short 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; } 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 currentLen; /* get the one line contents into the version */ fp = fopen(current, "r"); /* TODO check fp ok */ fgets(temp, MPS_LINE_LENGTH, fp); printf("mpsGetDatabaseVersion: %s\n", temp); currentLen = strlen(temp); /* 1/20/9: remove blanks on the end if they are present */ while (temp[currentLen]==' ') { currentLen--; } /* Need this for dev, but not for prod!!!! diff version of fgets? if(temp[currentLen]=='\0') { currentLen--; } NEED FOR DEV, BUT DON'T DO THIS IN PRODUCTION */ strncpy(pNode->databaseVersion, temp, currentLen); 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() { int fault; fault = (*virtual_input_card_sts >> 6) & 1; return fault; } int mpsGetBYKUnderThresholdFault() { int fault; fault = (*virtual_input_card_sts >> 5) & 1; return fault; } int mpsGetBXKickLatch() { int fault; fault = (*virtual_input_card_sts >> 4) & 1; return fault; } int mpsGet30HzStdbyTriggerMissed() { int fault; fault = (*virtual_input_card_sts >> 3) & 1; return fault; } int mpsGet30HzAbortTriggerMissed() { int fault; fault = (*virtual_input_card_sts >> 2) & 1; return fault; } int mpsGet120HzStdbyTriggerMissed() { int fault; fault = (*virtual_input_card_sts >> 1) & 1; return fault; } int mpsGet120HzAbortTriggerMissed() { int fault; fault = *virtual_input_card_sts & 1; 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() { *link_node_control = 8; /* it takes 20 ms to read out the FPGA @ 8 MHz. the wicked fast coldfire reads 16 bits at 16 MHz, so hang back a bit */ sleep(0.02); return OK; } int mpsGetQADCReadoutStatus() { unsigned long status; status = (*link_node_control >> 3) & 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 short *addr; /* 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, drvMpsSetBLMThresholdFlag, ("mpsSetBLMHVThreshold: channel is out of range: %d\n", channel)); #endif return ERROR; } /* Now can update the threshold */ if (thld_type == MPS_THLD_HIGH) { addr = (short *)(BLM_HV_THRESHOLD_BASE + (channel*4) + 2); pNode->blmChannels[channel].highthreshold = threshold; } else { if (thld_type == MPS_THLD_LOW) { addr = (short *)(BLM_HV_THRESHOLD_BASE + (channel*4)); pNode->blmChannels[channel].lowthreshold = threshold; } else { /*errlogPrintf("mpsSetBLMHVThreshold: invalid threshold type: %d\n", thld_type);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetBLMThresholdFlag, ("mpsSetBLMHVThreshold: invalid threshold type: %d\n", thld_type)); #endif return ERROR; } } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetBLMThresholdFlag, ("mpsSetBLMHVThreshold: ch: %d, type:%d (0=low, 1=high), val:%hd to addr: 0x%08x\n", channel, thld_type, threshold, (unsigned int) addr)); #endif *addr = threshold; return OK; } int mpsGetBLMThreshold(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("mpsGetBLMThreshold: channel is out of range: %d\n", channel);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetBLMThresholdFlag, ("mpsGetBLMThreshold: 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].highthreshold; } else { if (thld_type == MPS_THLD_LOW) { addr = (volatile short *)(BLM_HV_THRESHOLD_BASE + (channel*4)); thresholdFromReg = *addr; thresholdFromStruct = pNode->blmChannels[channel].lowthreshold; } else { /*errlogPrintf("mpsGetBLMThreshold: invalid threshold type: %d\n", thld_type);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetBLMThresholdFlag, ("mpsGetBLMThreshold: invalid threshold type: %d\n", thld_type)); #endif return ERROR; } } /* Ensure register consistent with structure contents */ if (thresholdFromReg != thresholdFromStruct) { /*errlogPrintf("mpsGetBLMThreshold: mismatch threshold in reg has: %d, in struct it's: %d\n", thresholdFromReg, thresholdFromStruct);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetBLMThresholdFlag, ("mpsGetBLMThreshold: mismatch threshold in reg has: %d, in struct it's: %d\n", thresholdFromReg, thresholdFromStruct)); #endif } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetBLMThresholdFlag, ("mpsGetBLMThreshold: %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; } int mpsSetPICThreshold(int pic, int channel, int thld_type, int threshold) { volatile short *addr; /* don't check PIC_MODE. all nodes load all PVs and this causes errors. */ /* check */ if ((pic < 0) || (pic > 3)) { /*errlogPrintf("mpsSetPICThreshold: pic is out of range: %d\n", pic);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetPICThresholdFlag, ("mpsSetPICThreshold: pic is out of range: %d\n", pic)); #endif return ERROR; } /* check */ if ((channel < 0) || (channel > 7)) { /*errlogPrintf("mpsSetPICThreshold: channel is out of range: %d\n", channel);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetPICThresholdFlag, ("mpsSetPICThreshold: channel is out of range: %d\n", channel)); #endif return ERROR; } /* Prepare to access the PIC by setting pic number in reg #49 */ *pic_select = pic; /* Now that pic_select knows which pic, can update the threshold */ if (thld_type == MPS_THLD_HIGH) { addr = (short *)(PIC_THRESHOLD_BASE + (channel*0x100) + 0x24); pNode->pics[pic].picchannels[channel].highthreshold = threshold; } else { if (thld_type == MPS_THLD_LOW) { addr = (short *)(PIC_THRESHOLD_BASE + (channel*0x100) + 0x22); pNode->pics[pic].picchannels[channel].lowthreshold = threshold; } else { /*errlogPrintf("mpsSetPICThreshold: invalid threshold type: %d\n", thld_type);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsSetPICThresholdFlag, ("mpsSetPICThreshold: invalid threshold type: %d\n", thld_type)); #endif return ERROR; } } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetPICThresholdFlag, ("mpsSetPICThreshold: pic: %d, ch: %d, type:%d (0=low, 1=high), val:%hd\n", pic, channel, thld_type, threshold)); #endif *addr = threshold; return OK; } /* New 12/1/8 */ int mpsGetPICThreshold(int pic, int channel, int thld_type) { volatile short *addr; short thresholdFromReg; short thresholdFromStruct; /* don't check PIC_MODE. all nodes load all PVs and this causes errors. */ /* check */ if ((pic < 0) || (pic > 3)) { /*errlogPrintf("mpsGetPICThreshold: pic is out of range: %d\n", pic);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetPICThresholdFlag, ("mpsGetPICThreshold: pic is out of range: %d\n", pic)); #endif return ERROR; } /* check */ if ((channel < 0) || (channel > 7)) { /*errlogPrintf("mpsGetPICThreshold: channel is out of range: %d\n", channel);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetPICThresholdFlag, ("mpsGetPICThreshold: channel is out of range: %d\n", channel)); #endif return ERROR; } /* Prepare to access the PIC by setting pic number in reg #49 */ *pic_select = pic; /* Do a setup step in order to be able to read */ *link_node_control = 8; /* 1/12/9: check! necess? not doing this for blm thld */ /* 1/20/9: per 1/16/9 changes for BLM, this step may not be removable if triggers in ops obviate it */ if (thld_type == MPS_THLD_HIGH) { addr = (volatile short *)(PIC_THRESHOLD_BASE + (channel*0x100) + 0x24); thresholdFromReg = *addr; thresholdFromStruct = pNode->pics[pic].picchannels[channel].highthreshold; } else { if (thld_type == MPS_THLD_LOW) { addr = (volatile short *)(PIC_THRESHOLD_BASE + (channel*0x100) + 0x22); thresholdFromReg = *addr; thresholdFromStruct = pNode->pics[pic].picchannels[channel].lowthreshold; } else { /*errlogPrintf("mpsGetPICThreshold: invalid threshold type: %d\n", thld_type);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetPICThresholdFlag, ("mpsGetPICThreshold: invalid threshold type: %d\n", thld_type)); #endif return ERROR; } } /* Ensure register consistent with structure contents */ if (thresholdFromReg != thresholdFromStruct) { /*errlogPrintf("mpsGetPICThreshold: mismatch threshold in reg has: %d, in struct it's: %d\n", thresholdFromReg, thresholdFromStruct);*/ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvMpsGetPICThresholdFlag, ("mpsGetPICThreshold: mismatch threshold in reg has: %d, in struct it's: %d\n", thresholdFromReg, thresholdFromStruct)); #endif } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsGetPICThresholdFlag, ("mpsGetPICThreshold: %hd for pic: %d, ch: %d, type:%d (0=low, 1=high)\n", thresholdFromReg, pic, channel, thld_type)); #endif return OK; } /* 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. */ int mpsGetQADCFault(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_INFO, drvMpsGetQADCFaultFlag, ("mpsGetQADCFault: unrecognized type: %d for channel: %d\n", channel, type)); #endif } /* Do a setup step in order to be able to read CHECK needed in production *link_node_control = 8; take this out 1/26/09!!!!!!!!! */ fault = *addr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, 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; } } } 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; } 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; } } } 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; int filtered; state = pNode->inputchannels[channel].state; /* filtered = mpsGetLatchedReg(channel); 2/23/9 should be mpsGetStateReg!!!!*/ filtered = mpsGetStateReg(channel); if (state == filtered) { /*errlogPrintf("mpsGetState: state does not match !filtered and it must. ch: %d state: mem has: %d; filtered: reg has: %d\n", channel, state, filtered); */ return ERROR; } return state; } /* Note: threshold scaling and offset is done by device support (ao record) */ /* Incoming "threshold" is in counts, ranging from 0 to 65535 */ int mpsSetBYKThreshold(int threshold_type, int threshold) { volatile unsigned short *addr; unsigned short thld; thld = (unsigned short) threshold; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetBYKThresholdFlag, ("mpsSetBYKThreshold: top. threshold type:%d threshold: %hu counts [0,65535]\n", threshold_type, thld)); #endif /* check */ if (pNode->linknodetype != MPS_BYKIK_MODE) { /* errlogPrintf("mpsSetBYKThreshold: MPS Link Node is wrong type: %d\n", pNode->linknodetype);*/ return ERROR; } if (threshold_type == MPS_THLD_LOW) { addr = (volatile unsigned short*)BYKIK_THLD_LO_ADDR; pNode->BYKThresholdLow = threshold * 20/65525 -10.; /* 6feb2009 chg */ /* BYKThresholdLowCounts is needed to display on xy graph in correct scale as raw waveform pNode->BYKThresholdLowCountsArray[0] = 65535 / 20 * (threshold - (-10)); pNode->BYKThresholdLowCountsArray[1] = 65535 / 20 * (threshold - (-10)); */ pNode->BYKThresholdLowCountsArray[0] = thld; pNode->BYKThresholdLowCountsArray[1] = thld; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetBYKThresholdFlag, ("mpsSetBYKThreshold: set low threshold to: %d\n", pNode->BYKThresholdLow)); DEBUGPRINT(DP_INFO, drvMpsSetBYKThresholdFlag, ("mpsSetBYKThreshold: set low threshold counts to: %d\n", pNode->BYKThresholdLowCountsArray[0])); #endif } else { if (threshold_type == MPS_THLD_HIGH) { addr = (volatile unsigned short*)BYKIK_THLD_HI_ADDR; pNode->BYKThresholdHigh = threshold * 20/65525 -10.; /* 6feb2009 chg */ /* BYKThresholdLowCounts is needed to display on xy graph in correct scale as raw waveform pNode->BYKThresholdHighCountsArray[0] = 65535 /20 * (threshold - (-10)); pNode->BYKThresholdHighCountsArray[1] = 65535 /20 * (threshold - (-10));*/ pNode->BYKThresholdHighCountsArray[0] = thld; pNode->BYKThresholdHighCountsArray[1] = thld; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvMpsSetBYKThresholdFlag, ("mpsSetBYKThreshold: set high threshold to: %d\n", pNode->BYKThresholdHigh)); DEBUGPRINT(DP_INFO, drvMpsSetBYKThresholdFlag, ("mpsSetBYKThreshold: set high threshold counts to: %hd\n", pNode->BYKThresholdHighCountsArray[0])); #endif } else { return ERROR; } } *addr = thld; return OK; } /* TODO: -1 gets returned as value of threshold if anything goes wrong. This could cause more problems */ short mpsGetBYKThreshold(int threshold_type) { volatile short *addr; /*errlogPrintf("mpsGetBYKThreshold: invasive to FPGA!!!!\n");*/ /* check */ if (pNode->linknodetype != MPS_BYKIK_MODE) { /* errlogPrintf("mpsGetBYKThreshold: MPS Link Node is wrong type: %d\n", pNode->linknodetype);*/ return (short) ERROR; } if (threshold_type == MPS_THLD_LOW) { addr = (volatile short*)BYKIK_THLD_LO_ADDR; } else { if (threshold_type == MPS_THLD_HIGH) { addr = (volatile short*)BYKIK_THLD_HI_ADDR; } else { /* errlogPrintf("mpsGetBYKThreshold: MPS Link Node has bad threshold type: %d\n", threshold_type);*/ return (short) ERROR; } } 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; } } } int mpsSetBYKADCNumPresamples(int number) { volatile short* addr; addr = (volatile short *) BYKIK_ADC_NPSAMP_ADDR; *addr = (short) number; pNode->BYKADCNumPresamples = number; return OK; } short mpsGetBYKADCNumPresamples(void) { volatile short* addr; /*errlogPrintf("mpsGetBYKADCNumPresamples: invasive to FPGA!!!!\n");*/ addr = (volatile short *) BYKIK_ADC_NPSAMP_ADDR; return *addr; } int mpsSetBYKADCNumSamples(int number) { volatile short* addr; addr = (volatile short *) BYKIK_ADC_NSAMP_ADDR; *addr = (short) number; pNode->BYKADCNumSamples = number; return OK; } short mpsGetBYKADCNumSamples() { volatile short* addr; /*errlogPrintf("mpsGetBYKADCNumSamples: invasive to FPGA!!!!\n");*/ addr = (volatile short *) BYKIK_ADC_NPSAMP_ADDR; return *addr; } int mpsSetBYKADCDelay(int number) { volatile short* addr; addr = (volatile short *) BYKIK_ADC_DLY_ADDR; *addr = (short) number; pNode->BYKADCDelay = number; return OK; } short mpsGetBYKADCDelay() { volatile short* addr; /*errlogPrintf("mpsGetBYKDelay: invasive to FPGA. no read done\n");*/ addr = (volatile short *) BYKIK_ADC_DLY_ADDR; return *addr; } int mpsPICReport(int pic) { int ii; printf ("MPS PIC %d Report\n", pic); for (ii = 0; ii < 8; ii++) { printf (" PIC:%d, ch:%d, highthld:%d, lowthld:%d\n", pic, ii, pNode->pics[pic].picchannels[ii].highthreshold, pNode->pics[pic].picchannels[ii].lowthreshold); } 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); if (pNode->linknodetype == MPS_PIC_MODE) { printf ("MPS Link Node has 4 PICs\n\n"); for (ii = 0; ii < MPS_NODE_NUM_CHANS; ii++) { mpsPICReport(ii); } } if (pNode->linknodetype == MPS_BYKIK_MODE) { printf (" BYK high threshold: %d\n", pNode->BYKThresholdHigh); printf (" BYK high threshold counts: %d\n", pNode->BYKThresholdHighCountsArray[0]); printf (" BYK low threshold: %d\n", pNode->BYKThresholdLow); printf (" BYK low threshold counts: %d\n", pNode->BYKThresholdLowCountsArray[0]); 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 ("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); 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)); #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; iiMPS_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 */ return (unsigned short*) bykik_addr; } short* mpsGetWaveform(int rise, int run, int offset, int num_pts) { int ii; if (num_pts > 1000) { return (short*) NULL; } for (ii=0; ii