# Precision Receiver Chassis (PRC) Firmware

The current version of this firmware is (the top level Verilog module is `prc.v`) is a combination of the RFS and PRC builds, which will eventually be split into two.
To generate the PRC bitfile run:

	$ make prc.bit

To program the Kintex-7 with the PRC application firmware, go to the `prc/run/` directory and type:

	$ python prc.py -a 192.168.1.127 -b ../prc_vivado.bit -r

Note that `192.168.1.127` is the default Spartan IP address, please adapt accordingly if it has been modified.

## BMB7 v1.5

The principles above also apply to generate and load bitfiles on the BMB7 v1.5, which has been baptized as [Sesqui](https://en.wikipedia.org/wiki/Sesqui) (Latin for one-and-a-half times). To generate a bitfile for the BMB7 v1.5 (Sesqui):

	$ make prc_sesqui.bit

`prc.py` will use detect the presence (or absence) of sesqui in the file name to check if it is headed for the right version of the BMB7. To program the Kintex on the v1.5 BMB7, type:

	$ python prc.py -a 192.168.1.127 -b ../prc_sesqui_vivado.bit -r

If you adhere to this file naming convention, the worst that can happen is that prc.py will give you the error message "Bitfile name interlock failed".
If you attempt to override this feature, hardware will probably not be damaged, but the board will certainly not do anything useful with the wrong bitfile loaded.

## Kivy GUI

To launch the Kivy user interface:

	$ cd prc_plotter
	$ make
	$ cd ethio/kivy
	$ cd ..
	$ ln -s ../../prc/run/prc_plotter prc_plotter
	$ python kivy/main.py

## CMOC

Building and running the CryoModule On Chip (CMOC) simulator:
1. Uncomment the `define CMOC in real_sim_mux.v
2. Uncomment the `define PLACEHOLDER_PIEZO in sel4v/piezo_control.v

```
make prc_tb && make prc.bit
```

## Register mappings

|   **dac_mode** |   **DAC i (chassis Tx 2)**  |   **DAC q (chassis Tx 1)**  |
|:----------:|:---------:|:----------:|
| 1 | DAC test pattern | 0 |
| 2 | 0 | DAC test pattern |
| 4 | Stimulus signal | 0 |
| 5 | 0 | Stimulus signal |
| 10 | Controller Output (Cavity 2) | Controller output (Cavity 1) |
| 11 | Controller Output (Cavity 1) | Controller output (Cavity 2) |


The stimulus signal is controllable through a separate register (`ssa_sim_en`) as shown below, where DDS stands for Digital Direct Synthesizer and the SSA stimulus signal is used to characterize the SSAs:

|   **ssa_sim_en** |   **stim_out**  |
|:----------:|:---------:|
| 0 | CW DDS |
| 1 | SSA stimulus signal |

## Front Panel LEDs

Five LEDs show up on the chassis front panel.  **D5** is hardware-only
showing presence of +3.3V.  The others are FPGA-defined; the current
features are:

**D1**: Chassis health

| state        | pattern       |
|:------------:|:-------------:|
| initial      |  6 Hz  25%    |
| clock good   |  1.5 Hz  75%  |
| crc pass     |  0.75 Hz  94% |

**D2**: Network activity

| state                 | pattern     |
|:---------------------:|:-----------:|
| UDP traffic to Kintex |  1.5 Hz 50% |
| otherwise             |  dark       |

**D3**: RF Tx1/cavity status and
**D4**: RF Tx2/cavity status

| state              | pattern    |
|:------------------:|:----------:|
| off                | dark       |
| enabled            | 3 Hz 25%   |
| amplitude locked * | 1.5 Hz 75% |
| fully locked *     | solid on   |
&#42; Not yet implemented

The four LEDs also show a test pattern for the first two seconds
after the bitfile is loaded.

As implemented in [fp_leds.v](fp_leds.v) in this directory.

## FPGA Utilization

See [resource.md](resource.md) in this directory.
