element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet & Tria Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
Avnet Boards General Zedboard: Problem with code in SDK
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Avnet Boards Forums to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 3 replies
  • Subscribers 359 subscribers
  • Views 582 views
  • Users 0 members are here
Related

Zedboard: Problem with code in SDK

lukwolf
lukwolf over 12 years ago

Hi, I am trying to create my first project SDK with example Zedboard following:

============================================================================================================
/*
* Copyright (c) 2009 Xilinx, Inc. All rights reserved.
*
* Xilinx, Inc.
* XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
* COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
* ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
* STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
* IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
* FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
* XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
* THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
* ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
* FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE.
*
* helloworld.c: simple test application
*/
#include <stdio.h>
#include "platform.h"
#include "xil_types.h"
#include "xgpio.h"
#include "xtmrctr.h"
#include "xparameters.h"
#include "xgpiops.h"
#include "xil_io.h"
#include "xil_exception.h"
#include "xscugic.h"
static XGpioPs psGpioInstancePtr;
extern XGpioPs_Config XGpioPs_ConfigTable[XPAR_XGPIOPS_NUM_INSTANCES];
static int iPinNumber = 7; /*Led LD9 is connected to MIO pin 7*/
XScuGic InterruptController; /* Instance of the Interrupt Controller */
static XScuGic_Config *GicConfig;/* The configuration parameters of the
            controller */
static int InterruptFlag;
extern char inbyte(void);

