Merge pull request #11119 from Reda-RM/master

Riot Micro cellular device
pull/11179/head
Seppo Takalo 2019-08-07 14:07:27 +03:00 committed by GitHub
commit 5f6379a55d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 1421 additions and 0 deletions

View File

@ -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

View File

@ -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_

View File

@ -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 */

View File

@ -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_

View File

@ -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 */
}
}

View File

@ -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_

View File

@ -0,0 +1,374 @@
/*
* 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_CellularStack.h"
#include "mbed_poll.h"
#include "mbed-trace/mbed_trace.h"
#ifndef TRACE_GROUP
#define TRACE_GROUP "RIOT"
#endif // TRACE_GROUP
using namespace mbed;
using namespace mbed_cellular_util;
RM1000_AT_CellularStack::RM1000_AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : AT_CellularStack(atHandler, cid, stack_type)
{
tr_debug("RM1000_AT_CellularStack::RM1000_AT_CellularStack");
// URC handlers for sockets
_at.set_urc_handler("+RUSORCV:", callback(this, &RM1000_AT_CellularStack::RUSORCV_URC));
_at.set_urc_handler("+RUSOCL:", callback(this, &RM1000_AT_CellularStack::RUSOCL_URC));
}
RM1000_AT_CellularStack::~RM1000_AT_CellularStack()
{
tr_debug("RM1000_AT_CellularStack::~RM1000_AT_CellularStack");
_at.set_urc_handler("+RUSORCV:", NULL);
_at.set_urc_handler("+RUSOCL:", NULL);
}
nsapi_error_t RM1000_AT_CellularStack::socket_listen(nsapi_socket_t handle, int backlog)
{
tr_debug("RM1000_AT_CellularStack::socket_listen");
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t RM1000_AT_CellularStack::socket_accept(void *server, void **socket, SocketAddress *addr)
{
tr_debug("RM1000_AT_CellularStack::socket_accept");
return NSAPI_ERROR_UNSUPPORTED;
}
// Callback for Socket Receive URC.
void RM1000_AT_CellularStack::RUSORCV_URC()
{
int a, b;
CellularSocket *socket;
a = _at.read_int();
b = _at.read_int();
socket = find_socket(a);
if (socket != NULL) {
socket->pending_bytes = b;
// No debug prints here as they can affect timing
// and cause data loss in UARTSerial
if (socket->_cb != NULL) {
socket->_cb(socket->_data);
}
}
}
// Callback for Socket Close URC.
void RM1000_AT_CellularStack::RUSOCL_URC()
{
int a;
CellularSocket *socket;
a = _at.read_int();
socket = find_socket(a);
clear_socket(socket);
}
int RM1000_AT_CellularStack::get_max_socket_count()
{
tr_debug("RM1000_AT_CellularStack::get_max_socket_count");
return RM1000_MAX_SOCKET;
}
bool RM1000_AT_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
{
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
}
nsapi_error_t RM1000_AT_CellularStack::create_socket_impl(CellularSocket *socket)
{
tr_debug("RM1000_AT_CellularStack::create_socket_impl");
int sock_id = SOCKET_UNUSED;
_at.lock();
if (socket->proto == NSAPI_UDP) {
_at.cmd_start("AT+RSOCR=0");
_at.cmd_stop();
_at.resp_start("+RSOCR:");
sock_id = _at.read_int();
_at.resp_stop();
} else if (socket->proto == NSAPI_TCP) {
_at.cmd_start("AT+RSOCR=1");
_at.cmd_stop();
_at.resp_start("+RSOCR:");
sock_id = _at.read_int();
_at.resp_stop();
} // Unsupported protocol is checked in "is_protocol_supported" function
if ((_at.get_last_error() != NSAPI_ERROR_OK) || (sock_id == -1)) {
_at.unlock();
tr_error("RM1000_AT_CellularStack::create_socket_impl error sock_id=%d err=%d", sock_id, _at.get_last_error());
return NSAPI_ERROR_NO_SOCKET;
}
_at.unlock();
// Check for duplicate socket id delivered by modem
for (int i = 0; i < RM1000_MAX_SOCKET; i++) {
CellularSocket *sock = _socket[i];
if (sock && sock != socket && sock->id == sock_id) {
return NSAPI_ERROR_NO_SOCKET;
}
}
socket->id = sock_id;
return NSAPI_ERROR_OK;
}
nsapi_error_t RM1000_AT_CellularStack::socket_connect(nsapi_socket_t handle, const SocketAddress &addr)
{
tr_debug("RM1000_AT_CellularStack::socket_connect");
CellularSocket *socket = (CellularSocket *)handle;
if (socket) {
if (socket->id == SOCKET_UNUSED) {
nsapi_error_t err = create_socket_impl(socket);
if (err != NSAPI_ERROR_OK) {
return err;
}
}
} else {
return NSAPI_ERROR_DEVICE_ERROR;
}
_at.lock();
_at.cmd_start("AT+RSOCO=");
_at.write_int(socket->id);
_at.write_string(addr.get_ip_address(), false);
_at.write_int(addr.get_port());
_at.cmd_stop();
_at.resp_start("+RSOCO:");
int socket_id = _at.read_int();
_at.resp_stop();
nsapi_error_t error = _at.get_last_error();
_at.unlock();
if ((error == NSAPI_ERROR_OK) && (socket_id == socket->id)) {
socket->remoteAddress = addr;
socket->connected = true;
return NSAPI_ERROR_OK;
}
return NSAPI_ERROR_NO_CONNECTION;
}
nsapi_size_or_error_t RM1000_AT_CellularStack::socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
const void *data, nsapi_size_t size)
{
tr_debug("RM1000_AT_CellularStack::socket_sendto_impl");
int sent_len = 0;
pollfh fhs;
fhs.fh = _at.get_file_handle();
fhs.events = POLLIN;
bool success = true;
const char *buf = (const char *) data;
nsapi_size_t blk = RM1000_MAX_PACKET_SIZE;
nsapi_size_t count = size;
while ((count > 0) && success) {
if (count < blk) {
blk = count;
}
_at.cmd_start("AT+RSOSND=");
_at.write_int(socket->id);
_at.write_int(blk);
if (socket->proto == NSAPI_UDP) {
_at.write_string(address.get_ip_address(), false);
_at.write_int(address.get_port());
}
_at.cmd_stop();
(void)poll(&fhs, 1, 50);
_at.write_bytes((uint8_t *)buf, blk);
_at.resp_start("+RSOSND:");
_at.skip_param(); // skip socket id
sent_len = _at.read_int();
_at.resp_stop();
if ((sent_len >= (int) blk) &&
(_at.get_last_error() == NSAPI_ERROR_OK)) {
} else {
success = false;
}
buf += blk;
count -= blk;
}
if (success && _at.get_last_error() == NSAPI_ERROR_OK) {
return size - count;
}
return _at.get_last_error();
}
nsapi_size_or_error_t RM1000_AT_CellularStack::socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
void *buffer, nsapi_size_t size)
{
tr_debug("RM1000_AT_CellularStack::socket_recvfrom_impl");
nsapi_size_or_error_t nsapi_error_size = NSAPI_ERROR_DEVICE_ERROR;
bool success = true;
nsapi_size_t read_blk;
nsapi_size_t count = 0;
nsapi_size_t rsorcv_sz;
char ipAddress[NSAPI_IP_SIZE];
int port = 0;
Timer timer;
if (socket->pending_bytes == 0) {
_at.process_oob();
if (socket->pending_bytes == 0) {
return NSAPI_ERROR_WOULD_BLOCK;
}
}
timer.start();
while (success && (size > 0)) {
read_blk = RM1000_MAX_PACKET_SIZE;
if (read_blk > size) {
read_blk = size;
}
if (socket->pending_bytes > 0) {
_at.cmd_start("AT+RSORCV=");
_at.write_int(socket->id);
_at.write_int(read_blk);
_at.cmd_stop();
_at.resp_start("+RSORCV:");
_at.skip_param(); // receiving socket id
rsorcv_sz = _at.read_int();
if (socket->proto == NSAPI_UDP) {
_at.read_string(ipAddress, sizeof(ipAddress));
port = _at.read_int();
}
if (rsorcv_sz > size) {
rsorcv_sz = size;
}
_at.read_bytes((uint8_t *)buffer + count, rsorcv_sz);
_at.resp_stop();
// Must use what +RSORCV returns here as it may be less or more than we asked for
if (rsorcv_sz > socket->pending_bytes) {
socket->pending_bytes = 0;
} else {
socket->pending_bytes -= rsorcv_sz;
}
if (rsorcv_sz > 0) {
count += rsorcv_sz;
size -= rsorcv_sz;
} else {
// read() should not fail
success = false;
}
} else if (timer.read_ms() < SOCKET_TIMEOUT) {
// Wait for URCs
_at.process_oob();
} else {
if (count == 0) {
// Timeout with nothing received
nsapi_error_size = NSAPI_ERROR_WOULD_BLOCK;
success = false;
}
size = 0; // This simply to cause an exit
}
}
timer.stop();
if (!count || (_at.get_last_error() != NSAPI_ERROR_OK)) {
return NSAPI_ERROR_WOULD_BLOCK;
} else {
nsapi_error_size = count;
}
if (success && socket->proto == NSAPI_UDP && address) {
address->set_ip_address(ipAddress);
address->get_ip_address();
address->set_port(port);
}
return nsapi_error_size;
}
nsapi_error_t RM1000_AT_CellularStack::socket_close_impl(int sock_id)
{
tr_debug("RM1000_AT_CellularStack::socket_close_impl");
_at.cmd_start("AT+RSOCL=");
_at.write_int(sock_id);
_at.cmd_stop_read_resp();
return _at.get_last_error();
}
// Clear out the storage for a socket
void RM1000_AT_CellularStack::clear_socket(CellularSocket *socket)
{
if (socket != NULL) {
socket->id = SOCKET_UNUSED;
socket->pending_bytes = 0;
socket->_cb = NULL;
socket->_data = NULL;
}
}
nsapi_error_t RM1000_AT_CellularStack::gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version, const char *interface_name)
{
tr_debug("RM1000_AT_CellularStack::gethostbyname");
char ipAddress[NSAPI_IP_SIZE];
nsapi_error_t err = NSAPI_ERROR_NO_CONNECTION;
_at.lock();
if (address->set_ip_address(host)) {
err = NSAPI_ERROR_OK;
} else {
// This interrogation can sometimes take longer than the usual 8 seconds
_at.cmd_start("AT+RDNS=");
_at.write_string(host, false);
_at.cmd_stop();
_at.set_at_timeout(70000);
_at.resp_start("+RDNS:");
if (_at.info_resp()) {
_at.read_string(ipAddress, sizeof(ipAddress));
if (address->set_ip_address(ipAddress)) {
err = NSAPI_ERROR_OK;
}
}
_at.resp_stop();
_at.restore_at_timeout();
}
_at.unlock();
return err;
}

View File

@ -0,0 +1,97 @@
/*
* 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_CELLULARSTACK_H_
#define RM1000_AT_CELLULARSTACK_H_
#include "AT_CellularStack.h"
#include "CellularUtil.h"
#include "mbed_wait_api.h"
#include "drivers/Timer.h"
namespace mbed {
class RM1000_AT_CellularStack : public AT_CellularStack {
public:
RM1000_AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type);
virtual ~RM1000_AT_CellularStack();
virtual nsapi_error_t gethostbyname(const char *host,
SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC, const char *interface_name = NULL);
protected:
virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog);
virtual nsapi_error_t socket_accept(nsapi_socket_t server,
nsapi_socket_t *handle, SocketAddress *address = 0);
protected: // AT_CellularStack
/** The profile to use (on board the modem).
*/
#define PROFILE "0"
/** Socket "unused" value.
*/
static const int SOCKET_UNUSED = -1;
/** Socket timeout value in milliseconds.
* Note: the sockets layer above will retry the
* call to the functions here when they return NSAPI_ERROR_WOULD_BLOCK
* and the user has set a larger timeout or full blocking.
*/
static const int SOCKET_TIMEOUT = 1000;
/** Maximum allowed sockets.
*/
static const int RM1000_MAX_SOCKET = 7;
/** The maximum number of bytes in a packet that can be write/read from
* the AT interface in one go.
*/
static const int RM1000_MAX_PACKET_SIZE = 1024;
virtual int get_max_socket_count();
virtual bool is_protocol_supported(nsapi_protocol_t protocol);
virtual nsapi_error_t create_socket_impl(CellularSocket *socket);
virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address);
virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
const void *data, nsapi_size_t size);
virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
void *buffer, nsapi_size_t size);
virtual nsapi_error_t socket_close_impl(int sock_id);
private:
// URC handlers
void RUSORCV_URC();
void RUSOCL_URC();
/** Clear out the storage for a socket.
*
* @param id Cellular Socket.
* @return None
*/
void clear_socket(CellularSocket *socket);
};
} // namespace mbed
#endif /* RM1000_AT_CELLULARSTACK_H_ */

