Re: prioritizing of active connections

Norbert,

The Cortex-M CPU that you are using has architectural features that can
solve your problem.

The trick is to install a SVC handler, and use that to call lwIP.      If
the SVC handler has the same IRQ priority as the ethernet interrupt, the
interrupt controller will enforce exclusive access to the lwIP stack.
Then you wrap the lwIP functions that you need in system calls, and it will
all just work.   The only place where things get complicated is getting
data out of lwIP structures in an interrupt-safe method.   That may not be
an issue in your case, or you can just use system calls when accessing lwIP
structures.

Keep in mind that you cannot use these system calls from interrupt context,
only the lower-priority worker tasks that you describe.

Here's a sample syscall handler: svchandler.S
<https://github.com/rbsexton/sockpuppet/blob/master/sapi/svchandler.S>
 with a few sample lwIP calls at the bottom.

If you don't want to resort to compiler trickery, you will have to define
some simple assembly functions to serve as the stand-ins for the final lwIP
functions:

Declaration:
extern err_t SAPI_tcp_write(struct tcp_pcb * pcb, void *,uint16_t len,
uint8_t flags);

systemcalls.S:
....
.global SAPI_tcp_write
SAPI_tcp_write:
svc #22
bx lr
....

The latter function could also be done with a compiler inline.

You can use this technique to safely access any lwIP function from main().

- Robert






On Sat, Sep 24, 2016 at 9:01 AM <[email protected]> wrote:

> Send lwip-users mailing list submissions to
>         [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://lists.nongnu.org/mailman/listinfo/lwip-users
> or, via email, send a message with subject or body 'help' to
>         [email protected]
>
> You can reach the person managing the list at
>         [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of lwip-users digest..."
>
>
> Today's Topics:
>
>    1. Re: prioritizing of active connections (Noam Weissman)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 24 Sep 2016 12:58:10 +0000
> From: Noam Weissman <[email protected]>
> To: "[email protected]" <[email protected]>
> Subject: Re: [lwip-users] prioritizing of active connections
> Message-ID:
>         <
> db6pr0902mb17038622a45c15ff324ec26cd8...@db6pr0902mb1703.eurprd09.prod.outlook.com
> >
>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
>
> Doing some "dirty" trick will not help but cause other problems. IwIP can
> back-fire and
>
> you will get unpredictable results. Problems that can be difficult to find.
>
>
> sys_timeout is an LwIP function that runs inside the context of LwIP. Time
> interval is in milliseconds.
>
>
> That means that if you set it to 100ms it will call your function (only
> once) when time elapses.
>
>
> So instead of using the poll call back that is triggered at best every 0.5
> seconds ... you can set your
>
> own timeout function that will handle some house keeping at a faster rate.
> Do remember that if you
>
> need it to periodically do something you need to set it again and again...
> until you finish the process.
>
>
> BR,
>
> Noam.
>
>
> ________________________________
> From: lwip-users <[email protected]> on behalf
> of Norbert Kleber <[email protected]>
> Sent: Saturday, September 24, 2016 11:20 AM
> To: [email protected]
> Subject: Re: [lwip-users] prioritizing of active connections
>
>
> Hi Noam,
>
>
> thank you for your suggestion. I guess I will start with an OS for the
> next project. For this one it's allready to late I am afraid (thesis due
> date next month). I didn't fully understand the explanation in the wiki
> regarding the sys_timeout(TMR_INTERVAL, function , NULL); function. Which
> timer triggers this function and how can i calculate the exact timing of
> the sys_timeout?
>
> For now i found an quick and dirty approach which i can't recommand to
> anyone. I just call 2x tcp_tmr() directly after my computing work is done.
> This improves my performance. Where i needed 36 seconds for one run I now
> only need 16 seconds.
>
>
> sincerly,
>
> Norbert
>
> Am 23.09.2016 um 18:30 schrieb Noam Weissman:
>
> Hi Norbert,
>
>
> First of all I would suggest changing your design and use an OS. I am
> running FreeRTOS
>
> on STM micro's for 6 years now and I do not see myself doing it any other
> way.
>
>
> The STM32F4 is a strong micro with sufficient power to do much more then
> you do now.
>
>
> If you run an OS there will be a small overhead but your system design
> will be much simpler
>
> to menage.
>
>
> If you use Socket API you can send data outside of the LwIP context. If
> you use RAW API
>
> you cannot send data from outside of the LwIP context and must take that
> into consideration:
>
>
> First option protect the code that is called from outside of the LwIP
> context. Either by using a
>
> critical section (OS).... or using the poll call back.... or triggering
> LwIP own system_timer call-back:
>
>
>     sys_timeout(TMR_INTERVAL, function , NULL);
>
>
> The above is an LwIP internal timer handling. You pass the function you
> want (see prototype)
>
> with or without parameters and it will be triggered when time expires.
>
>
>
> BR,
>
> Noam.
>
> ________________________________
> From: lwip-users <[email protected]><mailto:
> [email protected]> on behalf of Norbert Kleber
> <[email protected]><mailto:
> [email protected]>
> Sent: Friday, September 23, 2016 6:58 PM
> To: [email protected]<mailto:[email protected]>
> Subject: [lwip-users] prioritizing of active connections
>
> Hi evereyone,
>
> I got some questions again.
>
> I am using the lwIP on a STM32F4 mikrocontroller without OS. A client
> will connect to the stack at two ports for transmission. First port will
> be used for controlsignals and second for datatransmission. The whole
> System works sequentially.
>
> Firstly 1 package will be received on the ctrl connection afterwards we
> receive many packages on the dataconnection. Now I was wondering that
> the stack acknowlegded all data packages before he acknowledges the ctrl
> package. Due to the operation of the ?C I can tell that he received the
> package right away and ofcause i use the acknowledgement function in the
> receive function.  But somehow it is severly delayed approx. 200ms but
> the later received data packages all get acknowledged right away.
>
> Does the stack some prioritizing between open connections? Or is it due
> to the Ctrl Package being quite short?
>
> Also I am doing some computational work outside of the callback
> functions and want to transmit some of the results asap over the ctrl
> connection. Is there a way to do that without waiting for the polling
> function? Or is there a way to trigger the polling function somehow for
> a instant call? Also it seemed like i can't use tcp_write if i am
> outside of a callback function (i was storing the pointer to the pcb in
> a global variable).
>
> sincerly,
>
> Norbert
>
>
> _______________________________________________
> lwip-users mailing list
> [email protected]<mailto:[email protected]>
> https://lists.nongnu.org/mailman/listinfo/lwip-users
> lwip-users -- Mailing list for lwIP users - lists.nongnu.org<
> https://lists.nongnu.org/mailman/listinfo/lwip-users>
> lists.nongnu.org
> Welcome to the lwip-users mailing list. Use it to ask questions, share
> your experience and discuss new ideas. To see the collection of prior
> postings to the list ...
>
>
>
>
>
> _______________________________________________
> lwip-users mailing list
> [email protected]<mailto:[email protected]>
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://lists.nongnu.org/archive/html/lwip-users/attachments/20160924/f8a4573d/attachment.html
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> lwip-users mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
> ------------------------------
>
> End of lwip-users Digest, Vol 157, Issue 27
> *******************************************
>
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to