|
| 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 | +} |
0 commit comments