#!/bin/sh
#
# The check file can help the user debug the issue that dsp crash.
# It's used for S2(S2E), S2L, S3L, S5, S5L, cv2, cv22, cv25, s6lm, cv28, cv5 and cv52.
#
# History:
#	2012/05/05 - [Jian Tang] Created file
#	2015/07/07 - [Jingyang Qiu] Add S3L support
#	2016/05/31 - [Jian Tang] Add S5 support
#	2016/12/13 - [Jian Tang] Add S5L support
#	2021/06/28 - [Zhaoyang Chen] Add CV5x support
#
# Copyright (c) 2021 Ambarella International LP
#
# This file and its contents ("Software") are protected by intellectual
# property rights including, without limitation, U.S. and/or foreign
# copyrights. This Software is also the confidential and proprietary
# information of Ambarella International LP and its licensors. You may not use, reproduce,
# disclose, distribute, modify, or otherwise prepare derivative works of this
# Software or any portion thereof except pursuant to a signed license agreement
# or nondisclosure agreement with Ambarella International LP or its authorized affiliates.
# In the absence of such an agreement, you agree to promptly notify and return
# this Software to Ambarella International LP.
#
# This file includes sample code and is only for internal testing and evaluation.  If you
# distribute this sample code (whether in source, object, or binary code form), it will be
# without any warranty or indemnity protection from Ambarella International LP or its affiliates.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
# MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; COMPUTER FAILURE OR MALFUNCTION; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

IRQ_LAST_PIXEL="vin0_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN1="vin1_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN2="vin2_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN3="vin3_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN4="vin4_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN5="vin5_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN6="vin6_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN7="vin7_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN8="vin8_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN9="vin9_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN10="vin10_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN11="vin11_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN12="vin12_idsp_last_pixel"
IRQ_LAST_PIXEL_VIN13="vin13_idsp_last_pixel"
IRQ_VCAP="vcap"
IRQ_VDSP="vdsp"
IRQ_VENC="venc"

LOG_TYPE_DSP="0_dsp"
LOG_TYPE_IAV="1_iav"
LOG_TYPE_VIN="2_vin"
LOG_TYPE_DRAM="3_dram"
LOG_TYPE_SYS="4_sys"

DSPLOG_FOLDER="/tmp"
REGISTER_FOLDER="/var/log/ambarella"
DSPLOG_AMBADEBUG_FILE="${LOG_TYPE_DSP}_dsplog_ambadebug"
DSPLOG_BEFORE_FILE="${LOG_TYPE_DSP}_dsplog_capture_before_hang"
DSPLOG_AFTER_FILE="${LOG_TYPE_DSP}_dsplog_capture_after_hang"
DSPLOG_FILE_SIZE=10000000
DSPLOG_DEBUG_LEVEL=3

KERNEL_VERSION=$(uname -r)
CHIP=$(grep AMBARELLA_ARCH /etc/ambarella.conf | cut -d'=' -f 2 | tr '[:lower:]' '[:upper:]')

glo_var=0

func_is_encoding_state()
{
	test_encode --show-system-state | grep Encoding
	if [ "$?" -eq "0" ]; then
		return 1
	else
		return 0
	fi
}

func_is_iav_init_state()
{
	test_encode --show-system-state | grep Init > /dev/null
	if [ "$?" -eq "0" ]; then
		return 1
	else
		return 0
	fi
}

func_get_interrupts()
{
	local irq=$(grep "$1" /proc/interrupts | cut -d':' -f2 | grep -o "[0-9]*[0-9] ")
	local tmp=0
	for i in $irq ; do
		tmp=$((tmp+i))
	done
	glo_var=$tmp
}

func_dump_reg_error()
{
	echo "Invalid Chip ID! Do nothing."
}

