Browse Source

Updated reset.sh and status.sh sequence

Uros Stevanovic 9 years ago
parent
commit
c6448bb79f
2 changed files with 118 additions and 28 deletions
  1. 118 21
      reset.sh
  2. 0 7
      status.sh

+ 118 - 21
reset.sh

@@ -2,9 +2,9 @@
 
 PCI=$(which pci)
 NUM_ROWS=1088
+EXP_TIME=100 #us
 SLEEP_VAL=0.03
 
-
 if [ -z "$PCI" ]; then
     echo "pcitool not found."
     exit 1
@@ -17,12 +17,14 @@ function reset_dma () {
     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`
+    #only 4096B buffers should be 4K alligned
+    # local VAR=`cat /sys/class/fpga/fpga0/kbuf* | grep bus | cut -c 16- | grep -v 000`
+    local VAR=`cat /sys/class/fpga/fpga0/kbuffers | awk '{print $1 $2 $3}'`
+    VAR=`printf "%s\n" $VAR | grep 4096 | 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"
@@ -49,6 +51,7 @@ function reset_dma () {
     sleep 0.1
     echo "set 4k AXI packet size"
     pci -w 0x9100 0x20001000
+    sleep .01
 }
 
 function reset_logic () {
@@ -77,7 +80,7 @@ function reset_all () {
 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 -e "\e[31m---------------------->>>> ERROR! in the camera status ...\033[1;m"
         echo $status
         error=1
     fi
@@ -85,7 +88,7 @@ function check_status () {
     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"
+        echo -e "\e[32mCamera READY ..................... OK\033[1;m"
     fi
 }
 
@@ -93,7 +96,7 @@ function read_9010 () {
     local val=$1
     value=`pci -r 0x9010 -s 1  | grep 9010 | awk '{print $2}' | cut -c 4-8`
     if [ "$value" != "b$val" ]; then
-        echo "--------------------------------->>>> ERROR! read value: $value, written value: $val"
+        echo -e "\e[31m----------------->>>> ERROR! read value: $value, written value: $val\033[1;m"
         error=1
     fi
     sleep $SLEEP_VAL
@@ -108,7 +111,7 @@ function write_val () {
 
 function set_exp_time () {
     exp_time=$1             # in us
-    echo "Write exp time...... $exp_time us"
+    echo -e "Write exp time...... \e[93m$exp_time\033[1;m us"
 
     value=`pci -r 9030 | awk '{print $2}' | cut -c 7-7`
     if [ "$value" == "0"  ]; then
@@ -157,10 +160,15 @@ function configure_cmosis () {
     # register 111, bit mode, 1-10bits per pixel 0-12bits-per pixel
     write_val ef00
 
-    # ADC_resolution @ 12 bits
-    echo "10 bit mode, set ADC resolution 10 bits "
+    # ADC_resolution @ 10/12 bits
     ## register 112, ADC resolution, 0-10bit per pixel, 1-11bit per pixel, 2-12bit per pixel
-    write_val f000  # qui for 10 - 11 - 12 bits
+    if [ "$MODE12b" ]; then
+        echo -e "\e[93m12\033[1;m bit mode, set ADC resolution \e[93m12\033[1;m bits "
+        write_val f002 
+    else
+        echo -e "\e[93m10\033[1;m bit mode, set ADC resolution \e[93m10\033[1;m bits "
+        write_val f000  
+    fi
 
     # adc recommended 28=44
     # register 103, ADC gain
@@ -208,8 +216,13 @@ function configure_cmosis () {
     write_val e36c
 
     ### NUMBER OF OUTPUT
-    echo "set reg 72 - 16 data lines"
-    write_val c800
+    if [ "$MODE12b" ]; then
+        echo -e "se reg 72 - \e[93m4\033[1;m data lines"
+        write_val c802
+    else
+        echo -e "set reg 72 - \e[93m16\033[1;m data lines"
+        write_val c800
+    fi
 
     # register 40, image flipping, 0-no flip, 1-X, 2-Y, 3-both X and Y
     echo "set reg 40"
@@ -220,7 +233,7 @@ function configure_cmosis () {
 
 function set_number_lines () {
     number_lines=$1
-    echo "Write number of lines: " $number_lines
+    echo -e "Write number of lines: \e[93m$number_lines\033[1;m" 
     number_lines=$(printf "%04x\n" $number_lines)
 
     val=81${number_lines:2:4}
@@ -230,8 +243,42 @@ function set_number_lines () {
     write_val $val
 }
 
+function print_help () {
+
+echo -e ""
+echo -e "usage: \e[33mreset.sh [options1] [options2] ...\033[1;m"
+echo -e "order of options is not important"
+echo -e ""
+echo -e "\e[33m     empty: \033[1;m print this message and exit"
+echo -e "\e[33m     --dma: \033[1;m reset only dma"
+echo -e "\e[33m   --logic: \033[1;m reset only logic"
+echo -e "\e[33m  --cmosis: \033[1;m reset cmosis, and set default cmosis values"
+echo -e "\e[33m     --all: \033[1;m reset logic and cmosis, and set default cmosis values"
+echo -e "\e[33m     --4MP: \033[1;m set 2047 rows, default 1088 rows"
+echo -e "\e[33m     --12b: \033[1;m use 12bits, default 10 bits, only use with --cmosis or --all flag"
+echo -e "\e[33m--num-rows: \033[1;m set number of rows, default 1088"
+echo -e "\e[33m--exp-time: \033[1;m set exposure time in us, default 100"
+echo -e "\nExample:"
+echo -e "reset.sh --cmosis            ; --> Reset CMOSIS in 10bit mode"
+echo -e "reset.sh --cmosis --12b --4MP; --> Reset CMOSIS in 12bit mode, 2047 rows"
+echo -e "\nWrong:"
+echo -e "reset.sh --12b                  "
+echo -e "reset.sh --4MP --num-rows=1000  "
+echo -e "\nDiscouraged:"
+echo -e "reset.sh --all --dma --logic --cmosis  "
+
+}
+input=$@
 for i in "$@"; do
     case $i in
+        --all)
+            RESET_ALL=YES
+            shift
+            ;;
+        --cmosis)
+            RESET_CMOSIS=YES
+            shift
+            ;;
         --dma)
             RESET_DMA=YES
             shift
@@ -240,37 +287,87 @@ for i in "$@"; do
             RESET_LOGIC=YES
             shift
             ;;
-        --cmosis)
-            RESET_CMOSIS=YES
-            shift
-            ;;
-        --all)
-            RESET_ALL=YES
+        --12b)
+            MODE12b=YES
             shift
             ;;
         --4MP)
+            SET_4MP=YES
             NUM_ROWS=2047
             shift
             ;;
         --num-rows=*)
+            # ROW_SET=YES
             NUM_ROWS="${i#*=}"
+            SET_ROWS=YES
+            shift
+            ;;
+        --exp-time=*)
+            EXP_TIME="${i#*=}"
+            SET_EXP_TIME=YES
             shift
             ;;
         *)
