This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

_timeout_handler

I have just started coding in Timers in nrf51822. Here i am not clear with the Timer part. Can anybody explain me how to use timer with use of Event Scheduler. Here in app_timer_create() function i am not clear with app_timer_timeout_handler_t timeout_handle. Want some explanation in timeout_handler how to use it and where to use it and why to use it.

  • Basically, the timeout handler contains the code to be executed with the associated timer. So a timer set to run once every second will run the timeout handler code once every second. Here is some example code showing relevant parts for a timer going off every second. As for the scheduler, the Nan-36 documentation states:

    The SDK contains a scheduler module which provides a mechanism for moving the handling of events and interrupts from the interrupt handlers to main context. This ensures that all interrupt handlers execute quickly.

    I've only been using this chip for a short while but I hope this helps :)

    #define ADC_SAMPLING_INTERVAL                APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER) /**< Sampling rate for the ADC. Once per second */
    
    #define SCHED_MAX_EVENT_DATA_SIZE       sizeof(app_timer_event_t)                   /**< Maximum size of scheduler events. Note that scheduler BLE stack events do not contain any data, as the events are being pulled from the stack in the event handler. */
    #define SCHED_QUEUE_SIZE                10                                          /**< Maximum number of events in the scheduler queue. */
    
    static app_timer_id_t                        m_adc_sampling_timer_id;										/**<set  ADC timer id */
    
    static void adc_sampling_timeout_handler(void * p_context)
    {
      adc_1();
    }
    
    /**@brief Function for the Timer initialization.
     *
     * @details Initializes the timer module.
     */
    static void timers_init(void)
    {
    		uint32_t err_code;
        // Initialize timer module, making it use the scheduler
        APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, true);
    	err_code = app_timer_create(&m_adc_sampling_timer_id, APP_TIMER_MODE_REPEATED, adc_sampling_timeout_handler);
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for starting timers.
    */
    static void timers_start(void)
    {
    	uint32_t err_code;
    	//ADC timer start
    	err_code = app_timer_start(m_adc_sampling_timer_id, ADC_SAMPLING_INTERVAL, NULL);
        APP_ERROR_CHECK(err_code);
    }
    
    int main(void)
    {
        // Initialize
        leds_init();
        timers_init();
        ble_stack_init();
        bond_manager_init();
        scheduler_init();    
        gap_params_init();
        services_init();
        advertising_init();
        sensor_sim_init();
        conn_params_init();
        sec_params_init();
        // Start execution
        timers_start();
        advertising_start();
    
        // Enter main loop
        for (;;)
        {  
            app_sched_execute();
            power_manage();
        }
    }
    
Related