Skip to content

Commit 9a1309f

Browse files
author
Chris Trowbridge
committed
Modify ME910 driver to follow power on/off best practices and add custom get_context() function
1 parent 0a717e4 commit 9a1309f

File tree

5 files changed

+275
-21
lines changed

5 files changed

+275
-21
lines changed

features/cellular/framework/targets/TELIT/ME910/TELIT_ME910.cpp

Lines changed: 134 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,31 @@
1616
*/
1717

1818
#include "TELIT_ME910.h"
19+
#include "TELIT_ME910_CellularContext.h"
1920
#include "AT_CellularNetwork.h"
20-
#include "gpio_api.h"
21-
#include "platform/mbed_wait_api.h"
21+
#include "PinNames.h"
22+
#include "rtos/ThisThread.h"
2223

2324
using namespace mbed;
25+
using namespace rtos;
2426
using namespace events;
2527

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+
2644
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
2745
AT_CellularNetwork::RegistrationModeLAC, // C_EREG
2846
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
@@ -41,11 +59,20 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
4159
1, // PROPERTY_AT_CGEREP
4260
};
4361

44-
TELIT_ME910::TELIT_ME910(FileHandle *fh) : AT_CellularDevice(fh)
62+
TELIT_ME910::TELIT_ME910(FileHandle *fh, PinName pwr, bool active_high)
63+
: AT_CellularDevice(fh),
64+
_active_high(active_high),
65+
_pwr_key(pwr, !_active_high)
4566
{
4667
AT_CellularBase::set_cellular_properties(cellular_properties);
4768
}
4869

70+
AT_CellularContext *TELIT_ME910::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
71+
{
72+
return new TELIT_ME910_CellularContext(at, this, apn, cp_req, nonip_req);
73+
}
74+
75+
4976
uint16_t TELIT_ME910::get_send_delay() const
5077
{
5178
return DEFAULT_DELAY_BETWEEN_AT_COMMANDS;
@@ -65,6 +92,99 @@ nsapi_error_t TELIT_ME910::init()
6592
#endif
6693
_at->cmd_stop_read_resp();
6794

95+
// AT#QSS=1
96+
// Enable the Query SIM Status unsolicited indication in the ME. The format of the
97+
// unsolicited indication is the following:
98+
// #QSS: <status>
99+
// The ME informs at
100+
// every SIM status change through the basic unsolicited indication where <status> range is 0...1
101+
// <status> values:
102+
// - 0: SIM not inserted
103+
// - 1: SIM inserted
104+
_at->cmd_start("AT#QSS=1");
105+
_at->cmd_stop_read_resp();
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->cmd_start("AT#PSNT=1");
116+
_at->cmd_stop_read_resp();
117+
118+
// AT+CGEREP=2
119+
// Set command enables sending of unsolicited result codes in case of certain events
120+
// occurring in the module or in the network.
121+
// Current setting: buffer unsolicited result codes in the TA when TA-TE link is reserved (e.g.
122+
// in on-line data mode) and flush them to the TE when TA-TE link becomes
123+
// available; otherwise forward them directly to the TE.
124+
_at->cmd_start("AT+CGEREP=2");
125+
_at->cmd_stop_read_resp();
126+
127+
// AT+CMER=2
128+
// Set command enables sending of unsolicited result codes from TA to TE in the case of
129+
// indicator state changes.
130+
// Current setting: buffer +CIEV Unsolicited Result Codes in the TA when TA-TE link is
131+
// reserved (e.g. on-line data mode) and flush them to the TE after
132+
// reservation; otherwise forward them directly to the TE
133+
_at->cmd_start("AT+CMER=2");
134+
_at->cmd_stop_read_resp();
135+
136+
// AT+CREG=1
137+
// Set command enables the network registration unsolicited result code and selects one of
138+
// the two available formats:
139+
// short format: +CREG: <stat>
140+
// long format: +CREG: <stat>[,<lac>,<ci>[,<AcT>]]
141+
// Current setting: enable the network registration unsolicited result code, and selects the
142+
// short format
143+
_at->cmd_start("AT+CREG=1");
144+
_at->cmd_stop_read_resp();
145+
146+
// AT+CGREG=1
147+
// Set command enables/disables the +CGREG: unsolicited result code, and selects one of the
148+
// available formats:
149+
// short format:
150+
// +CGREG:<stat>
151+
// long format:
152+
// +CGREG:<stat>[,<lac>,<ci>[,<AcT>,<rac>]]
153+
// extra long format:
154+
// +CGREG:<stat>[,[<lac>],[<ci>],[<AcT>],[<rac>][,,[,[<ActiveTime>],[<PeriodicRAU>],[<GPRSREADYtimer>]]]]
155+
// Current setting: enable the network registration unsolicited result code, and selects the
156+
// short format
157+
_at->cmd_start("AT+CGREG=1");
158+
_at->cmd_stop_read_resp();
159+
160+
// AT+CEREG=1
161+
// Set command enables the EPS network registration unsolicited result code (URC) in LTE,
162+
// and selects one of the available formats:
163+
// short format: +CEREG: <stat>
164+
// long format: +CEREG: <stat>[,[<tac>],[<ci>],[<AcT>]]
165+
// <tac>, <ci>, and <AcT> are reported by the command only if available.
166+
// Current setting: enable the network registration unsolicited result code, and select the short
167+
// format
168+
_at->cmd_start("AT+CEREG=1");
169+
_at->cmd_stop_read_resp();
170+
171+
// AT+CMEE=2
172+
// Set command disables the use of result code +CME ERROR: <err> as an indication of an
173+
// error relating to the +Cxxx command issued. When enabled, device related errors cause the +CME
174+
// ERROR: <err> final result code instead of the default ERROR final result code. ERROR is returned
175+
// normally when the error message is related to syntax, invalid parameters or DTE functionality.
176+
// Current setting: enable and use verbose <err> values
177+
_at->cmd_start("AT+CMEE=2");
178+
_at->cmd_stop_read_resp();
179+
180+
// AT&W&P
181+
// - AT&W: Execution command stores on profile <n> the complete configuration of the device. If
182+
// parameter is omitted, the command has the same behavior of AT&W0.
183+
// - AT&P: Execution command defines which full profile will be loaded at startup. If parameter
184+
// is omitted, the command has the same behavior as AT&P0
185+
_at->cmd_start("AT&W&P");
186+
_at->cmd_stop_read_resp();
187+
68188
return _at->unlock_return_error();
69189
}
70190