+            WRONG=YES
+            shift
             ;;
     esac
 done
 
+# check wrong or empty inputs #######################
+if [ -z "$input" ]; then
+  # echo -e $HELP_MESSAGE
+  # printf "%s\n" $HELP_MESS
+  print_help
+fi
+
+if [ "$SET_4MP" ] && [ "$SET_ROWS" ]; then
+  WRONG=YES
+fi
+
+if [ -z "$RESET_CMOSIS" ]; then
+  if [ -z "$RESET_ALL" ]; then
+    if [ "$MODE12b" ]; then
+      WRONG=YES
+    elif [ "$SET_4MP" ] && [ "$SET_ROWS" ]; then
+      WRONG=YES
+    elif [ "$SET_4MP" ]; then
+      set_number_lines $NUM_ROWS
+    elif [ "$SET_ROWS" ]; then
+      set_number_lines $NUM_ROWS
+    elif [ "$SET_EXP_TIME" ]; then
+      set_exp_time $EXP_TIME
+    fi
+  fi
+fi
+
+if [ "$WRONG" ]; then
+  echo -e ""
+  echo -e "\e[101m  !!!WRONG ARGUMENT!!!, see usage below \033[1;m"
+  echo -e ""
+  print_help
+  exit
+fi
+#################################################
+
 if [ "$RESET_DMA" ]; then
     reset_dma
 fi
 
 if [ "$RESET_LOGIC" ]; then
     reset_logic
+    if [ -z "$WRONG" ]; then
+      check_status
+    fi
 fi
 
 if [ "$RESET_CMOSIS" ]; then
+    pci -w 9020 e
     reset_cmosis
+    configure_cmosis
+    set_number_lines $NUM_ROWS
+    set_exp_time $EXP_TIME
+    check_status
 fi
 
 if [ "$RESET_ALL" ]; then
@@ -279,7 +376,7 @@ if [ "$RESET_ALL" ]; then
     reset_dma
     configure_cmosis
     set_number_lines $NUM_ROWS
-    set_exp_time 100
+    set_exp_time $EXP_TIME
+    check_status
 fi
 
-check_status

+ 0 - 7
status.sh

@@ -1,11 +1,4 @@
 #!/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}