/** * * Checks if the specified timer counter of the device has expired. In capture * mode, expired is defined as a capture occurred. In compare mode, expired is * defined as the timer counter rolled over/under for up/down counting. * * When interrupts are enabled, the expiration causes an interrupt. This function * is typically used to poll a timer counter to determine when it has expired. * * @param InstancePtr is a pointer to the XIOModule instance. * @param TimerNumber is the timer counter of the device to operate on. * Each device may contain multiple timer counters. The timer * number is a zero based number with a range of * 0 to (XTC_DEVICE_TIMER_COUNT - 1). * * @return TRUE if the timer has expired, and FALSE otherwise. * * @note None. * ******************************************************************************/ int XIOModule_IsExpired(XIOModule * InstancePtr, u8 TimerNumber) { u32 CounterReg; u32 TimerOffset = TimerNumber << XTC_TIMER_COUNTER_SHIFT; Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(TimerNumber < XTC_DEVICE_TIMER_COUNT); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertNonvoid(InstancePtr->CfgPtr->PitReadable[TimerNumber]); /* * Check if timer is expired */ if (InstancePtr->CurrentTCSR[TimerNumber] & XTC_CSR_AUTO_RELOAD_MASK) { return 1; /* Always expired for reload */ } else { CounterReg = XIOModule_ReadReg(InstancePtr->BaseAddress, TimerOffset + XTC_TCR_OFFSET); if (CounterReg & InstancePtr->CfgPtr->PitMask[TimerNumber] == InstancePtr->CfgPtr->PitMask[TimerNumber]) { return 1; } else { return 0; } } }
/** * * Interrupt Service Routine (ISR) for the driver. This function only performs * processing for the Programmable Interval Timere and does not save and restore * the interrupt context. * * @param InstancePtr contains a pointer to the IO Module instance for * the interrupt. * * @return None. * * @note None. * ******************************************************************************/ void XIOModule_Timer_InterruptHandler(void *InstancePtr) { XIOModule *IOModulePtr = NULL; u8 Index; u32 IntPendingReg, ModeMask; /* * Verify that each of the inputs are valid. */ Xil_AssertVoid(InstancePtr != NULL); /* * Convert the non-typed pointer to an IO Module instance pointer * such that there is access to the IO Module */ IOModulePtr = (XIOModule *) InstancePtr; /* * Read the pending interrupts to be able to check if interrupt occurred */ IntPendingReg = XIOModule_ReadReg(IOModulePtr->BaseAddress, XIN_IPR_OFFSET); ModeMask = ~IOModulePtr->CurrentIMR; /* * Loop thru each timer in the device and call the callback function * for each timer which has caused an interrupt, but only if not fast */ for (Index = 0; Index < XTC_DEVICE_TIMER_COUNT; Index++) { /* * Check if timer is enabled */ if (IOModulePtr->CfgPtr->PitUsed[Index]) { /* * Check if timer expired and interrupt occured, * but only if it is not a fast interrupt */ if (IntPendingReg & ModeMask & XIOModule_TimerBitPosMask[Index]) { /* * Increment statistics for the number of interrupts and call * the callback to handle any application specific processing */ IOModulePtr->Timer_Stats[Index].Interrupts++; IOModulePtr->Handler(IOModulePtr->CallBackRef, Index); /* * Acknowledge the interrupt in the interrupt controller * acknowledge register to mark it as handled */ XIOModule_WriteReg(IOModulePtr->BaseAddress, XIN_IAR_OFFSET, XIOModule_TimerBitPosMask[Index]); } } } }
/** * Read state of discretes for the specified GPI channnel. * * @param InstancePtr is a pointer to an XIOModule instance to be * worked on. * @param Channel contains the channel of the GPI (1, 2, 3 or 4) to * operate on. * * @return Current copy of the discretes register. * *****************************************************************************/ u32 XIOModule_DiscreteRead(XIOModule * InstancePtr, unsigned Channel) { XASSERT_NONVOID(InstancePtr != NULL); XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); XASSERT_VOID((Channel >= 1) && (Channel <= XGPI_DEVICE_COUNT)); return XIOModule_ReadReg(InstancePtr->BaseAddress, ((Channel - 1) * XGPI_CHAN_OFFSET) + XGPI_DATA_OFFSET); }
/** * Read state of discretes for the specified GPI channnel. * * @param InstancePtr is a pointer to an XIOModule instance to be * worked on. * @param Channel contains the channel of the GPI (1, 2, 3 or 4) to * operate on. * * @return Current copy of the discretes register. * *****************************************************************************/ u32 XIOModule_DiscreteRead(XIOModule * InstancePtr, unsigned Channel) { Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertVoid((Channel >= 1) && (Channel <= XGPI_DEVICE_COUNT)); return XIOModule_ReadReg(InstancePtr->BaseAddress, ((Channel - 1) * XGPI_CHAN_OFFSET) + XGPI_DATA_OFFSET); }
/** * * Get the current value of the specified timer counter. The timer counter * may be either incrementing or decrementing based upon the current mode of * operation. * * @param InstancePtr is a pointer to the XIOModule instance. * @param TimerNumber is the timer counter of the device to operate on. * Each device may contain multiple timer counters. The timer * number is a zero based number with a range of * 0 to (XTC_DEVICE_TIMER_COUNT - 1). * * @return The current value for the timer counter. * * @note None. * ******************************************************************************/ u32 XIOModule_GetValue(XIOModule * InstancePtr, u8 TimerNumber) { u32 TimerOffset = TimerNumber << XTC_TIMER_COUNTER_SHIFT; XASSERT_NONVOID(InstancePtr != NULL); XASSERT_NONVOID(TimerNumber < XTC_DEVICE_TIMER_COUNT); XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); return XIOModule_ReadReg(InstancePtr->BaseAddress, TimerOffset + XTC_TCR_OFFSET); }
/** * * This function determines if the specified UART is sending data. If the * transmitter register is not empty, it is sending data. * * @param InstancePtr is a pointer to the XIOModule instance. * * @return A value of TRUE if the UART is sending data, otherwise FALSE. * * @note None. * *****************************************************************************/ int XIOModule_IsSending(XIOModule *InstancePtr) { u32 StatusRegister; /* * Assert validates the input arguments */ Xil_AssertNonvoid(InstancePtr != NULL); /* * Read the status register to determine if the transmitter is empty */ StatusRegister = XIOModule_ReadReg(InstancePtr->BaseAddress, XUL_STATUS_REG_OFFSET); /* * If the transmitter is not empty then indicate that the UART is still * sending some data */ return ((StatusRegister & XUL_SR_TX_FIFO_FULL) == XUL_SR_TX_FIFO_FULL); }
/** * * 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 XIOModule 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 the UART 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 by the * UART. * * In a polled mode, this function will only receive as much data as the UART * can buffer, either in the receiver or in the FIFO if present and enabled. * 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. * * @param InstancePtr is a pointer to the XIOModule instance. * * @return The number of bytes received. * * @note None. * *****************************************************************************/ unsigned int XIOModule_ReceiveBuffer(XIOModule *InstancePtr) { u8 StatusRegister; unsigned int ReceivedCount = 0; /* * Loop until there is not more data buffered by the UART or the * specified number of bytes is received */ while (ReceivedCount < InstancePtr->ReceiveBuffer.RemainingBytes) { /* * Read the Status Register to determine if there is any data in * the receiver */ StatusRegister = XIOModule_GetStatusReg(InstancePtr->BaseAddress); /* * If there is data ready to be removed, then put the next byte * received into the specified buffer and update the stats to * reflect any receive errors for the byte */ if (StatusRegister & XUL_SR_RX_FIFO_VALID_DATA) { InstancePtr->ReceiveBuffer.NextBytePtr[ReceivedCount++]= XIOModule_ReadReg(InstancePtr->BaseAddress, XUL_RX_OFFSET); XIOModule_UpdateStats(InstancePtr, StatusRegister); } /* * There's no more data buffered, so exit such that this * function does not block waiting for data */ else { break; } } /* * Enter a critical region by disabling all the UART interrupts to allow * this call to stop a previous operation that may be interrupt driven */ StatusRegister = InstancePtr->CurrentIER; XIomodule_Out32(InstancePtr->BaseAddress + XIN_IER_OFFSET, StatusRegister & 0xFFFFFFF8); /* * Update the receive buffer to reflect the number of bytes that was * received */ InstancePtr->ReceiveBuffer.NextBytePtr += ReceivedCount; InstancePtr->ReceiveBuffer.RemainingBytes -= ReceivedCount; /* * Increment associated counters in the statistics */ InstancePtr->Uart_Stats.CharactersReceived += ReceivedCount; /* * Restore the interrupt enable register to it's previous value such * that the critical region is exited */ XIomodule_Out32(InstancePtr->BaseAddress + XIN_IER_OFFSET, (InstancePtr->CurrentIER & 0xFFFFFFF8) | (StatusRegister & 0x7)); return ReceivedCount; }