Coincidence Counter Protocols
=============================
Started 1 Dec 2008, astummer@physics.utoronto.ca



NOMENCLATURE
=================================================================
Unit:    The Coincidence Counter device.
Host:    Any computer controlling the unit.
MONITOR: An optional computer listening to UDP messages from the unit.



HOST CONNECTION NOTES
=================================================================
- Host initiates all transactions by sending commands.
- Unit will send data to host only as requested by host.
- Once a connection is made by the host sending data to the unit,
  the unit will refuse all other hosts (if any) and must be reset
  to accept a new host.
- Protocol is UDP, port 37829.
- first unit address is 192.168.1.132, ethernet 00:90:C2:D6:32:94.
- a packet must be sent by the host every second.  If no packet
  is sent then it must send a heartbeat.
- unit echos the heartbeats to show it is alive.
- a connection is considered alive after any packets recieved.
- a connection is considered lost if 2 or more heartbeats or data
  packets are missed.
- each data packet fits into one IP packet, set MTU >= 1026.
- if possible, set IP recieve buffer to > 8.3K.



MONITOR CONNECTION NOTES
=================================================================
- The monitor is optional.
- The unit sends the monitor status, warning and error messages.
- The monitor listens to any Rabbit based unit on the network.
- All Coincidence Counter monitor messages are text only and so
  may be directly printed on a monitor text box, possibly with
  time stamps added.
- The unit broadcasts on UDP to its subnet.
- The monitor is UDP, listen-only.
- Monitor is any address on 192.168.1.xxx subnet, port 6595.



COMMANDS SENT BY HOST TO RABBIT
=================================================================
Cmd  Size  Description and Details
---  ----  ------------------------------------------------------
 H     1   Heartbeat
 D    12   Delay lines setting
           Byte 0: The "D" command
                1: Channel 0 delay line, 8-bits according to device
             2-12: Channels 1 to 11.
 C     2   Pause and read all counters, then resume running
           Byte 0: The "C" command
                1: Number of packets to send, from 1 to 8, integer.
 P     1   Pause (does not affect counters)
 R     1   Run and collect coincidences
 T     1   Request experiment run time from "R" to "C" to "C"... (mS)
 X     1   Stop running and clear all counters
 F     1   Load fixed test data into counters.  First send "F",
           then "C" to read test data.  See table below.
NOTE ON "C": Each packet takes 30mS of Rabbit's time.  All counters
             are always running.  The only reason to show less than
             all counters is experiment pause time.  The only really
             usefull packet counts are 1, 2, 4 or 8.
             Packets  Counters  APDs
             =======  ========  ====
                1       256       8
                2       512       9
                4      1024      10
                8      2048      11
         


DATA SENT FROM RABBIT TO HOST
=================================================================
Cmd  Size  Description and Details
---  ----  ------------------------------------------------------
 H      1  Heartbeat echo
 T      5  Experiment run time from "R" to "C" to "C"... (mS)
           Byte 0: The "T" command
                1: Time, LS byte
                2: Time
                3: Time
                4: Time, MS byte
 C   1026  Counters
           Byte 0: The "C" command
                1: Packet number, 0 to 7
                2: First counter, LS byte
                3: First counter
                4: First counter
                5: First counter, MS byte
                6-1022: Counters 2 to 255
                1023: 256th counter, LS byte
                1024: 256th counter
                1025: 256th counter
                1026: 256th counter, MS byte

REFERENCE INFO ABOUT COUNTERS AND COUNTER PACKETS
=================================================================
Number of channels: 11
Number of counters: 2,048 (2^11)
Bits per counter: 32
Bytes per counter: 4
Total counter bytes: 8,192
Counters per packet: 256
Bytes per packet (inc header): 1,027
Packets to send all counters to host: 8
Packet #0 has counters #0    to #255
Packet #1 has counters #256  to #511
Packet #2 has counters #512  to #767
Packet #3 has counters #768  to #1023
Packet #4 has counters #1024 to #1279
Packet #5 has counters #1280 to #1535
Packet #6 has counters #1536 to #1791
Packet #7 has counters #1792 to #2047



