Skip to content

Riot Micro cellular device #11119

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 2 commits into from
Aug 7, 2019
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
105 changes: 105 additions & 0 deletions features/cellular/framework/targets/RiotMicro/AT/RM1000_AT.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* 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.
*/

#include "RM1000_AT.h"

#include "RM1000_AT_CellularContext.h"
#include "RM1000_AT_CellularNetwork.h"

#include "mbed-trace/mbed_trace.h"
#ifndef TRACE_GROUP
#define TRACE_GROUP "RIOT"
#endif // TRACE_GROUP

using namespace mbed;
using namespace events;
static const uint16_t retry_timeout[] = {1, 2, 4};
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
AT_CellularNetwork::RegistrationModeLAC,// C_EREG
AT_CellularNetwork::RegistrationModeDisable,// C_GREG
AT_CellularNetwork::RegistrationModeDisable,// C_REG
0, // AT_CGSN_WITH_TYPE
0, // AT_CGDATA
0, // AT_CGAUTH
0, // AT_CNMI
0, // AT_CSMP
0, // AT_CMGF
0, // AT_CSDH
1, // PROPERTY_IPV4_STACK
1, // PROPERTY_IPV6_STACK
1, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
0, // PROPERTY_AT_CGEREP
};

RM1000_AT::RM1000_AT(FileHandle *fh) : AT_CellularDevice(fh)
{
tr_debug("RM1000_AT::RM1000_AT");
AT_CellularBase::set_cellular_properties(cellular_properties);
set_retry_timeout_array(retry_timeout, sizeof(retry_timeout) / sizeof(retry_timeout[0]));
}

AT_CellularNetwork *RM1000_AT::open_network_impl(ATHandler &at)
{
tr_debug("RM1000_AT::open_network_impl");
return new RM1000_AT_CellularNetwork(at);
}

AT_CellularContext *RM1000_AT::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
{
tr_debug("RM1000_AT::create_context_impl");
return new RM1000_AT_CellularContext(at, this, apn, cp_req, nonip_req);
}

nsapi_error_t RM1000_AT::init()
{
tr_debug("RM1000_AT::init");

_at->lock();
_at->flush();
_at->cmd_start("ATE0"); // echo off
_at->cmd_stop_read_resp();

_at->cmd_start("AT+SIM=physical");
_at->cmd_stop_read_resp();

_at->set_at_timeout(5000);
_at->cmd_start("AT+CFUN=1"); // set full functionality
_at->cmd_stop_read_resp();

_at->cmd_start("AT+VERBOSE=0"); // verbose responses
_at->cmd_stop_read_resp();

return _at->unlock_return_error();
}

#if MBED_CONF_RM1000_AT_PROVIDE_DEFAULT
#include "UARTSerial.h"
CellularDevice *CellularDevice::get_default_instance()
{
tr_debug("Calling CellularDevice::get_default_instance from RM1000_AT");

static UARTSerial serial(MBED_CONF_RM1000_AT_TX, MBED_CONF_RM1000_AT_RX, MBED_CONF_RM1000_AT_BAUDRATE);
#if defined (MBED_CONF_RM1000_AT_RTS) && defined(MBED_CONF_RM1000_AT_CTS)
tr_debug("RM1000_AT flow control: RTS %d CTS %d", MBED_CONF_RM1000_AT_RTS, MBED_CONF_RM1000_AT_CTS);
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_RM1000_AT_RTS, MBED_CONF_RM1000_AT_CTS);
#endif
static RM1000_AT device(&serial);
return &device;
}
#endif

41 changes: 41 additions & 0 deletions features/cellular/framework/targets/RiotMicro/AT/RM1000_AT.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* 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 RM1000_AT_H_
#define RM1000_AT_H_

#include "AT_CellularDevice.h"

namespace mbed {

class RM1000_AT : public AT_CellularDevice {
public:
RM1000_AT(FileHandle *fh);

protected: // AT_CellularDevice
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);

virtual nsapi_error_t init();

public: // NetworkInterface
void handle_urc(FileHandle *fh);
};

} // namespace mbed

#endif // RM1000_AT_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* 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.
*/
#include "RM1000_AT_CellularContext.h"

#include "APN_db.h"
#include "RM1000_AT_CellularStack.h"
#include "mbed-trace/mbed_trace.h"
#ifndef TRACE_GROUP
#define TRACE_GROUP "RIOT"
#endif // TRACE_GROUP

