/** @brief Function for initializing the PPI peripheral. */ static void ppi_init(void) { uint32_t err_code = NRF_SUCCESS; err_code = nrf_drv_ppi_init(); APP_ERROR_CHECK(err_code); // Configure 1st available PPI channel to stop TIMER0 counter on TIMER1 COMPARE[0] match, which is every even number of seconds. err_code = nrf_drv_ppi_channel_alloc(&ppi_channel1); APP_ERROR_CHECK(err_code); err_code = nrf_drv_ppi_channel_assign(ppi_channel1, nrf_drv_timer_event_address_get(&timer1, NRF_TIMER_EVENT_COMPARE0), nrf_drv_timer_task_address_get(&timer0, NRF_TIMER_TASK_STOP)); APP_ERROR_CHECK(err_code); // Configure 2nd available PPI channel to start timer0 counter at TIMER2 COMPARE[0] match, which is every odd number of seconds. err_code = nrf_drv_ppi_channel_alloc(&ppi_channel2); APP_ERROR_CHECK(err_code); err_code = nrf_drv_ppi_channel_assign(ppi_channel2, nrf_drv_timer_event_address_get(&timer2, NRF_TIMER_EVENT_COMPARE0), nrf_drv_timer_task_address_get(&timer0, NRF_TIMER_TASK_START)); APP_ERROR_CHECK(err_code); // Enable both configured PPI channels err_code = nrf_drv_ppi_channel_enable(ppi_channel1); APP_ERROR_CHECK(err_code); err_code = nrf_drv_ppi_channel_enable(ppi_channel2); APP_ERROR_CHECK(err_code); }
static void led_blinking_setup() { uint32_t compare_evt_addr; uint32_t gpiote_task_addr; nrf_ppi_channel_t ppi_channel; ret_code_t err_code; nrf_drv_gpiote_out_config_t config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(false); err_code = nrf_drv_gpiote_out_init(GPIO_OUTPUT_PIN_NUMBER, &config); APP_ERROR_CHECK(err_code); nrf_drv_timer_extended_compare(&timer, (nrf_timer_cc_channel_t)0, 200 * 1000UL, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false); err_code = nrf_drv_ppi_channel_alloc(&ppi_channel); APP_ERROR_CHECK(err_code); compare_evt_addr = nrf_drv_timer_event_address_get(&timer, NRF_TIMER_EVENT_COMPARE0); gpiote_task_addr = nrf_drv_gpiote_out_task_addr_get(GPIO_OUTPUT_PIN_NUMBER); err_code = nrf_drv_ppi_channel_assign(ppi_channel, compare_evt_addr, gpiote_task_addr); APP_ERROR_CHECK(err_code); err_code = nrf_drv_ppi_channel_enable(ppi_channel); APP_ERROR_CHECK(err_code); nrf_drv_gpiote_out_task_enable(GPIO_OUTPUT_PIN_NUMBER); }
void saadc_sampling_event_init(void) { ret_code_t err_code; err_code = nrf_drv_ppi_init(); APP_ERROR_CHECK(err_code); nrf_drv_timer_config_t timer_config = NRF_DRV_TIMER_DEFAULT_CONFIG; timer_config.frequency = NRF_TIMER_FREQ_31250Hz; err_code = nrf_drv_timer_init(&m_timer, &timer_config, timer_handler); APP_ERROR_CHECK(err_code); /* setup m_timer for compare event */ uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer,SAADC_SAMPLE_RATE); nrf_drv_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false); nrf_drv_timer_enable(&m_timer); uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&m_timer, NRF_TIMER_CC_CHANNEL0); uint32_t saadc_sample_event_addr = nrf_drv_saadc_sample_task_get(); /* setup ppi channel so that timer compare event is triggering sample task in SAADC */ err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel); APP_ERROR_CHECK(err_code); err_code = nrf_drv_ppi_channel_assign(m_ppi_channel, timer_compare_event_addr, saadc_sample_event_addr); APP_ERROR_CHECK(err_code); }
void setup_example(void) { uint32_t event; nrf_ppi_channel_t ppi_channel; uint32_t err_code; nrf_gpio_cfg_output(BSP_LED_0); err_code = nrf_drv_rtc_init(&rtc, NULL, rtc_evt_handler); APP_ERROR_CHECK(err_code); nrf_drv_rtc_tick_enable(&rtc, false); event = nrf_drv_rtc_event_address_get(&rtc, NRF_RTC_EVENT_TICK); nrf_gpiote_task_config(0, BSP_LED_0, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW); err_code = nrf_drv_ppi_init(); APP_ERROR_CHECK(err_code); err_code = nrf_drv_ppi_channel_alloc(&ppi_channel); APP_ERROR_CHECK(err_code); err_code = nrf_drv_ppi_channel_assign(ppi_channel,event,(uint32_t)&NRF_GPIOTE->TASKS_OUT[0]); APP_ERROR_CHECK(err_code); err_code = nrf_drv_ppi_channel_enable(ppi_channel); APP_ERROR_CHECK(err_code); nrf_drv_rtc_enable(&rtc); }
/** * @brief Function for initializing and enabling PPI channels. * * @retval NRF_ERROR_INTERNAL If there were error initializing or enabling PPI channels. * @retval NRF_SUCCESS If PPI channels were initialized and enabled successfully. */ static ret_code_t ppi_init(void) { ret_code_t err_code; uint8_t i; err_code = nrf_drv_ppi_init(); if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_MODULE_ALREADY_INITIALIZED)) { return NRF_ERROR_INTERNAL; } for(i = 0; i < PPI_REQUIRED_CHANNELS ; i++) { err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channels[i]); if (NRF_SUCCESS != err_code) { return NRF_ERROR_INTERNAL; } } err_code = nrf_drv_ppi_channel_assign(m_ppi_channels[0], nrf_drv_comp_event_address_get(NRF_COMP_EVENT_CROSS), nrf_drv_timer_task_address_get(&m_timer0, NRF_TIMER_TASK_COUNT)); if (NRF_SUCCESS != err_code) { return NRF_ERROR_INTERNAL; } err_code = nrf_drv_ppi_channel_assign(m_ppi_channels[1], nrf_drv_timer_event_address_get(&m_timer0, NRF_TIMER_EVENT_COMPARE0), nrf_drv_timer_task_address_get(&m_timer1, NRF_TIMER_TASK_CAPTURE1)); if (NRF_SUCCESS != err_code) { return NRF_ERROR_INTERNAL; } err_code = nrf_drv_ppi_channel_fork_assign(m_ppi_channels[1], nrf_drv_comp_task_address_get(NRF_COMP_TASK_STOP)); if (NRF_SUCCESS != err_code) { return NRF_ERROR_INTERNAL; } err_code = nrf_drv_ppi_channel_assign(m_ppi_channels[2], nrf_drv_comp_event_address_get(NRF_COMP_EVENT_READY), nrf_drv_timer_task_address_get(&m_timer0, NRF_TIMER_TASK_CLEAR)); if (NRF_SUCCESS != err_code) { return NRF_ERROR_INTERNAL; } err_code = nrf_drv_ppi_channel_fork_assign(m_ppi_channels[2], nrf_drv_timer_task_address_get(&m_timer1, NRF_TIMER_TASK_CLEAR)); if (NRF_SUCCESS != err_code) { return NRF_ERROR_INTERNAL; } for(i = 0; i < PPI_REQUIRED_CHANNELS ; i++) { err_code = nrf_drv_ppi_channel_enable(m_ppi_channels[i]); if (NRF_SUCCESS != err_code) { return NRF_ERROR_INTERNAL; } } return NRF_SUCCESS; }
void setup_example(void) { uint32_t event; nrf_ppi_channel_t ppi_channel; uint32_t err_code; nrf_gpio_cfg_output(BSP_LED_0); err_code = nrf_drv_rtc_init(&rtc, NULL, rtc_evt_handler); APP_ERROR_CHECK(err_code); nrf_drv_rtc_tick_enable(&rtc, false); event = nrf_drv_rtc_event_address_get(&rtc, NRF_RTC_EVENT_TICK); if (!nrf_drv_gpiote_is_init()) { err_code = nrf_drv_gpiote_init(); APP_ERROR_CHECK(err_code); } nrf_drv_gpiote_out_config_t pin_out_config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(false); err_code = nrf_drv_gpiote_out_init(BSP_LED_0,&pin_out_config); APP_ERROR_CHECK(err_code); nrf_drv_gpiote_out_task_enable(BSP_LED_0); uint32_t gpiote_task_addr = nrf_drv_gpiote_out_task_addr_get(BSP_LED_0); err_code = nrf_drv_ppi_init(); APP_ERROR_CHECK(err_code); err_code = nrf_drv_ppi_channel_alloc(&ppi_channel); APP_ERROR_CHECK(err_code); err_code = nrf_drv_ppi_channel_assign(ppi_channel,event,gpiote_task_addr); APP_ERROR_CHECK(err_code); err_code = nrf_drv_ppi_channel_enable(ppi_channel); APP_ERROR_CHECK(err_code); nrf_drv_rtc_enable(&rtc); }
/** @brief Function for initializing PPI used in infrared signal decoding * The PPI is needed to convert the timer event into a task. */ uint32_t ir_ppi_init(void) { uint32_t gpiote_event_addr; uint32_t timer_task_addr; nrf_ppi_channel_t ppi_channel; ret_code_t err_code; nrf_drv_gpiote_in_config_t config; config.sense = NRF_GPIOTE_POLARITY_HITOLO; config.pull = NRF_GPIO_PIN_PULLUP; config.hi_accuracy = false; config.is_watcher = false; nrf_drv_timer_config_t timer_config; timer_config.frequency = NRF_TIMER_FREQ_1MHz; timer_config.mode = NRF_TIMER_MODE_TIMER; timer_config.bit_width = NRF_TIMER_BIT_WIDTH_32; timer_config.interrupt_priority = 3; err_code = nrf_drv_timer_init(&ir_timer, &timer_config, timer_dummy_handler); APP_ERROR_CHECK(err_code); // Set up GPIOTE err_code = nrf_drv_gpiote_in_init(IR_RECEIVER_PIN_1, &config, ir_in_pin_handler); APP_ERROR_CHECK(err_code); err_code = nrf_drv_gpiote_in_init(IR_RECEIVER_PIN_2, &config, ir_in_pin_handler); APP_ERROR_CHECK(err_code); err_code = nrf_drv_gpiote_in_init(IR_RECEIVER_PIN_3, &config, ir_in_pin_handler); APP_ERROR_CHECK(err_code); // Set up timer for capturing nrf_drv_timer_capture_get(&ir_timer, NRF_TIMER_CC_CHANNEL0); // Set up PPI channel err_code = nrf_drv_ppi_channel_alloc(&ppi_channel); APP_ERROR_CHECK(err_code); timer_task_addr = nrf_drv_timer_capture_task_address_get(&ir_timer, NRF_TIMER_CC_CHANNEL0); gpiote_event_addr = nrf_drv_gpiote_in_event_addr_get(IR_RECEIVER_PIN_1); //err_code = nrf_drv_ppi_channel_assign(ppi_channel, gpiote_event_addr, timer_task_addr); //APP_ERROR_CHECK(err_code); //err_code = nrf_drv_ppi_channel_enable(ppi_channel); //APP_ERROR_CHECK(err_code); nrf_drv_gpiote_in_event_enable(IR_RECEIVER_PIN_1, true); nrf_drv_gpiote_in_event_enable(IR_RECEIVER_PIN_2, true); nrf_drv_gpiote_in_event_enable(IR_RECEIVER_PIN_3, true); // Enable timer nrf_drv_timer_enable(&ir_timer); return 0; }