2 lwgpio interrupt handlers for 2 different pins

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

2 lwgpio interrupt handlers for 2 different pins

跳至解决方案
3,174 次查看
albertcalpito
Contributor II

I've been trying to initialize 2 separate gpio pins to have 2 separate interrupt handlers, however they seem to only be linked to the 2nd handler i initialize.  Is there some hardware restriction I am missing where 2 pins of the same port must share 1 interrupt hander?  I am seeing that although they are different pins, that the lwgpio_int_get_vector function is returning the same value for both.

LWGPIO_STRUCT column_1;

LWGPIO_STRUCT column_2;

lwgpio_init(&column_1, (GPIO_PORT_B | GPIO_PIN17), LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);
lwgpio_set_functionality(&column_1, 1);
lwgpio_set_attribute(&column_1, LWGPIO_ATTR_PULL_DOWN, LWGPIO_AVAL_ENABLE);
lwgpio_int_init(&column_1, LWGPIO_INT_MODE_RISING);
_int_install_isr(lwgpio_int_get_vector(&column_1), column_1_button_pressed_function, (void *) &column_1);
_bsp_int_init(lwgpio_int_get_vector(&column_1), 3, 0, TRUE);
lwgpio_int_enable(&column_1, TRUE);

lwgpio_init(&column_2, (GPIO_PORT_B | GPIO_PIN18), LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);
lwgpio_set_functionality(&column_2, 1);
lwgpio_set_attribute(&column_2, LWGPIO_ATTR_PULL_DOWN, LWGPIO_AVAL_ENABLE);
lwgpio_int_init(&column_2, LWGPIO_INT_MODE_RISING);
_int_install_isr(lwgpio_int_get_vector(&column_2), column_2_button_pressed_function, (void *) &column_2);
_bsp_int_init(lwgpio_int_get_vector(&column_2), 3, 0, TRUE);
lwgpio_int_enable(&column_2, TRUE);


vector_value = lwgpio_int_get_vector(&column_1);
vector_value = lwgpio_int_get_vector(&column_2);

void column_1_button_pressed_function(void *pin)
{
  printf("1\r\n");
  lwgpio_int_clear_flag((LWGPIO_STRUCT_PTR) pin);
}

void column_2_button_pressed_function(void *pin)
{
  printf("2\r\n");
  lwgpio_int_clear_flag((LWGPIO_STRUCT_PTR) pin);
}

标记 (3)
1 解答
2,624 次查看
c0170
Senior Contributor III

Hello albert calpito,

you almost answered your question. I would recommend read NVIC part in a reference manual. Each port has own interrupt handler which indicates that your two buttons on PORTB share same ISR.

There is even here a discussion about it and how they solved an identification which button was pushed in ISR.

Regards,

c0170

在原帖中查看解决方案

0 项奖励
回复
7 回复数
2,625 次查看
c0170
Senior Contributor III

Hello albert calpito,

you almost answered your question. I would recommend read NVIC part in a reference manual. Each port has own interrupt handler which indicates that your two buttons on PORTB share same ISR.

There is even here a discussion about it and how they solved an identification which button was pushed in ISR.

Regards,

c0170

0 项奖励
回复
2,624 次查看
nikhilsarnaik
Contributor III

Hi I am having similar issue, can you please point to the discussion of how to resolve it.

Thanks

Nikhil

0 项奖励
回复
2,624 次查看
albertcalpito
Contributor II

I have just responded to the thread with some c and h files to solve this issue.

Thank you,

Sincerely,

Albert Calpito

Ayantra

47873 Fremont Blvd,

Fremont. CA 94538

<http://www.ayantra.com> www.ayantra.com

510-623-7526 Office

510-552-4399 Cell

510-623-7839

0 项奖励
回复
2,624 次查看
kyleyang
Contributor IV

Hi Albert

Many thanks for your sharing.

But still need your help.

I got an issue on lwevent settings.

I have assign a lwevent to a gpio.

But the handler task can not receive the lwevent even if interrupt occur and set the event.

0 项奖励
回复
2,624 次查看
kyleyang
Contributor IV

Hi Albert

Sorry for bother you.

I fix this issue just now.

I find that missing some address map code in the "register_gpio_file".

It is works fine now.

Many thanks for your effort again.

0 项奖励
回复
2,624 次查看
nikhilsarnaik
Contributor III

Thanks Albert for your info, I fixed it, it was error in my code. I was not clearing the correct interrupt flag.

Nikhil

0 项奖励
回复
2,624 次查看
albertcalpito
Contributor II


Hello Nikhil,

Please see the attached files.  I've written an init function that will map interrupt events for the gpio's to their specific interrupt handlers.  The interrupt handlers will set the event that was specified in the init structure.

I've tested this for a few gpios at a time, and basic functionality seems to be working.