<?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>Force GPIOTE event manually.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93022/force-gpiote-event-manually</link><description>Using SDK17.1.0, I need to manually force an event handler to run. But the event handler is part of the SDK and is declared static. Key constraint is that i cannot modify the SDK. 
 I&amp;#39;m using the app_button library. But the handler i registered for the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 19 Oct 2022 14:53:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93022/force-gpiote-event-manually" /><item><title>RE: Force GPIOTE event manually.</title><link>https://devzone.nordicsemi.com/thread/391488?ContentTypeID=1</link><pubDate>Wed, 19 Oct 2022 14:53:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b130b533-793e-4611-82ae-c1f6a12b3f33</guid><dc:creator>SeanHowsonTB</dc:creator><description>&lt;p&gt;Cant find the quote tool, to i&amp;#39;ve inserted this as code! -_-&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; But it was a suggested solution for how to call a static function without changing the code that is static, which is what you describe.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Yep all reasoning here is sound &amp;amp; appreciate you giving a solution regardless or whether it was dirty. Had i been working in assembler, or on a platform where i perhaps had much better control over the linker i would have considered the option. but as we&amp;#39;ve both agreed, the more layers you add, the less you want to mess around with the deeper layers/foundations. Thanks for the solution regardless, an interesting thought experiment if nothing else!&lt;/p&gt;
