예제 #1
0
파일: serial.c 프로젝트: cuiyanzhe/ReFrESH
/* --- serGetChar1()  Get 1 char from the UART Lite, but do not block.
   --- Return number of chars received. */
char serGetChar1(unsigned char *str)
{
	if (bootLoadCmd1G == BLC_NORMAL){
		/* Check if data is available */

		if (!XUartLite_IsReceiveEmpty(UARTLITE_BASEADDRESS)){
			*str = XUartLite_ReadReg(UARTLITE_BASEADDRESS, XUL_RX_FIFO_OFFSET);
			return 1;
		}
		return 0;
	}
	else if (bootLoadCmd1G == BLC_DL_RECVD){
		return 0;
	}
	else if (bootLoadCmd1G == BLC_DL_WAITING){
		if (!XUartLite_IsReceiveEmpty(UARTLITE_BASEADDRESS)){
			*str = XUartLite_ReadReg(UARTLITE_BASEADDRESS, XUL_RX_FIFO_OFFSET);
			if (*str == ':'){
				bootLoadCmd1G = BLC_DL_RECVD;
				return 0;
			}
			return 1;
		}
		return 0;
	}
	else{
		*str = bootLoadCmd1G;
		bootLoadCmd1G = BLC_DL_WAITING;
		return 1;
	}
}
예제 #2
0
파일: serial.c 프로젝트: cuiyanzhe/ReFrESH
/* --- serGetDLline1()  Receives a full Download Line (DL) of chars from USART 1.
   --- It strips off the ':' */
