📄 xps2.c
字号:
* designed for either polled or interrupt driven modes. It is non-blocking* such that it will return if no data has already received by the PS/2 port.** 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 receiving data 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.** @param InstancePtr is a pointer to the XPs2 instance to be worked on.* @param BufferPtr is pointer to buffer for data to be received into* @param NumBytes is the number of bytes to be received. A value of zero will* stop a previous receive operation that is in progress in interrupt mode.** @return** The number of bytes received.** @note** The number of bytes is not asserted so that this function may be called with* a value of zero to stop an operation that is already in progress.******************************************************************************/unsigned int XPs2_Recv(XPs2 *InstancePtr, Xuint8 *BufferPtr, unsigned int NumBytes){ unsigned int ReceivedCount; /* * Assert validates the input arguments */ XASSERT_NONVOID(InstancePtr != XNULL); XASSERT_NONVOID(BufferPtr != XNULL); XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); /* * Setup the specified buffer to be sent by setting the instance * variables so it can be sent with polled or interrupt mode */ InstancePtr->ReceiveBuffer.RequestedBytes = NumBytes; InstancePtr->ReceiveBuffer.RemainingBytes = NumBytes; InstancePtr->ReceiveBuffer.NextBytePtr = BufferPtr; /* * Receive the data from PS/2 and return the number of bytes * received */ ReceivedCount = XPs2_ReceiveBuffer(InstancePtr); return ReceivedCount;}/****************************************************************************//**** This function sends 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 sends the specified buffer of data to the PS/2 port in either* polled or interrupt driven modes. This function is non-blocking such that* it will return before the data has been sent.** In a polled mode, this function will only send 1 byte which is as much data* transmitter can buffer. The application may need to call it repeatedly to* send a buffer.** In interrupt mode, this function will start sending the specified buffer and* then the interrupt handler of the driver will continue until the buffer* has been sent. A callback function, as specified by the application, will* be called to indicate the completion of sending the buffer.** @param InstancePtr is a pointer to the XPs2 instance to be worked on.** @return** NumBytes is the number of bytes actually sent** @note** None.******************************************************************************/unsigned int XPs2_SendBuffer(XPs2 *InstancePtr){ unsigned int SentCount = 0; /* * If the transmitter is empty send one byte of data */ if (!XPs2_mIsTransmitFull(InstancePtr->BaseAddress)) { XPs2_SendByte(InstancePtr->BaseAddress, InstancePtr->SendBuffer.NextBytePtr[SentCount]); SentCount = 1; } /* * Update the buffer to reflect the bytes that were sent * from it */ InstancePtr->SendBuffer.NextBytePtr += SentCount; InstancePtr->SendBuffer.RemainingBytes -= SentCount; /* * If interrupts are enabled as indicated by the receive interrupt, then * enable the transmit interrupt */ if (XPs2_mIsIntrEnabled((InstancePtr->BaseAddress), XPS2_INT_RX_FULL)) { XPs2_mEnableIntr(InstancePtr->BaseAddress, XPS2_INT_TX_ALL | XPS2_INT_WDT_TOUT); } return SentCount;}/****************************************************************************//**** 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;}/****************************************************************************//**** This function is a stub handler that is the default handler such that if the* application has not set the handler when interrupts are enabled, this* function will be called. The function interface has to match the interface* specified for a handler even though none of the arguments are used.** @param CallBackRef is unused by this function.* @param Event is unused by this function.* @param ByteCount is unused by this function.** @return** None.** @note** None.******************************************************************************/static void XPs2_StubHandler(void *CallBackRef, Xuint32 Event, unsigned int ByteCount){ /* * Assert alway occurs since this is a stub and should never be called */ XASSERT_VOID_ALWAYS();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -