<?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>Peripheral event handler tips</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55519/peripheral-event-handler-tips</link><description>Hi, 
 I am using nRF52 SDK v16 and I am wondering where one can find relevant information regarding peripheral event handlers. 
 Here are a few puzzles I have for now: 
 
 Are peripheral (e.g. timer device) event handlers running in a different thread</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 12 Dec 2019 09:04:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55519/peripheral-event-handler-tips" /><item><title>RE: Peripheral event handler tips</title><link>https://devzone.nordicsemi.com/thread/225087?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2019 09:04:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3015cec5-3967-424e-8aa5-fe1066caf0bf</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Yes, that is correct. In the SDK you will find the&amp;nbsp;&lt;a title="Schedule handling library" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/lib_scheduler.html?cp=6_1_3_39"&gt;Schedule handling library&lt;/a&gt;, which can be used to schedule tasks for later processing.&lt;/p&gt;
&lt;p&gt;You can also find a scheduler tutorial on &lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/scheduler-tutorial"&gt;this page&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peripheral event handler tips</title><link>https://devzone.nordicsemi.com/thread/225049?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2019 00:45:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0965f3ee-4278-48ec-bbce-509d9378c1d1</guid><dc:creator>yf13</dc:creator><description>&lt;p&gt;Thanks for the information.&lt;/p&gt;
&lt;p&gt;No I am not using any RTOS, I just use nRF SDK. So according to your explanation, these event handlers shall be mostly executed from the &amp;quot;interrupt&amp;quot; context.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The interrupt context bare the restrictions (of not blocking others for too long) thus should be finished as soon as possible. This means it is not proper place for extensive calculations. So maybe a typical pattern of such event handler is to queue up the data to another queue which the main context can pickup for handling? does the SDK have utility libraries proper for this scenario?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;yf13&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peripheral event handler tips</title><link>https://devzone.nordicsemi.com/thread/225038?ContentTypeID=1</link><pubDate>Wed, 11 Dec 2019 21:32:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4231fa3-ca09-47ac-9044-fa35e9721724</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m assuming that you are talking about the callback event handlers for the peripheral drivers in the SDK?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The handlers are mostly called from the IRQ_handler of the hardware peripheral and will run in the interrupt context.&amp;nbsp;Unless you are running an RTOS (FreeRTOS/Zephyr/etc), there is no threading in the nRF devices.&lt;/li&gt;
&lt;li&gt;You cannot call blocking APIs that run at a lower or equal interrupt priority. Since you are running in an interrupt context, all lower or equal priority events are blocked while you are in the handler. This is the reason that it is recommended to exit the handler as soon as possible. How long you can stay will depend on the application.&lt;/li&gt;
&lt;li&gt;The handlers will be called when there are relevant events to be passed to the application. This is very specific to each peripheral/driver. I would recommend that you check out the event type in the struct that is passed to the handler in most drivers. This will provide details on the relevant events you can expect.
&lt;ul&gt;
&lt;li&gt;You can typically set the priority for the driver when you initialize it. This is mainly done in the sdk_config.h file. Priority levels are documented in the &lt;a href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/processor_avail_interrupt_latency/exception_mgmt_sd.html?cp=4_5_2_0_15_1"&gt;softdevice specifications&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>