Skip to content

Commit 8e720d0

Browse files
committed
valid connection and service to switch led on/off
Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent 9849b46 commit 8e720d0

File tree

1 file changed

+26
-41
lines changed

1 file changed

+26
-41
lines changed

src/utility/HCISharedMemTransport.cpp

+26-41
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ static void evt_received(TL_EvtPacket_t *hcievt)
8484

8585
// We need to memcpy the data before passing to higher layers.
8686
switch (hcievt->evtserial.type) {
87-
case TL_BLEEVT_PKT_TYPE:
88-
87+
case TL_BLEEVT_PKT_TYPE: {
8988
#if defined(DEBUG)
9089
#if defined(PRINT_HCI_DATA)
9190
printf("RX<< EVT : ");
@@ -101,7 +100,7 @@ static void evt_received(TL_EvtPacket_t *hcievt)
101100
#endif /* DEBUG */
102101

103102
if (phase_running == false) {
104-
/* check the Rx event of complete the previous bd_addr opcode 0xfc0c */
103+
/* check the Rx event of complete the previous bd_addr opcode 0xFC0C */
105104
if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) &&
106105
(hcievt->evtserial.evt.payload[0] == 0x01) &&
107106
(hcievt->evtserial.evt.payload[1] == 0x0C) &&
@@ -157,31 +156,32 @@ __disable_irq();
157156
_write_index += len;
158157
//TODO: control the _rxbuff cannot overflow
159158
__enable_irq();
159+
}
160160
break;
161161
case TL_ACL_DATA_PKT_TYPE: {
162+
TL_AclDataSerial_t *acl = &(((TL_AclDataPacket_t *)hcievt)->AclDataSerial);
163+
__disable_irq();
164+
len = acl->length + 5;
165+
memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)acl, len);
166+
/* move index */
167+
_write_index += len;
168+
//TODO: control the _rxbuff cannot overflow
169+
__enable_irq();
162170
#if defined(DEBUG)
163171
#if defined(PRINT_HCI_DATA)
164172
printf("RX<< ACL : ");
165-
printf(" Type %#x", hcievt->evtserial.type);
166-
printf(" evt %#x", hcievt->evtserial.evt.evtcode);
167-
printf(" Len %#d", hcievt->evtserial.evt.plen);
173+
printf(" Type %#x", acl->type);
174+
printf(" evt %#x", acl->handle);
175+
printf(" Len %#d", acl->length);
168176
printf(" :");
169-
for (uint8_t i = 0; i < hcievt->evtserial.evt.plen; i++) {
170-
printf(" %02X", hcievt->evtserial.evt.payload[i]);
177+
for (uint8_t i = 0; i < acl->length; i++) {
178+
printf(" %02X", acl->acl_data[i]);
171179
}
172180
printf("\r\n");
173181
#endif /* PRINT_HCI_DATA */
174182
#endif /* DEBUG */
175-
TL_AclDataSerial_t *acl = &(((TL_AclDataPacket_t *)hcievt)->AclDataSerial);
176-
__disable_irq();
177-
len = acl->length + 5;
178-
memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)&acl, len);
179-
/* move index */
180-
_write_index += len;
181-
//TODO: control the _rxbuff cannot overflow
182-
__enable_irq();
183183
}
184-
break;
184+
break;
185185
default:
186186
// should not happen - let's block to check
187187
#if defined(DEBUG)
@@ -388,16 +388,11 @@ int HCISharedMemTransportClass::available()
388388
if (_read_index != _write_index) {
389389
return 1;
390390
} else {
391-
return 0;
391+
return 0;
392392
}
393393
} else {
394394
return 0;
395395
}
396-
if (sys_event) {
397-
sys_event = false;
398-
399-
return 1;
400-
}
401396

402397
return 0;
403398
}
@@ -474,12 +469,8 @@ size_t HCISharedMemTransportClass::write(const uint8_t* data, size_t length)
474469
LL_RCC_ReleaseBackupDomainReset();
475470
}
476471

477-
/* Switch OFF LSI */
472+
/* Switch OFF LSI as LSE is the source clock */
478473
LL_RCC_LSI2_Disable();
479-
480-
/* Select wakeup source of BLE RF */
481-
LL_RCC_SetRFWKPClockSource(LL_RCC_RFWKP_CLKSOURCE_LSE);
482-
483474
}
484475

485476
void stm32wb_reset(void)
@@ -595,10 +586,8 @@ size_t HCISharedMemTransportClass::write(const uint8_t* data, size_t length)
595586
tl_ble_config.IoBusEvtCallBack = evt_received;
596587
tl_ble_config.IoBusAclDataTxAck = acl_data_ack;
597588
TL_BLE_Init((void *)&tl_ble_config);
598-
599589
}
600590

601-
#if 1
602591
/* This function fills in a BD address table */
603592
bool get_bd_address(uint8_t *bd_addr)
604593
{
@@ -692,7 +681,7 @@ static int bt_ipm_set_power(void)
692681
return 1; /* success */
693682
}
694683

695-
#else
684+
#if 0
696685
int bt_ipm_ble_init(void)
697686
{
698687
uint16_t opcode;
@@ -953,16 +942,11 @@ static int bt_ipm_set_power(void)
953942
TL_BLE_SendCmd(NULL, 0); // unused parameters for now
954943
break;
955944
case 2://ACL DATA
956-
if (!acl_data) {
957-
#if defined(DEBUG)
958-
printf("ERROR: previous ACL message not ACK'd\r\n");
959-
#endif /* DEBUG */
960-
/* return number of bytes sent, 0 in this error case */
961-
return 0;
962-
}
963-
memcpy((void *)
964-
&((TL_AclDataPacket_t *)HciAclDataBuffer)->AclDataSerial, pData, len);
965-
TL_BLE_SendAclData(NULL, 0); // unused parameters for now
945+
/*memcpy((void *)
946+
&((TL_AclDataPacket_t *)HciAclDataBuffer)->AclDataSerial, pData, len);*/
947+
TL_AclDataSerial_t *aclDataSerial = (TL_AclDataSerial_t *)(HciAclDataBuffer + sizeof(TL_PacketHeader_t));
948+
aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd
949+
memcpy(HciAclDataBuffer + + sizeof(TL_PacketHeader_t) + sizeof(type), pData, len);
966950
#if defined(DEBUG)
967951
#if defined(PRINT_HCI_DATA)
968952
printf("TX>> ACL : ");
@@ -972,6 +956,7 @@ static int bt_ipm_set_power(void)
972956
printf("\r\n");
973957
#endif /* PRINT_HCI_DATA */
974958
#endif /* DEBUG */
959+
TL_BLE_SendAclData(NULL, 0); // unused parameters for now
975960
break;
976961
}
977962
return len;

0 commit comments

Comments
 (0)