<?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>GPS deinitialization</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/69298/gps-deinitialization</link><description>Hi, 
 OS: Windows 10 Editor: SEGGER Embedded Studio for ARM (Nordic Edition) V5.10d (64-bit) nrfjprog version: 10.12.1 JLinkARM.dll version: 6.88a nRF Connect SDK version: 1.4.0 
 I have had some problems with powering off our custom nRF9160 device. For</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 22 Dec 2020 08:04:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/69298/gps-deinitialization" /><item><title>RE: GPS deinitialization</title><link>https://devzone.nordicsemi.com/thread/286225?ContentTypeID=1</link><pubDate>Tue, 22 Dec 2020 08:04:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6555f9e2-c938-43a8-92f4-ae7e57f68015</guid><dc:creator>anicare-tero</dc:creator><description>&lt;p&gt;Okay, that&amp;#39;s good to know. I&amp;#39;m going with my custom deinit function for now and then take the API to use when it&amp;#39;s replaces the GPS driver.&lt;/p&gt;
&lt;p&gt;Thanks for your support!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPS deinitialization</title><link>https://devzone.nordicsemi.com/thread/286119?ContentTypeID=1</link><pubDate>Mon, 21 Dec 2020 16:14:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b72a17b8-5ba1-4184-96f8-e38c3b5cb282</guid><dc:creator>Didrik Rokhaug</dc:creator><description>[quote user="ziirou"]Do you have any information if there are coming the deinit functions from your side?[/quote]
&lt;p&gt;&amp;nbsp;We do not have any plans for implementing a deinit function for the GPS driver.&lt;/p&gt;
&lt;p&gt;However, the current GPS driver will soon be deprecated, and replaced with a (similar) API in libmodem (formerly bsdlib).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPS deinitialization</title><link>https://devzone.nordicsemi.com/thread/285979?ContentTypeID=1</link><pubDate>Mon, 21 Dec 2020 08:54:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4913a20d-6a76-4674-a3a9-cbe72d1227ec</guid><dc:creator>anicare-tero</dc:creator><description>&lt;p&gt;Hi Didrik,&lt;/p&gt;
[quote userid="81181" url="~/f/nordic-q-a/69298/gps-deinitialization/285865#285865"]I assume you are calling the init() function to re-initialize the driver?[/quote]
&lt;p&gt;I&amp;#39;m not re-initializing the driver because I&amp;#39;m only doing deinit before powering the device off. And if we power on the device again, it should do a normal startup and initialize the GPS driver normally with the default init function.&lt;/p&gt;
[quote userid="81181" url="~/f/nordic-q-a/69298/gps-deinitialization/285865#285865"]Your deinit functions seems fine.[/quote]
&lt;p&gt;They have worked fine for me so for now I&amp;#39;m going with those. Do you have any information if there are coming the deinit functions from your side?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPS deinitialization</title><link>https://devzone.nordicsemi.com/thread/285865?ContentTypeID=1</link><pubDate>Fri, 18 Dec 2020 14:28:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc33ace1-1f9a-4c77-84da-2bf60a8001a3</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi, and sorry for the late answer.&lt;/p&gt;
&lt;p&gt;Your deinit functions seems fine.&lt;/p&gt;
&lt;p&gt;I am however not sure about drv_data-&amp;gt;thread_run_sem. For the most part, it seems OK to initialize a semaphore twice (I assume you are calling the init() function to re-initialize the driver?), but there are a few calls inside k_sem_init() I haven&amp;#39;t been able to check.&lt;/p&gt;
&lt;p&gt;It might be that everything works OK, I just don&amp;#39;t know for sure.&lt;/p&gt;
&lt;p&gt;However, I did a quick test with a simple application calling k_sem_init() on the same semaphore in a loop, and it has currently been running for over 9 300 000 iterations.&lt;/p&gt;
&lt;p&gt;My test doesn&amp;#39;t test any usage of the semaphore though, so I can not guarantee that everything is 100% fine. But at least there doesn&amp;#39;t seem to be any major memory leaks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPS deinitialization</title><link>https://devzone.nordicsemi.com/thread/284322?ContentTypeID=1</link><pubDate>Thu, 10 Dec 2020 12:33:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab79c1df-fe81-4d75-b490-73090f89e6e7</guid><dc:creator>anicare-tero</dc:creator><description>&lt;p&gt;Hi Didrik,&lt;/p&gt;
&lt;p&gt;Thanks for replying!&lt;/p&gt;
[quote userid="81181" url="~/f/nordic-q-a/69298/gps-deinitialization/284318#284318"]What modem firmware are you using?[/quote]
&lt;p&gt;mfw_nrf9160_1.2.2 and also tested with 1.2.1.&lt;/p&gt;
[quote userid="81181" url="~/f/nordic-q-a/69298/gps-deinitialization/284318#284318"]What mode are you running the GPS in (single shot, periodic, continuous)?[/quote]
&lt;p&gt;Periodic.&lt;/p&gt;
[quote userid="81181" url="~/f/nordic-q-a/69298/gps-deinitialization/284318#284318"]Please see this answer by one of my colleague for more information: &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/67618/gps-position-fix-interval/277521#277521"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/67618/gps-position-fix-interval/277521#277521&lt;/a&gt;[/quote]
&lt;p&gt;There&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/hkn"&gt;Håkon Alseth&lt;/a&gt;&amp;nbsp;said: &amp;quot;&lt;span&gt;&lt;em&gt;However, it is possible to prevent scheduled downloads by starting GNSS whenever a fix is needed and stopping it right after the fix&lt;/em&gt;.&amp;quot;. I&amp;#39;m stopping the GPS before powering the device off so that shouldn&amp;#39;t be the case, right?&lt;/span&gt;&lt;/p&gt;
[quote userid="81181" url="~/f/nordic-q-a/69298/gps-deinitialization/284318#284318"]In your deinit function, you should also make sure that all resources allocated by the driver has been properly deallocated. In your case, it seems like you are at least leaving the socket open, though you should also check if you are leaking other resources.[/quote]
&lt;p&gt;Is there coming a deinit function from your side? And I&amp;#39;m gonna update my function to at least close the socket too. What are the other resources that should be deallocated? And how should I do that?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; I updated the nrf9160_gps.c a little bit. Should it be better now and what else should I do?&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static int deinit(const struct device *dev)
{
	int err;
	struct gps_drv_data *drv_data = dev-&amp;gt;data;

	if (!atomic_get(&amp;amp;drv_data-&amp;gt;is_init)) {
		LOG_WRN(&amp;quot;GPS is already deinitialized&amp;quot;);

		return -EALREADY;
	}

	cancel_works(drv_data);
	atomic_set(&amp;amp;drv_data-&amp;gt;is_active, 0);
	atomic_set(&amp;amp;drv_data-&amp;gt;is_shutdown, 1);

	LOG_DBG(&amp;quot;Closing GPS socket, fd: %d&amp;quot;, drv_data-&amp;gt;socket);
	err = nrf_close(drv_data-&amp;gt;socket);
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to close GPS socket, err: %d&amp;quot;, err);
	}

	LOG_DBG(&amp;quot;Aborting GPS thread.&amp;quot;);
	k_thread_abort(drv_data-&amp;gt;thread_id);

	atomic_set(&amp;amp;drv_data-&amp;gt;is_init, 0);

	return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;Best Regards,&lt;br /&gt;Tero&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPS deinitialization</title><link>https://devzone.nordicsemi.com/thread/284318?ContentTypeID=1</link><pubDate>Thu, 10 Dec 2020 12:16:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:878febbd-8f2a-44cc-8514-253e920f5034</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;What modem firmware are you using?&lt;/p&gt;
&lt;p&gt;What mode are you running the GPS in (single shot, periodic, continuous)?&lt;/p&gt;
&lt;p&gt;What you are seeing might be periodic almanac downloads performed by the modem.&lt;/p&gt;
&lt;p&gt;Please see this answer by one of my colleague for more information: &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/67618/gps-position-fix-interval/277521#277521"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/67618/gps-position-fix-interval/277521#277521&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In your deinit function, you should also make sure that all resources allocated by the driver has been properly deallocated. In your case, it seems like you are at least leaving the socket open, though you should also check if you are leaking other resources.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Didrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>