cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Observer
Observer
435 Views
Registered: ‎11-01-2018

How do I register a buffer with the XUARTPS driver for receving data in interrupt mode?

Hardware: MicroZed Board Zynq7010

I'm a bit confused on how I'm to register a buffer for receiving data on the UART in interrupt mode. I noticed in the uart interrupt example that Xilinx has provided they call this function called XUartPs_Recv(...) before they even start receiving data. Obviously, in this case the function will do nothing cause there is no data to be received. However, my assumption here is that this function is called ahead of time to complete one important task which is to register the receive buffer. Am I right?!?! This code is found in BSP file "xuartps.c" line 328 -> 330 as I show below.

u32 XUartPs_Recv(XUartPs *InstancePtr,
			  u8 *BufferPtr, u32 NumBytes)
{
	u32 ReceivedCount;
	u32 ImrRegister;

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

	/*
	 * Disable all the interrupts.
	 * This stops a previous operation that may be interrupt driven
	 */
	ImrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,
				  XUARTPS_IMR_OFFSET);
	XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_IDR_OFFSET,
		XUARTPS_IXR_MASK);

	/* Setup the buffer parameters */
	InstancePtr->ReceiveBuffer.RequestedBytes = NumBytes;
	InstancePtr->ReceiveBuffer.RemainingBytes = NumBytes;
	InstancePtr->ReceiveBuffer.NextBytePtr = BufferPtr;

	/* Receive the data from the device */
	ReceivedCount = XUartPs_ReceiveBuffer(InstancePtr);

	/* Restore the interrupt state */
	XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_IER_OFFSET,
		ImrRegister);

	return ReceivedCount;
}

This seems ok but why call the entire function XUartPs_Recv(...) when there's no data to be received in the beginning. Wouldn't the ideal way to register a receive buffer with the XUartPs driver be to do something like the following? As you can see I'm confused how the interrupt service routine (called upon a receive event) knows where it's suppose to put the data.

int main()
{
          /* initialize uart */
          InstancePtr->ReceiveBuffer.RequestedBytes = NumBytes;
          InstancePtr->ReceiveBuffer.RemainingBytes = NumBytes;
          InstancePtr->ReceiveBuffer.NextBytePtr = BufferPtr;
          /* initialize Generic Interrupt Controller Stuff */
          /* set handlers */
          /* set uart interrupts */

          while(1)
          {
                    /* main loop */
          }
}
0 Kudos
0 Replies