Skip to content

Commit 532654e

Browse files
authored
Merge pull request #12597 from kivaisan/alt1250_ppp_cellular
Cellular: Add ALT1250 PPP cellular target
2 parents d61187c + 164a2ca commit 532654e

File tree

7 files changed

+385
-0
lines changed

7 files changed

+385
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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 "ALT1250_PPP.h"
19+
#include "ALT1250_PPP_CellularContext.h"
20+
#include "AT_CellularNetwork.h"
21+
#include "ALT1250_PPP_CellularNetwork.h"
22+
#include "CellularLog.h"
23+
#include "rtos/ThisThread.h"
24+
25+
using namespace rtos;
26+
using namespace mbed;
27+
using namespace events;
28+
29+
#define CONNECT_DELIM "\r\n"
30+
#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format
31+
#define CONNECT_TIMEOUT 8000
32+
33+
#if !defined(MBED_CONF_ALT1250_PPP_RST)
34+
#define MBED_CONF_ALT1250_PPP_RST NC
35+
#endif
36+
37+
static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
38+
AT_CellularNetwork::RegistrationModeEnable,// C_EREG
39+
AT_CellularNetwork::RegistrationModeDisable, // C_GREG
40+
AT_CellularNetwork::RegistrationModeLAC, // C_REG
41+
1, // AT_CGSN_WITH_TYPE
42+
0, // AT_CGDATA
43+
0, // AT_CGAUTH
44+
1, // AT_CNMI
45+
1, // AT_CSMP
46+
1, // AT_CMGF
47+
1, // AT_CSDH
48+
1, // PROPERTY_IPV4_STACK
49+
0, // PROPERTY_IPV6_STACK
50+
0, // PROPERTY_IPV4V6_STACK
51+
0, // PROPERTY_NON_IP_PDP_TYPE
52+
1, // PROPERTY_AT_CGEREP
53+
};
54+
55+
ALT1250_PPP::ALT1250_PPP(FileHandle *fh, PinName rst, PinDirection pin_dir, PinMode pin_mode, bool value)
56+
: AT_CellularDevice(fh),
57+
_rst(rst, pin_dir, pin_mode, value)
58+
{
59+
set_cellular_properties(cellular_properties);
60+
}
61+
62+
AT_CellularContext *ALT1250_PPP::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
63+
{
64+
return new ALT1250_PPP_CellularContext(at, this, apn, cp_req, nonip_req);
65+
}
66+
67+
AT_CellularNetwork *ALT1250_PPP::open_network_impl(ATHandler &at)
68+
{
69+
return new ALT1250_PPP_CellularNetwork(at, *this);
70+
}
71+
72+
nsapi_error_t ALT1250_PPP::soft_power_on()
73+
{
74+
// check if modem is already ready
75+
_at.lock();
76+
_at.flush();
77+
_at.set_at_timeout(30);
78+
_at.cmd_start("AT");
79+
_at.cmd_stop_read_resp();
80+
nsapi_error_t err = _at.get_last_error();
81+
_at.restore_at_timeout();
82+
_at.unlock();
83+
84+
// modem is not responding to AT commands, power it on
85+
if (err != NSAPI_ERROR_OK) {
86+
tr_warn("Modem is not responding to AT commands, reset it");
87+
if (_rst.is_connected()) {
88+
_rst = 0;
89+
ThisThread::sleep_for(100);
90+
_rst = 1;
91+
}
92+
if (_at.sync(2000)) {
93+
tr_warn("Modem is AT ready");
94+
return NSAPI_ERROR_OK;
95+
}
96+
tr_warn("Modem is not AT ready following reset");
97+
return _at.get_last_error();
98+
}
99+
100+
return NSAPI_ERROR_OK;
101+
}
102+
103+
#if MBED_CONF_ALT1250_PPP_PROVIDE_DEFAULT
104+
105+
#if !NSAPI_PPP_AVAILABLE
106+
#error Must define lwip.ppp-enabled
107+
#endif
108+
109+
#include "BufferedSerial.h"
110+
CellularDevice *CellularDevice::get_default_instance()
111+
{
112+
static BufferedSerial serial(MBED_CONF_ALT1250_PPP_TX, MBED_CONF_ALT1250_PPP_RX, MBED_CONF_ALT1250_PPP_BAUDRATE);
113+
#if defined (MBED_CONF_ALT1250_PPP_RTS) && defined (MBED_CONF_ALT1250_PPP_CTS)
114+
tr_debug("ALT1250_PPP flow control: RTS %d CTS %d", MBED_CONF_ALT1250_PPP_RTS, MBED_CONF_ALT1250_PPP_CTS);
115+
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_ALT1250_PPP_RTS, MBED_CONF_ALT1250_PPP_CTS);
116+
#endif
117+
static ALT1250_PPP device(&serial, MBED_CONF_ALT1250_PPP_RST, PIN_OUTPUT, OpenDrainNoPull, 1);
118+
return &device;
119+
}
120+
#endif
121+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 ALT1250_PPP_H_
19+
#define ALT1250_PPP_H_
20+
21+
#ifdef TARGET_FF_ARDUINO
22+
#ifndef MBED_CONF_ALT1250_PPP_TX
23+
#define MBED_CONF_ALT1250_PPP_TX D1
24+
#endif
25+
#ifndef MBED_CONF_ALT1250_PPP_RX
26+
#define MBED_CONF_ALT1250_PPP_RX D0
27+
#endif
28+
#endif /* TARGET_FF_ARDUINO */
29+
30+
#include "AT_CellularDevice.h"
31+
#include "DigitalInOut.h"
32+
33+
namespace mbed {
34+
35+
class ALT1250_PPP : public AT_CellularDevice {
36+
public:
37+
ALT1250_PPP(FileHandle *fh, PinName rst = NC, PinDirection pin_dir = PIN_OUTPUT, PinMode pin_mode = PullUp, bool value = 1);
38+
39+
protected: // AT_CellularDevice
40+
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
41+
42+
AT_CellularNetwork *open_network_impl(ATHandler &at);
43+
virtual nsapi_error_t soft_power_on();
44+
DigitalInOut _rst;
45+
};
46+
47+
} // namespace mbed
48+
#endif // ALT1250_PPP_H_
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
#include "ALT1250_PPP_CellularContext.h"
18+
19+
namespace mbed {
20+
21+
ALT1250_PPP_CellularContext::ALT1250_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
22+
AT_CellularContext(at, device, apn, cp_req, nonip_req)
23+
{
24+
}
25+
26+
ALT1250_PPP_CellularContext::~ALT1250_PPP_CellularContext()
27+
{
28+
}
29+
30+
nsapi_error_t ALT1250_PPP_CellularContext::do_user_authentication()
31+
{
32+
nsapi_error_t err = NSAPI_ERROR_OK;
33+
if (_pwd && _uname) {
34+
err = _at.at_cmd_discard("%PPPAUTH", "=", "%d%d%s%s", _cid, _authentication_type,
35+
_uname, _pwd);
36+
if (err != NSAPI_ERROR_OK) {
37+
return NSAPI_ERROR_AUTH_FAILURE;
38+
}
39+
}
40+
41+
return err;
42+
}
43+
44+
} /* namespace mbed */
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 ALT1250_PPP_CELLULARCONTEXT_H_
18+
#define ALT1250_PPP_CELLULARCONTEXT_H_
19+
20+
#include "AT_CellularContext.h"
21+
22+
namespace mbed {
23+
24+
class ALT1250_PPP_CellularContext: public AT_CellularContext {
25+
public:
26+
ALT1250_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false);
27+
virtual ~ALT1250_PPP_CellularContext();
28+
29+
protected:
30+
virtual nsapi_error_t do_user_authentication();
31+
};
32+
33+
} /* namespace mbed */
34+
35+
#endif // ALT1250_PPP_CELLULARCONTEXT_H_
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 "ALT1250_PPP_CellularNetwork.h"
19+
#include "CellularLog.h"
20+
21+
using namespace mbed;
22+
23+
ALT1250_PPP_CellularNetwork::ALT1250_PPP_CellularNetwork(ATHandler &atHandler, AT_CellularDevice &device) : AT_CellularNetwork(atHandler, device)
24+
{
25+
}
26+
27+
ALT1250_PPP_CellularNetwork::~ALT1250_PPP_CellularNetwork()
28+
{
29+
}
30+
31+
nsapi_error_t ALT1250_PPP_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opsAct)
32+
{
33+
_at.lock();
34+
35+
_at.set_at_timeout(10000);
36+
char resp[20];
37+
_at.at_cmd_str("%RATACT", "?", resp, 20);
38+
tr_debug("ALT1250_PPP RAT: %s", resp);
39+
40+
switch (opsAct) {
41+
case RAT_CATM1:
42+
if (memcmp(resp, "CATM", 4)) {
43+
_at.at_cmd_discard("%RATACT", "=\"CATM\"");
44+
}
45+
break;
46+
case RAT_NB1:
47+
if (memcmp(resp, "NBIOT", 5)) {
48+
_at.at_cmd_discard("%RATACT", "=\"NBIOT\"");
49+
}
50+
break;
51+
case RAT_GSM:
52+
case RAT_GSM_COMPACT:
53+
case RAT_UTRAN:
54+
case RAT_EGPRS:
55+
break;
56+
default:
57+
if (memcmp(resp, "DEFAULT", 7)) {
58+
_at.at_cmd_discard("%RATACT", "=\"DEFAULT\"");
59+
}
60+
_at.unlock();
61+
_op_act = RAT_UNKNOWN;
62+
return NSAPI_ERROR_UNSUPPORTED;
63+
}
64+
65+
_at.restore_at_timeout();
66+
67+
return _at.unlock_return_error();
68+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 ALT1250_PPP_CELLULAR_NETWORK_H_
19+
#define ALT1250_PPP_CELLULAR_NETWORK_H_
20+
21+
#include "AT_CellularNetwork.h"
22+
23+
namespace mbed {
24+
25+
class ALT1250_PPP_CellularNetwork : public AT_CellularNetwork {
26+
public:
27+
ALT1250_PPP_CellularNetwork(ATHandler &atHandler, AT_CellularDevice &device);
28+
virtual ~ALT1250_PPP_CellularNetwork();
29+
30+
protected:
31+
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);
32+
};
33+
34+
} // namespace mbed
35+
36+
#endif // ALT1250_PPP_CELLULAR_NETWORK_H_
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "ALT1250_PPP",
3+
"config": {
4+
"tx": {
5+
"help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.",
6+
"value": null
7+
},
8+
"rx": {
9+
"help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.",
10+
"value": null
11+
},
12+
"rts": {
13+
"help": "RTS pin for serial connection",
14+
"value": null
15+
},
16+
"cts": {
17+
"help": "CTS pin for serial connection",
18+
"value": null
19+
},
20+
"rst": {
21+
"help": "Reset control pin",
22+
"value": null
23+
},
24+
"baudrate": {
25+
"help": "Serial connection baud rate",
26+
"value": 115200
27+
},
28+
"provide-default": {
29+
"help": "Provide as default CellularDevice [true/false]",
30+
"value": false
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)