echo "Loading nxyter read-out configuration"
+case $1 in
+ 0x38*)
+ board=$1
+ ;;
+ *)
+ echo "Wrong board!"
+ exit
+ ;;
+esac
+
# i2c_sm_reset
-trbcmd w 0x3800 0x8100 0x01
+trbcmd w $board 0x8100 0x01
# i2c_reg_reset_start
-trbcmd w 0x3800 0x8101 0x01
+trbcmd w $board 0x8101 0x01
# Write nxsetup.dat to memory and transfer to nx-i2c-registers
-trbcmd wm 0x3800 0x8200 0 nxsetup.dat
+echo "Using nxsetup_$board.dat"
+trbcmd wm $board 0x8200 0 nxsetup_${board}.dat
+
+
+# Data Validate
+trbcmd w $board 0x8120 1 # reset all counters
+
+# Trigger Validate
+trbcmd w $board 0x8400 0 # set readout mode
+trbcmd w $board 0x8401 0 # window offset
+trbcmd w $board 0x8402 0x0064 # window width 400ns
+trbcmd setbit $board 0x8419 0x80000000 # Disable WaitForData
+
+CTS_DELAY=0
+ADC_OFF=0
+case $board in
+ 0x3800)
+ CTS_DELAY=210
+ ADC_OFF=1
+ ;;
+
+ 0x3801)
+ CTS_DELAY=210
+ ADC_OFF=1
+ ;;
+
+ 0x3810)
+ CTS_DELAY=175
+ ADC_OFF=0
+ ;;
-trbcmd w 0x3800 0x8212 150
+ 0x3811)
+ CTS_DELAY=175
+ ADC_OFF=0
+ ;;
+
+ *)
+ echo "Wrong board!"
+ ;;
+esac
-# nx_ts_reset_start
-trbcmd w 0x3800 0x8102 0x01
+trbcmd loadbit $board 0x8403 0x0000ffff $CTS_DELAY
+trbcmd loadbit $board 0x8403 0xffff0000 $((CTS_DELAY << 16))
+if [ $ADC_OFF -eq 1 ] ; then
+ trbcmd w $board 0x8504 0x80000000
+fi
-# reset counters, flush FIFO
-echo "clear data fifo"
-trbcmd rm 0x3800 0x8600 4000 2>/dev/null
+# Turn on SEU
+trbcmd w $board 0xd500 1
-# Set readout Mode
-trbcmd w 0x3800 0x8400 0x00 # 0: normal mode 4: no TS Window mode
-trbcmd w 0x3800 0x8401 50 # window offset 200ns
-trbcmd w 0x3800 0x8402 200 # window width 800ns
-trbcmd w 0x3800 0x8403 100 # CTS-Delay 400ns
+# Data Receiver
+#trbcmd w $board 0x8507 5 # PLLDPhase, default is 5
-# Decoder Settings
-trbcmd w 0x3800 0x8120 0 # reset all counters
+# TS Cut Level2 140 220 [ns]
+trbcmd w $board 0x8420 0x007d0064
-# Enable nxyter
-trbcmd w 0x3800 0x8103 0
+# HistRange
+trbcmd w $board 0x8421 2
-#Debugging to test ADC alignment / reset feature
-# sleep 1;
-# trbcmd w 0x3800 0x8501 1
+# Turn off Status Trigger, enable Physics and Calibration Trigger
+trbcmd w $board 0x8166 0x02
+#Enable Testpulse
+trbcmd w $board 0x8253 1