foss-for-synopsys-dwc-arc-processors / embarc_osp

embARC Open Software Platform (OSP) - An embedded software distribution for IoT and other embedded applications for ARC
https://www.embarc.org/
BSD 3-Clause "New" or "Revised" License
70 stars 62 forks source link

Interrupt example for Iotdk #97

Closed ericwu13 closed 5 years ago

ericwu13 commented 5 years ago

Issue Summary

ericwu13 commented 5 years ago

I'm setting interrupt for arduino AD0 like this, however the serial keeps printing message like the below picture (periodically) when the interrupt pin is trigger, do I set it right? image

#define PIN_VSYNC 7
int main() {
     io_arduino_config(ARDUINO_PIN_AD0, ARDUINO_GPIO, IO_PINMUX_ENABLE); // vsync
     clk_ptr = gpio_get_dev(DFSS_GPIO_8B3_ID);
     if (clk_ptr->gpio_open((1 << PIN_VSYNC)) == E_OPNED) {
         clk_ptr->gpio_control(GPIO_CMD_DIS_BIT_INT,
         (void *)(1 << PIN_VSYNC));
     }
     DEV_GPIO_BIT_ISR bit_isr_vsync;
     DEV_GPIO_INT_CFG int_cfg_vsync;
     int_cfg_vsync.int_bit_mask = 1 << PIN_VSYNC;
     int_cfg_vsync.int_bit_type = GPIO_INT_EDGE_TRIG;
     int_cfg_vsync.int_bit_polarity = GPIO_INT_FALLING_EDGE;
     int_cfg_vsync.int_bit_debounce = GPIO_INT_NO_DEBOUNCE;
     clk_ptr->gpio_control(GPIO_CMD_SET_BIT_INT_CFG, &int_cfg_vsync);

     bit_isr_vsync.int_bit_ofs = PIN_VSYNC;
     bit_isr_vsync.int_bit_handler = vsyncHandler;

     clk_ptr->gpio_control(GPIO_CMD_SET_BIT_ISR, &bit_isr_vsync);
     clk_ptr->gpio_control(GPIO_CMD_ENA_BIT_INT, (void *)(1 << PIN_VSYNC));
}
ericwu13 commented 5 years ago

Is there any comments? I wonder if my int_bit_ofs is set correctly. Is this represent the PIN number of the interrupt PIN? Hope you can provide some example about interrupt setting. Thanks.

IRISZZW commented 5 years ago

you can reference the GPIO related code in pmwifi.c.

int main()
{
    io_arduino_config(ARDUINO_PIN_AD0, ARDUINO_GPIO, IO_PINMUX_ENABLE); // vsync
    clk_ptr = gpio_get_dev(PIN_PORT);
    if (clk_ptr->gpio_open((1 << PIN_VSYNC)) == E_OK) {
        clk_ptr->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, (void *)(1 << PIN_VSYNC));
    }
    int_cfg_vsync.int_bit_mask = 1 << PIN_VSYNC;
    int_cfg_vsync.int_bit_type = GPIO_INT_BIT_LEVEL_TRIG(PIN_VSYNC);
    int_cfg_vsync.int_bit_polarity = GPIO_INT_BIT_POL_ACT_LOW(PIN_VSYNC);
    int_cfg_vsync.int_bit_debounce = GPIO_INT_BIT_DIS_DEBOUNCE(PIN_VSYNC);
    clk_ptr->gpio_control(GPIO_CMD_SET_BIT_INT_CFG, (void *)&int_cfg_vsync);

    bit_isr_vsync.int_bit_ofs = PIN_VSYNC;
    bit_isr_vsync.int_bit_handler = vsyncHandler;
    clk_ptr->gpio_control(GPIO_CMD_SET_BIT_ISR, (void *)&bit_isr_vsync);

    clk_ptr->gpio_control(GPIO_CMD_ENA_BIT_INT, (void *)(1 << PIN_VSYNC));
}
ericwu13 commented 5 years ago

Hi, I still couldn't use interrupt pin correctly, I used your code, and change the configuration to falling edge trigger. The function just can't be triggered, but the signal is working. Do you have any idea about it? I wonder if the problem is that I didn't use the right pin to configure interrupt?

int_cfg_vsync.int_bit_type = GPIO_INT_BIT_EDGE_TRIG(PIN_VSYNC);
int_cfg_vsync.int_bit_polarity = GPIO_INT_BIT_POL_FALL_EDGE(PIN_VSYNC);