Browse Source

Initial commit

Matthias Vogelgesang 9 years ago
commit
6c0bf6b79b
3 changed files with 184 additions and 0 deletions
  1. 14 0
      Makefile
  2. 110 0
      reset.sh
  3. 60 0
      status.sh

+ 14 - 0
Makefile

@@ -0,0 +1,14 @@
+prefix ?= /usr/local
+exec_prefix ?= $(prefix)
+bindir ?= $(exec_prefix)/bin
+
+
+.PHONY: install
+
+install:
+	install -D -m 755 reset.sh $(bindir)
+	install -D -m 755 status.sh $(bindir)
+
+uninstall:
+	rm -f $(bindir)/reset.sh
+	rm -f $(bindir)/status.sh

+ 110 - 0
reset.sh

@@ -0,0 +1,110 @@
+#!/bin/bash
+
+PCI=$(which pci)
+
+# if [ -z "$PCI" ]; then
+#     echo "pcitool not found."
+#     exit 1
+# fi
+
+function reset_dma () {
+    pci --stop-dma dma0r
+    sleep .1
+    pci --start-dma dma0r
+    sleep .1
+    #check that all of the buffers are on the x1000 addresses
+    local VAR=`cat /sys/class/fpga/fpga0/kbuf* | grep bus | cut -c 16- | grep -v 000`
+    local i=0
+
+    while [ -n "$VAR" ]; do
+        echo $VAR
+        exit
+        i=$(echo $i + 1 | bc)
+        num=`cat /sys/class/fpga/fpga0/kbuf* | grep bus | cut -c 16- | grep -v 000 | grep -c [1-9]`
+        echo "Buffer addresses not aligned; Redo:" $i " times," $num "buffers unaligned"
+        pci --stop-dma dma0r
+        sleep .1
+        pci --start-dma dma0r
+        sleep .05
+        VAR=`cat /sys/class/fpga/fpga0/kbuf* | grep bus | cut -c 16- | grep -v 000`
+        if [ "$i" -gt 10 ]; then
+            echo "ERROR!!! Addresses still not aligned, stopping!"
+            break
+        fi
+    done
+
+    if [ -z "$VAR" ]; then
+        echo -e "\e[32mBuf addr aligned\033[1;m"
+    else
+        echo -e "\e[31mBuf addr UNALIGNED!!!\033[1;m"
+    fi
+
+    sleep 0.1
+    echo "Enable DMA"
+    pci -w 0x4 0x1
+    sleep 0.1
+    echo "set 4k AXI packet size"
+    pci -w 0x9100 0x20001000
+}
+
+function reset_logic () {
+    pci -w 0x9040 80000005
+    sleep .1
+    pci -w 0x9040 80000001
+    sleep .1
+}
+
+function reset_cmosis () {
+    pci -w 0x9040 80000000
+    sleep .3
+    pci -w 0x9040 80000001
+    sleep .3
+}
+
+function check_status () {
+    status=`pci -r 0x9050 -s 4 | awk '{print $2$3$4}'`
+    if [ "$status" != "8449ffff0000300100000000" ]; then
+        echo -e "\e[31m--------------------------------->>>> ERROR! in the camera status ...\033[1;m"
+        echo $status
+        error=1
+    fi
+
+    if [ "$error" = "1" ]; then
+        echo -e "\e[31mError in the reset and initialization\033[1;m"
+    else
+        echo -e "\e[32mCamera READY ........................... OK\033[1;m"
+    fi
+}
+
+for i in "$@"; do
+    case $i in
+        --dma)
+            RESET_DMA=YES
+            shift
+            ;;
+        --logic)
+            RESET_LOGIC=YES
+            shift
+            ;;
+        --cmosis)
+            RESET_CMOSIS=YES
+            shift
+            ;;
+        *)
+            ;;
+    esac
+done
+
+if [ "$RESET_DMA" ]; then
+    reset_dma
+fi
+
+if [ "$RESET_LOGIC" ]; then
+    reset_logic
+fi
+
+if [ "$RESET_CMOSIS" ]; then
+    reset_cmosis
+fi
+
+check_status

+ 60 - 0
status.sh

@@ -0,0 +1,60 @@
+#!/bin/bash
+
+BAR=`pci -i | grep "BAR 0" | awk '{print $6}' | cut -c -6` # it was -4 for cut, uros
+
+echo "Status ... "
+
+pci -r $BAR"9000" -s 80
+
+value=`pci -r 0x9110 -s 8 | grep 9110 | awk '{print $2}' | cut -c 1-8`
+
+sensor_tmp=${value:4:4}
+fpga_tmp=${value:0:4}
+fpga_mon=${value:0:1}
+
+sleep 0.01
+
+value=`pci -r 9030 | awk '{print $2}' | cut -c 6-6`
+
+if [ "$value" == "0"  ]; then
+    echo "40 MHz"
+    clk_mhz=40
+    clk_ratio=$(echo "scale = 2; 40/40" | bc)
+else
+    echo "48 MHz"
+    clk_mhz=48
+    clk_ratio=$(echo "scale = 2; 48/40" | bc)
+fi
+
+# for 48 MHz use 48/40, for 40 MHz use 40/40 for clk_ratio offset can differ per
+# device
+
+offset_zero_celsius=$(echo "scale = 2; 1000*$clk_ratio " | bc)
+tmp_slope_sensor=$(echo "scale = 2; 0.3/$clk_ratio" | bc)
+
+# fpga monitor
+let "fpga_mon=16#$fpga_mon"
+fpga_mon=$(echo "ibase=10;obase=2;$fpga_mon" | bc)
+fpga_mon=$(printf "%04d\n" $fpga_mon)
+monitor_val=${fpga_mon:0:3}
+
+# fpga temperature
+let "fpga_tmp=16#$fpga_tmp"
+fpga_tmp=$(echo "ibase=10;obase=2;$fpga_tmp" | bc)
+fpga_tmp=$(printf "%016d\n" $fpga_tmp)
+let "fpga_adc=2#${fpga_tmp:3:10}"
+fpga_tmp=$(echo "scale = 2; (($fpga_adc*503.975)/1024.)-273.15   " |bc)
+
+# sensor temperature
+let "sensor_tmp=16#$sensor_tmp"
+# use 48/40 for 40MHz, or 40/40 for 40 MHz main clock
+sensor_tmp=$(echo "scale = 2; ($sensor_tmp-$offset_zero_celsius)*$tmp_slope_sensor" | bc)
+
+# echo "Sensor temperature,according to the datasheet: $sensor_tmp C"
+echo "Sensor temperature, clock $clk_mhz MHz: $sensor_tmp C"
+echo "FPGA temperature: $fpga_tmp C"
+if [ "$monitor_val" != "000" ]; then
+    echo "ERROR FPGA MONITOR: $monitor_val"
+else
+    echo "MONITOR OK"
+fi