TI BLE5-Stack API Documentation  3.02.01.00
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 
27 #ifndef UBLE_H
28 #define UBLE_H
29 
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34 
35 /*-------------------------------------------------------------------
36  * INCLUDES
37  */
38 #include <urfc.h>
39 #include <port.h>
40 
41 /*-------------------------------------------------------------------
42  * DEFINITIONS & CONSTANTS
43  */
44 
53  #define UBLE_PARAM_COMMON_START 0
55 
66  #define UBLE_PARAM_RFPRIORITY (UBLE_PARAM_COMMON_START+0)
67 
75  #define UBLE_PARAM_TXPOWER (UBLE_PARAM_COMMON_START+1)
76 
78  #define UBLE_PARAM_COMMON_END UBLE_PARAM_TXPOWER
79 #if defined(FEATURE_ADVERTISER)
81  #define UBLE_PARAM_ADV_CMN_START (UBLE_PARAM_COMMON_END+1)
83 
92  #define UBLE_PARAM_ADVINTERVAL (UBLE_PARAM_ADV_CMN_START+0)
93 
100  #define UBLE_PARAM_ADVCHANMAP (UBLE_PARAM_ADV_CMN_START+1)
101 
108  #define UBLE_PARAM_ADVTYPE (UBLE_PARAM_ADV_CMN_START+2)
109 
120  #define UBLE_PARAM_TIMETOADV (UBLE_PARAM_ADV_CMN_START+3)
121 
128  #define UBLE_PARAM_ADVDATA (UBLE_PARAM_ADV_CMN_START+4)
129 
131  #define UBLE_PARAM_ADV_CMN_END UBLE_PARAM_ADVDATA
132  #if defined(FEATURE_SCAN_RESPONSE)
134  #define UBLE_PARAM_ADV_SR_START (UBLE_PARAM_ADV_CMN_END+1)
136 
145  #define UBLE_PARAM_SCANRSPDATA (UBLE_PARAM_ADV_SR_START+0)
146 
155  #define UBLE_PARAM_ADVFLTPOLICY (UBLE_PARAM_ADV_SR_START+1)
156  #define UBLE_PARAM_ADV_SR_END UBLE_PARAM_ADVFLTPOLICY
158  #else /* FEATURE_SCAN_RESPONSE */
160  #define UBLE_PARAM_ADV_SR_END UBLE_PARAM_ADV_CMN_END
162  #endif /* FEATURE_SCAN_RESPONSE */
164 #else /* FEATURE_ADVERTISER */
165  #define UBLE_PARAM_ADV_SR_END UBLE_PARAM_COMMON_END
167 #endif /* FEATURE_ADVERTISER */
169 #if defined(FEATURE_SCANNER)
170  #define UBLE_PARAM_SCAN_START (UBLE_PARAM_ADV_SR_END+1)
172 
180  #define UBLE_PARAM_SCANINTERVAL (UBLE_PARAM_SCAN_START+0)
181 
188  #define UBLE_PARAM_SCANWINDOW (UBLE_PARAM_SCAN_START+1)
189 
196  #define UBLE_PARAM_SCANCHANMAP (UBLE_PARAM_SCAN_START+2)
197 
204  #define UBLE_PARAM_SCANTYPE (UBLE_PARAM_SCAN_START+3)
205 
212  #define UBLE_PARAM_FLTDUPLICATE (UBLE_PARAM_SCAN_START+4)
213 
220  #define UBLE_PARAM_SCANFLTPOLICY (UBLE_PARAM_SCAN_START+5)
221  #define UBLE_PARAM_SCAN_END UBLE_PARAM_SCANFLTPOLICY
223 #else /*FEATURE_SCANNER */
225  #define UBLE_PARAM_SCAN_END UBLE_PARAM_ADV_SR_END
227 #endif /* FEATURE_SCANNER */
229  #if defined(FEATURE_MONITOR)
230  #define UBLE_PARAM_MONITOR_START (UBLE_PARAM_ADV_SR_END+1)
232 
241  #define UBLE_PARAM_SESSIONID (UBLE_PARAM_MONITOR_START+0)
242 
249  #define UBLE_PARAM_MONITOR_CHAN (UBLE_PARAM_MONITOR_START+1)
250 
257  #define UBLE_PARAM_MONITOR_DURATION (UBLE_PARAM_MONITOR_START+2)
258 
265  #define UBLE_PARAM_MONITOR_START_TIME (UBLE_PARAM_MONITOR_START+3)
266 
273  #define UBLE_PARAM_MONITOR_ACCESS_ADDR (UBLE_PARAM_MONITOR_START+4)
274  #define UBLE_PARAM_MONITOR_END UBLE_PARAM_MONITOR_ACCESS_ADDR
276 #else /* FEATURE_MONITOR */
278  #define UBLE_PARAM_MONITOR_END UBLE_PARAM_ADV_SR_END
280 #endif /* FEATURE_MONITOR */
282  #define UBLE_NUM_PARAM (UBLE_PARAM_MONITOR_END+1)
284 
290 #define UBLE_RF_PRI_NORMAL ((uint8) RF_PriorityNormal)
291 #define UBLE_RF_PRI_HIGH ((uint8) RF_PriorityHigh)
292 #define UBLE_RF_PRI_HIGHEST ((uint8) RF_PriorityHighest)
293 
298 #define RF_TIME_RELAXED 0
299 #define RF_TIME_CRITICAL 1
300 
303 #define UBLE_TX_POWER_INVALID 0xFFFF
304 
308 #define UBLE_ADDRTYPE_PUBLIC 0
309 #define UBLE_ADDRTYPE_STATIC 1
310 #define UBLE_ADDRTYPE_NONRESOLVABLE 2
311 #define UBLE_ADDRTYPE_RESOLVABLE 3
312 #define UBLE_ADDRTYPE_BD 4
313 
318 #define UBLE_ADVTYPE_ADV_NC 5
319 #define UBLE_ADVTYPE_ADV_SCAN 6
320 
326 #define UBLE_ADV_CHAN_37 0x01
327 #define UBLE_ADV_CHAN_38 0x02
328 #define UBLE_ADV_CHAN_39 0x04
329 #define UBLE_ADV_CHAN_ALL (UBLE_ADV_CHAN_37 | UBLE_ADV_CHAN_38 | UBLE_ADV_CHAN_39)
330 
332 /* Min/Max for parameters */
333 #define UBLE_MIN_ADV_INTERVAL 160
334 #define UBLE_MAX_ADV_INTERVAL 16384
335 #define UBLE_MIN_CHANNEL_MAP UBLE_ADV_CHAN_37
336 #define UBLE_MAX_CHANNEL_MAP UBLE_ADV_CHAN_ALL
337 #define UBLE_MIN_TX_POWER TX_POWER_MINUS_21_DBM
338 #define UBLE_MAX_TX_POWER TX_POWER_5_DBM
339 #define UBLE_MIN_SCAN_INTERVAL 4
340 #define UBLE_MAX_SCAN_INTERVAL 16384
341 #define UBLE_MIN_SCAN_WINDOW 4
342 #define UBLE_MAX_SCAN_WINDOW 16384
343 #define UBLE_MIN_MONITOR_HANDLE 0
344 #define UBLE_MAX_MONITOR_HANDLE 8
345 #define UBLE_MIN_MONITOR_CHAN 0
346 #define UBLE_MAX_MONITOR_CHAN 39
347 #define UBLE_MIN_MONITOR_DURATION 0
348 #define UBLE_MAX_MONITOR_DURATION 64000
349 
350 /* Default Parameter Values */
351 #define UBLE_PARAM_DFLT_RFPRIORITY UBLE_RF_PRI_NORMAL
352 #define UBLE_PARAM_DFLT_RFTIMECRIT RF_TIME_RELAXED
353 #define UBLE_PARAM_DFLT_TXPOWER TX_POWER_0_DBM
354 #define UBLE_PARAM_DFLT_ADVINTERVAL 1600
355 #define UBLE_PARAM_DFLT_ADVCHANMAP UBLE_ADV_CHAN_ALL
356 #define UBLE_PARAM_DFLT_ADVTYPE UBLE_ADVTYPE_ADV_NC
357 #define UBLE_PARAM_DFLT_TIMETOADV 0
358 #define UBLE_PARAM_DFLT_ADVDATA {0}
359 #define UBLE_PARAM_DFLT_SCANRSPDATA {0}
360 #define UBLE_PARAM_DFLT_ADVFLTPOLICY 0
361 #define UBLE_PARAM_DFLT_SCANINTERVAL 16
362 #define UBLE_PARAM_DFLT_SCANWINDOW 16
363 #define UBLE_PARAM_DFLT_SCANCHAN UBLE_ADV_CHAN_ALL
364 #define UBLE_PARAM_DFLT_SCANTYPE 0
365 #define UBLE_PARAM_DFLT_FLTDUPLICATE 0
366 #define UBLE_PARAM_DFLT_SCANFLTPOLICY 0
367 #define UBLE_PARAM_DFLT_MONITOR_HANDLE 0
368 #define UBLE_PARAM_DFLT_MONITOR_CHAN 37
369 #define UBLE_PARAM_DFLT_MONITOR_DURATION 320
370 #define UBLE_PARAM_DFLT_MONITOR_START_TIME 6400
371 #define UBLE_PARAM_DFLT_MONITOR_ACCESS_ADDR 0x8E89BED6
372 #define UBLE_PARAM_DFLT_MONITOR_CRCINIT 0x555555
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 #define UBLE_MAX_OVERLAP_TIME_LIMIT 0x7270E000 // 8 minutes in 625us ticks. chosen to be half of 17 minutes RF overlap.
404 #define UBLE_MAX_32BIT_TIME 0xFFFFFFFF
405 
408 /*-------------------------------------------------------------------
409  * TYPEDEFS
410  */
411 
417 typedef uint8 ubleAddrType_t;
418 
420 typedef uint8 ubleEvtDst_t;
421 
423 typedef uint8 ubleEvt_t;
424 
425 PACKED_TYPEDEF_STRUCT {
426  port_queueElem_t pElem;
427  ubleEvtDst_t dst;
428  ubleEvt_t evt;
429 } ubleEvtHdr_t;
430 
432 typedef uint8 ubleMsg_t;
433 
434 PACKED_TYPEDEF_STRUCT {
435  ubleEvtHdr_t hdr;
436  ubleMsg_t msg[];
437 } ubleEvtMsg_t;
438 
452 typedef void (*ublePostEvtProxyCB_t)(void);
453 
459 typedef void (*ubleAntSwitchCB_t)(void);
460 
464 typedef void (*ubleProcessMsg_t)(ubleEvtMsg_t *pEvtMsg);
465 
468 
470 PACKED_TYPEDEF_STRUCT {
471  uint8 rfPriority;
472  int8 txPower;
473 #if defined(FEATURE_ADVERTISER)
474  uint16 advInterval;
475  uint8 advChanMap;
476  uint8 advType;
477  uint8 timeToAdv;
478  uint8 advData[UBLE_MAX_ADVDATA_LEN];
479 #if defined(FEATURE_SCAN_RESPONSE)
480  uint8 scanRspData[UBLE_MAX_ADVDATA_LEN];
481  uint8 advFltPolicy;
482 #endif /* FEATURE_SCAN_RESPONSE */
483 #endif /* FEATURE_ADVERTISER */
484 #if defined(FEATURE_SCANNER)
485  uint16 scanInterval;
486  uint16 scanWindow;
487  uint8 scanChanMap;
488  uint8 scanType;
489  uint8 fltDuplicate;
490  uint8 scanFltPolicy;
491 #endif /* FEATURE_SCANNER */
492 #if defined(FEATURE_MONITOR)
493  uint8 monitorHandle;
494  uint8 monitorChan;
495  uint16 monitorDuration;
496  uint32 startTime;
497  uint32 accessAddr;
498  uint32 crcInit;
499 #endif /* FEATURE_MONITOR */
500 } ubleParams_t;
501 
507 PACKED_TYPEDEF_STRUCT {
508  uint8 offset;
509  uint8 len;
510  uint8 min;
511  uint8 max;
512 } ubParamLookup_t;
514 
515 /*-------------------------------------------------------------------
516  * API FUNCTIONS
517  */
518 
548 bStatus_t uble_stackInit(ubleAddrType_t addrType, uint8* pStaticAddr,
549  ublePostEvtProxyCB_t pfnPostEvtProxyCB, uint8 timeCritical);
550 
563 uint8 uble_timeCompare(uint32 time1, uint32 time2);
564 
574 uint32 uble_timeDelta(uint32 time1, uint32 time2);
575 
590 bStatus_t uble_setParameter(uint8 param, uint8 len, void *pValue);
591 
604 bStatus_t uble_getParameter(uint8 param, void *pValue);
605 
617 bStatus_t uble_checkAddr(ubleAddrType_t addrType, uint8 *pAddr);
618 
623 void uble_resetAddr(void);
624 
635 bStatus_t uble_getAddr(ubleAddrType_t addrType, uint8* pAddr);
636 
645 
653 void uble_processMsg(void);
654 
655 /*-------------------------------------------------------------------
656  * BLE_LOG FUNCTIONS
657  */
658 //#define BLE_LOG
659 #ifdef BLE_LOG
660 
661 #define BLE_LOG_MODULE_CTRL 0x01
662 #define BLE_LOG_MODULE_HOST 0x02
663 #define BLE_LOG_MODULE_APP 0x04
664 #define BLE_LOG_MODULE_OSAL_TASK 0x08
665 #define BLE_LOG_MODULE_RF_CMD 0x10
666 
667 void bleLog_int_int(void *handle, uint32_t type, uint8_t *format, uint32_t param1, uint32_t param2);
668 void bleLog_int_str(void *handle, uint32_t type, uint8_t *format, uint32_t param1, char *param2);
669 void bleLog_int_time(void *handle, uint32_t type, uint8_t *start_str, uint32_t param1);
670 
671 #define BLE_LOG_INT_INT(handle, type, format, param1, param2) bleLog_int_int(handle, type, format, param1, param2)
672 #define BLE_LOG_INT_STR(handle, type, format, param1, param2) bleLog_int_str(handle, type, format, param1, param2)
673 #define BLE_LOG_INT_TIME(handle, type, start_str, param1) bleLog_int_time(handle, type, start_str, param1)
674 #else
675 #define BLE_LOG_INT_INT(handle, type, format, param1, param2)
676 #define BLE_LOG_INT_STR(handle, type, format, param1, param2)
677 #define BLE_LOG_INT_TIME(handle, type, start_str, param1)
678 
679 #endif //BLE_LOG
680 
681 /*-------------------------------------------------------------------
682 -------------------------------------------------------------------*/
683 
684 #ifdef __cplusplus
685 }
686 #endif
687 
688 #endif /* UBLE_H */
689 
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:464
void(* ubleAntSwitchCB_t)(void)
Type of the callback to switch antenna in the application.
Definition: uble.h:459
#define UBLE_MAX_ADVDATA_LEN
Max Advertising Data Length.
Definition: uble.h:401
uint8 ubleEvt_t
Micro BLE Stack Event.
Definition: uble.h:423
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:432
Status_t bStatus_t
BLE Generic Status return.
Definition: bcomdef.h:251
uint8 ubleEvtDst_t
Recipient of Micro BLE Stack Event.
Definition: uble.h:420
void(* ublePostEvtProxyCB_t)(void)
Type of the callback to have uble_processMsg called in the application task context.
Definition: uble.h:452
uint8 uble_timeCompare(uint32 time1, uint32 time2)
This function determines if the first time parameter is greater than the second time parameter...
uint8 ubleAddrType_t
Address Type.
Definition: uble.h:417
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.
uint32 uble_timeDelta(uint32 time1, uint32 time2)
This function determines the difference between two time parameters, taking timer counter wrap into a...
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale