|
| 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 | +#ifndef CELLULAR_API_CELLULARPOWER_H_ |
| 18 | +#define CELLULAR_API_CELLULARPOWER_H_ |
| 19 | + |
| 20 | +#include "nsapi_types.h" |
| 21 | +#include "Callback.h" |
| 22 | + |
| 23 | +namespace mbed { |
| 24 | + |
| 25 | +/** |
| 26 | + * Class CellularPower |
| 27 | + * |
| 28 | + * An interface that provides power handling functions for modem/module. |
| 29 | + */ |
| 30 | +class CellularPower { |
| 31 | +protected: |
| 32 | + // friend of CellularDevice so that it's the only way to close/delete this class. |
| 33 | + friend class CellularDevice; |
| 34 | + |
| 35 | + /** |
| 36 | + * virtual Destructor |
| 37 | + */ |
| 38 | + virtual ~CellularPower() {} |
| 39 | + |
| 40 | +public: |
| 41 | + /* Access technology used in method opt_receive_period */ |
| 42 | + enum EDRXAccessTechnology { |
| 43 | + EDRXGSM_EC_GSM_IoT_mode = 1, |
| 44 | + EDRXGSM_A_Gb_mode, |
| 45 | + EDRXUTRAN_Iu_mode, |
| 46 | + EDRXEUTRAN_WB_S1_mode, |
| 47 | + EDRXEUTRAN_NB_S1_mode |
| 48 | + }; |
| 49 | + |
| 50 | + /** Set cellular device power on. Default implementation is empty. |
| 51 | + * Device power on/off is modem/board specific behavior and must be done on inherited class if needed. |
| 52 | + * Power on is done by toggling power pin/button. |
| 53 | + * |
| 54 | + * @remark set_at_mode must be called to initialise modem |
| 55 | + * |
| 56 | + * @return NSAPI_ERROR_OK on success |
| 57 | + * NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem |
| 58 | + */ |
| 59 | + virtual nsapi_error_t on() = 0; |
| 60 | + |
| 61 | + /** Set cellular device power off. Default implementation is empty. |
| 62 | + * Device power on/off is modem/board specific behavior and must be done on inherited class if needed. |
| 63 | + * Power off is done by toggling power pin/button. |
| 64 | + * |
| 65 | + * @return NSAPI_ERROR_OK on success |
| 66 | + * NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem |
| 67 | + */ |
| 68 | + virtual nsapi_error_t off() = 0; |
| 69 | + |
| 70 | + /** Set AT command mode. Blocking until success or failure. |
| 71 | + * |
| 72 | + * @remark must be called after power on to prepare correct AT mode |
| 73 | + * |
| 74 | + * @return NSAPI_ERROR_OK on success |
| 75 | + * NSAPI_ERROR_DEVICE_ERROR on failure |
| 76 | + */ |
| 77 | + virtual nsapi_error_t set_at_mode() = 0; |
| 78 | + |
| 79 | + /** Set cellular device power level by enabling/disabling functionality. |
| 80 | + * |
| 81 | + * @param func_level: |
| 82 | + * 0 minimum functionality |
| 83 | + * 1 full functionality. Enable (turn on) the transmit and receive RF circuits for all supported radio access technologies. |
| 84 | + * For MTs supporting +CSRA, this equals the RATs indicated by the response of +CSRA=?. Current +CSRA setting is ignored. |
| 85 | + * It is not required that the MT transmit and receive RF circuits are in a disabled state for this setting to have effect. |
| 86 | + * 2 disable (turn off) MT transmit RF circuits only |
| 87 | + * 3 disable (turn off) MT receive RF circuits only |
| 88 | + * 4 disable (turn off) both MT transmit and receive RF circuits |
| 89 | + * @param do_reset 0 for do not reset, 1 for reset the device when changing the functionality |
| 90 | + * |
| 91 | + * @remark See 3GPP TS 27.007 CFUN for more details |
| 92 | + * |
| 93 | + * @return NSAPI_ERROR_OK on success |
| 94 | + * NSAPI_ERROR_DEVICE_ERROR on failure |
| 95 | + */ |
| 96 | + virtual nsapi_error_t set_power_level(int func_level, int do_reset = 0, const char *sim_pin = NULL) = 0; |
| 97 | + |
| 98 | + /** Reset and wake-up cellular device. |
| 99 | + * |
| 100 | + * @return NSAPI_ERROR_OK on success |
| 101 | + * NSAPI_ERROR_DEVICE_ERROR on failure |
| 102 | + */ |
| 103 | + virtual nsapi_error_t reset() = 0; |
| 104 | + |
| 105 | + /** Opt for power save setting on cellular device. If both parameters are zero, this disables PSM. |
| 106 | + * |
| 107 | + * @remark See 3GPP TS 27.007 PSM for details |
| 108 | + * |
| 109 | + * @param periodic_time Timeout in seconds IoT subsystem is not expecting messaging |
| 110 | + * @param active_time Timeout in seconds IoT subsystem waits for response |
| 111 | + * |
| 112 | + * @return NSAPI_ERROR_OK on success |
| 113 | + * NSAPI_ERROR_DEVICE_ERROR on failure |
| 114 | + */ |
| 115 | + virtual nsapi_error_t opt_power_save_mode(int periodic_time, int active_time) = 0; |
| 116 | + |
| 117 | + /** Opt for discontinuous reception on cellular device. |
| 118 | + * |
| 119 | + * @remark See 3GPP TS 27.007 eDRX for details. |
| 120 | + * |
| 121 | + * @param mode disable or enable the use of eDRX |
| 122 | + * @param act_type type of access technology |
| 123 | + * @param edrx_value requested edxr value. Extended DRX parameters information element. |
| 124 | + * |
| 125 | + * @return NSAPI_ERROR_OK on success |
| 126 | + * NSAPI_ERROR_DEVICE_ERROR on failure |
| 127 | + */ |
| 128 | + virtual nsapi_error_t opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) = 0; |
| 129 | + |
| 130 | + /** Check whether the device is ready to accept commands. |
| 131 | + * |
| 132 | + * @return NSAPI_ERROR_OK on success |
| 133 | + * NSAPI_ERROR_DEVICE_ERROR on failure |
| 134 | + */ |
| 135 | + virtual nsapi_error_t is_device_ready() = 0; |
| 136 | + |
| 137 | + /** Set URC callback function for device specific ready urc. URC is defined in device specific |
| 138 | + * power API. Used in startup sequence to listen when device is ready |
| 139 | + * for using at commands and possible sim. |
| 140 | + * |
| 141 | + * @param callback Callback function called when urc received |
| 142 | + * |
| 143 | + * @return NSAPI_ERROR_OK on success |
| 144 | + * NSAPI_ERROR_NO_MEMORY on memory failure |
| 145 | + * NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem |
| 146 | + */ |
| 147 | + virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback<void()> callback) = 0; |
| 148 | + |
| 149 | + /** Removes the device ready urc from the list of urc's. |
| 150 | + * |
| 151 | + * @param callback callback to remove from the list of urc's |
| 152 | + */ |
| 153 | + virtual void remove_device_ready_urc_cb(mbed::Callback<void()> callback) = 0; |
| 154 | +}; |
| 155 | + |
| 156 | +} // namespace mbed |
| 157 | + |
| 158 | +#endif /* CELLULAR_API_CELLULARPOWER_H_ */ |
0 commit comments