@@ -76,7 +196,9 @@ CellularDevice *CellularDevice::get_default_instance()
76196
#if defined (MBED_CONF_TELIT_ME910_RTS) && defined (MBED_CONF_TELIT_ME910_CTS)
77197
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_TELIT_ME910_RTS, MBED_CONF_TELIT_ME910_CTS);
78198
#endif
79-
static TELIT_ME910 device(&serial);
199+
static TELIT_ME910 device(&serial,
200+
MBED_CONF_TELIT_ME910_PWR,
201+
MBED_CONF_TELIT_ME910_POLARITY);
80202
return &device;
81203
}
82204
#endif
@@ -90,28 +212,20 @@ nsapi_error_t TELIT_ME910::hard_power_on()
90212

91213
nsapi_error_t TELIT_ME910::soft_power_on()
92214
{
93-
gpio_t gpio;
94-
95-
gpio_init_out_ex(&gpio, MDMPWRON, 1);
96-
wait_ms(500);
97-
gpio_write(&gpio, 0);
98-
wait_ms(5000);
99-
gpio_write(&gpio, 1);
100-
wait_ms(5000);
215+
_pwr_key = _active_high;
216+
ThisThread::sleep_for(500);
217+
_pwr_key = !_active_high;
218+
ThisThread::sleep_for(5000);
219+
_pwr_key = _active_high;
220+
ThisThread::sleep_for(5000);
101221

102222
return NSAPI_ERROR_OK;
103223
}
104224

105225
nsapi_error_t TELIT_ME910::hard_power_off()
106226
{
107-
gpio_t gpio;
108-
109-
gpio_init_out_ex(&gpio, MDMPWRON, 0);
110-
/* keep the power line low for more than 10 seconds.
111-
* If 3G_ON_OFF pin is kept low for more than a second, a controlled disconnect and shutdown takes
112-
* place, Due to the network disconnect, shut-off can take up to 30 seconds. However, we wait for 10
113-
* seconds only */
114-
wait_ms(10 * 1000);
227+
_pwr_key = !_active_high;
228+
ThisThread::sleep_for(10000);
115229

116230
return NSAPI_ERROR_OK;
117231
}

features/cellular/framework/targets/TELIT/ME910/TELIT_ME910.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#endif
2828
#endif /* TARGET_FF_ARDUINO */
2929

30+
#include "DigitalOut.h"
3031
#include "AT_CellularDevice.h"
3132

3233
//the delay between sending AT commands
@@ -36,15 +37,23 @@ namespace mbed {
3637

3738
class TELIT_ME910 : public AT_CellularDevice {
3839
public:
39-
TELIT_ME910(FileHandle *fh);
40+
/**
41+
* Constructs the Telit ME910 series driver. It is mandatory to provide
42+
* a FileHandle object, the power pin and the polarity of the pin.
43+
*/
44+
TELIT_ME910(FileHandle *fh, PinName pwr, bool active_high);
4045

4146
protected: // AT_CellularDevice
4247
virtual uint16_t get_send_delay() const;
48+
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
4349
virtual nsapi_error_t init();
4450
virtual nsapi_error_t hard_power_on();
4551
virtual nsapi_error_t hard_power_off();
4652
virtual nsapi_error_t soft_power_on();
4753
virtual nsapi_error_t soft_power_off();
54+
private:
55+
bool _active_high;
56+
DigitalOut _pwr_key;
4857
};
4958
} // namespace mbed
5059
#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_

features/cellular/framework/targets/TELIT/ME910/mbed_lib.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
"help": "CTS pin for serial connection",
1818
"value": null
1919
},
20+
"pwr": {
21+
"help": "Power control pin",
22+
"value": null
23+
},
24+
"polarity": {
25+
"help": "Pin polarity, 1 = Active high, 0 = Active low",
26+
"value": null
27+
},
2028
"baudrate" : {
2129
"help": "Serial connection baud rate",
2230
"value": 115200

0 commit comments

Comments
 (0)