BLE-Stack APIs  3.00.00
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
uble.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!*****************************************************************************
33  * @defgroup Micro_BLE_Stack Micro BLE Stack
34  * @brief This module implmements the Micro BLE Stack
35  * @{
36  * @defgroup UBLE Micro Link Layer
37  * @{
38  * @file uble.h
39  * @brief This file contains the interface to the Micro Link Layer.
40  */
41 
42 #ifndef UBLE_H
43 #define UBLE_H
44 
45 #ifdef __cplusplus
46 extern "C"
47 {
48 #endif
49 
50 /*-------------------------------------------------------------------
51  * INCLUDES
52  */
53 #include <ti/sysbios/knl/Queue.h>
54 #include <urfc.h>
55 
56 /*-------------------------------------------------------------------
57  * DEFINITIONS & CONSTANTS
58  */
59 
68  #define UB_PARAM_COMMON_START 0
70 
81  #define UB_PARAM_RFPRIORITY (UB_PARAM_COMMON_START+0)
82 
92  #define UB_PARAM_RFTIMECRIT (UB_PARAM_COMMON_START+1)
93 
101  #define UB_PARAM_TXPOWER (UB_PARAM_COMMON_START+2)
102 
104  #define UB_PARAM_COMMON_END UB_PARAM_TXPOWER
105 #if defined(FEATURE_ADVERTISER)
106  #define UB_PARAM_ADV_CMN_START (UB_PARAM_COMMON_END+1)
107 
116  #define UB_PARAM_ADVINTERVAL (UB_PARAM_ADV_CMN_START+0)
117 
124  #define UB_PARAM_ADVCHANMAP (UB_PARAM_ADV_CMN_START+1)
125 
132  #define UB_PARAM_ADVTYPE (UB_PARAM_ADV_CMN_START+2)
133 
144  #define UB_PARAM_TIMETOADV (UB_PARAM_ADV_CMN_START+3)
145 
152  #define UB_PARAM_ADVDATA (UB_PARAM_ADV_CMN_START+4)
153 
155  #define UB_PARAM_ADV_CMN_END UB_PARAM_ADVDATA
156  #if defined(FEATURE_SCAN_RESPONSE)
157  #define UB_PARAM_ADV_SR_START (UB_PARAM_ADV_CMN_END+1)
158 
167  #define UB_PARAM_SCANRSPDATA (UB_PARAM_ADV_SR_START+0)
168 
177  #define UB_PARAM_ADVFLTPOLICY (UB_PARAM_ADV_SR_START+1)
178 
180  #define UB_PARAM_ADV_SR_END UB_PARAM_ADVFLTPOLICY
181  #else /* FEATURE_SCAN_RESPONSE */
182  #define UB_PARAM_ADV_SR_END UB_PARAM_ADV_CMN_END
183  #endif /* FEATURE_SCAN_RESPONSE */
184 #else /* FEATURE_ADVERTISER */
185  #define UB_PARAM_ADV_SR_END UB_PARAM_COMMON_END
186 #endif /* FEATURE_ADVERTISER */
187 #if defined(FEATURE_SCANNER)
188  #define UB_PARAM_SCAN_START (UB_PARAM_ADV_SR_END+1)
189  #define UB_PARAM_SCANINTERVAL (UB_PARAM_SCAN_START+0)
190  #define UB_PARAM_SCANWINDOW (UB_PARAM_SCAN_START+1)
191  #define UB_PARAM_SCANCHANMAP (UB_PARAM_SCAN_START+2)
192  #define UB_PARAM_SCANTYPE (UB_PARAM_SCAN_START+3)
193  #define UB_PARAM_FLTDUPLICATE (UB_PARAM_SCAN_START+4)
194  #define UB_PARAM_SCANFLTPOLICY (UB_PARAM_SCAN_START+5)
195  #define UB_PARAM_SCAN_END UB_PARAM_SCANFLTPOLICY
196 #else /*FEATURE_SCANNER */
197  #define UB_PARAM_SCAN_END UB_PARAM_ADV_SR_END
198 #endif /* FEATURE_SCANNER */
199  #define UB_NUM_PARAM (UB_PARAM_SCAN_END+1)
200 
206 #define RF_PRI_NORMAL ((uint8) RF_PriorityNormal)
207 #define RF_PRI_HIGH ((uint8) RF_PriorityHigh)
208 #define RF_PRI_HIGHEST ((uint8) RF_PriorityHighest)
209 
214 #define RF_TIME_RELAXED 0
215 #define RF_TIME_CRITICAL 1
216 
219 #define UB_TX_POWER_INVALID 0xFFFF
220 
224 #define UB_ADDRTYPE_PUBLIC 0
225 #define UB_ADDRTYPE_STATIC 1
226 #define UB_ADDRTYPE_NONRESOLVABLE 2
227 #define UB_ADDRTYPE_RESOLVABLE 3
228 #define UB_ADDRTYPE_BD 4
229 
234 #define UB_ADVTYPE_ADV_NC 5
235 #define UB_ADVTYPE_ADV_SCAN 6
236 
242 #define UB_ADV_CHAN_37 0x01
243 #define UB_ADV_CHAN_38 0x02
244 #define UB_ADV_CHAN_39 0x04
245 #define UB_ADV_CHAN_ALL (UB_ADV_CHAN_37 | UB_ADV_CHAN_38 | UB_ADV_CHAN_39)
246 
248 /* Min/Max for parameters */
249 #define UB_MIN_ADV_INTERVAL 160
250 #define UB_MAX_ADV_INTERVAL 16384
251 #define UB_MIN_CHANNEL_MAP UB_ADV_CHAN_37
252 #define UB_MAX_CHANNEL_MAP UB_ADV_CHAN_ALL
253 #define UB_MIN_TX_POWER TX_POWER_MINUS_21_DBM
254 #define UB_MAX_TX_POWER TX_POWER_5_DBM
255 
256 /* Default Parameter Values */
258 #define UB_PARAM_DFLT_RFPRIORITY RF_PRI_NORMAL
259 #define UB_PARAM_DFLT_RFTIMECRIT RF_TIME_RELAXED
260 #define UB_PARAM_DFLT_TXPOWER TX_POWER_0_DBM
261 #define UB_PARAM_DFLT_ADVINTERVAL 1600
262 #define UB_PARAM_DFLT_ADVCHANMAP UB_ADV_CHAN_ALL
263 #define UB_PARAM_DFLT_ADVTYPE UB_ADVTYPE_ADV_NC
264 #define UB_PARAM_DFLT_TIMETOADV 0
265 #define UB_PARAM_DFLT_ADVDATA {0}
266 #define UB_PARAM_DFLT_SCANRSPDATA {0}
267 #define UB_PARAM_DFLT_ADVFLTPOLICY 0
268 
270 
273 #define UB_EVTDST_LL 0
274 #define UB_EVTDST_GAP 1
275 #define UB_NUM_EVTDST 2
276 
280 /* 1 us = 4 RAT tick */
281 #define US_TO_RAT 4
282 /* 1 ms = 4000 RAT tick */
283 #define MS_TO_RAT 4000
284 /* 1 BLE tick(0.625 ms) = 2500 RAT tick */
285 #define BLE_TO_RAT 2500
286 /* 1 system tick = (Clock_tickPeriod * US_TO_RAT) RAT tick */
287 #define SYSTICK_TO_RAT (Clock_tickPeriod * US_TO_RAT)
288 /* 1 ms = (1000 / Clock_tickPeriod) system tick */
289 #define MS_TO_SYSTICK (1000 / Clock_tickPeriod)
290 
291 /* Length of ADV Data */
292 #define UB_MAX_ADVDATA_LEN B_MAX_ADV_LEN
293 
294 
296 /*-------------------------------------------------------------------
297  * TYPEDEFS
298  */
299 
305 typedef uint8 ubAddrType_t;
306 
308 typedef uint8 ubEvtDst_t;
309 
311 typedef uint8 ubEvt_t;
312 
315  Queue_Elem _elem;
316  ubEvtDst_t dst;
317  ubEvt_t evt;
318 } ubEvtHdr_t;
319 
321 typedef uint8 ubMsg_t;
322 
325  ubEvtHdr_t hdr;
326  ubMsg_t msg[];
327 } ubEvtMsg_t;
328 
342 typedef void (*ubPostEvtProxyCB_t)(void);
343 
347 typedef void (*ubProcessMsg_t)(ubEvtMsg_t *pEvtMsg);
348 
351 
354  uint8 rfPriority;
355  uint8 rfTimeCrit;
356  int8 txPower;
357  uint8 _dummy0;
358 #if defined(FEATURE_ADVERTISER)
359  uint16 advInterval;
360  uint8 advChanMap;
361  uint8 advType;
362  uint8 timeToAdv;
363  uint8 advData[UB_MAX_ADVDATA_LEN];
364 #if defined(FEATURE_SCAN_RESPONSE)
365  uint8 scanRspData[UB_MAX_ADVDATA_LEN];
366  uint8 advFltPolicy;
367 #endif /* FEATURE_SCAN_RESPONSE */
368 #endif /* FEATURE_ADVERTISER */
369 #if defined(FEATURE_SCANNER)
370  uint16 scanInterval;
371  uint16 scanWindow;
372  uint8 scanChanMap;
373  uint8 scanType;
374  uint8 fltDuplicate;
375  uint8 scanFltPolicy;
376 #endif /* FEATURE_SCANNER */
377 } ubParams_t;
378 
385  uint8 offset;
386  uint8 len;
387  uint8 min;
388  uint8 max;
389 } ubParamLookup_t;
391 
392 /*-------------------------------------------------------------------
393  * API FUNCTIONS
394  */
395 
422 bStatus_t ub_stackInit(ubAddrType_t addrType, uint8* pStaticAddr,
423  ubPostEvtProxyCB_t pfnPostEvtProxyCB);
424 
439 bStatus_t ub_setParameter(uint8 param, uint8 len, void *pValue);
440 
453 bStatus_t ub_getParameter(uint8 param, void *pValue);
454 
466 bStatus_t ub_checkAddr(ubAddrType_t addrType, uint8 *pAddr);
467 
472 void ub_resetAddr(void);
473 
484 bStatus_t ub_getAddr(ubAddrType_t addrType, uint8* pAddr);
485 
493 void ub_processMsg(void);
494 
495 /*-------------------------------------------------------------------
496 -------------------------------------------------------------------*/
497 
498 #ifdef __cplusplus
499 }
500 #endif
501 
502 #endif /* UBLE_H */
503 
void ub_resetAddr(void)
Make BD Addr revert to Random Static Address if exists or Public Address otherwise.
void(* ubProcessMsg_t)(ubEvtMsg_t *pEvtMsg)
Function to process event messages destined to the calle module.
Definition: uble.h:347
void(* ubPostEvtProxyCB_t)(void)
Type of the callback to have ub_processMsg called in the application task context.
Definition: uble.h:342
bStatus_t ub_checkAddr(ubAddrType_t addrType, uint8 *pAddr)
Check if the given address is valid.
bStatus_t ub_getParameter(uint8 param, void *pValue)
Get a Micro BLE Stack parameter.
bStatus_t ub_setParameter(uint8 param, uint8 len, void *pValue)
Set a Micro BLE Stack parameter.
PACKED_TYPEDEF_STRUCT
Type of Micro BLE Stack event header.
Definition: uble.h:314
#define UB_MAX_ADVDATA_LEN
Max Advertising Data Length.
Definition: uble.h:292
uint8 ubEvt_t
Micro BLE Stack Event.
Definition: uble.h:311
bStatus_t ub_stackInit(ubAddrType_t addrType, uint8 *pStaticAddr, ubPostEvtProxyCB_t pfnPostEvtProxyCB)
Initialize Micro BLE Stack.
uint8 ubAddrType_t
Address Type.
Definition: uble.h:305
uint8 ubMsg_t
Type of Micro BLE Stack message.
Definition: uble.h:321
void ub_processMsg(void)
Let the Micro Stack process the queued messages.
Status_t bStatus_t
BLE Generic Status return.
Definition: bcomdef.h:243
bStatus_t ub_getAddr(ubAddrType_t addrType, uint8 *pAddr)
Retrieve the address corresponding to the given address type.
uint8 ubEvtDst_t
Recipient of Micro BLE Stack Event.
Definition: uble.h:308
This file contains configurable variables for the Micro BLE Stack radio.
Copyright 2016, Texas Instruments Incorporated