From bf65342d7543880d6ac75f6978977013f6375877 Mon Sep 17 00:00:00 2001 From: mudassar-ublox Date: Mon, 30 Mar 2020 17:01:09 +0500 Subject: [PATCH] Added UBLOX modem api for power up modem UBLOX_C027 --- .../TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp | 34 ++-------- .../TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h | 3 - .../UBLOX_onboard_modem_api.c | 62 +++++++++++++++++++ .../UBLOX_onboard_modem_api.h | 54 ++++++++++++++++ 4 files changed, 121 insertions(+), 32 deletions(-) create mode 100644 targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/UBLOX_onboard_modem_api.c create mode 100644 targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/UBLOX_onboard_modem_api.h diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp index da3794d003d..c1ef5524192 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp @@ -17,12 +17,7 @@ #if MBED_CONF_NSAPI_PRESENT #include "ONBOARD_UBLOX_PPP.h" - -#include "ublox_low_level_api.h" -#include "gpio_api.h" -#include "platform/mbed_thread.h" -#include "PinNames.h" - +#include "UBLOX_onboard_modem_api.h" #include "drivers/BufferedSerial.h" #include "CellularLog.h" @@ -34,47 +29,28 @@ ONBOARD_UBLOX_PPP::ONBOARD_UBLOX_PPP(FileHandle *fh) : UBLOX_PPP(fh) nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_on() { - //currently USB is not supported, so pass 0 to disable USB - //This call does everything except actually pressing the power button - ublox_mdm_powerOn(0); - + ::onboard_modem_init(); return NSAPI_ERROR_OK; } nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_off() { - ublox_mdm_powerOff(); - + ::onboard_modem_deinit(); return NSAPI_ERROR_OK; } nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_on() { - /* keep the power line low for 150 milisecond */ - press_power_button(150); - /* give modem a little time to respond */ - thread_sleep_for(100); - + ::onboard_modem_power_up(); return NSAPI_ERROR_OK; } nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_off() { - /* keep the power line low for 1 second */ - press_power_button(1000); - + ::onboard_modem_power_down(); return NSAPI_ERROR_OK; } -void ONBOARD_UBLOX_PPP::press_power_button(int time_ms) -{ - gpio_t gpio; - - gpio_init_out_ex(&gpio, MDMPWRON, 0); - thread_sleep_for(time_ms); - gpio_write(&gpio, 1); -} - CellularDevice *CellularDevice::get_target_default_instance() { static BufferedSerial serial(MDMTXD, MDMRXD, 115200); diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h index 2cbea38cdec..f95f2228c38 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h @@ -29,9 +29,6 @@ class ONBOARD_UBLOX_PPP : public UBLOX_PPP { virtual nsapi_error_t hard_power_off(); virtual nsapi_error_t soft_power_on(); virtual nsapi_error_t soft_power_off(); - -private: - void press_power_button(int time_ms); }; } // namespace mbed diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/UBLOX_onboard_modem_api.c b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/UBLOX_onboard_modem_api.c new file mode 100644 index 00000000000..2bf565a8255 --- /dev/null +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/UBLOX_onboard_modem_api.c @@ -0,0 +1,62 @@ +/* mbed Microcontroller Library + * Copyright (c) 2020 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if MBED_CONF_NSAPI_PRESENT + +#include "UBLOX_onboard_modem_api.h" +#include "gpio_api.h" +#include "platform/mbed_wait_api.h" +#include "platform/mbed_thread.h" +#include "PinNames.h" + +static void press_power_button(time_ms) +{ + gpio_t gpio; + + gpio_init_out_ex(&gpio, MDMPWRON, 0); + thread_sleep_for(time_ms); + gpio_write(&gpio, 1); +} + +void onboard_modem_init() +{ + //currently USB is not supported, so pass 0 to disable USB + //This call does everything except actually pressing the power button + ublox_mdm_powerOn(0); +} + +void onboard_modem_deinit() +{ + ublox_mdm_powerOff(); +} + +void onboard_modem_power_up() +{ + /* keep the power line low for 150 microseconds */ + press_power_button(150); + + /* give modem a little time to respond */ + thread_sleep_for(100); +} + +void onboard_modem_power_down() +{ + /* keep the power line low for 1 seconds */ + press_power_button(1000); +} + +#endif //MBED_CONF_NSAPI_PRESENT diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/UBLOX_onboard_modem_api.h b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/UBLOX_onboard_modem_api.h new file mode 100644 index 00000000000..2a2e76edb28 --- /dev/null +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/UBLOX_onboard_modem_api.h @@ -0,0 +1,54 @@ +/* mbed Microcontroller Library + * Copyright (c) 2020 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UBLOX_ONBOARD_MODEM_API_H_ +#define UBLOX_ONBOARD_MODEM_API_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** Sets the modem up for powering on + * modem_init() will be equivalent to plugging in the device, i.e., + * attaching power and serial port. + */ +void onboard_modem_init(void); + +/** Sets the modem in unplugged state + * modem_deinit() will be equivalent to pulling the plug off of the device, i.e., + * detaching power and serial port. + * This puts the modem in lowest power state. + */ +void onboard_modem_deinit(void); + +/** Powers up the modem + * modem_power_up() will be equivalent to pressing the soft power button. + * The driver may repeat this if the modem is not responsive to AT commands. + + */ +void onboard_modem_power_up(void); + +/** Powers down the modem + * modem_power_down() will be equivalent to turning off the modem by button press. + */ +void onboard_modem_power_down(void); + +#ifdef __cplusplus +} +#endif + +#endif /* UBLOX_ONBOARD_MODEM_API_H_ */