11 Replies Latest reply on Aug 10, 2016 4:27 AM by malcolm.prinn

    GPIO Interupts

    GPIO

      Hi,

       

      is it possible to configure two GPIO interupts in D2000. Also, please mention, how many GPIO interrupts can be configured in a single program.

       

      Regards,

       

      Dilip Shankar

        • 1. Re: GPIO Interupts
          Lockdog
          • 2. Re: GPIO Interupts
            PabloM_Intel

            Hi GPIO,

             

            The Quark D2000 has 6 fast response/high performance comparator. And I believe you can use them simultaneously, at least in theory, however, if two or more interrupts trigger at the same time the one with the highest priority would be the one to take action, with the possibility that the others will be ignored. So I would suggest you to take that in mind. The link provided by Lockdog is also very helpful, you should check that for reference.

             

            Regards,

            -Pablo

            • 3. Re: GPIO Interupts
              GPIO

              #include "qm_gpio.h"

              #include "qm_interrupt.h"

               

               

              /* QMSI GPIO app example

              *

              *  PIN_OUT will be configured as an output pin and PIN_INTR will be

              * configured as an input pin with interrupts

              * enabled.

              *

              * On the Intel(R) Quark(TM) Microcontroller D2000 Development Platform PIN_OUT

              * and PIN_INTR are marked "SSO 10" and "A0".

              */

               

               

              /* Connect LED to PIN_OUT */

              #define PIN_OUT 0

              /*Connect Button to PIN_INTR */

              #define PIN_INTR 3

               

              /* Example callback function */

              static void gpio_example_callback(uint32_t);

               

              int main(void)

              {

                qm_gpio_port_config_t cfg;

               

               

                /* Request IRQ and write GPIO port config */

                cfg.direction = BIT(PIN_OUT);

                cfg.int_en = BIT(PIN_INTR);       /* Interrupt enabled */

                cfg.int_type = BIT(PIN_INTR);     /* Edge sensitive interrupt */

                cfg.int_polarity = BIT(PIN_INTR); /* Rising edge */

                cfg.int_debounce = BIT(PIN_INTR); /* Debounce enabled */

                cfg.int_bothedge = 0x0;  /* Both edge disabled */

                cfg.callback = gpio_example_callback;

               

                qm_irq_request(QM_IRQ_GPIO_0, qm_gpio_isr_0);

               

                qm_gpio_set_config(QM_GPIO_0, &cfg);

               

                /* Set PIN_OUT to trigger PIN_INTR interrupt*/

                qm_gpio_clear_pin(QM_GPIO_0, PIN_OUT);

                qm_gpio_set_pin(QM_GPIO_0, PIN_OUT);

               

              while(1)

              {

                /* Your code goes here */

              }

              return 0;

              }

               

               

              void gpio_example_callback(uint32_t status)

              {

                /* toggle LED state  - ON/OFF  */

                if(false == qm_gpio_read_pin(QM_GPIO_0, PIN_OUT))

                {

                qm_gpio_set_pin(QM_GPIO_0, PIN_OUT);

                }

                else{

                qm_gpio_clear_pin(QM_GPIO_0, PIN_OUT);

                }

              }

               

               

              How to include another GPIO interrupt configuration for the same code?

              • 4. Re: GPIO Interupts
                PabloM_Intel

                Hi GPIO,

                 

                You’ll need to define a new input pin as interrupt along with the one that’s already configure (PIN_INTR is the existing one, so you can use a similar name to define the new one). The one that’s already configured is A0, so check the documentation for the Pin Configuration to see which ones you can use. To set the new pin as interrupt you’ll need to configure it just as the “Request IRQ and write GPIO port config” section from the code. I guess you’ll also use a different input/output pin to trigger the new interrupt (in the example, this output pin is PIN_OUT), so you can use that configuration as well.

                 

                Regards,

                -Pablo

                • 5. Re: GPIO Interupts
                  GPIO

                  Hi PabloM,

                   

                  Could you please send me the code, including two GPIO (Switch) interrupts.

                   

                   

                  Regards,

                  Dilip Shankar

                  • 6. Re: GPIO Interupts
                    PabloM_Intel

                    Hi GPIO,

                     

                    I’ll give you some hints so you can continue by yourself with the code.

                     

                    /*Define two new pins, one to control the interrupt and another one for the Interrupt itself, (where X and Y are the GPIO number that you’ll use)*/
                    #define SECOND_PIN_OUT X
                    #define SECOND_PIN_INTR Y
                    
                    /*Request IRQ and write GPIO port config */
                    cfg.direction = BIT(SECOND_PIN_OUT);
                    cfg.int_en = BIT(SECOND_PIN_INTR); /* Interrupt enabled */
                    cfg.int_type = BIT(SECOND_PIN_INTR); /* Edge sensitive interrupt */
                    cfg.int_polarity = BIT(SECOND_PIN_INTR); /* Rising edge */
                    cfg.int_debounce = BIT(SECOND_PIN_INTR); /* Debounce enabled */
                    cfg.int_bothedge = 0x0;  /* Both edge disabled */
                    cfg.callback = gpio_example_callback;
                    
                    qm_irq_request(QM_IRQ_GPIO_Y, qm_gpio_isr_0);
                    qm_gpio_set_config(QM_GPIO_Y, &cfg);
                    

                     

                    Regards,

                    -Pablo

                    • 7. Re: GPIO Interupts
                      GPIO

                      Hi PabloM_Intel,

                       

                      I was also trying to  code, in the same manner, but only one interrupt seems to be working. Please have a look into the code, below
                       

                      #include "qm_pinmux.h"

                      #include "qm_uart.h"

                      #include "qm_interrupt.h"

                      #include "qm_scss.h"

                      #include "qm_gpio.h"

                       

                      #define PIN_INTR 2

                      #define PIN_INTR1 10

                      #define BIT1(x) (0U << x)

                       

                      static qm_gpio_port_config_t sw_cfg;

                      static qm_gpio_port_config_t sw_cfg1; 

                      static void gpio_example_callback();

                      static void gpio_example_callback1();

                         

                      /* Sample UART0 QMSI application. */

                      int main(void)

                      {

                      qm_uart_config_t cfg, rd_cfg; 

                      qm_uart_status_t ret __attribute__((unused));

                       

                      /* Set divisors to yield 115200bps baud rate. */

                      /* Sysclk is set by boot ROM to hybrid osc in crystal mode (32MHz),

                      * peripheral clock divisor set to 1.

                      */

                      cfg.baud_divisor = QM_UART_CFG_BAUD_DL_PACK(0, 17, 6);

                       

                      cfg.line_control = QM_UART_LC_8N1;

                      cfg.hw_fc = false;

                       

                      /* Mux out UART0 tx/rx pins and enable input for rx. */

                       

                      qm_pmux_select(QM_PIN_ID_12, QM_PMUX_FN_2);

                      qm_pmux_select(QM_PIN_ID_13, QM_PMUX_FN_2);

                      qm_pmux_input_en(QM_PIN_ID_13, true);

                       

                      clk_periph_enable(CLK_PERIPH_CLK | CLK_PERIPH_UARTA_REGISTER);

                      qm_uart_set_config(QM_UART_0, &cfg);

                      qm_uart_get_config(QM_UART_0, &rd_cfg);
                       

                      /*sw_cfg.direction = BIT(LED_BIT);*/

                      sw_cfg.int_en = BIT(PIN_INTR);

                      sw_cfg.int_type = BIT(PIN_INTR);

                      sw_cfg.int_polarity = BIT(PIN_INTR);

                      sw_cfg.int_debounce = 0;

                      sw_cfg.int_bothedge = 0x0;

                      sw_cfg.callback = gpio_example_callback;

                       

                      qm_irq_request(QM_IRQ_GPIO_0, qm_gpio_isr_0); 

                      qm_gpio_set_config(QM_GPIO_0, &sw_cfg);

                        

                      sw_cfg1.direction = BIT1(PIN_INTR1);

                      sw_cfg1.int_en = BIT(PIN_INTR1);

                      sw_cfg1.int_type = BIT(PIN_INTR1);

                      sw_cfg1.int_polarity = BIT(PIN_INTR1);

                      sw_cfg1.int_debounce = 0;

                      sw_cfg1.int_bothedge = 0x0;

                      sw_cfg1.callback = gpio_example_callback1;

                       

                      qm_irq_request(QM_IRQ_GPIO_0, qm_gpio_isr_0);

                      qm_gpio_set_config(QM_GPIO_0, &sw_cfg1);

                      return 0;

                      }


                       

                      void gpio_example_callback()

                      qm_uart_write_buffer(QM_UART_0,(uint8_t *)"Good Morning",sizeof("Good Morning"));

                      }


                       

                      void gpio_example_callback1()

                      {

                       

                      qm_uart_write_buffer(QM_UART_0,(uint8_t *)"Hello World",sizeof("Hello World"));

                      }

                      • 8. Re: GPIO Interupts
                        PabloM_Intel

                        Hi GPIO,

                         

                        Let us investigate your code a little bit more and we will get back to you soon. Thank you for your patience.

                         

                        Regards,

                        -Pablo

                        • 9. Re: GPIO Interupts
                          Lockdog

                          Look at this row in your code:

                          sw_cfg1.direction = BIT1(PIN_INTR1);

                          BIT1 instead BIT.

                          Are you sure, that your code compiles without error?

                          And set the direction, are not required for the interrupts. The most important thing, that you configure the gpio pin as OUTPUT,  by this command.

                          • 10. Re: GPIO Interupts
                            PabloM_Intel

                            Hi GPIO,

                             

                            Have you tried Lockdog' suggestion? Have you checked if you get any errors when compiling?

                             

                            Regards,

                            -Pablo

                            • 11. Re: GPIO Interupts
                              malcolm.prinn

                              Hi Dilip,

                               

                              I just had a look at your code,

                               

                              you set the GPIO config once here in your line

                               

                              qm_gpio_set_config(QM_GPIO_0, &sw_cfg);

                               

                              and then overwrite the GPIO configuration with this line

                              qm_gpio_set_config(QM_GPIO_0, &sw_cfg1);

                               

                              If you want to configure the GPIO to have two interrupts, you'd have to set just one configuration and have your lines be something like

                               

                              sw_cfg.int_en = BIT(PIN_INTR) | BIT(SECOND_INTERRUPT_PIN);

                               

                              the int_en is a bit field. As is the case for most of the registers for GPIO.

                               

                              HTH,

                              Mal