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

What does this particular "flag" do in the mesh example?

Hi, I've searched and googled through this site and made sure no one asked this question before.

In core\Bearer_event.c, there is this function:

bearer_event_flag_t bearer_event_flag_add(bearer_event_flag_callback_t callback)
{
NRF_MESH_ASSERT(callback != NULL);

/* Check if we can still fit flags in the pool. */
NRF_MESH_ASSERT(m_flag_count < BEARER_EVENT_FLAG_COUNT);

uint32_t was_masked;
_DISABLE_IRQS(was_masked);

uint32_t flag = m_flag_count++;
m_flag_event_callbacks[flag] = callback;

_ENABLE_IRQS(was_masked);

return flag;
}

and other places where a "flag" is used. What are these flags and what do they do? If there are many different types of flags, please just explain the type used in this scenario.

My guess is that the flag serves as some sort of handle or index, for example if I want to know how many events are in a queue waiting to be dealt with, I clearly don't need to (and shouldn't because that would be extremely slow) sift through the entire queue but instead, I just look at their corresponding flags.

Is my guess wrong? I personally would have given it the name "meta_handle" or "meta_data" instead of "flag", but "meta_anything" could risk duplicating with other variables thus causing confusion.

Parents
  • Hi Mitch,

    What exactly do you plan do to with the flags ?

    The flags used in our stack is kind of event flags. So a module can register an event handler and set a flag to trygger the event handler asynchronously. Something similar to this.

    We use it in several modules: scanner.c , flash_manager.c

    The flags have been set will be executed inside handle_events() in bearer_event.c one by one.

  • Thanks Hung. Although not 100%, I think I know what it does.

    You have a series of events that comes with 2 critical components (among other components): one of them is callbacks (of course), which will perform specific tasks based on the nature of the event.

    Another critical component is flag. This flag will be set to a specific value to decide whether its corresponding event will be executed or when and how etc. it will be executed.

    In other words, sometimes an event has been added, but we do not want to respond to it immediately, we look at its flag to decide what to do with it.

    Is that how it works?

    I'm not planning on doing anything about it hehe, I just want to know exactly how it works.

Reply
  • Thanks Hung. Although not 100%, I think I know what it does.

    You have a series of events that comes with 2 critical components (among other components): one of them is callbacks (of course), which will perform specific tasks based on the nature of the event.

    Another critical component is flag. This flag will be set to a specific value to decide whether its corresponding event will be executed or when and how etc. it will be executed.

    In other words, sometimes an event has been added, but we do not want to respond to it immediately, we look at its flag to decide what to do with it.

    Is that how it works?

    I'm not planning on doing anything about it hehe, I just want to know exactly how it works.

Children
No Data
Related