Beispiel #1
0
/***************************************************************************//**
 * @brief Main function.
 *
 * @return Returns 0.
*******************************************************************************/
int main()
{
	UINT32 StartCount;

	MajorRev     = 1;
	MinorRev     = 1;
	RcRev        = 1;
	DriverEnable = TRUE;
	LastEnable   = FALSE;

	Xil_ICacheEnable();
	Xil_DCacheEnable();

#ifdef XPAR_AXI_IIC_0_BASEADDR
	HAL_PlatformInit(XPAR_AXI_IIC_0_BASEADDR,	/* Perform any required platform init */
					 XPAR_SCUTIMER_DEVICE_ID,	/* including hardware reset to HDMI devices */
					 XPAR_SCUGIC_SINGLE_DEVICE_ID,
					 XPAR_SCUTIMER_INTR);
#else
	HAL_PlatformInit(XPAR_AXI_IIC_MAIN_BASEADDR,	/* Perform any required platform init */
					 XPAR_SCUTIMER_DEVICE_ID,	/* including hardware reset to HDMI devices */
					 XPAR_SCUGIC_SINGLE_DEVICE_ID,
					 XPAR_SCUTIMER_INTR);
#endif

	Xil_ExceptionEnable();

	SetVideoResolution(RESOLUTION_640x480);
	InitHdmiAudioPcore();

	APP_PrintRevisions();       /* Display S/W and H/W revisions */

	DBG_MSG("To change the video resolution press:\r\n");
	DBG_MSG("  '0' - 640x480;  '1' - 800x600;  '2' - 1024x768; '3' - 1280x720 \r\n");
	DBG_MSG("  '4' - 1360x768; '5' - 1600x900; '6' - 1920x1080.\r\n");

	ADIAPI_TransmitterInit();   /* Initialize ADI repeater software and h/w */

	ADIAPI_TransmitterSetPowerMode(REP_POWER_UP);

	StartCount = HAL_GetCurrentMsCount();

	while(1)
	{
		if (ATV_GetElapsedMs (StartCount, NULL) >= HDMI_CALL_INTERVAL_MS)
		{
			StartCount = HAL_GetCurrentMsCount();
			if (APP_DriverEnabled())
			{
				ADIAPI_TransmitterMain();
			}
		}
		APP_ChangeResolution();
	}

	Xil_DCacheDisable();
	Xil_ICacheDisable();

	return(0);
}
Beispiel #2
0
/***************************************************************************//**
 * @brief Changes the video resolution.
 *
 * @return None.
*******************************************************************************/
static void APP_ChangeResolution (void)
{
	char *resolutions[7] = {"640x480", "800x600", "1024x768", "1280x720", "1360x768", "1600x900", "1920x1080"};
	char receivedChar    = 0;

	if(XUartPs_IsReceiveData(UART_BASEADDR))
	{
		receivedChar = inbyte();
		if((receivedChar >= 0x30) && (receivedChar <= 0x36))
		{
			SetVideoResolution(receivedChar - 0x30);
			DBG_MSG("Resolution was changed to %s \r\n", resolutions[receivedChar - 0x30]);
		}
		else
		{
			if((receivedChar != 0x0A) && (receivedChar != 0x0D))
			{
				SetVideoResolution(RESOLUTION_640x480);
				DBG_MSG("Resolution was changed to %s \r\n", resolutions[0]);
			}
		}
	}
}
void SCREEN_Init(UINT32 resolution)
{

	UINT32 StartCount;

		MajorRev     = 1;
		MinorRev     = 1;
		RcRev        = 1;
		DriverEnable = TRUE;
		LastEnable   = FALSE;

		Xil_ICacheEnable();
		Xil_DCacheEnable();

	#ifdef XPAR_AXI_IIC_0_BASEADDR
		HAL_PlatformInit(XPAR_AXI_IIC_0_BASEADDR,	/* Perform any required platform init */
						 XPAR_SCUTIMER_DEVICE_ID,	/* including hardware reset to HDMI devices */
						 XPAR_SCUGIC_SINGLE_DEVICE_ID,
						 XPAR_SCUTIMER_INTR);
	#else
		HAL_PlatformInit(XPAR_AXI_IIC_MAIN_BASEADDR,	/* Perform any required platform init */
						 XPAR_SCUTIMER_DEVICE_ID,	/* including hardware reset to HDMI devices */
						 XPAR_SCUGIC_SINGLE_DEVICE_ID,
						 XPAR_SCUTIMER_INTR);
	#endif

		Xil_ExceptionEnable();

		SetVideoResolution( resolution);
		InitHdmiAudioPcore();

		APP_PrintRevisions();       /* Display S/W and H/W revisions */

//		DBG_MSG("To change the video resolution press:\r\n");
//		DBG_MSG("  '0' - 640x480;  '1' - 800x600;  '2' - 1024x768; '3' - 1280x720 \r\n");
//		DBG_MSG("  '4' - 1360x768; '5' - 1600x900; '6' - 1920x1080.\r\n");

		ADIAPI_TransmitterInit();   /* Initialize ADI repeater software and h/w */

		ADIAPI_TransmitterSetPowerMode(REP_POWER_UP);

		StartCount = HAL_GetCurrentMsCount();

}
Beispiel #4
0
/***************************************************************************//**
 * @brief Main function.
 *
 * @return Returns 0.
 *******************************************************************************/
