NordicPlayground / nRF51-ble-bcast-mesh

Other
323 stars 121 forks source link

Erasing old mesh packets to make space for new ones? #164

Open bayou9 opened 7 years ago

bayou9 commented 7 years ago

When testing mesh nodes, I ran into a problem, app_error_looped, if you will, and the function that caused the program to enter app error loop is mesh_packet_acquire, code as follows:

bool mesh_packet_acquire(mesh_packet_t** pp_packet)
{
       uint32_t was_masked;
    for (uint32_t i = 0; i < RBC_MESH_PACKET_POOL_SIZE; ++i)
    {
        _DISABLE_IRQS(was_masked);
        if (g_packet_refs[i] == 0) /* no refs, free to use */
        {                        //This is how things work:loop through all packet refs to see if it's 
            g_packet_refs[i] = 1;//a 0. If it is, then set it to 1, meaning it's claimed.
        *pp_packet = &g_packet_pool[i];//now that above steps had acquired the proper, free index number i, we can allocate a pointer to point at it.
        _ENABLE_IRQS(was_masked);
        return true;
    }
    _ENABLE_IRQS(was_masked);
}
APP_ERROR_CHECK(NRF_ERROR_NO_MEM);
return false;
}

And it was APP_ERROR_CHECK(NRF_ERROR_NO_MEM); that invoked the error loop.

Apparently, I ran out of mesh packets, or, in other words, exceeded the limit of RBC_MESH_PACKET_POOL_SIZE.

Now I have 2 questions:

  1. Can I arbitrarily modify RBC_MESH_PACKET_POOL_SIZE? For example, since its macro definition is:

    define RBC_MESH_PACKET_POOL_SIZE (RBC_MESH_DATA_CACHE_ENTRIES +\

                                                 RBC_MESH_APP_EVENT_QUEUE_LENGTH + \
                                                 RBC_MESH_RADIO_QUEUE_LENGTH + \
                                                 RBC_MESH_INTERNAL_EVENT_QUEUE_LENGTH +\
                                                 3)

I'll simply put a "30" or "60" if I want instead of "3" at the end?

  1. What is the SAFEST way to erase old mesh packet so room can be made for the new ones? I don't want to simply free them and cause unpredictable behavior.

Please help, Many thanks!

trond-snekvik commented 7 years ago
  1. Yes, but keep it at least at its current size, or you'll get NO_MEMs on allocation. Manipulating the 3 is the best way of doing this :)

  2. The mesh packets will be freed as they disappear from the data cache (in a "least recently used" order). There's no way of explicitly deleting a packet from the cache. See #103.