Post Go back to editing

GPIO Interrupt problem

Category: Software
Product Number: ADSP-21569
Software Version: CCES 2.9.2

Hello,

I have some problems with GPIO interrupts.

When I use only 3 GPIO pins as interrupt sources, everything works OK. However, if I add 2 more pins, the processor hangs after a short time. I have tried various solutions but unfortunately I am not able to run interrupts on all 5 pins that I need. Below is the code that I am trying to use to trigger interrupts. Can anyone tell me what I'm doing wrong? I have no idea what could be wrong anymore. I initialized interrupts and GPIO according to the examples from AD.

#define GPIO_MEMORY_SIZE ((ADI_GPIO_CALLBACK_MEM_SIZE)*5)
static uint8_t gpioMemory[GPIO_MEMORY_SIZE];

void gpioCallback(ADI_GPIO_PIN_INTERRUPT ePinInt, uint32_t Data, void *pCBParam)
{
	if (ePinInt == ADI_GPIO_PIN_INTERRUPT_0)
	{
		if(Data & ADI_GPIO_PIN_15)
		{
			ToggleLed(LED1);
		}
		if (Data & ADI_GPIO_PIN_5)
		{
			ToggleLed(LED2);
		}
	}

	if (ePinInt == ADI_GPIO_PIN_INTERRUPT_1)
	{

		if(Data & ADI_GPIO_PIN_14)
		{
			ToggleLed(LED3);
		}
		if(Data & ADI_GPIO_PIN_11)
		{
			ToggleLed(LED4);
		}
	}

	if (ePinInt == ADI_GPIO_PIN_INTERRUPT_2)
	{
		if (Data & ADI_GPIO_PIN_0)
		{
			ToggleLed(LED5);
		}
	}

}


void GPIO_Interrupt_Init(void)
{
	uint32_t gpioMaxCallbacks;

	ADI_GPIO_RESULT result,result1,result2,result3,result4;

	result = adi_gpio_Init((void*)gpioMemory,GPIO_MEMORY_SIZE,&gpioMaxCallbacks);
	if(result != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed1 \n");
	}


	/*Initialize PC_00 as input pin. Also set input enable */
	result1 = adi_gpio_PortInit(ADI_GPIO_PORT_C,ADI_GPIO_PIN_0, ADI_GPIO_DIRECTION_INPUT,true);
	if(result1 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed2 \n");
	}

	/*Register a callback */
	result2 = adi_gpio_RegisterCallback(ADI_GPIO_PIN_INTERRUPT_2,ADI_GPIO_PIN_0,gpioCallback,(void*)0);
	if(result2 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed3 \n");
	}

	/* Configure the PINT2 interrupt for level */
	result3 =adi_gpio_PinInt(ADI_GPIO_PIN_ASSIGN_PCL_PINT2,ADI_GPIO_PIN_0, ADI_GPIO_PIN_INTERRUPT_2,ADI_GPIO_PIN_ASSIGN_BYTE_0,true,ADI_GPIO_SENSE_RISING_EDGE);
	if(result3 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed4 \n");
	}


	/*Initialize PA_15 as input pin. Also set input enable */
	result1 = adi_gpio_PortInit(ADI_GPIO_PORT_A,ADI_GPIO_PIN_15, ADI_GPIO_DIRECTION_INPUT,true);
	if(result1 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed5 \n");
	}

	/*Register a callback */
	result2 = adi_gpio_RegisterCallback(ADI_GPIO_PIN_INTERRUPT_0,ADI_GPIO_PIN_15,gpioCallback,(void*)0);
	if(result2 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed6 \n");
	}

	/* Configure the PINT0 interrupt for level */
	result3 =adi_gpio_PinInt(ADI_GPIO_PIN_ASSIGN_PAH_PINT0,ADI_GPIO_PIN_15, ADI_GPIO_PIN_INTERRUPT_0,ADI_GPIO_PIN_ASSIGN_BYTE_1,true,ADI_GPIO_SENSE_RISING_EDGE);
	if(result3 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed7 \n");
	}



	/*Initialize PB_14 as input pin. Also set input enable */
	result1 = adi_gpio_PortInit(ADI_GPIO_PORT_B,ADI_GPIO_PIN_14, ADI_GPIO_DIRECTION_INPUT,true);
	if(result1 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed8 \n");
	}

	/*Register a callback */
	result2 = adi_gpio_RegisterCallback(ADI_GPIO_PIN_INTERRUPT_1,ADI_GPIO_PIN_14,gpioCallback,(void*)0);
	if(result2 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed9 \n");
	}

	/* Configure the PINT1 interrupt for level */
	result3 =adi_gpio_PinInt(ADI_GPIO_PIN_ASSIGN_PBH_PINT1,ADI_GPIO_PIN_14, ADI_GPIO_PIN_INTERRUPT_1,ADI_GPIO_PIN_ASSIGN_BYTE_1,true,ADI_GPIO_SENSE_RISING_EDGE);
	if(result3 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed10 \n");
	}



	/*Initialize PB_11 as input pin. Also set input enable */
	result1 = adi_gpio_PortInit(ADI_GPIO_PORT_B,ADI_GPIO_PIN_11, ADI_GPIO_DIRECTION_INPUT,true);
	if(result1 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed11 \n");
	}

	/*Register a callback */
	result2 = adi_gpio_RegisterCallback(ADI_GPIO_PIN_INTERRUPT_1,ADI_GPIO_PIN_11,gpioCallback,(void*)0);
	if(result2 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed12 \n");
	}

	/* Configure the PINT1 interrupt for level */
	result3 =adi_gpio_PinInt(ADI_GPIO_PIN_ASSIGN_PBH_PINT1,ADI_GPIO_PIN_11, ADI_GPIO_PIN_INTERRUPT_1,ADI_GPIO_PIN_ASSIGN_BYTE_3,true,ADI_GPIO_SENSE_RISING_EDGE);
	if(result3 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed13 \n");
	}



	/*Initialize PA_05 as input pin. Also set input enable */
	result1 = adi_gpio_PortInit(ADI_GPIO_PORT_A,ADI_GPIO_PIN_5, ADI_GPIO_DIRECTION_INPUT,true);
	if(result1 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed14 \n");
	}
	/*Register a callback */
	result2 = adi_gpio_RegisterCallback(ADI_GPIO_PIN_INTERRUPT_0,ADI_GPIO_PIN_5,gpioCallback,(void*)0);
	if(result2 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed15 \n");
	}

	/* Configure the PINT0 interrupt for level */
	result3 =adi_gpio_PinInt(ADI_GPIO_PIN_ASSIGN_PAL_PINT0,ADI_GPIO_PIN_5, ADI_GPIO_PIN_INTERRUPT_0,ADI_GPIO_PIN_ASSIGN_BYTE_0,true,ADI_GPIO_SENSE_RISING_EDGE);
	if(result3 != ADI_GPIO_SUCCESS)
	{
		printf("GPIO Initialization failed7 \n");
	}
}