namespace mbed {

RM1000_AT_CellularContext::RM1000_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
AT_CellularContext(at, device, apn, cp_req, nonip_req)
{
tr_debug("Calling RM1000_AT_CellularContext::RM1000_AT_CellularContext");
}

RM1000_AT_CellularContext::~RM1000_AT_CellularContext()
{
tr_debug("Calling RM1000_AT_CellularContext::~RM1000_AT_CellularContext");
}

NetworkStack *RM1000_AT_CellularContext::get_stack()
{
tr_debug("Calling RM1000_AT_CellularContext::get_stack");

if (_pdp_type == NON_IP_PDP_TYPE || _cp_in_use) {
tr_error("Requesting stack for NON-IP context! Should request control plane netif: get_cp_netif()");
return NULL;
}
if (!_stack) {
_stack = new RM1000_AT_CellularStack(_at, _cid, (nsapi_ip_stack_t)_pdp_type);
}

return _stack;
}

} /* namespace mbed */
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* 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 RM1000_AT_CELLULARCONTEXT_H_
#define RM1000_AT_CELLULARCONTEXT_H_

#include "AT_CellularContext.h"

namespace mbed {

class RM1000_AT_CellularContext: public AT_CellularContext {
public:
RM1000_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false);
virtual ~RM1000_AT_CellularContext();

protected:
virtual NetworkStack *get_stack();
};

} /* namespace mbed */

#endif // RM1000_AT_CELLULARCONTEXT_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* 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.
*/

#include <stdlib.h>
#include "rtos.h"
#include "CellularCommon.h"
#include "RM1000_AT_CellularNetwork.h"
#include "platform/mbed_wait_api.h"

#include "mbed-trace/mbed_trace.h"
#ifndef TRACE_GROUP
#define TRACE_GROUP "RIOT"
#endif // TRACE_GROUP
using namespace mbed;

// Callback for MODEM faults URC.
void RM1000_AT_CellularNetwork::MODEM_FAULT_URC()
{
tr_debug("RM1000_AT_CellularNetwork::ASSERTED_URC");
_connect_status = NSAPI_STATUS_DISCONNECTED;
if (_connection_status_cb) {
_connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
}
}

RM1000_AT_CellularNetwork::RM1000_AT_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler)
{
tr_debug("RM1000_AT_CellularNetwork::RM1000_B0_CellularNetwork");
_op_act = RAT_UNKNOWN;
_at.set_urc_handler("ASSERTED!", callback(this, &RM1000_AT_CellularNetwork::MODEM_FAULT_URC));
_at.set_urc_handler("ERRCODE:", callback(this, &RM1000_AT_CellularNetwork::MODEM_FAULT_URC));
_at.set_urc_handler("Halt the processor", callback(this, &RM1000_AT_CellularNetwork::MODEM_FAULT_URC));
}

RM1000_AT_CellularNetwork::~RM1000_AT_CellularNetwork()
{
tr_debug("RM1000_AT_CellularNetwork::~RM1000_B0_CellularNetwork");

_at.set_urc_handler("ASSERTED!", NULL);
_at.set_urc_handler("ERRCODE:", NULL);
_at.set_urc_handler("Halt the processor", NULL);
}

nsapi_error_t RM1000_AT_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat)
{
nsapi_error_t ret = NSAPI_ERROR_OK;

tr_debug("RM1000_AT_CellularNetwork::set_access_technology_impl %d", opRat);

switch (opRat) {
case RAT_NB1:
break;
default: {
_op_act = RAT_UNKNOWN;
ret = NSAPI_ERROR_UNSUPPORTED;
}
}

return (ret);
}

nsapi_error_t RM1000_AT_CellularNetwork::set_registration_urc(RegistrationType type, bool urc_on)
{
tr_debug("RM1000_AT_CellularNetwork::set_registration_urc");

int index = (int)type;
MBED_ASSERT(index >= 0 && index < C_MAX);

RegistrationMode mode = (RegistrationMode)get_property((AT_CellularBase::CellularProperty)type);
if (mode == RegistrationModeDisable) {
return NSAPI_ERROR_UNSUPPORTED;
} else {
return NSAPI_ERROR_OK; /* FIXME use at commands */
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* 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 RM1000_AT_CELLULAR_NETWORK_H_
#define RM1000_AT_CELLULAR_NETWORK_H_

#include "AT_CellularNetwork.h"

namespace mbed {

class RM1000_AT_CellularNetwork : public AT_CellularNetwork {
public:
RM1000_AT_CellularNetwork(ATHandler &atHandler);
virtual ~RM1000_AT_CellularNetwork();

virtual nsapi_error_t set_registration_urc(RegistrationType type, bool on);

protected:
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);
private:
// URC handlers
void MODEM_FAULT_URC();
};

} // namespace mbed

#endif // RM1000_AT_CELLULAR_NETWORK_H_
Loading