func_dump_reg_s2()
{
	amba_debug -w 0x70118000 -d 0x1000 && amba_debug -r 0x70110000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}_register.txt
	amba_debug -r 0x70107C00 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x70107C00_0x120.txt
	amba_debug -r 0x70118040 -s 0x220 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x70118040_0x220.txt
	# DSP PC address:
	amba_debug -r 0x70160020 -s 0x20 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x70160020_0x20.txt
	amba_debug -r 0x70160400 -s 0x410 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x70160400_0x410.txt
	amba_debug -r 0x70140028 -s 0x20 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x70140028_0x20.txt
	amba_debug -r 0x70150028 -s 0x20 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x70150028_0x20.txt
	amba_debug -r 0x70140800 -s 0x210 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x70140800_0x210.txt
	amba_debug -r 0x70150800 -s 0x210 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x70150800_0x210.txt
	dmesg > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_dmesg.txt
	if [ "$KERNEL_VERSION" = "3.8.8" ] || [ "$KERNEL_VERSION" = "3.8.8+" ]; then
		cat /proc/ambarella/mode > ${REGISTER_FOLDER}/mode.txt
	else
		cat /proc/ambarella/clock > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_clock.txt
	fi

	sleep 10
	amba_debug -r 0x80000 -s 0x20000 -f ${DSPLOG_FOLDER}/${DSPLOG_AMBADEBUG_FILE}.bin
	dsplog_cap -i ${DSPLOG_FOLDER}/${DSPLOG_AMBADEBUG_FILE}.bin -f ${REGISTER_FOLDER}/${DSPLOG_AMBADEBUG_FILE}.txt
}

func_dump_reg_s2l()
{
	amba_debug -w 0xec118000 -d 0x1000 && amba_debug -r 0xec110000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}_register.txt

	amba_debug -r 0xec160020 -s  0x20 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec160020_0x20.txt
	amba_debug -r 0xec160200 -s 0x200 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec160200_0x200.txt
	amba_debug -r 0xec150028 -s  0x20 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec150028_0x20.txt
	amba_debug -r 0xec101c00 -s  0x80 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec101c00_0x80.txt

	cat /proc/ambarella/iav > ${REGISTER_FOLDER}/${LOG_TYPE_IAV}.txt
	cat /proc/ambarella/clock > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_clock.txt
}

func_dump_reg_s3l()
{
	amba_debug -w 0xec118000 -d 0x1000 && amba_debug -r 0xec110000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}_register.txt

	amba_debug -r 0xec160020 -s  0x20 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec160020_0x20.txt
	amba_debug -r 0xec160400 -s 0x200 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec160400_0x200.txt
	amba_debug -r 0xec150028 -s  0x20 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec150028_0x20.txt
	amba_debug -r 0xec101c00 -s 0x100 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec101c00_0x100.txt

	cat /proc/ambarella/iav > ${REGISTER_FOLDER}/${LOG_TYPE_IAV}.txt
	cat /proc/ambarella/clock > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_clock.txt
}

func_dump_reg_s5()
{
	amba_debug -w 0xf4008000 -d 0x100 && amba_debug -r 0xf4000000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}0_register.txt
	amba_debug -w 0xf4008000 -d 0x900 && amba_debug -r 0xf4000000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}1_register.txt
	amba_debug -w 0xf4008000 -d 0x1500 && amba_debug -r 0xf4000000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}2_register.txt
	amba_debug -w 0xf4008000 -d 0x1600 && amba_debug -r 0xf4000000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}3_register.txt

	amba_debug -r 0xec130010 -s  0x40 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec130010_0x40.txt
	amba_debug -r 0xec130800 -s 0x800 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec130800_0x800.txt
	amba_debug -r 0xec010010 -s  0x40 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec010010_0x40.txt
	amba_debug -r 0xec010800 -s 0x800 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec010800_0x800.txt
	amba_debug -r 0xec160010 -s 0x1c0 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec160010_0x1c0.txt
	amba_debug -r 0xec160800 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec160800_0x600.txt
	amba_debug -r 0xec06f000 -s 0x400 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec06f000_0x400.txt
}

func_dump_reg_s5l()
{
	amba_debug -w 0xec118000 -d 0x1000 && amba_debug -r 0xec110000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}0_register.txt
	amba_debug -w 0xec118000 -d 0xa000 && amba_debug -r 0xec110000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}1_register.txt

	amba_debug -r 0xec160020 -s  0x20 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec160020_0x20.txt
	amba_debug -r 0xec160400 -s 0x200 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec160400_0x200.txt
	amba_debug -r 0xec150028 -s  0x20 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec150028_0x20.txt
	amba_debug -r 0xec101c00 -s 0x100 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xec101c00_0x100.txt

	cat /proc/ambarella/iav > ${REGISTER_FOLDER}/${LOG_TYPE_IAV}.txt
	cat /proc/ambarella/clock > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_clock.txt
}

func_dump_reg_cv1()
{
	amba_debug -w 0xed1c8000 -d 0x1000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}0_register.txt
	amba_debug -w 0xed1c8000 -d 0xa000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}1_register.txt
	amba_debug -w 0xed1c8000 -d 0xb000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}2_register.txt
	amba_debug -w 0xed1c8000 -d 0xc000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}3_register.txt
	amba_debug -w 0xed1c8000 -d 0xd000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}4_register.txt

	cat /proc/ambarella/iav > ${REGISTER_FOLDER}/${LOG_TYPE_IAV}.txt
	cat /proc/ambarella/clock > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_clock.txt

	visdmsg > ${REGISTER_FOLDER}/vp_log.txt
}

