1 /***************************************************************************//**
2  * @file
3  * @brief The BLE specific header file for the RAIL library.
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
7  *******************************************************************************
8  *
9  * SPDX-License-Identifier: Zlib
10  *
11  * The licensor of this software is Silicon Laboratories Inc.
12  *
13  * This software is provided 'as-is', without any express or implied
14  * warranty. In no event will the authors be held liable for any damages
15  * arising from the use of this software.
16  *
17  * Permission is granted to anyone to use this software for any purpose,
18  * including commercial applications, and to alter it and redistribute it
19  * freely, subject to the following restrictions:
20  *
21  * 1. The origin of this software must not be misrepresented; you must not
22  *    claim that you wrote the original software. If you use this software
23  *    in a product, an acknowledgment in the product documentation would be
24  *    appreciated but is not required.
25  * 2. Altered source versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.
27  * 3. This notice may not be removed or altered from any source distribution.
28  *
29  ******************************************************************************/
30 
31 #ifndef __RAIL_BLE_H__
32 #define __RAIL_BLE_H__
33 
34 // Get the standard include types
35 #include <stdint.h>
36 #include <stdbool.h>
37 
38 // Get the RAIL specific structures and types
39 #include "rail_types.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /// @addtogroup BLE
46 /// @ingroup Protocol_Specific
47 /// Accelerator routines for Bluetooth Low Energy (BLE).
48 ///
49 /// The APIs in this module configure the radio for BLE
50 /// operation and provide additional helper routines necessary for
51 /// normal BLE send/receive that aren't available directly in RAIL.
52 /// RAIL APIs should be used to set up the application. However,
53 /// \ref RAIL_ConfigChannels() and \ref RAIL_ConfigRadio() should not be called to set up
54 /// the PHY. Instead, RAIL_BLE_Config* APIs should be used to set up the
55 /// 1 Mbps, 2 Mbps, or Coded PHY configurations needed by the application. These
56 /// APIs will configure the hardware and also configure the set of valid BLE
57 /// channels.
58 ///
59 /// To implement a standard BLE link layer, you will also need to handle tight
60 /// turnaround times and send packets at specific instants. This can all be
61 /// managed through general RAIL functions, such as \ref RAIL_StartScheduledTx(),
62 /// \ref RAIL_ScheduleRx(), and \ref RAIL_SetStateTiming(). See RAIL APIs for more
63 /// useful functions.
64 ///
65 /// A simple example to set up the application to be in BLE mode is shown
66 /// below. Note that this will put the radio on the first advertising channel
67 /// with the advertising Access Address. In any full-featured BLE application you
68 /// will need to use the \ref RAIL_BLE_ConfigChannelRadioParams() function to change
69 /// the sync word and other parameters as needed based on your connection.
70 /// @code{.c}
71 /// // RAIL handle set at initialization time.
72 /// static RAIL_Handle_t gRailHandle = NULL;
73 ///
74 /// static void radioEventHandler(RAIL_Handle_t railHandle,
75 ///                               RAIL_Events_t events)
76 /// {
77 ///   // ... handle RAIL events, e.g., receive and transmit completion
78 /// }
79 ///
80 /// // Set the radio to receive on the first BLE advertising channel.
81 /// void bleAdvertiseEnable(void)
82 /// {
83 ///   RAIL_Config_t railCfg = {
84 ///     .eventsCallback = &radioEventHandler,
85 ///   };
86 ///
87 ///   // Initializes the RAIL library and any internal state it requires.
88 ///   gRailHandle = RAIL_Init(&railCfg, NULL);
89 ///
90 ///   // Calls the BLE initialization function to load the right radio configuration.
91 ///   RAIL_BLE_Init(gRailHandle);
92 ///
93 ///   // Always choose the Viterbi PHY configuration if available on your chip
94 ///   // for performance reasons.
95 ///   RAIL_BLE_ConfigPhy1MbpsViterbi(gRailHandle);
96 ///
97 ///   // Configures us for the first advertising channel (Physical: 0, Logical: 37).
98 ///   // The CRC init value and Access Address come from the BLE specification.
99 ///   RAIL_BLE_ConfigChannelRadioParams(gRailHandle,
100 ///                                     0x555555,
101 ///                                     0x8E89BED6,
102 ///                                     37,
103 ///                                     false);
104 ///
105 ///   // Starts receiving on physical channel 0 (logical channel 37).
106 ///   RAIL_StartRx(gRailHandle, 0, NULL);
107 ///  }
108 /// @endcode
109 ///
110 /// @{
111 
112 /**
113  * @enum RAIL_BLE_Coding_t
114  * @brief The variant of the BLE Coded PHY.
115  */
RAIL_ENUM(RAIL_BLE_Coding_t)116 RAIL_ENUM(RAIL_BLE_Coding_t) {
117   /** Enables the 125 kbps variant of the BLE Coded PHY. */
118   RAIL_BLE_Coding_125kbps = 0,
119   /** @deprecated Will be removed in a future version of RAIL. */
120   RAIL_BLE_Coding_125kbps_DSA = 1,
121   /** Enables the 500 kbps variant of the BLE Coded PHY. */
122   RAIL_BLE_Coding_500kbps = 2,
123   /** @deprecated Will be removed in a future version of RAIL. */
124   RAIL_BLE_Coding_500kbps_DSA = 3,
125 };
126 
127 #ifndef DOXYGEN_SHOULD_SKIP_THIS
128 // Self-referencing defines minimize compiler complaints when using RAIL_ENUM
129 #define RAIL_BLE_Coding_125kbps     ((RAIL_BLE_Coding_t) RAIL_BLE_Coding_125kbps)
130 #define RAIL_BLE_Coding_125kbps_DSA ((RAIL_BLE_Coding_t) RAIL_BLE_Coding_125kbps_DSA)
131 #define RAIL_BLE_Coding_500kbps     ((RAIL_BLE_Coding_t) RAIL_BLE_Coding_500kbps)
132 #define RAIL_BLE_Coding_500kbps_DSA ((RAIL_BLE_Coding_t) RAIL_BLE_Coding_500kbps_DSA)
133 #endif //DOXYGEN_SHOULD_SKIP_THIS
134 
135 /**
136  * @enum RAIL_BLE_Phy_t
137  * @brief The variant of the BLE PHY.
138  */
RAIL_ENUM(RAIL_BLE_Phy_t)139 RAIL_ENUM(RAIL_BLE_Phy_t) {
140   /** Use the standard BLE 1 Mbps PHY. */
141   RAIL_BLE_1Mbps = 0U,
142   /** Use the high data rate BLE 2 Mbps PHY. */
143   RAIL_BLE_2Mbps = 1U,
144   /** Enables the 125 kbps variant of the BLE Coded PHY. */
145   RAIL_BLE_Coded125kbps = 2U,
146   /** Enables the 500 kbps variant of the BLE Coded PHY. */
147   RAIL_BLE_Coded500kbps = 3U,
148   /** Use the BLE Simulscan PHY. */
149   RAIL_BLE_Simulscan = 4U,
150   /** Use the 1 Mbps variant of the BLE CS PHY. */
151   RAIL_BLE_CS1Mbps = 5U,
152   /** Use the 2 Mbps variant of the BLE CS PHY. */
153   RAIL_BLE_CS2Mbps = 6U,
154   /** Use the BLE 2 Mbps AOX PHY. */
155   RAIL_BLE_AOX2Mbps = 7U,
156   /** Use the BLE 1 Mbps Quuppa PHY. */
157   RAIL_BLE_Quuppa1Mbps = 8U,
158 };
159 
160 #ifndef DOXYGEN_SHOULD_SKIP_THIS
161 // Self-referencing defines minimize compiler complaints when using RAIL_ENUM
162 #define RAIL_BLE_1Mbps        ((RAIL_BLE_Phy_t) RAIL_BLE_1Mbps)
163 #define RAIL_BLE_2Mbps        ((RAIL_BLE_Phy_t) RAIL_BLE_2Mbps)
164 #define RAIL_BLE_Coded125kbps ((RAIL_BLE_Phy_t) RAIL_BLE_Coded125kbps)
165 #define RAIL_BLE_Coded500kbps ((RAIL_BLE_Phy_t) RAIL_BLE_Coded500kbps)
166 #define RAIL_BLE_Simulscan    ((RAIL_BLE_Phy_t) RAIL_BLE_Simulscan)
167 #define RAIL_BLE_CS1Mbps      ((RAIL_BLE_Phy_t) RAIL_BLE_CS1Mbps)
168 #define RAIL_BLE_CS2Mbps      ((RAIL_BLE_Phy_t) RAIL_BLE_CS2Mbps)
169 #define RAIL_BLE_AOX2Mbps     ((RAIL_BLE_Phy_t) RAIL_BLE_AOX2Mbps)
170 #define RAIL_BLE_Quuppa1Mbps  ((RAIL_BLE_Phy_t) RAIL_BLE_Quuppa1Mbps)
171 #endif //DOXYGEN_SHOULD_SKIP_THIS
172 
173 /// @addtogroup BLE_PHY BLE Radio Configurations
174 /// Radio configurations for the RAIL BLE Accelerator
175 ///
176 /// These radio configurations are used to configure BLE when a function such
177 /// as \ref RAIL_BLE_ConfigPhy1MbpsViterbi() is called. Each radio
178 /// configuration listed below is compiled into the RAIL library as a weak
179 /// symbol that will take into account per-die defaults. If the board
180 /// configuration in use has different settings than the default, such as a
181 /// different radio subsystem clock frequency, these radio configurations can
182 /// be overriden to account for those settings.
183 /// @{
184 
185 /**
186  * Default PHY to use for BLE 1 Mbps non-Viterbi. Will be NULL if
187  * \ref RAIL_BLE_SUPPORTS_1MBPS_NON_VITERBI is 0.
188  */
189 extern const RAIL_ChannelConfig_t *const RAIL_BLE_Phy1Mbps;
190 
191 /**
192  * Default PHY to use for BLE 2 Mbps non-Viterbi. Will be NULL if
193  * \ref RAIL_BLE_SUPPORTS_2MBPS_NON_VITERBI is 0.
194  */
195 extern const RAIL_ChannelConfig_t *const RAIL_BLE_Phy2Mbps;
196 
197 /**
198  * Default PHY to use for BLE 1 Mbps Viterbi. Will be NULL if
199  * \ref RAIL_BLE_SUPPORTS_1MBPS_VITERBI is 0.
200  */
201 extern const RAIL_ChannelConfig_t *const RAIL_BLE_Phy1MbpsViterbi;
202 
203 /**
204  * Default PHY to use for BLE 2 Mbps Viterbi. Will be NULL if
205  * \ref RAIL_BLE_SUPPORTS_2MBPS_VITERBI is 0.
206  */
207 extern const RAIL_ChannelConfig_t *const RAIL_BLE_Phy2MbpsViterbi;
208 
209 #ifndef DOXYGEN_SHOULD_SKIP_THIS
210 /**
211  * Default PHY to use for BLE 1M Viterbi CS. Will be NULL if
212  * \ref RAIL_BLE_SUPPORTS_CS is 0. On EFR32xG24, this will also
213  * be NULL for non 40MHz HFXO frequencies.
214  */
215 extern const RAIL_ChannelConfig_t *const RAIL_BLE_Phy1MbpsViterbiCs;
216 
217 /**
218  * Default PHY to use for BLE 2M Viterbi CS. Will be NULL if
219  * \ref RAIL_BLE_SUPPORTS_CS is 0. On EFR32xG24, this will also
220  * be NULL for non 40MHz HFXO frequencies.
221  */
222 extern const RAIL_ChannelConfig_t *const RAIL_BLE_Phy2MbpsViterbiCs;
223 #endif
224 
225 /**
226  * PHY to use for BLE 2 Mbps with AoX functionality. Will be NULL if either
227  * \ref RAIL_BLE_SUPPORTS_2MBPS_VITERBI or \ref RAIL_BLE_SUPPORTS_AOX is 0.
228  */
229 extern const RAIL_ChannelConfig_t *const RAIL_BLE_Phy2MbpsAox;
230 
231 /**
232  * Default PHY to use for BLE Coded 125 kbps. Will be NULL if
233  * \ref RAIL_BLE_SUPPORTS_CODED_PHY is 0. This PHY can receive on both
234  * 125 kbps and 500 kbps BLE Coded, but will only transmit at 125 kbps.
235  */
236 extern const RAIL_ChannelConfig_t *const RAIL_BLE_Phy125kbps;
237 
238 /**
239  * Default PHY to use for BLE Coded 500 kbps. Will be NULL if
240  * \ref RAIL_BLE_SUPPORTS_CODED_PHY is 0. This PHY can receive on both
241  * 125 kbps and 500 kbps BLE Coded, but will only transmit at 125 kbps.
242  */
243 extern const RAIL_ChannelConfig_t *const RAIL_BLE_Phy500kbps;
244 
245 /**
246  * Default PHY to use for BLE Simulscan. Will be NULL if
247  * \ref RAIL_BLE_SUPPORTS_SIMULSCAN_PHY is 0. This PHY can receive on 1 Mbps
248  * as well as 125 kbps and 500 kbps BLE Coded, but will only transmit at 1 Mbps.
249  */
250 extern const RAIL_ChannelConfig_t *const RAIL_BLE_PhySimulscan;
251 
252 /**
253  * Default 1 Mbps Quuppa PHY. Will be NULL if
254  * \ref RAIL_BLE_SUPPORTS_QUUPPA is 0.
255  */
256 extern const RAIL_ChannelConfig_t *const RAIL_BLE_PhyQuuppa;
257 
258 /// @} // End of group BLE_PHY
259 
260 /** \ref RAIL_RxPacketDetails_t::subPhyId indicating a 500 kbps packet. */
261 #define RAIL_BLE_RX_SUBPHY_ID_500K     (0U)
262 /** \ref RAIL_RxPacketDetails_t::subPhyId indicating a 125 kbps packet. */
263 #define RAIL_BLE_RX_SUBPHY_ID_125K     (1U)
264 /** \ref RAIL_RxPacketDetails_t::subPhyId value indicating a 1 Mbps packet. */
265 #define RAIL_BLE_RX_SUBPHY_ID_1M       (2U)
266 /** \ref RAIL_RxPacketDetails_t::subPhyId invalid value. */
267 #define RAIL_BLE_RX_SUBPHY_ID_INVALID  (3U)
268 /** The total count of BLE subPhyId's. Must be last. */
269 #define RAIL_BLE_RX_SUBPHY_COUNT       (4U)
270 
271 /**
272  * @enum RAIL_BLE_SignalIdentifierMode_t
273  * @brief Available Signal Identifier modes.
274  */
RAIL_ENUM(RAIL_BLE_SignalIdentifierMode_t)275 RAIL_ENUM(RAIL_BLE_SignalIdentifierMode_t) {
276   /** Disable signal detection mode. */
277   RAIL_BLE_SIGNAL_IDENTIFIER_MODE_DISABLE = 0,
278   /** BLE 1 Mbps (GFSK) detection mode. */
279   RAIL_BLE_SIGNAL_IDENTIFIER_MODE_1MBPS = 1,
280   /** BLE 2 Mbps (GFSK) detection mode. */
281   RAIL_BLE_SIGNAL_IDENTIFIER_MODE_2MBPS = 2,
282 };
283 
284 #ifndef DOXYGEN_SHOULD_SKIP_THIS
285 // Self-referencing defines minimize compiler complaints when using RAIL_ENUM
286 #define RAIL_BLE_SIGNAL_IDENTIFIER_MODE_DISABLE ((RAIL_BLE_SignalIdentifierMode_t) RAIL_BLE_SIGNAL_IDENTIFIER_MODE_DISABLE)
287 #define RAIL_BLE_SIGNAL_IDENTIFIER_MODE_1MBPS   ((RAIL_BLE_SignalIdentifierMode_t) RAIL_BLE_SIGNAL_IDENTIFIER_MODE_1MBPS)
288 #define RAIL_BLE_SIGNAL_IDENTIFIER_MODE_2MBPS   ((RAIL_BLE_SignalIdentifierMode_t) RAIL_BLE_SIGNAL_IDENTIFIER_MODE_2MBPS)
289 #endif
290 
291 /**
292  * @struct RAIL_BLE_State_t
293  * @brief A structure for BLE radio state parameters.
294  */
295 typedef struct RAIL_BLE_State {
296   /** The value used to initialize the CRC algorithm. */
297   uint32_t crcInit;
298   /**
299    * The access address used for the connection.
300    * It is transmitted or received least-significant bit first.
301    */
302   uint32_t accessAddress;
303   /** The logical channel used. */
304   uint16_t channel;
305   /** Indicates whether the whitening engine should be off (generally used for testing only). */
306   bool disableWhitening;
307   /** Reserved for future use; specify 0. */
308   uint16_t whiteInit;
309 } RAIL_BLE_State_t;
310 
311 /**
312  * Configure RAIL to run in BLE mode.
313  *
314  * @param[in] railHandle A handle for RAIL instance.
315  * @return Status code indicating success of the function call.
316  *
317  * This function changes your radio, channel configuration, and other
318  * parameters to match what is needed for BLE, initially establishing
319  * the BLE 1 Mbps PHY. To switch back to a
320  * default RAIL mode, call \ref RAIL_BLE_Deinit() first. This function
321  * will configure the protocol output on PTI to \ref RAIL_PTI_PROTOCOL_BLE.
322  *
323  * @note BLE may not be enabled while Auto-ACKing is enabled.
324  */
325 RAIL_Status_t RAIL_BLE_Init(RAIL_Handle_t railHandle);
326 
327 /**
328  * Take RAIL out of BLE mode.
329  *
330  * @param[in] railHandle A handle for RAIL instance.
331  * @return Status code indicating success of the function call.
332  *
333  * This function will undo some of the configuration that happens when you call
334  * \ref RAIL_BLE_Init(). After this you can safely run your normal radio
335  * initialization code to use a non-BLE configuration. This function does \b
336  * not change back your radio or channel configurations so you must do this by
337  * manually reinitializing. This also resets the protocol output on PTI to \ref
338  * RAIL_PTI_PROTOCOL_CUSTOM.
339  */
340 RAIL_Status_t RAIL_BLE_Deinit(RAIL_Handle_t railHandle);
341 
342 /**
343  * Determine whether BLE mode is enabled or not.
344  *
345  * @param[in] railHandle A handle for RAIL instance.
346  * @return true if BLE mode is enabled and false otherwise.
347  *
348  * This function returns the current status of RAIL's BLE mode. It is enabled by
349  * a call to \ref RAIL_BLE_Init() and disabled by a call to \ref RAIL_BLE_Deinit().
350  */
351 bool RAIL_BLE_IsEnabled(RAIL_Handle_t railHandle);
352 
353 /**
354  * Switch to the 1 Mbps Quuppa PHY.
355  *
356  * @param[in] railHandle A handle for RAIL instance.
357  * @return Status code indicating success of the function call.
358  *
359  * You can use this function to switch to the Quuppa PHY.
360  *
361  * @note Not all chips support the 1 Mbps Quuppa PHY. This API should return \ref RAIL_STATUS_INVALID_CALL if
362  *   unsupported by the hardware we're building for.
363  */
364 RAIL_Status_t RAIL_BLE_ConfigPhyQuuppa(RAIL_Handle_t railHandle);
365 
366 /**
367  * Switch to the Viterbi 1 Mbps BLE PHY.
368  *
369  * @param[in] railHandle A handle for RAIL instance.
370  * @return Status code indicating success of the function call.
371  *
372  * Use this function to switch back to the default BLE 1 Mbps PHY if you
373  * have switched to the 2 Mbps or another configuration. You may only call this
374  * function after initializing BLE and while the radio is idle.
375  */
376 RAIL_Status_t RAIL_BLE_ConfigPhy1MbpsViterbi(RAIL_Handle_t railHandle);
377 
378 /**
379  * Switch to the legacy non-Viterbi 1 Mbps BLE PHY.
380  *
381  * @param[in] railHandle A handle for RAIL instance.
382  * @return Status code indicating success of the function call.
383  *
384  * Use this function to switch back to the legacy BLE 1 Mbps PHY if you
385  * have switched to the 2 Mbps or another configuration. You may only call this
386  * function after initializing BLE and while the radio is idle.
387  *
388  * @deprecated BLE non-Viterbi PHYs are no longer supported.
389  */
390 RAIL_Status_t RAIL_BLE_ConfigPhy1Mbps(RAIL_Handle_t railHandle);
391 
392 /**
393  * Switch to the Viterbi 2 Mbps BLE PHY.
394  *
395  * @param[in] railHandle A handle for RAIL instance.
396  * @return Status code indicating success of the function call.
397  *
398  * Use this function to switch back to the BLE 2 Mbps PHY from the
399  * default 1 Mbps option. You may only call this function after initializing BLE
400  * and while the radio is idle.
401  */
402 RAIL_Status_t RAIL_BLE_ConfigPhy2MbpsViterbi(RAIL_Handle_t railHandle);
403 
404 /**
405  * Switch to the legacy non-Viterbi 2 Mbps BLE PHY.
406  *
407  * @param[in] railHandle A handle for RAIL instance.
408  * @return Status code indicating success of the function call.
409  *
410  * Use this function to switch back to legacy BLE 2 Mbps PHY from the
411  * default 1 Mbps option. You may only call this function after initializing BLE
412  * and while the radio is idle.
413  *
414  * @deprecated BLE non-Viterbi PHYs are no longer supported.
415  */
416 RAIL_Status_t RAIL_BLE_ConfigPhy2Mbps(RAIL_Handle_t railHandle);
417 
418 /**
419  * Switch to the BLE Coded PHY.
420  *
421  * @param[in] railHandle A handle for RAIL instance.
422  * @param[in] bleCoding The \ref RAIL_BLE_Coding_t to use
423  * @return Status code indicating success of the function call.
424  *
425  * Use this function to switch back to BLE Coded PHY from the default
426  * 1 Mbps option. You may only call this function after initializing BLE and
427  * while the radio is idle. When using a BLE Coded PHY, the \ref
428  * RAIL_RxPacketDetails_t::subPhyId marks the coding of the received packet.
429  * A subPhyId of 0 marks a 500 kbps packet, and a subPhyId of 1 marks a 125
430  * kbps packet.
431  */
432 RAIL_Status_t RAIL_BLE_ConfigPhyCoded(RAIL_Handle_t railHandle,
433                                       RAIL_BLE_Coding_t bleCoding);
434 
435 /**
436  * Switch to the Simulscan PHY.
437  *
438  * @param[in] railHandle A handle for RAIL instance.
439  * @return Status code indicating success of the function call.
440  *
441  * Use this function to switch to the BLE Simulscan PHY. You may only
442  * call this function after initializing BLE and while the radio is idle.
443  * When using Simulscan PHY, the \ref RAIL_RxPacketDetails_t::subPhyId
444  * marks the coding of the received packet. A subPhyId of 0 marks a
445  * 500 kbps packet, a subPhyId of 1 marks a 125 kbps packet, and a
446  * subPhyId of 2 marks a 1 Mbps packet.
447  *
448  * @note: The Simulscan PHY is supported only on some parts.
449  *   The preprocessor symbol \ref RAIL_BLE_SUPPORTS_SIMULSCAN_PHY and the
450  *   runtime function \ref RAIL_BLE_SupportsSimulscanPhy() may be used to
451  *   test for support of the Simulscan PHY.
452  */
453 RAIL_Status_t RAIL_BLE_ConfigPhySimulscan(RAIL_Handle_t railHandle);
454 
455 #ifndef DOXYGEN_SHOULD_SKIP_THIS
456 /**
457  * Switch to the 1 Mbps BLE PHY for CS.
458  *
459  * @param[in] railHandle A handle for RAIL instance.
460  * @return Status code indicating success of the function call.
461  *
462  * Use this function to switch back to the BLE 1 Mbps CS PHY from
463  * another configuration. You may only call this
464  * function after initializing BLE and while the radio is idle.
465  *
466  * @note This PHY is only supported when \ref RAIL_BLE_SUPPORTS_CS is not 0.
467  */
468 RAIL_Status_t RAIL_BLE_ConfigPhy1MbpsCs(RAIL_Handle_t railHandle);
469 
470 /**
471  * Switch to the 2 Mbps BLE PHY for CS.
472  *
473  * @param[in] railHandle A handle for RAIL instance.
474  * @return Status code indicating success of the function call.
475  *
476  * Use this function to switch back to the BLE 2 Mbps CS PHY from
477  * another configuration. You may only call this
478  * function after initializing BLE and while the radio is idle.
479  *
480  * @note This PHY is only supported when \ref RAIL_BLE_SUPPORTS_CS is not 0.
481  */
482 RAIL_Status_t RAIL_BLE_ConfigPhy2MbpsCs(RAIL_Handle_t railHandle);
483 #endif //DOXYGEN_SHOULD_SKIP_THIS
484 
485 /**
486  * Change BLE radio parameters.
487  *
488  * @param[in] railHandle A handle for RAIL instance.
489  * @param[in] crcInit The value to use for CRC initialization.
490  * @param[in] accessAddress The access address to use for the connection. The
491  *   bits of this parameter are transmitted or received LSB first.
492  * @param[in] channel The logical channel that you're changing to, which
493  *   initializes the whitener if used.
494  * @param[in] disableWhitening This can turn off the whitening engine and is useful
495  *   for sending BLE test mode packets that don't have this turned on.
496  * @return Status code indicating success of the function call.
497  *
498  * This function can be used to switch radio parameters on every connection
499  * and/or channel change. It is BLE-aware and will set the access address,
500  * preamble, CRC initialization value, and whitening configuration without
501  * requiring you to load a new radio configuration. This function should be
502  * called after switching to a particular BLE phy (1 Mbps, 2 Mbps, etc.) and
503  * not while the radio is active.
504  */
505 RAIL_Status_t RAIL_BLE_ConfigChannelRadioParams(RAIL_Handle_t railHandle,
506                                                 uint32_t crcInit,
507                                                 uint32_t accessAddress,
508                                                 uint16_t channel,
509                                                 bool disableWhitening);
510 
511 /**
512  * Change the current BLE PHY and go into receive.
513  *
514  * @param[in] railHandle A handle for RAIL instance.
515  * @param[in] phy Indicates which PHY to receive on.
516  * @param[in] railChannel Which channel of the given PHY to receive on.
517  * @param[in] startRxTime Absolute near-future RAIL time to enter RX.
518  * @param[in] crcInit The value to use for CRC initialization.
519  * @param[in] accessAddress The access address to use for the connection. The
520  *   bits of this parameter are transmitted or received LSB first.
521  * @param[in] logicalChannel The logical channel that you're changing to, which
522  *   initializes the whitener if used.
523  * @param[in] disableWhitening This can turn off the whitening engine and is useful
524  *   for sending BLE test mode packets that don't have this turned on.
525  * @return Status code indicating success of the function call.
526  *
527  * This function is used to implement auxiliary packet reception, as defined in
528  * the BLE specification. The radio will be put into IDLE, the PHY and channel
529  * will be changed, and then receive will be entered at the start time given.
530  * The new receive will have a timeout of 30 us, which means that this function
531  * should only be called if the offset unit is 30 us.
532  *
533  * This function is extremely time-sensitive, and may only be called within the
534  * interrupt context of a \ref RAIL_EVENT_RX_PACKET_RECEIVED event.
535  */
536 RAIL_Status_t RAIL_BLE_PhySwitchToRx(RAIL_Handle_t railHandle,
537                                      RAIL_BLE_Phy_t phy,
538                                      uint16_t railChannel,
539                                      RAIL_Time_t startRxTime,
540                                      uint32_t crcInit,
541                                      uint32_t accessAddress,
542                                      uint16_t logicalChannel,
543                                      bool disableWhitening);
544 
545 /**
546  * Configure and enable signal identifier for BLE signal detection.
547  *
548  * @param[in] railHandle A RAIL instance handle.
549  * @param[in] signalIdentifierMode Mode of signal identifier operation.
550  * @return Status code indicating success of the function call.
551  *
552  * This features allows detection of BLE signal on air based on the mode.
553  * This function must be called once before \ref RAIL_BLE_EnableSignalDetection
554  * to configure and enable signal identifier.
555  *
556  * To enable event for signal detection \ref RAIL_ConfigEvents() must be called
557  * for enabling \ref RAIL_EVENT_SIGNAL_DETECTED.
558  *
559  * This function is only supported by chips where
560  * \ref RAIL_BLE_SUPPORTS_SIGNAL_IDENTIFIER and
561  * \ref RAIL_BLE_SupportsSignalIdentifier() are true.
562  */
563 RAIL_Status_t RAIL_BLE_ConfigSignalIdentifier(RAIL_Handle_t railHandle,
564                                               RAIL_BLE_SignalIdentifierMode_t signalIdentifierMode);
565 
566 /**
567  * Enable or disable signal identifier interrupt for BLE signal detection.
568  *
569  * @param[in] railHandle A RAIL instance handle.
570  * @param[in] enable Signal detection is enabled if true, disabled if false.
571  * @return Status code indicating success of the function call.
572  *
573  * \ref RAIL_BLE_ConfigSignalIdentifier() must be called once before calling this
574  * function to configure and enable signal identifier.
575  * Once a signal is detected signal detection will be turned off and this
576  * function should be called to re-enable the signal detection without needing
577  * to call \ref RAIL_BLE_ConfigSignalIdentifier() if the signal identifier
578  * is already configured and enabled.
579  *
580  * This function is only supported by chips where
581  * \ref RAIL_BLE_SUPPORTS_SIGNAL_IDENTIFIER and
582  * \ref RAIL_BLE_SupportsSignalIdentifier() are true.
583  */
584 RAIL_Status_t RAIL_BLE_EnableSignalDetection(RAIL_Handle_t railHandle,
585                                              bool enable);
586 
587 /**
588  * @brief Backward compatible name for the \ref
589  *   RAIL_BLE_EnableSignalDetection API.
590  */
591 #define RAIL_BLE_EnableSignalIdentifier RAIL_BLE_EnableSignalDetection
592 
593 /******************************************************************************
594  * Angle of Arrival/Departure (AoX)
595  *****************************************************************************/
596 /**
597  * @addtogroup AoX Angle of Arrival/Departure
598  * @{
599  * @brief These APIs are to a stack implementing BLE's angle of arrival and
600  *   angle of departure functionality.
601  *
602  * They are designed for use by the Silicon Labs BLE stack only at this time and
603  * may cause problems if accessed directly.
604  */
605 
606 /**
607  * The maximum number of GPIO pins used for AoX Antenna switching.
608  *
609  * If the user configures more pins using
610  * \ref RAIL_BLE_ConfigAoxAntenna() than allowed
611  * \ref RAIL_BLE_AOX_ANTENNA_PIN_COUNT, then
612  * \ref RAIL_STATUS_INVALID_PARAMETER status will be returned.
613  *
614  * \ref RAIL_STATUS_INVALID_CALL is returned if :
615  * \ref RAIL_BLE_AOX_ANTENNA_PIN_COUNT is set to 0 or
616  * the user configures no pins.
617  *
618  * The maximum value \ref RAIL_BLE_AOX_ANTENNA_PIN_COUNT can take depends on
619  * number of Antenna route pins , a chip provides.
620  * For EFR32xG22, the maximum value of \ref RAIL_BLE_AOX_ANTENNA_PIN_COUNT is 6.
621  * If the user configures fewer pins than \ref RAIL_BLE_AOX_ANTENNA_PIN_COUNT,
622  * then only number of pins asked by user will be configured with
623  * \ref RAIL_STATUS_NO_ERROR.
624  */
625 #define RAIL_BLE_AOX_ANTENNA_PIN_COUNT (6U)
626 
627 /**
628  * @enum RAIL_BLE_AoxOptions_t
629  * @brief Angle of Arrival/Departure options bit fields
630  */
RAIL_ENUM_GENERIC(RAIL_BLE_AoxOptions_t,uint16_t)631 RAIL_ENUM_GENERIC(RAIL_BLE_AoxOptions_t, uint16_t) {
632   /** Shift position of \ref RAIL_BLE_AOX_OPTIONS_SAMPLE_MODE bit. */
633   RAIL_BLE_AOX_OPTIONS_SAMPLE_MODE_SHIFT = 0,
634   /** Shift position of \ref RAIL_BLE_AOX_OPTIONS_CONNLESS bit. */
635   RAIL_BLE_AOX_OPTIONS_CONNLESS_SHIFT = 1,
636   /** Shift position of \ref RAIL_BLE_AOX_OPTIONS_CONN bit. */
637   RAIL_BLE_AOX_OPTIONS_CONN_SHIFT = 2,
638   /** Shift position of \ref RAIL_BLE_AOX_OPTIONS_DISABLE_BUFFER_LOCK bit. */
639   RAIL_BLE_AOX_OPTIONS_DISABLE_BUFFER_LOCK_SHIFT = 3,
640 };
641 
642 /**
643  * @deprecated Obsolete AOX option
644  */
645 #define RAIL_BLE_AOX_OPTIONS_DO_SWITCH           (0U)
646 /**
647  * @deprecated Obsolete AOX option
648  */
649 #define RAIL_BLE_AOX_OPTIONS_TX_ENABLED          (0U)
650 /**
651  * @deprecated Obsolete AOX option
652  */
653 #define RAIL_BLE_AOX_OPTIONS_RX_ENABLED          (0U)
654 /**
655  * @deprecated Please use \ref RAIL_BLE_AOX_OPTIONS_DISABLE_BUFFER_LOCK_SHIFT instead.
656  */
657 #define RAIL_BLE_AOX_OPTIONS_LOCK_CTE_BUFFER_SHIFT RAIL_BLE_AOX_OPTIONS_DISABLE_BUFFER_LOCK_SHIFT
658 
659 /**
660  * Disable the AoX feature.
661  */
662 #define RAIL_BLE_AOX_OPTIONS_DISABLED            (0U)
663 /**
664  * Sets one of the two AoX sampling/switching modes: 1 us or 2 us window.
665  */
666 #define RAIL_BLE_AOX_OPTIONS_SAMPLE_MODE         (1U << RAIL_BLE_AOX_OPTIONS_SAMPLE_MODE_SHIFT)
667 /**
668  * Enables connectionless AoX Rx packets.
669  */
670 #define RAIL_BLE_AOX_OPTIONS_CONNLESS            (1U << RAIL_BLE_AOX_OPTIONS_CONNLESS_SHIFT)
671 /**
672  * Enables connection based AoX Rx packets.
673  */
674 #define RAIL_BLE_AOX_OPTIONS_CONN                (1U << RAIL_BLE_AOX_OPTIONS_CONN_SHIFT)
675 /**
676  * Disables CTE buffer lock.
677  */
678 #define RAIL_BLE_AOX_OPTIONS_DISABLE_BUFFER_LOCK (1U << RAIL_BLE_AOX_OPTIONS_DISABLE_BUFFER_LOCK_SHIFT)
679 /**
680  * Enables connection based or connectionless AoX Rx packets.
681  */
682 #define RAIL_BLE_AOX_OPTIONS_ENABLED             (RAIL_BLE_AOX_OPTIONS_CONN | RAIL_BLE_AOX_OPTIONS_CONNLESS)
683 
684 /**
685  * @struct RAIL_BLE_AoxConfig_t
686  * @brief Contains arguments for \ref RAIL_BLE_ConfigAox() function.
687  */
688 typedef struct RAIL_BLE_AoxConfig {
689   /** AoX options. */
690   RAIL_BLE_AoxOptions_t aoxOptions;
691   /**
692    * Size of the raw AoX CTE (continuous tone extension) data capture buffer in
693    * bytes. Note this value should be a multiple of 4 as each IQ sample
694    * requires 4 bytes.
695    */
696   uint16_t cteBuffSize;
697   /**
698    * Address to where the received CTE is written. Buffer must be 32-bit
699    * aligned.
700    */
701   uint32_t * cteBuffAddr;
702   /**
703    * Address to first element of antenna pattern array. Array must be in RAM.
704    * Each element of the array contains an antenna number. The switching pattern
705    * is defined by the order of antennas in this array.
706    */
707   uint8_t * antArrayAddr;
708   /**
709    * Number of entries in the antenna pattern array.
710    */
711   uint8_t antArraySize;
712 } RAIL_BLE_AoxConfig_t;
713 
714 /**
715  * @struct RAIL_BLE_AoxAntennaPortPins_t
716  * @brief Contains elements of \ref RAIL_BLE_AoxAntennaConfig_t struct.
717  */
718 typedef struct RAIL_BLE_AoxAntennaPortPins {
719   /** The port which is used for AoX antenna switching. */
720   uint8_t antPort;
721   /** The pin which is used for AoX antenna switching. */
722   uint8_t antPin;
723 } RAIL_BLE_AoxAntennaPortPins_t;
724 
725 /**
726  * @struct RAIL_BLE_AoxAntennaConfig_t
727  * @brief Contains arguments for \ref RAIL_BLE_ConfigAoxAntenna() function.
728  */
729 typedef struct RAIL_BLE_AoxAntennaConfig {
730   /**
731    * A pointer to an array containing struct of port and pin used for
732    * AoX antenna switching.
733    */
734   RAIL_BLE_AoxAntennaPortPins_t *antPortPin;
735   /**
736    * Number of antenna pins to be configured.
737    */
738   uint8_t antCount;
739 } RAIL_BLE_AoxAntennaConfig_t;
740 
741 /**
742  * Lock/unlock the CTE buffer from the application's perspective. The radio
743  * will write to the buffer only if the bit is NOT set at the beginning of the
744  * sampling period. The radio will set the bit once the sampling period starts
745  * to indicate that some CTE data has been collected, which will not be
746  * overwritten during the next sampling period, unless the buffer is unlocked by
747  * the application.
748  *
749  * @param[in] railHandle A RAIL instance handle.
750  * @param[in] lock Lock the CTE buffer if true and unlock it if false.
751  * @return true if the CTE buffer is locked after the call, otherwise false.
752  */
753 bool RAIL_BLE_LockCteBuffer(RAIL_Handle_t railHandle, bool lock);
754 
755 /**
756  * Determine whether the CTE buffer is currently locked or not.
757  *
758  * @param[in] railHandle A handle for RAIL instance.
759  * @return true if CTE buffer is locked and false otherwise.
760  */
761 bool RAIL_BLE_CteBufferIsLocked(RAIL_Handle_t railHandle);
762 
763 /**
764  * Get the offset into CTE sample of CTE data.
765  *
766  * @param[in] railHandle A handle for RAIL instance.
767  * @return The offset of CTE data in a CTE sample in bytes.
768  *   On unsupported platforms this returns 0.
769  */
770 uint8_t RAIL_BLE_GetCteSampleOffset(RAIL_Handle_t railHandle);
771 
772 /**
773  * Get the effective sample rate used by the ADC to capture the CTE samples.
774  *
775  * @param[in] railHandle A handle for RAIL instance.
776  * @return The actual sample rate used to capture the CTE in samples per second.
777  *   On unsupported platforms this returns 0.
778  */
779 uint32_t RAIL_BLE_GetCteSampleRate(RAIL_Handle_t railHandle);
780 
781 /**
782  * Configure Angle of Arrival/Departure (AoX) functionality.
783  *
784  * @param[in] railHandle A RAIL instance handle.
785  * @param[in] aoxConfig Configuration options for AoX
786  * @return Status code indicating success of the function call.
787  *
788  * AoX is a method
789  * of radio localization which infers angle of arrival/departure of the signal
790  * based on different phases of the raw I/Q signal from different antennas by
791  * controlling external RF switch during the continuous tone extension (CTE).
792  * Connection based AoX packets are different than normal BLE packets in that
793  * they have 3 header bytes instead of 2 and they have CTE appended after the
794  * payload's CRC. 3rd byte or CTE info contains CTE length. Connectionless AoX
795  * packets have 2 header bytes and CTE info is part of the payload.
796  *
797  * @note Calling \ref RAIL_GetRadioEntropy() during AoX reception may break
798  *   packet reception.
799  */
800 RAIL_Status_t RAIL_BLE_ConfigAox(RAIL_Handle_t railHandle,
801                                  const RAIL_BLE_AoxConfig_t *aoxConfig);
802 
803 /**
804  * Perform one time initialization of AoX registers.
805  * This function must be called before \ref RAIL_BLE_ConfigAox()
806  * and before configuring the BLE PHY.
807  *
808  * @param[in] railHandle A RAIL instance handle.
809  * @return Status code indicating success of the function call.
810  */
811 RAIL_Status_t RAIL_BLE_InitCte(RAIL_Handle_t railHandle);
812 
813 /**
814  * Perform initialization of AoX antenna GPIO pins.
815  * This function must be called before calls to \ref RAIL_BLE_InitCte()
816  * and \ref RAIL_BLE_ConfigAox(), and before configuring the BLE PHY,
817  * else a \ref RAIL_STATUS_INVALID_CALL is returned.
818  *
819  * If user configures more pins in \ref RAIL_BLE_AoxAntennaConfig_t::antCount
820  * than allowed by \ref RAIL_BLE_AOX_ANTENNA_PIN_COUNT, then the API returns
821  * \ref RAIL_STATUS_INVALID_PARAMETER.
822  *
823  * If user configures lesser than or equal to number of pins allowed by
824  * \ref RAIL_BLE_AOX_ANTENNA_PIN_COUNT, then the requested number of pins
825  * are configured and \ref RAIL_STATUS_NO_ERROR is returned.
826  *
827  * If AoX antenna switching is inactive, non-AoX transmits and receives
828  * will occur on the first antenna specified by the antenna pattern or
829  * on the default antenna if no antenna pattern is provided.
830  *
831  * @param[in] railHandle A RAIL instance handle.
832  * @param[in] antennaConfig A pointer to the antenna configuration
833  *   structure to hold the set of GPIO ports and pins for AoX antenna
834  *   switching.
835  * @return Status code indicating success of the function call.
836  */
837 RAIL_Status_t RAIL_BLE_ConfigAoxAntenna(RAIL_Handle_t railHandle,
838                                         RAIL_BLE_AoxAntennaConfig_t *antennaConfig);
839 
840 /** @} */  // end of group AoX
841 
842 #ifndef DOXYGEN_SHOULD_SKIP_THIS
843 /******************************************************************************
844  * Channel Sounding (CS)
845  *****************************************************************************/
846 /**
847  * @addtogroup CS Channel Sounding
848  * @{
849  * @brief These APIs are to a stack implementing BLE's channel sounding
850  *   functionality.
851  *
852  * They are designed for use by the Silicon Labs BLE stack only at this time and
853  * may cause problems if accessed directly.
854  */
855 
856 /** Total number of CS Channels. */
857 #define RAIL_BLE_CS_NUM_CHANNELS 79
858 
859 /** Total number of allowed CS Channels. */
860 #define RAIL_BLE_CS_NUM_ALLOWED_CHANNELS 72
861 
862 /**
863  * @enum RAIL_BLE_CsRole_t
864  * @brief The device role during CS events.
865  */
RAIL_ENUM(RAIL_BLE_CsRole_t)866 RAIL_ENUM(RAIL_BLE_CsRole_t) {
867   /** Device cannot perform CS events. */
868   RAIL_BLE_CS_ROLE_UNASSIGNED = 0,
869   /** Device is an initiator during CS events. */
870   RAIL_BLE_CS_ROLE_INITIATOR = 1,
871   /** Device is a reflector during CS events. */
872   RAIL_BLE_CS_ROLE_REFLECTOR = 2,
873 };
874 
875 #ifndef DOXYGEN_SHOULD_SKIP_THIS
876 // Self-referencing defines minimize compiler complaints when using RAIL_ENUM
877 #define RAIL_BLE_CS_ROLE_UNASSIGNED ((RAIL_BLE_CsRole_t) RAIL_BLE_CS_ROLE_UNASSIGNED)
878 #define RAIL_BLE_CS_ROLE_INITIATOR  ((RAIL_BLE_CsRole_t) RAIL_BLE_CS_ROLE_INITIATOR)
879 #define RAIL_BLE_CS_ROLE_REFLECTOR  ((RAIL_BLE_CsRole_t) RAIL_BLE_CS_ROLE_REFLECTOR)
880 #endif//DOXYGEN_SHOULD_SKIP_THIS
881 
882 /**
883  * @struct RAIL_BLE_CsResults_t
884  * @brief Contains measurement results from CS step.
885  */
886 typedef struct {
887   /** CS measurement data for a particular step. */
888   uint32_t result[7];
889 } RAIL_BLE_CsResults_t;
890 
891 /**
892  * @enum RAIL_BLE_CsRttType_t
893  * @brief CS RTT Types.
894  */
RAIL_ENUM(RAIL_BLE_CsRttType_t)895 RAIL_ENUM(RAIL_BLE_CsRttType_t) {
896   /** Coarse cost function engine method RTT. */
897   RAIL_BLE_CS_RTT_AA_ONLY = 0U,
898   /** 32 bit sounding sequence method RTT. */
899   RAIL_BLE_CS_RTT_32B_SS = 1U,
900   /** 96 bit sounding sequence method RTT. */
901   RAIL_BLE_CS_RTT_96B_SS = 2U,
902 };
903 
904 #ifndef DOXYGEN_SHOULD_SKIP_THIS
905 // Self-referencing defines minimize compiler complaints when using RAIL_ENUM
906 #define RAIL_BLE_CS_RTT_AA_ONLY ((RAIL_BLE_CsRttType_t) RAIL_BLE_CS_RTT_AA_ONLY)
907 #define RAIL_BLE_CS_RTT_32B_SS  ((RAIL_BLE_CsRttType_t) RAIL_BLE_CS_RTT_32B_SS)
908 #define RAIL_BLE_CS_RTT_96B_SS  ((RAIL_BLE_CsRttType_t) RAIL_BLE_CS_RTT_96B_SS)
909 #endif//DOXYGEN_SHOULD_SKIP_THIS
910 
911 /**
912  *  The minimum size in 32 bit words for the IQ buffer. This value guarantees
913  *  all IQ samples for a single 1 Mbps CS step can be stored.
914  */
915 #define RAIL_BLE_CS_1MBPS_MINIMUM_IQ_BUFFER_SIZE  1500U
916 
917 /**
918  * @struct RAIL_BLE_CsConfig_t
919  * @brief Contains arguments for \ref RAIL_BLE_ConfigCs function.
920  */
921 typedef struct RAIL_BLE_CsConfig {
922   /** The device role during CS event. */
923   RAIL_BLE_CsRole_t role;
924   /**
925    * Number of mode 2 phase measurement slots, including the
926    * tone extension slot. This value should be between
927    * \ref RAIL_BLE_CS_MIN_ANTENNA_SLOTS and
928    * \ref RAIL_BLE_CS_MAX_ANTENNA_SLOTS, inclusive.
929    * A provided value below or above this range will be pegged
930    * to the appropriate minimum or maximum value.
931    */
932   uint8_t slotCount;
933   /** Number of steps in CS event. */
934   uint16_t csSqteSteps;
935   /** Pointer to CS measurements. Set to NULL if unused. */
936   RAIL_BLE_CsResults_t *pCsDataOutput;
937   /** Frequency change spacing (in us). */
938   uint16_t t_fcs;
939   /** Interlude period for mode 0 & 1 steps (in us). */
940   uint16_t t_ip1;
941   /** Interlude period for mode 2 steps (in us). */
942   uint16_t t_ip2;
943   /** Phase measurement time (in us). */
944   uint16_t t_pm;
945   /**< Antenna switching time (in us). */
946   uint16_t t_sw;
947   /**
948    * Pointer to buffer where IQ data will be written. Buffer must be 32-bit
949    * aligned.
950    */
951   uint32_t *pIqBuffer;
952   /**
953    * Size of IQ buffer in 32 bit words. Must be at least \ref
954    * RAIL_BLE_CS_1MBPS_MINIMUM_IQ_BUFFER_SIZE or else an error will be
955    * returned by \ref RAIL_BLE_ConfigCs().
956    */
957   uint16_t iqBufferSize;
958   /**
959    * Step Index to perform the event calibration. This index must correspond
960    * to a mode 0 step or else the event calibration won't occur.
961    */
962   uint8_t eventCalStepIndex;
963   /** RTT type returned during mode 1 step. */
964   RAIL_BLE_CsRttType_t rttType;
965   /**
966    * A pointer to the selected CS event gain index. This field will be
967    * populated after \ref eventCalStepIndex has been reached.
968    */
969   uint8_t *pEventGainIndex;
970   /**
971    * A pointer to the selected CS event Fractional Frequency Offset
972    * (FFO) * pp100m (parts-per-100-million). This field will be populated
973    * after \ref eventCalStepIndex has been reached.
974    */
975   int16_t *pEventFfoPp100m;
976   /** Debug flag to disable RTT GD compensation. */
977   bool disableRttGdComp;
978   /** Debug flag to disable PBR DC compensation. */
979   bool disablePbrDcComp;
980   /** Debug flag to disable PBR GD compensation. */
981   bool disablePbrGdComp;
982   /** Debug flag to force event gain for calibration. */
983   bool forceAgcGain;
984   /**
985    * Pointer to an FAE table of size \ref RAIL_BLE_CS_NUM_ALLOWED_CHANNELS
986    * that holds the FAE value for each allowed CS channel in units of
987    * parts-per-32-million (pp32m). In units of parts-per-million (ppm),
988    * the FAE ranges from [-4, +3.96875] ppm with a resolution of 0.03125 ppm.
989    * Set to NULL if unused.
990    */
991   int8_t(*pFaeTable)[RAIL_BLE_CS_NUM_ALLOWED_CHANNELS];
992   /** Equivalent AGC STATUS0 register to force. */
993   uint32_t forcedAgcStatus0;
994 } RAIL_BLE_CsConfig_t;
995 
996 /** The maximum number of CS steps allowed during a CS event. */
997 #define RAIL_BLE_CS_MAX_SQTE_STEPS 512U
998 
999 /**
1000  * @enum RAIL_BLE_CsStepState_t
1001  * @brief The current CS step state.
1002  */
RAIL_ENUM(RAIL_BLE_CsStepState_t)1003 RAIL_ENUM(RAIL_BLE_CsStepState_t) {
1004   /** CS step state idle. */
1005   RAIL_BLE_CS_STATE_IDLE = 0,
1006   /** CS step state initiator initiator transmit mode 0. */
1007   RAIL_BLE_CS_STATE_I_TX_MODE0 = 1,
1008   /** CS step state initiator reflector transmit mode 0. */
1009   RAIL_BLE_CS_STATE_R_TX_MODE0 = 2,
1010   /** CS step state initiator initiator transmit mode 1. */
1011   RAIL_BLE_CS_STATE_I_TX_MODE1 = 3,
1012   /** CS step state initiator reflector transmit mode 1. */
1013   RAIL_BLE_CS_STATE_R_TX_MODE1 = 4,
1014   /** CS step state initiator initiator transmit mode 2. */
1015   RAIL_BLE_CS_STATE_R_TX_MODE2 = 6,
1016   /** CS step state initiator reflector transmit mode 2. */
1017   RAIL_BLE_CS_STATE_I_TX_MODE2 = 7,
1018 };
1019 
1020 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1021 // Self-referencing defines minimize compiler complaints when using RAIL_ENUM
1022 #define RAIL_BLE_CS_STATE_IDLE       ((RAIL_BLE_CsStepState_t) RAIL_BLE_CS_STATE_IDLE)
1023 #define RAIL_BLE_CS_STATE_I_TX_MODE0 ((RAIL_BLE_CsStepState_t) RAIL_BLE_CS_STATE_I_TX_MODE0)
1024 #define RAIL_BLE_CS_STATE_R_TX_MODE0 ((RAIL_BLE_CsStepState_t) RAIL_BLE_CS_STATE_R_TX_MODE0)
1025 #define RAIL_BLE_CS_STATE_I_TX_MODE1 ((RAIL_BLE_CsStepState_t) RAIL_BLE_CS_STATE_I_TX_MODE1)
1026 #define RAIL_BLE_CS_STATE_R_TX_MODE1 ((RAIL_BLE_CsStepState_t) RAIL_BLE_CS_STATE_R_TX_MODE1)
1027 #define RAIL_BLE_CS_STATE_R_TX_MODE2 ((RAIL_BLE_CsStepState_t) RAIL_BLE_CS_STATE_R_TX_MODE2)
1028 #define RAIL_BLE_CS_STATE_I_TX_MODE2 ((RAIL_BLE_CsStepState_t) RAIL_BLE_CS_STATE_I_TX_MODE2)
1029 #endif//DOXYGEN_SHOULD_SKIP_THIS
1030 
1031 /**
1032  * First step state for CS mode 0.
1033  */
1034 #define RAIL_BLE_CS_STEP_MODE0             RAIL_BLE_CS_STATE_I_TX_MODE0
1035 
1036 /**
1037  * First step state for CS mode 1.
1038  */
1039 #define RAIL_BLE_CS_STEP_MODE1             RAIL_BLE_CS_STATE_I_TX_MODE1
1040 
1041 /**
1042  * First step state for CS mode 2.
1043  */
1044 #define RAIL_BLE_CS_STEP_MODE2             RAIL_BLE_CS_STATE_I_TX_MODE2
1045 
1046 /**
1047  * @enum RAIL_BLE_CsStepMode_t
1048  * @brief The CS step mode.
1049  */
RAIL_ENUM(RAIL_BLE_CsStepMode_t)1050 RAIL_ENUM(RAIL_BLE_CsStepMode_t) {
1051   /** CS step mode 0. */
1052   RAIL_BLE_CS_MODE_0 = 0,
1053   /** CS step mode 1. */
1054   RAIL_BLE_CS_MODE_1 = 1,
1055   /** CS step mode 2. */
1056   RAIL_BLE_CS_MODE_2 = 2,
1057   /** CS step mode 3. */
1058   RAIL_BLE_CS_MODE_3 = 3,
1059 };
1060 
1061 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1062 // Self-referencing defines minimize compiler complaints when using RAIL_ENUM
1063 #define RAIL_BLE_CS_MODE_0 ((RAIL_BLE_CsStepMode_t) RAIL_BLE_CS_MODE_0)
1064 #define RAIL_BLE_CS_MODE_1 ((RAIL_BLE_CsStepMode_t) RAIL_BLE_CS_MODE_1)
1065 #define RAIL_BLE_CS_MODE_2 ((RAIL_BLE_CsStepMode_t) RAIL_BLE_CS_MODE_2)
1066 #define RAIL_BLE_CS_MODE_3 ((RAIL_BLE_CsStepMode_t) RAIL_BLE_CS_MODE_3)
1067 #endif//DOXYGEN_SHOULD_SKIP_THIS
1068 
1069 /** The maximum number of antennas supported. */
1070 #define RAIL_BLE_CS_MAX_ANTENNAS 4U
1071 
1072 /**
1073  * @enum RAIL_BLE_CsAntennaId_t
1074  * @brief The CS antenna ID. Valid values according to the CS spec are within
1075  *   the range 1 and 4 inclusive.
1076  */
RAIL_ENUM(RAIL_BLE_CsAntennaId_t)1077 RAIL_ENUM(RAIL_BLE_CsAntennaId_t) {
1078   /** Antenna ID of the first supported antenna. */
1079   RAIL_BLE_CS_ANTENNA_ID_1 = 1U,
1080   /** Antenna ID of the second supported antenna. */
1081   RAIL_BLE_CS_ANTENNA_ID_2 = 2U,
1082   /** Antenna ID of the third supported antenna. */
1083   RAIL_BLE_CS_ANTENNA_ID_3 = 3U,
1084   /** Antenna ID of the fourth supported antenna. */
1085   RAIL_BLE_CS_ANTENNA_ID_4 = 4U,
1086 };
1087 
1088 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1089 // Self-referencing defines minimize compiler complaints when using RAIL_ENUM
1090 #define RAIL_BLE_CS_ANTENNA_ID_1 ((RAIL_BLE_CsAntennaId_t) RAIL_BLE_CS_ANTENNA_ID_1)
1091 #define RAIL_BLE_CS_ANTENNA_ID_2 ((RAIL_BLE_CsAntennaId_t) RAIL_BLE_CS_ANTENNA_ID_2)
1092 #define RAIL_BLE_CS_ANTENNA_ID_3 ((RAIL_BLE_CsAntennaId_t) RAIL_BLE_CS_ANTENNA_ID_3)
1093 #define RAIL_BLE_CS_ANTENNA_ID_4 ((RAIL_BLE_CsAntennaId_t) RAIL_BLE_CS_ANTENNA_ID_4)
1094 #endif//DOXYGEN_SHOULD_SKIP_THIS
1095 
1096 /** The value returned by RAIL for an invalid CS antenna count. */
1097 #define RAIL_BLE_CS_INVALID_ANTENNA_COUNT 0U
1098 
1099 /**
1100  * @enum RAIL_BLE_CsRttPacketQuality_t
1101  * @brief CS RTT packet quality.
1102  */
RAIL_ENUM(RAIL_BLE_CsRttPacketQuality_t)1103 RAIL_ENUM(RAIL_BLE_CsRttPacketQuality_t) {
1104   /** Access address check succeeded. */
1105   RAIL_BLE_CS_RTT_AA_SUCCESS = 0U,
1106   /** Access address had one or more bit errors. */
1107   RAIL_BLE_CS_RTT_AA_BIT_ERRORS = 1U,
1108   /** Access address not found. */
1109   RAIL_BLE_CS_RTT_AA_NOT_FOUND = 2U,
1110 };
1111 
1112 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1113 // Self-referencing defines minimize compiler complaints when using RAIL_ENUM
1114 #define RAIL_BLE_CS_RTT_AA_SUCCESS    ((RAIL_BLE_CsRttPacketQuality_t) RAIL_BLE_CS_RTT_AA_SUCCESS)
1115 #define RAIL_BLE_CS_RTT_AA_BIT_ERRORS ((RAIL_BLE_CsRttPacketQuality_t) RAIL_BLE_CS_RTT_AA_BIT_ERRORS)
1116 #define RAIL_BLE_CS_RTT_AA_NOT_FOUND  ((RAIL_BLE_CsRttPacketQuality_t) RAIL_BLE_CS_RTT_AA_NOT_FOUND)
1117 #endif//DOXYGEN_SHOULD_SKIP_THIS
1118 
1119 /**
1120  * @struct RAIL_BLE_CsMode0Results_t
1121  * @brief Contains CS mode 0 step measurement results.
1122  */
1123 typedef struct RAIL_BLE_CsMode0Results {
1124   /** Mode of CS step. */
1125   uint8_t mode;
1126   /** Antenna ID. */
1127   RAIL_BLE_CsAntennaId_t antenna;
1128   /** RSSI during step in integer dBm. */
1129   int8_t rssi;
1130   /** Packet quality. */
1131   uint8_t packetQuality;
1132   /** Reserved. */
1133   uint16_t reserved;
1134   /** Fractional Frequency Offset (FFO) in units of parts per 100 million. */
1135   int16_t csFfoPp100m;
1136   /** The gain setting. */
1137   uint32_t stepGainSetting;
1138   /** Reserved. */
1139   uint32_t reserved1[4];
1140 } RAIL_BLE_CsMode0Results_t;
1141 
1142 /**
1143  *  A sentinel value to indicate an invalid rtt time value in
1144  *  \ref RAIL_BLE_CsMode1Results_t::rttHalfNs
1145  */
1146 #define RAIL_BLE_CS_INVALID_RTT_VALUE ((int16_t)0x8000)
1147 
1148 /**
1149  * @struct RAIL_BLE_CsMode1Results_t
1150  * @brief Contains CS mode 1 step measurement results.
1151  */
1152 typedef struct RAIL_BLE_CsMode1Results {
1153   /** Mode of CS step. */
1154   uint8_t mode;
1155   /** Antenna ID. */
1156   RAIL_BLE_CsAntennaId_t antenna;
1157   /** RSSI during step in integer dBm. */
1158   int8_t rssi;
1159   /** Packet quality. */
1160   uint8_t packetQuality;
1161   /**
1162    * For the initiator, this is the time (in 0.5 ns units) between time of
1163    * departure and time of arrival excluding known offsets such as interlude
1164    * period and packet length.
1165    * For the reflector, this is the time (in 0.5 ns units) between time of
1166    * arrival and time of departure excluding known offsets such as interlude
1167    * period and packet length.
1168    */
1169   int16_t rttHalfNs;
1170   /** Flag used to indicate whether we have missed frequency calibration. */
1171   uint8_t missedFcal;
1172   /** Reserved. */
1173   uint8_t reserved;
1174   /** Reserved. */
1175   uint32_t reserved1[5];
1176 } RAIL_BLE_CsMode1Results_t;
1177 
1178 /**
1179  * @enum RAIL_BLE_CsToneQuality_t
1180  * @brief CS tone quality.
1181  */
RAIL_ENUM(RAIL_BLE_CsToneQuality_t)1182 RAIL_ENUM(RAIL_BLE_CsToneQuality_t) {
1183   /** Good quality CS mode 2 tone. */
1184   RAIL_BLE_CS_TONE_QUALITY_GOOD = 0U,
1185   /** Medium quality CS mode 2 tone. */
1186   RAIL_BLE_CS_TONE_QUALITY_MEDIUM = 1U,
1187   /** Low quality CS mode 2 tone. */
1188   RAIL_BLE_CS_TONE_QUALITY_LOW = 2U,
1189   /** CS mode 2 tone quality indication unavailable. */
1190   RAIL_BLE_CS_TONE_QUALITY_UNAVAILABLE = 3U,
1191 };
1192 
1193 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1194 // Self-referencing defines minimize compiler complaints when using RAIL_ENUM
1195 #define RAIL_BLE_CS_TONE_QUALITY_GOOD        ((RAIL_BLE_CsToneQuality_t) RAIL_BLE_CS_TONE_QUALITY_GOOD)
1196 #define RAIL_BLE_CS_TONE_QUALITY_MEDIUM      ((RAIL_BLE_CsToneQuality_t) RAIL_BLE_CS_TONE_QUALITY_MEDIUM)
1197 #define RAIL_BLE_CS_TONE_QUALITY_LOW         ((RAIL_BLE_CsToneQuality_t) RAIL_BLE_CS_TONE_QUALITY_LOW)
1198 #define RAIL_BLE_CS_TONE_QUALITY_UNAVAILABLE ((RAIL_BLE_CsToneQuality_t) RAIL_BLE_CS_TONE_QUALITY_UNAVAILABLE)
1199 #endif//DOXYGEN_SHOULD_SKIP_THIS
1200 
1201 /** The minimum number of antenna slots supported during a CS event. */
1202 #define RAIL_BLE_CS_MIN_ANTENNA_SLOTS 2U
1203 
1204 /** The maximum number of antenna slots supported during a CS event. */
1205 #define RAIL_BLE_CS_MAX_ANTENNA_SLOTS 5U
1206 
1207 /**
1208  * @struct RAIL_BLE_CsMode2Results_t
1209  * @brief Contains CS mode 2 step measurement results.
1210  */
1211 typedef struct RAIL_BLE_CsMode2Results {
1212   /** Mode of CS step. */
1213   uint8_t mode;
1214   /** Flag used to indicate whether we have missed frequency calibration. */
1215   uint8_t missedFcal;
1216   /** PCT i value. */
1217   int16_t pctI[RAIL_BLE_CS_MAX_ANTENNA_SLOTS];
1218   /** PCT q value. */
1219   int16_t pctQ[RAIL_BLE_CS_MAX_ANTENNA_SLOTS];
1220   /** Tone quality indicator. */
1221   RAIL_BLE_CsToneQuality_t tqi[RAIL_BLE_CS_MAX_ANTENNA_SLOTS];
1222   /** Reserved. */
1223   uint8_t reserved[3];
1224 } RAIL_BLE_CsMode2Results_t;
1225 
1226 /**
1227  * @struct RAIL_BLE_CsStepResults_t
1228  * @brief Generic CS step mode result structure. Based on the value of the
1229  *   mode field, this structure can be type cast to the appropriate mode
1230  *   specific structure \ref RAIL_BLE_CsMode0Results_t,
1231  *   \ref RAIL_BLE_CsMode1Results_t, or \ref RAIL_BLE_CsMode2Results_t.
1232  */
1233 typedef struct RAIL_BLE_CsStepResults {
1234   /** Mode of CS step. */
1235   uint8_t mode;
1236   /** Reserved. */
1237   uint8_t reserved;
1238   /** Reserved. */
1239   uint16_t reserved1;
1240   /** Reserved. */
1241   uint32_t reserved2[6];
1242 } RAIL_BLE_CsStepResults_t;
1243 
1244 /**
1245  * @struct RAIL_BLE_CsMode0DebugResults_t
1246  * @brief Contains CS mode 0 step measurement debug results.
1247  */
1248 typedef struct RAIL_BLE_CsMode0DebugResults {
1249   /**
1250    * AGC gain value of the Mode 0 step with the highest recorded
1251    * RSSI up to and including the current Mode 0 step.
1252    */
1253   uint32_t agcStatus0;
1254   /**
1255    * For devices configured as an initiator, the measured frequency offset
1256    * in Hz between the two devices during a CS mode 0 step. For devices
1257    * configured as a reflector, this value will always be 0.
1258    */
1259   int32_t freqOffHz;
1260   /** Estimated coarse frequency offset in internal units. */
1261   int32_t hwFreqOffEst;
1262   /** Starting index IQ sample index of unmodulated carrier. */
1263   uint16_t ucStartIndex;
1264   /** End index IQ sample index of unmodulated carrier. */
1265   uint16_t ucEndIndex;
1266   /** Reserved. */
1267   uint32_t reserved[2];
1268   /**
1269    * FFO of the Mode 0 step with the highest recorded RSSI
1270    * up to and including the current Mode 0 step.
1271    */
1272   int16_t csFfoPp100m;
1273   /** Highest recorded RSSI up to and including the current mode 0 step, in dBm. */
1274   int8_t highestRssiDbm;
1275   /** Reserved. */
1276   uint8_t reserved1;
1277   /** Reserved. */
1278   uint32_t reserved2[3];
1279 } RAIL_BLE_CsMode0DebugResults_t;
1280 
1281 /**
1282  * @struct RAIL_BLE_CsMode1DebugResults_t
1283  * @brief Contains CS mode 1 step measurement debug results.
1284  */
1285 typedef struct RAIL_BLE_CsMode1DebugResults {
1286   /** Coarse time of flight in units of HFXO clock cycles. */
1287   uint16_t toxClks;
1288   /** Fractional component of time of flight in units of half nanoseconds. */
1289   int16_t fracRttHalfNs;
1290   /** Coarse component of time of flight in units of half nanoseconds. */
1291   uint32_t coarseRttHalfNs;
1292   /** Group delay compensation in units of half nanoseconds. */
1293   int32_t gdCompRttHalfNs;
1294   /** Time of flight without T_SY_CENTER_DELTA compensation in units of half nanoseconds. */
1295   int32_t toxWithOffsetsRttHalfNs;
1296   /** Internal CS status register. */
1297   uint32_t csstatus3;
1298   /** Internal CS status register. */
1299   uint32_t csstatus4;
1300   /** Internal CS status register. */
1301   uint32_t csstatus5;
1302   /** Reserved. */
1303   uint32_t reserved[3];
1304 } RAIL_BLE_CsMode1DebugResults_t;
1305 
1306 /**
1307  * @struct RAIL_BLE_CsMode2DebugResults_t
1308  * @brief Contains CS mode 2 step measurement debug results.
1309  */
1310 typedef struct RAIL_BLE_CsMode2DebugResults {
1311   /** Hardware PCT I value. */
1312   int16_t hardwarePctI;
1313   /** Hardware PCT Q value. */
1314   int16_t hardwarePctQ;
1315   /** DCCOMP i value. */
1316   int16_t dcCompI;
1317   /** DCCOMP q value. */
1318   int16_t dcCompQ;
1319   /** GDCOMP i value. */
1320   int16_t gdCompI[RAIL_BLE_CS_MAX_ANTENNAS];
1321   /** GDCOMP q value. */
1322   int16_t gdCompQ[RAIL_BLE_CS_MAX_ANTENNAS];
1323   /** Raw tone quality value. */
1324   uint16_t tqiRaw;
1325   /** Raw tone quality tone extension value. */
1326   uint16_t tqiToneExtRaw;
1327   /**
1328    * Pointer to the starting index of each antenna slot for
1329    * reading IQ samples.
1330    */
1331   uint16_t *ucStartIndex;
1332   /**
1333    * Pointer to the end index of each antenna slot for
1334    * reading IQ samples.
1335    */
1336   uint16_t *ucEndIndex;
1337   /** Frequency calibration value in internal units. */
1338   uint16_t fcal;
1339   /** Reserved. */
1340   uint16_t reserved;
1341 } RAIL_BLE_CsMode2DebugResults_t;
1342 
1343 /**
1344  * @struct RAIL_BLE_CsStepDebugResults_t
1345  * @brief Generic CS step mode debug result structure. Based on the value of
1346  *   the mode field, this structure can be type cast to the appropriate mode
1347  *   specific structure \ref RAIL_BLE_CsMode0DebugResults_t,
1348  *   \ref RAIL_BLE_CsMode1DebugResults_t, or \ref RAIL_BLE_CsMode2DebugResults_t.
1349  */
1350 typedef struct RAIL_BLE_CsStepDebugResults {
1351   /** Reserved. */
1352   uint32_t reserved;
1353   /** Reserved. */
1354   uint32_t reserved1;
1355   /** Reserved. */
1356   uint32_t reserved2;
1357   /** Reserved. */
1358   uint32_t reserved3;
1359   /** Reserved. */
1360   uint32_t reserved4;
1361   /** Reserved. */
1362   uint32_t reserved5;
1363   /** Reserved. */
1364   uint32_t reserved6;
1365   /** Reserved. */
1366   uint32_t reserved7;
1367   /** Reserved. */
1368   uint32_t reserved8;
1369   /** Reserved. */
1370   uint32_t reserved9;
1371 } RAIL_BLE_CsStepDebugResults_t;
1372 
1373 /**
1374  * @struct RAIL_BLE_CsStepConfig_t
1375  * @brief Contains arguments for \ref RAIL_BLE_SetNextCsStep().
1376  */
1377 typedef struct RAIL_BLE_CsStepConfig {
1378   /** Sets the CS step state. */
1379   RAIL_BLE_CsStepState_t stepState;
1380   /** Indicates whether this is final step in CS event. */
1381   bool lastStep;
1382   /**
1383    * Transmit tone during tone extension slot in mode 2 packet.
1384    * This field is ignored during RX and for all non mode 2 packets.
1385    */
1386   bool transmitToneExtension;
1387   /**
1388    * Length of packet payload in bytes. Should not include trailer, guard,
1389    * or UC bits. Only used for mode 1 steps, ignored otherwise.
1390    */
1391   uint8_t packetLength;
1392   /** Sets the CS step logical channel. */
1393   uint16_t channel;
1394   /** RTT marker bit positions. Ignored for mode 0 and 2 steps. */
1395   uint8_t rttMarkerBitPosition[2];
1396   /** The initiator (first) access address during step. */
1397   uint32_t initAccessAddress;
1398   /** The reflector (second) access address during step. */
1399   uint32_t reflAccessAddress;
1400   /** A pointer to TX data to be transmitted. Ignored for mode 0 and 2 steps. */
1401   uint8_t *pTxData;
1402   /**
1403    * A pointer to an array of CS step results. These results will be
1404    * populated after the completion of the CS step. This array can be cast to
1405    * \ref RAIL_BLE_CsMode0Results_t, \ref RAIL_BLE_CsMode1Results_t, or
1406    * \ref RAIL_BLE_CsMode2Results_t as appropriate to read mode specific
1407    * results.
1408    */
1409   RAIL_BLE_CsStepResults_t *pResults;
1410   /**
1411    * A pointer to an array of CS step debug results. These results will be
1412    * populated after the completion of the CS step. This array can be cast to
1413    * \ref RAIL_BLE_CsMode0DebugResults_t, \ref
1414    * RAIL_BLE_CsMode1DebugResults_t, or \ref RAIL_BLE_CsMode2DebugResults_t
1415    * as appropriate to read mode specific debug results.
1416    *
1417    * Setting this pointer to NULL means no debug data will be collected.
1418    */
1419   RAIL_BLE_CsStepDebugResults_t *pDebugResults;
1420   /**
1421    * A pointer to the start of captured IQ data for this step. This pointer
1422    * will be populated after the completion of the CS step.
1423    */
1424   uint32_t **pIqBuffer;
1425   /**
1426    * A pointer to captured IQ data size in 32 bit words. This pointer will be
1427    * populated after the completion of the CS step.
1428    */
1429   uint16_t *pIqBufferSize;
1430   /**
1431    * A pointer to a boolean to indicate whether to preserve IQ data for this
1432    * step. If this is the final step of the event, IQ data will automatically
1433    * be preserved regardless of how this boolean is set. For other steps, if
1434    * this boolean is set true, and there are at least \ref
1435    * RAIL_BLE_CS_1MBPS_MINIMUM_IQ_BUFFER_SIZE unused 32 bit words still
1436    * available in the event IQ buffer, this step's IQ data will be preserved
1437    * and not be overwritten by IQ data from a subsequent step. Otherwise, this
1438    * step's IQ data will not be preserved and may be overwritten. This boolean
1439    * will be updated after completion of the CS step to indicate whether the
1440    * IQ data from that step was actually preserved.
1441    */
1442   bool *pSaveIqData;
1443   /**
1444    * Array containing antenna settings for this step. This field has two uses
1445    * depending on the mode of the current step.
1446    *
1447    * On mode 0 and mode 1 steps, only the first element will be used to
1448    * indicate the antenna to be utilized during a mode 0 and
1449    * mode 1 step.
1450    *
1451    * On mode 2 steps, as many elements as
1452    * \ref RAIL_BLE_CS_MAX_ANTENNA_SLOTS - 1 that were configured for the
1453    * CS event will be applied.
1454    *
1455    * @note \ref RAIL_BLE_ConfigCsAntenna must be called prior to setting
1456    *   this field in order to set the antenna count as well as configure
1457    *   each antenna. Each element must be a valid antenna between 1 and
1458    *   the set antenna count.
1459    */
1460   RAIL_BLE_CsAntennaId_t antennaSelectBuffer[RAIL_BLE_CS_MAX_ANTENNAS];
1461 } RAIL_BLE_CsStepConfig_t;
1462 
1463 /**
1464  * @struct RAIL_BLE_CsAntennaConfig_t
1465  * @brief Contains arguments for \ref RAIL_BLE_ConfigCsAntenna() function.
1466  */
1467 typedef struct RAIL_BLE_CsAntennaConfig {
1468   /** Total number of antenna elements. */
1469   uint8_t antennaCount;
1470   /** A pointer to antenna offsets in cm units. */
1471   const int16_t *pAntennaOffsetCm;
1472 } RAIL_BLE_CsAntennaConfig_t;
1473 
1474 /**
1475  * @struct RAIL_BLE_CsGdCompTables_t
1476  * @brief Contains pointers to CS group delay compensation tables.
1477  */
1478 typedef struct RAIL_BLE_CsGdCompTables {
1479   /** A pointer to PBR phase LSB group delay compensation table. */
1480   const int16_t *pPbrPhaseLsb;
1481   /** A pointer to RTT slope group delay compensation table. */
1482   const int16_t *pRttSlope;
1483   /** A pointer to RTT offset group delay compensation table. */
1484   const int16_t *pRttOffset;
1485   /** Common length for each table in units of int16_t. */
1486   uint8_t length;
1487 } RAIL_BLE_CsGdCompTables_t;
1488 
1489 /**
1490  * Configure Channel Sounding (CS) functionality.
1491  *
1492  * @param[in] railHandle A RAIL instance handle.
1493  * @param[in] csConfig A non-NULL pointer to configuration options for CS.
1494  * @return Status code indicating success of the function call.
1495  *
1496  * @warning This API is not safe to use in a multiprotocol app.
1497  */
1498 RAIL_Status_t RAIL_BLE_ConfigCs(RAIL_Handle_t railHandle,
1499                                 const RAIL_BLE_CsConfig_t *csConfig);
1500 
1501 /**
1502  * Enable Channel Sounding (CS) functionality.
1503  *
1504  * @param[in] railHandle A RAIL instance handle.
1505  * @param[in] enable Enable or disable CS functionality.
1506  * @return Status code indicating success of the function call.
1507  *
1508  * @warning This API is not safe to use in a multiprotocol app.
1509  */
1510 RAIL_Status_t RAIL_BLE_EnableCs(RAIL_Handle_t railHandle,
1511                                 bool enable);
1512 
1513 /**
1514  * Set up the next CS step.
1515  *
1516  * @param[in] railHandle A RAIL instance handle.
1517  * @param[in,out] csStepConfig A pointer to configuration options for next CS step.
1518  * @param[in] pend If true, apply configuration at next appropriate radio
1519  *   transition (i.e., at Rx-to-Tx for an initiator, or Tx-to-Rx for a reflector).
1520  *   Otherwise, apply configuration immediately.
1521  * @return Status code indicating success of the function call.
1522  *
1523  * @note When the next CS step is to be pended, the specified step in
1524  *   csStepConfig must be the initial step state for a particular mode (e.g.
1525  *   \ref RAIL_BLE_CS_STEP_MODE0, \ref RAIL_BLE_CS_STEP_MODE1, or \ref
1526  *   RAIL_BLE_CS_STEP_MODE2). Otherwise this API will return \ref
1527  *   RAIL_STATUS_INVALID_PARAMETER.
1528  *
1529  * @warning This API is not safe to use in a multiprotocol app.
1530  */
1531 RAIL_Status_t RAIL_BLE_SetNextCsStep(RAIL_Handle_t railHandle,
1532                                      const RAIL_BLE_CsStepConfig_t *csStepConfig,
1533                                      bool pend);
1534 
1535 /**
1536  * Configure antennas for CS event.
1537  *
1538  * @param[in] railHandle A RAIL instance handle.
1539  * @param[in] pAntennaConfig A pointer to the antenna config
1540  * @return Status code indicating success of the function call.
1541  */
1542 RAIL_Status_t RAIL_BLE_ConfigCsAntenna(RAIL_Handle_t railHandle,
1543                                        RAIL_BLE_CsAntennaConfig_t *pAntennaConfig);
1544 
1545 /**
1546  * Returns the number of antennas configured for a CS event.
1547  *
1548  * @param[in] railHandle A RAIL instance handle.
1549  * @return The number of antennas configured for a CS event.
1550  *
1551  * @note If \ref RAIL_BLE_ConfigCsAntenna has not been called, this
1552  *   API will return \ref RAIL_BLE_CS_INVALID_ANTENNA_COUNT as
1553  *   no antennas have been configured for the CS event. The CS event
1554  *   will still run with an antenna count of 1 and 0 cm antenna offset.
1555  */
1556 uint8_t RAIL_BLE_GetCsAntennaCount(RAIL_Handle_t railHandle);
1557 
1558 /**
1559  * Loads the CS RTT and PBR group delay compensation tables for a
1560  * particular PA mode.
1561  *
1562  * @param[in] railHandle A RAIL instance handle.
1563  * @param[in] pTables A pointer to group delay compensation lookup tables.
1564  * @param[in] powerMode The PA mode for which to load compensation tables.
1565  * @return Status code indicating success of the function call.
1566  */
1567 RAIL_Status_t RAIL_BLE_LoadCsCompTables(RAIL_Handle_t railHandle,
1568                                         const RAIL_BLE_CsGdCompTables_t *pTables,
1569                                         RAIL_TxPowerMode_t powerMode);
1570 
1571 /**
1572  * Callback used to load CS group delay compensation tables for all PA modes
1573  * supported by device during \ref RAIL_BLE_EnableCs() when enable is true.
1574  * This function is optional to implement.
1575  *
1576  * @return Status code indicating success of the function call.
1577  *
1578  * @note If this callback function is not implemented, unneeded tables may not
1579  *   be dead stripped, resulting in larger overall code size. The API \ref
1580  *   RAIL_BLE_LoadCsCompTables() should be used within this callback to load the
1581  *   appropriate tables for each supported PA mode.
1582  */
1583 RAIL_Status_t RAILCb_BLE_CsGdCompTableLoad(void);
1584 
1585 /** @} */  // end of group CS
1586 #endif//DOXYGEN_SHOULD_SKIP_THIS
1587 
1588 /// @addtogroup BLETX2TX BLE TX Channel Hopping
1589 /// @{
1590 /// @code{.c}
1591 /// // Configuration to send one additional packet
1592 /// static RAIL_BLE_TxChannelHoppingConfigEntry_t entry[1];
1593 /// static uint32_t buffer[BUFFER_SIZE];
1594 /// static RAIL_BLE_TxRepeatConfig_t repeat = {
1595 ///   .iterations = 1,
1596 ///   .repeatOptions = RAIL_TX_REPEAT_OPTION_HOP,
1597 ///   .delayOrHop.channelHopping = {
1598 ///     .buffer = buffer,
1599 ///     .bufferLength = BUFFER_SIZE,
1600 ///     .numberOfChannels = 1,
1601 ///     .entries = &entry[0],
1602 ///   },
1603 /// };
1604 ///
1605 /// // Send a normal packet on the current channel, then a packet on a new channel
1606 /// void bleSendThenAdvertise(uint8_t *firstPacket, uint8_t *secondPacket)
1607 /// {
1608 ///   // Load both packets into the FIFO
1609 ///   RAIL_WriteTxFifo(railHandle, firstPacket, FIRST_PACKET_LEN, true);
1610 ///   RAIL_WriteTxFifo(railHandle, secondPacket, SECOND_PACKET_LEN, false);
1611 ///
1612 ///   // Configure a 300 us turnaround between transmits
1613 ///   entry[0].delayMode = RAIL_CHANNEL_HOPPING_DELAY_MODE_STATIC;
1614 ///   entry[0].delay = 300; // microseconds
1615 ///
1616 ///   // Use default advertising parameters
1617 ///   entry[0].disableWhitening = false;
1618 ///   entry[0].crcInit = 0x00555555;
1619 ///   entry[0].accessAddress = 0x8E89BED6;
1620 ///
1621 ///   // Transmit the repeated packet on the first advertising channel
1622 ///   entry[0].phy = RAIL_BLE_1Mbps;
1623 ///   entry[0].railChannel = 0;
1624 ///   entry[0].logicalChannel = 37;
1625 ///
1626 ///  // Configure repeated transmit in RAIL, then transmit, sending both packets
1627 ///  RAIL_BLE_SetNextTxRepeat(railHandle, &repeat);
1628 ///  RAIL_StartTx(railHandle, currentChannel, RAIL_TX_OPTIONS_DEFAULT, NULL);
1629 /// }
1630 /// @endcode
1631 
1632 /**
1633  * @struct RAIL_BLE_TxChannelHoppingConfigEntry_t
1634  * @brief Structure that represents one of the channels that is part of a
1635  *   \ref RAIL_BLE_TxChannelHoppingConfig_t sequence of channels used in
1636  *   channel hopping.
1637  */
1638 typedef struct RAIL_BLE_TxChannelHoppingConfigEntry {
1639   /**
1640    * Idle time in microseconds to wait before hopping into the
1641    * channel indicated by this entry.
1642    */
1643   uint32_t delay;
1644   /**
1645    * The BLE PHY to use for this hop's transmit.
1646    */
1647   RAIL_BLE_Phy_t phy;
1648   /**
1649    * The logical channel to use for this hop's transmit. The whitener will
1650    * be reinitialized if used.
1651    */
1652   uint8_t logicalChannel;
1653   /**
1654    * The channel number to be used for this hop's transmit. If this is an
1655    * invalid channel for the chosen PHY, the call to \ref RAIL_SetNextTxRepeat()
1656    * will fail.
1657    */
1658   uint8_t railChannel;
1659   /**
1660    * This can turn off the whitening engine and is useful for sending BLE test
1661    * mode packets that don't have this turned on.
1662    */
1663   bool disableWhitening;
1664   /**
1665    * The value to use for CRC initialization.
1666    */
1667   uint32_t crcInit;
1668   /**
1669    * The access address to use for the connection.
1670    */
1671   uint32_t accessAddress;
1672 } RAIL_BLE_TxChannelHoppingConfigEntry_t;
1673 
1674 /**
1675  * @struct RAIL_BLE_TxChannelHoppingConfig_t
1676  * @brief Wrapper struct that will contain the sequence of
1677  *   \ref RAIL_BLE_TxChannelHoppingConfigEntry_t that represents the channel
1678  *   sequence to use during TX Channel Hopping.
1679  */
1680 typedef struct RAIL_BLE_TxChannelHoppingConfig {
1681   /**
1682    * Pointer to contiguous global read-write memory that will be used
1683    * by RAIL to store channel hopping information throughout its operation.
1684    * It need not be initialized and applications should never write
1685    * data anywhere in this buffer.
1686    */
1687   uint32_t *buffer;
1688   /**
1689    * This parameter must be set to the length of the buffer array. This way,
1690    * during configuration, the software can confirm it's writing within the
1691    * range of the buffer. The configuration API will return an error
1692    * if bufferLength is insufficient.
1693    */
1694   uint16_t bufferLength;
1695   /** The number of channels that is in the channel hopping sequence. */
1696   uint8_t numberOfChannels;
1697   /**
1698    * Pad bytes reserved for future use and currently ignored.
1699    */
1700   uint8_t reserved;
1701   /**
1702    * A pointer to the first element of an array of \ref
1703    * RAIL_BLE_TxChannelHoppingConfigEntry_t that represents the channels
1704    * used during channel hopping. The number of entries in this array must be
1705    * numberOfChannels.
1706    */
1707   RAIL_BLE_TxChannelHoppingConfigEntry_t *entries;
1708 } RAIL_BLE_TxChannelHoppingConfig_t;
1709 
1710 /// @struct RAIL_BLE_TxRepeatConfig_t
1711 /// @brief A configuration structure for repeated transmits
1712 ///
1713 typedef struct RAIL_BLE_TxRepeatConfig {
1714   /**
1715    * The number of repeated transmits to run. A total of (iterations + 1)
1716    * transmits will go on-air in the absence of errors.
1717    */
1718   uint16_t iterations;
1719   /**
1720    * Repeat option(s) to apply.
1721    */
1722   RAIL_TxRepeatOptions_t repeatOptions;
1723   /**
1724    * Per-repeat delay or hopping configuration, depending on repeatOptions.
1725    */
1726   union {
1727     /**
1728      * When \ref RAIL_TX_REPEAT_OPTION_HOP is not set, this specifies
1729      * the delay time between each repeated transmit. Specify \ref
1730      * RAIL_TRANSITION_TIME_KEEP to use the current \ref
1731      * RAIL_StateTiming_t::txToTx transition time setting.
1732      */
1733     RAIL_TransitionTime_t delay;
1734     /**
1735      * When \ref RAIL_TX_REPEAT_OPTION_HOP is set, this specifies
1736      * the channel hopping configuration to use when hopping between
1737      * repeated transmits. Per-hop delays are configured within each
1738      * \ref RAIL_BLE_TxChannelHoppingConfigEntry_t::delay rather than
1739      * this union's delay field.
1740      */
1741     RAIL_BLE_TxChannelHoppingConfig_t channelHopping;
1742   } delayOrHop;
1743 } RAIL_BLE_TxRepeatConfig_t;
1744 
1745 /**
1746  * Set up automatic repeated transmits after the next transmit.
1747  *
1748  * @param[in] railHandle A RAIL instance handle.
1749  * @param[in] repeatConfig A non-NULL pointer to the configuration structure for repeated transmits.
1750  * @return Status code indicating a success of the function call.
1751  *
1752  * Repeated transmits will occur after an application-initiated transmit caused
1753  * by calling one of the \ref Packet_TX APIs. The repetition will only occur
1754  * after the first application-initiated transmit after this function is
1755  * called. Future repeated transmits must be requested by calling this function
1756  * again.
1757  *
1758  * Each repeated transmit that occurs will have full \ref PTI information and
1759  * will receive events such as \ref RAIL_EVENT_TX_PACKET_SENT as normal.
1760  *
1761  * If a TX error occurs during the repetition, the process will abort and the
1762  * TX error transition from \ref RAIL_SetTxTransitions() will be used. If the
1763  * repetition completes successfully, the TX success transition from
1764  * \ref RAIL_SetTxTransitions() will be used.
1765  *
1766  * Any call to \ref RAIL_Idle(), \ref RAIL_StopTx(), or \ref
1767  * RAIL_SetTxTransitions() will clear the pending
1768  * repeated transmits. The state will also be cleared by another call to this
1769  * function. To clear the repeated transmits before they've started without
1770  * stopping other radio actions, call this function with a \ref
1771  * RAIL_BLE_TxRepeatConfig_t::iterations count of 0. A DMP switch will clear this
1772  * state only if the initial transmit triggering the repeated transmits has
1773  * started.
1774  *
1775  * The application is responsible for populating the transmit data to be used
1776  * by the repeated transmits via \ref RAIL_SetTxFifo() or \ref RAIL_WriteTxFifo().
1777  * Data will be transmitted from the TX FIFO. If the TX FIFO does not have
1778  * sufficient data to transmit, a TX error and a \ref
1779  * RAIL_EVENT_TX_UNDERFLOW will occur. To avoid an underflow, the
1780  * application should queue data to be transmitted as early as possible.
1781  *
1782  * This function will fail to configure the repetition if a transmit of any
1783  * kind is ongoing, including during the time between an initial transmit and
1784  * the end of a previously-configured repetition.
1785  *
1786  * @note Use the compile time symbol \ref RAIL_SUPPORTS_TX_TO_TX or the runtime
1787  *   call \ref RAIL_SupportsTxToTx() to check whether the platform supports
1788  *   this feature.
1789  */
1790 RAIL_Status_t RAIL_BLE_SetNextTxRepeat(RAIL_Handle_t railHandle,
1791                                        const RAIL_BLE_TxRepeatConfig_t *repeatConfig);
1792 
1793 /** @} */  // end of group BLETX2TX
1794 
1795 /** @} */ // end of BLE
1796 
1797 /// @addtogroup Calibration
1798 /// @brief Bluetooth protocol-specific APIs for calibrating the radio.
1799 /// @{
1800 
1801 /**
1802  * Calibrate image rejection for Bluetooth Low Energy.
1803  *
1804  * @param[in] railHandle A RAIL instance handle.
1805  * @param[out] imageRejection A pointer to where the result of the image
1806  *   rejection calibration will be stored.
1807  * @return Status code indicating success of the function call.
1808  *
1809  * Some chips have protocol-specific image rejection calibrations programmed
1810  * into their flash. This function will either get the value from flash and
1811  * apply it, or run the image rejection algorithm to find the value.
1812  */
1813 RAIL_Status_t RAIL_BLE_CalibrateIr(RAIL_Handle_t railHandle,
1814                                    uint32_t *imageRejection);
1815 
1816 /// @} // End of group Calibration
1817 
1818 #ifdef __cplusplus
1819 }
1820 #endif
1821 
1822 #endif // __RAIL_BLE_H__
1823