unsigned char serGetDLline1(unsigned char *str)
{
	unsigned char i, slen[5], *dummy;
	uint8_t len;

	if (bootLoadCmd1G == BLC_NORMAL){
		return 0;
	}
	else if (bootLoadCmd1G == BLC_DL_WAITING){
		/* Check if data is available */
		if (!XUartLite_IsReceiveEmpty(UARTLITE_BASEADDRESS)){
			*slen = XUartLite_ReadReg(UARTLITE_BASEADDRESS, XUL_RX_FIFO_OFFSET);
			if (*slen != ':'){
				bootLoadCmd1G = *slen;
				return 0;
			}
			bootLoadCmd1G = BLC_DL_RECVD;
		}
		else{
			return 0;
		}
	}

	// If we made it here, a char has been received
	if (bootLoadCmd1G == BLC_DL_RECVD){
		// ':' has been received, get the number of data bytes
		i = 0;
		str[2] = 0;
		// get first two chars to determine length of line
		while(i < 2){
			if(!XUartLite_IsReceiveEmpty(UARTLITE_BASEADDRESS)){
				str[i++] = XUartLite_ReadReg(UARTLITE_BASEADDRESS, XUL_RX_FIFO_OFFSET);
			}
		}

		len = (uint8_t)strtol(str,&dummy,16);

		// Now get the 2-byte address, the 1-byte type, the data and the 1-byte Checksum (2 chars per byte)
		while(i < (10 + (len <<1))){
			if(!XUartLite_IsReceiveEmpty(UARTLITE_BASEADDRESS)){
				str[i++] = XUartLite_ReadReg(UARTLITE_BASEADDRESS, XUL_RX_FIFO_OFFSET);
			}
		}
		str[i] = 0;			// place the end-of-string char
		bootLoadCmd1G = BLC_DL_WAITING;
		return i;
	}
	else{
    	return 0;		// A char other than ':' was received - not a download string
    }
}
예제 #3
0
void receiveWorldInfo(){
	// Function to handle integration with the user via UART
	int state = 0; // Store the state of the UART integration
	while(1){
		if (XUartLite_IsReceiveEmpty(XPAR_RS232_DTE_BASEADDR) == 0){
			char received = receive();
			if (state == 0){ // If this is the first character to be received
				worldSize = received - '0'; // We have received the world size
				state++; // Increment the state
				xil_printf("%s", "\r\nPlease input the desired world ID: ");
			}
			else{ // We are receiving worldID information
				if (received == '\r'){ // User has pressed return, indicating end of the worldID.
					int i;
					tmit_buffer[14] = 0x01; // Set the type field
					tmit_buffer[15] = worldSize; // Add the world size to the transmit buffer
					for(i = 0; i < 4; i++){ // Add the world ID to the transmit, as it is over several bytes we need to loop through and bit shift
						tmit_buffer[16 + i] = worldID >> 8*(3-i);
					}
					sendToEthernet(6); // Send the generated buffer to the server via ethernet
					return;
				}
				else{ // User has entered a character other than return so we are still receiving the worldID
					worldID = (worldID * 10) + (received - '0'); // Decimal representation so each successive character requires timesing by 10
				}
			}
예제 #4
0
파일: serial.c 프로젝트: cuiyanzhe/ReFrESH
/* --- serRecvChk1()  Checks for incoming data on USART 1.
   --- Also checks for overrun. Returns true, fail, or error. */
char serRecvChk1(void)
{
	if ((bootLoadCmd1G != BLC_NORMAL) && (bootLoadCmd1G != BLC_DL_WAITING) && (bootLoadCmd1G != BLC_DL_RECVD))
		return 1;

	if (!XUartLite_IsReceiveEmpty(UARTLITE_BASEADDRESS))
		return 1;

	return 0;
}
예제 #5
0
파일: serial.c 프로젝트: cuiyanzhe/ReFrESH
/* --- serRecvStr1()  Receive n chars from the UART Lite.
   --- If n == 0, get only available chars (don't block) 
   --- n cannot be larger than 255 */
unsigned char serRecvStr1(unsigned char *str, unsigned char n)
{
  unsigned char i;

  i = 0;
  if (n > 0){
    /* If n > 0, block for n chars */
    while(i < n){
        (str[i++]) = XUartLite_RecvByte(UARTLITE_BASEADDRESS);
    }
    return n;
  } else if (XUartLite_IsReceiveEmpty(UARTLITE_BASEADDRESS)){
  	return 0;
  } else {
    /* if n == 0, get as many as available now (non-blocking) */
      (str[i++]) = XUartLite_RecvByte(UARTLITE_BASEADDRESS);
    return i;
  }
}
static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
{
signed char cRxedChar;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

	( void ) pvUnused;
	( void ) uxByteCount;

	/* Place any received characters into the receive queue. */
	while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )
	{
		cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);
		xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );
	}

	/* If calling xQueueSendFromISR() caused a task to unblock, and the task 
	that unblocked has a priority equal to or greater than the task currently
	in the Running state (the task that was interrupted), then 
	xHigherPriorityTaskWoken will have been set to pdTRUE internally within the
	xQueueSendFromISR() API function.  If xHigherPriorityTaskWoken is equal to
	pdTRUE then a context switch should be requested to ensure that the 
	interrupt returns to the highest priority task that is able	to run. */
	portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
예제 #7
0
파일: xuartlite_l.c 프로젝트: KapSteR/TIHSC
/**
*
* This functions receives a single byte using the UART. It is blocking in that
* it waits for the receiver to become non-empty before it reads from the
* receive register.
*
* @param	BaseAddress is the base address of the device
*
* @return	The byte of data received.
*
* @note		None.
*
******************************************************************************/
u8 XUartLite_RecvByte(u32 BaseAddress)
{
	while (XUartLite_IsReceiveEmpty(BaseAddress));

	return (u8)XUartLite_ReadReg(BaseAddress, XUL_RX_FIFO_OFFSET);
}
예제 #8
0
파일: serial.c 프로젝트: cuiyanzhe/ReFrESH
/* --- serRecvChk1()  Checks for incoming data on USART 1.
   --- Also checks for overrun. Returns true, fail, or error. */
char serRecvChk1(void)
{
  return (char)!XUartLite_IsReceiveEmpty(UARTLITE_BASEADDRESS);

}
예제 #9
0
void DemoChangeRes()
{
	int fResSet = 0;
	int status;
	char userInput = 0;

	/* Flush UART FIFO */
	while (!XUartLite_IsReceiveEmpty(UART_BASEADDR))
		{
			XUartLite_ReadReg(UART_BASEADDR, XUL_RX_FIFO_OFFSET);
		}

	while (!fResSet)
	{
		DemoCRMenu();

		/* Wait for data on UART */
		while (XUartLite_IsReceiveEmpty(UART_BASEADDR) && !fRefresh)
		{}

		/* Store the first character in the UART recieve FIFO and echo it */

		userInput = XUartLite_ReadReg(UART_BASEADDR, XUL_RX_FIFO_OFFSET);
		xil_printf("%c", userInput);
		status = XST_SUCCESS;
		switch (userInput)
		{
		case '1':
			status = DisplayStop(&dispCtrl);
			DisplaySetMode(&dispCtrl, &VMODE_640x480);
			DisplayStart(&dispCtrl);
			fResSet = 1;
			break;
		case '2':
			status = DisplayStop(&dispCtrl);
			DisplaySetMode(&dispCtrl, &VMODE_800x600);
			DisplayStart(&dispCtrl);
			fResSet = 1;
			break;
		case '3':
			status = DisplayStop(&dispCtrl);
			DisplaySetMode(&dispCtrl, &VMODE_1280x720);
			DisplayStart(&dispCtrl);
			fResSet = 1;
			break;
		case '4':
			status = DisplayStop(&dispCtrl);
			DisplaySetMode(&dispCtrl, &VMODE_1280x1024);
			DisplayStart(&dispCtrl);
			fResSet = 1;
			break;
		case '5':
			status = DisplayStop(&dispCtrl);
			DisplaySetMode(&dispCtrl, &VMODE_1920x1080);
			DisplayStart(&dispCtrl);
			fResSet = 1;
			break;
		case 'q':
			fResSet = 1;
			break;
		default :
			xil_printf("\n\rInvalid Selection");
			MB_Sleep(50);
		}
		if (status == XST_DMA_ERROR)
		{
			xil_printf("\n\rWARNING: AXI VDMA Error detected and cleared\n\r");
		}
	}
}
예제 #10
0
void DemoRun()
{
	int nextFrame = 0;
	char userInput = 0;
	u32 locked;
	XGpio *GpioPtr = &videoCapt.gpio;

	/* Flush UART FIFO */
	while (!XUartLite_IsReceiveEmpty(UART_BASEADDR))
	{
		XUartLite_ReadReg(UART_BASEADDR, XUL_RX_FIFO_OFFSET);
	}
	while (userInput != 'q')
	{
		fRefresh = 0;
		DemoPrintMenu();

		/* Wait for data on UART */
		while (XUartLite_IsReceiveEmpty(UART_BASEADDR) && !fRefresh)
		{}

		/* Store the first character in the UART receive FIFO and echo it */
		if (!XUartLite_IsReceiveEmpty(UART_BASEADDR))
		{
			userInput = XUartLite_ReadReg(UART_BASEADDR, XUL_RX_FIFO_OFFSET);
			xil_printf("%c", userInput);
		}
		else  //Refresh triggered by video detect interrupt
		{
			userInput = 'r';
		}

		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':
			if (videoCapt.state == VIDEO_STREAMING)
				VideoStop(&videoCapt);
			else
				VideoStart(&videoCapt);
			break;
		case '6':
			nextFrame = videoCapt.curFrame + 1;
			if (nextFrame >= DISPLAY_NUM_FRAMES)
			{
				nextFrame = 0;
			}
			VideoChangeFrame(&videoCapt, nextFrame);
			break;
		case '7':
			nextFrame = videoCapt.curFrame + 1;
			if (nextFrame >= DISPLAY_NUM_FRAMES)
			{
				nextFrame = 0;
			}
			VideoStop(&videoCapt);
			DemoInvertFrame(pFrames[videoCapt.curFrame], pFrames[nextFrame], videoCapt.timing.HActiveVideo, videoCapt.timing.VActiveVideo, DEMO_STRIDE);
			VideoStart(&videoCapt);
			DisplayChangeFrame(&dispCtrl, nextFrame);
			break;
		case '8':
			nextFrame = videoCapt.curFrame + 1;
			if (nextFrame >= DISPLAY_NUM_FRAMES)
			{
				nextFrame = 0;
			}
			VideoStop(&videoCapt);
			DemoScaleFrame(pFrames[videoCapt.curFrame], pFrames[nextFrame], videoCapt.timing.HActiveVideo, videoCapt.timing.VActiveVideo, dispCtrl.vMode.width, dispCtrl.vMode.height, DEMO_STRIDE);
			VideoStart(&videoCapt);
			DisplayChangeFrame(&dispCtrl, nextFrame);
			break;
		case 'q':
			break;
		case 'r':
			locked = XGpio_DiscreteRead(GpioPtr, 2);
			xil_printf("%d", locked);
			break;
		default :
			xil_printf("\n\rInvalid Selection");
			MB_Sleep(50);
		}
	}

	return;
}