drivers: modem: sim7080: added stop functions for network and gnss
Network and gnss can be disabled with stop functions instead of power
cycling the modem. The start functions will also not power cycle the
modem. In order to call the start functions the modem needs to be
booted.
Signed-off-by: Lukas Gehreke <lk.gehreke@gmail.com>
diff --git a/drivers/modem/simcom/sim7080/sim7080.c b/drivers/modem/simcom/sim7080/sim7080.c
index a552e47..4f8f786 100644
--- a/drivers/modem/simcom/sim7080/sim7080.c
+++ b/drivers/modem/simcom/sim7080/sim7080.c
@@ -677,10 +677,14 @@
int mdm_sim7080_start_network(void)
{
- int ret = -EINVAL;
+ int ret = -EALREADY;
- if (sim7080_get_state() != SIM7080_STATE_IDLE) {
+ if (sim7080_get_state() == SIM7080_STATE_NETWORKING) {
+ LOG_WRN("Network already active");
+ goto out;
+ } else if (sim7080_get_state() != SIM7080_STATE_IDLE) {
LOG_WRN("Can only activate networking from idle state");
+ ret = -EINVAL;
goto out;
}
@@ -690,6 +694,23 @@
return ret;
}
+int mdm_sim7080_stop_network(void)
+{
+ int ret = -EINVAL;
+
+ if (sim7080_get_state() != SIM7080_STATE_NETWORKING) {
+ LOG_WRN("Modem not in networking state");
+ goto out;
+ }
+
+ //TODO: close sockets
+
+ ret = sim7080_pdp_deactivate();
+
+out:
+ return ret;
+}
+
int mdm_sim7080_power_on(void)
{
return modem_boot(false);
diff --git a/drivers/modem/simcom/sim7080/sim7080_gps.c b/drivers/modem/simcom/sim7080/sim7080_gps.c
index 61ab3ef..03d3c9a 100644
--- a/drivers/modem/simcom/sim7080/sim7080_gps.c
+++ b/drivers/modem/simcom/sim7080/sim7080_gps.c
@@ -267,23 +267,53 @@
int mdm_sim7080_start_gnss(void)
{
- int ret;
+ int ret = -EALREADY;
- sim7080_change_state(SIM7080_STATE_INIT);
- k_work_cancel_delayable(&mdata.rssi_query_work);
+ if (sim7080_get_state() == SIM7080_STATE_GNSS) {
+ LOG_WRN("Modem already in gnss state");
+ goto out;
+ } else if (sim7080_get_state() != SIM7080_STATE_IDLE) {
+ LOG_WRN("Can only activate gnss from idle state");
+ ret = -EINVAL;
+ goto out;
+ }
- ret = mdm_sim7080_power_on();
+ ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler, NULL, 0U, "AT+CGNSPWR=1",
+ &mdata.sem_response, K_SECONDS(2));
if (ret < 0) {
- LOG_ERR("Failed to start modem!!");
- return -1;
+ LOG_ERR("Failed to power on gnss: %d", ret);
+ goto out;
}
ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler, NULL, 0U, "AT+CGNSCOLD",
&mdata.sem_response, K_SECONDS(2));
if (ret < 0) {
- return -1;
+ LOG_ERR("Failed to start gnss: %d", ret);
+ goto out;
}
sim7080_change_state(SIM7080_STATE_GNSS);
- return 0;
-}
\ No newline at end of file
+out:
+ return ret;
+}
+
+int mdm_sim7080_stop_gnss(void)
+{
+ int ret = -EINVAL;
+
+ if (sim7080_get_state() != SIM7080_STATE_GNSS) {
+ LOG_WRN("Modem not in gnss state");
+ goto out;
+ }
+
+ ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler, NULL, 0U, "AT+CGNSPWR=0",
+ &mdata.sem_response, K_SECONDS(2));
+ if (ret < 0) {
+ LOG_ERR("Failed to power on gnss: %d", ret);
+ goto out;
+ }
+
+ sim7080_change_state(SIM7080_STATE_IDLE);
+out:
+ return ret;
+}
diff --git a/drivers/modem/simcom/sim7080/sim7080_pdp.c b/drivers/modem/simcom/sim7080/sim7080_pdp.c
index 88f2255..5a92d5d 100644
--- a/drivers/modem/simcom/sim7080/sim7080_pdp.c
+++ b/drivers/modem/simcom/sim7080/sim7080_pdp.c
@@ -258,6 +258,8 @@
ret = -EIO;
}
+ k_work_cancel_delayable(&mdata.rssi_query_work);
+
LOG_INF("PDP context deactivated");
sim7080_change_state(SIM7080_STATE_IDLE);
diff --git a/include/zephyr/drivers/modem/simcom-sim7080.h b/include/zephyr/drivers/modem/simcom-sim7080.h
index d656063..3c5612a 100644
--- a/include/zephyr/drivers/modem/simcom-sim7080.h
+++ b/include/zephyr/drivers/modem/simcom-sim7080.h
@@ -133,20 +133,38 @@
int mdm_sim7080_power_off(void);
/**
- * @brief Starts the modem in network operation mode.
+ * @brief Activates the network operation mode of the modem.
+ *
+ * @return 0 on success. Otherwise <0 is returned.
+ * @note The modem needs to be booted for this function to work.
+ * Concurrent use of network and gnss is not possible.
+ */
+int mdm_sim7080_start_network(void);
+
+/**
+ * @brief Stops the networking operation mode of the modem.
*
* @return 0 on success. Otherwise <0 is returned.
*/
-int mdm_sim7080_start_network(void);
+int mdm_sim7080_stop_network(void);
/**
* @brief Starts the modem in gnss operation mode.
*
* @return 0 on success. Otherwise <0 is returned.
+ * @note The modem needs to be booted for this function to work.
+ * Concurrent use of network and gnss is not possible.
*/
int mdm_sim7080_start_gnss(void);
/**
+ * @brief Stops the modem gnss operation mode.
+ *
+ * @return 0 on success. Otherwise <0 is returned.
+ */
+int mdm_sim7080_stop_gnss(void);
+
+/**
* @brief Query gnss position form the modem.
*
* @return 0 on success. If no fix is acquired yet -EAGAIN is returned.