JLab Signal Distribution Switch Slot module  A5
 All Data Structures Files Functions Variables Macros Groups
sdLib.h
Go to the documentation of this file.
1 
24 #ifndef SDLIB_H
25 #define SDLIB_H
26 
27 #define SD_SUPPORTED_FIRMWARE 0xA5
28 
29 #define TEST
30 /* JLab SD Register definitions (defined within TI/TS register space) */
31 struct SDStruct
32 { unsigned int blankSD0[(0x3C00-0x0000)/4]; volatile unsigned int system; volatile unsigned int status; volatile unsigned int payloadPorts; volatile unsigned int tokenPorts; volatile unsigned int busyoutPorts; volatile unsigned int trigoutPorts; unsigned int RFU0; volatile unsigned int busyoutStatus; volatile unsigned int trigoutStatus; volatile unsigned int busyoutCounter[16]; volatile unsigned int busyoutTest; volatile unsigned int sdLinkTest; volatile unsigned int tokenInTest; volatile unsigned int trigOutTest; volatile unsigned int tokenOutTest; volatile unsigned int statBitBTest; volatile unsigned int version; volatile unsigned int csrTest; volatile unsigned int trigoutCounter[16]; volatile unsigned int clkACounterTest; volatile unsigned int clkBCounterTest; unsigned int blankSD1[(0x3D14-0x3CCC)/4]; volatile unsigned int memAddrLSB; volatile unsigned int memAddrMSB; volatile unsigned int memWriteCtrl; volatile unsigned int memReadCtrl; volatile unsigned int memCheckStatus; unsigned int blankSD2[(0x10000-0x3D28)/4];
62 };
63 
64 /* Initialization flags */
65 #define SD_INIT_IGNORE_VERSION (1<<0)
66 
67 /* 0x0 system bits and masks */
68 #define SD_SYSTEM_CLKA_BYPASS_MODE (1<<0)
69 #define SD_SYSTEM_CLKA_FREQUENCY_MASK 0x000C
70 #define SD_SYSTEM_CLKB_BYPASS_MODE (1<<4)
71 #define SD_SYSTEM_CLKB_FREQUENCY_MASK 0x00C0
72 #define SD_SYSTEM_TI_LINK_ENABLE (1<<9)
73 #define SD_SYSTEM_TEST_RESET (1<<15)
74 
75 /* 0x4 status bits and masks */
76 #define SD_STATUS_CLKB_LOSS_OF_SIGNAL (1<<0)
77 #define SD_STATUS_CLKB_LOSS_OF_LOCK (1<<1)
78 #define SD_STATUS_CLKA_LOSS_OF_SIGNAL (1<<2)
79 #define SD_STATUS_CLKA_LOSS_OF_LOCK (1<<3)
80 #define SD_STATUS_POWER_FAULT (1<<4)
81 #define SD_STATUS_TRIGOUT (1<<5)
82 #define SD_STATUS_BUSYOUT (1<<6)
83 #define SD_STATUS_CLKA_DETECTED_MASK 0x300
84 #define SD_STATUS_CLKA_DETECTED_UNKNOWN (0<<8)
85 #define SD_STATUS_CLKA_DETECTED_31_25 (1<<8)
86 #define SD_STATUS_CLKA_DETECTED_125 (2<<8)
87 #define SD_STATUS_CLKA_DETECTED_250 (3<<8)
88 #define SD_STATUS_CLKB_DETECTED_MASK 0xC00
89 #define SD_STATUS_CLKB_DETECTED_UNKNOWN (0<<10)
90 #define SD_STATUS_CLKB_DETECTED_31_25 (1<<10)
91 #define SD_STATUS_CLKB_DETECTED_125 (2<<10)
92 #define SD_STATUS_CLKB_DETECTED_250 (3<<10)
93 
94 #define SD_CSRTEST_CLKA_PLL_BYPASS (1<<0)
95 #define SD_CSRTEST_CLKA_TEST_STATUS (1<<1)
96 #define SD_CSRTEST_CLKA_FREQ ((1<<2)|(1<<3))
97 #define SD_CSRTEST_CLKB_PLL_BYPASS (1<<4)
98 #define SD_CSRTEST_CLKB_TEST_STATUS (1<<5)
99 #define SD_CSRTEST_CLKB_FREQ ((1<<6)|(1<<7))
100 #define SD_CSRTEST_TI_BUSYOUT (1<<8)
101 #define SD_CSRTEST_TI_TOKENIN (1<<9)
102 #define SD_CSRTEST_TI_GTPLINK (1<<10)
103 #define SD_CSRTEST_SWA_LOOPBACK0 (1<<11)
104 #define SD_CSRTEST_SWA_LOOPBACK1 (1<<12)
105 #define SD_CSRTEST_SWA_LOOPBACK2 (1<<13)
106 #define SD_CSRTEST_SWA_LOOPBACK_MASK (SD_CSRTEST_SWA_LOOPBACK0|SD_CSRTEST_SWA_LOOPBACK1|SD_CSRTEST_SWA_LOOPBACK2)
107 #define SD_CSRTEST_TEST_RESET (1<<15)
108 
109 /* Bits and Masks used for Remote Programming */
110 #define SD_MEMADDR_LSB_MASK 0xFFFF
111 #define SD_MEMADDR_MSB_MASK 0x00FF
112 #define SD_MEMWRITECTRL_DATA_MASK 0x00FF
113 #define SD_MEMWRITECTRL_WRITE (1<<8)
114 #define SD_MEMWRITECTRL_WREN (1<<9)
115 #define SD_MEMWRITECTRL_SHIFT_BYTES (1<<10)
116 #define SD_MEMWRITECTRL_SECTOR_ERASE (1<<12)
117 #define SD_MEMWRITECTRL_SECTOR_PROTECT (1<<13)
118 #define SD_MEMREADCTRL_DATA_MASK 0x00FF
119 #define SD_MEMREADCTRL_READ (1<<8)
120 #define SD_MEMREADCTRL_RDEN (1<<9)
121 #define SD_MEMREADCTRL_READ_STATUS (1<<10)
122 #define SD_MEMREADCTRL_NEGATE_BUSY (1<<11)
123 
124 
125 /* SD routine prototypes */
126 int sdInit(int flag);
127 int sdStatus();
128 int sdGetFirmwareVersion(int pflag);
129 int sdSetTiFastLink(int enable);
130 int sdGetTiFastLink();
131 int sdSetPLLClockFrequency(int iclk, int ifreq);
132 int sdGetPLLClockFrequency(int iclk);
133 int sdGetClockFrequency(int iclk, int pflag);
134 int sdSetClockMode(int iclk, int imode);
135 int sdGetClockMode(int iclk);
136 int sdReset();
137 int sdSetActivePayloadPorts(unsigned int imask);
138 int sdSetActiveVmeSlots(unsigned int vmemask);
140 int sdGetBusyoutCounter(int ipayload);
142 int sdGetTrigoutCounter(int ipayload);
144 int sdGetBusyoutStatus(int pflag);
145 
146 #ifndef VXWORKSPPC
147 int sdFirmwareFlushFifo();
148 int sdFirmwareLoadFile(char *filename);
149 void sdFirmwareFreeMemory();
150 int sdFirmwareVerifyPage(unsigned int mem_addr);
151 int sdFirmwareVerifyPageZero(unsigned int mem_addr);
152 void sdFirmwareWritePage(unsigned int mem_addr);
157 void sdFirmwareWriteSpecs(unsigned int addr, unsigned int serial_number,
158  unsigned int hall_board_version, unsigned int firmware_version);
160 #endif
161 
162 int sdFirmwareReadAddr(unsigned int addr);
163 unsigned int sdGetSerialNumber(char *rSN);
164 
165 /* SD Test Mode routines */
166 int sdTestGetBusyout();
167 int sdTestGetSdLink();
168 int sdTestGetTokenIn();
169 int sdTestGetTrigOut();
170 void sdTestSetTokenOutMask(int mask);
171 void sdTestSetStatBitBMask(int mask);
172 void sdTestSetClkAPLL(int mode);
174 int sdTestGetClockAFreq();
175 void sdTestSetClkBPLL(int mode);
177 int sdTestGetClockBFreq();
178 void sdTestSetTIBusyOut(int level);
179 int sdTestGetTITokenIn();
180 void sdTestSetTIGTPLink(int level);
181 unsigned int sdTestGetClkACounter();
182 unsigned int sdTestGetClkBCounter();
183 unsigned int sdTestGetSWALoopback();
184 
185 #endif /* SDLIB_H */
volatile unsigned int trigoutStatus
0x3C20
Definition: sdLib.h:42
unsigned int blankSD2[(0x10000-0x3D28)/4]
0x3D28
Definition: sdLib.h:61
void sdFirmwareFreeMemory()
Free the memory allocated to store the firmware.
Definition: sdLib.c:1418
int sdGetTrigoutCounter(int ipayload)
Return the value of the Trigout Counter for a specified payload board Value of the counter is reset a...
Definition: sdLib.c:1208
int sdFirmwareFlushFifo()
Flush the FIFO used in write data to the ROM.
Definition: sdLib.c:1315
void sdTestSetClkAPLL(int mode)
Set the PLL mode for Clock A (LHS of crate).
Definition: sdLib.c:2149
int sdFirmwareVerifyPageZero(unsigned int mem_addr)
Verify the page of data starting a specified memory address, is zero.
Definition: sdLib.c:1501
volatile unsigned int memReadCtrl
0x3D20
Definition: sdLib.h:59
unsigned int blankSD0[(0x3C00-0x0000)/4]
0x0000
Definition: sdLib.h:33
volatile unsigned int system
0x3C00
Definition: sdLib.h:34
volatile unsigned int status
0x3C04
Definition: sdLib.h:35
volatile unsigned int sdLinkTest
0x3C68
Definition: sdLib.h:45
int sdPrintBusyoutCounters()
Display (to standard out) values of the busy counters for all VME Slots.
Definition: sdLib.c:1137
int sdSetActivePayloadPorts(unsigned int imask)
Routine for user to define the Payload Ports that participate in Trigger Out, Busy Out...
Definition: sdLib.c:975
volatile unsigned int csrTest
0x3C80
Definition: sdLib.h:51
unsigned int sdTestGetClkBCounter()
Get the counter associated with the Clock B Frequency during period of 0.1ms.
Definition: sdLib.c:2457
void sdTestSetStatBitBMask(int mask)
Set StatBitB levels HI to those payload ports specified in mask.
Definition: sdLib.c:2115
Definition: sdLib.h:31
int sdTestGetClockAFreq()
Return the Clock A Frequency. This test was bypassed during acceptance testing.
Definition: sdLib.c:2213
void sdTestSetTIBusyOut(int level)
Set the Busy OUT level to the TI.
Definition: sdLib.c:2335
int sdTestGetTITokenIn()
Get the input level from the TI TokenIN.
Definition: sdLib.c:2366
int sdGetActivePayloadPorts()
Routine to return the currently defined Payload Ports that participate in Trigger Out...
Definition: sdLib.c:1062
int sdTestGetSdLink()
Return the asserted level from the TI over the SDlink.
Definition: sdLib.c:1996
volatile unsigned int clkACounterTest
0x3CC4
Definition: sdLib.h:53
int sdReset()
Reset the SD.
Definition: sdLib.c:946
int sdTestGetBusyout()
Return the mask of busy's asserted from the payload ports.
Definition: sdLib.c:1967
volatile unsigned int busyoutCounter[16]
0x3C24
Definition: sdLib.h:43
int sdGetBusyoutStatus(int pflag)
Return the mask value of payload ports that are currently BUSY.
Definition: sdLib.c:1174
int sdTestGetClockBStatus()
Return the amount of clocks ticks that occurred for a two second period after the Clock A Mode was se...
Definition: sdLib.c:2275
int sdTestGetTokenIn()
Return payload port mask of those payload modules asserting TokenIN.
Definition: sdLib.c:2025
volatile unsigned int busyoutStatus
0x3C1C
Definition: sdLib.h:41
int sdSetTiFastLink(int enable)
Enable or Disable the Fast link to the TI.
Definition: sdLib.c:644
int sdGetTiFastLink()
Return the state of the fast link to the TI.
Definition: sdLib.c:675
unsigned int sdTestGetSWALoopback()
Return the bit mask of levels sent from the SWA Module. This test was bypassed during acceptance test...
Definition: sdLib.c:2486
int sdInit(int flag)
Initialize the Signal Distribution Module.
Definition: sdLib.c:86
int sdSetPLLClockFrequency(int iclk, int ifreq)
Set the PLL Clock Frequency of A/B/Both.
Definition: sdLib.c:711
int sdFirmwareVerifyMemory()
Verify that SD's ROM contains exactly the contents of the firmware.
Definition: sdLib.c:1704
void sdTestSetTokenOutMask(int mask)
Set TokenOUT levels HI to those payload ports specified in mask.
Definition: sdLib.c:2083
int sdTestGetTrigOut()
Return payload port mask of those payload modules asserting TrigOUT.
Definition: sdLib.c:2054
volatile unsigned int busyoutPorts
0x3C10
Definition: sdLib.h:38
int sdFirmwareLoadFile(char *filename)
Load the specified file containing the firmware, into local memory.
Definition: sdLib.c:1355
int sdGetFirmwareVersion(int pflag)
Return and optionally display the SD firmware version.
Definition: sdLib.c:610
volatile unsigned int clkBCounterTest
0x3CC8
Definition: sdLib.h:54
int sdGetClockFrequency(int iclk, int pflag)
Return the detected clock frequency for the selected iclk.
Definition: sdLib.c:802
int sdFirmwareReadStatus()
Check the read status of the FIFO.
Definition: sdLib.c:1769
volatile unsigned int memCheckStatus
0x3D24
Definition: sdLib.h:60
unsigned int sdTestGetClkACounter()
Get the counter associated with the Clock A Frequency during period of 0.1ms.
Definition: sdLib.c:2429
int sdFirmwareVerifyPage(unsigned int mem_addr)
Verify the page of data starting a specified memory address.
Definition: sdLib.c:1434
volatile unsigned int memAddrLSB
0x3D14
Definition: sdLib.h:56
void sdTestSetTIGTPLink(int level)
Set the GTP Link output to the TI.
Definition: sdLib.c:2398
unsigned int RFU0
0x3C18
Definition: sdLib.h:40
int sdFirmwareWriteToMemory()
Write entire firmware to SD's ROM.
Definition: sdLib.c:1620
volatile unsigned int version
0x3C7C
Definition: sdLib.h:50
int sdTestGetClockAStatus()
Return the amount of clocks ticks that occurred for a two second period after the Clock A Mode was se...
Definition: sdLib.c:2183
int sdStatus()
int sdFirmwareReadAddr(unsigned int addr)
Read a specific address from the ROM.
Definition: sdLib.c:1885
void sdFirmwareWritePage(unsigned int mem_addr)
Write a page of data starting a specified memory address.
Definition: sdLib.c:1573
volatile unsigned int trigOutTest
0x3C70
Definition: sdLib.h:47
int sdPrintTrigoutCounters()
Display (to standard out) values of the trigout counters for all VME Slots.
Definition: sdLib.c:1240
volatile unsigned int memAddrMSB
0x3D18
Definition: sdLib.h:57
volatile unsigned int statBitBTest
0x3C78
Definition: sdLib.h:49
volatile unsigned int tokenOutTest
0x3C74
Definition: sdLib.h:48
void sdTestSetClkBPLL(int mode)
Set the PLL mode for Clock B (LHS of crate).
Definition: sdLib.c:2244
unsigned int sdGetSerialNumber(char *rSN)
Return the serial number of the SD.
Definition: sdLib.c:1933
int sdTestGetClockBFreq()
Return the Clock B Frequency. This test was bypassed during acceptance testing.
Definition: sdLib.c:2305
volatile unsigned int memWriteCtrl
0x3D1C
Definition: sdLib.h:58
volatile unsigned int payloadPorts
0x3C08
Definition: sdLib.h:36
int sdGetClockMode(int iclk)
Return whether the Clock fanned out will be jitter attenuated (PLL) or as received from the TI(D) ...
Definition: sdLib.c:913
int sdSetActiveVmeSlots(unsigned int vmemask)
Routine for user to define the Vme Slots that participate in Trigger Out, Busy Out, Token, and Status communication.
Definition: sdLib.c:1017
volatile unsigned int busyoutTest
0x3C64
Definition: sdLib.h:44
unsigned int blankSD1[(0x3D14-0x3CCC)/4]
0x3CCC
Definition: sdLib.h:55
volatile unsigned int tokenPorts
0x3C0C
Definition: sdLib.h:37
int sdSetClockMode(int iclk, int imode)
Select whether the Clock fanned out will be jitter attenuated (PLL on) or as received from the TI...
Definition: sdLib.c:865
int sdGetPLLClockFrequency(int iclk)
Return the PLL clock frequency for the selected iclk.
Definition: sdLib.c:760
volatile unsigned int tokenInTest
0x3C6C
Definition: sdLib.h:46
int sdGetBusyoutCounter(int ipayload)
Return the value of the Busyout Counter for a specified payload board Value of the counter is reset a...
Definition: sdLib.c:1105
volatile unsigned int trigoutPorts
0x3C14
Definition: sdLib.h:39
volatile unsigned int trigoutCounter[16]
0x3C84
Definition: sdLib.h:52