Skip to content

Commit 2fd7f80

Browse files
authored
Merge pull request #10484 from trowbridgec/telit-me910-driver
Cellular: Telit ME910 driver
2 parents 6000724 + 28f7a4e commit 2fd7f80

File tree

5 files changed

+412
-0
lines changed

5 files changed

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

0 commit comments

Comments
 (0)