bcomdef.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /**
  2. * @file
  3. * @author chipsea
  4. * @brief
  5. * @version 0.1
  6. * @date 2020-11-30
  7. * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
  8. * @note
  9. */
  10. /**
  11. @headerfile: bcomdef.h
  12. <!--
  13. Revised:
  14. Revision:
  15. Description: Type definitions and macros for BLE stack.
  16. -->
  17. **************************************************************************************************/
  18. #ifndef BCOMDEF_H
  19. #define BCOMDEF_H
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. /*********************************************************************
  25. * INCLUDES
  26. */
  27. #include "rom_sym_def.h"
  28. #include "comdef.h"
  29. #include "log.h"
  30. //#define LOG_DEBUG(...)
  31. //#define LOG(...)
  32. //#define OM_LOG(...)
  33. /*********************************************************************
  34. * CONSTANTS
  35. */
  36. //#define DBG_SPI_USE
  37. #ifdef DBG_SPI_USE
  38. void dbg_spi_init(AP_SSI_TypeDef* SPIx);
  39. void dbg_spi_out_buf(uint8_t connId, uint8_t *buf, uint8_t len);
  40. #define DBG_GPIO_WRITE(a,b) gpio_write((a),(b))
  41. #define DBG_HW_TRIG 0xC0
  42. #define DBG_ISR_ENTRY 0xC1
  43. #define DBG_RX_TIMEOUT 0xC2
  44. #define DBG_CRC_OK 0xC3
  45. #define DBG_ISR_EXIT 0xC4
  46. #define DBG_MASTER_ISR 0xA0
  47. #define DBG_SLAVE_ISR 0xB0
  48. #define DBG_ADV_ISR 0x90
  49. #define DBG_ADV_SCAN_RSP_ISR 0x91
  50. #define DBG_SCAN_TRX_ISR 0x80
  51. #define DBG_SCAN_RX_ISR 0x70
  52. #define DBG_CUSTOM_RF_ISR 0x60
  53. #define DBG_SPI_INIT() dbg_spi_init(AP_SPI1)
  54. #define DBG_CONN_OUT_BUF(connId, buf, len) dbg_spi_out_buf(connId, buf, len)
  55. #define DBG_SPI_OUT(x) //AP_SPI1->DataReg=x
  56. #define DBGIO_LL_TRIG P14
  57. #define DBGIO_LL_IRQ P15
  58. #define DBGIO_APP_WAKEUP P18
  59. #define DBGIO_APP_SLEEP P26
  60. #define DBGIO_LL_SCHEDULE P27
  61. #else
  62. #define DBG_SPI_INIT()
  63. #define DBG_CONN_OUT_BUF(connId, buf, len)
  64. #define DBG_SPI_OUT(x)
  65. #define DBG_GPIO_WRITE(a,b)
  66. #endif
  67. //#define ADV_NCONN_CFG 0x01
  68. //#define ADV_CONN_CFG 0x02
  69. //#define SCAN_CFG 0x04
  70. //#define INIT_CFG 0x08
  71. //#define BROADCASTER_CFG 0x01
  72. //#define OBSERVER_CFG 0x02
  73. //#define PERIPHERAL_CFG 0x04
  74. //#define CENTRAL_CFG 0x08
  75. #define CTRL_CONFIG ( ADV_NCONN_CFG | ADV_CONN_CFG | SCAN_CFG | INIT_CFG )
  76. //#if defined ( HOST_CONFIG )
  77. // // Set the Controller Configuration
  78. /*
  79. // #if ( HOST_CONFIG == ( CENTRAL_CFG | PERIPHERAL_CFG ) )
  80. // #define CTRL_CONFIG ( ADV_NCONN_CFG | ADV_CONN_CFG | SCAN_CFG | INIT_CFG )
  81. // #elif ( HOST_CONFIG == ( CENTRAL_CFG | BROADCASTER_CFG ) )
  82. // #define CTRL_CONFIG ( ADV_NCONN_CFG | SCAN_CFG | INIT_CFG )
  83. // #elif ( HOST_CONFIG == ( PERIPHERAL_CFG | OBSERVER_CFG ) )
  84. // #define CTRL_CONFIG ( ADV_NCONN_CFG | ADV_CONN_CFG | SCAN_CFG )
  85. // #elif ( HOST_CONFIG == ( BROADCASTER_CFG | OBSERVER_CFG ) )
  86. // #define CTRL_CONFIG ( ADV_NCONN_CFG | SCAN_CFG )
  87. // #elif ( HOST_CONFIG == CENTRAL_CFG )
  88. // #define CTRL_CONFIG ( SCAN_CFG | INIT_CFG )
  89. // #elif ( HOST_CONFIG == PERIPHERAL_CFG )
  90. // #define CTRL_CONFIG ( ADV_NCONN_CFG | ADV_CONN_CFG )
  91. // #elif ( HOST_CONFIG == OBSERVER_CFG )
  92. // #define CTRL_CONFIG SCAN_CFG
  93. // #elif ( HOST_CONFIG == BROADCASTER_CFG )
  94. // #define CTRL_CONFIG ADV_NCONN_CFG
  95. // #else
  96. // #error "Build Configuration Error: Invalid Host Role!"
  97. // #endif
  98. //#else
  99. // // Controller Sanity Check: Stop build when no configuration is defined.
  100. // #if !defined( CTRL_CONFIG ) || !( CTRL_CONFIG & ( ADV_NCONN_CFG | \
  101. // ADV_CONN_CFG | \
  102. // SCAN_CFG | \
  103. // INIT_CFG ) )
  104. // #error "Build Configuration Error: At least one Controller build component required!"
  105. // #endif // no Controller build components defined
  106. //#endif
  107. */
  108. #if !defined ( MAX_NUM_LL_CONN )
  109. #if ( CTRL_CONFIG & INIT_CFG )
  110. #define MAX_NUM_LL_CONN 6
  111. #elif ( !( CTRL_CONFIG & INIT_CFG ) && ( CTRL_CONFIG & ADV_CONN_CFG ) )
  112. #define MAX_NUM_LL_CONN 1
  113. #else // no connection needed
  114. #define MAX_NUM_LL_CONN 0
  115. #endif // CTRL_CONFIG=INIT_CFG
  116. #endif // !MAX_NUM_LL_CONN
  117. #define MAX_NUM_LL_CONN_ROM_LIMT 16 //hard code for BBB ROM define
  118. #if (MAX_NUM_LL_CONN_ROM_LIMT<MAX_NUM_LL_CONN)
  119. #warning "MAX_NUM_LL_CONN > MAX_NUM_LL_CONN_ROM"
  120. #endif
  121. /** @defgroup BLE_COMMON_DEFINES BLE Common Defines
  122. * @{
  123. */
  124. //! Default Public and Random Address Length
  125. #define B_ADDR_LEN 6
  126. //! Default key length
  127. #define KEYLEN 16
  128. //! BLE Channel Map length
  129. #define B_CHANNEL_MAP_LEN 5
  130. //! BLE Event mask length
  131. #define B_EVENT_MASK_LEN 8
  132. //! BLE Local Name length
  133. #define B_LOCAL_NAME_LEN 248
  134. //! BLE Maximum Advertising Packet Length
  135. #define B_MAX_ADV_LEN 31
  136. #define B_MAX_EXT_ADV_LEN 229
  137. #define B_MAX_PERIOD_ADV_LEN 247
  138. // 2020-01-14 AOA/AOD IQ Sample LEN
  139. #define B_MAX_IQ_LEN 0x52
  140. //! BLE Random Number Size
  141. #define B_RANDOM_NUM_SIZE 8
  142. //! BLE Feature Supported length
  143. #define B_FEATURE_SUPPORT_LENGTH 8
  144. /** @defgroup BLE_STATUS_VALUES BLE Default BLE Status Values
  145. * returned as bStatus_t
  146. * @{
  147. */
  148. #define bleInvalidTaskID INVALID_TASK //!< Task ID isn't setup properly
  149. #define bleNotReady 0x10 //!< Not ready to perform task
  150. #define bleAlreadyInRequestedMode 0x11 //!< Already performing that task
  151. #define bleIncorrectMode 0x12 //!< Not setup properly to perform that task
  152. #define bleMemAllocError 0x13 //!< Memory allocation error occurred
  153. #define bleNotConnected 0x14 //!< Can't perform function when not in a connection
  154. #define bleNoResources 0x15 //!< There are no resource available
  155. #define blePending 0x16 //!< Waiting
  156. #define bleTimeout 0x17 //!< Timed out performing function
  157. #define bleInvalidRange 0x18 //!< A parameter is out of range
  158. #define bleLinkEncrypted 0x19 //!< The link is already encrypted
  159. #define bleProcedureComplete 0x1A //!< The Procedure is completed
  160. // GAP Status Return Values - returned as bStatus_t
  161. #define bleGAPUserCanceled 0x30 //!< The user canceled the task
  162. #define bleGAPConnNotAcceptable 0x31 //!< The connection was not accepted
  163. #define bleGAPBondRejected 0x32 //!< The bound information was rejected.
  164. // ATT Status Return Values - returned as bStatus_t
  165. #define bleInvalidPDU 0x40 //!< The attribute PDU is invalid
  166. #define bleInsufficientAuthen 0x41 //!< The attribute has insufficient authentication
  167. #define bleInsufficientEncrypt 0x42 //!< The attribute has insufficient encryption
  168. #define bleInsufficientKeySize 0x43 //!< The attribute has insufficient encryption key size
  169. // L2CAP Status Return Values - returned as bStatus_t
  170. #define INVALID_TASK_ID 0xFF //!< Task ID isn't setup properly
  171. /** @} End BLE_STATUS_VALUES */
  172. /** @defgroup BLE_NV_IDS BLE Non-volatile IDs
  173. * @{
  174. */
  175. // Device NV Items - Range 0 - 0x1F
  176. #define BLE_NVID_IRK 0x02 //!< The Device's IRK
  177. #define BLE_NVID_CSRK 0x03 //!< The Device's CSRK
  178. #define BLE_NVID_SIGNCOUNTER 0x04 //!< The Device's Sign Counter
  179. // Bonding NV Items - Range 0x20 - 0x5F - This allows for 10 bondings
  180. #define BLE_NVID_GAP_BOND_START 0x20 //!< Start of the GAP Bond Manager's NV IDs
  181. #define BLE_NVID_GAP_BOND_END 0x5f //!< End of the GAP Bond Manager's NV IDs Range
  182. // GATT Configuration NV Items - Range 0x70 - 0x79 - This must match the number of Bonding entries
  183. #define BLE_NVID_GATT_CFG_START 0x70 //!< Start of the GATT Configuration NV IDs
  184. #define BLE_NVID_GATT_CFG_END 0x79 //!< End of the GATT Configuration NV IDs
  185. /** @} End BLE_NV_IDS */
  186. /*********************************************************************
  187. * BLE OSAL GAP GLOBAL Events
  188. */
  189. #define GAP_EVENT_SIGN_COUNTER_CHANGED 0x4000 //!< The device level sign counter changed
  190. /** @defgroup BLE_MSG_IDS BLE OSAL Message ID Events
  191. * Reserved Message ID Event Values:<BR>
  192. * 0xC0 - Key Presses<BR>
  193. * 0xE0 to 0xFC - App<BR>
  194. * @{
  195. */
  196. // GAP - Messages IDs (0xD0 - 0xDF)
  197. #define GAP_MSG_EVENT 0xD0 //!< Incoming GAP message
  198. // SM - Messages IDs (0xC1 - 0xCF)
  199. #define SM_NEW_RAND_KEY_EVENT 0xC1 //!< New Rand Key Event message
  200. // GATT - Messages IDs (0xB0 - 0xBF)
  201. #define GATT_MSG_EVENT 0xB0 //!< Incoming GATT message
  202. #define GATT_SERV_MSG_EVENT 0xB1 //!< Incoming GATT Serv App message
  203. // L2CAP - Messages IDs (0xA0 - 0xAF)
  204. #define L2CAP_DATA_EVENT 0xA0 //!< Incoming data on a channel
  205. #define L2CAP_SIGNAL_EVENT 0xA2 //!< Incoming Signaling message
  206. // HCI - Messages IDs (0x90 - 0x9F)
  207. #define HCI_DATA_EVENT 0x90 //!< HCI Data Event message
  208. #define HCI_GAP_EVENT_EVENT 0x91 //!< GAP Event message
  209. #define HCI_SMP_EVENT_EVENT 0x92 //!< SMP Event message
  210. #define HCI_EXT_CMD_EVENT 0x93 //!< HCI Extended Command Event message
  211. /** @} End BLE_MSG_IDS */
  212. /*********************************************************************
  213. * TYPEDEFS
  214. */
  215. //! BLE Generic Status return: @ref BLE_STATUS_VALUES
  216. typedef Status_t bStatus_t;
  217. /** @} End GAP_MSG_EVENT_DEFINES */
  218. /*********************************************************************
  219. * System Events
  220. */
  221. /*********************************************************************
  222. * Global System Messages
  223. */
  224. /*********************************************************************
  225. * MACROS
  226. */
  227. #define TI_BASE_UUID_128( uuid ) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, \
  228. 0x00, 0x40, 0x51, 0x04, LO_UINT16( uuid ), HI_UINT16( uuid ), 0x00, 0xF0
  229. /*********************************************************************
  230. * GLOBAL VARIABLES
  231. */
  232. /*********************************************************************
  233. * FUNCTIONS
  234. */
  235. /*********************************************************************
  236. *********************************************************************/
  237. #ifdef __cplusplus
  238. }
  239. #endif
  240. #endif /* BCOMDEF_H */