Mistake on this page?
Report an issue in GitHub or email us
pal_bb.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file
4  *
5  * \brief Baseband interface file.
6  *
7  * Copyright (c) 2016-2019 Arm Ltd. All Rights Reserved.
8  *
9  * Copyright (c) 2019-2020 Packetcraft, Inc.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 /*************************************************************************************************/
24 
25 #ifndef PAL_BB_H
26 #define PAL_BB_H
27 
28 #include "pal_types.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**************************************************************************************************
35  Macros
36 **************************************************************************************************/
37 
38 /*! \brief Protocol types */
39 typedef enum
40 {
41  BB_PROT_NONE, /*!< Non-protocol specific operation. */
42  BB_PROT_BLE, /*!< Bluetooth Low Energy normal mode. */
43  BB_PROT_BLE_DTM, /*!< Bluetooth Low Energy direct test mode. */
44  BB_PROT_PRBS15, /*!< Enable the continuous PRBS15 transmit sequence. */
45  BB_PROT_15P4, /*!< 802.15.4. */
46  BB_PROT_NUM /*!< Number of protocols. */
47 } PalBbProt_t;
48 
49 /*! \brief Status codes */
50 enum
51 {
52  BB_STATUS_SUCCESS, /*!< Operation successful. */
53  BB_STATUS_FAILED, /*!< General failure. */
54  BB_STATUS_CANCELED, /*!< Receive canceled. */
55  BB_STATUS_RX_TIMEOUT, /*!< Receive packet timeout. */
56  BB_STATUS_CRC_FAILED, /*!< Receive packet with CRC verification failed. */
57  BB_STATUS_FRAME_FAILED, /*!< Receive packet with frame verification failed. */
58  BB_STATUS_ACK_FAILED, /*!< ACK packet failure. */
59  BB_STATUS_ACK_TIMEOUT, /*!< ACK packet timeout. */
60  BB_STATUS_TX_CCA_FAILED, /*!< Transmit CCA failure. */
61  BB_STATUS_TX_FAILED /*!< Transmit failure. */
62 };
63 
64 /*! \brief PHY types. */
65 typedef enum
66 {
67  BB_PHY_BLE_1M = 1, /*!< Bluetooth Low Energy 1Mbps PHY. */
68  BB_PHY_BLE_2M = 2, /*!< Bluetooth Low Energy 2Mbps PHY. */
69  BB_PHY_BLE_CODED = 3, /*!< Bluetooth Low Energy Coded PHY (data coding unspecified). */
70  BB_PHY_15P4 = 4, /*!< 802.15.4 PHY. */
71 } PalBbPhy_t;
72 
73 /*! \brief PHY options. */
74 enum
75 {
76  BB_PHY_OPTIONS_DEFAULT = 0, /*!< BB defined PHY Options behavior. */
77  BB_PHY_OPTIONS_BLE_S2 = 1, /*!< Always use S=2 coding when transmitting on LE Coded PHY. */
78  BB_PHY_OPTIONS_BLE_S8 = 2 /*!< Always use S=8 coding when transmitting on LE Coded PHY. */
79 };
80 
81 #ifndef BB_CLK_RATE_HZ
82 /*! \brief BB clock rate in hertz. */
83 #define BB_CLK_RATE_HZ 1000000
84 #endif
85 
86 /*! \brief Binary divide with 1,000,000 divisor (n[max]=0xFFFFFFFF). */
87 #define BB_MATH_DIV_10E6(n) ((uint32_t)(((uint64_t)(n) * UINT64_C(4295)) >> 32))
88 
89 #if (BB_CLK_RATE_HZ == 1000000)
90 /*! \brief Return microseconds (no conversion required). */
91 #define BB_US_TO_BB_TICKS(us) (us)
92 #elif (BB_CLK_RATE_HZ == 8000000)
93 /*! \brief Compute BB ticks from given time in microseconds (max time is interval=1,996s). */
94 #define BB_US_TO_BB_TICKS(us) ((uint32_t)((us) << 3))
95 #elif (BB_CLK_RATE_HZ == 32768)
96 /*! \brief Compute BB ticks from given time in microseconds (max time is interval=1,996s). */
97 #define BB_US_TO_BB_TICKS(us) ((uint32_t)(((uint64_t)(us) * (uint64_t)(70368745)) >> 31)) /* calculated value may be one tick low */
98 #else
99 /*! \brief Compute BB ticks from given time in microseconds (max time is interval=1,996s). */
100 #define BB_US_TO_BB_TICKS(us) BB_MATH_DIV_10E6((uint64_t)(us) * (uint64_t)(BB_CLK_RATE_HZ))
101 #endif
102 
103 #define RTC_CLOCK_RATE 32768
104 #define USE_RTC_BB_CLK (BB_CLK_RATE_HZ == RTC_CLOCK_RATE)
105 
106 #if (BB_CLK_RATE_HZ == 1000000)
107 /*! \brief BB ticks to microseconds (no conversion required). */
108 #define BB_TICKS_TO_US(n) (n)
109 #elif (BB_CLK_RATE_HZ == 8000000)
110 /*! \brief BB ticks to microseconds (8MHz). */
111 #define BB_TICKS_TO_US(n) ((n) >> 3)
112 #elif (BB_CLK_RATE_HZ == 32768)
113 /*! \brief BB ticks to microseconds (32768 Hz). */
114 #define BB_TICKS_TO_US(n) (uint32_t)(((uint64_t)(n) * 15625) >> 9)
115 #else
116 /*! \brief BB ticks to microseconds. */
117 #define BB_TICKS_TO_US(n) (uint32_t)((uint64_t)(n) * 1000000 / BB_CLK_RATE_HZ)
118 #endif
119 
120 /*! \brief Typical maximum duration to scan in a scan interval (BbRtCfg_t::maxScanPeriodMs). */
121 #define BB_MAX_SCAN_PERIOD_MS 1000
122 
123 /*! \brief Typical RF setup delay (BbRtCfg_t::rfSetupDelayUs). */
124 #define BB_RF_SETUP_DELAY_US 150
125 
126 /*! \brief Typical operation setup delay in microseconds (BbRtCfg_t::schSetupDelayUs). */
127 #define BB_SCH_SETUP_DELAY_US 500
128 
129 /*! \brief Maximum time tick for 32 bit timer(1MHz) in microseconds (BbRtCfg_t::schSetupDelayUs). */
130 #define BB_TIMER_1MHZ_MAX_VALUE_US 0xFFFFFFFF /* 2^32 - 1 = 0xFFFFFFFF. */
131 
132 /*! \brief Maximum time tick for 32 bit timer(8MHz) in microseconds (BbRtCfg_t::schSetupDelayUs). */
133 #define BB_TIMER_8MHZ_MAX_VALUE_US 0x1FFFFFFF /* 2^29 - 1 = 0x1FFFFFFF. */
134 
135 /*! \brief Maximum time tick for 24 bit RTC counter(32768Hz) in microseconds. (BbRtCfg_t::BbTimerBoundaryUs) */
136 #define BB_RTC_MAX_VALUE_US 511999999 /* 2^24 / 32768 * 10^6 - 1 = 512 * 10^6 - 1 = 511999999. */
137 
138 /**************************************************************************************************
139  Type Definitions
140 **************************************************************************************************/
141 
142 /*! \brief IRQ callback datatypes. */
143 typedef void (*bbDrvIrqCback_t)(void);
144 
145 /*! \brief BB configuration. */
146 typedef struct
147 {
148  uint16_t clkPpm; /*!< Clock accuracy in PPM. */
149  uint8_t rfSetupDelayUsec; /*!< RF setup delay in microseconds. */
150  uint16_t maxScanPeriodMsec; /*!< Maximum scan period in milliseconds. */
151  uint16_t schSetupDelayUsec; /*!< Schedule setup delay in microseconds. */
152  uint32_t BbTimerBoundaryUsec; /*!< BB timer boundary translated in microseconds before wraparound. */
153 } PalBbCfg_t;
154 
155 /**************************************************************************************************
156  Function Declarations
157 **************************************************************************************************/
158 
159 /*! \addtogroup PAL_BB_INIT
160  * \{
161  * This section contains driver routines which initialize as well as enable the sleep mode
162  * of the BB hardware.
163  */
164 
165 /*************************************************************************************************/
166 /*!
167  * \brief Initialize the baseband driver.
168  *
169  * One-time initialization of baseband resources. This routine can be used to setup baseband
170  * resources, load RF trim parameters and execute RF calibrations and seed the random number
171  * generator.
172  *
173  * This routine should block until the BB hardware is completely initialized.
174  */
175 /*************************************************************************************************/
176 void PalBbInit(void);
177 
178 /*************************************************************************************************/
179 /*!
180  * \brief Enable the BB hardware.
181  *
182  * This routine brings the BB hardware out of low power (enable power and clocks) just before a
183  * first BB operation is executed.
184  */
185 /*************************************************************************************************/
186 void PalBbEnable(void);
187 
188 /*************************************************************************************************/
189 /*!
190  * \brief Disable the BB hardware.
191  *
192  * This routine signals the BB hardware to go into low power (disable power and clocks) after all
193  * BB operations have been disabled.
194  */
195 /*************************************************************************************************/
196 void PalBbDisable(void);
197 
198 /*************************************************************************************************/
199 /*!
200  * \brief Load BB timing configuration.
201  *
202  * \param pCfg Return configuration values.
203  */
204 /*************************************************************************************************/
205 void PalBbLoadCfg(PalBbCfg_t *pCfg);
206 
207 /*! \} */ /* PAL_BB_INIT */
208 
209 /*! \addtogroup PAL_BB_CLOCK
210  * \{
211  * This section contains driver routines related to the BB clock.
212  */
213 
214 /*************************************************************************************************/
215 /*!
216  * \brief Get the current BB clock value in microseconds.
217  *
218  * \return Current BB clock value, units are microseconds.
219  *
220  * This routine reads the current value from the BB clock and returns its value.
221  */
222 /*************************************************************************************************/
223 uint32_t PalBbGetCurrentTime(void);
224 
225 /*************************************************************************************************/
226 /*!
227  * \brief Get the current FRC time.
228  *
229  * \param pTime Pointer to return the current time.
230  *
231  * \return TRUE if time is valid, FALSE otherwise.
232  *
233  * Get the current FRC time.
234  *
235  * \note FRC is limited to the same bit-width as the BB clock. Return value is available
236  * only when the BB is active.
237  */
238 /*************************************************************************************************/
239 bool_t PalBbGetTimestamp(uint32_t *pTime);
240 
241 /*************************************************************************************************/
242 /*!
243  * \brief Called to register a protocol's Radio and Timer IRQ callback functions.
244  *
245  * \param protId Protocol ID.
246  * \param timerCback Timer IRQ callback.
247  * \param radioCback Timer IRQ callback.
248  */
249 /*************************************************************************************************/
250 void PalBbRegisterProtIrq(uint8_t protId, bbDrvIrqCback_t timerCback, bbDrvIrqCback_t radioCback);
251 
252 /*************************************************************************************************/
253 /*!
254  * \brief Set protocol ID.
255  *
256  * \param protId Protocol ID.
257  */
258 /*************************************************************************************************/
259 void PalBbSetProtId(uint8_t protId);
260 
261 /*! \} */ /* PAL_BB_CLOCK */
262 
263 #ifdef __cplusplus
264 };
265 #endif
266 
267 #endif /* PAL_BB_H */
void PalBbInit(void)
Initialize the baseband driver.
void PalBbEnable(void)
Enable the BB hardware.
void(* bbDrvIrqCback_t)(void)
IRQ callback datatypes.
Definition: pal_bb.h:143
uint32_t PalBbGetCurrentTime(void)
Get the current BB clock value in microseconds.
uint8_t rfSetupDelayUsec
Definition: pal_bb.h:149
void PalBbSetProtId(uint8_t protId)
Set protocol ID.
BB configuration.
Definition: pal_bb.h:146
uint16_t schSetupDelayUsec
Definition: pal_bb.h:151
uint8_t PalBbGetTimestamp(uint32_t *pTime)
Get the current FRC time.
uint16_t maxScanPeriodMsec
Definition: pal_bb.h:150
uint32_t BbTimerBoundaryUsec
Definition: pal_bb.h:152
PalBbProt_t
Protocol types.
Definition: pal_bb.h:39
Platform-independent data types.
void PalBbDisable(void)
Disable the BB hardware.
PalBbPhy_t
PHY types.
Definition: pal_bb.h:65
uint16_t clkPpm
Definition: pal_bb.h:148
void PalBbRegisterProtIrq(uint8_t protId, bbDrvIrqCback_t timerCback, bbDrvIrqCback_t radioCback)
Called to register a protocol&#39;s Radio and Timer IRQ callback functions.
void PalBbLoadCfg(PalBbCfg_t *pCfg)
Load BB timing configuration.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.