View File

@ -0,0 +1,29 @@
{
"name": "RM1000_AT",
"config": {
"tx": {
"help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.",
"value": null
},
"rx": {
"help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.",
"value": null
},
"rts": {
"help": "RTS pin for serial connection",
"value": null
},
"cts": {
"help": "CTS pin for serial connection",
"value": null
},
"baudrate" : {
"help": "Serial connection baud rate",
"value": 230400
},
"provide-default": {
"help": "Provide as default CellularDevice [true/false]",
"value": false
}
}
}

View File

@ -0,0 +1,79 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 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_RM1000_AT.h"
#include "cellular/onboard_modem_api.h"
#include "UARTSerial.h"
#include "mbed-trace/mbed_trace.h"
#ifndef TRACE_GROUP
#define TRACE_GROUP "RIOTMICRO"
#endif // TRACE_GROUP
using namespace mbed;
ONBOARD_RM1000_AT::ONBOARD_RM1000_AT(FileHandle *fh) : RM1000_AT(fh)
{
}
nsapi_error_t ONBOARD_RM1000_AT::hard_power_on()
{
tr_debug("Calling ONBOARD_RM1000_AT::hard_power_on");
return NSAPI_ERROR_OK;
}
nsapi_error_t ONBOARD_RM1000_AT::hard_power_off()
{
tr_debug("Calling ONBOARD_RM1000_AT::hard_power_off");
return NSAPI_ERROR_OK;
}
nsapi_error_t ONBOARD_RM1000_AT::soft_power_on()
{
tr_debug("Calling ONBOARD_RM1000_AT::soft_power_on");
::onboard_modem_init();
return NSAPI_ERROR_OK;
}
nsapi_error_t ONBOARD_RM1000_AT::soft_power_off()
{
tr_debug("Calling ONBOARD_RM1000_AT::soft_power_off");
::onboard_modem_deinit();
return NSAPI_ERROR_OK;
}
CellularDevice *CellularDevice::get_target_default_instance()
{
tr_debug("Calling CellularDevice::get_target_default_instance from ONBOARD_RM1000_AT");
static UARTSerial serial(MDM_UART3_TXD, MDM_UART3_RXD, 230400);
#if DEVICE_SERIAL_FC
if (MDM_UART3_RTS != NC && MDM_UART3_CTS != NC) {
tr_debug("Modem flow control: RTS %d CTS %d", MDM_UART3_RTS, MDM_UART3_CTS);
serial.set_flow_control(SerialBase::RTSCTS, MDM_UART3_RTS, MDM_UART3_CTS);
}
#endif
static ONBOARD_RM1000_AT device(&serial);
return &device;
}
#endif // MBED_CONF_NSAPI_PRESENT

