Mistake on this page?
Report an issue in GitHub or email us
lctr_int.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file
4  *
5  * \brief Internal link layer controller interface file.
6  *
7  * Copyright (c) 2013-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 LCTR_INT_H
26 #define LCTR_INT_H
27 
28 #include "lctr_api.h"
29 #include "lmgr_api.h"
30 #include "ll_defs.h"
31 #include "ll_math.h"
32 #include "util/crc32.h"
33 #include "pal_bb.h"
34 
35 #if (LL_ENABLE_TESTER)
36 #include "ll_tester_api.h"
37 #include "lctr_int_tester.h"
38 #endif
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /**************************************************************************************************
45  Macros
46 **************************************************************************************************/
47 
48 /*! \brief Minimum delay between connect indication and data channel in CONNECT_IND units. */
49 #define LCTR_DATA_CHAN_DLY 1 /* 1.25 ms */
50 
51 /*! \brief Minimum delay between auxiliary connect request and data channel using uncoded PHY in CONNECT_REQ units. */
52 #define LCTR_DATA_CHAN_DLY_AUX_UNCODED 2 /* 2.5 ms */
53 
54 /*! \brief Minimum delay between auxiliary connect request and data channel using coded PHY in CONNECT_REQ units. */
55 #define LCTR_DATA_CHAN_DLY_AUX_CODED 3 /* 3.75 ms */
56 
57 /*! \brief Convert connect indication ticks to scheduler ticks. */
58 #define LCTR_CONN_IND_TICKS(x) ((x) * (1250 / LL_BLE_US_PER_TICK))
59 
60 /*! \brief Convert connect indication ticks to milliseconds (no divide, rounds up). */
61 #define LCTR_CONN_IND_MS(x) ((x) + ((x) >> 2) + (((x) & 3) ? 1 : 0))
62 
63 /*! \brief Convert connect indication ticks to microseconds. */
64 #define LCTR_CONN_IND_US(x) ((x) * 1250)
65 
66 /*! \brief Convert connect indication timeout ticks to milliseconds. */
67 #define LCTR_CONN_IND_TO_MS(x) ((x) * 10)
68 
69 /*! \brief Convert microseconds to connection indication ticks. */
70 #define LCTR_US_TO_CONN_IND(x) LL_MATH_DIV_1250(x)
71 
72 /*! \brief Convert BLE protocol ticks to microseconds. */
73 #define LCTR_BLE_TO_US(x) ((x) * LL_BLE_US_PER_TICK)
74 
75 /*! \brief Convert periodic interval milliseconds to microseconds. */
76 #define LCTR_PER_INTER_TO_US(x) ((x) * 1250)
77 
78 /*! \brief Convert periodic interval microseconds to milliseconds. */
79 #define LCTR_PER_INTER_TO_MS(x) LL_MATH_DIV_1250(x)
80 
81 /*! \brief Convert periodic sync timeout unit to milliseconds. */
82 #define LCTR_PER_SYNC_TIMEOUT_TO_MS(x) ((x) * 10)
83 
84 /*! \brief Convert isochronous interval to microseconds. */
85 #define LCTR_ISO_INT_TO_US(x) ((x) * 1250)
86 
87 /*! \brief Fast termination supervision multiplier. */
88 #define LCTR_FAST_TERM_CNT 6
89 
90 /*! \brief Duration of a advertising packet in microseconds. */
91 #define LCTR_ADV_PKT_1M_US(len) ((LL_PREAMBLE_LEN_1M + LL_AA_LEN + LL_ADV_HDR_LEN + len + LL_CRC_LEN) << 3)
92 
93 /*! \brief Duration of a connection indication packet in microseconds. */
94 #define LCTR_CONN_IND_PKT_1M_US LCTR_ADV_PKT_1M_US(LL_CONN_IND_PDU_LEN)
95 
96 /*! \brief Extra area in ADVB buffer. */
97 #define LCTR_ADVB_BUF_EXTRA_SIZE 6
98 
99 /*! \brief Size for ADVB buffer allocation. */
100 #define LCTR_ADVB_BUF_SIZE (WSF_MAX(BB_FIXED_ADVB_PKT_LEN, LL_ADVB_MAX_LEN) + LCTR_ADVB_BUF_EXTRA_SIZE)
101 
102 /*! \brief RSSI offset of extra data in ADVB buffer. */
103 #define LCTR_ADVB_BUF_OFFSET_RSSI ((LCTR_ADVB_BUF_SIZE - LCTR_ADVB_BUF_EXTRA_SIZE) + 0)
104 
105 /*! \brief RPA offset of extra data in ADVB buffer. */
106 #define LCTR_ADVB_BUF_OFFSET_RX_RPA ((LCTR_ADVB_BUF_SIZE - LCTR_ADVB_BUF_EXTRA_SIZE) + 1)
107 
108 /*! \brief CRC offset of extra data in ADVB buffer. */
109 #define LCTR_ADVB_BUF_OFFSET_CRC ((LCTR_ADVB_BUF_SIZE - LCTR_ADVB_BUF_EXTRA_SIZE) + 2)
110 
111 /*! \brief LCTR Maximum span of scheduler elements. */
112 #define LCTR_SCH_MAX_SPAN ((BbGetBbTimerBoundaryUs() >> 1) + 1)
113 
114 /*! \brief LCTR Maximum value for sleep clock accuracy. */
115 #define LCTR_MAX_SCA 7
116 
117 /*! \brief Change supervision timeout value to us. */
118 #define LCTR_SUP_TIMEOUT_VAL_TO_US(x) (x * 10000)
119 
120 /**************************************************************************************************
121  Data Types
122 **************************************************************************************************/
123 
124 /*! \brief Call signature of a reset handler. */
125 typedef void (*LctrResetHdlr_t)(void);
126 
127 /*! \brief Call signature of a message dispatch handler. */
128 typedef void (*LctrMsgDisp_t)(lctrMsgHdr_t *pMsg);
129 
130 /*! \brief Call signature of a message dispatch handler. */
131 typedef void (*LctrEvtHdlr_t)(void);
132 
133 /*! \brief Reservation manager callback signature. */
134 typedef void (*LctrRmCback_t)(uint32_t rsvnOffs[], uint32_t refTime);
135 
136 /*! \brief Channel class update handler call signature. */
137 typedef uint8_t (*lctrChClassHdlr_t)(uint64_t chanMap);
138 
139 /**************************************************************************************************
140  Globals
141 **************************************************************************************************/
142 
143 extern LctrResetHdlr_t lctrResetHdlrTbl[LCTR_DISP_TOTAL];
144 extern LctrMsgDisp_t lctrMsgDispTbl[LCTR_DISP_TOTAL];
145 extern LctrEvtHdlr_t lctrEventHdlrTbl[LCTR_EVENT_TOTAL];
146 extern lctrMsgHdr_t *pLctrMsg;
147 extern const uint16_t scaPpmTbl[];
148 extern bool_t lctrResetEnabled;
149 
150 /**************************************************************************************************
151  Functions
152 **************************************************************************************************/
153 
154 /* Initialization. */
155 void lctrRegisterChClassHandler(lctrChClassHdlr_t cback);
156 
157 /* Helper routines. */
158 uint32_t lctrComputeAccessAddr(void);
159 uint32_t lctrComputeSeedAccessAddr(void);
160 uint8_t lctrComputeHopInc(void);
161 uint8_t lctrPeriodicSelectNextChannel(lmgrChanParam_t *pChanParam, uint16_t eventCounter);
162 void lctrPeriodicBuildRemapTable(lmgrChanParam_t *pChanParam);
163 uint16_t lctrCalcTotalAccuracy(uint8_t mstScaIdx);
164 uint32_t lctrComputeCrcInit(void);
165 uint32_t lctrCalcWindowWideningUsec(uint32_t unsyncTimeUsec, uint32_t caPpm);
166 
167 /* Host events */
168 void lctrNotifyHostHwErrInd(uint8_t code);
169 void lctrNotifyHostConnectInd(uint16_t handle, uint8_t role, lctrConnInd_t *pConnInd,
170  uint8_t peerIdAddrType, uint64_t peerIdAddr, uint64_t peerRpa,
171  uint64_t localRpa, uint8_t status, uint8_t usedChSel);
172 
173 /* State machine */
174 void lctrMstScanExecuteSm(uint8_t event);
175 void lctrMstInitExecuteSm(uint8_t event);
176 void lctrSlvAdvExecuteSm(uint8_t event);
177 
178 /*************************************************************************************************/
179 /*!
180  * \brief Calculate DID.
181  *
182  * \param pBuf Data buffer.
183  * \param len Length of data buffer.
184  *
185  * \return DID value.
186  */
187 /*************************************************************************************************/
188 static inline uint16_t lctrCalcDID(const uint8_t *pBuf, uint16_t len)
189 {
190  return CalcCrc32(LlMathRandNum(), len, pBuf);
191 }
192 
193 /*************************************************************************************************/
194 /*!
195  * \brief Convert PHYS bit to PHY.
196  *
197  * \param physBit PHYS bit.
198  *
199  * \return PHY.
200  */
201 /*************************************************************************************************/
202 static inline PalBbPhy_t lctrPhysBitToPhy(uint8_t physBit)
203 {
204  switch (physBit)
205  {
206  default:
207  case LL_PHYS_LE_1M_BIT:
208  return BB_PHY_BLE_1M;
209  case LL_PHYS_LE_2M_BIT:
210  return BB_PHY_BLE_2M;
212  return BB_PHY_BLE_CODED;
213  }
214 }
215 
216 /*************************************************************************************************/
217 /*!
218  * \brief Convert PHY to PHYS bit.
219  *
220  * \param phy PHY.
221  *
222  * \return PHYS bit.
223  */
224 /*************************************************************************************************/
225 static inline uint8_t lctrPhyToPhysBit(uint8_t phy)
226 {
227  switch (phy)
228  {
229  default:
230  case BB_PHY_BLE_1M:
231  return LL_PHYS_LE_1M_BIT;
232  case BB_PHY_BLE_2M:
233  return LL_PHYS_LE_2M_BIT;
234  case BB_PHY_BLE_CODED:
235  return LL_PHYS_LE_CODED_BIT;
236  }
237 }
238 
239 #ifdef __cplusplus
240 };
241 #endif
242 
243 #endif /* LCTR_INT_H */
uint32_t LlMathRandNum(void)
Generate random number.
static PalBbPhy_t lctrPhysBitToPhy(uint8_t physBit)
Convert PHYS bit to PHY.
Definition: lctr_int.h:202
uint32_t CalcCrc32(uint32_t crcInit, uint32_t len, const uint8_t *pBuf)
Calculate the CRC-32 of the given buffer.
Connect request PDU.
Definition: lctr_api.h:131
static uint16_t lctrCalcDID(const uint8_t *pBuf, uint16_t len)
Calculate DID.
Definition: lctr_int.h:188
CRC-32 utilities.
Link layer controller common interface file.
Channel parameters.
Definition: lmgr_api.h:137
void(* LctrResetHdlr_t)(void)
Call signature of a reset handler.
Definition: lctr_int.h:125
Common message structure passed to event handler.
Definition: lctr_api.h:109
void(* LctrMsgDisp_t)(lctrMsgHdr_t *pMsg)
Call signature of a message dispatch handler.
Definition: lctr_int.h:128
Link layer manager common interface file.
void(* LctrRmCback_t)(uint32_t rsvnOffs[], uint32_t refTime)
Reservation manager callback signature.
Definition: lctr_int.h:134
Link layer constant definitions.
uint8_t(* lctrChClassHdlr_t)(uint64_t chanMap)
Channel class update handler call signature.
Definition: lctr_int.h:137
PalBbPhy_t
PHY types.
Definition: pal_bb.h:65
void(* LctrEvtHdlr_t)(void)
Call signature of a message dispatch handler.
Definition: lctr_int.h:131
Baseband interface file.
Link Layer math utilities.
static uint8_t lctrPhyToPhysBit(uint8_t phy)
Convert PHY to PHYS bit.
Definition: lctr_int.h:225
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.