Better understanding of the system_soft_wdt_feed function
Better understanding of the system_soft_wdt_feed function
Postby kolban » Thu Sep 03, 2015 10:48 am
Neil
Re: Better understanding of the system_soft_wdt_feed function
Postby dkinzer » Thu Sep 03, 2015 2:07 pm
Beaverton, OR, USA
Re: Better understanding of the system_soft_wdt_feed function
Postby kolban » Thu Sep 03, 2015 7:56 pm
Are you suggesting that calling the "system_soft_wdt_feed" merely says to the watchdog "I know you are there ... don't worry ... I'll get back to you eventually ...." ... effectively subverting the purpose of the watchdog completely? I would hope that the "system_soft_wdt_feed()" is actually an SDK implementation of "yield()" that returns control to the SDK ... lets the SDK take care of ALL its housekeeping and then returns control back to where the "system_soft_wdt_feed()" was called.
Before bed last night, I wrote a test to see if this would work. I created a 30 second loop which would otherwise case a hard timer based reset and in that 30 second loop, every 10msecs called "system_soft_wdt_feed()". My experiment seemed to show NO timer based exception. However ... I haven't completed all my tests yet ... so the jury is still out.
Neil
Re: Better understanding of the system_soft_wdt_feed function
Postby dkinzer » Thu Sep 03, 2015 11:18 pm
Yes, I am. In just about the same way that poking a hardware watchdog does nothing more than reset its timer.kolban wrote:Are you suggesting that calling the "system_soft_wdt_feed" merely says to the watchdog "I know you are there ... don't worry ... I'll get back to you eventually ...."
I added system_soft_wdt_feed() to a test app and timed how long it took to execute. The result is 14 RTC TImer2 ticks (each tick being 200nS). That's not long enough to do much.
Then I took a look at the actual code. system_soft_wdt_feed() maps to pp_soft_wdt_feed() and the code for it is shown below. As you can see, it doesn't do much. It does store zero at address 3ffe8dc0 - probably the soft watchdog counter.
Code: Select all
40219a20: 000600
40219a23: 800460
...
40219a78: fe8dc0
40219a7b: 3f
...
40219a7c <pp_soft_wdt_feed>:
40219a7c: ffff51 l32r a5, 40219a78 <pp_soft_wdt_init+0x20>
40219a7f: 040c movi.n a4, 0
40219a81: 004542 s8i a4, a5, 0
40219a84: 73a022 movi a2, 115
40219a87: ffe631 l32r a3, 40219a20
40219a8a: 0020c0 memw
40219a8d: c56322 s32i a2, a3, 0x314
40219a90: f00d ret.n
Beaverton, OR, USA
Re: Better understanding of the system_soft_wdt_feed function
Postby dkinzer » Fri Sep 04, 2015 2:43 am
Beaverton, OR, USA
Re: Better understanding of the system_soft_wdt_feed function
Postby eriksl » Sat Sep 05, 2015 2:26 am
Re: Better understanding of the system_soft_wdt_feed function
Postby kolban » Sat Sep 05, 2015 12:09 pm
Code: Select all
while(connected == false) {
system_soft_wdt_feed();
}
I also registered an espconn_regist_connetcb() which, when called, sets the global variable "connected" to true. My thinking is that I would have achieved a logical "blocking" connect() call. Unfortunately, after the espconn_connect(), we enter the while loop but never exit as the connected callback doesn't appear to be invoked.
I had really hoped that calling system_soft_wdt_feed() would have given control back to the ESP controller to do its work and then return control to me after having processed what ever needed to be processed (such as TCP connections).
If all system_soft_wdt_feed() does is caused the watch dog timer not to fire ... I don't get its purpose. Why would we want to do that?
Neil
Re: Better understanding of the system_soft_wdt_feed function
Postby eriksl » Sat Sep 05, 2015 3:11 pm
kolban wrote:Code: Select all
while(connected == false) {
system_soft_wdt_feed();
}
This is the wrong approach. Don't mess with the watchdog.
At startup the user_init function is called. There do the necessary configuration that needs to be done there (actually very little, I don't know from the top of my head, probably none in your case). Also there register a callback for a init done callback and return.
In the "init done" callback setup your tcp listener, register a callback for incoming connections. Return.
In the "incoming connection" callback setup "data received" and "data sent" callbacks. Return.
Handle data via the two above callbacks. If at any point you need to do something lengthy (loops...), post a background task.
In the background task do "work" for a small amount of time (no endless loops!!!), if there is any work left, just post the background task again. Return.
It's all just like TCP on Windows, no blocking available nor allowed, everything is handled with callbacks.
The watchdog is not your enemy that you need to keep happy! If you do it right, you won't notice the watchdog!
Re: Better understanding of the system_soft_wdt_feed function
Postby kolban » Sat Sep 05, 2015 10:25 pm
Thanks for the information. Unfortunately, I am porting an application that runs on ARM and other embedded devices to the ESP8266. That application is almost 100% device independent but provides "plugins" or implement device specific areas. One of those is networking at the TCP level. The application expects me to implement a series of C language functions whose signature and contract is architected.
Among these are:
connect(IPAddr, port)
which, when called, is supposed to form a TCP connection to the target IPAddr and port and ... importantly, not return until either done or failed. Because IMMEDIATELY after returning from connect, there is a second contracted call which is:
send(data, length)
Which is meant to send data over the previous connection. It too is not meant to return until the data has been transmitted or has failed.
However, in the ESP8266 story, I figured I would implement "connect" with a call to espconn_connect(). However, that is an asynchronous call which does not block but instead later invokes a callback to describe the outcome of the connect. And here is where I get into trouble. Ideally I would like to the application's "connect()" call to block while I await the espconn_connect outcome. Since I can't block, I figured I would busy wait ... and ... while waiting ... somehow give the ESP8266 all the CPU time it needed by called system_soft_wdt_feed() ... because I "guessed" that the purpose of this was to feed kernel to let it do its stuff to handle WiFi and TCP.
In this story.... I have zero control over the application being ported ... in this story ... I need to "map" from the application "thinking" that it is making synchronous calls to the ESP8266 needing to make asynch calls.
Re: Better understanding of the system_soft_wdt_feed function
Postby dkinzer » Sat Sep 05, 2015 10:44 pm
It should only be used for a few unusual situations. One that I mentioned is erasing/writing Flash. Since both of these operations require a significant amount of time and you can't know how near the software WDT is to expiring you call system_soft_wdt_feed() just before you initiate those operations.kolban wrote:If all system_soft_wdt_feed() does is caused the watch dog timer not to fire ... I don't get its purpose.l
Beaverton, OR, USA
Who is online
Users browsing this forum: No registered users and 60 guests
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.