|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * Copyright (c) 2006-2019 ARM Limited |
| 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 | +#if MBED_CONF_NSAPI_PRESENT |
| 19 | + |
| 20 | +#if EP_AGORA_ENABLE_CELL |
| 21 | + |
| 22 | +#include "cellular/onboard_modem_api.h" |
| 23 | +#include "UARTSerial.h" |
| 24 | +#include "ONBOARD_TELIT_ME910.h" |
| 25 | +#include "ThisThread.h" |
| 26 | +#include "CellularLog.h" |
| 27 | + |
| 28 | +using namespace mbed; |
| 29 | + |
| 30 | +ONBOARD_TELIT_ME910::ONBOARD_TELIT_ME910(FileHandle *fh) : TELIT_ME910(fh, PIN_NAME_CELL_ON_OFF, true) |
| 31 | +{ |
| 32 | +} |
| 33 | + |
| 34 | +nsapi_error_t ONBOARD_TELIT_ME910::hard_power_on() |
| 35 | +{ |
| 36 | + ::onboard_modem_init(); |
| 37 | + return NSAPI_ERROR_OK; |
| 38 | +} |
| 39 | + |
| 40 | +nsapi_error_t ONBOARD_TELIT_ME910::hard_power_off() |
| 41 | +{ |
| 42 | + ::onboard_modem_deinit(); |
| 43 | + return NSAPI_ERROR_OK; |
| 44 | +} |
| 45 | + |
| 46 | +nsapi_error_t ONBOARD_TELIT_ME910::soft_power_on() |
| 47 | +{ |
| 48 | + ::onboard_modem_power_up(); |
| 49 | + // From Telit_xE910 Global form factor App note: It is mandatory to avoid sending data to the serial ports during the first 200ms of the module start-up. |
| 50 | + rtos::ThisThread::sleep_for(200); |
| 51 | + return NSAPI_ERROR_OK; |
| 52 | +} |
| 53 | + |
| 54 | +nsapi_error_t ONBOARD_TELIT_ME910::soft_power_off() |
| 55 | +{ |
| 56 | + ::onboard_modem_power_down(); |
| 57 | + return NSAPI_ERROR_OK; |
| 58 | +} |
| 59 | + |
| 60 | +nsapi_error_t ONBOARD_TELIT_ME910::init() |
| 61 | +{ |
| 62 | + nsapi_error_t err = AT_CellularDevice::init(); |
| 63 | + if (err != NSAPI_ERROR_OK) { |
| 64 | + return err; |
| 65 | + } |
| 66 | + _at->lock(); |
| 67 | +#if DEVICE_SERIAL_FC |
| 68 | + _at->at_cmd_discard("&K3;&C1;&D0", ""); |
| 69 | +#else |
| 70 | + _at->at_cmd_discard("&K0;&C1;&D0", ""); |
| 71 | +#endif |
| 72 | + |
| 73 | + // AT#QSS=1 |
| 74 | + // Enable the Query SIM Status unsolicited indication in the ME. The format of the |
| 75 | + // unsolicited indication is the following: |
| 76 | + // #QSS: <status> |
| 77 | + // The ME informs at |
| 78 | + // every SIM status change through the basic unsolicited indication where <status> range is 0...1 |
| 79 | + // <status> values: |
| 80 | + // - 0: SIM not inserted |
| 81 | + // - 1: SIM inserted |
| 82 | + _at->at_cmd_discard("#QSS", "=1"); |
| 83 | + |
| 84 | + // AT#PSNT=1 |
| 85 | + // Set command enables unsolicited result code for packet service network type (PSNT) |
| 86 | + // having the following format: |
| 87 | + // #PSNT:<nt> |
| 88 | + // <nt> values: |
| 89 | + // - 0: GPRS network |
| 90 | + // - 4: LTE network |
| 91 | + // - 5: unknown or not registered |
| 92 | + _at->at_cmd_discard("#PSNT", "=1"); |
| 93 | + |
| 94 | + // AT+CMER=2 |
| 95 | + // Set command enables sending of unsolicited result codes from TA to TE in the case of |
| 96 | + // indicator state changes. |
| 97 | + // Current setting: buffer +CIEV Unsolicited Result Codes in the TA when TA-TE link is |
| 98 | + // reserved (e.g. on-line data mode) and flush them to the TE after |
| 99 | + // reservation; otherwise forward them directly to the TE |
| 100 | + _at->at_cmd_discard("+CMER", "=2"); |
| 101 | + |
| 102 | + // AT+CMEE=2 |
| 103 | + // Set command disables the use of result code +CME ERROR: <err> as an indication of an |
| 104 | + // error relating to the +Cxxx command issued. When enabled, device related errors cause the +CME |
| 105 | + // ERROR: <err> final result code instead of the default ERROR final result code. ERROR is returned |
| 106 | + // normally when the error message is related to syntax, invalid parameters or DTE functionality. |
| 107 | + // Current setting: enable and use verbose <err> values |
| 108 | + _at->at_cmd_discard("+CMEE", "=2"); |
| 109 | + |
| 110 | + // AT#PORTCFG=0 |
| 111 | + // Set command allows to connect Service Access Points to the external physical ports giving a great |
| 112 | + // flexibility. Examples of Service Access Points: AT Parser Instance #1, #2, #3, etc.. |
| 113 | + _at->at_cmd_discard("#PORTCFG", "=3"); |
| 114 | + |
| 115 | + // AT&W&P |
| 116 | + // - AT&W: Execution command stores on profile <n> the complete configuration of the device. If |
| 117 | + // parameter is omitted, the command has the same behavior of AT&W0. |
| 118 | + // - AT&P: Execution command defines which full profile will be loaded at startup. If parameter |
| 119 | + // is omitted, the command has the same behavior as AT&P0 |
| 120 | + _at->at_cmd_discard("&W&P", ""); |
| 121 | + |
| 122 | + return _at->unlock_return_error(); |
| 123 | +} |
| 124 | + |
| 125 | +CellularDevice *CellularDevice::get_target_default_instance() |
| 126 | +{ |
| 127 | + static UARTSerial serial(MDMTXD, MDMRXD, 115200); |
| 128 | +#if DEVICE_SERIAL_FC |
| 129 | + if (MDMRTS != NC && MDMCTS != NC) { |
| 130 | + tr_debug("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS); |
| 131 | + serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); |
| 132 | + } |
| 133 | +#endif |
| 134 | + static ONBOARD_TELIT_ME910 device(&serial); |
| 135 | + return &device; |
| 136 | +} |
| 137 | + |
| 138 | +#endif // EP_AGORA_ENABLE_CELL |
| 139 | + |
| 140 | +#endif // MBED_CONF_NSAPI_PRESENT |
0 commit comments