Schedule Alternate Toggle pulse for SDU Sync Ref to Audio Out tests
This commit is contained in:
18
src/main.c
18
src/main.c
@@ -503,7 +503,7 @@ static void sync_toggle_timer_isr_handler(nrf_timer_event_t event_type, void *p_
|
||||
LOG_INF("SDU Sync Ref: %d", capture_time_us);
|
||||
break;
|
||||
case ALTERNATE_TOGGLE_STATE_W4_AUDIO_OUT:
|
||||
alternate_toggle_state = ALTERNATE_TOGGLE_STATE_W4_AUDIO_OUT;
|
||||
alternate_toggle_state = ALTERNATE_TOGGLE_STATE_IDLE;
|
||||
gpio_pin_set_dt(&alternate_toggle_pin, 0);
|
||||
LOG_INF("Audio Out: %d", capture_time_us);
|
||||
break;
|
||||
@@ -522,7 +522,7 @@ static void setup_sdu_sync_to_audio_out_timer(uint32_t delay_us) {
|
||||
current_time_us = nrf_timer_cc_get(NRF_TIMER2, NRF_TIMER_CC_CHANNEL1);
|
||||
}
|
||||
uint32_t sdu_sync_ref_us = current_time_us + delay_us;
|
||||
LOG_INF("TOGGLE TIMER now %u, sdu_sync_ref %u", current_time_us, sdu_sync_ref_us);
|
||||
LOG_INF("TOGGLE TIMER now %u, delta %u, sdu_sync_ref %u", current_time_us, delay_us, sdu_sync_ref_us);
|
||||
nrfx_timer_compare(&sync_toggle_timer_instance, NRF_TIMER_CC_CHANNEL1, sdu_sync_ref_us, true);
|
||||
alternate_toggle_state = ALTERNATE_TOGGLE_STATE_W4_SDU_SYNC_REF;
|
||||
}
|
||||
@@ -541,9 +541,6 @@ int main(void)
|
||||
nrfx_timer_enable(&sync_toggle_timer_instance);
|
||||
alternate_toggle_state = ALTERNATE_TOGGLE_STATE_IDLE;
|
||||
|
||||
// simulate received packet
|
||||
setup_sdu_sync_to_audio_out_timer(100000);
|
||||
|
||||
/* incoming events and data from the controller */
|
||||
static K_FIFO_DEFINE(rx_queue);
|
||||
int err;
|
||||
@@ -596,11 +593,6 @@ int main(void)
|
||||
gpio_pin_configure_dt(&alternate_toggle_pin, GPIO_OUTPUT_INACTIVE);
|
||||
#endif
|
||||
|
||||
// try to toggle pin
|
||||
while (1) {
|
||||
gpio_pin_toggle_dt( &alternate_toggle_pin );
|
||||
}
|
||||
|
||||
bt_hci_raw_cmd_ext_register(&cmd_list, 1);
|
||||
#endif
|
||||
|
||||
@@ -637,6 +629,12 @@ int main(void)
|
||||
// get rx timestamp = sdu sync reference: Packet Type (1) | ISO Header (4) | Timestamp (if TS flag is set)
|
||||
uint32_t timestamp_sdu_sync_reference_us = little_endian_read_32(packet, 5);
|
||||
|
||||
// schedule SDU Sync Ref to Audio Out Toggle
|
||||
if (alternate_toggle_state == ALTERNATE_TOGGLE_STATE_IDLE) {
|
||||
int32_t sdu_sync_ref_delta_us = (int32_t)(timestamp_sdu_sync_reference_us - timestamp_toggle_us);
|
||||
setup_sdu_sync_to_audio_out_timer(sdu_sync_ref_delta_us);
|
||||
}
|
||||
|
||||
// calculate time of toggle relative to sdu sync reference (usually negative as the packet is received before it should be played)
|
||||
int32_t delta_us = (int32_t)(timestamp_toggle_us - timestamp_sdu_sync_reference_us);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user