@@ -35,8 +35,6 @@ extern "C" { void HW_IPCC_Rx_Handler(void);}
35
35
/* Private variables ---------------------------------------------------------*/
36
36
PLACE_IN_SECTION (" MB_MEM1" ) ALIGN(4 ) static TL_CmdPacket_t BleCmdBuffer;
37
37
38
- /* PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t HciAclDataBuffer[MAX_HCI_ACL_PACKET_SIZE];
39
- */
40
38
PLACE_IN_SECTION (" MB_MEM2" ) ALIGN(4 ) static uint8_t EvtPool[POOL_SIZE];
41
39
PLACE_IN_SECTION (" MB_MEM2" ) ALIGN(4 ) static TL_CmdPacket_t SystemCmdBuffer;
42
40
PLACE_IN_SECTION (" MB_MEM2" ) ALIGN(4 ) static uint8_t
@@ -52,6 +50,9 @@ PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t
52
50
uint16_t _write_index;
53
51
uint16_t _write_index_initial;
54
52
53
+ /* * Bluetooth Device Address */
54
+ static uint8_t bd_addr_udn[6 ];
55
+
55
56
HCISharedMemTransportClass::HCISharedMemTransportClass (BLEChip_t ble_chip) :
56
57
_ble_chip(ble_chip)
57
58
{
@@ -155,30 +156,6 @@ static bool sysevt_check(void)
155
156
}
156
157
}
157
158
158
- #if 0
159
- void shci_cmd_resp_release(uint32_t flag)
160
- {
161
- /* the semaphore is released here, so the variable becomes true. */
162
- sys_resp = true;
163
- return;
164
- }
165
-
166
- void shci_cmd_resp_wait(uint32_t timeout)
167
- {
168
- /* TO DO: manage timeouts if we can return an error */
169
- // for (unsigned long start = millis(); (millis() - start) < 10000;) {
170
- while(1) {
171
- /* Wait for 10sec max - if not return an error */
172
- if (sys_resp) { break; }
173
- }
174
-
175
- if (!sys_resp) {
176
- /* no event received, timeout occurs */
177
- return;
178
- }
179
- }
180
- #endif
181
-
182
159
static void acl_data_ack (void )
183
160
{
184
161
/* *
@@ -266,12 +243,20 @@ int HCISharedMemTransportClass::begin()
266
243
*/
267
244
268
245
269
- /* Now start BLE service on firmware side, using Vendor specific
270
- * command on the System Channel
271
- */
272
- stm32wb_start_ble ();
246
+ /* Now start BLE service on firmware side, using Vendor specific
247
+ * command on the System Channel
248
+ */
249
+ stm32wb_start_ble ();
273
250
274
251
/* "IPM Channel Open Completed" */
252
+
253
+ /* Once reset complete evet is received we need
254
+ * to send a few more commands:
255
+ * set bd addr */
256
+ bt_ipm_set_addr ();
257
+ /* and Tx power */
258
+ bt_ipm_set_power ();
259
+
275
260
return 1 ;
276
261
} else {
277
262
/* "Error opening IPM channel" */
@@ -488,11 +473,96 @@ size_t HCISharedMemTransportClass::write(const uint8_t* data, size_t length)
488
473
489
474
}
490
475
476
+ #if 1
477
+ /* This function fills in a BD address table */
478
+ bool get_bd_address (uint8_t *bd_addr)
479
+ {
480
+ uint8_t *otp_addr;
481
+ uint32_t udn;
482
+ uint32_t company_id;
483
+ uint32_t device_id;
484
+ bool bd_found;
485
+
486
+ udn = LL_FLASH_GetUDN ();
487
+
488
+ if (udn != 0xFFFFFFFF ) {
489
+ /* "Found Unique Device Number: %#06x", udn) */
490
+
491
+ company_id = LL_FLASH_GetSTCompanyID ();
492
+ device_id = LL_FLASH_GetDeviceID ();
493
+
494
+ bd_addr[0 ] = (uint8_t )(udn & 0x000000FF );
495
+ bd_addr[1 ] = (uint8_t )((udn & 0x0000FF00 ) >> 8 );
496
+ bd_addr[2 ] = (uint8_t )((udn & 0x00FF0000 ) >> 16 );
497
+ bd_addr[3 ] = (uint8_t )device_id;
498
+ bd_addr[4 ] = (uint8_t )(company_id & 0x000000FF );
499
+ bd_addr[5 ] = (uint8_t )((company_id & 0x0000FF00 ) >> 8 );
500
+
501
+ bd_found = true ;
502
+ } else {
503
+ bd_addr =NULL ;
504
+ bd_found = false ;
505
+ }
506
+
507
+ return bd_found;
508
+ }
509
+
510
+ static int bt_ipm_set_addr (void )
511
+ {
512
+ /* the specific table for set addr is 8 bytes:
513
+ * one byte for config_offset
514
+ * one byte for length
515
+ * 6 bytes for payload */
516
+ uint8_t data[4 +8 ];
517
+
518
+ if (get_bd_address (bd_addr_udn)) {
519
+ /* create ACI_HAL_WRITE_CONFIG_DATA */
520
+
521
+ data[0 ] = BT_BUF_CMD;
522
+ data[1 ] = uint8_t (ACI_WRITE_CONFIG_DATA_OPCODE & 0x000000FF ); /* OCF */
523
+ data[2 ] = uint8_t ((ACI_WRITE_CONFIG_DATA_OPCODE & 0x0000FF00 ) >> 8 ); /* OGF */
524
+ data[3 ] = 8 ; /* length of parameters */
525
+ /* fill the ACI_HAL_WRITE_CONFIG_DATA with the addr*/
526
+ data[4 ] = CONFIG_DATA_PUBADDR_OFFSET; /* the offset */
527
+ data[5 ] = 6 ; /* is the length of the bd_addr table */
528
+ memcpy (data + 6 , bd_addr_udn, 6 );
529
+ /* send the ACI_HAL_WRITE_CONFIG_DATA */
530
+ mbox_write (data[0 ], 11 , &data[1 ]);
531
+
532
+ return 1 ; /* success */
533
+ } else {
534
+ return 0 ; /* Error */
535
+ }
536
+ }
537
+
538
+ static int bt_ipm_set_power (void )
539
+ {
540
+ /* the specific table for power is 3 bytes:
541
+ * one byte for cmd
542
+ * two bytes for value */
543
+ uint8_t data[4 +3 ];
544
+
545
+ data[0 ] = BT_BUF_CMD; /* the type */
546
+ data[1 ] = (uint8_t )(ACI_HAL_SET_TX_POWER_LEVEL & 0x000000FF ); /* the OPCODE */
547
+ data[2 ] = (uint8_t )((ACI_HAL_SET_TX_POWER_LEVEL & 0x0000FF00 ) >> 8 );
548
+ data[3 ] = 3 ; /* the length */
549
+ /* fill the ACI_HAL_WRITE_CONFIG_DATA */
550
+ data[4 ] = 0x0F ; /* the command */
551
+ data[5 ] = 0x18 ;
552
+ data[6 ] = 0x01 ;
553
+
554
+ /* send the ACI_HAL_WRITE_CONFIG_DATA */
555
+ mbox_write (data[0 ], 3 , &data[1 ]);
556
+
557
+ return 1 ; /* success */
558
+ }
559
+
560
+ #else
491
561
int bt_ipm_ble_init(void)
492
562
{
493
563
uint16_t opcode;
494
564
static uint8_t randCnt;
495
- # if 0
565
+
496
566
/* if event is a command complete event */
497
567
if (*pMsg == HCI_CMD_CMPL_EVT) {
498
568
/* "Command Complete Event Command" */
@@ -707,9 +777,10 @@ size_t HCISharedMemTransportClass::write(const uint8_t* data, size_t length)
707
777
#endif /* DEBUG */
708
778
}
709
779
}
710
- # endif
711
- return 0 ;
780
+
781
+ return 1; /* success */
712
782
}
783
+ #endif
713
784
714
785
uint16_t mbox_write (uint8_t type, uint16_t len, const uint8_t *pData)
715
786
{
@@ -817,40 +888,3 @@ static void init_debug(void)
817
888
818
889
return ;
819
890
}
820
-
821
- /* This function fills in a BD address table */
822
- bool get_bd_address (uint8_t *bd_addr)
823
- {
824
- uint8_t *otp_addr;
825
- uint32_t udn;
826
- uint32_t company_id;
827
- uint32_t device_id;
828
- bool bd_found;
829
-
830
- udn = LL_FLASH_GetUDN ();
831
-
832
- if (udn != 0xFFFFFFFF ) {
833
- #if defined(DEBUG)
834
- tr_info (" Found Unique Device Number: %#06x" , udn);
835
- #endif /* DEBUG */
836
- company_id = LL_FLASH_GetSTCompanyID ();
837
- device_id = LL_FLASH_GetDeviceID ();
838
-
839
- bd_addr[0 ] = (uint8_t )(udn & 0x000000FF );
840
- bd_addr[1 ] = (uint8_t )((udn & 0x0000FF00 ) >> 8 );
841
- bd_addr[2 ] = (uint8_t )((udn & 0x00FF0000 ) >> 16 );
842
- bd_addr[3 ] = (uint8_t )device_id;
843
- bd_addr[4 ] = (uint8_t )(company_id & 0x000000FF );
844
- bd_addr[5 ] = (uint8_t )((company_id & 0x0000FF00 ) >> 8 );
845
-
846
- bd_found = true ;
847
- } else {
848
- #if defined(DEBUG)
849
- tr_info (" Cannot find Bluetooth Device ADDRESS to program - will leave hw default" );
850
- #endif /* DEBUG */
851
- bd_addr = NULL ;
852
- bd_found = false ;
853
- }
854
-
855
- return bd_found;
856
- }
0 commit comments