TI BLE-Stack for Bluetooth 4.2 API Documentation  3.01.00.07
uble.h
Go to the documentation of this file.
1 /******************************************************************************
2 
3  Group: WCS, BTS
4  $Target Device: DEVICES $
5 
6  ******************************************************************************
7  $License: TISD 2009 $
8  ******************************************************************************
9  $Release Name: PACKAGE NAME $
10  $Release Date: PACKAGE RELEASE DATE $
11  *****************************************************************************/
12 
28 #ifndef UBLE_H
29 #define UBLE_H
30 
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35 
36 /*-------------------------------------------------------------------
37  * INCLUDES
38  */
39 #include <urfc.h>
40 #include <port.h>
41 
42 /*-------------------------------------------------------------------
43  * DEFINITIONS & CONSTANTS
44  */
45 
54  #define UBLE_PARAM_COMMON_START 0
56 
67  #define UBLE_PARAM_RFPRIORITY (UBLE_PARAM_COMMON_START+0)
68 
76  #define UBLE_PARAM_TXPOWER (UBLE_PARAM_COMMON_START+1)
77 
79  #define UBLE_PARAM_COMMON_END UBLE_PARAM_TXPOWER
80 #if defined(FEATURE_ADVERTISER)
82  #define UBLE_PARAM_ADV_CMN_START (UBLE_PARAM_COMMON_END+1)
84 
93  #define UBLE_PARAM_ADVINTERVAL (UBLE_PARAM_ADV_CMN_START+0)
94 
101  #define UBLE_PARAM_ADVCHANMAP (UBLE_PARAM_ADV_CMN_START+1)
102 
109  #define UBLE_PARAM_ADVTYPE (UBLE_PARAM_ADV_CMN_START+2)
110 
121  #define UBLE_PARAM_TIMETOADV (UBLE_PARAM_ADV_CMN_START+3)
122 
129  #define UBLE_PARAM_ADVDATA (UBLE_PARAM_ADV_CMN_START+4)
130 
132  #define UBLE_PARAM_ADV_CMN_END UBLE_PARAM_ADVDATA
133  #if defined(FEATURE_SCAN_RESPONSE)
135  #define UBLE_PARAM_ADV_SR_START (UBLE_PARAM_ADV_CMN_END+1)
137 
146  #define UBLE_PARAM_SCANRSPDATA (UBLE_PARAM_ADV_SR_START+0)
147 
156  #define UBLE_PARAM_ADVFLTPOLICY (UBLE_PARAM_ADV_SR_START+1)
157  #define UBLE_PARAM_ADV_SR_END UBLE_PARAM_ADVFLTPOLICY
159  #else /* FEATURE_SCAN_RESPONSE */
161  #define UBLE_PARAM_ADV_SR_END UBLE_PARAM_ADV_CMN_END
163  #endif /* FEATURE_SCAN_RESPONSE */
165 #else /* FEATURE_ADVERTISER */
166  #define UBLE_PARAM_ADV_SR_END UBLE_PARAM_COMMON_END
168 #endif /* FEATURE_ADVERTISER */
170 #if defined(FEATURE_SCANNER)
171  #define UBLE_PARAM_SCAN_START (UBLE_PARAM_ADV_SR_END+1)
173 
181  #define UBLE_PARAM_SCANINTERVAL (UBLE_PARAM_SCAN_START+0)
182 
189  #define UBLE_PARAM_SCANWINDOW (UBLE_PARAM_SCAN_START+1)
190 
197  #define UBLE_PARAM_SCANCHANMAP (UBLE_PARAM_SCAN_START+2)
198 
205  #define UBLE_PARAM_SCANTYPE (UBLE_PARAM_SCAN_START+3)
206 
213  #define UBLE_PARAM_FLTDUPLICATE (UBLE_PARAM_SCAN_START+4)
214 
221  #define UBLE_PARAM_SCANFLTPOLICY (UBLE_PARAM_SCAN_START+5)
222  #define UBLE_PARAM_SCAN_END UBLE_PARAM_SCANFLTPOLICY
224 #else /*FEATURE_SCANNER */
226  #define UBLE_PARAM_SCAN_END UBLE_PARAM_ADV_SR_END
228 #endif /* FEATURE_SCANNER */
230  #if defined(FEATURE_MONITOR)
231  #define UBLE_PARAM_MONITOR_START (UBLE_PARAM_ADV_SR_END+1)
233 
242  #define UBLE_PARAM_SESSIONID (UBLE_PARAM_MONITOR_START+0)
243 
250  #define UBLE_PARAM_MONITOR_CHAN (UBLE_PARAM_MONITOR_START+1)
251 
258  #define UBLE_PARAM_MONITOR_DURATION (UBLE_PARAM_MONITOR_START+2)
259 
266  #define UBLE_PARAM_MONITOR_START_TIME (UBLE_PARAM_MONITOR_START+3)
267 
274  #define UBLE_PARAM_MONITOR_ACCESS_ADDR (UBLE_PARAM_MONITOR_START+4)
275  #define UBLE_PARAM_MONITOR_END UBLE_PARAM_MONITOR_ACCESS_ADDR
277 #else /* FEATURE_MONITOR */
279  #define UBLE_PARAM_MONITOR_END UBLE_PARAM_ADV_SR_END
281 #endif /* FEATURE_MONITOR */
283  #define UBLE_NUM_PARAM (UBLE_PARAM_MONITOR_END+1)
285 
291 #define UBLE_RF_PRI_NORMAL ((uint8) RF_PriorityNormal)
292 #define UBLE_RF_PRI_HIGH ((uint8) RF_PriorityHigh)
293 #define UBLE_RF_PRI_HIGHEST ((uint8) RF_PriorityHighest)
294 
299 #define RF_TIME_RELAXED 0
300 #define RF_TIME_CRITICAL 1
301 
304 #define UBLE_TX_POWER_INVALID 0xFFFF
305 
309 #define UBLE_ADDRTYPE_PUBLIC 0
310 #define UBLE_ADDRTYPE_STATIC 1
311 #define UBLE_ADDRTYPE_NONRESOLVABLE 2
312 #define UBLE_ADDRTYPE_RESOLVABLE 3
313 #define UBLE_ADDRTYPE_BD 4
314 
319 #define UBLE_ADVTYPE_ADV_NC 5
320 #define UBLE_ADVTYPE_ADV_SCAN 6
321 
327 #define UBLE_ADV_CHAN_37 0x01
328 #define UBLE_ADV_CHAN_38 0x02
329 #define UBLE_ADV_CHAN_39 0x04
330 #define UBLE_ADV_CHAN_ALL (UBLE_ADV_CHAN_37 | UBLE_ADV_CHAN_38 | UBLE_ADV_CHAN_39)
331 
333 /* Min/Max for parameters */
334 #define UBLE_MIN_ADV_INTERVAL 160
335 #define UBLE_MAX_ADV_INTERVAL 16384
336 #define UBLE_MIN_CHANNEL_MAP UBLE_ADV_CHAN_37
337 #define UBLE_MAX_CHANNEL_MAP UBLE_ADV_CHAN_ALL
338 #define UBLE_MIN_TX_POWER TX_POWER_MINUS_21_DBM
339 #define UBLE_MAX_TX_POWER TX_POWER_5_DBM
340 #define UBLE_MIN_SCAN_INTERVAL 4
341 #define UBLE_MAX_SCAN_INTERVAL 16384
342 #define UBLE_MIN_SCAN_WINDOW 4
343 #define UBLE_MAX_SCAN_WINDOW 16384
344 #define UBLE_MIN_MONITOR_HANDLE 0
345 #define UBLE_MAX_MONITOR_HANDLE 4
346 #define UBLE_MIN_MONITOR_CHAN 0
347 #define UBLE_MAX_MONITOR_CHAN 39
348 #define UBLE_MIN_MONITOR_DURATION 0
349 #define UBLE_MAX_MONITOR_DURATION 64000
350 
351 /* Default Parameter Values */
352 #define UBLE_PARAM_DFLT_RFPRIORITY UBLE_RF_PRI_NORMAL
353 #define UBLE_PARAM_DFLT_RFTIMECRIT RF_TIME_RELAXED
354 #define UBLE_PARAM_DFLT_TXPOWER TX_POWER_0_DBM
355 #define UBLE_PARAM_DFLT_ADVINTERVAL 1600
356 #define UBLE_PARAM_DFLT_ADVCHANMAP UBLE_ADV_CHAN_ALL
357 #define UBLE_PARAM_DFLT_ADVTYPE UBLE_ADVTYPE_ADV_NC
358 #define UBLE_PARAM_DFLT_TIMETOADV 0
359 #define UBLE_PARAM_DFLT_ADVDATA {0}
360 #define UBLE_PARAM_DFLT_SCANRSPDATA {0}
361 #define UBLE_PARAM_DFLT_ADVFLTPOLICY 0
362 #define UBLE_PARAM_DFLT_SCANINTERVAL 16
363 #define UBLE_PARAM_DFLT_SCANWINDOW 16
364 #define UBLE_PARAM_DFLT_SCANCHAN UBLE_ADV_CHAN_ALL
365 #define UBLE_PARAM_DFLT_SCANTYPE 0
366 #define UBLE_PARAM_DFLT_FLTDUPLICATE 0
367 #define UBLE_PARAM_DFLT_SCANFLTPOLICY 0
368 #define UBLE_PARAM_DFLT_MONITOR_HANDLE 0
369 #define UBLE_PARAM_DFLT_MONITOR_CHAN 37
370 #define UBLE_PARAM_DFLT_MONITOR_DURATION 320
371 #define UBLE_PARAM_DFLT_MONITOR_START_TIME 6400
372 #define UBLE_PARAM_DFLT_MONITOR_ACCESS_ADDR 0x8E89BED6
373 
374 
378 #define UBLE_EVTDST_LL 0
379 #define UBLE_EVTDST_GAP 1
380 #define UBLE_NUM_EVTDST 2
381 
382 
386 #define US_TO_RAT 4
387 
388 #define MS_TO_RAT 4000
389 
390 #define BLE_TO_RAT 2500
391 
392 #define SYSTICK_TO_RAT (Clock_tickPeriod * US_TO_RAT)
393 
394 #define MS_TO_SYSTICK (1000 / Clock_tickPeriod)
395 
396 #define BLE_TO_SYSTICK (625 / Clock_tickPeriod)
397 
398 #define BYTE_TO_RAT (8 * US_TO_RAT)
399 
400 /* Length of ADV Data */
401 #define UBLE_MAX_ADVDATA_LEN B_MAX_ADV_LEN
402 
403 
405 /*-------------------------------------------------------------------
406  * TYPEDEFS
407  */
408 
414 typedef uint8 ubleAddrType_t;
415 
417 typedef uint8 ubleEvtDst_t;
418 
420 typedef uint8 ubleEvt_t;
421 
422 PACKED_TYPEDEF_STRUCT {
423  port_queueElem_t pElem;
424  ubleEvtDst_t dst;
425  ubleEvt_t evt;
426 } ubleEvtHdr_t;
427 
429 typedef uint8 ubleMsg_t;
430 
431 PACKED_TYPEDEF_STRUCT {
432  ubleEvtHdr_t hdr;
433  ubleMsg_t msg[];
434 } ubleEvtMsg_t;
435 
449 typedef void (*ublePostEvtProxyCB_t)(void);
450 
456 typedef void (*ubleAntSwitchCB_t)(void);
457 
461 typedef void (*ubleProcessMsg_t)(ubleEvtMsg_t *pEvtMsg);
462 
465 
467 PACKED_TYPEDEF_STRUCT {
468  uint8 rfPriority;
469  int8 txPower;
470 #if defined(FEATURE_ADVERTISER)
471  uint16 advInterval;
472  uint8 advChanMap;
473  uint8 advType;
474  uint8 timeToAdv;
475  uint8 advData[UBLE_MAX_ADVDATA_LEN];
476 #if defined(FEATURE_SCAN_RESPONSE)
477  uint8 scanRspData[UBLE_MAX_ADVDATA_LEN];
478  uint8 advFltPolicy;
479 #endif /* FEATURE_SCAN_RESPONSE */
480 #endif /* FEATURE_ADVERTISER */
481 #if defined(FEATURE_SCANNER)
482  uint16 scanInterval;
483  uint16 scanWindow;
484  uint8 scanChanMap;
485  uint8 scanType;
486  uint8 fltDuplicate;
487  uint8 scanFltPolicy;
488 #endif /* FEATURE_SCANNER */
489 #if defined(FEATURE_MONITOR)
490  uint8 monitorHandle;
491  uint8 monitorChan;
492  uint16 monitorDuration;
493  uint32 startTime;
494  uint32 accessAddr;
495 #endif /* FEATURE_MONITOR */
496 } ubleParams_t;
497 
503 PACKED_TYPEDEF_STRUCT {
504  uint8 offset;
505  uint8 len;
506  uint8 min;
507  uint8 max;
508 } ubParamLookup_t;
510 
511 /*-------------------------------------------------------------------
512  * API FUNCTIONS
513  */
514 
544 bStatus_t uble_stackInit(ubleAddrType_t addrType, uint8* pStaticAddr,
545  ublePostEvtProxyCB_t pfnPostEvtProxyCB, uint8 timeCritical);
546 
561 bStatus_t uble_setParameter(uint8 param, uint8 len, void *pValue);
562 
575 bStatus_t uble_getParameter(uint8 param, void *pValue);
576 
588 bStatus_t uble_checkAddr(ubleAddrType_t addrType, uint8 *pAddr);
589 
594 void uble_resetAddr(void);
595 
606 bStatus_t uble_getAddr(ubleAddrType_t addrType, uint8* pAddr);
607 
616 
624 void uble_processMsg(void);
625 
626 /*-------------------------------------------------------------------
627 -------------------------------------------------------------------*/
628 
629 #ifdef __cplusplus
630 }
631 #endif
632 
633 #endif /* UBLE_H */
634 
void uble_processMsg(void)
Let the Micro Stack process the queued messages.
bStatus_t uble_registerAntSwitchCB(ubleAntSwitchCB_t pfnAntSwitchCB)
Register callback for antenna switch.
void uble_resetAddr(void)
Make BD Addr revert to Random Static Address if exists or Public Address otherwise.
bStatus_t uble_stackInit(ubleAddrType_t addrType, uint8 *pStaticAddr, ublePostEvtProxyCB_t pfnPostEvtProxyCB, uint8 timeCritical)
Initialize Micro BLE Stack.
bStatus_t uble_getParameter(uint8 param, void *pValue)
Get a Micro BLE Stack parameter.
void(* ubleProcessMsg_t)(ubleEvtMsg_t *pEvtMsg)
Function to process event messages destined to the calle module.
Definition: uble.h:461
void(* ubleAntSwitchCB_t)(void)
Type of the callback to switch antenna in the application.
Definition: uble.h:456
#define UBLE_MAX_ADVDATA_LEN
Max Advertising Data Length.
Definition: uble.h:401
uint8 ubleEvt_t
Micro BLE Stack Event.
Definition: uble.h:420
bStatus_t uble_setParameter(uint8 param, uint8 len, void *pValue)
Set a Micro BLE Stack parameter.
uint8 ubleMsg_t
Type of Micro BLE Stack message.
Definition: uble.h:429
Status_t bStatus_t
BLE Generic Status return.
Definition: bcomdef.h:227
uint8 ubleEvtDst_t
Recipient of Micro BLE Stack Event.
Definition: uble.h:417
void(* ublePostEvtProxyCB_t)(void)
Type of the callback to have uble_processMsg called in the application task context.
Definition: uble.h:449
uint8 ubleAddrType_t
Address Type.
Definition: uble.h:414
bStatus_t uble_getAddr(ubleAddrType_t addrType, uint8 *pAddr)
Retrieve the address corresponding to the given address type.
bStatus_t uble_checkAddr(ubleAddrType_t addrType, uint8 *pAddr)
Check if the given address is valid.
This file contains configurable variables for the Micro BLE Stack radio.
Copyright 2017, Texas Instruments Incorporated