func_dump_reg_cv2x()
{
	# dump VIN controller registers
	# CV25/S6LM/CV28 has 3 VIN controllers
	# CV2 has 6 VIN controllers
	# CV22 has 2 VIN controllers
	amba_debug -w 0xed1c8000 -d 0x1000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}0_register.txt
	amba_debug -w 0xed1c8000 -d 0xa000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}1_register.txt
	case "$1" in
	"CV25" | "S6LM" | "CV28")
	amba_debug -w 0xed1c8000 -d 0xb000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}2_register.txt
	;;
	"CV2")
	amba_debug -w 0xed1c8000 -d 0xb000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}2_register.txt
	amba_debug -w 0xed1c8000 -d 0xc000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}3_register.txt
	amba_debug -w 0xed1c8000 -d 0xd000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}4_register.txt
	amba_debug -w 0xed1c8000 -d 0xe000&&amba_debug -r 0xed1c0000 -s 0x120 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}5_register.txt
	;;
	"CV22")
	# Do Nothing
	;;
	*)
	;;
	esac

	# dump DRAM controller registers
	amba_debug -r 0xdffe0800 -s 0x200 > ${REGISTER_FOLDER}/${LOG_TYPE_DRAM}_0xdffe0800_0x200.txt
	amba_debug -r 0xdffe0a00 -s 0x200 > ${REGISTER_FOLDER}/${LOG_TYPE_DRAM}_0xdffe0a00_0x200.txt

	# dump dsp registers
	amba_debug -r 0xed030000 -s  0x40 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed030000_0x40.txt
	amba_debug -r 0xed0c0000 -s  0x48 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed0c0000_0x48.txt
	amba_debug -r 0xed020000 -s  0x48 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed020000_0x48.txt
	amba_debug -r 0xed05e100 -s  0x20 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed05e100_0x20.txt
	amba_debug -r 0xed05f000 -s 0x1fc > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed05f000_0x1fc.txt

	# dump dsp smem registers
	amba_debug -r 0xed040000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed040000_0x600.txt
	amba_debug -r 0xed041000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed041000_0x600.txt
	amba_debug -r 0xed042000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed042000_0x600.txt
	amba_debug -r 0xed043000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed043000_0x600.txt
	amba_debug -r 0xed044000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed044000_0x600.txt
	amba_debug -r 0xed045000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed045000_0x600.txt
	amba_debug -r 0xed046000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed046000_0x600.txt
	amba_debug -r 0xed047000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed047000_0x600.txt

	# dump dsp dram registers
	amba_debug -r 0xed050000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed050000_0x600.txt
	amba_debug -r 0xed051000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed051000_0x600.txt
	amba_debug -r 0xed052000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed052000_0x600.txt
	amba_debug -r 0xed053000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed053000_0x600.txt
	amba_debug -r 0xed054000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed054000_0x600.txt
	amba_debug -r 0xed055000 -s 0x600 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0xed055000_0x600.txt

	cat /proc/ambarella/iav > ${REGISTER_FOLDER}/${LOG_TYPE_IAV}.txt
	cat /proc/ambarella/clock > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_clock.txt
}