void Timer_InterruptHandler(void *data, u8 TmrCtrNumber)
{
  print("r
");
  print("r
");
  print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@r
");
  print(" Inside Timer ISR
r ");
  XTmrCtr_Stop(data,TmrCtrNumber);
  // PS GPIO Writing
  print("LED 'LD9' Turned ON r
");
  XGpioPs_WritePin(&psGpioInstancePtr,iPinNumber,1);
  XTmrCtr_Reset(data,TmrCtrNumber);
  print(" Timer ISR Exit

r");
  print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@r
");
  print("r
");
  print("r
");
  InterruptFlag = 1;
}

int SetUpInterruptSystem(XScuGic *XScuGicInstancePtr)
{
  /*
   * Connect the interrupt controller interrupt handler to the hardware
   * interrupt handling logic in the ARM processor.
   */
  Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
      (Xil_ExceptionHandler) XScuGic_InterruptHandler,
      XScuGicInstancePtr);
  /*
   * Enable interrupts in the ARM
   */
  Xil_ExceptionEnable();
  return XST_SUCCESS;
}

int ScuGicInterrupt_Init(u16 DeviceId,XTmrCtr *TimerInstancePtr)
{
  int Status;
  /*
   * Initialize the interrupt controller driver so that it is ready to
   * use.
   */
  GicConfig = XScuGic_LookupConfig(DeviceId);
  if (NULL == GicConfig) {
    return XST_FAILURE;
  }
  Status = XScuGic_CfgInitialize(&InterruptController, GicConfig,
      GicConfig->CpuBaseAddress);
  if (Status != XST_SUCCESS) {
    return XST_FAILURE;
  }
  /*
   * Setup the Interrupt System
   */
  Status = SetUpInterruptSystem(&InterruptController);
  if (Status != XST_SUCCESS) {
    return XST_FAILURE;
  }
  /*
   * Connect a device driver handler that will be called when an
   * interrupt for the device occurs, the device driver handler performs
   * the specific interrupt processing for the device
   */
  Status = XScuGic_Connect(&InterruptController,
      XPAR_FABRIC_AXI_TIMER_1_INTERRUPT_INTR,
      (Xil_ExceptionHandler)XTmrCtr_InterruptHandler,
      (void *)TimerInstancePtr);
  if (Status != XST_SUCCESS) {
    return XST_FAILURE;
  }
  /*
   * Enable the interrupt for the device and then cause (simulate) an
   * interrupt so the handlers will be called
   */
  XScuGic_Enable(&InterruptController, XPAR_FABRIC_AXI_TIMER_1_INTERRUPT_INTR);
  return XST_SUCCESS;
}

int main()
{
  static XGpio GPIOInstance_Ptr;
  XGpioPs_Config*GpioConfigPtr;
  XTmrCtr TimerInstancePtr;
  int xStatus;
  u32 Readstatus=0,OldReadStatus=0;
  //u32 EffectiveAdress = 0xE000A000;
  int iPinNumberEMIO = 54;
  u32 uPinDirectionEMIO = 0x0;
  // Input Pin
  // Pin direction
  u32 uPinDirection = 0x1;
  int exit_flag,choice,internal_choice;
  init_platform();
  /* data = *(u32 *)(0x42800004);
     print("OK
");
     data = *(u32 *)(0x41200004);
     print("OK-1
");
   */
  print("##### Application Starts #####
r");
  print("r
");
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Step-1 :AXI GPIO Initialization
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  xStatus = XGpio_Initialize(&GPIOInstance_Ptr,XPAR_AXI_GPIO_1_DEVICE_ID);
  if(XST_SUCCESS != xStatus)
    print("GPIO INIT FAILED
r");
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Step-2 :AXI GPIO Set the Direction
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  XGpio_SetDataDirection(&GPIOInstance_Ptr, 1,1);
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Step-3 :AXI Timer Initialization
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  xStatus = XTmrCtr_Initialize(&TimerInstancePtr,XPAR_AXI_TIMER_1_DEVICE_ID);
  if(XST_SUCCESS != xStatus)
    print("TIMER INIT FAILED
r");
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Step-4 :Set Timer Handler
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  XTmrCtr_SetHandler(&TimerInstancePtr,
      Timer_InterruptHandler,
      &TimerInstancePtr);
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Step-5 :Setting timer Reset Value
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  XTmrCtr_SetResetValue(&TimerInstancePtr,
      0, //Change with generic value
      0xf0000000);
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Step-6 :Setting timer Option (Interrupt Mode And Auto Reload )
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  XTmrCtr_SetOptions(&TimerInstancePtr,
      XPAR_AXI_TIMER_1_DEVICE_ID,
      (XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION ));
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Step-7 :PS GPIO Intialization
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  GpioConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_1_DEVICE_ID);
  if(GpioConfigPtr == NULL)
    return XST_FAILURE;
  xStatus = XGpioPs_CfgInitialize(&psGpioInstancePtr,
      GpioConfigPtr,
      GpioConfigPtr->BaseAddr);
  if(XST_SUCCESS != xStatus)
    print(" PS GPIO INIT FAILED
r");
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Step-8 :PS GPIO pin setting to Output
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  XGpioPs_SetDirectionPin(&psGpioInstancePtr, iPinNumber,uPinDirection);
  XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumber,1);
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Step-9 :EMIO PIN Setting to Input port
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  XGpioPs_SetDirectionPin(&psGpioInstancePtr,
      iPinNumberEMIO,uPinDirectionEMIO);
  XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumberEMIO,0);
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Step-10 : SCUGIC interrupt controller Initialization
  //Registration of the Timer ISR
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  xStatus=
      ScuGicInterrupt_Init(XPAR_PS7_SCUGIC_1_DEVICE_ID,&TimerInstancePtr);
  if(XST_SUCCESS != xStatus)
    print(" :( SCUGIC INIT FAILED
r");
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Step-11 :User selection procedure to select and execute tests
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  exit_flag = 0;
  while(exit_flag != 1)
  {
    print(" SELECT the Operation from the Below Menu r
");
    print("###################### Menu Starts ########################r
");
    print("Press '1' to use NORMAL GPIO as an input (BTNU switch)r
");
    print("Press '2' to use EMIO as an input (BTNR switch)r
");
    print("Press any other key to Exitr
");
    print(" ##################### Menu Ends #########################r
");
    choice = inbyte();
    printf("Selection : %c r
",choice);
    internal_choice = 1;
    switch(choice)
    {
    //~~~~~~~~~~~~~~~~~~~~~~~
    // Use case for AXI GPIO
    //~~~~~~~~~~~~~~~~~~~~~~~~
    case '1':
      exit_flag = 0;
      print("Press Switch 'BTNU' push button on board r
");
      print(" r
");
      while(internal_choice != '0')
      {
        Readstatus = XGpio_DiscreteRead(&GPIOInstance_Ptr, 1);
        if(1== Readstatus && 0 == OldReadStatus )
        {
          print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$r
");
          print("BTNU PUSH Button pressed
r");
          print("LED 'LD9' Turned OFF r
");
          XGpioPs_WritePin(&psGpioInstancePtr,iPinNumber,0);
          //Start Timer
          XTmrCtr_Start(&TimerInstancePtr,0);
          print("timer start
r");
          //Wait For interrupt;
          print("Wait for the Timer interrupt to tigger r
");
          print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$r
");
          print(" r
");
          while(InterruptFlag != 1);
          InterruptFlag = 0;
          print(" ###########################################r
");
          print("Press '0' to go to Main Menu
r ");
          print("Press any other key to remain in AXI GPIO Test
r ");
          print(" ###########################################r
");
          internal_choice = inbyte();
          printf("Select = %c r
",internal_choice);
          if(internal_choice != '0')
          {
            print("Press Switch 'BTNU' push button on board r
");
          }
        }
        OldReadStatus = Readstatus;
      }
      print(" r
");
      print(" r
");
      break;
    case '2' :
      //~~~~~~~~~~~~~~~~~~~~~~~
      //Usecase for PS GPIO
      //~~~~~~~~~~~~~~~~~~~~~~~~
      exit_flag = 0;
      print("Press Switch 'BTNR' push button on board r
");
      print(" r
");
      while(internal_choice != '0')
      {
        Readstatus = XGpioPs_ReadPin(&psGpioInstancePtr,
            iPinNumberEMIO);
        if(1== Readstatus && 0 == OldReadStatus )
        {
          print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$r
");
          print("BTNR PUSH Button pressed
r");
          print("LED 'LD9' Turned OFF r
");
          XGpioPs_WritePin(&psGpioInstancePtr,iPinNumber,0);
          //Start Timer
          XTmrCtr_Start(&TimerInstancePtr,0);
          print("timer start
r");
          //Wait For interrupt;
          print("Wait for the Timer interrupt to tigger r
");
          print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$r
");
          print(" r
");
          while(InterruptFlag != 1);
          InterruptFlag = 0;
          print(" ###########################################r
");
          print("Press '0' to go to Main Menu
r ");
          print("Press any other key to remain in EMIO Test
r ");
          print(" ###########################################r
");
          internal_choice = inbyte();
          printf("Select = %c r
",internal_choice);
          if(internal_choice != '0')
          {
            print("Press Switch 'BTNR' push button on board r
");
          }
        }
        OldReadStatus = Readstatus;
      }
      print(" r
");
      print(" r
");
      break;
    default :
      exit_flag = 1;
      break;
    }
  }
  print("r
");
  print("***********r
");
  print("BYE r
");
  print("***********r
");
  cleanup_platform();
  return 0;
}
============================================================================================================

The above code is what gives Zedboard in document ZedBoard: Zynq-7000 AP SoC Concepts, Tools, and Techniques, in section Reference Designs / Tutorials. This code gives me errors in a series of "constant" as:

- XPAR_AXI_TIMER_1_DEVICE_ID
- XPAR_AXI_GPIO_1_DEVICE_ID

The error it gives is:

undeclared (firts use In this function)

Why this error occurs? What value should have these constants?

Thank you very much

  • Sign in to reply
  • Cancel
  • Former Member
    0 Former Member over 12 years ago

    Depending on the version of Xilinx tools, or other implementation issues, the axi_gpio and axi_timer modules you added to your design may be enumerated starting with a '0' or a '1'. Take a look in the xparameters.h file (in the include directory under your Hello_world_bsp) and see if your modules were defined as XPAR_AXI_GPIO_1_DEVICE_ID and XPAR_AXI_TIMER_1_DEVICE_ID, as the application code is expecting, or  as XPAR_AXI_GPIO_0_DEVICE_ID and XPAR_AXI_TIMER_0_DEVICE_ID instead. If this is the case, just modify the application c code to match the values in the xparameters.h file.

     

    -Gary

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • lukwolf
    0 lukwolf over 11 years ago in reply to Former Member

    Thank you, Gray

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • sarah_shabani@rocketmail.com
    0 sarah_shabani@rocketmail.com over 8 years ago

    I am trying to run this on my zedboard but I got errors which shows that SDK complaining about these two libraries #include "xgpio.h"

    #include "xtmrctr.h". Anyone could help me???????

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube