xref: /OK3568_Linux_fs/device/rockchip/common/images/oem/oem_uvcc/aicamera.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/sh
2#
3
4TRY_CNT=0
5get_pid(){
6   ps -A | grep "$1" | awk '{print $1}'
7}
8wait_process_killed(){
9   if [ "$2" = "" ]; then return; fi
10   while [ "$(get_pid $1)" = "$2" ]
11   do
12     sleep 0.1
13   done
14}
15
16check_uvc_suspend()
17{
18  if [ -e /tmp/uvc_goto_suspend ];then
19     echo "uvc go to suspend now"
20     ispserver_pid=$(get_pid ispserver)
21     aiserver_pid=$(get_pid aiserver)
22     killall ispserver
23     killall aiserver
24     wait_process_killed ispserver ${ispserver_pid}
25     wait_process_killed aiserver ${aiserver_pid}
26     CNT=0
27     while [ "$CNT" -gt 20 ]
28     do
29       if [ -e /tmp/uvc_goto_suspend ];then
30          sleep 0.1
31          let CNT=CNT+1
32       else
33          CNT=100
34       fi
35     done
36     if [ -e /tmp/uvc_goto_suspend ];then
37       rm /tmp/uvc_goto_suspend -rf
38       echo mem > /sys/power/state
39     fi
40  fi
41}
42
43check_uvc_buffer()
44{
45  if [ "$TRY_CNT" -gt 0 ];then
46     let TRY_CNT=TRY_CNT-1
47     #echo "++++++++TRY_CNT:$TRY_CNT"
48  fi
49  if [ "$TRY_CNT" -gt 10 ];then
50     echo "+++check_uvc_buffer recovery fail,reboot to recovery now+++"
51     reboot &
52  fi
53  if [ -e /tmp/uvc_camera_no_buf ];then
54     let TRY_CNT=TRY_CNT+10
55     echo "uvc no buf to send 200 frames,try to recovery isp time,timeout:$TRY_CNT"
56     killall ispserver
57     killall aiserver
58     rm /tmp/uvc_camera_no_buf -rf
59  fi
60}
61check_alive()
62{
63  if [[ ! -f "/oem/usr/bin/$1"  && ! -f "/usr/bin/$1" ]]; then
64   return 1
65  fi
66  PID=`busybox ps |grep $1 |grep -v grep | wc -l`
67  if [ $PID -le 0 ];then
68     if [ "$1"x == "uvc_app"x ];then
69       echo " uvc app die ,restart it and usb reprobe !!!"
70       killall adbd
71       killall uac_app &
72       sleep 1
73       killall -9 adbd
74       killall -9 uac_app
75       rm -rf /sys/kernel/config/usb_gadget/rockchip/configs/b.1/f*
76       echo none > /sys/kernel/config/usb_gadget/rockchip/UDC
77       rmdir /sys/kernel/config/usb_gadget/rockchip/functions/rndis.gs0
78       rmdir /sys/kernel/config/usb_gadget/rockchip/functions/ffs.adb
79       rmdir /sys/kernel/config/usb_gadget/rockchip/functions/uac*
80       UDC=`ls /sys/class/udc/| awk '{print $1}'`
81       echo $UDC  > /sys/bus/platform/drivers/dwc3/unbind
82       echo $UDC  > /sys/bus/platform/drivers/dwc3/bind
83       /oem/usb_config.sh rndis off #disable adb
84       usb_irq_set
85       uvc_app &
86     else
87       if [ "$1"x == "ispserver"x ];then
88          ispserver -n &
89       else
90         if [ "$1"x == "aiserver"x ];then
91            echo "aiserver is die,tell uvc to recovery"
92            killall -3 uvc_app
93            aiserver &
94            sleep .5
95            killall -10 smart_display_service
96         else
97            $1 &
98         fi
99       fi
100     fi
101  fi
102}
103
104stop_unused_daemon()
105{
106  killall -9 adbd
107  killall -9 ntpd
108  killall -9 connmand
109  killall -9 dropbear
110  killall -9 start_rknn.sh
111  killall -9 rknn_server
112}
113
114usb_irq_set()
115{
116  #for usb uvc iso
117  usbirq=`cat /proc/interrupts |grep dwc3| awk '{print $1}'|tr -cd "[0-9]"`
118  echo "usb irq:$usbirq"
119  echo 1 > /proc/irq/$usbirq/smp_affinity_list
120}
121#ulimit -c unlimited
122dbserver &
123ispserver -n &
124stop_unused_daemon
125#uac_app &
126/oem/usb_config.sh rndis
127usb_irq_set
128uvc_app &
129aiserver &
130sleep .5
131smart_display_service &
132while true
133do
134  check_alive dbserver
135  check_alive ispserver
136  check_alive uvc_app
137#  check_alive uac_app
138  check_alive aiserver
139#  check_uvc_buffer
140#  check_uvc_suspend
141  sleep 2
142  check_alive smart_display_service
143done
144