|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @file nrf_modem_dect_clock_sync.h |
| 9 | + * |
| 10 | + * @defgroup nrf_modem_dect_clock_sync DECT clock sync interface |
| 11 | + * @{ |
| 12 | + * @brief DECT clock sync API. |
| 13 | + * |
| 14 | + */ |
| 15 | +#ifndef NRF_MODEM_DECT_CLOCK_SYNC_H__ |
| 16 | +#define NRF_MODEM_DECT_CLOCK_SYNC_H__ |
| 17 | + |
| 18 | + |
| 19 | +#ifdef __cplusplus |
| 20 | +extern "C" { |
| 21 | +#endif |
| 22 | + |
| 23 | +/** |
| 24 | + * @brief DECT CS errors. |
| 25 | + */ |
| 26 | +enum nrf_modem_dect_clock_sync_err { |
| 27 | + /** |
| 28 | + * @brief Success. |
| 29 | + */ |
| 30 | + NRF_MODEM_DECT_CLOCK_SYNC_NO_ERROR = 0, |
| 31 | + /** |
| 32 | + * @brief Clock synchronization not active. |
| 33 | + */ |
| 34 | + NRF_MODEM_DECT_CLOCK_SYNC_NOT_ACTIVE = 0xFFFE, |
| 35 | + /** |
| 36 | + * @brief Error. |
| 37 | + */ |
| 38 | + NRF_MODEM_DECT_CLOCK_SYNC_ERROR = 0xFFFF |
| 39 | +}; |
| 40 | + |
| 41 | +/** |
| 42 | + * @brief Clock synchronization enable event. |
| 43 | + */ |
| 44 | +struct nrf_modem_dect_clock_sync_enable_event { |
| 45 | + /** |
| 46 | + * @brief Operation result. |
| 47 | + * |
| 48 | + * Can be one of the following values: |
| 49 | + * |
| 50 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_NO_ERROR |
| 51 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_ERROR |
| 52 | + */ |
| 53 | + enum nrf_modem_dect_clock_sync_err err; |
| 54 | +}; |
| 55 | + |
| 56 | +/** |
| 57 | + * @brief Clock synchronization pulse info event. |
| 58 | + */ |
| 59 | +struct nrf_modem_dect_clock_sync_pulse_info_event { |
| 60 | + /** |
| 61 | + * @brief Operation result. |
| 62 | + * |
| 63 | + * Can be one of the following values: |
| 64 | + * |
| 65 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_NO_ERROR |
| 66 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_NOT_ACTIVE |
| 67 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_ERROR |
| 68 | + */ |
| 69 | + enum nrf_modem_dect_clock_sync_err err; |
| 70 | + |
| 71 | + /** @brief Queried pulse direction (copied from request) */ |
| 72 | + uint16_t pulse_direction; |
| 73 | + |
| 74 | + /** Padding */ |
| 75 | + uint8_t pad[2]; |
| 76 | + |
| 77 | + /** @brief Pulse occurrence time in modem time units */ |
| 78 | + uint64_t pulse_time; |
| 79 | +}; |
| 80 | + |
| 81 | +/** |
| 82 | + * @brief Clock synchronization disable event. |
| 83 | + */ |
| 84 | +struct nrf_modem_dect_clock_sync_disable_event { |
| 85 | + /** |
| 86 | + * @brief Operation result. |
| 87 | + * |
| 88 | + * Can be one of the following values: |
| 89 | + * |
| 90 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_NO_ERROR |
| 91 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_ERROR |
| 92 | + */ |
| 93 | + enum nrf_modem_dect_clock_sync_err err; |
| 94 | +}; |
| 95 | + |
| 96 | +/** |
| 97 | + * @brief Clock synchronization state event. |
| 98 | + */ |
| 99 | +struct nrf_modem_dect_clock_sync_state_event { |
| 100 | + /** |
| 101 | + * @brief Operation result. |
| 102 | + * |
| 103 | + * Can be one of the following values: |
| 104 | + * |
| 105 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_NO_ERROR |
| 106 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_ERROR |
| 107 | + */ |
| 108 | + enum nrf_modem_dect_clock_sync_err err; |
| 109 | + |
| 110 | + /** |
| 111 | + * @brief Clock synchronization status. |
| 112 | + * |
| 113 | + * Indicates whether the modem clock is synchronized to the external clock. |
| 114 | + * - true - synchronized |
| 115 | + * - false - not synchronized |
| 116 | + */ |
| 117 | + bool synchronized; |
| 118 | + |
| 119 | + /** |
| 120 | + * @brief Clock synchronization error standard deviation. |
| 121 | + * |
| 122 | + * Standard deviation of the clock error in parts per million (ppm) when synchronized. |
| 123 | + * Only valid when synchronized is true. |
| 124 | + * |
| 125 | + * Value is encoded in Q3.12 fixed-point format: |
| 126 | + * - Bit 15: Sign bit (0 = positive, 1 = negative) |
| 127 | + * - Bits 14-12: Integer part (3 bits) |
| 128 | + * - Bits 11-0: Fractional part (12 bits) |
| 129 | + * |
| 130 | + * To convert to floating-point ppm: value / 4096.0 |
| 131 | + * |
| 132 | + * Example: 0x1000 (4096 decimal) = 1.0 ppm standard deviation |
| 133 | + */ |
| 134 | + int16_t clock_std_ppm; |
| 135 | +}; |
| 136 | + |
| 137 | +/** |
| 138 | + * @brief Clock synchronization ref output enable event. |
| 139 | + */ |
| 140 | +struct nrf_modem_dect_clock_sync_enable_ref_output_event { |
| 141 | + /** |
| 142 | + * @brief Operation result. |
| 143 | + * |
| 144 | + * Can be one of the following values: |
| 145 | + * |
| 146 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_NO_ERROR |
| 147 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_ERROR |
| 148 | + */ |
| 149 | + enum nrf_modem_dect_clock_sync_err err; |
| 150 | +}; |
| 151 | + |
| 152 | +/** |
| 153 | + * @brief Clock synchronization ref output disable event. |
| 154 | + */ |
| 155 | +struct nrf_modem_dect_clock_sync_disable_ref_output_event { |
| 156 | + /** |
| 157 | + * @brief Operation result. |
| 158 | + * |
| 159 | + * Can be one of the following values: |
| 160 | + * |
| 161 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_NO_ERROR |
| 162 | + * - @ref NRF_MODEM_DECT_CLOCK_SYNC_ERROR |
| 163 | + */ |
| 164 | + enum nrf_modem_dect_clock_sync_err err; |
| 165 | +}; |
| 166 | + |
| 167 | + |
| 168 | +enum nrf_modem_dect_clock_sync_event_id { |
| 169 | + /** |
| 170 | + * @brief Event to indicate the completion of clock synchronization enable |
| 171 | + * operation. |
| 172 | + */ |
| 173 | + NRF_MODEM_DECT_CLOCK_SYNC_EVT_ENABLE, |
| 174 | + /** |
| 175 | + * @brief Event to indicate the completion of clock synchronization disable |
| 176 | + * operation. |
| 177 | + */ |
| 178 | + NRF_MODEM_DECT_CLOCK_SYNC_EVT_DISABLE, |
| 179 | + /** |
| 180 | + * @brief Event carrying synchronization signal information. |
| 181 | + */ |
| 182 | + NRF_MODEM_DECT_CLOCK_SYNC_EVT_PULSE_INFO, |
| 183 | + /** |
| 184 | + * @brief Event carrying clock synchronization state information. |
| 185 | + */ |
| 186 | + NRF_MODEM_DECT_CLOCK_SYNC_EVT_STATE, |
| 187 | + /** |
| 188 | + * @brief Event to indicate the completion of clock synchronization ref output |
| 189 | + * enable operation. |
| 190 | + */ |
| 191 | + NRF_MODEM_DECT_CLOCK_SYNC_EVT_ENABLE_REF_OUTPUT, |
| 192 | + /** |
| 193 | + * @brief Event to indicate the completion of clock synchronization ref output |
| 194 | + * disable operation. |
| 195 | + */ |
| 196 | + NRF_MODEM_DECT_CLOCK_SYNC_EVT_DISABLE_REF_OUTPUT, |
| 197 | +}; |
| 198 | + |
| 199 | +/** |
| 200 | + * @brief Clock synchronization event. |
| 201 | + */ |
| 202 | +struct nrf_modem_dect_clock_sync_event { |
| 203 | + /** |
| 204 | + * @brief Event ID. |
| 205 | + */ |
| 206 | + enum nrf_modem_dect_clock_sync_event_id id; |
| 207 | + /** |
| 208 | + * @brief Event data. |
| 209 | + */ |
| 210 | + union { |
| 211 | + struct nrf_modem_dect_clock_sync_enable_event clock_sync_enable; |
| 212 | + struct nrf_modem_dect_clock_sync_disable_event clock_sync_disable; |
| 213 | + struct nrf_modem_dect_clock_sync_pulse_info_event clock_sync_pulse_info; |
| 214 | + struct nrf_modem_dect_clock_sync_state_event clock_sync_state; |
| 215 | + struct nrf_modem_dect_clock_sync_enable_ref_output_event |
| 216 | + clock_sync_enable_ref_output; |
| 217 | + struct nrf_modem_dect_clock_sync_disable_ref_output_event |
| 218 | + clock_sync_disable_ref_output; |
| 219 | + }; |
| 220 | +}; |
| 221 | + |
| 222 | +/** |
| 223 | + * @brief Application handler prototype for clock sync events. |
| 224 | + */ |
| 225 | +typedef void (*nrf_modem_dect_clock_sync_event_handler_t)( |
| 226 | + const struct nrf_modem_dect_clock_sync_event *event); |
| 227 | + |
| 228 | +/** |
| 229 | + * @brief Set the application event handler for clock sync events. |
| 230 | + * |
| 231 | + * The application must set the handler for events coming for the DECT clock sync before attempting |
| 232 | + * other clock synchronization operations. |
| 233 | + * |
| 234 | + * @param handler Event handler. |
| 235 | + * |
| 236 | + * @return 0 On success. |
| 237 | + * @retval -NRF_EFAULT @p handler is @c NULL. |
| 238 | + */ |
| 239 | +int nrf_modem_dect_clock_sync_event_handler_set(nrf_modem_dect_clock_sync_event_handler_t handler); |
| 240 | + |
| 241 | +/** |
| 242 | + * @brief Clock synchronization pulse direction. |
| 243 | + */ |
| 244 | +enum nrf_modem_dect_clock_sync_pulse_direction { |
| 245 | + /** |
| 246 | + * @brief Received/incoming sync pulse time. |
| 247 | + */ |
| 248 | + NRF_MODEM_DECT_CLOCK_SYNC_PULSE_INCOMING = 0, |
| 249 | + /** |
| 250 | + * @brief Transmitted/outgoing sync pulse time. |
| 251 | + */ |
| 252 | + NRF_MODEM_DECT_CLOCK_SYNC_PULSE_OUTGOING = 1, |
| 253 | +}; |
| 254 | + |
| 255 | +/** |
| 256 | + * @brief Enable external clock synchronization. |
| 257 | + * |
| 258 | + * The external clock signal is expected to be a 1 PPS (pulse-per-second) signal. When |
| 259 | + * synchronization is enabled, the modem's clock rate aligns with the external signal, |
| 260 | + * ensuring that exactly NRF_MODEM_DECT_MODEM_TIME_TICK_RATE_KHZ clock cycles occur |
| 261 | + * between consecutive external clock pulses. |
| 262 | + * |
| 263 | + * Synchronization accuracy (jitter) is 0.001 ppm (parts per million). |
| 264 | + * |
| 265 | + * This operation is performed asynchronously. |
| 266 | + * Completion of this operation is indicated by the @ref NRF_MODEM_DECT_CLOCK_SYNC_EVT_ENABLE |
| 267 | + * event. |
| 268 | + * |
| 269 | + * @retval 0 Request was sent to modem. |
| 270 | + * @retval -NRF_EPERM The Modem library is not initialized. |
| 271 | + * @retval -NRF_EFAULT No event handler is set. |
| 272 | + * @retval -NRF_ENOMEM Not enough shared memory for this request. |
| 273 | + */ |
| 274 | +int nrf_modem_dect_clock_sync_enable(void); |
| 275 | + |
| 276 | +/** |
| 277 | + * @brief Disable external clock synchronization. |
| 278 | + * |
| 279 | + * Once complete, the modem's clock will not be synchronized to the external clock signal anymore. |
| 280 | + * |
| 281 | + * This operation is performed asynchronously. |
| 282 | + * Completion of this operation is indicated by the @ref NRF_MODEM_DECT_CLOCK_SYNC_EVT_DISABLE |
| 283 | + * event. |
| 284 | + * |
| 285 | + * @retval 0 Request was sent to modem. |
| 286 | + * @retval -NRF_EPERM The Modem library is not initialized. |
| 287 | + * @retval -NRF_EFAULT No event handler is set. |
| 288 | + * @retval -NRF_ENOMEM Not enough shared memory for this request. |
| 289 | + */ |
| 290 | +int nrf_modem_dect_clock_sync_disable(void); |
| 291 | + |
| 292 | +/** |
| 293 | + * @brief Query the modem for the next synchronization signal. |
| 294 | + * |
| 295 | + * Can be used to query when the next synchronization signal is expected to happen. |
| 296 | + * |
| 297 | + * This operation is performed asynchronously. |
| 298 | + * Completion of this operation is indicated by the |
| 299 | + * @ref NRF_MODEM_DECT_CLOCK_SYNC_EVT_PULSE_INFO event. |
| 300 | + * |
| 301 | + * @param pulse_direction Direction of the pulse to query information about. |
| 302 | + * |
| 303 | + * @retval 0 Request was sent to modem. |
| 304 | + * @retval -NRF_EPERM The Modem library is not initialized. |
| 305 | + * @retval -NRF_EFAULT No event handler is set. |
| 306 | + * @retval -NRF_ENOMEM Not enough shared memory for this request. |
| 307 | + */ |
| 308 | +int nrf_modem_dect_clock_sync_get_pulse_info( |
| 309 | + enum nrf_modem_dect_clock_sync_pulse_direction direction); |
| 310 | + |
| 311 | +/** |
| 312 | + * @brief Query the modem for the synchronization state. |
| 313 | + * |
| 314 | + * This operation is performed asynchronously. |
| 315 | + * Completion of this operation is indicated by the |
| 316 | + * @ref NRF_MODEM_DECT_CLOCK_SYNC_EVT_STATE event. |
| 317 | + * |
| 318 | + * @retval 0 Request was sent to modem. |
| 319 | + * @retval -NRF_EPERM The Modem library is not initialized. |
| 320 | + * @retval -NRF_EFAULT No event handler is set. |
| 321 | + * @retval -NRF_ENOMEM Not enough shared memory for this request. |
| 322 | + */ |
| 323 | +int nrf_modem_dect_clock_sync_get_state(void); |
| 324 | + |
| 325 | +/** |
| 326 | + * @brief Enable external clock synchronization reference output. |
| 327 | + * |
| 328 | + * When reference output is enabled, the modem outputs a signal on COEX1 |
| 329 | + * pin. The output signal is sent once per second as seen in modem internal |
| 330 | + * time. The output signal has 100 ms pulse width. |
| 331 | + * |
| 332 | + * This operation is performed asynchronously. |
| 333 | + * Completion of this operation is indicated by the |
| 334 | + * @ref NRF_MODEM_DECT_CLOCK_SYNC_EVT_ENABLE_REF_OUTPUT event. |
| 335 | + * |
| 336 | + * @retval 0 Request was sent to modem. |
| 337 | + * @retval -NRF_EPERM The Modem library is not initialized. |
| 338 | + * @retval -NRF_EFAULT No event handler is set. |
| 339 | + * @retval -NRF_ENOMEM Not enough shared memory for this request. |
| 340 | + */ |
| 341 | +int nrf_modem_dect_clock_sync_enable_ref_output(void); |
| 342 | + |
| 343 | +/** |
| 344 | + * @brief Disable external clock synchronization reference output. |
| 345 | + * |
| 346 | + * Once complete, the modem will not output the reference signal on COEX1 pin |
| 347 | + * anymore. |
| 348 | + * |
| 349 | + * This operation is performed asynchronously. |
| 350 | + * Completion of this operation is indicated by the |
| 351 | + * @ref NRF_MODEM_DECT_CLOCK_SYNC_EVT_DISABLE_REF_OUTPUT event. |
| 352 | + * |
| 353 | + * @retval 0 Request was sent to modem. |
| 354 | + * @retval -NRF_EPERM The Modem library is not initialized. |
| 355 | + * @retval -NRF_EFAULT No event handler is set. |
| 356 | + * @retval -NRF_ENOMEM Not enough shared memory for this request. |
| 357 | + */ |
| 358 | +int nrf_modem_dect_clock_sync_disable_ref_output(void); |
| 359 | + |
| 360 | +#ifdef __cplusplus |
| 361 | +} |
| 362 | +#endif |
| 363 | + |
| 364 | +#endif /* NRF_MODEM_DECT_CLOCK_SYNC_H__ */ |
| 365 | +/** @} */ |
0 commit comments