/****************************************************************************** * * (c) Copyright 2002-2013 Xilinx, Inc. All rights reserved. * * This file contains confidential and proprietary information of Xilinx, Inc. * and is protected under U.S. and international copyright and other * intellectual property laws. * * DISCLAIMER * This disclaimer is not a license and does not grant any rights to the * materials distributed herewith. Except as otherwise provided in a valid * license issued to you by Xilinx, and to the maximum extent permitted by * applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL * FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS, * IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF * MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; * and (2) Xilinx shall not be liable (whether in contract or tort, including * negligence, or under any other theory of liability) for any loss or damage * of any kind or nature related to, arising under or in connection with these * materials, including for any direct, or any indirect, special, incidental, * or consequential loss or damage (including loss of data, profits, goodwill, * or any type of loss or damage suffered as a result of any action brought by * a third party) even if such damage or loss was reasonably foreseeable or * Xilinx had been advised of the possibility of the same. * * CRITICAL APPLICATIONS * Xilinx products are not designed or intended to be fail-safe, or for use in * any application requiring fail-safe performance, such as life-support or * safety devices or systems, Class III medical devices, nuclear facilities, * applications related to the deployment of airbags, or any other applications * that could lead to death, personal injury, or severe property or * environmental damage (individually and collectively, "Critical * Applications"). Customer assumes the sole risk and liability of any use of * Xilinx products in Critical Applications, subject only to applicable laws * and regulations governing limitations on product liability. * * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE * AT ALL TIMES. * ******************************************************************************/ /*****************************************************************************/ /** * @file xgpio_low_level_example.c * * This file contains a design example using the General Purpose I/O (GPIO) low * level driver and hardware device. It only uses a channel 1 of a GPIO device. * *
* MODIFICATION HISTORY:
*
* Ver   Who  Date	 Changes
* ----- ---- -------- -----------------------------------------------
* 1.00b jhl  04/29/02 First release
* 2.00a jhl  12/30/02 Addition of dual channel capability
* 2.00a sv   04/18/05 Minor changes to comply to Doxygen and coding guidelines
* 3.00a ktn  11/21/09 Removed the macros XGpio_mSetDataDirection,
*		      XGpio_mGetDataReg and XGpio_mSetDataReg. Users
*		      should use XGpio_WriteReg/XGpio_ReadReg to achieve the
*		      same functionality.
* 
* ******************************************************************************/ /***************************** Include Files *********************************/ #include "xparameters.h" #include "xgpio_l.h" /************************** Constant Definitions *****************************/ #define LED 0x01 /* Assumes bit 0 of GPIO is connected to an LED */ /* * The following constant maps to the Base address of the hardware * instances that was created in the EDK XPS system. */ #define GPIO_REG_BASEADDR XPAR_LEDS_POSITIONS_BASEADDR /* * The following constant is used to wait after an LED is turned on to make * sure that it is visible to the human eye. This constant might need to be * tuned for faster or slower processor speeds. */ #define LED_DELAY 1000000 /* * The following constant is used to determine which channel of the GPIO is * used for the LED if there are 2 channels supported. */ #define LED_CHANNEL 1 /**************************** Type Definitions *******************************/ /***************** Macros (Inline Functions) Definitions *********************/ /************************** Function Prototypes ******************************/ /************************** Variable Definitions *****************************/ /*****************************************************************************/ /** * The purpose of this function is to illustrate how to use the GPIO low level * driver to turn on and off an LED. * * @param None * * @return Always 0 * * @note * The main function is returning an integer to prevent compiler warnings. * ******************************************************************************/ int main() { u32 Data; volatile int Delay; /* * Set the direction for all signals to be inputs except the LED output */ XGpio_WriteReg((GPIO_REG_BASEADDR), ((LED_CHANNEL - 1) * XGPIO_CHAN_OFFSET) + XGPIO_TRI_OFFSET, (~LED)); /* Loop forever blinking the LED */ while (1) { /* * Read the state of the data so that only the LED state can be * modified */ Data = XGpio_ReadReg(GPIO_REG_BASEADDR, ((LED_CHANNEL - 1) * XGPIO_CHAN_OFFSET) + XGPIO_DATA_OFFSET); /* Set the LED to the opposite state such that it blinks */ if (Data & LED) { XGpio_WriteReg((GPIO_REG_BASEADDR), ((LED_CHANNEL - 1) * XGPIO_CHAN_OFFSET) + XGPIO_DATA_OFFSET, Data & ~LED); } else { XGpio_WriteReg((GPIO_REG_BASEADDR), ((LED_CHANNEL - 1) * XGPIO_CHAN_OFFSET) + XGPIO_DATA_OFFSET, Data | LED); } /* Wait a small amount of time so that the LED is visible */ for (Delay = 0; Delay < LED_DELAY; Delay++); } return 0; }