Last active
October 20, 2021 12:01
-
-
Save phlegx/b555eb23db2f835970aaa54801603012 to your computer and use it in GitHub Desktop.
Mbed OS 5.15.7: Add wait on onboard modem deinit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* mbed Microcontroller Library | |
* Copyright (c) 2017 ARM Limited | |
* | |
* 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 "onboard_modem_api.h" | |
#include "gpio_api.h" | |
#include "platform/mbed_wait_api.h" | |
#include "platform/mbed_thread.h" | |
#include "PinNames.h" | |
#if MODEM_ON_BOARD | |
// Note microseconds not milliseconds | |
static void press_power_button(int time_us) | |
{ | |
gpio_t gpio; | |
#if defined(TARGET_UBLOX_C030_R41XM) | |
gpio_init_inout(&gpio, MDMPWRON, PIN_OUTPUT, OpenDrain, 0); | |
#else | |
gpio_init_out_ex(&gpio, MDMPWRON, 0); | |
#endif | |
wait_us(time_us); | |
gpio_write(&gpio, 1); | |
} | |
void onboard_modem_init() | |
{ | |
gpio_t gpio; | |
#if defined(TARGET_UBLOX_C030_R41XM) | |
// Set the pin to high so on powerup we can set low | |
gpio_init_inout(&gpio, MDMPWRON, PIN_OUTPUT, OpenDrain, 1); | |
#endif | |
// Take us out of reset | |
gpio_init_out_ex(&gpio, MDMRST, 1); | |
} | |
void onboard_modem_deinit() | |
{ | |
#ifndef TARGET_UBLOX_C030_R41XM | |
gpio_t gpio; | |
// Back into reset | |
gpio_init_out_ex(&gpio, MDMRST, 0); | |
/* In case of SARA-R4, MDMRST needs to be asserted for 10 seconds before modem actually powers down. | |
* This means that modem is initially responsive to AT commands but powers down | |
* after 10 seconds unless MDMRST is de-asserted (onboard_modem_init()). | |
*/ | |
thread_sleep_for(10500); | |
#endif | |
} | |
void onboard_modem_power_up() | |
{ | |
#if defined(TARGET_UBLOX_C030_R41XM) | |
/* keep the power line low for 1 seconds */ | |
press_power_button(1000000); | |
#else | |
/* keep the power line low for 50 microseconds */ | |
press_power_button(50); | |
#endif | |
/* give modem a little time to respond */ | |
thread_sleep_for(100); | |
} | |
void onboard_modem_power_down() | |
{ | |
/* keep the power line low for 1.5 seconds */ | |
press_power_button(1500000); | |
} | |
#endif //MODEM_ON_BOARD | |
#endif //MBED_CONF_NSAPI_PRESENT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment