TI BLE-Stack for Bluetooth API Documentation  3.03.08.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 
406 #define BLE_ROLE_PERIPHERAL 4
407 #define BLE_ROLE_CENTRAL 8
408 
411 /*-------------------------------------------------------------------
412  * TYPEDEFS
413  */
414 
420 typedef uint8 ubleAddrType_t;
421 
423 typedef uint8 ubleEvtDst_t;
424 
426 typedef uint8 ubleEvt_t;
427 
428 PACKED_TYPEDEF_STRUCT {
429  port_queueElem_t pElem;
430  ubleEvtDst_t dst;
431  ubleEvt_t evt;
432 } ubleEvtHdr_t;
433 
435 typedef uint8 ubleMsg_t;
436 
437 PACKED_TYPEDEF_STRUCT {
438  ubleEvtHdr_t hdr;
439  ubleMsg_t msg[];
440 } ubleEvtMsg_t;
441 
455 typedef void (*ublePostEvtProxyCB_t)(void);
456 
462 typedef void (*ubleAntSwitchCB_t)(void);
463 
467 typedef void (*ubleProcessMsg_t)(ubleEvtMsg_t *pEvtMsg);
468 
471 
473 PACKED_TYPEDEF_STRUCT {
474  uint8 rfPriority;
475  int8 txPower;
476 #if defined(FEATURE_ADVERTISER)
477  uint16 advInterval;
478  uint8 advChanMap;
479  uint8 advType;
480  uint8 timeToAdv;
481  uint8 advData[UBLE_MAX_ADVDATA_LEN];
482 #if defined(FEATURE_SCAN_RESPONSE)
483  uint8 scanRspData[UBLE_MAX_ADVDATA_LEN];
484  uint8 advFltPolicy;
485 #endif /* FEATURE_SCAN_RESPONSE */
486 #endif /* FEATURE_ADVERTISER */
487 #if defined(FEATURE_SCANNER)
488  uint16 scanInterval;
489  uint16 scanWindow;
490  uint8 scanChanMap;
491  uint8 scanType;
492  uint8 fltDuplicate;
493  uint8 scanFltPolicy;
494 #endif /* FEATURE_SCANNER */
495 #if defined(FEATURE_MONITOR)
496  uint8 monitorHandle;
497  uint8 monitorChan;
498  uint16 monitorDuration;
499  uint32 startTime;
500  uint32 accessAddr;
501  uint32 crcInit;
502 #endif /* FEATURE_MONITOR */
503 } ubleParams_t;
504 
510 PACKED_TYPEDEF_STRUCT {
511  uint8 offset;
512  uint8 len;
513  uint8 min;
514  uint8 max;
515 } ubParamLookup_t;
517 
518 /*-------------------------------------------------------------------
519  * API FUNCTIONS
520  */
521 
551 bStatus_t uble_stackInit(ubleAddrType_t addrType, uint8* pStaticAddr,
552  ublePostEvtProxyCB_t pfnPostEvtProxyCB, uint8 timeCritical);
553 
566 uint8 uble_timeCompare(uint32 time1, uint32 time2);
567 
577 uint32 uble_timeDelta(uint32 time1, uint32 time2);
578 
593 bStatus_t uble_setParameter(uint8 param, uint8 len, void *pValue);
594 
607 bStatus_t uble_getParameter(uint8 param, void *pValue);
608 
620 bStatus_t uble_checkAddr(ubleAddrType_t addrType, uint8 *pAddr);
621 
626 void uble_resetAddr(void);
627 
638 bStatus_t uble_getAddr(ubleAddrType_t addrType, uint8* pAddr);
639 
648 
656 void uble_processMsg(void);
657 
658 /*-------------------------------------------------------------------
659  * BLE_LOG FUNCTIONS
660  */
661 //#define BLE_LOG
662 #ifdef BLE_LOG
663 
664 #define BLE_LOG_MODULE_CTRL 0x01
665 #define BLE_LOG_MODULE_HOST 0x02
666 #define BLE_LOG_MODULE_APP 0x04
667 #define BLE_LOG_MODULE_OSAL_TASK 0x08
668 #define BLE_LOG_MODULE_RF_CMD 0x10
669 
670 void bleLog_int_int(void *handle, uint32_t type, uint8_t *format, uint32_t param1, uint32_t param2);
671 void bleLog_int_str(void *handle, uint32_t type, uint8_t *format, uint32_t param1, char *param2);
672 void bleLog_int_time(void *handle, uint32_t type, uint8_t *start_str, uint32_t param1);
673 
674 #define BLE_LOG_INT_INT(handle, type, format, param1, param2) bleLog_int_int(handle, type, format, param1, param2)
675 #define BLE_LOG_INT_STR(handle, type, format, param1, param2) bleLog_int_str(handle, type, format, param1, param2)
676 #define BLE_LOG_INT_TIME(handle, type, start_str, param1) bleLog_int_time(handle, type, start_str, param1)
677 #else
678 #define BLE_LOG_INT_INT(handle, type, format, param1, param2)
679 #define BLE_LOG_INT_STR(handle, type, format, param1, param2)
680 #define BLE_LOG_INT_TIME(handle, type, start_str, param1)
681 
682 #endif //BLE_LOG
683 
684 /*-------------------------------------------------------------------
685 -------------------------------------------------------------------*/
686 
687 #ifdef __cplusplus
688 }
689 #endif
690 
691 #endif /* UBLE_H */
692 
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:467
void(* ubleAntSwitchCB_t)(void)
Type of the callback to switch antenna in the application.
Definition: uble.h:462
#define UBLE_MAX_ADVDATA_LEN
Max Advertising Data Length.
Definition: uble.h:401
uint8 ubleEvt_t
Micro BLE Stack Event.
Definition: uble.h:426
uint32_t len
Image length in bytes.
Definition: oad_image_header.h:662
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:435
Status_t bStatus_t
BLE Generic Status return.
Definition: bcomdef.h:233
uint8 ubleEvtDst_t
Recipient of Micro BLE Stack Event.
Definition: uble.h:423
void(* ublePostEvtProxyCB_t)(void)
Type of the callback to have uble_processMsg called in the application task context.
Definition: uble.h:455
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:420
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.
uint32 uble_timeDelta(uint32 time1, uint32 time2)
This function determines the difference between two time parameters, taking timer counter wrap into a...
© Copyright 1995-2021, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale