BLE Connection Sync - Uninitilize?

I've been working off this example, which provides a great synchronization mechanism.

https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/samples/bluetooth/conn_time_sync/README.html

the example uses RTC, TIMER and EGU peripherals to do the timing, but only initialises it once in controller_timer_nrf52.c and never turns it off. How should i go about uninitialising these peripherals and reinitialising them again? I need to free up the PPI channels for use in other places and need to turn off the peripherals to save on power.

this is my attempt so far

static int timer_uninit(void)
{
	int ret;
	
    nrfx_gppi_channel_free(ppi_chan_timer_clear_on_rtc_tick);

	nrfx_timer_uninit(&app_timer_instance);
	return 0;
}

static int rtc_uninit(void)
{
	int ret;

	nrfx_rtc_disable(&app_rtc_instance);
    nrfx_rtc_counter_clear(&app_rtc_instance);
    nrfx_gppi_channel_free(ppi_chan_on_rtc_match);
    nrfx_gppi_channel_free(ppi_chan_on_timer_match);
	nrfx_rtc_uninit(&app_rtc_instance);

	return 0;
}
int controller_time_init(void)
{
	int ret;

    nrfx_err_t status;
    
    num_rtc_overflows = 0;
    offset_ticks_and_controller_to_app_rtc = 0;

#if defined(__ZEPHYR__)
    IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_EGU_INST_GET(EGU_INST_IDX)), IRQ_PRIO_LOWEST,
                NRFX_EGU_INST_HANDLER_GET(EGU_INST_IDX), 0, 0);
#endif
    nrfx_egu_t egu_inst = NRFX_EGU_INSTANCE(EGU_INST_IDX);
    status = nrfx_egu_init(&egu_inst, NRFX_EGU_DEFAULT_CONFIG_IRQ_PRIORITY, egu_handler, NULL);
    NRFX_ASSERT(status == NRFX_SUCCESS);
    uint32_t ch0_idx = 0;
    uint32_t channels_to_trigger = (1 << ch0_idx);
    nrfx_egu_int_enable(&egu_inst, channels_to_trigger);

	ret = rtc_config();
	if (ret) {
		return ret;
	}

	ret = timer_config();
	if (ret) {
		return ret;
	}

    int final_ret = config_egu_trigger_on_rtc_and_timer_match();
	return final_ret;
}

int controller_time_uninit(void)
{
	int ret;

    nrfx_err_t status;

    nrfx_gppi_group_clear(NRFX_GPPI_CHANNEL_GROUP0);
	nrfx_gppi_group_disable(NRFX_GPPI_CHANNEL_GROUP0);

    nrfx_gppi_channels_disable(BIT(ppi_chan_timer_clear_on_rtc_tick) | BIT(ppi_chan_on_rtc_match) | BIT(ppi_chan_on_timer_match));

    timer_uninit();
	rtc_uninit();

	nrfx_egu_t egu_inst = NRFX_EGU_INSTANCE(EGU_INST_IDX);
    nrfx_egu_uninit(&egu_inst);

    return 0;
}

Parents
  • Hi Simon, 


    I haven't looked deep into the code of the sample but your idea is to disable TIMER and EGU and let the RTC to run. When the RTC CC event occur you will start the TIMER and the EGU to wait for the TIMER CC to match. correct ? 


    I am not so sure it would work because  you will need to involve the CPU to set the EGU, right ? And the TIMER even though can be started with PPI (not sure if you have extra PPI for that) would need time to ramp up and start I am not so sure it would be able to give good accuracy. 

    Have you done any testing  ? 

Reply
  • Hi Simon, 


    I haven't looked deep into the code of the sample but your idea is to disable TIMER and EGU and let the RTC to run. When the RTC CC event occur you will start the TIMER and the EGU to wait for the TIMER CC to match. correct ? 


    I am not so sure it would work because  you will need to involve the CPU to set the EGU, right ? And the TIMER even though can be started with PPI (not sure if you have extra PPI for that) would need time to ramp up and start I am not so sure it would be able to give good accuracy. 

    Have you done any testing  ? 

Children
No Data
Related