AnsweredAssumed Answered

Example code of setting up interrupts without drivers

Question asked by cmerritt Employee on Sep 6, 2017
Latest reply on Sep 7, 2017 by cmerritt

How do you connect your interrupt service routine without using the drivers? For example, below I have modified the LED_button_callback.c example to configure the GPIO with direct register calls associated with the ADUCM302x hardware reference. The example works but I don't want my code to be dependent on the adi_gpio driver. I still am using the following call to connect my ISR.

 

adi_gpio_RegisterCallback (ADI_GPIO_INTA_IRQ, pinIntCallback, (void*)ADI_GPIO_INTA_IRQ);

 

How do I point my "pinIntCallback()" method to the correct place without using all of this abstraction?

 

Thanks,

cmerritt

 

 

 

 

/*********************************************************************************

Copyright(c) 2016 Analog Devices, Inc. All Rights Reserved.

This software is proprietary and confidential.  By using this software you agree
to the terms of the associated Analog Devices License Agreement.

*********************************************************************************/

/*
* Use the GPIO service to Toggle LED's when the push buttons are pressed
* on the ADuCM4x50 EZ-Kit.
*/

#include <drivers/pwr/adi_pwr.h>
#include <drivers/gpio/adi_gpio.h>

#if defined(__ADUCM302x__)

#define PB1_PORT_NUM        ADI_GPIO_PORT1
#define PB1_PIN_NUM         ADI_GPIO_PIN_14

#define PB2_PORT_NUM        ADI_GPIO_PORT2
#define PB2_PIN_NUM         ADI_GPIO_PIN_6

#define LED1_PORT_NUM       ADI_GPIO_PORT1
#define LED1_PIN_NUM        ADI_GPIO_PIN_12

#define LED2_PORT_NUM       ADI_GPIO_PORT1
#define LED2_PIN_NUM        ADI_GPIO_PIN_13

#define PB1_LABEL           "PB0"
#define PB2_LABEL           "PB1"

#define LED1_LABEL          "LED4"
#define LED2_LABEL          "LED5"

#endif

/*
 * GPIO event Callback function
 */
static void pinIntCallback(void* pCBParam, uint32_t Port,  void* PinIntData)
{
    /* push button 1 */
    if((Port == (uint32_t)PB1_PORT_NUM) && (*(uint32_t*)PinIntData & PB1_PIN_NUM))
    {
        /* toggle LED 4 */
        adi_gpio_Toggle(LED1_PORT_NUM, LED1_PIN_NUM);
    }
    /* push button 2 */
    else if((Port == (uint32_t)PB2_PORT_NUM) && (*(uint32_t*)PinIntData & PB2_PIN_NUM))
    {
        /* toggle LED 5 */
        adi_gpio_Toggle(LED2_PORT_NUM, LED2_PIN_NUM);
    }
}

/*
 * main
 */
int main(void)
{
  static uint8_t gpioMemory[ADI_GPIO_MEMORY_SIZE];
      
  adi_pwr_Init();
  adi_pwr_SetClockDivider(ADI_CLOCK_HCLK,1);
  adi_pwr_SetClockDivider(ADI_CLOCK_PCLK,1); 
 
  adi_gpio_Init(gpioMemory, ADI_GPIO_MEMORY_SIZE);
 
  /* enable gpio function on gpio */
  *pREG_GPIO1_CFG = 0x00000000;               /* set gpio 1 mux to all function 0 for GPIOxx */
  *pREG_GPIO2_CFG = 0x00000000;               /* set gpio 2 mux to all function 0 for GPIOxx */ 
  /* enable inputs on push buttons */
  *pREG_GPIO1_IEN = ADI_GPIO_PIN_14;          /* enable input on pin 1.14 */
  *pREG_GPIO2_IEN = ADI_GPIO_PIN_6;           /* enable input on pin 2.06 */
  /* set interrupt polarity to rising edge */
  *pREG_GPIO1_POL = ADI_GPIO_PIN_14;          /* set interrupt polarity to rising edge */
  *pREG_GPIO2_POL = ADI_GPIO_PIN_6;           /* set interrupt polarity to rising edge */
  /* enable port interrupt A for push buttons */
  *pREG_GPIO1_IENA = ADI_GPIO_PIN_14;         /* enable interrupt on gpio 1.14 */
  *pREG_GPIO2_IENA = ADI_GPIO_PIN_6;          /* enable interrupt on gpio 2.06 */
 
//  adi_gpio_InputEnable(PB1_PORT_NUM, PB1_PIN_NUM, true);
//  adi_gpio_InputEnable(PB2_PORT_NUM, PB2_PIN_NUM, true);
//  adi_gpio_SetGroupInterruptPolarity(PB1_PORT_NUM, PB1_PIN_NUM);
//  adi_gpio_SetGroupInterruptPolarity(PB2_PORT_NUM, PB2_PIN_NUM);
//  adi_gpio_SetGroupInterruptPins(PB1_PORT_NUM, ADI_GPIO_INTA_IRQ, PB1_PIN_NUM);
//  adi_gpio_SetGroupInterruptPins(PB2_PORT_NUM, ADI_GPIO_INTA_IRQ, PB2_PIN_NUM);
  adi_gpio_RegisterCallback (ADI_GPIO_INTA_IRQ, pinIntCallback, (void*)ADI_GPIO_INTA_IRQ);
//  adi_gpio_OutputEnable(ADI_GPIO_PORT1, (ADI_GPIO_PIN_12 | ADI_GPIO_PIN_13), true);
 
  /* enable LED outputs on gpio */
  *pREG_GPIO1_OEN = (ADI_GPIO_PIN_12 | ADI_GPIO_PIN_13);
 
  /* wait forever */   
  while(1);

}

Outcomes