element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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 Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
Software Application Development 2 interruptions (timer + button)
  • 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 328 subscribers
  • Views 553 views
  • Users 0 members are here
Related

2 interruptions (timer + button)

Former Member
Former Member over 12 years ago

Hello,
I am trying to make an application using two interrupts (timer overflow and input button). I used the project zedboard Timer that uses fclk0 internal clock, and I added another project u00E9lu00E8ments (Lab6) that uses fclk0 external clock, I do not know how to use both. As I am a beginner in using PlanAhead zedbaord and I do not see how to correct my mistakes. (The images attached shows my XML configuration and error), thank you to tell me what I should do,
Thank you.
configuration:
http://img11.hostingpics.net/pics/350853XML2.png
http://img11.hostingpics.net/pics/634095XML3.png
http://img11.hostingpics.net/pics/249540XML4.png
http://img11.hostingpics.net/pics/327212XML5.png

error:
http://img11.hostingpics.net/pics/323541Error.png

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

    I created a new project and I set to get two interruptions, one for timer and for the buttons, it worked without error. When I launched the SDK, both separately code works correctly but when I merged the two, no work me .. I checked everywhere but I do not understand why, if you can help me please. Here is the SDK code: Thank you.

    /*
    * 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"

    #define LED_CHANNEL 2
    #define BUTTON_CHANNEL 1
    #define GPIO_EXAMPLE_DEVICE_ID  XPAR_AXI_GPIO_0_DEVICE_ID
    #define INTC_DEVICE_IDtXPAR_PS7_SCUGIC_0_DEVICE_ID
    #define INTC_GPIO_INTERRUPT_IDtXPAR_FABRIC_GPIO_0_VEC_ID
    #define INTC XScuGic
    #define INTC_HANDLERtXScuGic_InterruptHandler
    #define BUTTON_INTERRUPT XGPIO_IR_CH1_MASK


    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);
    XGpio Gpio;
    static INTC Intc;
    static u8 Var = 0XFF;
    XTmrCtr TimerInstancePtr;

    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_0_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_0_INTERRUPT_INTR);
      return XST_SUCCESS;
    }

    int main()
    {
      //static XGpio Gpio;
      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(&Gpio,XPAR_AXI_GPIO_0_DEVICE_ID);
      if(XST_SUCCESS != xStatus)
        print("GPIO INIT FAILED
    r");
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //Step-2 :AXI GPIO Set the Direction
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      XGpio_SetDataDirection(&Gpio, 1,0X1F);
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //Step-3 :AXI Timer Initialization
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      xStatus = XTmrCtr_Initialize(&TimerInstancePtr,XPAR_AXI_TIMER_0_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
          0xffffffff);
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //Step-6 :Setting timer Option (Interrupt Mode And Auto Reload )
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      XTmrCtr_SetOptions(&TimerInstancePtr,
          XPAR_AXI_TIMER_0_DEVICE_ID,
          (XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION ));
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //Step-7 :PS GPIO Intialization
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      GpioConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_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_0_DEVICE_ID,&TimerInstancePtr);
      if(XST_SUCCESS != xStatus)
        print(" :( SCUGIC INIT FAILED
    r");
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //Step-11 :User selection procedure to select and execute tests
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    int Status;
      Status = SetupInterruptSystem();
      t  if (Status != XST_SUCCESS) {
      t    print("Interrupt Setup FAILED
    r");

      ttreturn XST_FAILURE;
      t  }
      while(1)
    {/*
            Readstatus = XGpio_DiscreteRead(&Gpio, 1);
            if(1== Readstatus)
            {
                XTmrCtr_Start(&TimerInstancePtr,0);

                print(" :( SCUGIC INIT FAILED
    r");
            }
            */

    }

              //while(InterruptFlag != 1)

             // InterruptFlag = 0;




      return 0;
    }



    void GpioIsr(void *InstancePtr)
    {
    tu32 Buttons;  // Paste near top of function, with variables
    tu32 New_DutyCycle; // Paste near top of function, with variables

    tXGpio *GpioPtr = (XGpio *)InstancePtr;
    t/*
    t * Disable the interrupt
    t */
    tXGpio_InterruptDisable(GpioPtr, BUTTON_INTERRUPT);
    t/*
    t * There should not be any other interrupts occuring other
    t * than the the button changes
    t */
    tif ((XGpio_InterruptGetStatus(GpioPtr) & BUTTON_INTERRUPT)!= BUTTON_INTERRUPT) {
    ttreturn;
    t}
    t/*
    t * Read state of push buttons and determine which ones changed
    t * states from the previous interrupt. Save a copy of the buttons
    t * for the next interrupt
    t */
    tButtons = XGpio_DiscreteRead(&Gpio, BUTTON_CHANNEL);
    tprintf("Brightness updated to: %d
    r", Buttons);

    tif (Buttons == 1) {

    ttxil_printf("Button 1r
    ");
           XTmrCtr_Start(&TimerInstancePtr,0);

    ttVar = 1;t}
    tif (Buttons == 2) {
    ttxil_printf("Button 2r
    ");
    ttVar = 2;t}
    tif (Buttons == 4) {
    ttxil_printf("Button 3r
    ");
    ttVar = 4;t}
    tif (Buttons == 8) {
    ttxil_printf("Button 4r
    ");
    ttVar = 8;t}
    tif (Buttons == 16) {
    ttxil_printf("Button 5r
    ");
    ttVar = 16;t}

    t//New_DutyCycle = brightness/110000;

    t//XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, V);
    t//xil_printf("Brightness updated to: %d
    r", New_DutyCycle);
    t/* Clear the interrupt such that it is no longer pending in the GPIO */

    t (void)XGpio_InterruptClear(GpioPtr, BUTTON_INTERRUPT);

    t /*
    t  * Enable the interrupt
    t  */
    t XGpio_InterruptEnable(GpioPtr, BUTTON_INTERRUPT);
    t print("Interrupt Processed r
    ");

    }


    /****************************************************************************/
    /**
    * This function sets up the interrupt system for the example.  The processing
    * contained in this funtion assumes the hardware system was built with
    * and interrupt controller.
    *
    * @paramtNone.
    *
    * @returntA status indicating XST_SUCCESS or a value that is contained in
    *ttxstatus.h.
    *
    * @notettNone.
    *
    *****************************************************************************/
    int SetupInterruptSystem()
    {
    tint Result;
    tINTC *IntcInstancePtr = &Intc;

    #ifdef XPAR_INTC_0_DEVICE_ID
    t/*
    t * Initialize the interrupt controller driver so that it's ready to use.
    t * specify the device ID that was generated in xparameters.h
    t */
    tResult = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID);
    tif (Result != XST_SUCCESS) {
    ttreturn Result;
    t}

    t/* Hook up interrupt service routine */
    tXIntc_Connect(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID,
    tt      (Xil_ExceptionHandler)GpioIsr, &Gpio);

    t/* Enable the interrupt vector at the interrupt controller */

    tXIntc_Enable(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID);

    t/*
    t * Start the interrupt controller such that interrupts are recognized
    t * and handled by the processor
    t */
    tResult = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE);
    tif (Result != XST_SUCCESS) {
    ttreturn Result;
    t}

    #else
    tXScuGic_Config *IntcConfig;

    t/*
    t * Initialize the interrupt controller driver so that it is ready to
    t * use.
    t */
    tIntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);
    tif (NULL == IntcConfig) {
    ttreturn XST_FAILURE;
    t}

    tResult = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig,
    tttttIntcConfig->CpuBaseAddress);
    tif (Result != XST_SUCCESS) {
    ttreturn XST_FAILURE;
    t}

    tXScuGic_SetPriorityTriggerType(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID,
    ttttt0xA0, 0x3);

    t/*
    t * Connect the interrupt handler that will be called when an
    t * interrupt occurs for the device.
    t */
    tResult = XScuGic_Connect(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID,
    tttt (Xil_ExceptionHandler)GpioIsr, &Gpio);
    tif (Result != XST_SUCCESS) {
    ttreturn Result;
    t}

    t/*
    t * Enable the interrupt for the GPIO device.
    t */
    tXScuGic_Enable(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID);
    #endif

    t/*
    t * Enable the GPIO channel interrupts so that push button can be
    t * detected and enable interrupts for the GPIO device
    t */
    tXGpio_InterruptEnable(&Gpio, BUTTON_INTERRUPT);
    tXGpio_InterruptGlobalEnable(&Gpio);

    t/*
    t * Initialize the exception table and register the interrupt
    t * controller handler with the exception table
    t */
    tXil_ExceptionInit();

    tXil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
    ttt (Xil_ExceptionHandler)INTC_HANDLER, IntcInstancePtr);

    t/* Enable non-critical exceptions */
    tXil_ExceptionEnable();

    treturn XST_SUCCESS;
    }

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

    I created a new project and I set to get two interruptions, one for timer and for the buttons, it worked without error. When I launched the SDK, both separately code works correctly but when I merged the two, no work me .. I checked everywhere but I do not understand why, if you can help me please. Here is the SDK code: Thank you.

    /*
    * 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"

    #define LED_CHANNEL 2
    #define BUTTON_CHANNEL 1
    #define GPIO_EXAMPLE_DEVICE_ID  XPAR_AXI_GPIO_0_DEVICE_ID
    #define INTC_DEVICE_IDtXPAR_PS7_SCUGIC_0_DEVICE_ID
    #define INTC_GPIO_INTERRUPT_IDtXPAR_FABRIC_GPIO_0_VEC_ID
    #define INTC XScuGic
    #define INTC_HANDLERtXScuGic_InterruptHandler
    #define BUTTON_INTERRUPT XGPIO_IR_CH1_MASK


    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);
    XGpio Gpio;
    static INTC Intc;
    static u8 Var = 0XFF;
    XTmrCtr TimerInstancePtr;

    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_0_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_0_INTERRUPT_INTR);
      return XST_SUCCESS;
    }

    int main()
    {
      //static XGpio Gpio;
      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(&Gpio,XPAR_AXI_GPIO_0_DEVICE_ID);
      if(XST_SUCCESS != xStatus)
        print("GPIO INIT FAILED
    r");
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //Step-2 :AXI GPIO Set the Direction
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      XGpio_SetDataDirection(&Gpio, 1,0X1F);
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //Step-3 :AXI Timer Initialization
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      xStatus = XTmrCtr_Initialize(&TimerInstancePtr,XPAR_AXI_TIMER_0_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
          0xffffffff);
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //Step-6 :Setting timer Option (Interrupt Mode And Auto Reload )
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      XTmrCtr_SetOptions(&TimerInstancePtr,
          XPAR_AXI_TIMER_0_DEVICE_ID,
          (XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION ));
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //Step-7 :PS GPIO Intialization
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      GpioConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_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_0_DEVICE_ID,&TimerInstancePtr);
      if(XST_SUCCESS != xStatus)
        print(" :( SCUGIC INIT FAILED
    r");
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //Step-11 :User selection procedure to select and execute tests
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    int Status;
      Status = SetupInterruptSystem();
      t  if (Status != XST_SUCCESS) {
      t    print("Interrupt Setup FAILED
    r");

      ttreturn XST_FAILURE;
      t  }
      while(1)
    {/*
            Readstatus = XGpio_DiscreteRead(&Gpio, 1);
            if(1== Readstatus)
            {
                XTmrCtr_Start(&TimerInstancePtr,0);

                print(" :( SCUGIC INIT FAILED
    r");
            }
            */

    }

              //while(InterruptFlag != 1)

             // InterruptFlag = 0;




      return 0;
    }



    void GpioIsr(void *InstancePtr)
    {
    tu32 Buttons;  // Paste near top of function, with variables
    tu32 New_DutyCycle; // Paste near top of function, with variables

    tXGpio *GpioPtr = (XGpio *)InstancePtr;
    t/*
    t * Disable the interrupt
    t */
    tXGpio_InterruptDisable(GpioPtr, BUTTON_INTERRUPT);
    t/*
    t * There should not be any other interrupts occuring other
    t * than the the button changes
    t */
    tif ((XGpio_InterruptGetStatus(GpioPtr) & BUTTON_INTERRUPT)!= BUTTON_INTERRUPT) {
    ttreturn;
    t}
    t/*
    t * Read state of push buttons and determine which ones changed
    t * states from the previous interrupt. Save a copy of the buttons
    t * for the next interrupt
    t */
    tButtons = XGpio_DiscreteRead(&Gpio, BUTTON_CHANNEL);
    tprintf("Brightness updated to: %d
    r", Buttons);

    tif (Buttons == 1) {

    ttxil_printf("Button 1r
    ");
           XTmrCtr_Start(&TimerInstancePtr,0);

    ttVar = 1;t}
    tif (Buttons == 2) {
    ttxil_printf("Button 2r
    ");
    ttVar = 2;t}
    tif (Buttons == 4) {
    ttxil_printf("Button 3r
    ");
    ttVar = 4;t}
    tif (Buttons == 8) {
    ttxil_printf("Button 4r
    ");
    ttVar = 8;t}
    tif (Buttons == 16) {
    ttxil_printf("Button 5r
    ");
    ttVar = 16;t}

    t//New_DutyCycle = brightness/110000;

    t//XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, V);
    t//xil_printf("Brightness updated to: %d
    r", New_DutyCycle);
    t/* Clear the interrupt such that it is no longer pending in the GPIO */

    t (void)XGpio_InterruptClear(GpioPtr, BUTTON_INTERRUPT);

    t /*
    t  * Enable the interrupt
    t  */
    t XGpio_InterruptEnable(GpioPtr, BUTTON_INTERRUPT);
    t print("Interrupt Processed r
    ");

    }


    /****************************************************************************/
    /**
    * This function sets up the interrupt system for the example.  The processing
    * contained in this funtion assumes the hardware system was built with
    * and interrupt controller.
    *
    * @paramtNone.
    *
    * @returntA status indicating XST_SUCCESS or a value that is contained in
    *ttxstatus.h.
    *
    * @notettNone.
    *
    *****************************************************************************/
    int SetupInterruptSystem()
    {
    tint Result;
    tINTC *IntcInstancePtr = &Intc;

    #ifdef XPAR_INTC_0_DEVICE_ID
    t/*
    t * Initialize the interrupt controller driver so that it's ready to use.
    t * specify the device ID that was generated in xparameters.h
    t */
    tResult = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID);
    tif (Result != XST_SUCCESS) {
    ttreturn Result;
    t}

    t/* Hook up interrupt service routine */
    tXIntc_Connect(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID,
    tt      (Xil_ExceptionHandler)GpioIsr, &Gpio);

    t/* Enable the interrupt vector at the interrupt controller */

    tXIntc_Enable(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID);

    t/*
    t * Start the interrupt controller such that interrupts are recognized
    t * and handled by the processor
    t */
    tResult = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE);
    tif (Result != XST_SUCCESS) {
    ttreturn Result;
    t}

    #else
    tXScuGic_Config *IntcConfig;

    t/*
    t * Initialize the interrupt controller driver so that it is ready to
    t * use.
    t */
    tIntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);
    tif (NULL == IntcConfig) {
    ttreturn XST_FAILURE;
    t}

    tResult = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig,
    tttttIntcConfig->CpuBaseAddress);
    tif (Result != XST_SUCCESS) {
    ttreturn XST_FAILURE;
    t}

    tXScuGic_SetPriorityTriggerType(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID,
    ttttt0xA0, 0x3);

    t/*
    t * Connect the interrupt handler that will be called when an
    t * interrupt occurs for the device.
    t */
    tResult = XScuGic_Connect(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID,
    tttt (Xil_ExceptionHandler)GpioIsr, &Gpio);
    tif (Result != XST_SUCCESS) {
    ttreturn Result;
    t}

    t/*
    t * Enable the interrupt for the GPIO device.
    t */
    tXScuGic_Enable(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID);
    #endif

    t/*
    t * Enable the GPIO channel interrupts so that push button can be
    t * detected and enable interrupts for the GPIO device
    t */
    tXGpio_InterruptEnable(&Gpio, BUTTON_INTERRUPT);
    tXGpio_InterruptGlobalEnable(&Gpio);

    t/*
    t * Initialize the exception table and register the interrupt
    t * controller handler with the exception table
    t */
    tXil_ExceptionInit();

    tXil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
    ttt (Xil_ExceptionHandler)INTC_HANDLER, IntcInstancePtr);

    t/* Enable non-critical exceptions */
    tXil_ExceptionEnable();

    treturn XST_SUCCESS;
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
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 © 2025 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