RABBIT COMMANDS TO FPGA
=================================================================
Cmd  Description and Details
---  ------------------------------------------------------------
0x00 Reset counters and read pointers for counters
0x01 Run
0x02 Pause
0x03 Put next partial counter on data bus
0x04 Set fixed test counter data as described below
0x05 Reset read pointers for counters
0x06 Read version (0xvvrr: as "<vv version>.<rr revision>")
0x07 future use



RABBIT PORT MAPPING
=================================================================
Port I/O Description
---- --- --------------------------------------------------------
PA0   I  FPGA data bus D[0]
PA1   I  FPGA data bus D[1]
PA2   I  FPGA data bus D[2]
PA3   I  FPGA data bus D[3]
PA4   I  FPGA data bus D[4]
PA5   I  FPGA data bus D[5]
PA6   I  FPGA data bus D[6]
PA7   I  FPGA data bus D[7]

PB0   I  FPGA data bus D[15] (sic)
PB1   I  FPGA data bus D[8]
PB2   I  FPGA data bus D[9]
PB3   I  FPGA data bus D[10]
PB4   I  FPGA data bus D[11]
PB5   I  FPGA data bus D[12]
PB6   I  FPGA data bus D[13]
PB7   I  FPGA data bus D[14]

PC0   O  Delay lines serial clock
PC1   O  Delay lines Latch Enable
PC2   -  do not use, linked to PC3 as TXC
PC3   O  Display asyncronous data
PC4   O  Test pont "B"
PC5   O  Delay lines serial data
PC6   -  reserved by RCM4200
PC7   -  reserved by RCM4200

PD0   -  not used
PD1   -  not used
PD2   -  not used
PD3   -  not used
PD4   -  not used
PD5   -  not used
PD6   -  not used
PD7   -  not used

PE0   O  FPGA command bus CMD[0]
PE1   O  FPGA command bus CMD[1]
PE2   O  reserved by RCM4200
PE3   O  FPGA command bus CMD[2]
PE4   O  FPGA command bus CS
PE5   O  reserved by RCM4200
PE6   O  reserved by RCM4200
PE7   O  reserved by RCM4200



TEST COUNTER DATA, COMMAND "F"
=================================================================
Counter  Hex          Decimal
-------  -----------  -------------
  0      0x3DCC 01E0  1,036,780,000 (sum of all counters, always)
  1      0x0000 00FF  255
  2      0x0000 0100  256
  3      0x0000 FFFF  65,535
  4      0x0001 0000  65,536
  5      0x00FF FFFF  16,777,215
  6      0x0100 0000  16,777,216
  7      0xFFFF FFFF  4,294,967,295
  8      0x0000 03E8  1,000
  9      0x000F 4240  1,000,000
 10      0x3B9A CA00  1,000,000,000
 11      0x0000 0001  1
 12      0x0000 0002  2
 13      0x0000 0004  4
 14      0x0000 0008  8
 15      0x0000 0010  16
 16      0x0000 0020  32
 17      0x0000 0040  64
 18      0x0000 0080  128
 19      0x0000 0100  256
 20      0x0000 0200  512
 21      0x0000 0400  1,024
 22      0x0000 0800  2,048
 23      0x0000 1000  4,096
 24      0x0000 2000  8,192
 25      0x0000 4000  16,384
 26      0x0000 8000  32,768
 27      0x0001 0000  65,536
 28      0x0002 0000  131,072
 29      0x0004 0000  262,144
 30      0x0008 0000  524,288
 31      0x0010 0000  1,048,576
 32      0x0020 0000  2,097,152
 33      0x0040 0000  4,194,304
 34      0x0080 0000  8,388,608
 35      0x0100 0000  16,777,216
 36      0x0200 0000  33,554,432
 37      0x0400 0000  67,108,864
 38      0x0800 0000  134,217,728
 39      0x1000 0000  268,435,456
 40      0x2000 0000  536,870,912
 41      0x4000 0000  1,073,741,824
 42      0x8000 0000  2,147,483,648
 All others contain counter number, last is 2047.