View File

@ -0,0 +1,38 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 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.
*/
#ifndef ONBOARD_RM1000_AT_
#define ONBOARD_RM1000_AT_
#include "RM1000_AT.h"
namespace mbed
{
class ONBOARD_RM1000_AT : public RM1000_AT
{
public:
ONBOARD_RM1000_AT(FileHandle *fh);
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_RM1000_AT_

View File

@ -0,0 +1,138 @@
#ifndef MBED_PINNAMES_H
#define MBED_PINNAMES_H
#include "cmsis.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
PIN_INPUT,
PIN_OUTPUT
} PinDirection;
#define PORT_SHIFT 3
typedef enum {
// nRF52 pin names
p0 = 0,
p1 = 1,
p2 = 2,
p3 = 3,
p4 = 4,
p5 = 5,
p6 = 6,
p7 = 7,
p8 = 8,
p9 = 9,
p10 = 10,
p11 = 11,
p12 = 12,
p13 = 13,
p14 = 14,
p15 = 15,
p16 = 16,
p17 = 17,
p18 = 18,
p19 = 19,
p20 = 20,
p21 = 21,
p22 = 22,
p23 = 23,
p24 = 24,
p25 = 25,
p26 = 26,
p27 = 27,
p28 = 28,
p29 = 29,
p30 = 30,
p31 = 31,
NC = (int)0xFFFFFFFF, // Not connected
P0_0 = p0,
P0_1 = p1,
P0_2 = p2,
P0_3 = p3,
P0_4 = p4,
P0_5 = p5,
P0_6 = p6,
P0_7 = p7,
P0_8 = p8,
P0_9 = p9,
P0_10 = p10,
P0_11 = p11,
P0_12 = p12,
P0_13 = p13,
P0_14 = p14,
P0_15 = p15,
P0_16 = p16,
P0_17 = p17,
P0_18 = p18,
P0_19 = p19,
P0_20 = p20,
P0_21 = p21,
P0_22 = p22,
P0_23 = p23,
P0_24 = p24,
P0_25 = p25,
P0_26 = p26,
P0_27 = p27,
P0_28 = p28,
P0_29 = p29,
P0_30 = p30,
P0_31 = p31,
MDMCHEN = p13,
MDMREMAP = p14,
MDMRST = p25,
MDM_UART0_TXD = p15,
MDM_UART0_RXD = p16,
MDM_UART1_TXD = p17,
MDM_UART1_RXD = p18,
MDM_UART3_TXD = p19,
MDM_UART3_RXD = p20,
MDM_UART3_RTS = NC,
MDM_UART3_CTS = NC,
LED1 = P0_10,
LED2 = P0_22,
RX_PIN_NUMBER = NC,
TX_PIN_NUMBER = NC,
CTS_PIN_NUMBER = NC,
RTS_PIN_NUMBER = NC,
// mBed interface Pins
USBTX = TX_PIN_NUMBER,
USBRX = RX_PIN_NUMBER,
STDIO_UART_TX = TX_PIN_NUMBER,
STDIO_UART_RX = RX_PIN_NUMBER,
STDIO_UART_CTS = CTS_PIN_NUMBER,
STDIO_UART_RTS = RTS_PIN_NUMBER,
A0 = NC,
A1 = p4,
A2 = p28,
A3 = p29,
A4 = p30,
A5 = p31,
} PinName;
typedef enum {
PullNone = 0,
PullDown = 1,
PullUp = 3,
PullDefault = PullUp
} PinMode;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,141 @@
#ifndef MBED_PINNAMES_H
#define MBED_PINNAMES_H
#include "cmsis.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
PIN_INPUT,
PIN_OUTPUT
} PinDirection;
#define PORT_SHIFT 3
typedef enum {
// nRF52 pin names
p0 = 0,
p1 = 1,
p2 = 2,
p3 = 3,
p4 = 4,
p5 = 5,
p6 = 6,
p7 = 7,
p8 = 8,
p9 = 9,
p10 = 10,
p11 = 11,
p12 = 12,
p13 = 13,
p14 = 14,
p15 = 15,
p16 = 16,
p17 = 17,
p18 = 18,
p19 = 19,
p20 = 20,
p21 = 21,
p22 = 22,
p23 = 23,
p24 = 24,
p25 = 25,
p26 = 26,
p27 = 27,
p28 = 28,
p29 = 29,
p30 = 30,
p31 = 31,
NC = (int)0xFFFFFFFF, // Not connected
P0_0 = p0,
P0_1 = p1,
P0_2 = p2,
P0_3 = p3,
P0_4 = p4,
P0_5 = p5,
P0_6 = p6,
P0_7 = p7,
P0_8 = p8,
P0_9 = p9,
P0_10 = p10,
P0_11 = p11,
P0_12 = p12,
P0_13 = p13,
P0_14 = p14,
P0_15 = p15,
P0_16 = p16,
P0_17 = p17,
P0_18 = p18,
P0_19 = p19,
P0_20 = p20,
P0_21 = p21,
P0_22 = p22,
P0_23 = p23,
P0_24 = p24,
P0_25 = p25,
P0_26 = p26,
P0_27 = p27,
P0_28 = p28,
P0_29 = p29,
P0_30 = p30,
P0_31 = p31,
MDMCHEN = p13,
MDMREMAP = p14,
MDMRST = p25,
MDM_UART0_TXD = p15,
MDM_UART0_RXD = p16,
MDM_UART1_TXD = p17,
MDM_UART1_RXD = p18,
MDM_UART3_TXD = p19,
MDM_UART3_RXD = p20,
MDM_UART3_RTS = NC,
MDM_UART3_CTS = NC,
LED1 = P0_10,
LED2 = P0_22,
RX_PIN_NUMBER = NC,
TX_PIN_NUMBER = NC,
CTS_PIN_NUMBER = NC,
RTS_PIN_NUMBER = NC,
// mBed interface Pins
USBTX = TX_PIN_NUMBER,
USBRX = RX_PIN_NUMBER,
STDIO_UART_TX = TX_PIN_NUMBER,
STDIO_UART_RX = RX_PIN_NUMBER,
STDIO_UART_CTS = CTS_PIN_NUMBER,
STDIO_UART_RTS = RTS_PIN_NUMBER,
I2C_SDA0 = p12,
I2C_SCL0 = p11,
A0 = p2,
A1 = p28,
A2 = p4,
A3 = p29,
A4 = p30,
A5 = p31,
} PinName;
typedef enum {
PullNone = 0,
PullDown = 1,
PullUp = 3,
PullDefault = PullUp
} PinMode;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,23 @@
// The 'features' section in 'target.json' is now used to create the device's hardware preprocessor switches.
// Check the 'features' section of the target description in 'targets.json' for more details.
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 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.
*/
#ifndef MBED_DEVICE_H
#define MBED_DEVICE_H
#include "objects.h"
#endif

