コード例 #1
0
ファイル: main.c プロジェクト: circuitsenses/FreeRTOS-Zybo
int main(void)
{
	u32 *vgaPtr[DISPLAY_NUM_FRAMES];
	u32 *hdmiPtr[DISPLAY_NUM_FRAMES];
	int i;
	char userInput = 0;

	for (i = 0; i < DISPLAY_NUM_FRAMES; i++)
	{
		vgaPtr[i] = vgaBuf[i];
		hdmiPtr[i] = hdmiBuf[i];
	}

	DisplayDemoInitialize(&vgaCtrl, VGA_VDMA_ID, SCU_TIMER_ID, VGA_BASEADDR, DISPLAY_NOT_HDMI, vgaPtr);
	DisplayDemoInitialize(&hdmiCtrl, HDMI_VDMA_ID, SCU_TIMER_ID, HDMI_BASEADDR, DISPLAY_HDMI, hdmiPtr);
	AudioInitialize(SCU_TIMER_ID, AUDIO_IIC_ID, AUDIO_CTRL_BASEADDR);
	TimerInitialize(SCU_TIMER_ID);

	/* Flush UART FIFO */
	while (XUartPs_IsReceiveData(UART_BASEADDR))
	{
		XUartPs_ReadReg(UART_BASEADDR, XUARTPS_FIFO_OFFSET);
	}

	while (userInput != 'q')
	{
		MainDemoPrintMenu();

		/* Wait for data on UART */
		while (!XUartPs_IsReceiveData(UART_BASEADDR))
		{}

		/* Store the first character in the UART recieve FIFO and echo it */
		userInput = XUartPs_ReadReg(UART_BASEADDR, XUARTPS_FIFO_OFFSET);
		xil_printf("%c", userInput);

		switch (userInput)
		{
		case '1':
			AudioRunDemo(AUDIO_CTRL_BASEADDR, UART_BASEADDR, SW_BASEADDR, BTN_BASEADDR);
			break;
		case '2':
			DisplayDemoRun(&vgaCtrl, UART_BASEADDR);
			break;
		case '3':
			DisplayDemoRun(&hdmiCtrl, UART_BASEADDR);
			break;
		case 'q':
			break;
		default :
			xil_printf("\n\rInvalid Selection");
			TimerDelay(500000);
		}
	}

	return 0;
}
コード例 #2
0
ファイル: pong.c プロジェクト: felipebetancur/Zybo
char readUART(u32 uartAddress){
	char userInput;
	/* Wait for data on UART */
	while (!XUartPs_IsReceiveData(uartAddress))
	{}

	/* Store the first character in the UART recieve FIFO and echo it */
	userInput = XUartPs_ReadReg(uartAddress, XUARTPS_FIFO_OFFSET);
	xil_printf("%c", userInput);
	return userInput;
}
コード例 #3
0
ファイル: backup.c プロジェクト: BBfight/CNN-on-FPGA
//function to receive from UART port
void uart_receive(float* in,int RecvCount){
	u8 buff[RecvCount];
	int counter = 0;
	while(counter < RecvCount){
		while (!XUartPs_IsReceiveData(Config->BaseAddress));
			;//waiting for input
		XUartPs_Recv(&uart,&buff[counter],1);
		counter++;
	}
	in =(float*) buff;
}
コード例 #4
0
/**
*
* This function receives a byte from the device. It operates in polled mode
* and blocks until a byte has received.
*
* @param	BaseAddress contains the base address of the device.
*
* @return	The data byte received.
*
* @note		None.
*
*****************************************************************************/
u8 XUartPs_RecvByte(u32 BaseAddress)
{
    /*
     * Wait until there is data
     */
    while (!XUartPs_IsReceiveData(BaseAddress));

    /*
     * Return the byte received
     */
    return (XUartPs_ReadReg(BaseAddress, XUARTPS_FIFO_OFFSET));
}
コード例 #5
0
/* ---------------------------------------------------------------------------- *
 * 									menu()										*
 * ---------------------------------------------------------------------------- *
 * Presented at system startup. Allows the user to select between three
 * options by pressing certain keys on the keyboard:
 * 		's' - 	Audio loopback streaming
 * 		'n' - 	Tonal noise is generated by an NCO and added to the audio
 * 				being captured from the audio codec.
 * 		'f' - 	The audio + tonal noise is passed to an adaptive LMS noise
 * 				cancellation filter which will use the tonal noise estimate
 * 				to remove the noise from the audio.
 *
 * 	This menu is shown upon exiting from any of the above options.
 * ---------------------------------------------------------------------------- */
