Skip to content

Commit 95a3a30

Browse files
authored
Merge pull request #13009 from trowbridgec/add-telit-me310-driver
Add support for the Telit ME310 module
2 parents 28b7cf3 + 125f169 commit 95a3a30

9 files changed

+1247
-0
lines changed
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/*
2+
* Copyright (c) 2020, 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 "TELIT_ME310.h"
19+
#include "TELIT_ME310_CellularContext.h"
20+
#include "TELIT_ME310_CellularStack.h"
21+
#include "TELIT_ME310_CellularNetwork.h"
22+
#include "AT_CellularNetwork.h"
23+
#include "PinNames.h"
24+
#include "rtos/ThisThread.h"
25+
26+
using namespace std::chrono_literals;
27+
using namespace mbed;
28+
using namespace rtos;
29+
using namespace events;
30+
31+
#if !defined(MBED_CONF_TELIT_ME310_PWR)
32+
#define MBED_CONF_TELIT_ME310_PWR NC
33+
#endif
34+
35+
#if !defined(MBED_CONF_TELIT_ME310_TX)
36+
#define MBED_CONF_TELIT_ME310_TX NC
37+
#endif
38+
39+
#if !defined(MBED_CONF_TELIT_ME310_RX)
40+
#define MBED_CONF_TELIT_ME310_RX NC
41+
#endif
42+
43+
#if !defined(MBED_CONF_TELIT_ME310_POLARITY)
44+
#define MBED_CONF_TELIT_ME310_POLARITY 1 // active high
45+
#endif
46+
47+
static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
48+
AT_CellularNetwork::RegistrationModeLAC, // C_EREG
49+
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
50+
AT_CellularNetwork::RegistrationModeLAC, // C_REG
51+
0, // AT_CGSN_WITH_TYPE
52+
0, // AT_CGDATA
53+
1, // AT_CGAUTH
54+
1, // AT_CNMI
55+
1, // AT_CSMP
56+
1, // AT_CMGF
57+
1, // AT_CSDH
58+
1, // PROPERTY_IPV4_STACK
59+
1, // PROPERTY_IPV6_STACK
60+
1, // PROPERTY_IPV4V6_STACK
61+
0, // PROPERTY_NON_IP_PDP_TYPE
62+
1, // PROPERTY_AT_CGEREP,
63+
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
64+
6, // PROPERTY_SOCKET_COUNT
65+
1, // PROPERTY_IP_TCP
66+
1, // PROPERTY_IP_UDP
67+
20, // PROPERTY_AT_SEND_DELAY
68+
};
69+
70+
TELIT_ME310::TELIT_ME310(FileHandle *fh, PinName pwr, bool active_high)
71+
: AT_CellularDevice(fh),
72+
_active_high(active_high),
73+
_pwr_key(pwr, !_active_high)
74+
{
75+
set_cellular_properties(cellular_properties);
76+
}
77+
78+
AT_CellularContext *TELIT_ME310::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
79+
{
80+
return new TELIT_ME310_CellularContext(at, this, apn, cp_req, nonip_req);
81+
}
82+
83+
nsapi_error_t TELIT_ME310::init()
84+
{
85+
nsapi_error_t err = AT_CellularDevice::init();
86+
if (err != NSAPI_ERROR_OK) {
87+
return err;
88+
}
89+
_at.lock();
90+
#if defined (MBED_CONF_TELIT_ME310_RTS) && defined (MBED_CONF_TELIT_ME310_CTS)
91+
_at.at_cmd_discard("&K3;&C1;&D0", "");
92+
#else
93+
_at.at_cmd_discard("&K0;&C1;&D0", "");
94+
#endif
95+
96+
// AT#QSS=1
97+
// Enable the Query SIM Status unsolicited indication in the ME. The format of the
98+
// unsolicited indication is the following:
99+
// #QSS: <status>
100+
// The ME informs at
101+
// every SIM status change through the basic unsolicited indication where <status> range is 0...1
102+
// <status> values:
103+
// - 0: SIM not inserted
104+
// - 1: SIM inserted
105+
_at.at_cmd_discard("#QSS", "=1");
106+
107+
// AT#PSNT=1
108+
// Set command enables unsolicited result code for packet service network type (PSNT)
109+
// having the following format:
110+
// #PSNT:<nt>
111+
// <nt> values:
112+
// - 0: GPRS network
113+
// - 4: LTE network
114+
// - 5: unknown or not registered
115+
_at.at_cmd_discard("#PSNT", "=1");
116+
117+
// AT+CMER=2
118+
// Set command enables sending of unsolicited result codes from TA to TE in the case of
119+
// indicator state changes.
120+
// Current setting: buffer +CIEV Unsolicited Result Codes in the TA when TA-TE link is
121+
// reserved (e.g. on-line data mode) and flush them to the TE after
122+
// reservation; otherwise forward them directly to the TE
123+
_at.at_cmd_discard("+CMER", "=2");
124+
125+
// AT+CMEE=2
126+
// Set command disables the use of result code +CME ERROR: <err> as an indication of an
127+
// error relating to the +Cxxx command issued. When enabled, device related errors cause the +CME
128+
// ERROR: <err> final result code instead of the default ERROR final result code. ERROR is returned
129+
// normally when the error message is related to syntax, invalid parameters or DTE functionality.
130+
// Current setting: enable and use verbose <err> values
131+
_at.at_cmd_discard("+CMEE", "=2");
132+
133+
// AT&W&P
134+
// - AT&W: Execution command stores on profile <n> the complete configuration of the device. If
135+
// parameter is omitted, the command has the same behavior of AT&W0.
136+
// - AT&P: Execution command defines which full profile will be loaded at startup. If parameter
137+
// is omitted, the command has the same behavior as AT&P0
138+
_at.at_cmd_discard("&W&P", "");
139+
140+
return _at.unlock_return_error();
141+
}
142+
143+
#if MBED_CONF_TELIT_ME310_PROVIDE_DEFAULT
144+
#include "drivers/BufferedSerial.h"
145+
CellularDevice *CellularDevice::get_default_instance()
146+
{
147+
static BufferedSerial serial(MBED_CONF_TELIT_ME310_TX, MBED_CONF_TELIT_ME310_RX, MBED_CONF_TELIT_ME310_BAUDRATE);
148+
#if defined (MBED_CONF_TELIT_ME310_RTS) && defined (MBED_CONF_TELIT_ME310_CTS)
149+
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_TELIT_ME310_RTS, MBED_CONF_TELIT_ME310_CTS);
150+
#endif
151+
static TELIT_ME310 device(&serial,
152+
MBED_CONF_TELIT_ME310_PWR,
153+
MBED_CONF_TELIT_ME310_POLARITY);
154+
return &device;
155+
}
156+
#endif
157+
158+
nsapi_error_t TELIT_ME310::hard_power_on()
159+
{
160+
soft_power_on();
161+
162+
return NSAPI_ERROR_OK;
163+
}
164+
165+
nsapi_error_t TELIT_ME310::soft_power_on()
166+
{
167+
_pwr_key = _active_high;
168+
ThisThread::sleep_for(500ms);
169+
_pwr_key = !_active_high;
170+
ThisThread::sleep_for(5s);
171+
_pwr_key = _active_high;
172+
ThisThread::sleep_for(5s);
173+
174+
return NSAPI_ERROR_OK;
175+
}
176+
177+
nsapi_error_t TELIT_ME310::hard_power_off()
178+
{
179+
_pwr_key = !_active_high;
180+
ThisThread::sleep_for(10s);
181+
182+
return NSAPI_ERROR_OK;
183+
}
184+
185+
nsapi_error_t TELIT_ME310::soft_power_off()
186+
{
187+
return AT_CellularDevice::soft_power_off();
188+
}
189+
190+
AT_CellularNetwork *TELIT_ME310::open_network_impl(ATHandler &at)
191+
{
192+
return new TELIT_ME310_CellularNetwork(at, *this);
193+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2020, 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 CELLULAR_TARGETS_TELIT_ME310_TELIT_ME310_H_
19+
#define CELLULAR_TARGETS_TELIT_ME310_TELIT_ME310_H_
20+
21+
#ifdef TARGET_FF_ARDUINO
22+
#ifndef MBED_CONF_TELIT_ME310_TX
23+
#define MBED_CONF_TELIT_ME310_TX D1
24+
#endif
25+
#ifndef MBED_CONF_TELIT_ME310_RX
26+
#define MBED_CONF_TELIT_ME310_RX D0
27+
#endif
28+
#endif /* TARGET_FF_ARDUINO */
29+
30+
#include "DigitalOut.h"
31+
#include "AT_CellularDevice.h"
32+
33+
namespace mbed {
34+
35+
class TELIT_ME310 : public AT_CellularDevice {
36+
public:
37+
/**
38+
* Constructs the Telit ME310 series driver. It is mandatory to provide
39+
* a FileHandle object, the power pin and the polarity of the pin.
40+
*/
41+
TELIT_ME310(FileHandle *fh, PinName pwr, bool active_high);
42+
43+
protected: // AT_CellularDevice
44+
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
45+
virtual nsapi_error_t init();
46+
virtual nsapi_error_t hard_power_on();
47+
virtual nsapi_error_t hard_power_off();
48+
virtual nsapi_error_t soft_power_on();
49+
virtual nsapi_error_t soft_power_off();
50+
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
51+
52+
private:
53+
bool _active_high;
54+
DigitalOut _pwr_key;
55+
};
56+
} // namespace mbed
57+
#endif /* CELLULAR_TARGETS_TELIT_ME310_TELIT_ME310_H_ */
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 "TELIT_ME310_CellularContext.h"
18+
#include "TELIT_ME310_CellularStack.h"
19+
#include "CellularLog.h"
20+
21+
#include "Semaphore.h"
22+
23+
using namespace mbed_cellular_util;
24+
25+
namespace mbed {
26+
27+
TELIT_ME310_CellularContext::TELIT_ME310_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
28+
AT_CellularContext(at, device, apn, cp_req, nonip_req)
29+
{
30+
}
31+
32+
TELIT_ME310_CellularContext::~TELIT_ME310_CellularContext()
33+
{
34+
}
35+
36+
#if !NSAPI_PPP_AVAILABLE
37+
NetworkStack *TELIT_ME310_CellularContext::get_stack()
38+
{
39+
if (_pdp_type == NON_IP_PDP_TYPE || (_nonip_req && _pdp_type != DEFAULT_PDP_TYPE)) {
40+
tr_error("Requesting stack for NON-IP context! Should request control plane netif: get_cp_netif()");
41+
return NULL;
42+
}
43+
44+
if (!_stack) {
45+
_stack = new TELIT_ME310_CellularStack(_at, _cid, (nsapi_ip_stack_t)_pdp_type, *get_device());
46+
}
47+
48+
return _stack;
49+
}
50+
#endif // #if !NSAPI_PPP_AVAILABLE
51+
52+
bool TELIT_ME310_CellularContext::get_context()
53+
{
54+
bool modem_supports_ipv6 = get_device()->get_property(AT_CellularDevice::PROPERTY_IPV6_PDP_TYPE);
55+
bool modem_supports_ipv4 = get_device()->get_property(AT_CellularDevice::PROPERTY_IPV4_PDP_TYPE);
56+
57+
_at.cmd_start_stop("+CGDCONT", "?");
58+
_at.resp_start("+CGDCONT:");
59+
_cid = -1;
60+
int cid_max = 0; // needed when creating new context
61+
char apn[MAX_ACCESSPOINT_NAME_LENGTH];
62+
int apn_len = 0;
63+
64+
while (_at.info_resp()) {
65+
int cid = _at.read_int();
66+
if (cid > cid_max) {
67+
cid_max = cid;
68+
}
69+
char pdp_type_from_context[10];
70+
int pdp_type_len = _at.read_string(pdp_type_from_context, sizeof(pdp_type_from_context));
71+
if (pdp_type_len > 0) {
72+
apn_len = _at.read_string(apn, sizeof(apn));
73+
if (apn_len >= 0) {
74+
if (_apn && apn_len > 0 && (strcmp(apn, _apn) != 0)) {
75+
continue;
76+
}
77+
78+
// APN matched -> Check PDP type
79+
pdp_type_t pdp_type = string_to_pdp_type(pdp_type_from_context);
80+
81+
// Accept exact matching PDP context type or dual PDP context for IPv4/IPv6 only modems
82+
if (get_device()->get_property(pdp_type_t_to_cellular_property(pdp_type)) ||
83+
((pdp_type == IPV4V6_PDP_TYPE && (modem_supports_ipv4 || modem_supports_ipv6)) && !_nonip_req)) {
84+
_pdp_type = pdp_type;
85+
set_new_context(cid);
86+
}
87+
}
88+
}
89+
}
90+
91+
_at.resp_stop();
92+
if (_cid == -1) { // no suitable context was found so create a new one
93+
if (!set_new_context(1)) {
94+
return false;
95+
}
96+
}
97+
98+
// save the apn
99+
if (apn_len > 0 && !_apn) {
100+
memcpy(_found_apn, apn, apn_len + 1);
101+
}
102+
103+
tr_info("Found PDP context %d", _cid);
104+
return true;
105+
}
106+
107+
} /* namespace mbed */
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2020, 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 TELIT_ME310_CELLULARCONTEXT_H_
18+
#define TELIT_ME310_CELLULARCONTEXT_H_
19+
20+
#include "AT_CellularContext.h"
21+
22+
namespace mbed {
23+
24+
class TELIT_ME310_CellularContext: public AT_CellularContext {
25+
public:
26+
TELIT_ME310_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false);
27+
virtual ~TELIT_ME310_CellularContext();
28+
protected:
29+
#if !NSAPI_PPP_AVAILABLE
30+
virtual NetworkStack *get_stack();
31+
#endif // #if !NSAPI_PPP_AVAILABLE
32+
virtual bool get_context();
33+
};
34+
35+
} /* namespace mbed */
36+
37+
#endif // TELIT_ME310_CELLULARCONTEXT_H_

0 commit comments

Comments
 (0)