Best practice for using same interrupt vectors as SDK components?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Best practice for using same interrupt vectors as SDK components?

Jump to solution
667 Views
jackking
Senior Contributor I

I have several GPIO interrupts that need to share the same GPIO port as the Card Detect GPIO pin I am using for the sdcard.

In fsl_sdmmc_host.c, card detect has a GPIO interrupt handler defined.  It uses variables scoped only to fsl_sdmmc_host.c.

What is the recommendation to add additional GPIO interrupts and keep the CD interrupt handler?  I didn't want to have to make substantial changes to the SDK component, but I don't see many other options.

0 Kudos
1 Solution
511 Views
jackking
Senior Contributor I

Here is what I ended up doing, although modifying the SDK code isn't desirable.

I have my project specific interrupt handlers defined in a local header file.   For the Card Detect handler included in the SDK, I had to comment out the provided code and create a separate function that I call from my own handler.

#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
extern "C"
{
#endif

void GPIO1_Combined_0_15_IRQHandler()
{
  if (GPIO_PortGetInterruptFlags(GPIO1) & (1U << ENCODER0_GPIO_PIN_A))
  {
    GPIO_PortClearInterruptFlags(GPIO1, 1U << ENCODER0_GPIO_PIN_A);
    // do something
  }
  else if (SDMMCHOST_CARD_DETECT_GPIO_INTERRUPT_STATUS() & (1U << BOARD_USDHC_CD_GPIO_PIN))
  {
    CD_Handler();
  }
}

#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
}
#endif‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Here is the modified handler I put in the SDK:

// void SDMMCHOST_CARD_DETECT_GPIO_INTERRUPT_HANDLER(void)
// {
//     if (SDMMCHOST_CARD_DETECT_GPIO_INTERRUPT_STATUS() & (1U << BOARD_USDHC_CD_GPIO_PIN))
//     {
//         SDMMCHOST_NofiyCardInsertStatus((SDMMCHOST_CARD_DETECT_GPIO_STATUS() == SDMMCHOST_CARD_INSERT_CD_LEVEL),
//                                         ((sdmmhostcard_usr_param_t *)s_usdhcHandle.userData)->cd);
//     }
//     /* Clear interrupt flag.*/
//     SDMMCHOST_CARD_DETECT_GPIO_INTERRUPT_STATUS_CLEAR(~0U);
//     SDMMCEVENT_Notify(kSDMMCEVENT_CardDetect);
// }

void CD_Handler(void)
{
  SDMMCHOST_NofiyCardInsertStatus((SDMMCHOST_CARD_DETECT_GPIO_STATUS() == SDMMCHOST_CARD_INSERT_CD_LEVEL), ((sdmmhostcard_usr_param_t*) s_usdhcHandle.userData)->cd);
  /* Clear interrupt flag.*/
  SDMMCHOST_CARD_DETECT_GPIO_INTERRUPT_STATUS_CLEAR(~0U);
  SDMMCEVENT_Notify(kSDMMCEVENT_CardDetect);
}

View solution in original post

0 Kudos
2 Replies
512 Views
jackking
Senior Contributor I

Here is what I ended up doing, although modifying the SDK code isn't desirable.

I have my project specific interrupt handlers defined in a local header file.   For the Card Detect handler included in the SDK, I had to comment out the provided code and create a separate function that I call from my own handler.

#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
extern "C"
{
#endif

void GPIO1_Combined_0_15_IRQHandler()
{
  if (GPIO_PortGetInterruptFlags(GPIO1) & (1U << ENCODER0_GPIO_PIN_A))
  {
    GPIO_PortClearInterruptFlags(GPIO1, 1U << ENCODER0_GPIO_PIN_A);
    // do something
  }
  else if (SDMMCHOST_CARD_DETECT_GPIO_INTERRUPT_STATUS() & (1U << BOARD_USDHC_CD_GPIO_PIN))
  {
    CD_Handler();
  }
}

#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
}
#endif‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Here is the modified handler I put in the SDK:

// void SDMMCHOST_CARD_DETECT_GPIO_INTERRUPT_HANDLER(void)
// {
//     if (SDMMCHOST_CARD_DETECT_GPIO_INTERRUPT_STATUS() & (1U << BOARD_USDHC_CD_GPIO_PIN))
//     {
//         SDMMCHOST_NofiyCardInsertStatus((SDMMCHOST_CARD_DETECT_GPIO_STATUS() == SDMMCHOST_CARD_INSERT_CD_LEVEL),
//                                         ((sdmmhostcard_usr_param_t *)s_usdhcHandle.userData)->cd);
//     }
//     /* Clear interrupt flag.*/
//     SDMMCHOST_CARD_DETECT_GPIO_INTERRUPT_STATUS_CLEAR(~0U);
//     SDMMCEVENT_Notify(kSDMMCEVENT_CardDetect);
// }

void CD_Handler(void)
{
  SDMMCHOST_NofiyCardInsertStatus((SDMMCHOST_CARD_DETECT_GPIO_STATUS() == SDMMCHOST_CARD_INSERT_CD_LEVEL), ((sdmmhostcard_usr_param_t*) s_usdhcHandle.userData)->cd);
  /* Clear interrupt flag.*/
  SDMMCHOST_CARD_DETECT_GPIO_INTERRUPT_STATUS_CLEAR(~0U);
  SDMMCEVENT_Notify(kSDMMCEVENT_CardDetect);
}
0 Kudos
511 Views
soledad
NXP Employee
NXP Employee

Hello, 

Yes, as mentioned you have to differentiate the pin by the interrupt status Flag, as you did. 

Have a nice day, 

Regards 

Soledad

0 Kudos