&lt;p&gt;Thanks for the suggestion at the bottom of your last reply. You might not be far off. I could perhaps have a special case, where we accept that for the first press &lt;strong&gt;and&lt;/strong&gt; release, app_button does nothing. then begin handling things through app_button library.... or something similar to this. &lt;/p&gt;
&lt;p&gt;Currently, my button only generates actions based on a couple of fairly specific button presses, (long, super long, and some other special criteria, way outside the realms of normal mechanical bounce)... regardless, what this means is that i have some inbuilt debounce. I was only using the app_button library because months ago, i struggled to get gpiote to work on it&amp;#39;s own. While trying to solve this issue i&amp;#39;ve gained a deeper insight to the app_button library &amp;amp; it may be that i can peel back a layer and just use the GPIOTE library alone.&lt;/p&gt;
&lt;p&gt;I appreciate you working around my requirements and appreciate the feedback, opinions &amp;amp; discussion. It seems you&amp;#39;ve confirmed that there isn&amp;#39;t some &amp;quot;non-static&amp;quot; function i wasn&amp;#39;t aware of and i&amp;#39;ll have to take some other approach outside of app_button (special cases, or maybe just GPIOTE on it&amp;#39;s own). Thanks for the help. I think this concludes my original query regarding functions &amp;amp; pointers so will mark the case closed. Have a good one.&lt;/p&gt;
&lt;p&gt;-S&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Force GPIOTE event manually.</title><link>https://devzone.nordicsemi.com/thread/391487?ContentTypeID=1</link><pubDate>Wed, 19 Oct 2022 14:37:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e6fac7c-0b64-488c-913a-fdfe9cc74562</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Sean,&lt;/p&gt;
[quote user="SeanHowsonTB"]IMHO altering the SDK counstitutes as a dirty hack[/quote]
&lt;p&gt;You could say that. And I agree that you should try to avoid it . But in reality, the SDK does not cover all use cases even though we try to make it as generic as possible, and also, it is not bug free. So it is not uncommon to have to change the SDK code, even though it is not ideal.&lt;/p&gt;
[quote user="SeanHowsonTB"]If i&amp;#39;m being honest, while i appreciate the solution you&amp;#39;ve presented it really sounds like a long winded solution for a very simple problem. [/quote]
&lt;p&gt;I fully agree. But it was a suggested solution for how to call a static function without changing the code that is static, which is what you describe. I do not like that approach at all, though, as mentioned.&lt;/p&gt;
&lt;p&gt;I see the problem with&amp;nbsp;interpreting the button press when it is a wakeup source. I would consider doing this with a completely different approach, handling the startup case as a special case, and using some dedicated code to handel it without the app_button library. You could still use the app_timer (with a dedicated instance) to do the debouncing. This would involve&amp;nbsp;a bit more code so perhaps not ideal, but you would not have to do any changes in the SDK, and you will not have to do any other dirty hacks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Force GPIOTE event manually.</title><link>https://devzone.nordicsemi.com/thread/391486?ContentTypeID=1</link><pubDate>Wed, 19 Oct 2022 13:54:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3637b6e-d2a2-4344-a10e-27cf5fa4c8d1</guid><dc:creator>SeanHowsonTB</dc:creator><description>&lt;p&gt;Einar, thanks for the reply.&lt;/p&gt;
&lt;p&gt;The goal is, as is it was in my original post. Allow the chip to enter shutdown mode. Wake up from the button press and have the button press event handler run (the handler i registered to the button when initialising the app_button).&lt;/p&gt;
&lt;p&gt;But i&amp;#39;ve found that this does not happen because the debounce timer is never started. So i am trying to manually start the chain of events that leads to my button handler being run. I am asking about the gpiote event handler because this seems to be the first domino in the chain/ first item in the call stack, that drives the app_button library. So it seemed sensible to start from the top... I tried just calling the contents of my custom app_button handler. But the app_button library, then doesn&amp;#39;t &amp;quot;know&amp;quot; that the button has been pushed, subsequently when the button is released, my app_button handler does not run.&lt;/p&gt;
&lt;p&gt;the chain of events i&amp;#39;ve described, runs my custom event handler, and other functions that tell the app_button library that the button is pressed. I find it odd that i seemingly cant initialised the app_button library in the &amp;quot;already pressed&amp;quot; state... anyway,&lt;strong&gt; another approach might be to make sure&lt;/strong&gt; &lt;strong&gt;app_button library to understand that the button is pressed. so that my handler runsproperly when the button is released, that way i could manually run my handler (which is global), once upon startup, to register the press, tell the libary the button is pressed. Then the handler will run just fine when the button is released. &lt;/strong&gt;This is the equivilent of running all the things that would be triggered by manually calling the GPIOTE event handler as id originally proposed.&lt;/p&gt;
&lt;p&gt;I had considered &amp;amp; tried copying chunks of code from the functions run as a result of the debounce timer etc. But the ones i&amp;#39;ve tried require access to global variables within the app_button library, so basically the same problem i have with calling functions... (scope!)&lt;/p&gt;
&lt;p&gt;I take your point on not having a dirty hack. I am not a fan of dirty code so would agree here. IMHO altering the SDK counstitutes as a dirty hack (this isn&amp;#39;t the only reason i cant change it). But the purpose of this forum post is to see if there is a non-dirty-hack solution that i&amp;#39;m not aware of.&lt;/p&gt;
&lt;p&gt;If i&amp;#39;m being honest, while i appreciate the solution you&amp;#39;ve presented it really sounds like a long winded solution for a very simple problem. While i appreciate the out-of-the-box idea, it&amp;#39;s really not suitable for a peice of firmware being deployed into an active product and makes automation of piplining &amp;amp; deployment very tricky and it could easily result in some serious errors in future, especially when trying to pass the code around multiple developers &amp;amp; use in multiple debugging environments.&lt;/p&gt;
&lt;p&gt;Thanks, sorry for the long reply,&lt;/p&gt;
&lt;p&gt;Sean&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Force GPIOTE event manually.</title><link>https://devzone.nordicsemi.com/thread/391485?ContentTypeID=1</link><pubDate>Wed, 19 Oct 2022 12:28:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ac919b3-632d-4754-8e63-daa302c50480</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Sean,&lt;/p&gt;
&lt;p&gt;May I ask why you want to call the event handler directly in the first place? What is the end goal? And can you potentially achieve the end goal in another matter (for instance by doing the same as the event handler from another function)?&lt;/p&gt;
&lt;p&gt;Also, while I understand that in some cases you may have qualified the SDK as is and cannot change it, it seems a bit unfortunate that it leads to a the need for potentially dirty hacks. It seems counter productive if the goal of not changing the SDK is related to quality somehow.&lt;/p&gt;
&lt;p&gt;If this really is the approach you need to use, then perhaps an alternative could be this: Read a function pointer from a specific address (for simplicity you could perhaps put it in UICR for testing, but in order to support DFU etc later it should be in normal flash). Call that&amp;nbsp;function pointer when you want to call the static event handler. Then, after you have built the project, check the map file to find the address of the event handler, and write that to the location that should hold the function pointer. This could be done manually first for testing. When you get this working, you can script this so that you automatically parse the map file and modify the hex file, writing the address/pointer to the fixed location you have reserved for it.&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>