protect/unprotect is totally implementation dependent with only intention
of providing exclusive access to network related operation to be performed
without any context switching. You can do this by using a mutext in
simplest way but you have to make sure ISR do not do any operation either
when system is locked, this can be implemented with a complex
implementation but still possible. I have dealt with such system in past
where critical section APIs were not possible to use and only possible
option was to use a mutex.

lev may or may not be used which again depends on your implementation.

For your RTOS where nested critical section is not possible, you can
maintain a global variable (maybe) protected by mutex along with critical
section API which gets incremented with every call to protect, So only when
global counter is 1 you call enter_critical and with every nested call that
counter gets incremented and no further call to enter_ciritcal. On
the other hand when unprotect is called counter is decremented and when
it's 0 exit_critical is called. Now you can see in this case lev is kind of
unused or not required at all.

Disabling of context switch is the only requirement of lwip when it comes
to protect/unprotect. Implementation is upon the programmer depending on
system.

Regards,
Ajay Bhargav

On Mon, Nov 15, 2021, 8:24 PM Grant Edwards <grant.b.edwa...@gmail.com>
wrote:

> On 2021-11-15, Ajay Bhargav via lwip-users <lwip-users@nongnu.org> wrote:
>
> > sys_arch_protect() and sys_arch_unprotect() is always called in
> > pairs with call order maintained.
>
> So the requirement stated in the documentation that
>
>   SYS_ARCH_UNPROTECT Perform a "fast" set of the protection level to "lev".
>
> is incorrect and the parameter passed to sys_arch_unprotect() may be
> ignored.
>
> > From rtos prospective, you can consider sys_arch_protect() as
> > enter_critical_section() and sys_arch_unprotect() as
> > exit_critical_section().
>
> That's only true if enter_critical_section() and
> exit_critical_section() enforce nesting/paired calls.
>
> > These calls might already be provided by rtos you're using.
>
> They are, but they do not nest. In the uItron RTOS I'm using the "exit
> critical section" function re-enables context switching no matter how
> many times "enter critical section" has been called. I'm working on a
> nesting equivalent.
>
> Thanks much for the clarification.
>
> Once I'm satisfied I understand the real requirements, I'll submit a
> patch for the documentation. Hopefully that will avoid in the future
> the problems created when the original authors of my sys_arch.c code
> interpreted the existing documentation literally.
>
> --
> Grant
>
>
>
> _______________________________________________
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to