/** * * This function receives a byte from PS/2. It operates in the polling mode * and blocks until a byte of data is received. * * @param BaseAddress contains the base address of the PS/2 port. * * @return The data byte received by PS/2. * * @note None. * *****************************************************************************/ u8 XPs2_RecvByte(u32 BaseAddress) { while (XPs2_mIsReceiveEmpty(BaseAddress)) { } return (u8) XIo_In8(BaseAddress + XPS2_RX_REG_OFFSET); }
/** * * This function receives a buffer that has been previously specified by setting * up the instance variables of the instance. This function is designed to be * an internal function for the XPs2 component such that it may be called * from a shell function that sets up the buffer or from an interrupt handler. * * This function will attempt to receive a specified number of bytes of data * from PS/2 and store it into the specified buffer. This function is * designed for either polled or interrupt driven modes. It is non-blocking * such that it will return if there is no data has already received. * * In a polled mode, this function will only receive 1 byte which is as much * data as the receiver can buffer. The application may need to call it * repeatedly to receive a buffer. Polled mode is the default mode of operation * for the driver. * * In interrupt mode, this function will start receiving and then the interrupt * handler of the driver will continue until the buffer has been received. A * callback function, as specified by the application, will be called to indicate * the completion of receiving the buffer or when any receive errors or timeouts * occur. Interrupt mode must be enabled using the SetOptions function. * * @param InstancePtr is a pointer to the XPs2 instance to be worked on. * * @return * * The number of bytes received. * * @note * * None. * *****************************************************************************/ unsigned int XPs2_ReceiveBuffer(XPs2 *InstancePtr) { unsigned int ReceivedCount = 0; /* * Loop until there is no more date buffered by the PS/2 receiver or the * specified number of bytes has been received */ while (ReceivedCount < InstancePtr->ReceiveBuffer.RemainingBytes) { /* * If there is data ready to be read , then put the next byte * read into the specified buffer */ if (!XPs2_mIsReceiveEmpty(InstancePtr->BaseAddress)) { InstancePtr->ReceiveBuffer.NextBytePtr[ReceivedCount++] = XPs2_RecvByte(InstancePtr->BaseAddress); } /* * There is no more data buffered, so exit such that this function does * not block waiting for data */ else { break; } } /* * Update the receive buffer to reflect the number of bytes that was * received */ InstancePtr->ReceiveBuffer.NextBytePtr += ReceivedCount; InstancePtr->ReceiveBuffer.RemainingBytes -= ReceivedCount; return ReceivedCount; }