Skip to content

Commit 5f6379a

Browse files
author
Seppo Takalo
authored
Merge pull request #11119 from Reda-RM/master
Riot Micro cellular device
2 parents 976c30c + ef1d977 commit 5f6379a

File tree

16 files changed

+1421
-0
lines changed

16 files changed

+1421
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "RM1000_AT.h"
19+
20+
#include "RM1000_AT_CellularContext.h"
21+
#include "RM1000_AT_CellularNetwork.h"
22+
23+
#include "mbed-trace/mbed_trace.h"
24+
#ifndef TRACE_GROUP
25+
#define TRACE_GROUP "RIOT"
26+
#endif // TRACE_GROUP
27+
28+
using namespace mbed;
29+
using namespace events;
30+
static const uint16_t retry_timeout[] = {1, 2, 4};
31+
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
32+
AT_CellularNetwork::RegistrationModeLAC,// C_EREG
33+
AT_CellularNetwork::RegistrationModeDisable,// C_GREG
34+
AT_CellularNetwork::RegistrationModeDisable,// C_REG
35+
0, // AT_CGSN_WITH_TYPE
36+
0, // AT_CGDATA
37+
0, // AT_CGAUTH
38+
0, // AT_CNMI
39+
0, // AT_CSMP
40+
0, // AT_CMGF
41+
0, // AT_CSDH
42+
1, // PROPERTY_IPV4_STACK
43+
1, // PROPERTY_IPV6_STACK
44+
1, // PROPERTY_IPV4V6_STACK
45+
0, // PROPERTY_NON_IP_PDP_TYPE
46+
0, // PROPERTY_AT_CGEREP
47+
};
48+
49+
RM1000_AT::RM1000_AT(FileHandle *fh) : AT_CellularDevice(fh)
50+
{
51+
tr_debug("RM1000_AT::RM1000_AT");
52+
AT_CellularBase::set_cellular_properties(cellular_properties);
53+
set_retry_timeout_array(retry_timeout, sizeof(retry_timeout) / sizeof(retry_timeout[0]));
54+
}
55+
56+
AT_CellularNetwork *RM1000_AT::open_network_impl(ATHandler &at)
57+
{
58+
tr_debug("RM1000_AT::open_network_impl");
59+
return new RM1000_AT_CellularNetwork(at);
60+
}
61+
62+
AT_CellularContext *RM1000_AT::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
63+
{
64+
tr_debug("RM1000_AT::create_context_impl");
65+
return new RM1000_AT_CellularContext(at, this, apn, cp_req, nonip_req);
66+
}
67+
68+
nsapi_error_t RM1000_AT::init()
69+
{
70+
tr_debug("RM1000_AT::init");
71+
72+
_at->lock();
73+
_at->flush();
74+
_at->cmd_start("ATE0"); // echo off
75+
_at->cmd_stop_read_resp();
76+
77+
_at->cmd_start("AT+SIM=physical");
78+
_at->cmd_stop_read_resp();
79+
80+
_at->set_at_timeout(5000);
81+
_at->cmd_start("AT+CFUN=1"); // set full functionality
82+
_at->cmd_stop_read_resp();
83+
84+
_at->cmd_start("AT+VERBOSE=0"); // verbose responses
85+
_at->cmd_stop_read_resp();
86+
87+
return _at->unlock_return_error();
88+
}
89+
90+
#if MBED_CONF_RM1000_AT_PROVIDE_DEFAULT
91+
#include "UARTSerial.h"
92+
CellularDevice *CellularDevice::get_default_instance()
93+
{
94+
tr_debug("Calling CellularDevice::get_default_instance from RM1000_AT");
95+
96+
static UARTSerial serial(MBED_CONF_RM1000_AT_TX, MBED_CONF_RM1000_AT_RX, MBED_CONF_RM1000_AT_BAUDRATE);
97+
#if defined (MBED_CONF_RM1000_AT_RTS) && defined(MBED_CONF_RM1000_AT_CTS)
98+
tr_debug("RM1000_AT flow control: RTS %d CTS %d", MBED_CONF_RM1000_AT_RTS, MBED_CONF_RM1000_AT_CTS);
99+
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_RM1000_AT_RTS, MBED_CONF_RM1000_AT_CTS);
100+
#endif
101+
static RM1000_AT device(&serial);
102+
return &device;
103+
}
104+
#endif
105+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef RM1000_AT_H_
19+
#define RM1000_AT_H_
20+
21+
#include "AT_CellularDevice.h"
22+
23+
namespace mbed {
24+
25+
class RM1000_AT : public AT_CellularDevice {
26+
public:
27+
RM1000_AT(FileHandle *fh);
28+
29+
protected: // AT_CellularDevice
30+
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
31+
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
32+
33+
virtual nsapi_error_t init();
34+
35+
public: // NetworkInterface
36+
void handle_urc(FileHandle *fh);
37+
};
38+
39+
} // namespace mbed
40+
41+
#endif // RM1000_AT_H_
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "RM1000_AT_CellularContext.h"
18+
19+
#include "APN_db.h"
20+
#include "RM1000_AT_CellularStack.h"
21+
#include "mbed-trace/mbed_trace.h"
22+
#ifndef TRACE_GROUP
23+
#define TRACE_GROUP "RIOT"
24+
#endif // TRACE_GROUP
25+
26+
namespace mbed {
27+
28+
RM1000_AT_CellularContext::RM1000_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
29+
AT_CellularContext(at, device, apn, cp_req, nonip_req)
30+
{
31+
tr_debug("Calling RM1000_AT_CellularContext::RM1000_AT_CellularContext");
32+
}
33+
34+
RM1000_AT_CellularContext::~RM1000_AT_CellularContext()
35+
{
36+
tr_debug("Calling RM1000_AT_CellularContext::~RM1000_AT_CellularContext");
37+
}
38+
39+
NetworkStack *RM1000_AT_CellularContext::get_stack()
40+
{
41+
tr_debug("Calling RM1000_AT_CellularContext::get_stack");
42+
43+
if (_pdp_type == NON_IP_PDP_TYPE || _cp_in_use) {
44+
tr_error("Requesting stack for NON-IP context! Should request control plane netif: get_cp_netif()");
45+
return NULL;
46+
}
47+
if (!_stack) {
48+
_stack = new RM1000_AT_CellularStack(_at, _cid, (nsapi_ip_stack_t)_pdp_type);
49+
}
50+
51+
return _stack;
52+
}
53+
54+
} /* namespace mbed */
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef RM1000_AT_CELLULARCONTEXT_H_
18+
#define RM1000_AT_CELLULARCONTEXT_H_
19+
20+
#include "AT_CellularContext.h"
21+
22+
namespace mbed {
23+
24+
class RM1000_AT_CellularContext: public AT_CellularContext {
25+
public:
26+
RM1000_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false);
27+
virtual ~RM1000_AT_CellularContext();
28+
29+
protected:
30+
virtual NetworkStack *get_stack();
31+
};
32+
33+
} /* namespace mbed */
34+
35+
#endif // RM1000_AT_CELLULARCONTEXT_H_
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <stdlib.h>
19+
#include "rtos.h"
20+
#include "CellularCommon.h"
21+
#include "RM1000_AT_CellularNetwork.h"
22+
#include "platform/mbed_wait_api.h"
23+
24+
#include "mbed-trace/mbed_trace.h"
25+
#ifndef TRACE_GROUP
26+
#define TRACE_GROUP "RIOT"
27+
#endif // TRACE_GROUP
28+
using namespace mbed;
29+
30+
// Callback for MODEM faults URC.
31+
void RM1000_AT_CellularNetwork::MODEM_FAULT_URC()
32+
{
33+
tr_debug("RM1000_AT_CellularNetwork::ASSERTED_URC");
34+
_connect_status = NSAPI_STATUS_DISCONNECTED;
35+
if (_connection_status_cb) {
36+
_connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
37+
}
38+
}
39+
40+
RM1000_AT_CellularNetwork::RM1000_AT_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler)
41+
{
42+
tr_debug("RM1000_AT_CellularNetwork::RM1000_B0_CellularNetwork");
43+
_op_act = RAT_UNKNOWN;
44+
_at.set_urc_handler("ASSERTED!", callback(this, &RM1000_AT_CellularNetwork::MODEM_FAULT_URC));
45+
_at.set_urc_handler("ERRCODE:", callback(this, &RM1000_AT_CellularNetwork::MODEM_FAULT_URC));
46+
_at.set_urc_handler("Halt the processor", callback(this, &RM1000_AT_CellularNetwork::MODEM_FAULT_URC));
47+
}
48+
49+
RM1000_AT_CellularNetwork::~RM1000_AT_CellularNetwork()
50+
{
51+
tr_debug("RM1000_AT_CellularNetwork::~RM1000_B0_CellularNetwork");
52+
53+
_at.set_urc_handler("ASSERTED!", NULL);
54+
_at.set_urc_handler("ERRCODE:", NULL);
55+
_at.set_urc_handler("Halt the processor", NULL);
56+
}
57+
58+
nsapi_error_t RM1000_AT_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat)
59+
{
60+
nsapi_error_t ret = NSAPI_ERROR_OK;
61+
62+
tr_debug("RM1000_AT_CellularNetwork::set_access_technology_impl %d", opRat);
63+
64+
switch (opRat) {
65+
case RAT_NB1:
66+
break;
67+
default: {
68+
_op_act = RAT_UNKNOWN;
69+
ret = NSAPI_ERROR_UNSUPPORTED;
70+
}
71+
}
72+
73+
return (ret);
74+
}
75+
76+
nsapi_error_t RM1000_AT_CellularNetwork::set_registration_urc(RegistrationType type, bool urc_on)
77+
{
78+
tr_debug("RM1000_AT_CellularNetwork::set_registration_urc");
79+
80+
int index = (int)type;
81+
MBED_ASSERT(index >= 0 && index < C_MAX);
82+
83+
RegistrationMode mode = (RegistrationMode)get_property((AT_CellularBase::CellularProperty)type);
84+
if (mode == RegistrationModeDisable) {
85+
return NSAPI_ERROR_UNSUPPORTED;
86+
} else {
87+
return NSAPI_ERROR_OK; /* FIXME use at commands */
88+
}
89+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef RM1000_AT_CELLULAR_NETWORK_H_
19+
#define RM1000_AT_CELLULAR_NETWORK_H_
20+
21+
#include "AT_CellularNetwork.h"
22+
23+
namespace mbed {
24+
25+
class RM1000_AT_CellularNetwork : public AT_CellularNetwork {
26+
public:
27+
RM1000_AT_CellularNetwork(ATHandler &atHandler);
28+
virtual ~RM1000_AT_CellularNetwork();
29+
30+
virtual nsapi_error_t set_registration_urc(RegistrationType type, bool on);
31+
32+
protected:
33+
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);
34+
private:
35+
// URC handlers
36+
void MODEM_FAULT_URC();
37+
};
38+
39+
} // namespace mbed
40+
41+
#endif // RM1000_AT_CELLULAR_NETWORK_H_

0 commit comments

Comments
 (0)