diff --git a/fast-servo/pyfastservo/adc.py b/fast-servo/pyfastservo/adc.py index a3fd106..69fefcf 100644 --- a/fast-servo/pyfastservo/adc.py +++ b/fast-servo/pyfastservo/adc.py @@ -21,7 +21,7 @@ import mmap import os import spidev -from common import ( +from pyfastservo.common import ( ADC_AFE_CTRL_ADDR, ADC_BITSLIP_ADDR, ADC_CH0_HIGH_ADDR, diff --git a/fast-servo/pyfastservo/common.py b/fast-servo/pyfastservo/common.py index b14c44b..dbf60ab 100644 --- a/fast-servo/pyfastservo/common.py +++ b/fast-servo/pyfastservo/common.py @@ -22,8 +22,8 @@ MAP_SIZE = 0x1000 MAP_MASK = 0xFFF PAGESIZE = 0x1000 -LINIEN_OFFSET = 0x0 -# LINIEN_OFFSET = 0x300000 +# LINIEN_OFFSET = 0x0 +LINIEN_OFFSET = 0x300000 # ---------------------------------------------------------------- # FRONT PANEL LEDS REGISTER ADDRESSES diff --git a/fast-servo/pyfastservo/dac.py b/fast-servo/pyfastservo/dac.py index 33bf477..e16a14a 100644 --- a/fast-servo/pyfastservo/dac.py +++ b/fast-servo/pyfastservo/dac.py @@ -21,7 +21,7 @@ import mmap import os import spidev -from common import ( +from pyfastservo.common import ( CH0_HIGH_WORD_ADDR, CH0_LOW_WORD_ADDR, CH1_HIGH_WORD_ADDR, diff --git a/fast-servo/pyfastservo/fp_leds.py b/fast-servo/pyfastservo/fp_leds.py index 7bd2347..dfda8b0 100644 --- a/fast-servo/pyfastservo/fp_leds.py +++ b/fast-servo/pyfastservo/fp_leds.py @@ -21,7 +21,7 @@ import mmap import os import time -from common import ( +from pyfastservo.common import ( LED0_BASE_ADDR, LED1_BASE_ADDR, LED2_BASE_ADDR, diff --git a/fast-servo/pyfastservo/initialize.py b/fast-servo/pyfastservo/initialize.py index 12f9ca7..9adeb2b 100644 --- a/fast-servo/pyfastservo/initialize.py +++ b/fast-servo/pyfastservo/initialize.py @@ -17,9 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import adc -import si5340 -import dac +from pyfastservo import adc, si5340, dac def main(): si5340.configure_si5340() diff --git a/flake.nix b/flake.nix index 082d9c2..04d3e58 100644 --- a/flake.nix +++ b/flake.nix @@ -180,6 +180,27 @@ ''; }; + pyfastservo = pkgs-armv7l.python3Packages.buildPythonPackage rec { + name = "pyfastservo"; + src = ./fast-servo; + preBuild = '' + cat > setup.py << EOF + from setuptools import setup + + setup( + name="pyfastservo", + packages=["pyfastservo"], + install_requires=["spidev", "smbus2"], + entry_points = {"console_scripts": ["fp_leds=pyfastservo.fp_leds:main"]}, + ) + EOF + ''; + propagatedBuildInputs = with pkgs-armv7l.python3Packages; [ + spidev + smbus2 + ]; + }; + mkbootimage = pkgs.stdenv.mkDerivation { pname = "mkbootimage"; version = "2.3dev"; @@ -209,8 +230,25 @@ extraModules = [ "${patched-not-os}/zynq_image.nix" ] ++ pkgs.lib.optionals (board == "fast-servo") [ - ({ config, pkgs, ... }: { - environment.systemPackages = [ linien-server ]; + ({ config, pkgs, lib, ... }: { + environment.systemPackages = [ + linien-server + (pkgs.python3.withPackages(ps: [ pyfastservo ])) + ]; + boot.postBootCommands = lib.mkAfter '' + + # Program the FPGA + set +x + echo "Flashing bitstream..." + echo 0 > /sys/class/fpga_manager/fpga0/flags + mkdir -p /lib/firmware + cp ${fast-servo-gateware}/gateware.bin /lib/firmware/ + echo gateware.bin > /sys/class/fpga_manager/fpga0/firmware + + # Run device init scripts + echo "Initializing clock generator, ADC, and DAC..." + python3 -m pyfastservo.initialize + ''; })]; system = "x86_64-linux"; inherit crossSystem; @@ -387,7 +425,7 @@ BASE=$(realpath $(dirname $0)) qemu-img convert -O qcow2 -f raw -o preallocation=metadata $BASE/sd-image.img $IMGDIR/sd-sparse.qcow2 - qemu-img create -F qcow2 -f qcow2 -b $IMGDIR/sd-sparse.qcow2 $IMGDIR/sd-overlay.qcow2 1G + qemu-img create -F qcow2 -f qcow2 -b $IMGDIR/sd-sparse.qcow2 $IMGDIR/sd-overlay.qcow2 2G # Some command arguments are based from samples in Xilinx QEMU User Documentation # See: https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/821854273/Running+Bare+Metal+Applications+on+QEMU