josef sageder

lwgpio interrupt problem

Discussion created by josef sageder on Jan 12, 2012
Latest reply on Jan 23, 2013 by Mohsin455

hi there,

i have a custom board using a kinetis k60 and i don't seem to get my lwgpio isr properly working... 2 buttons (PortC14, PortC15) trigger interrupts on either edge, enter the same isr to set a lwevent depending on which button has been pressed...

 

if i setup only one button to use interrupts (doesn't matter which one) everything works fine (except for the second interrupt)...

 

what happens now is that, if i press the second button first (the one where the isr is registerd later) it works fine... if i then press the first button the isr gets called over and over again with the wrong pin as parameter passed to the isr (the second pin instead of the first)...

 

 

any idea anyone?

thx,

joe

 

sry about posting the code, couldn't attach the files...

 

 

ISR

// callback for PortC, interrupts coming from HMI (2 pins)
void PortC_int_callback(void *pin) {
    
    uint_32 pinmask = ((LWGPIO_STRUCT_PTR)pin)->pinmask;
    
    switch(pinmask) {
        
        case(HMI_BUTTON1_MASK):
            printf("\n PortC_int_callback entered, source: HMI_BUTTON1, pinmask: %x", pinmask);
            if (_lwevent_set(&BUTTON1_LWEVENT, INT_EVENT_MASK) != MQX_OK) {
                printf("\nSet Event BUTTON1_LWEVENT failed");
                _mqx_exit(0);
            }
            break;
        case(HMI_BUTTON2_MASK):
            printf("\n PortC_int_callback entered, source: HMI_BUTTON2, pinmask: %x", pinmask);
            if (_lwevent_set(&BUTTON2_LWEVENT, INT_EVENT_MASK) != MQX_OK) {
                printf("\nSet Event BUTTON2_LWEVENT failed");
                _mqx_exit(0);
            }
            break;    
        default:    
            printf("\n PortC_int_callback entered, unknown int source");
            break;
    }
    
    lwgpio_int_clear_flag((LWGPIO_STRUCT_PTR) pin);
}

 

BUTTON SETUP

    // opening pin button1 as input
    if (!lwgpio_init(&btn1, HMI_BUTTON1, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE)) {
        printf("Initializing button GPIO as input failed.\n");
        _task_block();
    }
    lwgpio_set_functionality(&btn1, HMI_BUTTON1_MUX_GPIO);
    lwgpio_set_attribute(&btn1, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE);

    // install interrupt service routine for button1
    if (!lwgpio_int_init(&btn1, LWGPIO_INT_MODE_FALLING | LWGPIO_INT_MODE_RISING)) {
        printf("Initializing button1 GPIO for interrupt failed.\n");
        _task_block();
    }
    printf("\nButton1 configured for interrupt.");
    _int_install_isr(lwgpio_int_get_vector(&btn1), PortC_int_callback, (void *) &btn1);
    _bsp_int_init(lwgpio_int_get_vector(&btn1), 3, 0, TRUE);
    lwgpio_int_enable(&btn1, TRUE);
    
    
    
    // opening pin button2 as input
    if (!lwgpio_init(&btn2, HMI_BUTTON2, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE)) {
        printf("Initializing button GPIO as input failed.\n");
        _task_block();
    }
    lwgpio_set_functionality(&btn2, HMI_BUTTON2_MUX_GPIO);
    lwgpio_set_attribute(&btn2, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE);

    // install interrupt service routine for button2
    if (!lwgpio_int_init(&btn2, LWGPIO_INT_MODE_FALLING | LWGPIO_INT_MODE_RISING)) {
        printf("Initializing button2 GPIO for interrupt failed.\n");
        _task_block();
    }
    printf("\nButton2 configured for interrupt.");
    _int_install_isr(lwgpio_int_get_vector(&btn2), PortC_int_callback, (void *) &btn2);
    _bsp_int_init(lwgpio_int_get_vector(&btn2), 3, 0, TRUE);
    lwgpio_int_enable(&btn2, TRUE);

 

Outcomes