Ejemplo n.º 1
0
void SW3_InterruptCB(void)
{
   bool err = true;
   uint8_t status = 0x00;

   // Fetch input edge status
   err &= R_INTC_GetExtInterruptStatus
      (
         PDL_INTC_IRQ4,
         &status
         );

   // Check if interrupt was triggered from falling edge
   if((status & 0x0C) == 0x04)
   {
      // Disable switch interrupts and change to rising edge detection
      err &= R_INTC_ControlExtInterrupt
         (
            PDL_INTC_IRQ4,
            PDL_INTC_DISABLE|PDL_INTC_RISING
            );

      // Check if switch press callback function is not NULL
      if(SwitchPressCallbackFunc)
      {
         // Execute user callback function
         SwitchPressCallbackFunc(SWITCH_3);
      }
   }

   else
   {
      // Switch to falling edge detection
      err &= R_INTC_ControlExtInterrupt
         (
            PDL_INTC_IRQ4,
            PDL_INTC_FALLING
            );

      if(SwitchReleaseCallbackFunc)
      {
         SwitchReleaseCallbackFunc(SWITCH_3);
      }
   }

   // Create 10ms one-shot timer interrupt to de-bounce the switch input
   err &= R_CMT_CreateOneShot
      (
         1,
         PDL_NO_DATA,
         10E-3,
         SwitchDebounceCB,
         8
         );

   while(!err)
      ;
}
Ejemplo n.º 2
0
/******************************************************************************
* Outline       : SW3_InterruptCB
* Description   : Switch 3 callback ISR function. The function disables switch
*                 interrupts, then uses a oneshot timer to re-enable them after
*                 a 10ms debounce timer period.
* Argument      : none
* Return value  : none
******************************************************************************/
void SW3_InterruptCB(void)
{
    /* Declare error flag */
    bool err = true;

    /* Declare status container variable */
    uint8_t status = 0x00;

    /* Fetch input edge status */
    err &=  R_INTC_GetExtInterruptStatus
            (
            PDL_INTC_IRQ10,
            &status
            );

    /* Check if interrupt was triggered from falling edge */
    if ((status & 0x06) == 0x04)
    {
        /* Disable switch interrupts and change to rising edge detection */
        err &=  R_INTC_ControlExtInterrupt
                (
                PDL_INTC_IRQ10,
                PDL_INTC_DISABLE | PDL_INTC_RISING
                );

        /* Set global switch flag to indicate SW3 is held down */
        gSwitchFlag |= 0x02;

        /* Check if switch press callback function is not NULL */
        if (gSwitchPressCallbackFunc)
        {
            /* Execute user callback function */
            gSwitchPressCallbackFunc();
        }
    }

    else
    {
        /* Switch to falling edge detection */
        err &=  R_INTC_ControlExtInterrupt
                (
                PDL_INTC_IRQ10,
                PDL_INTC_FALLING
                );

        /* Clear SW3 held-down bit in switch flag */
        gSwitchFlag &= 0xFD;

        /* Set global switch flag to indicate SW3 press complete */
        gSwitchFlag |= 0x20;

        /* Check if switch release callback function is not NULL */
        if (gSwitchReleaseCallbackFunc)
        {
            /* Execute user callback function */
            gSwitchReleaseCallbackFunc();
        }
    }

    /* Set standby ready flag as false */
    gSwitchStandbyReady = false;

    /* Create 10ms one-shot timer interrupt to debounce the switch input */
    err &=  R_CMT_CreateOneShot
            (
            1,
            PDL_NO_DATA,
            10E-3,
            SwitchDebounceCB,
            8
            );

    /* Halt in while loop when RPDL errors detected */  
    while (!err);
}