This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

GPS deinitialization

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 some reason the GPS was starting again (I'm receiving GPS_EVT_SEARCH_STARTED event) even if it was stopped and that was causing a reboot for the device. Finally I got it fixed by adding a custom deinit function for nrf9160_gps driver and now our device is powering off. I have a similar gps_controller module than Asset Tracker has.

I added these:

gps_controller.c

/** @brief Deinitializes the GPS device. */
int gps_control_deinit(void)
{
	int err;

	if (gps_dev == NULL) {
		LOG_ERR("Error: Could not get %s device",
			log_strdup(CONFIG_GPS_DEV_NAME));
		return -ENODEV;
	}

	err = gps_deinit(gps_dev);
	if (err) {
		LOG_ERR("Error: Could not deinitialize GPS, error: %d", err);
		return err;
	}

	LOG_INF("GPS deinitialized");

	return err;
}

gps_controller.h

int gps_control_deinit(void);

nrf9160_gps.c

static int deinit(const struct device *dev)
{
	struct gps_drv_data *drv_data = dev->data;

	if (!atomic_get(&drv_data->is_init)) {
		LOG_WRN("GPS is already deinitialized");

		return -EALREADY;
	}

	k_thread_abort(drv_data->thread_id);

	atomic_set(&drv_data->is_init, 0);

	return 0;
}

static const struct gps_driver_api gps_api_funcs = {
...
	.deinit = deinit,
...
};

I wonder why there isn't already a deinit function for nrf9160_gps driver. I'm not sure if that's the proper way to do that but at least it's working for me. I hope you could help me to create a proper function for deinit.

Regards,
Tero

Related