int main() {

	MajorRev = 1;
	MinorRev = 1;
	RcRev = 1;
	DriverEnable = TRUE;
	LastEnable = FALSE;

	/*Enable cache*/
	Xil_ICacheEnable();
	Xil_DCacheEnable();

	/* Perform any required platform init */
	/* including hardware reset to HDMI devices */
	HAL_PlatformInit(XPAR_AXI_IIC_0_BASEADDR, XPAR_SCUTIMER_DEVICE_ID,
			XPAR_SCUGIC_SINGLE_DEVICE_ID, XPAR_SCUTIMER_INTR);

	/* Initialize ADI repeater software and h/w */
	ADIAPI_TransmitterInit();
	ADIAPI_TransmitterSetPowerMode(REP_POWER_UP);

	StartCount = HAL_GetCurrentMsCount();
	ADIAPI_TransmitterMain();

	/*Initialize the HDMI Core with default display settings*/
	SetVideoResolution(RESOLUTION_640x480);

	/*
	 * Initialize CE engine
	 */
	xstatus = CE_init();
	if (xstatus != XST_SUCCESS) {
		xil_printf("Unable to initialize CE HA!\n");
		return XST_FAILURE;
	}

	/*
	 * Initialize ME engine
	 */
	xstatus = ME_init();
	if (xstatus != XST_SUCCESS) {
		xil_printf("Unable to initialize ME HA!\n");
		return XST_FAILURE;
	}

	/*
	 * Initialize EEE engine
	 */
	xstatus = EEE_init();
	if (xstatus != XST_SUCCESS) {
		xil_printf("Unable to initialize EEE HA!\n");
		return XST_FAILURE;
	}

	/*
	 * Initialize ECE engine
	 */
	xstatus = ECE_init();
	if (xstatus != XST_SUCCESS) {
		xil_printf("Unable to initialize ECE HA!\n");
		return XST_FAILURE;
	}

	/* Initialize the interrupt controller */
	xstatus = ScuGicInterrupt_Init();
	if (xstatus != XST_SUCCESS) {
		xil_printf("Unable to initialize Interrupts\n");
		return XST_FAILURE;
	}

	/*
	 * Initially configure CE
	 */
	XCe_SetWidth(&hlsCE, width);
	XCe_SetHeight(&hlsCE, height);
	XCe_SetCsd1(&hlsCE, csd1);
	XCe_SetCsd2(&hlsCE, csd2);
	XCe_SetEpsilon(&hlsCE, epsilon);

	/*
	 *  Initially configure ME
	 */

	XMatchingengine32_SetWidth_v(&hlsME, width);
	XMatchingengine32_SetHeight_v(&hlsME, height);
	XMatchingengine32_SetReadaddress1_v(&hlsME, CE_OUTPUT_1_BASEADDR);
	XMatchingengine32_SetReadaddress2_v(&hlsME, CE_OUTPUT_2_BASEADDR);
	XMatchingengine32_SetFeatureout_v(&hlsME, FEATURE_X1_BASEADDR);

	/*
	 *  Initially configure EEE
	 */

	XEee_SetFaddr_v(&hlsEEE, FEATURE_X1_BASEADDR);
	XEee_SetVecoutaddr_v(&hlsEEE, PRE_COMP_VECTOR_HW);
	XEee_SetModelcount_v(&hlsEEE, 300);
	XEee_SetErrthres_v(&hlsEEE, 2);
	XEee_SetResultaddr_v(&hlsEEE, RESULT_ADDR);
	XEee_SetModeladdr_v(&hlsEEE, (u32) model_param_32);

	/*
	 *  No initial configuration for EEE
	 */

	XEee_SetFaddr_v(&hlsEEE, FEATURE_X1_BASEADDR);
	XEee_SetVecoutaddr_v(&hlsEEE, PRE_COMP_VECTOR_HW);
	XEee_SetModelcount_v(&hlsEEE, 300);
	XEee_SetErrthres_v(&hlsEEE, 2);
	XEee_SetResultaddr_v(&hlsEEE, RESULT_ADDR);
	XEee_SetModeladdr_v(&hlsEEE, (u32) model_param_32);

	/*
	 * Initial Camera/Still Image mode choose
	 */
	printf("-------------------------------------\n");
	printf("----------------Menu-----------------\n");
	printf("-------------------------------------\n");
	printf("-----Camera mode: press 'v' or 'V'---\n");
	printf("-Sill images mode: press 'i' or 'I'--\n");
	printf("--Quit Processing: press 'q' or 'Q'--\n");
	printf("-------------------------------------\n");
	printf("-------------------------------------\n");

	char ctmp = 0;
	while (1) {
		while (!XUartPs_IsReceiveData(UART_BASEADDR))
			;
		ctmp = inbyte();
		if (ctmp == 'v' || ctmp == 'V') {
			Camflag = 1;
			printf("-------------------------------------\n");
			printf("--------------Camera mode------------\n");
			printf("-------------------------------------\n");
			printf("-------------------------------------\n");
			printf(
					"You can switch to Still Image mode using 'i' or 'I' later\n");
			printf("-------------------------------------\n");
			break;
		}
		if (ctmp == 'i' || ctmp == 'I') {
			Camflag = 0;
			printf("-------------------------------------\n");
			printf("------------Still image mode---------\n");
			printf("-------------------------------------\n");
			printf("-------------------------------------\n");
			printf("You can switch to Camera mode using 'v' or 'V' later\n");
			printf("-------------------------------------\n");
			break;
		}
		if (ctmp == 'q' || ctmp == 'Q') {
			printf("-----------Exiting Application-------\n");
			return 0;
		}
		printf("No such Option!!\n");
	}

	/*
	 * Instruction book
	 */
	printf("-------------------------------------\n");
	printf("-------------Instructions------------\n");
	printf("-------------------------------------\n");
	printf("With/W.o. processing: press 'o' or 'O'\n");
	printf("---Pure software: press 's' or 'S'---\n");
	printf("---Pure hardware: press 'h' or 'H'---\n");
	printf("Toggle SW/HW for CE: press 'c' or 'C'\n");
	printf("Toggle SW/HW for ME: press 'm' or 'M'\n");
	printf("Toggle SW/HW for EEE: press 'e' or 'E'\n");
	printf("Toggle SW/HW for ECE: press 'f' or 'F'\n");
	printf("--------Show CE output: press '1'--------\n");
	printf("--------Show ME output: press '2'--------\n");
	printf("------Show final output: press '3'-------\n");
	printf("--Quit Processing: press 'q' or 'Q'--\n");
	printf("-------------------------------------\n");
	printf("-------------------------------------\n");
	printf("-----------------------------------------\n");
	printf("Special instructions for Still Image mode\n");
	printf("-----------------------------------------\n");
	printf("Start from the first frame: press up arrow\n");
	printf("---Go to the last frame: press down arrow\n");
	printf("Processing the next frame: press right arrow\n");
	printf("Processing the previous frame: press left arrow\n");
	printf("-----------------------------------------\n");
	printf("-----------------------------------------\n");

	/*
	 * Main loop
	 */
	while (config()) {
		if (Oflag) {
			if (Camflag) {
				while (FRAME_INTR == 0)
					;
				FRAME_INTR = 0;
				CameraCopy(640, 480,
						detailedTiming[currentResolution][H_ACTIVE_TIME],
						detailedTiming[currentResolution][V_ACTIVE_TIME],
						VIDEO_BASEADDR, OUTPUT_BASEADDR);
			} else {
				ConvGray8ToGray32(640, 480, GET_INPUT_ADDR(fnum+1),
				OUTPUT_BASEADDR);
			}
		} else {
			if (!ceflag) {
				if (!Camflag) {
					printf("Still image mode, Software CE processing\n");
					init_perfcounters(1, 0);
					EnablePerfCounters();
					count = get_cyclecount();
					ImageSmoothGray8(640, 480, GET_INPUT_ADDR(fnum),
					CE_BYTE_1_BASEADDR);
					CensusEngine8to32(640, 480, 20, 3, 7, CE_BYTE_1_BASEADDR,
					CE_OUTPUT_1_BASEADDR);
					count = get_cyclecount() - count;
					printf("CE software processing 1 time:%f \n",
							((float) count) / CPUFREQ * 1000);
					ceswcount++;
					ceswsum += count;

					init_perfcounters(1, 0);
					EnablePerfCounters();
					count = get_cyclecount();
					ImageSmoothGray8(640, 480, GET_INPUT_ADDR(fnum+1),
					CE_BYTE_2_BASEADDR);
					CensusEngine8to32(640, 480, 20, 3, 7, CE_BYTE_2_BASEADDR,
					CE_OUTPUT_2_BASEADDR);
					count = get_cyclecount() - count;
					printf("CE software processing 2 time:%f \n",
							((float) count) / CPUFREQ * 1000);
					ceswcount++;
					ceswsum += count;
					Xil_DCacheFlush();
				} else {
					printf("Camera mode, Software CE processing\n");
					while (FRAME_INTR == 0)
						;
					FRAME_INTR = 0;
					Camera24ToGray8(640, 480,
							detailedTiming[currentResolution][H_ACTIVE_TIME],
							detailedTiming[currentResolution][V_ACTIVE_TIME],
							VIDEO_BASEADDR, CE_PROC_1_BASEADDR);

					init_perfcounters(1, 0);
					EnablePerfCounters();
					count = get_cyclecount();
					ImageSmoothGray8(640, 480, CE_PROC_1_BASEADDR,
					CE_BYTE_1_BASEADDR);
					CensusEngine8to32(640, 480, 20, 3, 7, CE_BYTE_1_BASEADDR,
					CE_OUTPUT_1_BASEADDR);
					count = get_cyclecount() - count;
					printf("CE software processing 1 time:%f \n",
							((float) count) / CPUFREQ * 1000);
					ceswcount++;
					ceswsum += count;

					while (FRAME_INTR == 0)
						;
					FRAME_INTR = 0;
					CameraCopy(640, 480,
							detailedTiming[currentResolution][H_ACTIVE_TIME],
							detailedTiming[currentResolution][V_ACTIVE_TIME],
							VIDEO_BASEADDR, BUF_CAM);
					Camera24ToGray8(640, 480,
							detailedTiming[currentResolution][H_ACTIVE_TIME],
							detailedTiming[currentResolution][V_ACTIVE_TIME],
							VIDEO_BASEADDR, CE_PROC_2_BASEADDR);

					init_perfcounters(1, 0);
					EnablePerfCounters();
					count = get_cyclecount();
					ImageSmoothGray8(640, 480, CE_PROC_2_BASEADDR,
					CE_BYTE_2_BASEADDR);
					CensusEngine8to32(640, 480, 20, 3, 7, CE_BYTE_2_BASEADDR,
					CE_OUTPUT_2_BASEADDR);
					count = get_cyclecount() - count;
					printf("CE software processing 2 time:%f \n",
							((float) count) / CPUFREQ * 1000);
					ceswcount++;
					ceswsum += count;

					Xil_DCacheFlush();
				}

			} else {
				if (!XCe_IsReady(&hlsCE)) {
					DBG_MSG(
							"!!! HLS_CE peripheral is not ready! Exiting...\n\r");
					return XST_FAILURE;
				}
				if (!Camflag) {
					printf("Still image mode, Hardware CE processing\n");
					XCe_SetReadaddress(&hlsCE, GET_INPUT_ADDR(fnum));
				} else {
					printf("Camera mode, Hardware CE processing\n");
					while (FRAME_INTR == 0)
						;
					FRAME_INTR = 0;
					Camera24ToGray8(640, 480,
							detailedTiming[currentResolution][H_ACTIVE_TIME],
							detailedTiming[currentResolution][V_ACTIVE_TIME],
							VIDEO_BASEADDR, CE_PROC_1_BASEADDR);
					Xil_DCacheFlush();
					XCe_SetReadaddress(&hlsCE, CE_PROC_1_BASEADDR);
				}

				XCe_SetWriteaddress(&hlsCE, CE_OUTPUT_1_BASEADDR);
				init_perfcounters(1, 0);
				EnablePerfCounters();
				count = get_cyclecount();
				CE_start();
				while (CEisdone == 0)
					;
				CEisdone = 0;
				count = get_cyclecount() - count;
				printf("CE hardware processing 1 time:%f \n",
						((float) count) / CPUFREQ * 1000);
				cehwcount++;
				cehwsum += count;

				if (!XCe_IsReady(&hlsCE)) {
					DBG_MSG(
							"!!! HLS_CE peripheral is not ready! Exiting...\n\r");
					return XST_FAILURE;
				}

				if (!Camflag) {
					XCe_SetReadaddress(&hlsCE, GET_INPUT_ADDR(fnum+1));
				} else {
					while (FRAME_INTR == 0)
						;
					FRAME_INTR = 0;
					CameraCopy(640, 480,
							detailedTiming[currentResolution][H_ACTIVE_TIME],
							detailedTiming[currentResolution][V_ACTIVE_TIME],
							VIDEO_BASEADDR, BUF_CAM);
					Camera24ToGray8(640, 480,
							detailedTiming[currentResolution][H_ACTIVE_TIME],
							detailedTiming[currentResolution][V_ACTIVE_TIME],
							VIDEO_BASEADDR, CE_PROC_2_BASEADDR);
					Xil_DCacheFlush();
					XCe_SetReadaddress(&hlsCE, CE_PROC_2_BASEADDR);
				}

				XCe_SetWriteaddress(&hlsCE, CE_OUTPUT_2_BASEADDR);
				init_perfcounters(1, 0);
				EnablePerfCounters();
				count = get_cyclecount();
				CE_start();
				while (CEisdone == 0)
					;
				CEisdone = 0;
				count = get_cyclecount() - count;
				printf("CE hardware processing 2 time:%f \n",
						((float) count) / CPUFREQ * 1000);
				cehwcount++;
				cehwsum += count;
			}
			if (!meflag) {
				if (!Camflag) {
					printf("Still image mode, Software ME processing\n");
				} else {
					printf("Camera mode, Software ME processing\n");
				}
				init_perfcounters(1, 0);
				EnablePerfCounters();
				count = get_cyclecount();
				matchcount = MatchingEngine32HWO(640, 480, 7, 7,
				CE_OUTPUT_1_BASEADDR, CE_OUTPUT_2_BASEADDR,
				FEATURE_X1_BASEADDR);
				count = get_cyclecount() - count;
				printf("ME software processing time:%f \n",
						((float) count) / CPUFREQ * 1000);
				printf("matchcount: %d\n", matchcount);
				meswcount++;
				meswsum += count;

				Xil_DCacheFlush();
			} else {
				if (!Camflag) {
					printf("Still image mode, Hardware ME processing\n");
				} else {
					printf("Camera mode, Hardware ME processing\n");
				}
				if (!XMatchingengine32_IsReady(&hlsME)) {
					DBG_MSG(
							"!!! HLS_ME peripheral is not ready! Exiting...\n\r");
					return XST_FAILURE;
				}

				init_perfcounters(1, 0);
				EnablePerfCounters();
				count = get_cyclecount();
				ME_start();
				while (MEisdone == 0)
					;
				MEisdone = 0;
				count = get_cyclecount() - count;
				printf("ME hardware processing time:%f \n",
						((float) count) / CPUFREQ * 1000);
				matchcount = XMatchingengine32_GetReturn(&hlsME);
				printf("matchcount: %d\n", matchcount);
				mehwcount++;
				mehwsum += count;
			}
			if (!Camflag) {
				ConvGray8ToGray32(640, 480, GET_INPUT_ADDR(fnum+1),
				OUTPUT_ME_BASEADDR);
				DrawVector32hw(640, 480, FEATURE_X1_BASEADDR, matchcount,
				OUTPUT_ME_BASEADDR, 0);
				Xil_DCacheFlush();
			}
			presample(FEATURE_X1_BASEADDR, FEATURE_IMG, matchcount, 640, 480);

			if (!eeeflag) {
				if (!Camflag) {
					printf("Still image mode, Software EEE processing\n");
				} else {
					printf("Camera mode, Software EEE processing\n");
				}
				init_perfcounters(1, 0);
				EnablePerfCounters();
				count = get_cyclecount();
				samplecount = sample_flow_vectors(FEATURE_IMG, COMP_VECTOR, 640,
						480, 2, 8);
				ret = estimate_ego_motion_first_order_flow(COMP_VECTOR,
						samplecount, model_param_est, 300, 300, 2, 0.75F);
				count = get_cyclecount() - count;
				printf("SW EEE consuming time: %f ms\n",
						((float) count) / CPUFREQ * 1000);
				printf("samplecount: %d\n", samplecount);

				if (ret) {
					printf("Software EEE succeeds!!\n");
					eeeswcount++;
					eeeswsum += count;
					Xil_DCacheFlush();
				} else {
					printf("Software EEE fails!!\n");
				}
			} else {
				if (!Camflag) {
					printf("Still image mode, Hardware EEE processing\n");
				} else {
					printf("Camera mode, Hardware EEE processing\n");
				}

				if (!XEee_IsReady(&hlsEEE)) {
					DBG_MSG(
							"!!! HLS_EEE peripheral is not ready! Exiting...\n\r");
					return XST_FAILURE;
				}

				XEee_SetMatchcount_v(&hlsEEE, matchcount);
				XEee_SetMode_v(&hlsEEE, 0);

				init_perfcounters(1, 0);
				EnablePerfCounters();
				count = get_cyclecount();

				EEE_start();
				while (EEEisdone == 0)
					;
				EEEisdone = 0;

				samplecount = compressvectorHW(PRE_COMP_VECTOR_HW,
				COMP_VECTOR_HW, 80, 60);

				ret = estimate_ego_motion_first_order_flow_HW( COMP_VECTOR_HW,
						samplecount, model_param_est, model_param_32, 300, 300);

				Xil_DCacheFlush();

				if (ret) {
					if (!XEee_IsReady(&hlsEEE)) {
						DBG_MSG(
								"!!! HLS_EEE peripheral is not ready! Exiting...\n\r");
						return XST_FAILURE;
					}

					XEee_SetMode_v(&hlsEEE, 1);
					XEee_SetModeladdr_v(&hlsEEE, (u32) model_param_32);

					EEE_start();
					while (EEEisdone == 0)
						;
					EEEisdone = 0;

					count = get_cyclecount() - count;
					printf("HW EEE consuming time: %f ms\n",
							((float) count) / CPUFREQ * 1000);
					printf("samplecount: %d\n", samplecount);

					eeehwcount++;
					eeehwsum += count;

					int validvectors = Xil_In32(RESULT_ADDR) >> 16;
					int betteroutlier = Xil_In32(RESULT_ADDR) & 0xffff;
					bmid = Xil_In32(RESULT_ADDR + 4);

					printf(" XC: %f \n\r",
							((float) model_param_32[4 * bmid]) / 8.0);
					printf(" YC: %f \n\r",
							((float) model_param_32[4 * bmid + 1]) / 8.0);
					printf(" D : %f \n\r",
							((float) model_param_32[4 * bmid + 2])
									/ 2147483648.0);
					printf(" R : %f \n\r",
							((float) model_param_32[4 * bmid + 3])
									/ 2147483648.0);
					printf(" Total iterations : %d \n\r", 300);
					printf(" Outlier count    : %d \n\r", betteroutlier);
					printf(" Total count      : %d \n\r", validvectors);
					printf(" Outlier Ratio    : %f \n\r",
							((float) betteroutlier) / ((float) validvectors));
					printf("HW EEE succeeds!!\n");
				} else {
					count = get_cyclecount() - count;
					printf("HW EEE consuming time: %f ms\n",
							((float) count) / CPUFREQ * 1000);
					printf("samplecount: %d\n", samplecount);
					printf("HW EEE fails!!\n");
				}
			}

			if (ret) {
				if (!eceflag) {
					if (eeeflag) {
						model_param_est[0] = ((float) model_param_32[4 * bmid])
								/ 8.0;
						model_param_est[1] = ((float) model_param_32[4 * bmid
								+ 1]) / 8.0;
						model_param_est[2] = ((float) model_param_32[4 * bmid
								+ 2]) / 2147483648.0;
						model_param_est[3] = ((float) model_param_32[4 * bmid
								+ 3]) / 2147483648.0;
					}
					init_perfcounters(1, 0);
					EnablePerfCounters();
					count = get_cyclecount();
					samplecount = sample_flow_vectors(FEATURE_IMG, FULL_VECTOR,
							640, 480, 0, 1);
					gen_firstOrderFlow_vectors_4(model_param_est, samplecount,
					FULL_VECTOR, RES_VECTOR);
					diff_motion_vectors(FULL_VECTOR, RES_VECTOR, samplecount,
					RES_VECTOR, 2);
					count = get_cyclecount() - count;
					printf("SW ECE consuming time: %f ms\n",
							((float) count) / CPUFREQ * 1000);
					if (!Camflag) {
						ConvGray8ToGray32(640, 480, GET_INPUT_ADDR(fnum+1),
						OUTPUT_BASEADDR);
					} else {
						CameraCopy(640, 480,
								detailedTiming[currentResolution][H_ACTIVE_TIME],
								detailedTiming[currentResolution][V_ACTIVE_TIME],
								BUF_CAM, OUTPUT_BASEADDR);
					}
					DrawVector32eee(640, 480, samplecount, RES_VECTOR,
					OUTPUT_BASEADDR, 0);
					Xil_DCacheFlush();

					eceswcount++;
					eceswsum += count;
				} else {
					if (!XEce_IsReady(&hlsECE)) {
						DBG_MSG(
								"!!! HLS_ECE peripheral is not ready! Exiting...\n\r");
						return XST_FAILURE;
					}

					XEce_SetFullvectoraddr_v(&hlsECE, FEATURE_X1_BASEADDR);
					XEce_SetVeccount_v(&hlsECE, matchcount);
					XEce_SetResultvectoraddr_v(&hlsECE, FEATURE_X2_BASEADDR);
					XEce_SetErrthres_v(&hlsECE, 2);

					if (!eeeflag) {
						model_param_32_tmp[0] = (int) (model_param_est[0] * 8);
						model_param_32_tmp[1] = (int) (model_param_est[1] * 8);
						model_param_32_tmp[2] = (int) (model_param_est[2]
								* 2147483648);
						model_param_32_tmp[3] = (int) (model_param_est[3]
								* 2147483648);
					} else {
						model_param_32_tmp[0] = model_param_32[4 * bmid];
						model_param_32_tmp[1] = model_param_32[4 * bmid + 1];
						model_param_32_tmp[2] = model_param_32[4 * bmid + 2];
						model_param_32_tmp[3] = model_param_32[4 * bmid + 3];
					}
					Xil_Out32(BEST_MODEL, model_param_32_tmp[0]);
					Xil_Out32(BEST_MODEL + 4, model_param_32_tmp[1]);
					Xil_Out32(BEST_MODEL + 8, model_param_32_tmp[2]);
					Xil_Out32(BEST_MODEL + 12, model_param_32_tmp[3]);
					Xil_DCacheFlush();

					XEce_SetBestmodeladdr_v(&hlsECE, BEST_MODEL);

					init_perfcounters(1, 0);
					EnablePerfCounters();
					count = get_cyclecount();
					ECE_start();
					while (ECEisdone == 0)
						;
					ECEisdone = 0;
					count = get_cyclecount() - count;
					matchcount2 = XEce_GetReturn(&hlsECE);

					printf("HW ECE consuming time: %f ms\n",
							((float) count) / CPUFREQ * 1000);
					printf("Rest vector numbers: %d \n", matchcount2);

					if (!Camflag) {
						ConvGray8ToGray32(640, 480, GET_INPUT_ADDR(fnum+1),
						OUTPUT_BASEADDR);
					} else {
						CameraCopy(640, 480,
								detailedTiming[currentResolution][H_ACTIVE_TIME],
								detailedTiming[currentResolution][V_ACTIVE_TIME],
								BUF_CAM, OUTPUT_BASEADDR);
					}
					DrawVector32hw(640, 480, FEATURE_X2_BASEADDR, matchcount2,
					OUTPUT_BASEADDR, 0);
					Xil_DCacheFlush();

					ecehwcount++;
					ecehwsum += count;
				}
			} else {
				printf("Because of EEE failure, no compensation done!!\n");
				if (!Camflag) {
					ConvGray8ToGray32(640, 480, GET_INPUT_ADDR(fnum+1),
					OUTPUT_BASEADDR);
				} else {
					CameraCopy(640, 480,
							detailedTiming[currentResolution][H_ACTIVE_TIME],
							detailedTiming[currentResolution][V_ACTIVE_TIME],
							BUF_CAM, OUTPUT_BASEADDR);
				}
				DrawVector32hw(640, 480, FEATURE_X1_BASEADDR, matchcount,
				OUTPUT_BASEADDR, 0);
				Xil_DCacheFlush();
			}
		}
		if (!Camflag) {
			ConfigHdmiVDMA(detailedTiming[currentResolution][H_ACTIVE_TIME],
					detailedTiming[currentResolution][V_ACTIVE_TIME],
					OUTPUT_BASEADDR);
			if (ATV_GetElapsedMs(StartCount, NULL) >= HDMI_CALL_INTERVAL_MS) {
				StartCount = HAL_GetCurrentMsCount();
				if (APP_DriverEnabled()) {
					ADIAPI_TransmitterMain();
				}
			}
		} else {
			if (camceflag) {
				ConfigHdmiVDMA(detailedTiming[currentResolution][H_ACTIVE_TIME],
						detailedTiming[currentResolution][V_ACTIVE_TIME],
						CE_OUTPUT_1_BASEADDR);
			} else if (cammeflag) {
				CameraCopy(640, 480,
						detailedTiming[currentResolution][H_ACTIVE_TIME],
						detailedTiming[currentResolution][V_ACTIVE_TIME],
						BUF_CAM, OUTPUT_ME_BASEADDR);
				DrawVector32hw(640, 480, FEATURE_X1_BASEADDR, matchcount,
				OUTPUT_ME_BASEADDR, 0);
				Xil_DCacheFlush();
				ConfigHdmiVDMA(detailedTiming[currentResolution][H_ACTIVE_TIME],
						detailedTiming[currentResolution][V_ACTIVE_TIME],
						OUTPUT_ME_BASEADDR);
			} else {
				ConfigHdmiVDMA(detailedTiming[currentResolution][H_ACTIVE_TIME],
						detailedTiming[currentResolution][V_ACTIVE_TIME],
						OUTPUT_BASEADDR);

			}
			if (ATV_GetElapsedMs(StartCount, NULL) >= HDMI_CALL_INTERVAL_MS) {
				StartCount = HAL_GetCurrentMsCount();
				if (APP_DriverEnabled()) {
					ADIAPI_TransmitterMain();
				}
			}
		}

	}