Browse Source

added script for taking frames

Uros Stevanovic 9 years ago
parent
commit
c1788a148d
3 changed files with 250 additions and 1 deletions
  1. 2 0
      Makefile
  2. 2 1
      README.md
  3. 246 0
      grab.sh

+ 2 - 0
Makefile

@@ -6,11 +6,13 @@ bindir ?= $(exec_prefix)/bin
 .PHONY: install
 
 install:
+	install -D -m 755 grab.sh $(bindir)
 	install -D -m 755 reload.sh $(bindir)
 	install -D -m 755 reset.sh $(bindir)
 	install -D -m 755 status.sh $(bindir)
 
 uninstall:
+	rm -f $(bindir)/grab.sh
 	rm -f $(bindir)/reload.sh
 	rm -f $(bindir)/reset.sh
 	rm -f $(bindir)/status.sh

+ 2 - 1
README.md

@@ -4,4 +4,5 @@ Install with `make install` or `prefix=/usr make install`. Use as follows:
 
     $ reload.sh         # unload and reload driver
     $ reset.sh --all    # set up registers
-    $ status.sh
+    $ status.sh --verbose # show full status
+    $ grab.sh --single # takes a single frame

+ 246 - 0
grab.sh

@@ -0,0 +1,246 @@
+#!/bin/bash
+
+PCI=$(which pci)
+NAME=bench.out
+TIMEOUT=100000
+SLEEP_VAL=0.0003 #in s
+DURATION=1 #in s
+DMA_DEFAULT_TIMEOUT=0.004 #in s
+# BAR=`pci -i | grep "BAR 0" | awk '{print $6}' | cut -c -6` # it was -4 for cut, uros
+function set_frame_rate () {
+    # change the dma timeout and wait period btw frames
+    local val=$1
+    local dma_val=$(echo "scale=0; 1000000000/(4*$val) + 100000 "|bc)
+    val=$(echo "scale=0; 1000000000/(8*($val+1))"|bc) #+1 for rounding error
+    val=$(echo "ibase=10;obase=16; $val"|bc)
+    dma_val=$(echo "ibase=10;obase=16; $dma_val"|bc)
+    pci -w 9180 $val
+    sleep $SLEEP_VAL
+    pci -w 64 $dma_val
+    sleep $SLEEP_VAL
+}
+
+function set_num_frames () {
+    local val=$1
+    if [ -n "$val" ];then
+        val=$(echo "ibase=10;obase=16; $val"|bc)
+        pci -w 9170 $val
+    fi
+}
+
+function single_frame () {
+    echo "Single frame"
+    if [ -f $NAME ]; then
+        rm $NAME
+    fi
+    pci -w 9040 80000209
+    sleep $SLEEP_VAL
+    pci -r dma0 --multipacket -o $NAME -t $TIMEOUT
+    sleep $SLEEP_VAL
+    pci -w 9040 80000201
+}
+function stimuli () {
+    echo "perform stimuli"
+    sleep $SLEEP_VAL
+    if [ -f $NAME ]; then
+        rm $NAME
+    fi
+    #write number of frames
+    sleep $SLEEP_VAL
+    # start stimuli
+    pci -w 9040 80000211
+    sleep $SLEEP_VAL
+    pci -r dma0 --multipacket -o $NAME -t $TIMEOUT
+    sleep $SLEEP_VAL
+    pci -w 9040 80000201
+    # stop stimuli, keep readout active
+    # pci -w 9040 80000201
+}
+
+function stream_active () {
+    if [ "$EDGE" ]; then
+        pci -w 0x9040 8000ca01
+        # for edge no need to sleep long
+        sleep $SLEEP_VAL
+        pci -w 0x9040 80000201
+    else
+        pci -w 0x9040 80004a01
+        sleep $DURATION
+        pci -w 0x9040 80000201
+    fi
+}
+
+function stream () {
+    echo "Stream"
+    if [ -f $NAME ]; then
+      rm $NAME
+    fi
+    stream_active  & 
+    sleep $SLEEP_VAL
+    pci -r dma0 --multipacket -o $NAME -t $TIMEOUT
+    sleep $SLEEP_VAL
+}
+
+
+function print_help () {
+    echo -e ""
+    echo "Usage: grab.sh [--help] [--single] [--edge] [--stimuli] [--stream] [--timeout=] [--num-frames=] [--name=] [--decode=] [--duration=] [--frame-rate=]" 
+    echo -e "order of options is not important"
+    echo -e ""
+    echo -e "\e[33m      --help: \033[1;m print this message and exit"
+    echo -e "\e[33m    --single: \033[1;m takes single frame"
+    echo -e "\e[33m   --stimuli: \033[1;m take frames with stimuli, default one frame"
+    echo -e "\e[33m    --stream: \033[1;m takes frames with software trigger"
+    echo -e "\e[33m    --decode: \033[1;m decode frame, place ipedec flags within quotes"
+    echo -e "\e[33m      --edge: \033[1;m takes frames on edge software trigger, use only with --stream flag"
+    echo -e "\e[33m   --timeout: \033[1;m set DMA timeout in us, default 100.000 us"
+    echo -e "\e[33m      --name: \033[1;m set name, default bench.out"
+    echo -e "\e[33m--num-frames: \033[1;m number of frames for stimuli, use only with --stimuli flag"
+    echo -e "\e[33m  --duration: \033[1;m set streaming duration in s, default 1s"
+    # echo -e "\e[33m--frame-rate: \033[1;m set frame rate in fps, use with --stimuli or --stream flag"
+    echo -e "\nExample:"
+    echo -e "grab.sh --single --name=test.out   ; --> takes single frame, saved as test.out"
+    echo -e "\nWrong:"
+    echo -e "grab.sh --edge                  "
+    echo -e "grab.sh --single --stimuli        "
+}
+input=$@
+for i in "$@"; do
+    case $i in
+        --help)
+            SHOW_USAGE=YES
+            shift
+            ;;
+        --single)
+            SINGLE=YES
+            shift
+            ;;
+        --stimuli)
+            MULTI=YES
+            shift
+            ;;
+        --stream)
+            STREAM=YES
+            shift
+            ;;
+        --edge)
+            EDGE=YES
+            shift
+            ;;
+        --name=*)
+            NAME="${i#*=}"
+            shift
+            ;;
+        --decode=*)
+            DECODE=YES
+            DCD_FLAGS="${i#*=}"
+            shift
+            ;;
+        --num-frames=*)
+            SET_NUM_FRAMES=YES
+            NUM_FRAMES="${i#*=}"
+            shift
+            ;;
+        --duration=*)
+            DURATION="${i#*=}"
+            shift
+            ;;
+         --timeout=*)
+            TIMEOUT="${i#*=}"
+            shift
+            ;;
+         # --frame-rate=*)
+         #    SET_RATE=YES
+         #    FRAME_RATE="${i#*=}"
+         #    shift
+         #    ;;
+        *)
+            WRONG=YES
+            shift
+            ;;
+    esac
+done
+
+if [ -z "$input" ]; then
+    echo "Usage: grab.sh [--help] [--single] [--edge] [--stimuli] [--stream] [--timeout=] [--num-frames=] [--name=] [--decode=] [--duration=] [--frame-rate=]" 
+    exit 0
+fi
+
+if [ "$SINGLE" ]; then
+    if [ "$MULTI" ]; then
+        WRONG=YES
+    elif [ "$STREAM" ]; then
+        WRONG=YES
+    fi
+elif [ "$MULTI" ]; then
+    if [ "$STREAM" ]; then
+        WRONG=YES
+    fi
+fi
+
+if [ "$WRONG" ]; then
+    echo -e ""
+    echo -e "\e[101m  !!!WRONG ARGUMENT!!!, check grab.sh --help \033[1;m"
+    echo -e ""
+    exit
+fi
+
+if [ "$SHOW_USAGE" ]; then
+    print_help
+    exit 0
+fi
+
+# if [ "$SET_RATE" ]; then
+#     set_frame_rate $FRAME_RATE
+# else
+#     # set default wai btw frames
+#     sleep $SLEEP_VAL
+#     pci -w 9180 280 
+#     sleep $SLEEP_VAL
+#     # set default dma timeout (4ms)
+#     pci -w 64 F4240
+#     sleep $SLEEP_VAL
+# fi
+
+if [ "$SET_NUM_FRAMES" ]; then
+    set_num_frames $NUM_FRAMES
+else
+    # set default reg value
+    sleep $SLEEP_VAL
+    pci -w 9170 1 
+    sleep $SLEEP_VAL
+fi
+
+if [ "$EDGE" ]; then
+    if [ -z "$STREAM" ]; then
+      echo -e "\e[31m--edge is used only with --stream flag \033[1;m"
+      exit 0
+    fi
+fi
+
+if [ "$SINGLE" ]; then
+    single_frame 
+    if [ "$DECODE" ]; then
+      ipedec $DCD_FLAGS $NAME 
+    fi
+    exit 0
+fi
+
+if [ "$MULTI" ]; then
+    stimuli
+    sleep $SLEEP_VAL
+    if [ "$DECODE" ]; then
+      echo "here"
+      ipedec $DCD_FLAGS $NAME 
+    fi
+    exit 0
+fi
+
+if [ "$STREAM" ]; then
+    stream
+    sleep $SLEEP_VAL
+    if [ "$DECODE" ]; then
+      ipedec $DCD_FLAGS $NAME 
+    fi
+    exit 0
+fi