コード例 #1
0
ファイル: trickle.c プロジェクト: Manu58/bluenet
void trickle_rx_inconsistent(trickle_t* trickle)
{
    if (trickle->i_relative > g_i_min)
    {
        trickle_timer_reset(trickle);
    }
}
コード例 #2
0
/** Allocate a new data entry. Will take the least recently updated entry if all are allocated.
  Returns the index of the resulting entry. */
static uint16_t data_entry_allocate(void)
{
    static uint16_t allocated = 0;
    TICK_PIN(7);

    for (uint32_t i = allocated; i < RBC_MESH_DATA_CACHE_ENTRIES; ++i)
    {
        if (m_data_cache[i].p_packet == NULL)
        {
            trickle_timer_reset(&m_data_cache[i].trickle, 0);
            allocated++;
            return i;
        }
    }

    /* no unused entries, take the least recently updated (and disregard persistent handles) */
    uint32_t handle_index = m_handle_cache_tail;
    while (m_handle_cache[handle_index].data_entry == DATA_CACHE_ENTRY_INVALID ||
           m_handle_cache[handle_index].persistent)
    {
        HANDLE_CACHE_ITERATE_BACK(handle_index);

        if (handle_index == HANDLE_CACHE_ENTRY_INVALID)
        {
            return DATA_CACHE_ENTRY_INVALID;
        }
    }

    uint32_t data_index = m_handle_cache[handle_index].data_entry;
    APP_ERROR_CHECK_BOOL(data_index < RBC_MESH_DATA_CACHE_ENTRIES);

    /* cleanup */
    m_handle_cache[handle_index].data_entry = DATA_CACHE_ENTRY_INVALID;

    data_entry_free(&m_data_cache[data_index]);
    trickle_timer_reset(&m_data_cache[data_index].trickle, 0);
    return data_index;
}
コード例 #3
0
uint32_t handle_storage_info_set(uint16_t handle, handle_info_t* p_info)
{
    if (p_info == NULL)
    {
        return NRF_ERROR_NULL;
    }
    if (handle == RBC_MESH_INVALID_HANDLE)
    {
        return NRF_ERROR_INVALID_ADDR;
    }

    uint16_t handle_index = handle_entry_get(handle, true);
    if (handle_index == HANDLE_CACHE_ENTRY_INVALID)
    {
        /* couldn't find an existing entry, allocate one */
        handle_index = handle_entry_to_head(handle);
        if (handle_index == HANDLE_CACHE_ENTRY_INVALID)
        {
            return NRF_ERROR_NO_MEM;
        }
    }

    uint16_t data_index = m_handle_cache[handle_index].data_entry;

    if (data_index == DATA_CACHE_ENTRY_INVALID)
    {
        data_index = data_entry_allocate();
        if (data_index == DATA_CACHE_ENTRY_INVALID)
        {
            return NRF_ERROR_NO_MEM;
        }
        m_handle_cache[handle_index].data_entry = data_index;
    }
    trickle_timer_reset(&m_data_cache[data_index].trickle, timer_now());

    m_handle_cache[handle_index].version = p_info->version;
    if (m_data_cache[data_index].p_packet != NULL)
    {
        mesh_packet_ref_count_dec(m_data_cache[data_index].p_packet);
    }

    /* reference for the cache */
    mesh_packet_ref_count_inc(p_info->p_packet);
    m_data_cache[m_handle_cache[handle_index].data_entry].p_packet = p_info->p_packet;
    return NRF_SUCCESS;
}