<?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>SDK app scheduler</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/7105/sdk-app-scheduler</link><description>Hello all, 
 I&amp;#39;m looking at the example projects and ble_app_template in particular, and have noticed something that doesn&amp;#39;t seem to make sense... 
 In main(), this project sets up the scheduler module, and then loops calling app_sched_execute(), so</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 11 Apr 2016 10:03:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/7105/sdk-app-scheduler" /><item><title>RE: SDK app scheduler</title><link>https://devzone.nordicsemi.com/thread/25102?ContentTypeID=1</link><pubDate>Mon, 11 Apr 2016 10:03:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2171a7e-6432-4231-90d1-11675685fab7</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Chadrick,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For the first, SW will be having higher priority as scheduler is designed to pull out requests from queue in main context (lowest priority context as compared to SW where the priority is programmable and can cause problems). That said, most of the designs should work well using SW interrupt in low priority rather than using scheduler. It could even be preferable this way as it will save us all software latency.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Other benefit is when you are running short of SWI contexts.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK app scheduler</title><link>https://devzone.nordicsemi.com/thread/25103?ContentTypeID=1</link><pubDate>Fri, 08 Apr 2016 09:06:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a628284e-771e-4904-a54f-812c373f85f3</guid><dc:creator>chadrick</dc:creator><description>&lt;p&gt;what is the benefit of using a scheduler instead of SW interrupt?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK app scheduler</title><link>https://devzone.nordicsemi.com/thread/25101?ContentTypeID=1</link><pubDate>Tue, 26 May 2015 06:43:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3218dc3-10df-46bd-be47-3ed0f596f9a6</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;sorry, my bad, just sent softdevice_evt_schedule as the handler and it will work. I will edit my answer to match this
There is another macro where you can use bool &lt;code&gt;SOFTDEVICE_HANDLER_APPSH_INIT&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK app scheduler</title><link>https://devzone.nordicsemi.com/thread/25100?ContentTypeID=1</link><pubDate>Mon, 25 May 2015 23:44:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:115aaf76-81ba-48fa-8930-70e6f96ea582</guid><dc:creator>Seth</dc:creator><description>&lt;p&gt;You said that if you want to receive both events in the scheduler, you need to pass &amp;quot;true&amp;quot; as the second argument in SOFTDEVICE_HANDLER_INIT, but as of softdevice 8.1.0, the second argument to that macro is not a boolean, but a pointer to a handler. I&amp;#39;m trying to figure out what handler I should be passing to use the scheduler. The documentation says &amp;quot; Point to ble_ant_stack_evt_schedule() to connect to the scheduler.&amp;quot; But I&amp;#39;m not using ant, just BLES110. Can you explain how to handle softdevice events in the scheduler given this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK app scheduler</title><link>https://devzone.nordicsemi.com/thread/25099?ContentTypeID=1</link><pubDate>Thu, 21 May 2015 09:07:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9eeb846-1885-4095-a53d-803b2dc8b10e</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Yes, BLE and SYS events. :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK app scheduler</title><link>https://devzone.nordicsemi.com/thread/25098?ContentTypeID=1</link><pubDate>Tue, 19 May 2015 08:21:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27c7025d-ec65-4820-beb6-2a8811905212</guid><dc:creator>Richard Phillips</dc:creator><description>&lt;p&gt;When you say &amp;quot;both events&amp;quot;, I presume you mean BLE and SYS events...  many thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK app scheduler</title><link>https://devzone.nordicsemi.com/thread/25097?ContentTypeID=1</link><pubDate>Mon, 18 May 2015 17:10:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8da8dee-c09f-42a6-9ad9-80fbfb32e153</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;scheduler is a very simple concept.  You just postpone some execution of a function from highter priority context to lower priority context. It is known that interrupt handlers need to be fast and short so that reset of the interrupt are not masked too long. So if you want to postpone some non urgent processing from higher priority interrupt to a lower priority interrupt (or main) you just put that request in a queue by calling below&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;app_sched_event_put  
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This takes the event, its size and a &lt;code&gt;third argument&lt;/code&gt; which the handler (which will be called at time of deque)
In lower priority context or main, you see if there is anything queued, by executing &lt;code&gt;app_sched_execute&lt;/code&gt; in a endless loop.
When this function finds something in the queue, it calls the handler you gave as argument to function while queuing it. This handler unpacks the first two arguments. These two can contain anything, events, handlers, function pointer or ANYTHING you can imagine that needs execution. This way we have transfered the exection from some higher priority context to lower priority context( or to any other context that has app_sched_execute in a loop)&lt;/p&gt;
&lt;p&gt;APP_TIMERS and SOFTDEVICE modules are using this concept to transfer their execution to main context. They do this by making the &lt;code&gt;third argument&lt;/code&gt;, smart enough to unpack data and call the handlers within the unpacked data.
I really hope i have not confused you more.
Last but not the least, if you want receive both the events in the scheduler then just pass &lt;code&gt;softdevice_evt_schedule&lt;/code&gt; to the second argument in SOFTDEVICE_HANDLER_INIT and it is done. Both events are queued to run in main context.&lt;/p&gt;
&lt;p&gt;example of how you can make your put and get functions&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;initialize the scheduler with enough buffer to hold events that needed to be pulled from different thread (or ISR context).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;make a struct that could hold information that needs to be passed&lt;/p&gt;
&lt;p&gt;typedef struct
{
type1 data1;
type2 data2;
type3 * pointer1;
type4 * callback_function(type1 data1, type2 data2, type3 * pointer1);&lt;br /&gt;
} some_struct_t;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;make a function that wraps the data and pushes it into scheduler queue.&lt;/p&gt;
&lt;p&gt;static inline uint32_t app_module_evt_schedule(type4 * callback_handler,
type1 d1, type2 d2, type3 *p1);
{
some_struct_t push_event;
push_event.callback_function = callback_handler;
push_event.data1 = d1;
push_event.data2 = d2;
push_event.pointer1 = p1;&lt;/p&gt;
&lt;p&gt;return app_sched_event_put((void *)&amp;amp;push_event, sizeof(push_event), pull_event_function);&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;What you have done now is that you made some function that wraps your data and callback function in one struct and asked the scheduler to put it in the queue. You also gave it a function that is smart enough to unwrap this struct and call the callback.&lt;/p&gt;
&lt;ol start="4"&gt;
&lt;li&gt;
&lt;p&gt;make the pull_event_function&lt;/p&gt;
&lt;p&gt;static inline void pull_event_function(void * p_event_data, uint16_t event_size)
{
some_struct_t *p_some_struct = (some_struct_t *)p_event_data;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ASSERT(event_size == sizeof(some_struct_t));
 p_some_struct-&amp;gt;callback_function(p_some_struct-&amp;gt;data1, p_some_struct-&amp;gt;data2, p_some_struct-&amp;gt;pointer1);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;now you have something to push your event into scheduler queue and something to pull from scheduler queue. All you need to do is push by calling &lt;code&gt;app_module_evt_schedule&lt;/code&gt;() in one contexxt and pull by calling   &lt;code&gt;app_sched_execute&lt;/code&gt;() in lower priority context and tadaaaa you have changed the execution of callback_function from one context to the other.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK app scheduler</title><link>https://devzone.nordicsemi.com/thread/25096?ContentTypeID=1</link><pubDate>Mon, 18 May 2015 13:53:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9397ae61-f9a0-4d3d-8137-95d244d832bf</guid><dc:creator>Richard Phillips</dc:creator><description>&lt;p&gt;Great, thanks.  So if I want to receive BLE events in the scheduler, I pass the handler in as a parameter to SOFTDEVICE_HANDLER_INIT... But what if I want to receive system events in the scheduler also?  Will this happen automatically, or do I need to do something else, or is this not possible?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK app scheduler</title><link>https://devzone.nordicsemi.com/thread/25095?ContentTypeID=1</link><pubDate>Mon, 18 May 2015 13:31:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41627407-45c4-4578-9894-46d41594d051</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;The BLE events and SYS events are not using the scheduler here. But Timers are.
Please check the timers_init function to see that they want their handlers to be run in main context.&lt;/p&gt;
&lt;p&gt;Update:
Note that the timers are initialized in a different way using the macro&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;APP_TIMER_APPSH_INIT&lt;/p&gt;
&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>