<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Watchdog feed while using blocking APIs</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/112637/watchdog-feed-while-using-blocking-apis</link><description>Hello, 
 Currently, I am working on a device that has multiple sensors connected with nRF53. Each sensor collects its own data in its thread. Some sensor threads are related to each other i.e. waiting to get a message from a peer sensor thread via ZBUS</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 29 Jul 2024 10:11:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/112637/watchdog-feed-while-using-blocking-apis" /><item><title>RE: Watchdog feed while using blocking APIs</title><link>https://devzone.nordicsemi.com/thread/495967?ContentTypeID=1</link><pubDate>Mon, 29 Jul 2024 10:11:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47bf8326-ec40-46b7-b84a-3ea965c68c09</guid><dc:creator>Ankit_chauhan</dc:creator><description>&lt;p&gt;Hi Charlie,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your reply.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Watchdog feed while using blocking APIs</title><link>https://devzone.nordicsemi.com/thread/495749?ContentTypeID=1</link><pubDate>Fri, 26 Jul 2024 07:46:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c0bedee-af86-4797-afd2-5e651056c33b</guid><dc:creator>Charlie</dc:creator><description>&lt;p&gt;Hi Ankit,&lt;/p&gt;
&lt;p&gt;Task watchdog is not directly maintained by Nordic, you can try to create an issue report here in its original Zephyr repository:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues/new?title=doc%3A%20Documentation%20issue%20in%20%27services/task_wdt/index%27&amp;amp;labels=area%3A%20Documentation,area:%20Task%20Watchdog&amp;amp;body=%2A%2ADescribe%20the%20bug%2A%2A%0A%0A%3C%3C%20Please%20describe%20the%20issue%20here%20%3E%3E%0A%3C%3C%20You%20may%20also%20want%20to%20update%20the%20automatically%20generated%20issue%20title%20above.%20%3E%3E%0A%0A%2A%2AEnvironment%2A%2A%0A%0A%2A%20Page%3A%20%60services/task_wdt/index%60%0A%2A%20Version%3A%20main%0A%2A%20SHA-1%3A%206fe0a373fc1ea78e3c752cb778bdae3067493a26%0A"&gt;New Issue · zephyrproject-rtos/zephyr (github.com)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.zephyrproject.org/latest/services/task_wdt/index.html"&gt;Task Watchdog — Zephyr Project Documentation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Charlie&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Watchdog feed while using blocking APIs</title><link>https://devzone.nordicsemi.com/thread/495213?ContentTypeID=1</link><pubDate>Tue, 23 Jul 2024 12:43:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:266194c1-6e96-4197-a0d1-e7395a3485e3</guid><dc:creator>Ankit_chauhan</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;In my last reply, as I mentioned I implemented the task watchdog for multi-thread application using the channel watchdog concept which allows me to set a distinct time in every watchdog channel. I have tested this approach and it is working as expected.&lt;/p&gt;
&lt;p&gt;However, I came across another issue with this approach. In task watchdog, I have defined a callback function that will be called in case of feed failure. Currently, I am not restarting the system, just indicating the system failure and continuing the operation.&lt;/p&gt;
&lt;p&gt;I am using the MCU boot to support the OTA using the nRF Connect App. When I performed the DFU, my sensor got restarted due to the watchdog (probably failed for feed). But the strange thing is that as I mentioned, I am not resetting the device when I am in task_watchdog callback function. Also from the logs, I can say that even the task watchdog callback is not even called. Below is my callback function snippet.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void task_wdt_callback(int channel_id, void *user_data)
{
	/*
	 * If the issue could be resolved, call task_wdt_feed(channel_id) here
	 * to continue operation.
	 *
	 * Otherwise we can perform some cleanup and reset the device.
	 */
	printk(&amp;quot;\n********************************************\n&amp;quot;);
	printk(&amp;quot;********************************************\n&amp;quot;);
	printk(&amp;quot;Task watchdog triggered with channel %d\n&amp;quot;, channel_id);
	
	task_wdt_feed(channel_id);

	printk(&amp;quot;Feeding the channel id : %d...\n&amp;quot;, channel_id);
	printk(&amp;quot;********************************************\n&amp;quot;);
	printk(&amp;quot;********************************************\n&amp;quot;);
	// sys_reboot(SYS_REBOOT_COLD);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Below is the error I got from the RTT logs,&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;00&amp;gt; I: Reset Reason, RESETREAS=0x2
00&amp;gt; I: Reset Causes: 
00&amp;gt; I:  Watchdog 0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I have checked the&amp;nbsp;task_wdt_init() which initializes the&amp;nbsp;wdt_timeout_cfg structure with flag value&amp;nbsp;WDT_FLAG_RESET_SOC. It has the option of&amp;nbsp;WDT_FLAG_RESET_NONE and I tried to change that flag but the&amp;nbsp;wdt_install_timeout() returns 134 which is a &amp;quot;not supported&amp;quot; error. I have also tried enabling the&amp;nbsp;CONFIG_WDT_DISABLE_AT_BOOT but it did not&amp;nbsp;help.&lt;/p&gt;
&lt;p&gt;So bottom of the line, I do not want to restart my system in case of watchdog failure, I can showcase the error via LED or other medium but the watchdog should not affect the OTA.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Ankit.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Watchdog feed while using blocking APIs</title><link>https://devzone.nordicsemi.com/thread/492069?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2024 12:46:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d881fa1-a3a7-4f36-a81f-ee31a679c44b</guid><dc:creator>Ankit_chauhan</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi&amp;nbsp;&lt;/span&gt;&lt;span&gt;Charlie,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for the update.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Sorry, I was using the Zephyr sample not the nRF SDK sample. Here is the link&amp;nbsp;&lt;a id="" href="https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/subsys/task_wdt"&gt;https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/subsys/task_wdt&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;For the second query for watchdog control in blocking API, I am thinking of controlling the watchdog start and stop in between the usage of those blocked threads.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My system is designed like that whenever the sensor sample collection is requested then only I am enabling the sensor threads otherwise all are in a suspended state. So I am planning to enable the task watchdog when the sensor threads are resumed. Similarly will stop the task watchdog when the threads are suspended using the &lt;strong&gt;task_wdt_add&lt;/strong&gt;&amp;nbsp;and &lt;strong&gt;task_wdt_delete&lt;/strong&gt;&amp;nbsp;APIs respectively.&lt;/p&gt;
&lt;p&gt;In between these states, even the threads which are having the blocking APIs will run repetitively. As you said I have calculated the time of a thread that stays blocking&amp;nbsp;and I have&amp;nbsp;set that time in the task watchdog time out and that should work.&lt;/p&gt;
&lt;p&gt;Let me try this approach and will let you know if I find any issues.&lt;/p&gt;
&lt;p&gt;Thanks once again for your support.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Ankit.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Watchdog feed while using blocking APIs</title><link>https://devzone.nordicsemi.com/thread/492057?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2024 12:10:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f381f20-374c-44ef-b69a-149705affc3f</guid><dc:creator>Charlie</dc:creator><description>&lt;p&gt;Hi Ankit,&lt;/p&gt;
&lt;p&gt;Thanks for the feedback. May I know which &amp;quot;&lt;span&gt;nRF SDK sample&amp;quot; you refer to? Do you mean&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/zephyr/samples/subsys/task_wdt/README.html"&gt;Task watchdog — Zephyr Project documentation (nRF Connect SDK) (nordicsemi.com)&lt;/a&gt;.&amp;nbsp;&lt;/span&gt;&lt;span&gt;To be honest, I do not have much experience about&amp;nbsp;Task Watchdog&lt;/span&gt;, it is one subsystem originally from Zephyr project. Good to hear it works as you expected, but I need to draw your attention that it used&amp;nbsp;&lt;span&gt;a kernel timer as its backend instead of a separate watchdog peripheral.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
[quote user="Ankit_chauhan"]However, I am unsure how to handle the other sensor threads that have the ZBUS and Semaphore blocking API with this approach.[/quote]
&lt;p&gt;When it comes to this question, have you evaluated what is the maximum time the thread could be blocking? As I shared before, this is critical for picking up the proper watchdog&amp;nbsp;&lt;span&gt;timeout to detect a real loop death, and it is related to your application logic about how to get and process sensor data.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Charlie&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Watchdog feed while using blocking APIs</title><link>https://devzone.nordicsemi.com/thread/491957?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2024 05:18:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:77e3cafd-567a-4e80-b217-22dee02679c4</guid><dc:creator>Ankit_chauhan</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Charlie,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for your reply.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;After spending some time finding the solution to this issue, I came across an nRF sample of &lt;strong&gt;task_wdt&amp;nbsp;&lt;/strong&gt;in the nRF SDK sample. I have implemented that into my application using the multi-channel watchdog concept where each channel is&amp;nbsp;configured with common&amp;nbsp;&lt;strong&gt;task_wdt_add&amp;nbsp;&lt;/strong&gt;API.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;On the main thread and a sensor thread, I am using &lt;strong&gt;task_wdt_feed&amp;nbsp;&lt;/strong&gt;which feeds the watchdog with the respective channel ID.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In some instances, I have seen that it is working because if I am not feeding either&amp;nbsp;thread with&amp;nbsp;&lt;strong&gt;task_wdt_feed&lt;/strong&gt;, the&amp;nbsp;&lt;strong&gt;task_wdt_callback&amp;nbsp;&lt;/strong&gt;will be called and&amp;nbsp;the system gets restarted with the channel ID of the thread which is expected.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;However, I am unsure how to handle the other sensor threads that have the ZBUS and Semaphore blocking API with this approach.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Ankit.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Watchdog feed while using blocking APIs</title><link>https://devzone.nordicsemi.com/thread/491880?ContentTypeID=1</link><pubDate>Tue, 02 Jul 2024 14:22:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e69abc8-abd1-4876-bc48-348772113561</guid><dc:creator>Charlie</dc:creator><description>&lt;p&gt;Hi Ankit,&lt;/p&gt;
&lt;p&gt;It would be better to have a main thread to run the app logic in a loop.&lt;/p&gt;
&lt;p&gt;If you have to use WDT in sensor threads or there is no main loop, you need to pick&amp;nbsp;up a proper watchdog triggering time for it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This will depend on your application, as sensor threads may block but only allow them to block for a period of time that your application can tolerate, otherwise the application will reset to restart.&lt;/p&gt;
&lt;p&gt;Let me know if you need more advice.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Charlie&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>