/// Reschedule the timer (it should already be running) to interrupt after 'period' void jshUtilTimerReschedule(JsSysTime period) { period = period * 1000000 / SYSCLK_FREQ; if (period < 2) period=2; if (period > 0xFFFFFFFF) period=0xFFFFFFFF; nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_CLEAR); nrf_timer_cc_write(NRF_TIMER1, NRF_TIMER_CC_CHANNEL0, (uint32_t)period); }
void nrf_802154_hp_timer_sync_prepare(void) { uint32_t past_time = timer_time_get() - 1; m_unexpected_sync = past_time; nrf_timer_cc_write(TIMER, TIMER_CC_SYNC, past_time); }
void us_ticker_set_interrupt(timestamp_t timestamp) { core_util_critical_section_enter(); const uint32_t counter_mask = ((1ULL << US_TICKER_COUNTER_BITS) - 1); nrf_timer_cc_write(NRF_TIMER1, NRF_TIMER_CC_CHANNEL0, timestamp & counter_mask); if (!nrf_timer_int_enable_check(NRF_TIMER1, nrf_timer_compare_int_get(NRF_TIMER_CC_CHANNEL0))) { nrf_timer_event_clear(NRF_TIMER1, NRF_TIMER_EVENT_COMPARE0); nrf_timer_int_enable(NRF_TIMER1, nrf_timer_compare_int_get(NRF_TIMER_CC_CHANNEL0)); } core_util_critical_section_exit(); }
void nrf_drv_timer_compare(nrf_drv_timer_t const * const p_instance, nrf_timer_cc_channel_t cc_channel, uint32_t cc_value, bool enable_int) { nrf_timer_int_mask_t timer_int = nrf_timer_compare_int_get(cc_channel); if (enable_int) { nrf_timer_int_enable(p_instance->p_reg, timer_int); } else { nrf_timer_int_disable(p_instance->p_reg, timer_int); } nrf_timer_cc_write(p_instance->p_reg, cc_channel, cc_value); }
void nrf_drv_timer_compare(nrf_drv_timer_t const * const p_instance, nrf_timer_cc_channel_t cc_channel, uint32_t cc_value, bool enable_int) { nrf_timer_int_mask_t timer_int = nrf_timer_compare_int_get(cc_channel); if (enable_int) { nrf_timer_int_enable(p_instance->p_reg, timer_int); } else { nrf_timer_int_disable(p_instance->p_reg, timer_int); } nrf_timer_cc_write(p_instance->p_reg, cc_channel, cc_value); NRF_LOG_INFO("Timer id: %d, capture value set: %d, channel: %d.\r\n", p_instance->instance_id, cc_value, cc_channel); }
void us_ticker_init(void) { if (us_ticker_initialized) { nrf_timer_event_clear(NRF_TIMER1, NRF_TIMER_EVENT_COMPARE0); nrf_timer_int_disable(NRF_TIMER1, nrf_timer_compare_int_get(NRF_TIMER_CC_CHANNEL0)); return; } nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_STOP); nrf_timer_int_disable(NRF_TIMER1, nrf_timer_compare_int_get(NRF_TIMER_CC_CHANNEL0)); /* Configure timer as follows: * - timer mode, * - timer width 16 bits for NRF51 and 32 bits for NRF52, * - timer freq 1 MHz. */ nrf_timer_mode_set(NRF_TIMER1, NRF_TIMER_MODE_TIMER); nrf_timer_frequency_set(NRF_TIMER1, NRF_TIMER_FREQ_1MHz); #ifdef NRF52 nrf_timer_bit_width_set(NRF_TIMER1, NRF_TIMER_BIT_WIDTH_32); #else nrf_timer_bit_width_set(NRF_TIMER1, NRF_TIMER_BIT_WIDTH_16); #endif nrf_timer_cc_write(NRF_TIMER1, NRF_TIMER_CC_CHANNEL0, 0); nrf_timer_event_clear(NRF_TIMER1, NRF_TIMER_EVENT_COMPARE0); NVIC_SetVector(TIMER1_IRQn, (uint32_t)us_ticker_irq_handler); nrf_drv_common_irq_enable(TIMER1_IRQn, APP_IRQ_PRIORITY_HIGH); nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_START); /* Bug fix. First value can't be trusted. */ nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_CAPTURE1); us_ticker_initialized = true; }
void nrf_drv_timer_compare(nrf_drv_timer_t const * const p_instance, nrf_timer_cc_channel_t cc_channel, uint32_t cc_value, bool enable) { nrf_timer_int_mask_t timer_int; timer_int = (nrf_timer_int_mask_t)((uint32_t)NRF_TIMER_INT_COMPARE0_MASK << cc_channel); if (enable == true) { /*lint -save -e644*/ nrf_timer_int_enable(p_instance->p_reg, timer_int); /*lint -restore*/ } else { nrf_timer_int_disable(p_instance->p_reg, timer_int); } nrf_timer_cc_write(p_instance->p_reg, cc_channel, cc_value); }