/****************************************************************************** * * Copyright (C) 2011 - 2014 Xilinx, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * Use of the Software is limited solely to applications: * (a) running on a Xilinx device, or * (b) that interact with a Xilinx device through a bus or interconnect. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Except as contained in this notice, the name of the Xilinx shall not be used * in advertising or otherwise to promote the sale, use or other dealings in * this Software without prior written authorization from Xilinx. * ******************************************************************************/ /*****************************************************************************/ /** * * @file xiomodule.h * * The Xilinx IO Module driver component. This component supports the * IO Module. The IO Module provides: *
* MODIFICATION HISTORY: * * Ver Who Date Changes * ----- ---- -------- ------------------------------------------------------- * 1.00a sa 07/15/11 First release * 1.01a sa 04/10/12 Updated with fast interrupt * 1.02a sa 07/25/12 Updated with GPI interrupts and programmable baudrate * 2.0 adk 19/12/13 Updated as per the New Tcl API's * 2.1 bss 05/02/14 Added PitMask in XIOModule_Config.(CR #794167) ** ******************************************************************************/ #ifndef IOMODULE_H /* prevent circular inclusions */ #define IOMODULE_H /* by using protection macros */ #ifdef __cplusplus extern "C" { #endif /***************************** Include Files *********************************/ #include "xparameters.h" #include "xstatus.h" #include "xiomodule_l.h" #include "xil_types.h" /************************** Constant Definitions *****************************/ /** * @name Configuration options * These options are used in XIOModule_SetOptions() to configure the * device. * @{ */ /** * Used to configure the Programmable Interval Timer. *
* XTC_INT_MODE_OPTION Dummy compatibility option. Enable interrupt * output. * XTC_AUTO_RELOAD_OPTION In compare mode, configures the timer to reload * from the load value. The default mode causes * the timer to hold after it rolls under. **/ #define XTC_INT_MODE_OPTION 0 #define XTC_AUTO_RELOAD_OPTION 0x00000002UL /** * Used to configure the Interrupt Controller. *
* XIN_SVC_SGL_ISR_OPTION Service the highest priority pending interrupt * and then return. * XIN_SVC_ALL_ISRS_OPTION Service all of the pending interrupts and then * return. **/ #define XIN_SVC_SGL_ISR_OPTION 1UL #define XIN_SVC_ALL_ISRS_OPTION 2UL /*@}*/ /** * @name Hardware configuration mnemonics * These mnemonics are used when accessing hardware configuration parameters. * @{ */ /** * Mnemonics for the Programmable Interval Timer hardware configuration. *
* XTC_PRESCALER_* Define the prescaler configured in hardware. **/ #define XTC_PRESCALER_NONE 0 #define XTC_PRESCALER_FIT1 1 #define XTC_PRESCALER_FIT2 2 #define XTC_PRESCALER_FIT3 3 #define XTC_PRESCALER_FIT4 4 #define XTC_PRESCALER_PIT1 5 #define XTC_PRESCALER_PIT2 6 #define XTC_PRESCALER_PIT3 7 #define XTC_PRESCALER_PIT4 8 #define XTC_PRESCALER_EXTERNAL 9 /*@}*/ /**************************** Type Definitions *******************************/ /** * Callback function. The first argument is a callback reference passed in by * the upper layer when setting the callback functions, and passed back to the * upper layer when the callback is invoked. * The second argument is the ByteCount which is the number of bytes that * actually moved from/to the buffer provided in the _Send/_Receive call. */ typedef void (*XIOModule_Handler)(void *CallBackRef, unsigned int ByteCount); /** * This typedef contains configuration information for the device. */ typedef struct { u16 DeviceId; /**< Unique ID of device */ u32 BaseAddress; /**< Unique identifier */ u32 IoBaseAddress; /**< IO Bus Base Address */ u32 FastIntr; /**< Fast Interrupt enabled */ u32 BaseVector; /**< Relocatable base vector */ u32 AckBeforeService; /**< Ack location per interrupt */ u32 Options; /**< Device options */ u32 InputClockHz; /**< Input clock frequency (Hz) */ u32 BaudRate; /**< Current baud rate */ u8 PitUsed[XTC_DEVICE_TIMER_COUNT]; /**< PIT is used */ u8 PitSize[XTC_DEVICE_TIMER_COUNT]; /**< PIT timer counter size */ u32 PitMask[XTC_DEVICE_TIMER_COUNT]; /**< PIT timer counter size */ u8 PitPrescaler[XTC_DEVICE_TIMER_COUNT]; /**< PIT prescaler */ u8 PitReadable[XTC_DEVICE_TIMER_COUNT]; /**< PIT readable */ u32 GpoInit[XGPO_DEVICE_COUNT]; /**< GPO initial value */ XIOModule_VectorTableEntry HandlerTable[XPAR_IOMODULE_INTC_MAX_INTR_SIZE]; /**< Static vector table of interrupt handlers */ } XIOModule_Config; /** * Statistics for the UART */ typedef struct { u32 TransmitInterrupts; /**< Number of transmit interrupts */ u32 ReceiveInterrupts; /**< Number of receive interrupts */ u32 CharactersTransmitted; /**< Number of characters transmitted */ u32 CharactersReceived; /**< Number of characters received */ u32 ReceiveOverrunErrors; /**< Number of receive overruns */ u32 ReceiveParityErrors; /**< Number of receive parity errors */ u32 ReceiveFramingErrors; /**< Number of receive framing errors */ } XIOModule_Uart_Stats; /** * The following data type is used to manage the buffers that are handled * when sending and receiving UART data in the interrupt mode. It is intended * for internal use only. */ typedef struct { u8 *NextBytePtr; unsigned int RequestedBytes; unsigned int RemainingBytes; } XIOModule_Buffer; /** * Signature for the timer callback function. * * @param CallBackRef is a callback reference passed in by the upper * layer when setting the callback functions, and passed back to * the upper layer when the callback is invoked. Its type is * unimportant to the driver, so it is a void pointer. * @param TimerNumber is the number of the timer within the device. The * device typically contains from one to four timers. The timer * number is a zero based number with a range of 0 to * (XTC_DEVICE_TIMER_COUNT - 1). */ typedef void (*XIOModule_Timer_Handler) (void *CallBackRef, u8 TimerNumber); /** * Programmable Interval Timer statistics */ typedef struct { u32 Interrupts; /**< Number of timer interrupts that have occurred */ } XIOModule_Timer_Stats; /** * The XIOModule driver instance data. The user is required to allocate a * variable of this type for every iomodule device in the system. A pointer * to a variable of this type is then passed to the driver API functions. */ typedef struct { u32 BaseAddress; /**< Base address of registers */ u32 IsReady; /**< Device initialized and ready */ u32 IsStarted; /**< Device has been started */ XIOModule_Config *CfgPtr; /**< Pointer to inst config entry */ XIOModule_Uart_Stats Uart_Stats; /**< UART Statistics */ XIOModule_Buffer SendBuffer; /**< UART Send buffer */ XIOModule_Buffer ReceiveBuffer; /**< UART Receive buffer */ XIOModule_Handler RecvHandler; /**< UART Receive Handler */ void *RecvCallBackRef; /**< Callback ref for recv handler */ XIOModule_Handler SendHandler; /**< UART Send Handler */ void *SendCallBackRef; /**< Callback ref for send handler */ u32 CurrentUBRR; /**< UART Baud Rate Register value */ u32 UnhandledInterrupts; /**< Iomodule Interrupt Statistics */ u32 CurrentIER; /**< Interrupt Enable Register value*/ u32 CurrentIMR; /**< Interrupt Mode Register value */ XIOModule_Timer_Stats Timer_Stats[XTC_DEVICE_TIMER_COUNT]; /**< Timer statistics */ u32 CurrentTLR[XTC_DEVICE_TIMER_COUNT]; /**< Timer Load Register values */ u8 CurrentTCSR[XTC_DEVICE_TIMER_COUNT]; /**< Timer Control Register values */ XIOModule_Timer_Handler Handler; /**< Timer Callback function */ void *CallBackRef; /**< Timer Callback handler ref */ u32 GpoValue[XGPO_DEVICE_COUNT]; /**< GPO current value */ u32 IoBaseAddress; /**< Base address of IO Bus */ } XIOModule; /***************** Macros (Inline Functions) Definitions *********************/ /************************** Function Prototypes ******************************/ /* * Required functions in xiomodule.c */ int XIOModule_Initialize(XIOModule * InstancePtr, u16 DeviceId); int XIOModule_Timer_Initialize(XIOModule * InstancePtr, u16 DeviceId); int XIOModule_Start(XIOModule * InstancePtr); void XIOModule_Stop(XIOModule * InstancePtr); int XIOModule_Connect(XIOModule * InstancePtr, u8 Id, XInterruptHandler Handler, void *CallBackRef); void XIOModule_Disconnect(XIOModule * InstancePtr, u8 Id); void XIOModule_Enable(XIOModule * InstancePtr, u8 Id); void XIOModule_Disable(XIOModule * InstancePtr, u8 Id); void XIOModule_Acknowledge(XIOModule * InstancePtr, u8 Id); XIOModule_Config *XIOModule_LookupConfig(u16 DeviceId); int XIOModule_ConnectFastHandler(XIOModule *InstancePtr, u8 Id, XFastInterruptHandler Handler); void XIOModule_SetNormalIntrMode(XIOModule *InstancePtr, u8 Id); /* * API Basic functions for GPI and GPO implemented in xiomodule.c */ u32 XIOModule_DiscreteRead(XIOModule *InstancePtr, unsigned Channel); void XIOModule_DiscreteWrite(XIOModule *InstancePtr, unsigned Channel, u32 Mask); /* * API Functions for GPI and GPO implemented in xiomodule_extra.c */ void XIOModule_DiscreteSet(XIOModule *InstancePtr, unsigned Channel, u32 Mask); void XIOModule_DiscreteClear(XIOModule *InstancePtr, unsigned Channel, u32 Mask); /* * Required functions, in file xiomodule_uart.c */ int XIOModule_CfgInitialize(XIOModule *InstancePtr, XIOModule_Config *Config, u32 EffectiveAddr); void XIOModule_ResetFifos(XIOModule *InstancePtr); /* Dummy */ unsigned int XIOModule_Send(XIOModule *InstancePtr, u8 *DataBufferPtr, unsigned int NumBytes); unsigned int XIOModule_Recv(XIOModule *InstancePtr, u8 *DataBufferPtr, unsigned int NumBytes); int XIOModule_IsSending(XIOModule *InstancePtr); int XIOModule_SetBaudRate(XIOModule *InstancePtr, u32 BaudRate); /* * Functions for statistics, in file xiomodule_stats.c */ void XIOModule_GetStats(XIOModule *InstancePtr, XIOModule_Uart_Stats *StatsPtr); void XIOModule_ClearStats(XIOModule *InstancePtr); /* * Interrupt functions in xiomodule_intr.c */ void XIOModule_VoidInterruptHandler(); void XIOModule_InterruptHandler(XIOModule * InstancePtr); void XIOModule_Uart_EnableInterrupt(XIOModule *InstancePtr); void XIOModule_Uart_DisableInterrupt(XIOModule *InstancePtr); void XIOModule_SetRecvHandler(XIOModule *InstancePtr, XIOModule_Handler FuncPtr, void *CallBackRef); void XIOModule_SetSendHandler(XIOModule *InstancePtr, XIOModule_Handler FuncPtr, void *CallBackRef); void XIOModule_Uart_InterruptHandler(XIOModule *InstancePtr); /* * Options functions in xiomodule_options.c */ int XIOModule_SetOptions(XIOModule * InstancePtr, u32 Options); u32 XIOModule_GetOptions(XIOModule * InstancePtr); /* * Self-test functions in xiomodule_selftest.c */ int XIOModule_SelfTest(XIOModule * InstancePtr); /* * Required functions, in file xiomodule.c */ void XIOModule_Timer_Start(XIOModule * InstancePtr, u8 TimerNumber); void XIOModule_Timer_Stop(XIOModule * InstancePtr, u8 TimerNumber); u32 XIOModule_GetValue(XIOModule * InstancePtr, u8 TimerNumber); void XIOModule_SetResetValue(XIOModule * InstancePtr, u8 TimerNumber, u32 ResetValue); u32 XIOModule_GetCaptureValue(XIOModule * InstancePtr, u8 TimerNumber); int XIOModule_IsExpired(XIOModule * InstancePtr, u8 TimerNumber); void XIOModule_Reset(XIOModule * InstancePtr, u8 TimerNumber); /* * Functions for options, in file xiomodule_options.c */ void XIOModule_Timer_SetOptions(XIOModule * InstancePtr, u8 TimerNumber, u32 Options); u32 XIOModule_Timer_GetOptions(XIOModule * InstancePtr, u8 TimerNumber); /* * Functions for statistics, in file xiomodule_stats.c */ void XIOModule_Timer_GetStats(XIOModule * InstancePtr, XIOModule_Timer_Stats * StatsPtr); void XIOModule_Timer_ClearStats(XIOModule * InstancePtr); /* * Functions for self-test, in file xiomodule_selftest.c */ int XIOModule_Timer_SelfTest(XIOModule * InstancePtr, u8 IOModuleNumber); /* * Functions for interrupts, in file xiomodule_intr.c */ void XIOModule_SetHandler(XIOModule * InstancePtr, XIOModule_Timer_Handler FuncPtr, void *CallBackRef); void XIOModule_Timer_InterruptHandler(void *InstancePtr); /* * Basic functions for IO Bus read and write implemented in xiomodule.c */ u32 XIOModule_IoReadWord(XIOModule *InstancePtr, u32 ByteOffset); u16 XIOModule_IoReadHalfword(XIOModule *InstancePtr, u32 ByteOffset); u8 XIOModule_IoReadByte(XIOModule *InstancePtr, u32 ByteOffset); void XIOModule_IoWriteWord(XIOModule *InstancePtr, u32 ByteOffset, u32 Data); void XIOModule_IoWriteHalfword(XIOModule *InstancePtr, u32 ByteOffset, u16 Data); void XIOModule_IoWriteByte(XIOModule *InstancePtr, u32 ByteOffset, u8 Data); #ifdef __cplusplus } #endif #endif /* end of protection macro */