|
| 1 | +/* |
| 2 | + * Copyright (c) 2023 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @file nrf_modem_rs_capture.h |
| 9 | + * |
| 10 | + * @defgroup nrf_modem_rs_capture RS capture API |
| 11 | + * @{ |
| 12 | + * @brief API for accessing the RS capture module on the modem. |
| 13 | + */ |
| 14 | +#ifndef NRF_MODEM_RS_CAPTURE_H__ |
| 15 | +#define NRF_MODEM_RS_CAPTURE_H__ |
| 16 | + |
| 17 | +#include <stdint.h> |
| 18 | +#include <stdbool.h> |
| 19 | + |
| 20 | +#ifdef __cplusplus |
| 21 | +extern "C" { |
| 22 | +#endif |
| 23 | + |
| 24 | +/** Maximum number of data samples in 'data' member in @ref nrf_modem_rs_capture_prs_sample. */ |
| 25 | +#define NRF_MODEM_RS_CAPTURE_MAX_DATA_SAMPLES 1536 |
| 26 | + |
| 27 | +/** |
| 28 | + * @defgroup nrf_modem_rs_capture_status RS capture status values. |
| 29 | + * @brief RS capture status values. |
| 30 | + * @{ |
| 31 | + */ |
| 32 | +/** Success. */ |
| 33 | +#define NRF_MODEM_RS_CAPTURE_STATUS_SUCCESS 0x00 |
| 34 | +/** Success, cell available. */ |
| 35 | +#define NRF_MODEM_RS_CAPTURE_STATUS_CELL_AVAILABLE 0x00 |
| 36 | +/** Memory not available. */ |
| 37 | +#define NRF_MODEM_RS_CAPTURE_STATUS_NO_MEM 0x01 |
| 38 | +/** Cell not available. */ |
| 39 | +#define NRF_MODEM_RS_CAPTURE_STATUS_NO_CELL 0x03 |
| 40 | +/** Modem or capture session not active. */ |
| 41 | +#define NRF_MODEM_RS_CAPTURE_STATUS_NOT_ACTIVE 0x04 |
| 42 | +/** Modem temporarily busy. */ |
| 43 | +#define NRF_MODEM_RS_CAPTURE_STATUS_BUSY 0x05 |
| 44 | +/** Operation not supported. */ |
| 45 | +#define NRF_MODEM_RS_CAPTURE_STATUS_NOT_SUPPORTED 0x06 |
| 46 | +/** Operation failed due to a timeout. */ |
| 47 | +#define NRF_MODEM_RS_CAPTURE_STATUS_TIMEOUT 0x07 |
| 48 | +/** Session stopped. */ |
| 49 | +#define NRF_MODEM_RS_CAPTURE_STATUS_STOPPED 0x08 |
| 50 | +/** @} */ |
| 51 | + |
| 52 | +/** Event IDs. */ |
| 53 | +enum nrf_modem_rs_capture_event_id { |
| 54 | + /** PRS sample notification. |
| 55 | + * |
| 56 | + * Event data is of type @ref nrf_modem_rs_capture_prs_sample |
| 57 | + * in @ref nrf_modem_rs_capture_event_data. |
| 58 | + */ |
| 59 | + NRF_MODEM_RS_CAPTURE_EVT_PRS_SAMPLE = 1, |
| 60 | + /** Cell status notification. |
| 61 | + * |
| 62 | + * Event data is of type @ref nrf_modem_rs_capture_cell_status |
| 63 | + * in @ref nrf_modem_rs_capture_event_data. |
| 64 | + */ |
| 65 | + NRF_MODEM_RS_CAPTURE_EVT_CELL_STATUS, |
| 66 | + /** RS capture session aborted. |
| 67 | + * |
| 68 | + * There is no associated event data. |
| 69 | + */ |
| 70 | + NRF_MODEM_RS_CAPTURE_EVT_ABORT, |
| 71 | +}; |
| 72 | + |
| 73 | +/** RS capture session start request parameters. */ |
| 74 | +struct nrf_modem_rs_capture_session_start_req { |
| 75 | + /** RS capture session timeout in milliseconds. */ |
| 76 | + uint32_t timeout; |
| 77 | +}; |
| 78 | + |
| 79 | +/** RS capture session start response parameters. */ |
| 80 | +struct nrf_modem_rs_capture_session_start_resp { |
| 81 | + /** PLMN ID. |
| 82 | + * |
| 83 | + * Bytes encoded as follows: |
| 84 | + * mcc2_mcc1, mnc3_mcc3, mnc2_mnc1 |
| 85 | + */ |
| 86 | + uint8_t plmn[3]; |
| 87 | + /** 28bit cell id. */ |
| 88 | + uint32_t cell_id; |
| 89 | + /** Mobile Country Code. Range: 0...999. */ |
| 90 | + uint16_t mcc; |
| 91 | + /** Mobile Network Code. Range: 0...999. */ |
| 92 | + uint16_t mnc; |
| 93 | +}; |
| 94 | + |
| 95 | +/** PRS capture configure request parameters. */ |
| 96 | +struct nrf_modem_rs_capture_prs_config { |
| 97 | + /** Set of gain offset values, in dB, used for RS capture. Range: -127...127. |
| 98 | + * |
| 99 | + * Offsets are relative to the normal LTE gain settings for the serving cell. |
| 100 | + * |
| 101 | + * This pattern is repeated one after the other in the RS capture procedure. |
| 102 | + * The table must be filled entirely but same value can be set into several indices. |
| 103 | + * The first value is applied in the first PRS occasion after SFN0. |
| 104 | + */ |
| 105 | + int8_t gain_offset[16]; |
| 106 | + /** Pattern of narrowband values used for RS capture. Range for each value is 0...16. |
| 107 | + * |
| 108 | + * Narrowband numbering is as in 3GPP TS 36.211 added by one. |
| 109 | + * Narrowband 0 is reserved for the central narrowband exactly in the middle of system BW. |
| 110 | + * |
| 111 | + * This pattern is repeated one after the other in the RS capture procedure. |
| 112 | + * The table must be filled entirely but same value can be set into several indices. |
| 113 | + * The first value is applied in the first PRS occasion after SFN0. |
| 114 | + */ |
| 115 | + uint8_t nb_pattern[16]; |
| 116 | + /** PRS configuration index specified in 3GPP TS 36.211. Range is 0...4095. */ |
| 117 | + uint16_t i_prs; |
| 118 | + /** Timing offset. Range: -2192...2192. |
| 119 | + * |
| 120 | + * Offset of FFT window compared to own cell timing, in 30.72MHz samples. |
| 121 | + */ |
| 122 | + int16_t timing_offset; |
| 123 | + /** Index of the configuration. Range: 0...255 |
| 124 | + * |
| 125 | + * Returned in @ref nrf_modem_rs_capture_prs_sample in |
| 126 | + * @ref NRF_MODEM_RS_CAPTURE_EVT_PRS_SAMPLE. |
| 127 | + */ |
| 128 | + uint8_t index; |
| 129 | +}; |
| 130 | + |
| 131 | +/** PRS sample. */ |
| 132 | +struct nrf_modem_rs_capture_prs_sample { |
| 133 | + /** PLMN ID. |
| 134 | + * |
| 135 | + * Bytes encoded as follows: |
| 136 | + * mcc2_mcc1, mnc3_mcc3, mnc2_mnc1 |
| 137 | + */ |
| 138 | + uint8_t plmn[3]; |
| 139 | + /** 28bit cell id. */ |
| 140 | + uint32_t cell_id; |
| 141 | + /** Mobile Country Code. Range: 0...999. */ |
| 142 | + uint16_t mcc; |
| 143 | + /** Mobile Network Code. Range: 0...999. */ |
| 144 | + uint16_t mnc; |
| 145 | + /** Index of the configuration used to capture the sample. Range: 0 ... 255 |
| 146 | + * |
| 147 | + * Index matches to the one given in @ref nrf_modem_rs_capture_prs_config. |
| 148 | + */ |
| 149 | + uint8_t index; |
| 150 | + /** Narrowband. Range: 0...16. |
| 151 | + * |
| 152 | + * Narrowband numbering is as in 3GPP TS 36.211 added by one. |
| 153 | + * Narrowband 0 is reserved for the central narrowband exactly in the middle of system BW. |
| 154 | + */ |
| 155 | + uint8_t nb; |
| 156 | + /** System frame number. Range: 0...1023. */ |
| 157 | + uint16_t sfn; |
| 158 | + /** Number of captured 16bit frequency domain samples, I and Q separately. |
| 159 | + * |
| 160 | + * 0 or 1536. |
| 161 | + */ |
| 162 | + uint16_t num_samples; |
| 163 | + /** Timing offset. Range: -2192...2192. |
| 164 | + * |
| 165 | + * Offset of FFT window compared to own cell timing, in 30.72MHz samples. |
| 166 | + */ |
| 167 | + int16_t timing_offset; |
| 168 | + /** RSSI in dBm. Range: -20...-120. */ |
| 169 | + int8_t rssi; |
| 170 | + /** Gain offset in dB. Range: -127...127. |
| 171 | + * |
| 172 | + * Offset is relative to the normal LTE gain settings for the serving cell. |
| 173 | + */ |
| 174 | + int8_t gain_offset; |
| 175 | + |
| 176 | + /** Data samples. |
| 177 | + * |
| 178 | + * Number of data samples is indicated in @ref num_samples variable. |
| 179 | + * |
| 180 | + * Frequency domain samples, 16bit signed I & Q, I first. |
| 181 | + * |
| 182 | + * 8 PRB's (96 subcarriers) are stored per OFDM symbol, in frequency increasing order |
| 183 | + * (subcarrier #0 first, #95 last). |
| 184 | + * |
| 185 | + * Only OFDM symbols containing PRS are stored except in 4 TX antenna configuration, where |
| 186 | + * every eight symbols is invalid. |
| 187 | + * |
| 188 | + * If present based on @ref num_samples variable, number of samples is |
| 189 | + * 2 (I+Q) * 8 PRS symbols * 8 PRBs * 12 subcarriers = 1536 samples. |
| 190 | + * |
| 191 | + * Centermost 6 PRB's (#1..#6, from #0..#7) within these 8 PRB's always correspond to |
| 192 | + * the configured LTE-M narrowband (@ref nb variable). |
| 193 | + * |
| 194 | + * If either or both PRB's on the edge (PRB #0 and/or #7) are outside of the |
| 195 | + * LTE cell bandwidth, they are still returned but do not contain LTE signal. |
| 196 | + * This happens if cell bandwidth is 1.4MHz, or cell bandwidth is 5MHz and first or |
| 197 | + * last narrowband is configured. |
| 198 | + * |
| 199 | + * When LTE-M narrowband reception is configured (@ref nb variable is 1..16): |
| 200 | + * - UE RF center frequency is set at the first subcarrier of PRB #4 (subcarrier #48), |
| 201 | + * except when physical cell ID mod 3 == 0, when it is at the second subcarrier of |
| 202 | + * PRB #4 (subcarrier #49). |
| 203 | + * - This subcarrier is zeroed in the data. |
| 204 | + * - Phase offset caused by subcarrier offset between UE RF center frequency and |
| 205 | + * cell center frequency is compensated in the data. |
| 206 | + * - If empty subcarrier at the cell center is within the 8 PRB reception window, |
| 207 | + * it is removed from the data. |
| 208 | + * |
| 209 | + * When LTE cell center frequency reception is configured (@ref nb variable is zero): |
| 210 | + * - UE RF center frequency is set at the empty subcarrier at cell center. |
| 211 | + * This subcarrier is removed from the data. |
| 212 | + */ |
| 213 | + int16_t *data; |
| 214 | +}; |
| 215 | + |
| 216 | +/** Cell status. */ |
| 217 | +struct nrf_modem_rs_capture_cell_status { |
| 218 | + /** PLMN ID. |
| 219 | + * |
| 220 | + * Bytes encoded as follows: |
| 221 | + * mcc2_mcc1, mnc3_mcc3, mnc2_mnc1 |
| 222 | + */ |
| 223 | + uint8_t plmn[3]; |
| 224 | + /** 28bit cell id. */ |
| 225 | + uint32_t cell_id; |
| 226 | + /** Mobile Country Code. Range: 0...999. */ |
| 227 | + uint16_t mcc; |
| 228 | + /** Mobile Network Code. Range: 0...999. */ |
| 229 | + uint16_t mnc; |
| 230 | +}; |
| 231 | + |
| 232 | +/** RS capture event data. */ |
| 233 | +struct nrf_modem_rs_capture_event_data { |
| 234 | + /** Event ID. */ |
| 235 | + enum nrf_modem_rs_capture_event_id event_id; |
| 236 | + |
| 237 | + /** Status from @ref nrf_modem_rs_capture_status. |
| 238 | + * |
| 239 | + * Possible values for @ref NRF_MODEM_RS_CAPTURE_EVT_PRS_SAMPLE event: |
| 240 | + * - NRF_MODEM_RS_CAPTURE_STATUS_SUCCESS Success. |
| 241 | + * - NRF_MODEM_RS_CAPTURE_STATUS_NO_MEM No memory for sample. |
| 242 | + * |
| 243 | + * Possible values for @ref NRF_MODEM_RS_CAPTURE_EVT_CELL_STATUS event: |
| 244 | + * - NRF_MODEM_RS_CAPTURE_STATUS_CELL_AVAILABLE: Cell available. |
| 245 | + * - NRF_MODEM_RS_CAPTURE_STATUS_NO_CELL: Cell lost. |
| 246 | + * |
| 247 | + * Possible values for @ref NRF_MODEM_RS_CAPTURE_EVT_ABORT event: |
| 248 | + * - NRF_MODEM_RS_CAPTURE_STATUS_NO_CELL: Cell lost. |
| 249 | + * - NRF_MODEM_RS_CAPTURE_STATUS_STOPPED: Session duration exceeded or |
| 250 | + * higher priority activity stopped the session. |
| 251 | + */ |
| 252 | + int32_t status; |
| 253 | + |
| 254 | + /** Event specific data. */ |
| 255 | + union { |
| 256 | + /** Data for @ref NRF_MODEM_RS_CAPTURE_EVT_PRS_SAMPLE event. */ |
| 257 | + struct nrf_modem_rs_capture_prs_sample prs_sample; |
| 258 | + /** Data for @ref NRF_MODEM_RS_CAPTURE_EVT_CELL_STATUS event. */ |
| 259 | + struct nrf_modem_rs_capture_cell_status cell_status; |
| 260 | + }; |
| 261 | +}; |
| 262 | + |
| 263 | +/** @brief Event handler prototype. |
| 264 | + * |
| 265 | + * @param[in] event_data Event data. |
| 266 | + */ |
| 267 | +typedef void (*nrf_modem_rs_capture_event_handler_type_t)( |
| 268 | + const struct nrf_modem_rs_capture_event_data *event_data); |
| 269 | + |
| 270 | +/** @brief Version negotiation for the RS capture API. |
| 271 | + * |
| 272 | + * @details Request desired RS capture version and get the selected version. |
| 273 | + * Selected version is decided by the modem based on its support and requested version. |
| 274 | + * |
| 275 | + * @param[in] version Requested version. |
| 276 | + * |
| 277 | + * @retval -NRF_EPERM The Modem library is not initialized. |
| 278 | + * @retval -NRF_EBADMSG The modem responded with wrong response. |
| 279 | + * @retval -NRF_ENOMEM There is not enough shared memory for this request. |
| 280 | + * @retval -NRF_ESHUTDOWN The modem was shut down. |
| 281 | + * @returns Positive value indicates selected version. |
| 282 | + */ |
| 283 | +int32_t nrf_modem_rs_capture_version(uint8_t version); |
| 284 | + |
| 285 | +/** @brief Starts RS capture session. |
| 286 | + * |
| 287 | + * @details This function prepares RS capture sampling session but the actual sampling |
| 288 | + * is not started until @ref nrf_modem_rs_capture_prs_configure function is called. |
| 289 | + * An event handler is also given to this function to receive the samples. |
| 290 | + * |
| 291 | + * @note The event handler is executed in interrupt context so a lot of processing inside the |
| 292 | + * handler may have performance implications and side effects. It's recommended to use the |
| 293 | + * handler only for signaling or re-scheduling processing to a separate thread. |
| 294 | + * |
| 295 | + * @param[in] req Session start request parameters. |
| 296 | + * @param[out] resp Session start response parameters if 0 is returned. |
| 297 | + * @param[in] callback Event handler function. |
| 298 | + * |
| 299 | + * @retval 0 on success. |
| 300 | + * @retval -NRF_EBUSY Another RS capture session is ongoing. |
| 301 | + * @retval -NRF_EPERM The Modem library is not initialized. |
| 302 | + * @retval -NRF_EBADMSG The modem responded with wrong response. |
| 303 | + * @retval -NRF_EFAULT Input parameter is NULL. |
| 304 | + * @retval -NRF_ENOMEM There is not enough shared memory for this request. |
| 305 | + * @retval -NRF_ESHUTDOWN The modem was shut down. |
| 306 | + * @retval NRF_MODEM_RS_CAPTURE_STATUS_NO_CELL Cell not found. |
| 307 | + * @retval NRF_MODEM_RS_CAPTURE_STATUS_BUSY Resources not available or session already started. |
| 308 | + * @retval NRF_MODEM_RS_CAPTURE_STATUS_NOT_SUPPORTED Capture not supported in current LTE system. |
| 309 | + * @retval NRF_MODEM_RS_CAPTURE_STATUS_TIMEOUT Timeout. |
| 310 | + * @retval NRF_MODEM_RS_CAPTURE_STATUS_STOPPED Stop requested during start. |
| 311 | + */ |
| 312 | +int32_t nrf_modem_rs_capture_session_start( |
| 313 | + const struct nrf_modem_rs_capture_session_start_req *req, |
| 314 | + struct nrf_modem_rs_capture_session_start_resp *resp, |
| 315 | + nrf_modem_rs_capture_event_handler_type_t callback); |
| 316 | + |
| 317 | +/** @brief Stops RS capture. |
| 318 | + * |
| 319 | + * @retval 0 on success. |
| 320 | + * @retval -NRF_EPERM The Modem library is not initialized. |
| 321 | + * @retval -NRF_EBADMSG The modem responded with wrong response. |
| 322 | + * @retval -NRF_ENOMEM There is not enough shared memory for this request. |
| 323 | + * @retval -NRF_ESHUTDOWN The modem was shut down. |
| 324 | + */ |
| 325 | +int32_t nrf_modem_rs_capture_session_stop(void); |
| 326 | + |
| 327 | +/** @brief Configure PRS capture. |
| 328 | + * |
| 329 | + * @details This function can be used to start PRS sampling, or reconfigure an ongoing sampling. |
| 330 | + * |
| 331 | + * Given configuration is applied immediately and index variable in |
| 332 | + * @ref nrf_modem_rs_capture_prs_sample indicates when exactly this happened. |
| 333 | + * |
| 334 | + * @param[in] req PRS configure request parameters. |
| 335 | + * |
| 336 | + * @retval 0 on success. |
| 337 | + * @retval -NRF_EPERM The Modem library is not initialized. |
| 338 | + * @retval -NRF_EBADMSG The modem responded with wrong response. |
| 339 | + * @retval -NRF_EFAULT Input parameter is NULL. |
| 340 | + * @retval -NRF_ENOMEM There is not enough shared memory for this request. |
| 341 | + * @retval -NRF_ESHUTDOWN The modem was shut down. |
| 342 | + * @retval NRF_MODEM_RS_CAPTURE_STATUS_NOT_ACTIVE Session not active. |
| 343 | + * @retval NRF_MODEM_RS_CAPTURE_STATUS_NOT_SUPPORTED Parameter values not supported. |
| 344 | + */ |
| 345 | +int32_t nrf_modem_rs_capture_prs_configure(const struct nrf_modem_rs_capture_prs_config *req); |
| 346 | + |
| 347 | +#ifdef __cplusplus |
| 348 | +} |
| 349 | +#endif |
| 350 | + |
| 351 | +#endif /* NRF_MODEM_RS_CAPTURE_H__ */ |
| 352 | +/** @} */ |
0 commit comments