Ejemplo n.º 1
0
/**@brief Function for handling the GPIOTE interrupt.
 */
void GPIOTE_IRQHandler(void)
{
    uint8_t  i;
    uint32_t pins_changed;
    uint32_t pins_state = NRF_GPIO->IN;

    // Clear event.
    NRF_GPIOTE->EVENTS_PORT = 0;

    // Check all users.
    for (i = 0; i < m_user_count; i++)
    {
        gpiote_user_t * p_user = &mp_users[i];

        // Check if user is enabled.
        if (((1 << i) & m_enabled_users_mask) != 0)
        {
            uint32_t transition_pins;
            uint32_t event_low_to_high;
            uint32_t event_high_to_low;

            // Find set of pins on which there has been a transition.
            transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;

            // Toggle SENSE level for all pins that have changed state.
            sense_level_toggle(p_user, transition_pins);

            // Second read after setting sense.
            // Check if any pins have changed while serving this interrupt.
            pins_changed = NRF_GPIO->IN ^ pins_state;
            if (pins_changed)
            {
                // Transition pins detected in late stage.
                uint32_t late_transition_pins;

                pins_state          |= pins_changed;

                // Find set of pins on which there has been a transition.
                late_transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;

                // Toggle SENSE level for all pins that have changed state in last phase.
                sense_level_toggle(p_user, late_transition_pins);

                // Update pins that has changed state since the interrupt occurred.
                transition_pins |= late_transition_pins;
            }

            // Call user event handler if an event has occurred.
            event_high_to_low = (~pins_state & p_user->pins_high_to_low_mask) & transition_pins;
            event_low_to_high = (pins_state & p_user->pins_low_to_high_mask) & transition_pins;

            if ((event_low_to_high | event_high_to_low) != 0)
            {
                p_user->event_handler(event_low_to_high, event_high_to_low);
            }
        }
    }
}
Ejemplo n.º 2
0
uint32_t app_gpiote_input_event_handler_register(const uint8_t                    channel,
                                                 const uint32_t                   pin,
                                                 const uint32_t                   polarity,
                                                 app_gpiote_input_event_handler_t event_handler)
{
    (void)sense_level_toggle(NULL, pin);
    return NRF_ERROR_NOT_SUPPORTED;
}
Ejemplo n.º 3
0
/**@brief Function for handling the GPIOTE interrupt.
 */
void GPIOTE_IRQHandler(void)
{
	  xprintf("enter the f*****g INT\n");
    uint8_t  i;
    uint32_t pins_state = NRF_GPIO->IN;
    
		//INT_state = 1;
    // Clear event.
    NRF_GPIOTE->EVENTS_PORT = 0;
	  // gpiote_user_t * p_user = &mp_users[0];
	  //p_user->event_handler(12, 0);
   
    // Check all users.
    for (i = 0; i < m_user_count; i++)
    {
        gpiote_user_t * p_user = &mp_users[i];

        // Check if user is enabled.
        if (((1 << i) & m_enabled_users_mask) != 0)
        {
            uint32_t transition_pins;
            uint32_t event_low_to_high;
            uint32_t event_high_to_low;

            // Find set of pins on which there has been a transition.
            transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;

            // Toggle SENSE level for all pins that have changed state.
            sense_level_toggle(p_user, transition_pins);
            
            // Call user event handler if an event has occurred.
            event_high_to_low = (~pins_state & p_user->pins_high_to_low_mask) & transition_pins;
            event_low_to_high = (pins_state & p_user->pins_low_to_high_mask) & transition_pins;

            if ((event_low_to_high | event_high_to_low) != 0)
            {
                p_user->event_handler(event_low_to_high, event_high_to_low);
            }
        }
    }
}
Ejemplo n.º 4
0
/**@brief Function for handling the GPIOTE interrupt.
 */
void GPIOTE_IRQHandler(void)
{
    uint8_t  i;
    uint32_t pins_changed        = 1;
    uint32_t pins_sense_enabled  = 0;
    uint32_t pins_sense_disabled = 0;
    uint32_t pins_state          = NRF_GPIO->IN;

    // Clear event.
    NRF_GPIOTE->EVENTS_PORT = 0;

    while (pins_changed)
    {
        // Check all users.
        for (i = 0; i < m_user_count; i++)
        {
            gpiote_user_t * p_user = &mp_users[i];

            // Check if user is enabled.
            if (((1 << i) & m_enabled_users_mask) != 0)
            {
                uint32_t transition_pins;
                uint32_t event_low_to_high = 0;
                uint32_t event_high_to_low = 0;

                pins_sense_enabled |= (p_user->pins_mask & ~pins_sense_disabled);

                // Find set of pins on which there has been a transition.
                transition_pins = (pins_state ^ ~p_user->sense_high_pins) & (p_user->pins_mask & ~pins_sense_disabled);

                sense_level_disable(transition_pins);
                pins_sense_disabled |= transition_pins;
                pins_sense_enabled  &= ~pins_sense_disabled;

                // Call user event handler if an event has occurred.
                event_high_to_low |= (~pins_state & p_user->pins_high_to_low_mask) & transition_pins;
                event_low_to_high |= (pins_state & p_user->pins_low_to_high_mask) & transition_pins;

                if ((event_low_to_high | event_high_to_low) != 0)
                {
                    p_user->event_handler(event_low_to_high, event_high_to_low);
                }
            }
        }

        // Second read after setting sense.
        // Check if any pins with sense enabled have changed while serving this interrupt.
        pins_changed = (NRF_GPIO->IN ^ pins_state) & pins_sense_enabled;
        pins_state  ^= pins_changed;
    }

    // Now re-enabling sense on all pins that have sense disabled.
    // Note: a new interrupt might fire immediatly.
    for (i = 0; i < m_user_count; i++)
    {
        gpiote_user_t * p_user = &mp_users[i];

        // Check if user is enabled.
        if (((1 << i) & m_enabled_users_mask) != 0)
        {
            if (pins_sense_disabled & p_user->pins_mask)
            {
                sense_level_toggle(p_user, pins_sense_disabled & p_user->pins_mask);
            }
        }
    }
}