func_dump_reg_cv5()
{
	amba_debug -w 0x20ed1e8000 -d 0x1000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}0_register.txt
	amba_debug -w 0x20ed1e8000 -d 0x2000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}1_register.txt
	amba_debug -w 0x20ed1e8000 -d 0x3000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}2_register.txt
	amba_debug -w 0x20ed1e8000 -d 0x4000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}3_register.txt
	amba_debug -w 0x20ed1e8000 -d 0x5000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}4_register.txt
	amba_debug -w 0x20ed1e8000 -d 0x6000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}5_register.txt
	amba_debug -w 0x20ed1e8000 -d 0x7000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}6_register.txt
	amba_debug -w 0x20ed1e8000 -d 0x8000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}7_register.txt
	amba_debug -w 0x20ed1e8000 -d 0x9000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}8_register.txt
	amba_debug -w 0x20ed1e8000 -d 0xa000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}9_register.txt
	amba_debug -w 0x20ed1e8000 -d 0xb000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}10_register.txt
	amba_debug -w 0x20ed1e8000 -d 0xc000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}11_register.txt
	amba_debug -w 0x20ed1e8000 -d 0xd000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}12_register.txt
	amba_debug -w 0x20ed1e8000 -d 0xe000 && amba_debug -r 0x20ed1e0000 -s 0x140 > ${REGISTER_FOLDER}/${LOG_TYPE_VIN}13_register.txt

	amba_debug -r 0x20ed140000 -s  0x48 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x20ed140000_0x48.txt
	amba_debug -r 0x20ed150000 -s  0x48 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x20ed150000_0x48.txt
	amba_debug -r 0x20ed160000 -s  0x48 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x20ed160000_0x48.txt
	amba_debug -r 0x20ed170000 -s  0x48 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x20ed170000_0x48.txt
	amba_debug -r 0x20ed020000 -s  0x44 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x20ed020000_0x44.txt
	amba_debug -r 0x20ed320000 -s  0x44 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x20ed320000_0x44.txt
	amba_debug -r 0x20ed030000 -s  0x44 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x20ed030000_0x44.txt
	amba_debug -r 0x20ed330000 -s  0x44 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x20ed330000_0x44.txt
	amba_debug -r 0x20ed05f000 -s  0x400 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_0x20ed05f000_0x400.txt

	cat /proc/ambarella/iav > ${REGISTER_FOLDER}/${LOG_TYPE_IAV}.txt
	cat /proc/ambarella/clock > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_clock.txt

	## TODO: Dump VP log with visdmsg
}

func_print_audit_cv2x()
{
	case "$CHIP" in
	"CV22" | "CV2" | "CV25" | "S6LM" | "CV28")
	test_encode --debug-audit-idsp >> ${REGISTER_FOLDER}/${LOG_TYPE_IAV}_idsp_audit.txt
	;;
	*)
	;;
	esac
}

func_dump_cma_info()
{
	case "$CHIP" in
	"CV22" | "CV2" | "CV25" | "S6LM" | "CV28" | "S5L")
	echo "---------------------------cma--------------------------------" > ${REGISTER_FOLDER}/${LOG_TYPE_DRAM}_cma.txt
	cat /proc/ambarella/cma >> ${REGISTER_FOLDER}/${LOG_TYPE_DRAM}_cma.txt
	date >> ${REGISTER_FOLDER}/${LOG_TYPE_DRAM}_cma.txt
	if [ "$CHIP" != "S5L" -a "$CHIP" != "S6LM" ]; then
		echo "---------------------------cavalry_cma--------------------------------" > ${REGISTER_FOLDER}/${LOG_TYPE_DRAM}_calvary_cma.txt
		cat /proc/ambarella/cavalry_cma >> ${REGISTER_FOLDER}/${LOG_TYPE_DRAM}_calvary_cma.txt
		date >> ${REGISTER_FOLDER}/${LOG_TYPE_DRAM}_calvary_cma.txt
	fi
	;;
	*)
	;;
	esac
}

func_dump_ucode_pc()
{
	file_size=`wc -c < /lib/firmware/$1`
	size=$(($(($file_size + 3)) & ~3))
	start=`amba_debug -r $2 | awk '{print $2}'`
	end=`expr $(($start)) + $size`
	start=$(($start))
	i=0
	pass=true

	printf "Base: 0x%x\nSize: 0x%x\n" $start $file_size
	printf "Valid range: [0x%x ~ 0x%x]\n" $start $end

	while [ $i -lt $4 ]
	do
		reg=$(($3+4*i))
		reg_val=`amba_debug -r $reg | awk '{print $2}'`
		reg_val=$(($reg_val))
		if [ $reg_val -lt $start ] || [ $reg_val -gt $end ]; then
			pass=false
			printf "PC%x: 0x%x out of the range\n" $i $reg_val
		else
			printf "PC%x: 0x%x \n" $i $reg_val
		fi
		i=$((i+1))
	done

	if [ $pass == true ]; then
		printf "Result: All PCs are in the valid range.\n\n"
	else
		printf "Result: Found invalid PCs.\n\n"
	fi
}

func_dump_ucode_pc_cv2x()
{
	echo "1. Check the PCs for ORC code (orccode.bin):"
	func_dump_ucode_pc "orccode.bin" 0xed030008 0xed030020 8
	echo "2. Check the PCs for ME code (orcme.bin):"
	func_dump_ucode_pc "orcme.bin"   0xed020008 0xed020028 4
	echo "3. Check the PCs for MDXF code (orcmdxf.bin):"
	func_dump_ucode_pc "orcmdxf.bin" 0xed0c0008 0xed0c0028 4
}

