-
Notifications
You must be signed in to change notification settings - Fork 3k
Cell bg96 power #10588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Cell bg96 power #10588
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
#include "rtos/ThisThread.h" | ||
#include "QUECTEL_BG96.h" | ||
#include "QUECTEL_BG96_CellularNetwork.h" | ||
#include "QUECTEL_BG96_CellularStack.h" | ||
|
@@ -24,13 +25,26 @@ | |
|
||
using namespace mbed; | ||
using namespace events; | ||
using namespace rtos; | ||
|
||
#define CONNECT_DELIM "\r\n" | ||
#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format | ||
#define CONNECT_TIMEOUT 8000 | ||
|
||
#define DEVICE_READY_URC "CPIN:" | ||
|
||
#if !defined(MBED_CONF_QUECTEL_BG96_PWR) | ||
#define MBED_CONF_QUECTEL_BG96_PWR NC | ||
#endif | ||
|
||
#if !defined(MBED_CONF_QUECTEL_BG96_RST) | ||
#define MBED_CONF_QUECTEL_BG96_RST NC | ||
#endif | ||
|
||
#if !defined(MBED_CONF_QUECTEL_BG96_POLARITY) | ||
#define MBED_CONF_QUECTEL_BG96_POLARITY 1 // active high | ||
#endif | ||
|
||
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { | ||
AT_CellularNetwork::RegistrationModeLAC, // C_EREG | ||
AT_CellularNetwork::RegistrationModeLAC, // C_GREG | ||
|
@@ -49,11 +63,16 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { | |
1, // PROPERTY_AT_CGEREP | ||
}; | ||
|
||
QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh) : AT_CellularDevice(fh) | ||
QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh, PinName pwr, bool active_high, PinName rst) | ||
: AT_CellularDevice(fh), | ||
_active_high(active_high), | ||
_pwr(pwr, !_active_high), | ||
_rst(rst, !_active_high) | ||
{ | ||
AT_CellularBase::set_cellular_properties(cellular_properties); | ||
} | ||
|
||
|
||
AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at) | ||
{ | ||
return new QUECTEL_BG96_CellularNetwork(at); | ||
|
@@ -74,6 +93,96 @@ void QUECTEL_BG96::set_ready_cb(Callback<void()> callback) | |
_at->set_urc_handler(DEVICE_READY_URC, callback); | ||
} | ||
|
||
nsapi_error_t QUECTEL_BG96::hard_power_on() | ||
{ | ||
if (_pwr.is_connected()) { | ||
tr_info("Modem power on"); | ||
ThisThread::sleep_for(250); | ||
_pwr = !_active_high; | ||
ThisThread::sleep_for(250); // BG96_Hardware_Design_V1.1 says 100 ms, but 250 ms seems to be more robust | ||
_pwr = _active_high; | ||
ThisThread::sleep_for(500); | ||
} | ||
|
||
return NSAPI_ERROR_OK; | ||
} | ||
|
||
nsapi_error_t QUECTEL_BG96::soft_power_on() | ||
{ | ||
if (_rst.is_connected()) { | ||
tr_info("Reset modem"); | ||
_rst = !_active_high; | ||
ThisThread::sleep_for(100); | ||
_rst = _active_high; | ||
ThisThread::sleep_for(150 + 460); // RESET_N timeout from BG96_Hardware_Design_V1.1 | ||
_rst = !_active_high; | ||
ThisThread::sleep_for(500); | ||
|
||
// wait for RDY | ||
_at->lock(); | ||
_at->set_at_timeout(10 * 1000); | ||
AriParkkila marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_at->resp_start(); | ||
_at->set_stop_tag("RDY"); | ||
bool rdy = _at->consume_to_stop_tag(); | ||
_at->set_stop_tag(OK); | ||
_at->restore_at_timeout(); | ||
_at->unlock(); | ||
|
||
if (!rdy) { | ||
return NSAPI_ERROR_DEVICE_ERROR; | ||
} | ||
} | ||
|
||
return NSAPI_ERROR_OK; | ||
} | ||
|
||
nsapi_error_t QUECTEL_BG96::hard_power_off() | ||
{ | ||
if (_pwr.is_connected()) { | ||
tr_info("Modem power off"); | ||
_pwr = _active_high; | ||
ThisThread::sleep_for(650); // from BG96_Hardware_Design_V1.1 | ||
_pwr = !_active_high; | ||
} | ||
|
||
return NSAPI_ERROR_OK; | ||
} | ||
|
||
nsapi_error_t QUECTEL_BG96::init() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this sequence be like this in base class already? |
||
{ | ||
int retry = 0; | ||
|
||
_at->lock(); | ||
_at->flush(); | ||
_at->cmd_start("ATE0"); // echo off | ||
_at->cmd_stop_read_resp(); | ||
|
||
_at->cmd_start("AT+CMEE=1"); // verbose responses | ||
_at->cmd_stop_read_resp(); | ||
|
||
if (_at->get_last_error() == NSAPI_ERROR_OK) { | ||
do { | ||
_at->cmd_start("AT+CFUN=1"); // set full functionality | ||
_at->cmd_stop_read_resp(); | ||
|
||
// CFUN executed ok | ||
if (_at->get_last_error() != NSAPI_ERROR_OK) { | ||
// wait some time that modem gets ready for CFUN command, and try again | ||
retry++; | ||
_at->flush(); | ||
ThisThread::sleep_for(64); // experimental value | ||
} else { | ||
// yes continue | ||
break; | ||
} | ||
|
||
/* code */ | ||
} while ((retry < 3)); | ||
} | ||
|
||
return _at->unlock_return_error(); | ||
} | ||
|
||
#if MBED_CONF_QUECTEL_BG96_PROVIDE_DEFAULT | ||
#include "UARTSerial.h" | ||
CellularDevice *CellularDevice::get_default_instance() | ||
|
@@ -83,7 +192,10 @@ CellularDevice *CellularDevice::get_default_instance() | |
tr_debug("QUECTEL_BG96 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_BG96_RTS, MBED_CONF_QUECTEL_BG96_CTS); | ||
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_BG96_RTS, MBED_CONF_QUECTEL_BG96_CTS); | ||
#endif | ||
static QUECTEL_BG96 device(&serial); | ||
static QUECTEL_BG96 device(&serial, | ||
MBED_CONF_QUECTEL_BG96_PWR, | ||
MBED_CONF_QUECTEL_BG96_POLARITY, | ||
MBED_CONF_QUECTEL_BG96_RST); | ||
return &device; | ||
} | ||
#endif |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.