void menu(){
	u8 inp = 0x00;
	u32 CntrlRegister;

	/* Turn off all LEDs */
	Xil_Out32(LED_BASE, 0);

	CntrlRegister = XUartPs_ReadReg(UART_BASEADDR, XUARTPS_CR_OFFSET);

	XUartPs_WriteReg(UART_BASEADDR, XUARTPS_CR_OFFSET,
				  ((CntrlRegister & ~XUARTPS_CR_EN_DIS_MASK) |
				   XUARTPS_CR_TX_EN | XUARTPS_CR_RX_EN));

	xil_printf("\r\n\r\n");
	xil_printf("Embedded LMS Filtering Demo\r\n");
	xil_printf("Enter 's' to stream pure audio, 'n' to add tonal noise and 'f' to adaptively filter\r\n");
	xil_printf("----------------------------------------\r\n");

	// Wait for input from UART via the terminal
	while (!XUartPs_IsReceiveData(UART_BASEADDR));
				inp = XUartPs_ReadReg(UART_BASEADDR, XUARTPS_FIFO_OFFSET);
	// Select function based on UART input
	switch(inp){
	case 's':
		xil_printf("STREAMING AUDIO\r\n");
		xil_printf("Press 'q' to return to the main menu\r\n");
		audio_stream();
		break;
	case 'n':
		xil_printf("ENTERING NOISE GENERATION OPERATION\r\n");
		xil_printf("Select step size via the DIP switches...\r\n\n");
		xil_printf("Press 'q' to return to the main menu\r\n");
		tonal_noise();
		break;
	case 'f':
		xil_printf("ENTERING LMS FILTERING OPERATION\r\n");
		xil_printf("Press 'q' to return to the main menu\r\n");
		lms_filter();
		break;
	default:
		menu();
		break;
	} // switch
} // menu()
コード例 #6
0
ファイル: main.c プロジェクト: gabi-l/inf3995_tp2
/***************************************************************************//**
 * @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]);
			}
		}
	}
}
コード例 #7
0
ファイル: uart_hello.c プロジェクト: pallavides/Bare_AMP_Zed
/**
*
* This function does a minimal test on the UART device using the hardware
* interface.
*
* @param	UartBaseAddress is the base address of the device
*
* @return	XST_SUCCESS if successful, XST_FAILURE if unsuccessful
*
* @note		None.
*
**************************************************************************/
int UartPsEchoExample(u32 UartBaseAddress)
{
	int Index;
	u32 Running;
	u8 RecvChar;
	u32 CntrlRegister;

	CntrlRegister = XUartPs_ReadReg(UartBaseAddress, XUARTPS_CR_OFFSET);

	/*
	 * Enable TX and RX for the device
	 */
	XUartPs_WriteReg(UartBaseAddress, XUARTPS_CR_OFFSET,
			  ((CntrlRegister & ~XUARTPS_CR_EN_DIS_MASK) |
			   XUARTPS_CR_TX_EN | XUARTPS_CR_RX_EN));
	/*
	 * Initialize the send buffer bytes with a pattern to send and the
	 * the receive buffer bytes to zero
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		SendBuffer[Index] = Index + '0';
	}

	/*
	 * Send the entire transmit buffer.
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		/*
		 * Wait until there is space in TX FIFO
		 */
		 while (XUartPs_IsTransmitFull(UartBaseAddress));

		/*
		 * Write the byte into the TX FIFO
		 */
		XUartPs_WriteReg(UartBaseAddress, XUARTPS_FIFO_OFFSET,
				  SendBuffer[Index]);
	}

	Running = TRUE;
	while (Running) {
		 /*
		  * Wait until there is data
		  */
		while (!XUartPs_IsReceiveData(UartBaseAddress));

		RecvChar = XUartPs_ReadReg(UartBaseAddress,
					    XUARTPS_FIFO_OFFSET);

		/* Change the capitalization */
		if (('a' <= RecvChar) && ('z' >= RecvChar)) {
//			 Convert the Capital letter to a small.
			RecvChar = RecvChar - 'a' + 'A';
		}
		else if (('A' <= RecvChar) && ('Z' >= RecvChar)) {
	//		 Convert the small letter to a Capital.
			RecvChar = RecvChar - 'A' + 'a';
		}
		else if (CHAR_ESC == RecvChar) {
			Running = FALSE;
		}

		/* Echo the character back */
		XUartPs_WriteReg(UartBaseAddress,  XUARTPS_FIFO_OFFSET,
				  RecvChar);
	}

	return XST_SUCCESS;
}
コード例 #8
0
void DisplayDemoChangeRes(DisplayCtrl *dispPtr, u32 uartAddr)
{
	char userInput = 0;
	int fResSet = 0;
	int status;

	/* Flush UART FIFO */
	while (XUartPs_IsReceiveData(uartAddr))
	{
		XUartPs_ReadReg(uartAddr, XUARTPS_FIFO_OFFSET);
	}

	while (!fResSet)
	{
		DisplayDemoCRMenu(dispPtr);

		/* Wait for data on UART */
		while (!XUartPs_IsReceiveData(uartAddr))
		{}

		/* Store the first character in the UART recieve FIFO and echo it */
		userInput = XUartPs_ReadReg(uartAddr, XUARTPS_FIFO_OFFSET);
		xil_printf("%c", userInput);
		status = XST_SUCCESS;
		switch (userInput)
		{
		case '1':
			status = DisplayStop(dispPtr);
			DisplaySetMode(dispPtr, &VMODE_640x480);
			DisplayStart(dispPtr);
			fResSet = 1;
			break;
		case '2':
			status = DisplayStop(dispPtr);
			DisplaySetMode(dispPtr, &VMODE_800x600);
			DisplayStart(dispPtr);
			fResSet = 1;
			break;
		case '3':
			status = DisplayStop(dispPtr);
			DisplaySetMode(dispPtr, &VMODE_1280x720);
			DisplayStart(dispPtr);
			fResSet = 1;
			break;
		case '4':
			status = DisplayStop(dispPtr);
			DisplaySetMode(dispPtr, &VMODE_1280x1024);
			DisplayStart(dispPtr);
			fResSet = 1;
			break;
		case '5':
			status = DisplayStop(dispPtr);
			DisplaySetMode(dispPtr, &VMODE_1920x1080);
			DisplayStart(dispPtr);
			fResSet = 1;
			break;
		case 'q':
			fResSet = 1;
			break;
		default :
			xil_printf("\n\rInvalid Selection");
			TimerDelay(500000);
		}
		if (status == XST_DMA_ERROR)
		{
			xil_printf("\n\rWARNING: AXI VDMA Error detected and cleared\n\r");
		}
	}
}
コード例 #9
0
int DisplayDemoRun(DisplayCtrl *dispPtr, u32 uartAddr)
{
	char userInput = 0;
	int nextFrame = 0;

	/* Flush UART FIFO */
	while (XUartPs_IsReceiveData(uartAddr))
	{
		XUartPs_ReadReg(uartAddr, XUARTPS_FIFO_OFFSET);
	}

	while (userInput != 'q')
	{
		DisplayDemoPrintMenu(dispPtr);

		/* Wait for data on UART */
		while (!XUartPs_IsReceiveData(uartAddr))
		{}

		/* Store the first character in the UART recieve FIFO and echo it */
		userInput = XUartPs_ReadReg(uartAddr, XUARTPS_FIFO_OFFSET);
		xil_printf("%c", userInput);

		switch (userInput)
		{
		case '1':
			DisplayDemoChangeRes(dispPtr, uartAddr);
			break;
		case '2':
			nextFrame = dispPtr->curFrame + 1;
			if (nextFrame >= DISPLAY_NUM_FRAMES)
			{
				nextFrame = 0;
			}
			DisplayChangeFrame(dispPtr, nextFrame);
			break;
		case '3':
			DisplayDemoPrintTest(dispPtr->framePtr[dispPtr->curFrame], dispPtr->vMode.width, dispPtr->vMode.height, dispPtr->stride, DISPLAYDEMO_PATTERN_0);
			break;
		case '4':
			DisplayDemoPrintTest(dispPtr->framePtr[dispPtr->curFrame], dispPtr->vMode.width, dispPtr->vMode.height, dispPtr->stride, DISPLAYDEMO_PATTERN_1);
			break;
		case '5':
			DisplayDemoInvertFrame(dispPtr->framePtr[dispPtr->curFrame], dispPtr->framePtr[dispPtr->curFrame], dispPtr->vMode.width, dispPtr->vMode.height, dispPtr->stride);
			break;
		case '6':
			nextFrame = dispPtr->curFrame + 1;
			if (nextFrame >= DISPLAY_NUM_FRAMES)
			{
				nextFrame = 0;
			}
			DisplayDemoInvertFrame(dispPtr->framePtr[dispPtr->curFrame], dispPtr->framePtr[nextFrame], dispPtr->vMode.width, dispPtr->vMode.height, dispPtr->stride);
			DisplayChangeFrame(dispPtr, nextFrame);
			break;
		case 'q':
			break;
		default :
			xil_printf("\n\rInvalid Selection");
			TimerDelay(500000);
		}
	}

	return XST_SUCCESS;
}
コード例 #10
0
ファイル: display_demo.c プロジェクト: Digilent/Arty-Z7
void DemoRun()
{
	int nextFrame = 0;
	char userInput = 0;

	/* Flush UART FIFO */
	while (XUartPs_IsReceiveData(UART_BASEADDR))
	{
		XUartPs_ReadReg(UART_BASEADDR, XUARTPS_FIFO_OFFSET);
	}

	while (userInput != 'q')
	{
		DemoPrintMenu();

		/* Wait for data on UART */
		while (!XUartPs_IsReceiveData(UART_BASEADDR))
		{}

		/* Store the first character in the UART receive FIFO and echo it */
		if (XUartPs_IsReceiveData(UART_BASEADDR))
		{
			userInput = XUartPs_ReadReg(UART_BASEADDR, XUARTPS_FIFO_OFFSET);
			xil_printf("%c", userInput);
		}

		switch (userInput)
		{
		case '1':
			DemoChangeRes();
			break;
		case '2':
			nextFrame = dispCtrl.curFrame + 1;
			if (nextFrame >= DISPLAY_NUM_FRAMES)
			{
				nextFrame = 0;
			}
			DisplayChangeFrame(&dispCtrl, nextFrame);
			break;
		case '3':
			DemoPrintTest(pFrames[dispCtrl.curFrame], dispCtrl.vMode.width, dispCtrl.vMode.height, DEMO_STRIDE, DEMO_PATTERN_0);
			break;
		case '4':
			DemoPrintTest(pFrames[dispCtrl.curFrame], dispCtrl.vMode.width, dispCtrl.vMode.height, DEMO_STRIDE, DEMO_PATTERN_1);
			break;
		case '5':
			DemoInvertFrame(dispCtrl.framePtr[dispCtrl.curFrame], dispCtrl.framePtr[dispCtrl.curFrame], dispCtrl.vMode.width, dispCtrl.vMode.height, dispCtrl.stride);
			break;
		case '6':
			nextFrame = dispCtrl.curFrame + 1;
			if (nextFrame >= DISPLAY_NUM_FRAMES)
			{
				nextFrame = 0;
			}
			DemoInvertFrame(dispCtrl.framePtr[dispCtrl.curFrame], dispCtrl.framePtr[nextFrame], dispCtrl.vMode.width, dispCtrl.vMode.height, dispCtrl.stride);
			DisplayChangeFrame(&dispCtrl, nextFrame);
			break;
		case 'q':
			break;
		default :
			xil_printf("\n\rInvalid Selection");
			TimerDelay(500000);
		}
	}

	return;
}
コード例 #11
0
ファイル: pong.c プロジェクト: felipebetancur/Zybo
void pong(DisplayCtrl *video ,u32 uartAddress, XGpio *btn, XGpio *sw){
	u32 	height = video->vMode.height,
			width = video->vMode.width,
			stride = video->stride,
			*frame,
			speed = 2,
			pause=false;
	char 	entrada;
	frame=video->framePtr[video->curFrame];

	xil_printf("\x1B[H"); //Set cursor to top left of terminal
	xil_printf("\x1B[2J"); //Clear terminal


	Rectangulo bola=crearRectangulo(10,10,RED,ANCHO_BOLA,ALTO_BOLA);
	Rectangulo palaIzquierda = crearRectangulo(0,height/2-ALTO_PALA/2,GREEN,ANCHO_PALA,ALTO_PALA);
	Rectangulo palaDerecha = crearRectangulo(width-ANCHO_PALA,height/2-ALTO_PALA/2,GREEN,ANCHO_PALA,ALTO_PALA);

	int dir_x=true, dir_y=true, indice_frame=0,salir=0,pulsar=0,puntuacionA=0,puntuacionB=0;

	salir = XGpio_DiscreteRead(sw, 1);
	while(salir & 0x8){

		if (salir & 0x1) // 0x1=0b0001=posicion de SW0
			bola.color = WHITE;
		else
			bola.color = RED;

		//apunta a al siguente frame
		indice_frame=nextFrame(video,&frame);
		pintarFondo(frame, BLACK, width,height,stride);

		//movimiento y colision
		if(dir_x == DERECHA)
			if ((bola.x+ANCHO_BOLA > palaDerecha.x) && (bola.y >= palaDerecha.y && bola.y < palaDerecha.y+ALTO_PALA )){
				bola.x-=speed;
				dir_x = IZQUIERDA;
			}else{
				bola.x+=speed;
			}
		else
			if ((bola.x < palaIzquierda.x+ANCHO_PALA) && (bola.y >= palaIzquierda.y && bola.y < palaIzquierda.y+ALTO_PALA)){
				bola.x+=speed;
				dir_x = DERECHA;
			}else{
				bola.x-=speed;
			}
		if(dir_y == ABAJO)
			bola.y+=speed;
		else
			bola.y-=speed;
		//control de direccion
		if (bola.x<0){
			bola.x=width/2;
			bola.y=height/2;
			dir_x=DERECHA;
			puntuacionB++;
			xil_printf("%d - %d\n\r",puntuacionA,puntuacionB);
			TimerDelay(1500000);
		}else if(bola.x>width - ANCHO_BOLA){
			bola.x=width/2;
			bola.y=height/2;
			dir_x=IZQUIERDA;
			puntuacionA++;
			xil_printf("%d - %d\n\r",puntuacionA,puntuacionB);
			TimerDelay(1500000);
		}
		if (bola.y<0){
			bola.y=0;
			dir_y=ABAJO;
		}else if(bola.y>height - ALTO_BOLA){
			bola.y=height - ALTO_BOLA;
			dir_y=ARRIBA;
		}

		//pintar la pelota y las palas
		pintarRectangulo(frame,&bola,width,height,stride);
		pintarRectangulo(frame,&palaDerecha,width,height,stride);
		pintarRectangulo(frame,&palaIzquierda,width,height,stride);
		//flush
		Xil_DCacheFlushRange((unsigned int) frame, DISPLAY_MAX_FRAME * 4);
		DisplayChangeFrame(video,indice_frame);
		//TimerDelay(17000);
		salir = XGpio_DiscreteRead(sw, 1);
		pulsar = XGpio_DiscreteRead(btn, 1);

		//control de las palas
		if (pulsar & 0x1){  	//Pala derecha
			if (palaDerecha.y+ALTO_PALA < height){
				palaDerecha.y+=speed;
			}
		}else if(pulsar & 0x2){
			if (palaDerecha.y >= 0){
				palaDerecha.y-=speed;
			}
		}

		if (pulsar & 0x4 ){		//Pala izquierda
			if (palaIzquierda.y+ALTO_PALA < height){
				palaIzquierda.y+=speed;
			}
		}else if(pulsar & 0x8){
			if (palaIzquierda.y >= 0){
				palaIzquierda.y-=speed;
			}
		}

		//recolocar las palas si se han salido fuera
		if (palaDerecha.y<0)
			palaDerecha.y=0;
		else if (palaDerecha.y+ALTO_PALA>height)
			palaDerecha.y=height-ALTO_PALA;
		if (palaIzquierda.y<0)
			palaIzquierda.y=0;
		else if (palaIzquierda.y+ALTO_PALA>height)
			palaIzquierda.y=height-ALTO_PALA;

		//leer pulsaciones de cambio de velocidad
		if (XUartPs_IsReceiveData(uartAddress)){
			entrada=XUartPs_ReadReg(uartAddress, XUARTPS_FIFO_OFFSET);
			if (entrada==' '){
				pause=true;
				while(pause){
					if (XUartPs_IsReceiveData(uartAddress)){
						entrada=XUartPs_ReadReg(uartAddress, XUARTPS_FIFO_OFFSET);
						if (entrada==' ')
							pause=false;
						else
							cambiarVelocidad(&speed,entrada);
					}
				}
			}else
				cambiarVelocidad(&speed,entrada);
		}
	}

}
コード例 #12
0
ファイル: main.c プロジェクト: munishjassi/vp_zebboard
/***************************************************************************//**
 * @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();
				}
			}
		}

	}
コード例 #13
0
ファイル: main.c プロジェクト: munishjassi/vp_zebboard
/***************************************************************************//**
 * @brief config function
 *
 * @return Returns 0 or 1
 *******************************************************************************/
int config() {
	char ctmp = 0;
	char count = 0;
	count = 0;
	if (!Camflag) {
		while (1) {
			while (!XUartPs_IsReceiveData(UART_BASEADDR))
				;
			ctmp = inbyte();
			if (count == 0) {
				if (ctmp == 27) {
					count++;
				}
				if (ctmp == 'q' || ctmp == 'Q') {
					printf("-----------Exiting Application-------\n");
					return 0;
				}
				if (ctmp == 'v' || ctmp == 'V') {
					printf("-----------Switch to Camera mode-------\n");
					Camflag = 1;
					return 1;
				}
				if (ctmp == 's' || ctmp == 'S') {
					ceflag = 0;
					meflag = 0;
					eeeflag = 0;
					eceflag = 0;
					printf("-----------Pure Software Mode-------\n");
				}
				if (ctmp == 'h' || ctmp == 'H') {
					ceflag = 1;
					meflag = 1;
					eeeflag = 1;
					eceflag = 1;
					printf("-----------Pure Hardware Mode-------\n");
				}
				if (ctmp == 'c' || ctmp == 'C') {
					if (ceflag == 0) {
						ceflag = 1;
						printf("-----------Hardware CE Mode-------\n");
					} else {
						ceflag = 0;
						printf("-----------Software CE Mode-------\n");
					}
				}
				if (ctmp == 'm' || ctmp == 'M') {
					if (meflag == 0) {
						meflag = 1;
						printf("-----------Hardware ME Mode-------\n");
					} else {
						meflag = 0;
						printf("-----------Software ME Mode-------\n");
					}
				}
				if (ctmp == 'e' || ctmp == 'E') {
					if (eeeflag == 0) {
						eeeflag = 1;
						printf("-----------Hardware EEE Mode-------\n");
					} else {
						eeeflag = 0;
						printf("-----------Software EEE Mode-------\n");
					}
				}
				if (ctmp == 'f' || ctmp == 'F') {
					if (eceflag == 0) {
						eceflag = 1;
						printf("-----------Hardware ECE Mode-------\n");
					} else {
						eceflag = 0;
						printf("-----------Software ECE Mode-------\n");
					}
				}
				if (ctmp == 'o' || ctmp == 'O') {
					if (Oflag == 0) {
						Oflag = 1;
						printf("-----------No Processing Mode-------\n");
					} else {
						Oflag = 0;
						printf("-----------With Processing Mode-------\n");
					}
				}
				if (ctmp == '1') {
					ConfigHdmiVDMA(
							detailedTiming[currentResolution][H_ACTIVE_TIME],
							detailedTiming[currentResolution][V_ACTIVE_TIME],
							CE_OUTPUT_2_BASEADDR);
					if (ATV_GetElapsedMs(StartCount,
							NULL) >= HDMI_CALL_INTERVAL_MS) {
						StartCount = HAL_GetCurrentMsCount();
						if (APP_DriverEnabled()) {
							ADIAPI_TransmitterMain();
						}
					}
				}
				if (ctmp == '2') {
					ConfigHdmiVDMA(
							detailedTiming[currentResolution][H_ACTIVE_TIME],
							detailedTiming[currentResolution][V_ACTIVE_TIME],
							OUTPUT_ME_BASEADDR);
					if (ATV_GetElapsedMs(StartCount,
							NULL) >= HDMI_CALL_INTERVAL_MS) {
						StartCount = HAL_GetCurrentMsCount();
						if (APP_DriverEnabled()) {
							ADIAPI_TransmitterMain();
						}
					}
				}
				if (ctmp == '3') {
					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 (count == 1) {
				if (ctmp == 91) {
					count++;
				} else {
					count--;
				}
			} else if (count == 2) {
				count = 0;
				if (ctmp == 68) {
					if (fnum > 0)
						fnum--;
					printf("-------------Play Backward-----------\n");
					break;
				} else if (ctmp == 67) {
					if (fnum < 8)
						fnum++;
					printf("-------------Play Forward------------\n");
					break;
				} else if (ctmp == 65) {
					fnum = 0;
					printf("-------------Start Frame-------------\n");
					break;
				} else if (ctmp == 66) {
					fnum = 8;
					printf("--------------End Frame--------------\n");
					break;
				}
			}
		}
	} else {
		char ctmp = 0;
		int i;
		for (i = 0; i < 15000; i++) {
			if (XUartPs_IsReceiveData(UART_BASEADDR)) {
				ctmp = inbyte();
				break;
			}
		}
		if (ctmp == 'q' || ctmp == 'Q') {
			printf("-----------Exiting Application-------\n");
			return 0;
		}
		if (ctmp == 'i' || ctmp == 'I') {
			printf("-----------Switch to Still Image mode-------\n");
			Camflag = 0;
		}
		if (ctmp == 's' || ctmp == 'S') {
			ceflag = 0;
			meflag = 0;
			eeeflag = 0;
			eceflag = 0;
			printf("-----------Pure Software Mode-------\n");
		}
		if (ctmp == 'h' || ctmp == 'H') {
			ceflag = 1;
			meflag = 1;
			eeeflag = 1;
			eceflag = 1;
			printf("-----------Pure Hardware Mode-------\n");
		}
		if (ctmp == 'c' || ctmp == 'C') {
			if (ceflag == 0) {
				ceflag = 1;
				printf("-----------Hardware CE Mode-------\n");
			} else {
				ceflag = 0;
				printf("-----------Software CE Mode-------\n");
			}
		}
		if (ctmp == 'm' || ctmp == 'M') {
			if (meflag == 0) {
				meflag = 1;
				printf("-----------Hardware ME Mode-------\n");
			} else {
				meflag = 0;
				printf("-----------Software ME Mode-------\n");
			}
		}
		if (ctmp == 'e' || ctmp == 'E') {
			if (eeeflag == 0) {
				eeeflag = 1;
				printf("-----------Hardware EEE Mode-------\n");
			} else {
				eeeflag = 0;
				printf("-----------Software EEE Mode-------\n");
			}
		}
		if (ctmp == 'f' || ctmp == 'F') {
			if (eceflag == 0) {
				eceflag = 1;
				printf("-----------Hardware ECE Mode-------\n");
			} else {
				eceflag = 0;
				printf("-----------Software ECE Mode-------\n");
			}
		}
		if (ctmp == 'o' || ctmp == 'O') {
			if (Oflag == 0) {
				Oflag = 1;
				printf("-----------No Processing Mode-------\n");
			} else {
				Oflag = 0;
				printf("-----------With Processing Mode-------\n");
			}
		}
		if (ctmp == '1') {
			camceflag = 1;
			cammeflag = 0;
		}
		if (ctmp == '2') {
			camceflag = 0;
			cammeflag = 1;
		}
		if (ctmp == '3') {
			camceflag = 0;
			cammeflag = 0;
		}
	}
	return 1;
}
コード例 #14
0
/* ---------------------------------------------------------------------------- *
 * 								lms_filter()									*
 * ---------------------------------------------------------------------------- *
 * This function adds a tonal noise component to the sampled audio from the
 * audio codec by passing a step size to the input of an NCO component in the
 * PL. A sinusoidal signal is received back from the NCO which is then scaled
 * and added to the sampled audio. The audio + noise sample can then be
 * adaptively filtered using an LMS filter in the PL. The resulting audio,
 * filtered or not, is then output to the audio codec.
 *
 * The main menu can be accessed by entering 'q' on the keyboard.
 * ---------------------------------------------------------------------------- */
void lms_filter()
{
	u32 nco_in, nco_out, in_left, in_right, out_left, out_right, step, \
		prevL, prevR, prevTone, temp;

	/* Read step size value from DIP switches */
	step = XGpio_DiscreteRead(&Gpio, SWITCH_CHANNEL);

	/* Write step size value to the LEDs */
	Xil_Out32(LED_BASE, step);

	/* Scale the step size */
	nco_in = step;
	xil_printf("Step = %d, nco_in = %d\r\n",step, nco_in);

	while (!XUartPs_IsReceiveData(UART_BASEADDR)){

		/* Input step size to the NCO core */
		XNco_Set_step_size_V(&Nco, nco_in);

		/* Receive sinusoidal sample from NCO core */
		nco_out = XNco_Get_sine_sample_V(&Nco);

		if(nco_out!=prevTone) { /* New sinusoidal sample? */
			temp = nco_out;
		}

		/* Sample L+R audio from the codec */

		in_left = Xil_In32(I2S_DATA_RX_L_REG);
		in_right = Xil_In32(I2S_DATA_RX_R_REG);

		/* -------------------------------------------------------------------------------- *
		 * --------------------------------- LEFT CHANNEL --------------------------------- *
		 * -------------------------------------------------------------------------------- */
		if(in_left != prevL) /* New left sample? */
		{
			/* Add noise component to the L+R audio samples */
			out_left = (temp + in_left);

			Xil_Out32(LMS_D, out_left >> SCALE);	// Input audio+noise as desired signal
			Xil_Out32(LMS_X, temp >> SCALE);		// Input noise as input
			Xil_Out32(LMS_STROBE, 0x01);			// Stobe LMS to signal inputs are finished

			/* If any button is pressed */
			if(XGpio_DiscreteRead(&Gpio, BUTTON_CHANNEL)>0){

				/* Wait until output data is ready */
				out_left = (Xil_In32(LMS_E) << (SCALE-1)); // Output filtered audio
			}

			/* Output audio to the codec */
			Xil_Out32(I2S_DATA_TX_L_REG, out_left);

		}

		/* -------------------------------------------------------------------------------- *
		 * --------------------------------- RIGHT CHANNEL -------------------------------- *
		 * -------------------------------------------------------------------------------- */
		if(in_right != prevR) /* New right sample? */
		{
			/* Add scaled noise component to the L+R audio samples */
			out_right = (temp + in_right);

			Xil_Out32(LMS_D, out_right >> SCALE); 	// Input audio+noise as desired signal
			Xil_Out32(LMS_X, temp >> SCALE); 		// Input noise as input
			Xil_Out32(LMS_STROBE, 0x01);			// Stobe LMS to signal inputs are finished

			/* If any button is pressed */
			if(XGpio_DiscreteRead(&Gpio, BUTTON_CHANNEL)>0){
				out_right = (Xil_In32(LMS_E) << (SCALE-1)); // output filtered audio
			}

			/* Output audio to the codec */
			Xil_Out32(I2S_DATA_TX_R_REG, out_right);
		}
コード例 #15
0
ファイル: xuartps_selftest.c プロジェクト: albanie/ThesisCode
/**
*
* This function runs a self-test on the driver and hardware device. This self
* test performs a local loopback and verifies data can be sent and received.
*
* The time for this test is proportional to the baud rate that has been set
* prior to calling this function.
*
* The mode and control registers are restored before return.
*
* @param	InstancePtr is a pointer to the XUartPs instance
*
* @return
*		 - XST_SUCCESS if the test was successful
*		- XST_UART_TEST_FAIL if the test failed looping back the data
*
* @note
*
* This function can hang if the hardware is not functioning properly.
*
******************************************************************************/
int XUartPs_SelfTest(XUartPs *InstancePtr)
{
	int Status = XST_SUCCESS;
	u32 IntrRegister;
	u32 ModeRegister;
	u8 Index;

	/*
	 * Assert validates the input arguments
	 */
	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);

	/*
	 * Disable all interrupts in the interrupt disable register
	 */
	IntrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,
				   XUARTPS_IMR_OFFSET);
	XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_IDR_OFFSET,
		XUARTPS_IXR_MASK);

	/*
	 * Setup for local loopback
	 */
	ModeRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,
				   XUARTPS_MR_OFFSET);
	XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_MR_OFFSET,
			   ((ModeRegister & (~XUARTPS_MR_CHMODE_MASK)) |
				XUARTPS_MR_CHMODE_L_LOOP));

	/*
	 * Send a number of bytes and receive them, one at a time.
	 */
	for (Index = 0; Index < XUARTPS_TOTAL_BYTES; Index++) {
		/*
		 * Send out the byte and if it was not sent then the failure
		 * will be caught in the comparison at the end
		 */
		XUartPs_Send(InstancePtr, &TestString[Index], 1);

		/*
		 * Wait until the byte is received. This can hang if the HW
		 * is broken. Watch for the FIFO empty flag to be false.
		 */
		while (!(XUartPs_IsReceiveData(InstancePtr->Config.
						BaseAddress)));

		/*
		 * Receive the byte
		 */
		XUartPs_Recv(InstancePtr, &ReturnString[Index], 1);
	}

	/*
	 * Compare the bytes received to the bytes sent to verify the exact data
	 * was received
	 */
	for (Index = 0; Index < XUARTPS_TOTAL_BYTES; Index++) {
		if (TestString[Index] != ReturnString[Index]) {
			Status = XST_UART_TEST_FAIL;
		}
	}

	/*
	 * Restore the registers which were altered to put into polling and
	 * loopback modes so that this test is not destructive
	 */
	XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_IER_OFFSET,
			   IntrRegister);
	XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_MR_OFFSET,
			   ModeRegister);

	return Status;
}