func_dump_ucode_pc_cv5()
{
	echo "1. Check the PCs for ORC code (orccode.bin):"
	func_dump_ucode_pc "orccode.bin" 0x20ed140008 0x20ed140020 4
	echo "2. Check the PCs for ORC vin (orcvin.bin):"
	func_dump_ucode_pc "orcvin.bin" 0x20ed150008 0x20ed150020 4
	echo "3. Check the PCs for ORC idsp0 (orcidsp0.bin):"
	func_dump_ucode_pc "orcidsp0.bin" 0x20ed160008 0x20ed160020 4
	echo "4. Check the PCs for ORC idsp1 (orcidsp1.bin):"
	func_dump_ucode_pc "orcidsp1.bin" 0x20ed170008 0x20ed170020 4

	echo "5. Check the PCs for ORC me0 (orcme0.bin):"
	func_dump_ucode_pc "orcme0.bin" 0x20ed020008 0x20ed020028 4
	echo "6. Check the PCs for ORC me1 (orcme1.bin):"
	func_dump_ucode_pc "orcme1.bin" 0x20ed320008 0x20ed320028 4
	echo "7. Check the PCs for ORC mdxf0 (orcmdxf0.bin):"
	func_dump_ucode_pc "orcmdxf0.bin" 0x20ed030008 0x20ed030028 4
	echo "8. Check the PCs for ORC mdxf1 (orcmdxf1.bin):"
	func_dump_ucode_pc "orcmdxf1.bin" 0x20ed330008 0x20ed330028 4
}

func_dump_info()
{
	cat /proc/interrupts > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_interrupt.txt
	date >> ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_interrupt.txt
	func_dump_cma_info

	killall  dsplog_cap
	date > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_stop_date.txt
	dsplog_cap -m all -b all -l ${DSPLOG_DEBUG_LEVEL} -o ${DSPLOG_FOLDER}/${DSPLOG_AFTER_FILE}.bin -p ${DSPLOG_FILE_SIZE} &
	sleep 2
	cat /proc/interrupts >> ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_interrupt.txt
	date >> ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_interrupt.txt

	echo "Get ${CHIP} DSP info"
	if [ "$CHIP" = "S2" ] ; then
		func_dump_reg_s2
	elif [ "$CHIP" = "S2L" ] ; then
		func_dump_reg_s2l
	elif [ "$CHIP" = "S3L" ] ; then
		func_dump_reg_s3l
	elif [ "$CHIP" = "S5" ] ; then
		func_dump_reg_s5
	elif [ "$CHIP" = "S5L" ] ; then
		func_dump_reg_s5l
	elif [ "$CHIP" = "CV1" ] ; then
		func_dump_reg_cv1
	elif [ "$CHIP" = "CV22" ] ; then
		func_dump_reg_cv2x $CHIP
		func_dump_ucode_pc_cv2x > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_ucode_pcs.txt
	elif [ "$CHIP" = "CV2" ] ; then
		func_dump_reg_cv2x $CHIP
		func_dump_ucode_pc_cv2x > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_ucode_pcs.txt
	elif [ "$CHIP" = "CV25" ] ; then
		func_dump_reg_cv2x $CHIP
		func_dump_ucode_pc_cv2x > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_ucode_pcs.txt
	elif [ "$CHIP" = "S6LM" ] ; then
		func_dump_reg_cv2x $CHIP
		func_dump_ucode_pc_cv2x > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_ucode_pcs.txt
	elif [ "$CHIP" = "CV28" ] ; then
		func_dump_reg_cv2x $CHIP
		func_dump_ucode_pc_cv2x > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_ucode_pcs.txt
	elif [ "$CHIP" = "CV5" ] ; then
		func_dump_reg_cv5
		func_dump_ucode_pc_cv5 > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_ucode_pcs.txt
	else
		func_dump_reg_error
	fi

	func_print_audit_cv2x
	cat /proc/meminfo > ${REGISTER_FOLDER}/${LOG_TYPE_DRAM}_meminfo.txt
	lsmod > ${REGISTER_FOLDER}/${LOG_TYPE_IAV}_lsmod.txt
	cat /proc/interrupts >> ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_interrupt.txt
	date >> ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_interrupt.txt
	test_encode --show-all > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_test_encode_show_a.txt &
	echo "================== ${CHIP} DSP HANG =================="
	echo " DSP log binary by dsplog_cap is ${DSPLOG_FOLDER}/dsplog_capture_*****.bin "
	echo " All the debug info have been captured on the /home/ "
	echo " Please help to parse the ${DSPLOG_FOLDER}/dsplog_capture.bin in the follow command : "
	echo " dsplog_cap -i ${DSPLOG_FOLDER}/dsplog_capture.bin -f ${REGISTER_FOLDER}/dsplog_capture.txt "
	echo " Then send us the ${REGISTER_FOLDER}/dsplog_capture.txt and all the files on the /home "
	echo "================== DSP HANG =================="
	sleep 2
	dmesg > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_dmesg.txt
	killall dsplog_cap
	dsplog_cap -V > ${REGISTER_FOLDER}/${LOG_TYPE_DSP}_ucode.txt
	dsplog_cap -i ${DSPLOG_FOLDER}/${DSPLOG_BEFORE_FILE}.bin.1 -f ${REGISTER_FOLDER}/${DSPLOG_BEFORE_FILE}.1.txt
	dsplog_cap -i ${DSPLOG_FOLDER}/${DSPLOG_BEFORE_FILE}.bin.2 -f ${REGISTER_FOLDER}/${DSPLOG_BEFORE_FILE}.2.txt
	dsplog_cap -i ${DSPLOG_FOLDER}/${DSPLOG_AFTER_FILE}.bin.1 -f ${REGISTER_FOLDER}/${DSPLOG_AFTER_FILE}.1.txt

	cat /proc/interrupts >> ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_interrupt.txt
	date >> ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_interrupt.txt

	date > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_end_date.txt
}

