mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-11 18:40:22 +00:00
hci: add hci_request_sco_can_send_now_event
This commit is contained in:
parent
282ceebcb6
commit
d057580e4d
@ -190,13 +190,8 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
|
||||
}
|
||||
#endif
|
||||
|
||||
static void try_send_sco(void){
|
||||
return;
|
||||
static void send_sco_data(void){
|
||||
if (!sco_handle) return;
|
||||
if (!hci_can_send_sco_packet_now()) {
|
||||
// printf("try_send_sco, cannot send now\n");
|
||||
return;
|
||||
}
|
||||
|
||||
const int sco_packet_length = hci_get_sco_packet_length();
|
||||
const int sco_payload_length = sco_packet_length - 3;
|
||||
@ -215,6 +210,10 @@ static void try_send_sco(void){
|
||||
if (phase >= sizeof(sine)) phase = 0;
|
||||
}
|
||||
hci_send_sco_packet_buffer(sco_packet_length);
|
||||
|
||||
// request another send event
|
||||
hci_request_sco_can_send_now_event();
|
||||
|
||||
static int count = 0;
|
||||
count++;
|
||||
if ((count & SCO_REPORT_PERIOD) == 0) printf("Sent %u\n", count);
|
||||
@ -236,7 +235,7 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
|
||||
show_usage();
|
||||
break;
|
||||
case HCI_EVENT_SCO_CAN_SEND_NOW:
|
||||
try_send_sco();
|
||||
send_sco_data();
|
||||
break;
|
||||
case HCI_EVENT_HSP_META:
|
||||
switch (event[2]) {
|
||||
@ -261,7 +260,7 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
|
||||
} else {
|
||||
sco_handle = hsp_subevent_audio_connection_complete_get_handle(event);
|
||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
||||
try_send_sco();
|
||||
hci_request_sco_can_send_now_event();
|
||||
}
|
||||
break;
|
||||
case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE:
|
||||
|
@ -190,32 +190,33 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
|
||||
}
|
||||
#endif
|
||||
|
||||
static void try_send_sco(void){
|
||||
static void send_sco_data(void){
|
||||
if (!sco_handle) return;
|
||||
|
||||
while (hci_can_send_sco_packet_now()) {
|
||||
|
||||
const int sco_packet_length = hci_get_sco_packet_length();
|
||||
const int sco_payload_length = sco_packet_length - 3;
|
||||
const int frames_per_packet = sco_payload_length; // for 8-bit data. for 16-bit data it's /2
|
||||
const int sco_packet_length = hci_get_sco_packet_length();
|
||||
const int sco_payload_length = sco_packet_length - 3;
|
||||
const int frames_per_packet = sco_payload_length; // for 8-bit data. for 16-bit data it's /2
|
||||
|
||||
hci_reserve_packet_buffer();
|
||||
uint8_t * sco_packet = hci_get_outgoing_packet_buffer();
|
||||
// set handle + flags
|
||||
little_endian_store_16(sco_packet, 0, sco_handle);
|
||||
// set len
|
||||
sco_packet[2] = sco_payload_length;
|
||||
int i;
|
||||
for (i=0;i<frames_per_packet;i++){
|
||||
sco_packet[3+i] = sine[phase];
|
||||
phase++;
|
||||
if (phase >= sizeof(sine)) phase = 0;
|
||||
}
|
||||
hci_send_sco_packet_buffer(sco_packet_length);
|
||||
static int count = 0;
|
||||
count++;
|
||||
if ((count & 15) == 0) printf("Sent %u\n", count);
|
||||
hci_reserve_packet_buffer();
|
||||
uint8_t * sco_packet = hci_get_outgoing_packet_buffer();
|
||||
// set handle + flags
|
||||
little_endian_store_16(sco_packet, 0, sco_handle);
|
||||
// set len
|
||||
sco_packet[2] = sco_payload_length;
|
||||
int i;
|
||||
for (i=0;i<frames_per_packet;i++){
|
||||
sco_packet[3+i] = sine[phase];
|
||||
phase++;
|
||||
if (phase >= sizeof(sine)) phase = 0;
|
||||
}
|
||||
hci_send_sco_packet_buffer(sco_packet_length);
|
||||
|
||||
// request another send event
|
||||
hci_request_sco_can_send_now_event();
|
||||
|
||||
static int count = 0;
|
||||
count++;
|
||||
if ((count & 15) == 0) printf("Sent %u\n", count);
|
||||
}
|
||||
|
||||
static void sco_packet_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
|
||||
@ -233,7 +234,7 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
|
||||
show_usage();
|
||||
break;
|
||||
case HCI_EVENT_SCO_CAN_SEND_NOW:
|
||||
try_send_sco();
|
||||
send_sco_data();
|
||||
break;
|
||||
case HCI_EVENT_HSP_META:
|
||||
switch (event[2]) {
|
||||
@ -258,7 +259,7 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
|
||||
} else {
|
||||
sco_handle = hsp_subevent_audio_connection_complete_get_handle(event);
|
||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
||||
try_send_sco();
|
||||
hci_request_sco_can_send_now_event();
|
||||
}
|
||||
break;
|
||||
case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE:
|
||||
|
15
src/hci.c
15
src/hci.c
@ -409,22 +409,21 @@ int hci_can_send_acl_packet_now(hci_con_handle_t con_handle){
|
||||
}
|
||||
|
||||
int hci_can_send_prepared_sco_packet_now(void){
|
||||
if (!hci_transport_can_send_prepared_packet_now(HCI_SCO_DATA_PACKET)) {
|
||||
hci_stack->sco_waiting_for_can_send_now = 1;
|
||||
return 0;
|
||||
}
|
||||
if (!hci_transport_can_send_prepared_packet_now(HCI_SCO_DATA_PACKET)) return 0;
|
||||
if (!hci_stack->synchronous_flow_control_enabled) return 1;
|
||||
return hci_number_free_sco_slots() > 0;
|
||||
}
|
||||
|
||||
int hci_can_send_sco_packet_now(void){
|
||||
if (hci_stack->hci_packet_buffer_reserved) {
|
||||
hci_stack->sco_waiting_for_can_send_now = 1;
|
||||
return 0;
|
||||
}
|
||||
if (hci_stack->hci_packet_buffer_reserved) return 0;
|
||||
return hci_can_send_prepared_sco_packet_now();
|
||||
}
|
||||
|
||||
void hci_request_sco_can_send_now_event(void){
|
||||
hci_stack->sco_waiting_for_can_send_now = 1;
|
||||
hci_notify_if_sco_can_send_now();
|
||||
}
|
||||
|
||||
// used for internal checks in l2cap.c
|
||||
int hci_is_packet_buffer_reserved(void){
|
||||
return hci_stack->hci_packet_buffer_reserved;
|
||||
|
11
src/hci.h
11
src/hci.h
@ -758,7 +758,14 @@ int hci_send_cmd(const hci_cmd_t *cmd, ...);
|
||||
int hci_get_sco_packet_length(void);
|
||||
|
||||
/**
|
||||
* @brief Check hci packet buffer and if SCO packet can be sent to controller
|
||||
* @brief Request emission of HCI_EVENT_SCO_CAN_SEND_NOW as soon as possible
|
||||
* @note HCI_EVENT_SCO_CAN_SEND_NOW might be emitted during call to this function
|
||||
* so packet handler should be ready to handle it
|
||||
*/
|
||||
void hci_request_sco_can_send_now_event(void);
|
||||
|
||||
/**
|
||||
* @brief Check HCI packet buffer and if SCO packet can be sent to controller
|
||||
*/
|
||||
int hci_can_send_sco_packet_now(void);
|
||||
|
||||
@ -768,7 +775,7 @@ int hci_can_send_sco_packet_now(void);
|
||||
int hci_can_send_prepared_sco_packet_now(void);
|
||||
|
||||
/**
|
||||
* @brief Send SCO packet prepared in hci packet buffer
|
||||
* @brief Send SCO packet prepared in HCI packet buffer
|
||||
*/
|
||||
int hci_send_sco_packet_buffer(int size);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user