Skip to content
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

EP_AGORA: Add config logic to enable BLE, cell, and LoRa by default #11566

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2019 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

#if EP_AGORA_ENABLE_CELL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way to only include this file when needed in the build versus #ifdef'ing out its contents?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@40Grit The reason I put the #if in was so that someone can change the ep-agora.enable-cell setting in their mbed_app.json file and toggle whether the contents of this file gets built. I'm not sure how it effects building/linking exactly though...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understand why it's there.

I'm questioning moreso if there is a way around needing to have the ifdef in the sources via build configuration that just doesn't include the file in the build.

Specifically question is for the tools team. But I'm on my personal account so I cannot @mention them.aa

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ARMmbed/mbed-os-tools

Copy link
Contributor

@0xc0170 0xc0170 Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not , we use this also for HAL files #if DEVICE_I2C for instance to exclude boards do not have i2c for instance (sharing common MCU family).

This should be fine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a reasonable thing to want, but it looks like the build system doesn't support the generic inclusion or exclusion of a file for compilation based on a configuration parameter. It's something we'll consider as we develop the build system in future. For now the #if defined solution looks like the way to do this.


#include "cellular/onboard_modem_api.h"
#include "UARTSerial.h"
#include "ONBOARD_TELIT_ME910.h"
#include "ThisThread.h"
#include "CellularLog.h"

using namespace mbed;

ONBOARD_TELIT_ME910::ONBOARD_TELIT_ME910(FileHandle *fh) : TELIT_ME910(fh, PIN_NAME_CELL_ON_OFF, true)
{
}

nsapi_error_t ONBOARD_TELIT_ME910::hard_power_on()
{
::onboard_modem_init();
return NSAPI_ERROR_OK;
}

nsapi_error_t ONBOARD_TELIT_ME910::hard_power_off()
{
::onboard_modem_deinit();
return NSAPI_ERROR_OK;
}

nsapi_error_t ONBOARD_TELIT_ME910::soft_power_on()
{
::onboard_modem_power_up();
// From Telit_xE910 Global form factor App note: It is mandatory to avoid sending data to the serial ports during the first 200ms of the module start-up.
rtos::ThisThread::sleep_for(200);
return NSAPI_ERROR_OK;
}

nsapi_error_t ONBOARD_TELIT_ME910::soft_power_off()
{
::onboard_modem_power_down();
return NSAPI_ERROR_OK;
}

nsapi_error_t ONBOARD_TELIT_ME910::init()
{
nsapi_error_t err = AT_CellularDevice::init();
if (err != NSAPI_ERROR_OK) {
return err;
}
_at->lock();
#if DEVICE_SERIAL_FC
_at->at_cmd_discard("&K3;&C1;&D0", "");
#else
_at->at_cmd_discard("&K0;&C1;&D0", "");
#endif

// AT#QSS=1
// Enable the Query SIM Status unsolicited indication in the ME. The format of the
// unsolicited indication is the following:
// #QSS: <status>
// The ME informs at
// every SIM status change through the basic unsolicited indication where <status> range is 0...1
// <status> values:
// - 0: SIM not inserted
// - 1: SIM inserted
_at->at_cmd_discard("#QSS", "=1");

// AT#PSNT=1
// Set command enables unsolicited result code for packet service network type (PSNT)
// having the following format:
// #PSNT:<nt>
// <nt> values:
// - 0: GPRS network
// - 4: LTE network
// - 5: unknown or not registered
_at->at_cmd_discard("#PSNT", "=1");

// AT+CMER=2
// Set command enables sending of unsolicited result codes from TA to TE in the case of
// indicator state changes.
// Current setting: buffer +CIEV Unsolicited Result Codes in the TA when TA-TE link is
// reserved (e.g. on-line data mode) and flush them to the TE after
// reservation; otherwise forward them directly to the TE
_at->at_cmd_discard("+CMER", "=2");

// AT+CMEE=2
// Set command disables the use of result code +CME ERROR: <err> as an indication of an
// error relating to the +Cxxx command issued. When enabled, device related errors cause the +CME
// ERROR: <err> final result code instead of the default ERROR final result code. ERROR is returned
// normally when the error message is related to syntax, invalid parameters or DTE functionality.
// Current setting: enable and use verbose <err> values
_at->at_cmd_discard("+CMEE", "=2");

// AT#PORTCFG=0
// Set command allows to connect Service Access Points to the external physical ports giving a great
// flexibility. Examples of Service Access Points: AT Parser Instance #1, #2, #3, etc..
_at->at_cmd_discard("#PORTCFG", "=3");

// AT&W&P
// - AT&W: Execution command stores on profile <n> the complete configuration of the device. If
// parameter is omitted, the command has the same behavior of AT&W0.
// - AT&P: Execution command defines which full profile will be loaded at startup. If parameter
// is omitted, the command has the same behavior as AT&P0
_at->at_cmd_discard("&W&P", "");

return _at->unlock_return_error();
}

