<?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>event data disappears in app_scheduler()</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9017/event-data-disappears-in-app_scheduler</link><description>I&amp;#39;m trying to send some data to a custom event handler function using app_scheduler. The problem I am having is the data I am sending is not being received. 
 I expect this is a C syntax issue on my part. Alas my C skills are weak, so any help is much</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 Feb 2016 17:58:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9017/event-data-disappears-in-app_scheduler" /><item><title>RE: event data disappears in app_scheduler()</title><link>https://devzone.nordicsemi.com/thread/33225?ContentTypeID=1</link><pubDate>Tue, 02 Feb 2016 17:58:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57231b50-f8b9-4483-a58d-c71f5ceb010a</guid><dc:creator>Mike Voytovich</dc:creator><description>&lt;p&gt;Actually it looks like the implementation of &lt;code&gt;app_sched_event_put&lt;/code&gt; copies the data into the event queue, so calling it with a stack variable is OK:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;               memcpy(&amp;amp;m_queue_event_data[event_index * m_queue_event_size],
                   p_event_data,
                   event_data_size);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: event data disappears in app_scheduler()</title><link>https://devzone.nordicsemi.com/thread/33224?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2015 02:54:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf4bd3ce-fe75-40dd-96df-501ce8ec9cfc</guid><dc:creator>Doug_H</dc:creator><description>&lt;p&gt;Thank you very much. All fixed now!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: event data disappears in app_scheduler()</title><link>https://devzone.nordicsemi.com/thread/33223?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2015 02:16:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5441ffe-5bbf-40a5-a3cf-e9b08ab1836a</guid><dc:creator>RK</dc:creator><description>&lt;pre&gt;&lt;code&gt;tag_evt_t * p_tag_evt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Two errors there - firstly you&amp;#39;re allocating a pointer to the data, but not allocating actual space for the data, that pointer starts pointing to some random piece of memory. You&amp;#39;re fortunate that you&amp;#39;re not getting a hard fault writing to illegal memory or writing over your code. You want&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;tag_evt_t tag_evt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and pass the address of it to your function &lt;code&gt;&amp;amp;tag_evt&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;But that&amp;#39;s no good either as that variable is on the stack, it&amp;#39;s local to the function, so as soon as you leave the function the memory is no-longer valid. By the time your event handler is called the stack will have overwritten the data, probably.&lt;/p&gt;
&lt;p&gt;If you only have one at any time, make the variable static, else use malloc() and free()&lt;/p&gt;
&lt;p&gt;static tag_evt_t tag_evt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>