func_check_interrupt_s2l()
{
	func_is_iav_init_state
	if [ $? -eq "1" ]; then
		continue;
	fi

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc=$glo_var

	sleep 1

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel2=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp2=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap2=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc2=$glo_var

	local diff_last_pixel=$((last_pixel2-last_pixel))
	local diff_vdsp=$((vdsp2-vdsp))
	local diff_vcap=$((vcap2-vcap))
	local diff_venc=$((venc2-venc))

	local p2=${diff_last_pixel#-}
	local p3=${diff_vdsp#-}
	local p4=${diff_vcap#-}

	echo "last_pixel in 1s: $p2"
	echo "vdsp in 1s: $p3"
	echo "vcap in 1s: $p4"

	func_is_encoding_state
	if [ $? -eq "1" ]; then
		local p5=${diff_venc#-}
		echo "venc in 1s: $p5"
		if [ "$p5" -eq 0 ]; then
			func_dump_info
			exit 1
		fi
	fi

	if [ "$p2" -eq 0 ] || [ "$p3" -eq 0 ] || [ "$p4" -eq 0 ]; then
		func_dump_info
		exit 1
	fi
}

func_check_interrupt_cv1()
{
	func_is_iav_init_state
	if [ $? -eq "1" ]; then
		continue;
	fi

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN1}
	local last_pixel_vin1=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN2}
	local last_pixel_vin2=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN3}
	local last_pixel_vin3=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN4}
	local last_pixel_vin4=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc=$glo_var

	sleep 1

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel2=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN1}
	local last_pixel2_vin1=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN2}
	local last_pixel2_vin2=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN3}
	local last_pixel2_vin3=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN4}
	local last_pixel2_vin4=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap2=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp2=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc2=$glo_var

	local diff_last_pixel=$((last_pixel2-last_pixel+last_pixel2_vin1-last_pixel_vin1+last_pixel2_vin2-last_pixel_vin2+last_pixel2_vin3-last_pixel_vin3+last_pixel2_vin4-last_pixel_vin4))
	local diff_vcap=$((vcap2-vcap))
	local diff_vdsp=$((vdsp2-vdsp))
	local diff_venc=$((venc2-venc))

	local p2=${diff_last_pixel#-}
	local p3=${diff_vcap#-}
	local p4=${diff_vdsp#-}

	echo "last_pixel in 1s: $p2"
	echo "vcap in 1s: $p3"
	echo "vdsp in 1s: $p4"

	func_is_encoding_state
	if [ $? -eq "1" ]; then
		local p5=${diff_venc#-}
		echo "venc in 1s: $p5"
		if [ "$p5" -eq 0 ]; then
			func_dump_info
			exit 1
		fi
	fi

	if [ "$p2" -eq 0 ] || [ "$p3" -eq 0 ] || [ "$p4" -eq 0 ]; then
		func_dump_info
		exit 1
	fi
}

func_check_interrupt_cv2x()
{
	func_is_iav_init_state
	if [ $? -eq "1" ]; then
		continue;
	fi

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN1}
	local last_pixel_vin1=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN2}
	local last_pixel_vin2=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN3}
	local last_pixel_vin3=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN4}
	local last_pixel_vin4=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN5}
	local last_pixel_vin5=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc=$glo_var

	sleep 1

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel2=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN1}
	local last_pixel2_vin1=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN2}
	local last_pixel2_vin2=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN3}
	local last_pixel2_vin3=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN4}
	local last_pixel2_vin4=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN5}
	local last_pixel2_vin5=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap2=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp2=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc2=$glo_var

	local diff_last_pixel=$((last_pixel2-last_pixel+last_pixel2_vin1-last_pixel_vin1+last_pixel2_vin2-last_pixel_vin2+last_pixel2_vin3-last_pixel_vin3+last_pixel2_vin4-last_pixel_vin4+last_pixel2_vin5-last_pixel_vin5))
	local diff_vcap=$((vcap2-vcap))
	local diff_vdsp=$((vdsp2-vdsp))
	local diff_venc=$((venc2-venc))

	local p2=${diff_last_pixel#-}
	local p3=${diff_vcap#-}
	local p4=${diff_vdsp#-}

	echo "last_pixel in 1s: $p2"
	echo "vcap in 1s: $p3"
	echo "vdsp in 1s: $p4"

	func_is_encoding_state
	if [ $? -eq "1" ]; then
		local p5=${diff_venc#-}
		echo "venc in 1s: $p5"
		if [ "$p5" -eq 0 ]; then
			func_dump_info
			exit 1
		fi
	fi

	if [ "$p2" -eq 0 ] || [ "$p3" -eq 0 ] || [ "$p4" -eq 0 ]; then
		func_dump_info
		exit 1
	fi
}

func_check_interrupt_cv5x()
{
	func_is_iav_init_state
	if [ $? -eq "1" ]; then
		continue;
	fi

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN1}
	local last_pixel_vin1=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN2}
	local last_pixel_vin2=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN3}
	local last_pixel_vin3=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN4}
	local last_pixel_vin4=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN5}
	local last_pixel_vin5=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN6}
	local last_pixel_vin6=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN7}
	local last_pixel_vin7=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN8}
	local last_pixel_vin8=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN9}
	local last_pixel_vin9=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN10}
	local last_pixel_vin10=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN11}
	local last_pixel_vin11=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN12}
	local last_pixel_vin12=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN13}
	local last_pixel_vin13=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc=$glo_var

	sleep 1

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel2=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN1}
	local last_pixel2_vin1=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN2}
	local last_pixel2_vin2=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN3}
	local last_pixel2_vin3=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN4}
	local last_pixel2_vin4=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN5}
	local last_pixel2_vin5=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN6}
	local last_pixel2_vin6=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN7}
	local last_pixel2_vin7=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN8}
	local last_pixel2_vin8=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN9}
	local last_pixel2_vin9=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN10}
	local last_pixel2_vin10=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN11}
	local last_pixel2_vin11=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN12}
	local last_pixel2_vin12=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN13}
	local last_pixel2_vin13=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap2=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp2=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc2=$glo_var

	local diff_last_pixel=$((last_pixel2-last_pixel+last_pixel2_vin1-last_pixel_vin1+last_pixel2_vin2-last_pixel_vin2+last_pixel2_vin3-last_pixel_vin3+\
		last_pixel2_vin4-last_pixel_vin4+last_pixel2_vin5-last_pixel_vin5+last_pixel2_vin6-last_pixel_vin6+last_pixel2_vin7-last_pixel_vin7+\
		last_pixel2_vin8-last_pixel_vin8+last_pixel2_vin9-last_pixel_vin9+last_pixel2_vin10-last_pixel_vin10+last_pixel2_vin11-last_pixel_vin11+\
		last_pixel2_vin12-last_pixel_vin12+last_pixel2_vin13-last_pixel_vin13))
	local diff_vcap=$((vcap2-vcap))
	local diff_vdsp=$((vdsp2-vdsp))
	local diff_venc=$((venc2-venc))

	local p2=${diff_last_pixel#-}
	local p3=${diff_vcap#-}
	local p4=${diff_vdsp#-}

	echo "last_pixel in 1s: $p2"
	echo "vcap in 1s: $p3"
	echo "vdsp in 1s: $p4"

	func_is_encoding_state
	if [ $? -eq "1" ]; then
		local p5=${diff_venc#-}
		echo "venc in 1s: $p5"
		if [ "$p5" -eq 0 ]; then
			func_dump_info
			exit 1
		fi
	fi

	if [ "$p2" -eq 0 ] || [ "$p3" -eq 0 ] || [ "$p4" -eq 0 ]; then
		func_dump_info
		exit 1
	fi
}

func_check_interrupt_others()
{
	func_is_iav_init_state
	if [ $? -eq "1" ]; then
		continue;
	fi

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc=$glo_var

	sleep 1

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel2=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap2=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp2=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc2=$glo_var

	local diff_last_pixel=$((last_pixel2-last_pixel))
	local diff_vcap=$((vcap2-vcap))
	local diff_vdsp=$((vdsp2-vdsp))
	local diff_venc=$((venc2-venc))

	local p2=${diff_last_pixel#-}
	local p3=${diff_vcap#-}
	local p4=${diff_vdsp#-}

	if [ "$CHIP" != "S5" ] ; then
		echo "last_pixel in 1s: $p2"
		echo "vcap in 1s: $p3"
		echo "vdsp in 1s: $p4"
	fi

	func_is_encoding_state
	if [ $? -eq "1" ]; then
		local p5=${diff_venc#-}
		echo "venc in 1s: $p5"
		if [ "$p5" -eq 0 ]; then
			func_dump_info
			exit 1
		fi
	fi

	if [ "$p2" -eq 0 ] || [ "$p3" -eq 0 ] || [ "$p4" -eq 0 ]; then
		func_dump_info
		exit 1
	fi
}

func_check_interrupt_s5l()
{
	func_is_iav_init_state
	if [ $? -eq "1" ]; then
		continue;
	fi

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN1}
	local last_pixel_vin1=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc=$glo_var
	sleep 1

	func_get_interrupts ${IRQ_LAST_PIXEL}
	local last_pixel2=$glo_var

	func_get_interrupts ${IRQ_LAST_PIXEL_VIN1}
	local last_pixel2_vin1=$glo_var

	func_get_interrupts ${IRQ_VCAP}
	local vcap2=$glo_var

	func_get_interrupts ${IRQ_VDSP}
	local vdsp2=$glo_var

	func_get_interrupts ${IRQ_VENC}
	local venc2=$glo_var

	local diff_last_pixel=$((last_pixel2-last_pixel+last_pixel2_vin1-last_pixel_vin1))
	local diff_vcap=$((vcap2-vcap))
	local diff_vdsp=$((vdsp2-vdsp))
	local diff_venc=$((venc2-venc))

	local p2=${diff_last_pixel#-}
	local p3=${diff_vcap#-}
	local p4=${diff_vdsp#-}

	echo "last_pixel in 1s: $p2"
	echo "vcap in 1s: $p3"
	echo "vdsp in 1s: $p4"

	func_is_encoding_state
	if [ $? -eq "1" ]; then
		local p5=${diff_venc#-}
		echo "venc in 1s: $p5"
		if [ "$p5" -eq 0 ]; then
			func_dump_info
			exit 1
		fi
	fi

	if [ "$p2" -eq 0 ] || [ "$p3" -eq 0 ] || [ "$p4" -eq 0 ]; then
		func_dump_info
		exit 1
	fi
}

func_check_interrupt()
{
	case "$CHIP" in
	"S2L")
	func_check_interrupt_s2l
	;;
	"S5L")
	func_check_interrupt_s5l
	;;
	"CV1")
	func_check_interrupt_cv1
	;;
	"CV22" | "CV25" | "CV2" | "S6LM" | "CV28")
	func_check_interrupt_cv2x
	;;
	"CV5" | "CV52")
	func_check_interrupt_cv5x
	;;
	*)
	func_check_interrupt_others
	;;
	esac
}

func_do_audit_enable_cv2x()
{
	func_is_encoding_state
	if [ $? -eq "1" ]; then
		test_encode --debug-audit-idsp-enable 1
	fi
}

func_enable_audit()
{
	case "$CHIP" in
	"CV22" | "CV25" | "CV2" | "S6LM" | "CV28")
	func_do_audit_enable_cv2x
	;;
	*)
	;;
	esac
}

echo "Delete ${REGISTER_FOLDER} folder if it already exists"
rm -rf ${REGISTER_FOLDER}
mkdir -p ${REGISTER_FOLDER}
date > ${REGISTER_FOLDER}/${LOG_TYPE_SYS}_start_date.txt

dsplog_cap -m all -b all -l ${DSPLOG_DEBUG_LEVEL} -o ${DSPLOG_FOLDER}/${DSPLOG_BEFORE_FILE}.bin -p ${DSPLOG_FILE_SIZE} &

func_enable_audit

while true
do
func_check_interrupt
done

