<?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>How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82412/how-to-become-notified-of-bsd-non-blocking-events</link><description>Hi there, 
 I&amp;#39;m intending to use the nrfxlib modem library and its BSD socket implementation on the nRF9160. My goal is to use non-blocking APIs and use `nrf_poll` in response to various events. 
 For example, I&amp;#39;d like to use `nrf_recv` (1) with ` NRF_O_NONBLOCK</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Dec 2021 22:39:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82412/how-to-become-notified-of-bsd-non-blocking-events" /><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342795?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 22:39:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:884e9d84-b4a9-43cf-a20d-36deb52f02d9</guid><dc:creator>Christopher Hunt</dc:creator><description>[quote userid="2115" url="~/f/nordic-q-a/82412/how-to-become-notified-of-bsd-non-blocking-events/342781#342781"]&lt;p&gt;It is closed source, atleast for the time being. I&amp;#39;ll input this internally as a feature request.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;That would be greatly appreciated. Please let me know if there is anything I can do to help support such an initiative.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342781?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 17:00:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:404a964b-18b1-44c4-8b0d-12aeec9b5b9f</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Christopher Hunt"]nrf_poll should work for multiple sockets though...[/quote]
&lt;p&gt;Yes, but if you have multiple poll() functions&amp;nbsp;across different modules, it might be problematic.&lt;/p&gt;
[quote user="Christopher Hunt"]&lt;p&gt;This is for use from the&amp;nbsp;&lt;a href="https://github.com/embassy-rs/embassy"&gt;https://github.com/embassy-rs/embassy&lt;/a&gt;&amp;nbsp;framework using Rust.&lt;/p&gt;
&lt;p&gt;Further to my questions here, is there any possibility that Nordic could open source the modem library and document the hardware interface of the modem? Thanks again.&lt;/p&gt;[/quote]
&lt;p&gt;It is closed source, atleast for the time being. I&amp;#39;ll input this internally as a feature request.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342614?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 01:23:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae09cac5-14d0-4a94-9296-ff733d825d38</guid><dc:creator>Christopher Hunt</dc:creator><description>[quote userid="2115" url="~/f/nordic-q-a/82412/how-to-become-notified-of-bsd-non-blocking-events/342510#342510"]&lt;p&gt;It is not that simple, unfortunately, as this event is used for all events coming from the modem. See the message sequences here for more details:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;I&amp;#39;m ok with that though... I&amp;#39;m just looking for an event that provides a reasonable excuse to call nrf_poll with a 0 timeout to find out about what, if anything, happened.&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/82412/how-to-become-notified-of-bsd-non-blocking-events/342510#342510"]&lt;p&gt;I am unable to give a definite answer on your scenario in question, as its not a scenario that&amp;nbsp;we&amp;#39;ve tested directly. What you&amp;#39;re suggesting might work for a single-socket application, but&amp;nbsp;I fear is problematic&amp;nbsp;for multiple sockets scenario.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;nrf_poll should work for multiple sockets though...&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/82412/how-to-become-notified-of-bsd-non-blocking-events/342510#342510"]&lt;p&gt;Which platform/language are you porting to?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;This is for use from the&amp;nbsp;&lt;a href="https://github.com/embassy-rs/embassy"&gt;https://github.com/embassy-rs/embassy&lt;/a&gt;&amp;nbsp;framework using Rust.&lt;/p&gt;
&lt;p&gt;Further to my questions here, is there any possibility that Nordic could open source the modem library and document the hardware interface of the modem? Thanks again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342510?ContentTypeID=1</link><pubDate>Wed, 08 Dec 2021 10:22:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e8682e9b-6bdf-4f6c-ab23-c13d1d49dadf</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is not that simple, unfortunately, as this event is used for all events coming from the modem. See the message sequences here for more details:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/nrf_modem/doc/ug_nrf_modem_porting_os.html#id4"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/nrf_modem/doc/ug_nrf_modem_porting_os.html#id4&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I am unable to give a definite answer on your scenario in question, as its not a scenario that&amp;nbsp;we&amp;#39;ve tested directly. What you&amp;#39;re suggesting might work for a single-socket application, but&amp;nbsp;I fear is problematic&amp;nbsp;for multiple sockets scenario.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Which platform/language are you porting to?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342503?ContentTypeID=1</link><pubDate>Wed, 08 Dec 2021 10:02:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:48ae8f2b-906f-4586-9ba9-c00f05faa558</guid><dc:creator>Christopher Hunt</dc:creator><description>[quote userid="2115" url="~/f/nordic-q-a/82412/how-to-become-notified-of-bsd-non-blocking-events/342484#342484"]&lt;p&gt;This is the interrupt that wakes up the threads if anything has happened:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.7.1/lib/nrf_modem_lib/nrf_modem_os.c#L437-L453"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v1.7.1/lib/nrf_modem_lib/nrf_modem_os.c#L437-L453&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Ah ha - so following that lead, I discover this in the nrf_modem_platform.h file:&lt;/p&gt;
&lt;p&gt;/**@brief Interrupt used for communication with the application layer. */&lt;br /&gt;#define NRF_MODEM_APPLICATION_IRQ EGU1_IRQn&lt;/p&gt;
&lt;p&gt;...so I should be able to subscribe to trigger events on EGU1 and then ultimately call nrf_poll as a consequence.&lt;/p&gt;
&lt;p&gt;Please let me know if I&amp;#39;m on track, and again thanks for your help so far.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342484?ContentTypeID=1</link><pubDate>Wed, 08 Dec 2021 08:58:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3e59cdc-269a-45c9-8633-3ec7f81c17b3</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Christopher Hunt"]My app has other peripherals to service and not just the modem and so I can&amp;#39;t block on the latter. I was looking for an interrupt or event that I can hook onto&amp;nbsp;indicating that &amp;quot;something&amp;quot; has happened re. the modem worthy of a subsequent call to nrf_poll. I&amp;#39;m unsure how `&lt;span&gt;nrf_modem_os_timedwait` achieves this as it must be something called indirectly from the main loop of my program. I suspect that subscribing to the IPC events might be sufficient. Thanks for any confirmation and apologies if I&amp;#39;m still not yet understanding something.&lt;/span&gt;[/quote]
&lt;p&gt;You are free to implement the nrf_modem_os_timedwait() in any way you&amp;#39;d like, including wrapping it around your applications sleep/event based system.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is the interrupt that wakes up the threads if anything has happened:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.7.1/lib/nrf_modem_lib/nrf_modem_os.c#L437-L453"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v1.7.1/lib/nrf_modem_lib/nrf_modem_os.c#L437-L453&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;here is a reference/template implementation of the file for porting into other systems:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/nrf_modem/doc/ug_nrf_modem_porting_os.html#reference-template-for-the-nrf-modem-os-c-file"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/nrf_modem/doc/ug_nrf_modem_porting_os.html#reference-template-for-the-nrf-modem-os-c-file&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342438?ContentTypeID=1</link><pubDate>Tue, 07 Dec 2021 22:36:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c428b96d-8b57-4e96-a4a7-fa180ea24d98</guid><dc:creator>Christopher Hunt</dc:creator><description>[quote userid="2115" url="~/f/nordic-q-a/82412/how-to-become-notified-of-bsd-non-blocking-events/342263#342263"]&lt;p&gt;You&amp;#39;re halfway right in the understanding of the function, its main purpose is to sleep for a timeout-period or until something happens on that specific socket. Think of it as an event based system.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;My app has other peripherals to service and not just the modem and so I can&amp;#39;t block on the latter. I was looking for an interrupt or event that I can hook onto&amp;nbsp;indicating that &amp;quot;something&amp;quot; has happened re. the modem worthy of a subsequent call to nrf_poll. I&amp;#39;m unsure how `&lt;span&gt;nrf_modem_os_timedwait` achieves this as it must be something called indirectly from the main loop of my program. I suspect that subscribing to the IPC events might be sufficient. Thanks for any confirmation and apologies if I&amp;#39;m still not yet understanding something.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342263?ContentTypeID=1</link><pubDate>Tue, 07 Dec 2021 09:01:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84d469d6-e4b2-4d91-b5d5-c318a45dacdc</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you looked at this page in the docs?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/nrf_modem/doc/ug_nrf_modem_porting_os.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/nrf_modem/doc/ug_nrf_modem_porting_os.html#&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Christopher Hunt"]However, it appears that the purpose of this callback is to sleep. I don&amp;#39;t want to do that. :-) I want my program to call poll if it is likely that there has been some socket activity. Apologies if I&amp;#39;m being unclear. I appreciate your replies.[/quote]
&lt;p&gt;No apologies necessary, I&amp;#39;m equal to blame for misunderstanding!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You&amp;#39;re halfway right in the understanding of the function, its main purpose is to sleep for a timeout-period or until something happens on that specific socket. Think of it as an event based system.&lt;/p&gt;
&lt;p&gt;The specific function takes a semaphore/mutex, with a timeout provided by the socket call, and if an event occurs before the timeout, it will give the sem/mutex and return an event to the application.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342244?ContentTypeID=1</link><pubDate>Tue, 07 Dec 2021 08:07:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a6f5f49-3c9d-4525-a906-62297b602844</guid><dc:creator>Christopher Hunt</dc:creator><description>[quote userid="2115" url="~/f/nordic-q-a/82412/how-to-become-notified-of-bsd-non-blocking-events/342240#342240"]&lt;p&gt;Triggering of a hw event indicates that something has happened, it does not indicate what. This comes by parsing the data, which is done in the &amp;quot;libmodem&amp;quot;, which then exposes a given API towards your application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Yes, understood. I&amp;#39;m happy to call poll often even if the peripheral event is only a hint toward poll needing to be called.&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/82412/how-to-become-notified-of-bsd-non-blocking-events/342240#342240"]&lt;p&gt;This is the callback that is triggered when one (or more) events have occurred on a socket:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;I should explain that I&amp;#39;m not using Zephyr. However, it appears that the purpose of this callback is to sleep. I don&amp;#39;t want to do that. :-) I want my program to call poll if it is likely that there has been some socket activity. Apologies if I&amp;#39;m being unclear. I appreciate your replies.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342240?ContentTypeID=1</link><pubDate>Tue, 07 Dec 2021 07:47:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e56b6539-c59e-4e88-b2c7-9a2b2ed71154</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user="Christopher Hunt"]What I’m actually trying to understand is what peripheral events occur when there is data available so that I should then poll.[/quote]
&lt;p&gt;Triggering of a hw event indicates that something has happened, it does not indicate what. This comes by parsing the data, which is done in the &amp;quot;libmodem&amp;quot;, which then exposes a given API towards your application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is the callback that is triggered when one (or more) events have occurred on a socket:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.7.1/lib/nrf_modem_lib/nrf_modem_os.c#L198"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v1.7.1/lib/nrf_modem_lib/nrf_modem_os.c#L198&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Which then tells the socket operation, poll() for instance, that a event is returned.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342169?ContentTypeID=1</link><pubDate>Mon, 06 Dec 2021 18:27:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f329c60-d6f8-4db7-b22e-90c9ed4cc9a4</guid><dc:creator>Christopher Hunt</dc:creator><description>&lt;p&gt;Thanks for the reply. What I&amp;rsquo;m actually trying to understand is what peripheral events occur when there is data available so that I should then poll. I&amp;rsquo;m wondering if connecting the IPC RECEIVE event is sufficient.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to become notified of BSD non-blocking events</title><link>https://devzone.nordicsemi.com/thread/342001?ContentTypeID=1</link><pubDate>Mon, 06 Dec 2021 09:09:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95f1436b-824f-43ee-8138-72de9bdf10bf</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]&lt;p&gt;I&amp;#39;m intending to use the nrfxlib modem library and its BSD socket implementation on the nRF9160. My goal is to use non-blocking APIs and use `nrf_poll` in response to various events.&lt;/p&gt;
&lt;p&gt;For example, I&amp;#39;d like to use `nrf_recv` (1) with `&lt;span&gt;NRF_O_NONBLOCK` and then receive a notification when there is data available given&amp;nbsp;its respective file descriptor. To achieve this, I&amp;#39;m wondering if I can connect an IPC RECEIVE event&amp;nbsp;with&amp;nbsp;all IPC channels, which&amp;#39;d see that `nrf_poll` is then called by my code.&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;You can use poll() for this use case, and then check the revents if there&amp;#39;s data available for you. mqtt and coap samples sets this up in the main loop:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.8.0-rc2/samples/nrf9160/coap_client/src/main.c#L246-L274"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v1.8.0-rc2/samples/nrf9160/coap_client/src/main.c#L246-L274&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.8.0-rc2/samples/nrf9160/mqtt_simple/src/main.c#L600"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v1.8.0-rc2/samples/nrf9160/mqtt_simple/src/main.c#L600&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>