View File

@ -0,0 +1,105 @@
/* 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 "mbed-trace/mbed_trace.h"
#ifndef TRACE_GROUP
#define TRACE_GROUP "RIOT"
#endif // TRACE_GROUP
#include "onboard_modem_api.h"
#include "gpio_api.h"
#include "PinNames.h"
#include "hal/serial_api.h"
#include "platform/mbed_thread.h"
#if MODEM_ON_BOARD
void onboard_modem_init()
{
char promptEnd;
tr_debug("onboard_modem_init");
gpio_t gpio;
gpio_init_out_ex(&gpio, MDMCHEN, 0);
gpio_init_out_ex(&gpio, MDMREMAP, 0);
// Take us out of reset
gpio_init_out_ex(&gpio, MDMRST, 0);
thread_sleep_for(100);
gpio_write(&gpio, 1);
/* Initialize UART1 pins to allow collecting logs from a PC */
gpio_init_in_ex(&gpio, MDM_UART1_TXD, PullNone);
gpio_init_in_ex(&gpio, MDM_UART1_RXD, PullNone);
serial_t bootrom_uart;
serial_init(&bootrom_uart, MDM_UART0_TXD, MDM_UART0_RXD);
serial_baud(&bootrom_uart, 115200);
tr_debug("%s: MODEM RESET", __func__);
serial_getc(&bootrom_uart);
tr_debug("%s: MODEM first activity after reset", __func__);
/* Wait for some dots */
for (int i = 0; i < 3; i++) {
do {
promptEnd = serial_getc(&bootrom_uart);
} while ('.' != promptEnd);
}
serial_putc(&bootrom_uart, ' ');
/* Wait for bootrom prompt */
for (int i = 0; i < 2; i++) {
do {
promptEnd = serial_getc(&bootrom_uart);
} while ('>' != promptEnd);
}
serial_putc(&bootrom_uart, '6');
serial_free(&bootrom_uart);
/* Wait for stack prompt */
tr_debug("%s: Wait for stack prompt", __func__);
thread_sleep_for(100);
serial_t cli_uart;
serial_init(&cli_uart, MDM_UART3_TXD, MDM_UART3_RXD);
serial_baud(&cli_uart, 230400); /* TODO make baud rate configurable */
do {
promptEnd = serial_getc(&cli_uart);
} while ('>' != promptEnd);
serial_free(&cli_uart);
tr_debug("%s: MODEM CLI prompt reached", __func__);
tr_debug("Reset RM1000 completed");
}
void onboard_modem_deinit()
{
tr_debug("onboard_modem_deinit");
gpio_t gpio;
// Back into reset
gpio_init_out_ex(&gpio, MDMRST, 0);
}
#endif //MODEM_ON_BOARD
#endif //MBED_CONF_NSAPI_PRESENT

View File

@ -7222,6 +7222,38 @@
],
"device_has_remove": ["ITM"]
},
"RIOT_MICRO_MODULE": {
"inherits": ["MCU_NRF52832"],
"release_versions": ["5"],
"public": false,
"config": {
"modem_is_on_board": {
"help": "Value: Tells the build system that the modem is on-board as opposed to a plug-in shield/module.",
"value": 1,
"macro_name": "MODEM_ON_BOARD"
},
"modem_data_connection_type": {
"help": "Value: Defines how the modem is wired up to the MCU, e.g., data connection can be a UART or USB and so forth.",
"value": 1,
"macro_name": "MODEM_ON_BOARD_UART"
}
},
"overrides": {
"network-default-interface-type": "CELLULAR"
},
"bootloader_supported": false
},
"RM6100": {
"inherits": ["RIOT_MICRO_MODULE"],
"device_name": "nRF52832_xxAA"
},
"RM7100": {
"inherits": ["RIOT_MICRO_MODULE"],
"macros_add": [
"CONFIG_NFCT_PINS_AS_GPIOS"
],
"device_name": "nRF52832_xxAA"
},
"SDT52832B": {
"inherits": ["MCU_NRF52832"],
"release_versions": ["5"],