This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

channel_port_alloc function

I'm going through pin_change_int example and can't understand how we tell controller where locate the function for our event. Probably it occures in channel_port_alloc that locate inside nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler); but where we point the function pointer... it seems we just fill out m_cb structure

static int8_t channel_port_alloc(uint32_t pin,nrf_drv_gpiote_evt_handler_t handler, bool channel)
{
    int8_t channel_id = NO_CHANNELS;
    uint32_t i;

    uint32_t start_idx = channel ? 0 : GPIOTE_CH_NUM; //(0, 8)
    uint32_t end_idx = channel ? GPIOTE_CH_NUM : (GPIOTE_CH_NUM + GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS);// (8, 9)
    //critical section
	 
    for (i = start_idx; i < end_idx; i++)
    {
        if (m_cb.handlers[i] == FORBIDDEN_HANDLER_ADDRESS)
        {
            pin_in_use_by_te_set(pin, i, handler, channel);
            channel_id = i;
            break;
        }
    }
    //critical section
    return channel_id;
}



_STATIC_INLINE void pin_in_use_by_te_set(uint32_t pin,
                                          uint32_t channel_id,
                                          nrf_drv_gpiote_evt_handler_t handler,
                                          bool is_channel)
{
    m_cb.pin_assignments[pin] = channel_id;
    m_cb.handlers[channel_id] = handler;
    if (!is_channel)
    {
        m_cb.port_handlers_pins[channel_id - GPIOTE_CH_NUM] = (int8_t)pin;
    }
}
Parents
  • I don't understand the problem here. You pass the handler in the nrf_drv_gpiote_in_init(..) function and then the gpiote module knows that this should be called when the pin changes. No need to worry about the channel_port_alloc() function. The m_cb (cb stands for "control block" and "m" just says that it is a local variable in the file) is just a local variable used within the gpiote driver.

Reply
  • I don't understand the problem here. You pass the handler in the nrf_drv_gpiote_in_init(..) function and then the gpiote module knows that this should be called when the pin changes. No need to worry about the channel_port_alloc() function. The m_cb (cb stands for "control block" and "m" just says that it is a local variable in the file) is just a local variable used within the gpiote driver.

Children
No Data
Related