CellularDevice *CellularDevice::get_target_default_instance()
{
static UARTSerial serial(MDMTXD, MDMRXD, 115200);
#if DEVICE_SERIAL_FC
if (MDMRTS != NC && MDMCTS != NC) {
tr_debug("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS);
serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
}
#endif
static ONBOARD_TELIT_ME910 device(&serial);
return &device;
}

#endif // EP_AGORA_ENABLE_CELL

#endif // MBED_CONF_NSAPI_PRESENT
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2019 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 ONBOARD_TELIT_ME910_
#define ONBOARD_TELIT_ME910_

#include "TELIT_ME910.h"

namespace mbed {

class ONBOARD_TELIT_ME910 : public TELIT_ME910 {
public:
ONBOARD_TELIT_ME910(FileHandle *fh);

virtual nsapi_error_t init();
virtual nsapi_error_t hard_power_on();
virtual nsapi_error_t hard_power_off();
virtual nsapi_error_t soft_power_on();
virtual nsapi_error_t soft_power_off();
};

} // namespace mbed

#endif // ONBOARD_TELIT_ME910_
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "ep-agora",
"config": {
"enable-cell" : {
"help" : "Enable the cell module on the EP_AGORA board",
"macro_name" : "EP_AGORA_ENABLE_CELL",
"value" : true
}
},
"target_overrides": {
"EP_AGORA": {
"target.network-default-interface-type": "CELLULAR"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2019 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 "cellular/onboard_modem_api.h"
#include "gpio_api.h"
#include "platform/mbed_thread.h"
#include "PinNames.h"

#if MODEM_ON_BOARD

static void press_power_button(int time_ms)
{
gpio_t gpio;

gpio_init_out_ex(&gpio, PIN_NAME_CELL_ON_OFF, 1);
gpio_write(&gpio, 0);
thread_sleep_for(time_ms);
gpio_write(&gpio, 1);
}

void onboard_modem_init()
{
gpio_t gpio;

gpio_init_out_ex(&gpio, PIN_NAME_CELL_POWER_ENABLE, 0);
gpio_write(&gpio, 1);
}

void onboard_modem_deinit()
{
gpio_t gpio;

gpio_init_out_ex(&gpio, PIN_NAME_CELL_POWER_ENABLE, 1);
gpio_write(&gpio, 0);
}

void onboard_modem_power_up()
{
/* keep the power line low for 5 seconds */
press_power_button(5000);
/* give modem a little time to respond */
thread_sleep_for(20 * 1000);
}

void onboard_modem_power_down()
{
gpio_t gpio;

gpio_init_out_ex(&gpio, PIN_NAME_CELL_ON_OFF, 0);
/* keep the power line low for more than 3 seconds.
* If 3G_ON_OFF pin is kept low for more than a second, a controlled disconnect and shutdown takes
* place, Due to the network disconnect, shut-off can take up to 30 seconds. However, we wait for 10
* seconds only */
thread_sleep_for(10 * 1000);
}
#endif //MODEM_ON_BOARD
#endif //MBED_CONF_NSAPI_PRESENT
10 changes: 7 additions & 3 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -9338,18 +9338,22 @@
"config": {
"modem_is_on_board": {
"help": "Value: Tells the build system that the modem is on-board as oppose to a plug-in shield/module.",
"value": 0,
"value": 1,
"macro_name": "MODEM_ON_BOARD"
},
"modem_data_connection_type": {
"help": "Value: Defines how an on-board modem is wired up to the MCU, e.g., data connection can be a UART or USB and so forth.",
"value": 0,
"value": 1,
"macro_name": "MODEM_ON_BOARD_UART"
}
},
"components_add": ["SPIF"],
"components_remove": ["QSPIF"],
"release_versions": ["5"]
"release_versions": ["5"],
"macros_add": [
"CONFIG_GPIO_AS_PINRESET",
"NRF52_ERRATA_20"
]
},
"IM880B": {
"inherits": ["FAMILY_STM32"],
Expand Down