/**@brief Timer initialization.
 *
 * @details Initializes the timer module. This creates and starts application timers.
 */
void timers_init(void)
{
    uint32_t err_code;

    // Initialize timer module
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);

    // Create battery timer
    err_code = app_timer_create(&m_battery_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                battery_level_meas_timeout_handler);
    APP_ERROR_CHECK(err_code);
    
    err_code = app_timer_create(&m_alert_led_blink_timer_id,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                mild_alert_timeout_handler);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&m_adv_led_blink_timer_id,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                adv_led_blink_timeout_handler);
    APP_ERROR_CHECK(err_code);
	
	  err_code = app_timer_create(&m_rtc_update_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                rtc_timeout_handler);
    APP_ERROR_CHECK(err_code); 
		 
	
}
예제 #2
0
파일: BikeTimers.c 프로젝트: azhn/smartbike
void timers_init(void) {
    uint32_t err_code;    
  
    //APP_TIMER_INIT(BIKE_TIMER_PRESCALER, BIKE_TIMER_MAX_TIMERS,
    //			BIKE_TIMER_OP_QUEUE_SIZE, false);
  
    // ADD YOUR TIMERS HERE
    err_code = app_timer_create(&millis_counter_timer, 
                                APP_TIMER_MODE_REPEATED,
                                millis_counter_handler);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&accel_sample_timer,
                                APP_TIMER_MODE_REPEATED,
                                accel_sample_handler);

    APP_ERROR_CHECK(err_code);

    //err_code = app_timer_create(&turn_signal_sample_timer,
    //                            APP_TIMER_MODE_REPEATED,
    //                            turn_signal_sample_handler);

    //APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&ble_timer, 
                                APP_TIMER_MODE_REPEATED, 
                                ble_handler);

    APP_ERROR_CHECK(err_code);
}
예제 #3
0
/**@brief Function for the timer, tracer, and BSP initialization.
 */
static void utils_setup(bool * p_erase_bonds)
{
		uint32_t err_code;
		bsp_event_t startup_event;

    app_trace_init();
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);

		//bsp init ant
		err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
	//FROM BLE uint32_t err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),bsp_event_handler);

    APP_ERROR_CHECK(err_code);
	
	  // Create timers for BLE
    err_code = app_timer_create(&m_battery_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                battery_level_meas_timeout_handler);
    APP_ERROR_CHECK(err_code);

    // Create battery timer.
    err_code = app_timer_create(&m_rsc_meas_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                rsc_meas_timeout_handler);
    APP_ERROR_CHECK(err_code);
		
		  err_code = bsp_btn_ble_init(NULL, &startup_event);
    APP_ERROR_CHECK(err_code);

    *p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA);
		
}
예제 #4
0
파일: main.c 프로젝트: stelios26/Aphrodite
/**@brief Function for the Timer initialization.
 *
 * @details Initializes the timer module. This creates and starts application timers.
 */
static void timers_init(void)
{
	uint32_t err_code;
	
	/* Initialise timer module */
	APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
	
  // Create timers.
  err_code = app_timer_create(&m_battery_timer_id,
                              APP_TIMER_MODE_REPEATED,
                              battery_level_meas_timeout_handler);
  if (err_code == NRF_SUCCESS)
		debug_printf("Battery timer initialised!\r\n");
	else
	{
		debug_printf("Error with initialising battery timer.\r\n");
		APP_ERROR_CHECK(err_code);
	}
	
	err_code = app_timer_create(&m_temperature_timer_id,
                              APP_TIMER_MODE_REPEATED,
                              temperature_timeout_handler);
	
	err_code = app_timer_create(&m_door_timer_id,
                              APP_TIMER_MODE_REPEATED,
                              door_timeout_handler);
		    
}
예제 #5
0
/**@brief Function for the Timer initialization.
 *
 * @details Initializes the timer module. This creates and starts application timers.
 */
static void timers_init(void)
{
    uint32_t err_code;

    // Initialize timer module.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);

    // Create timers.
    err_code = app_timer_create(&m_battery_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                battery_level_meas_timeout_handler);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&m_heart_rate_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                heart_rate_meas_timeout_handler);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&m_rr_interval_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                rr_interval_timeout_handler);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&m_sensor_contact_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                sensor_contact_detected_timeout_handler);
    APP_ERROR_CHECK(err_code);
}
예제 #6
0
static void create_timers(void)
{
    uint32_t err_code;

    err_code = app_timer_create(
        &led_0_timer_id, APP_TIMER_MODE_REPEATED, timer_0_handler);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(
        &led_1_timer_id, APP_TIMER_MODE_REPEATED, timer_1_handler);
    APP_ERROR_CHECK(err_code);
}
예제 #7
0
파일: main.c 프로젝트: xueliu/nRF51822
/**@brief Function for the Timer initialization.
 *
 * @details Initializes the timer module. This creates and starts application timers.
 */
static void timers_init(void)
{
    uint32_t err_code;
    // Initialize timer module.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);

    // Create timer to send Echo Requests and UDP6 packets to peer.
    err_code = app_timer_create(&m_tx_node_timer, APP_TIMER_MODE_SINGLE_SHOT, tx_timeout_handler);
    APP_ERROR_CHECK(err_code);
    // Create timer to control board LEDs.
    err_code = app_timer_create(&m_led_blink_timer, APP_TIMER_MODE_REPEATED, blink_timeout_handler);
    APP_ERROR_CHECK(err_code);
}
예제 #8
0
파일: main.c 프로젝트: azhn/smartbike
static void timers_init(void) {
    uint32_t err_code;

    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS,
            APP_TIMER_OP_QUEUE_SIZE, false);

    err_code = app_timer_create(&startup_timer, APP_TIMER_MODE_SINGLE_SHOT,
            startup_handler);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&sample_timer, APP_TIMER_MODE_REPEATED,
            timer_handler);
    APP_ERROR_CHECK(err_code);
}
예제 #9
0
void es_adv_timing_timers_init(void)
{
    ret_code_t err_code;

    err_code = app_timer_create(&m_es_adv_interval_timer,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                adv_interval_timeout);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&m_es_slot_timer,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                adv_slot_timeout);
    APP_ERROR_CHECK(err_code);
}
예제 #10
0
void sys_Timer_Handler_Init(void)
{
    uint32_t err_code;

    err_code = app_timer_create(&m_Main_timer_id, APP_TIMER_MODE_REPEATED, sys_Main_Timer_Handler);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&m_Ble_Tx_Timer_id, APP_TIMER_MODE_REPEATED, sys_Ble_Tx_Handler);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&m_Ble_Led_Timer_id, APP_TIMER_MODE_REPEATED, sys_Ble_Led_Timer_Handler);
    APP_ERROR_CHECK(err_code);


}
예제 #11
0
파일: main.c 프로젝트: xueliu/nRF51822
/**@brief Function for the Timer initialization.
 *
 * @details Initializes the timer module. This creates and starts application timers.
 */
static void timers_init(void)
{
    uint32_t err_code;

    // Initialize timer module.
    APP_TIMER_APPSH_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, true);

    // Create timers.
    err_code = app_timer_create(&m_sys_timer_id, APP_TIMER_MODE_REPEATED, system_timer_callback);
    APP_ERROR_CHECK(err_code);

    // Create timer to control board LEDs.
    err_code = app_timer_create(&m_led_blink_timer, APP_TIMER_MODE_SINGLE_SHOT, \
                                blink_timeout_handler);
    APP_ERROR_CHECK(err_code);
}
예제 #12
0
void advertising_timer_init(void){

  app_timer_create(&advertising_timer, APP_TIMER_MODE_REPEATED, &radio_notification_evt_handler);
  //Starts the timer, sets it up for repeated start.
  app_timer_start(advertising_timer, APP_TIMER_TICKS(300, APP_TIMER_PRESCALER), NULL);

}
예제 #13
0
void stopwatch_init(void) {
    uint32_t err_code;	 
    err_code = app_timer_create(&stopwatch_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                stopwatch_timeout_handler);
    APP_ERROR_CHECK(err_code);
}
예제 #14
0
/**
 * @brief Function for setup all thinks not directly associated witch ANT stack/protocol.
 * @desc Initialization of: @n
 *         - app_tarce for debug.
 *         - app_timer, presetup for bsp and ant pulse simulation.
 *         - bsp for signaling leds and user buttons (if use button is enabled in example).
 *         - ant pulse simulate for task of filling hrm profile data.
 */
static void utils_setup(void)
{
    uint32_t err_code;

    app_trace_init();

    // Initialize and start a single continuous mode timer, which is used to update the event time
    // on the main data page.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);

    #if (MODIFICATION_TYPE == MODIFICATION_TYPE_BUTTON)
    /** @snippet [ANT Pulse simulator button init] */
    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
                        APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
                        bsp_evt_handler);
    /** @snippet [ANT Pulse simulator button init] */
    #else
    err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);
    #endif

    err_code = app_timer_create(&m_tick_timer,
                                APP_TIMER_MODE_REPEATED,
                                app_tick_handler);
    APP_ERROR_CHECK(err_code);

    // Schedule a timeout event every 2 seconds
    err_code = app_timer_start(m_tick_timer, APP_TICK_EVENT_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);
}
예제 #15
0
파일: dfu_dual_bank.c 프로젝트: IOIOI/nRF51
uint32_t dfu_init(void)
{
    uint32_t err_code = NRF_SUCCESS;

    m_storage_module_param.cb          = pstorage_callback_handler;

    err_code = pstorage_raw_register(&m_storage_module_param, &m_storage_handle_app);
    if (err_code != NRF_SUCCESS)
    {
        m_dfu_state = DFU_STATE_INIT_ERROR;
        return err_code;
    }

    m_storage_handle_app.block_id   = CODE_REGION_1_START;
    m_storage_handle_swap           = m_storage_handle_app;
    m_storage_handle_swap.block_id += DFU_IMAGE_MAX_SIZE_BANKED;

    // Create the timer to monitor the activity by the peer doing the firmware update.
    err_code = app_timer_create(&m_dfu_timer_id,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                dfu_timeout_handler);
    if (err_code == NRF_SUCCESS)
    {
        // Start the DFU timer.
        err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL);
    }

    m_data_received = 0;
    m_dfu_state     = DFU_STATE_IDLE;

    return err_code;
}
예제 #16
0
void bicycle_power_rx_init(void)
{    
    const uint32_t err_code = app_timer_create(&m_timer_id, 
                                               APP_TIMER_MODE_SINGLE_SHOT, 
                                               timer_callback_handle);  
    APP_ERROR_CHECK(err_code);                                               
}
uint32_t dfu_init(void)
{
    uint32_t                err_code;


    m_init_packet_length = 0;
    m_image_crc          = 0;

    m_storage_handle_app  = (uint32_t *)DFU_BANK_0_REGION_START;
    m_storage_handle_sd   = (uint32_t *)0x1000; // DFU_SD_REGION_START

    // Create the timer to monitor the activity by the peer doing the firmware update.
    err_code = app_timer_create(&m_dfu_timer_id,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                dfu_timeout_handler);
    APP_ERROR_CHECK(err_code);

    // Start the DFU timer.
    err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);

    m_data_received = 0;
    m_dfu_state     = DFU_STATE_IDLE;

    return NRF_SUCCESS;
}
예제 #18
0
ret_code_t nrf_pwr_mgmt_init(uint32_t ticks_per_1s)
{
    NRF_LOG_INFO("Init\r\n");
    DEBUG_PINS_INIT();
    SLEEP_INIT();

#if NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED
    m_max_cpu_usage     = 0;
    m_ticks_sleeping    = 0;
    m_ticks_last        = 0;
#endif // NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED

#if NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED
    m_standby_counter   = 0;
#endif // NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED
    m_sysoff_guard      = false;
    m_next_handler      = 0;

#if APP_TIMER_REQUIRED
    ret_code_t ret_code = app_timer_create(&m_pwr_mgmt_timer,
                                           APP_TIMER_MODE_REPEATED,
                                           nrf_pwr_mgmt_timeout_handler);
    VERIFY_SUCCESS(ret_code);

    return app_timer_start(m_pwr_mgmt_timer, ticks_per_1s, NULL);
#else
    return NRF_SUCCESS;
#endif // APP_TIMER_REQUIRED
}
예제 #19
0
uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init)
{
    uint32_t err_code;
    
    m_conn_params_config = *p_init;
    m_change_param = false;
    if (p_init->p_conn_params != NULL)
    {
        m_preferred_conn_params = *p_init->p_conn_params;
        
        // Set the connection params in stack
        err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    }
    else
    {
        // Fetch the connection params from stack
        err_code = sd_ble_gap_ppcp_get(&m_preferred_conn_params);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    }

    m_conn_handle  = BLE_CONN_HANDLE_INVALID;
    m_update_count = 0;
    
    return app_timer_create(&m_conn_params_timer_id,
                            APP_TIMER_MODE_SINGLE_SHOT,
                            update_timeout_handler);
}
예제 #20
0
파일: main.c 프로젝트: ruelsison/simplewave
/**@brief 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, false);
    
    err_code = app_timer_create(&m_app_timer_id, APP_TIMER_MODE_REPEATED, process_step_count);
    APP_ERROR_CHECK(err_code); 
	
    err_code = app_timer_create(&m_app_call_id, APP_TIMER_MODE_SINGLE_SHOT, callLow);
    APP_ERROR_CHECK(err_code); 
	
		err_code = app_timer_create(&m_app_clock_id, APP_TIMER_MODE_REPEATED, clockOps);
    APP_ERROR_CHECK(err_code); 
}
예제 #21
0
/**
 * Public methods
 */
void initLEDDriver(void)
{
    ret_code_t err_code;
    
    // gpioteモジュールを初期化する
    if(!nrf_drv_gpiote_is_init()) {
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code);
    }
    nrf_drv_gpiote_out_config_t out_config;
    out_config.init_state = NRF_GPIOTE_INITIAL_VALUE_LOW;
    out_config.task_pin   = false;
    err_code = nrf_drv_gpiote_out_init(PIN_NUMBER_LED, &out_config);
    APP_ERROR_CHECK(err_code);
    
    // 変数の初期化
    m_pattern_index = 0;
    m_blink_count   = 1;
    m_blank_period  = 1000;

    // タイマーの初期化
    err_code = app_timer_create(&(m_led_timer_id), APP_TIMER_MODE_REPEATED, led_timer_handler);
    APP_ERROR_CHECK(err_code);
    err_code = app_timer_start(m_led_timer_id,
                               APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
                               NULL);
    APP_ERROR_CHECK(err_code);
}
예제 #22
0
파일: main.c 프로젝트: xueliu/nRF51822
/**@brief Function for initializing the IoT Timer. */
static void iot_timer_init(void)
{
    uint32_t err_code;

    static const iot_timer_client_t list_of_clients[] =
    {
        {app_lwip_time_tick,          LWIP_SYS_TICK_MS},
        {blink_timeout_handler,       LED_BLINK_INTERVAL_MS},
        {app_xively_publish_callback, MQTT_PUBLISH_INTERVAL_MS}
    };

    // The list of IoT Timer clients is declared as a constant.
    static const iot_timer_clients_list_t iot_timer_clients =
    {
        (sizeof(list_of_clients) / sizeof(iot_timer_client_t)),
        &(list_of_clients[0]),
    };

    // Passing the list of clients to the IoT Timer module.
    err_code = iot_timer_client_list_set(&iot_timer_clients);
    APP_ERROR_CHECK(err_code);

    // Create app timer to serve as tick source.
    err_code = app_timer_create(&m_iot_timer_tick_src_id,
                                APP_TIMER_MODE_REPEATED,
                                iot_timer_tick_callback);
    APP_ERROR_CHECK(err_code);
    
    // Starting the app timer instance that is the tick source for the IoT Timer.
    err_code = app_timer_start(m_iot_timer_tick_src_id, \
                               APP_TIMER_TICKS(IOT_TIMER_RESOLUTION_IN_MS, APP_TIMER_PRESCALER), \
                               NULL);
    APP_ERROR_CHECK(err_code);
}
예제 #23
0
uint32_t dfu_init(void)
{
    uint32_t                err_code;
    pstorage_module_param_t storage_module_param = {.cb = pstorage_callback_handler};

    m_init_packet_length = 0;
    m_image_crc          = 0;

    err_code = pstorage_register(&storage_module_param, &m_storage_handle_app);
    if (err_code != NRF_SUCCESS)
    {
        m_dfu_state = DFU_STATE_INIT_ERROR;
        return err_code;
    }

    m_storage_handle_app.block_id  = DFU_BANK_0_REGION_START;

    // Create the timer to monitor the activity by the peer doing the firmware update.
    err_code = app_timer_create(&m_dfu_timer_id,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                dfu_timeout_handler);
    APP_ERROR_CHECK(err_code);

    // Start the DFU timer.
    err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);

    m_data_received = 0;
    m_dfu_state     = DFU_STATE_IDLE;

    return NRF_SUCCESS;
}
예제 #24
0
파일: main.c 프로젝트: IOIOI/nRF51
/* Main function */
int main(void)
{
    uint32_t err_code;
    nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
    
    utils_setup();
    
    // Setup SoftDevice and events handler
    err_code = softdevice_ant_evt_handler_set(continuous_scan_event_handler);
    APP_ERROR_CHECK(err_code);

    err_code = softdevice_handler_init(&clock_lf_cfg, NULL, 0, NULL);
    APP_ERROR_CHECK(err_code);

    err_code = ant_stack_static_config();
    APP_ERROR_CHECK(err_code);
        
    continuous_scan_init();

    err_code = app_timer_create(&m_scan_timer_id,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                scan_timeout_event);
    APP_ERROR_CHECK(err_code);

    // Enter main loop
    for (;;)
    {
        err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
    }
}
static void lock_control_handler(ble_doorlock_t * p_doorlock, uint8_t state) 
{ 
    uint32_t             err_code;
    if (state) 
    { 
        // Open door
        LEDS_ON((BSP_LED_3_MASK));
        // Start timer
        if (m_lock_timer_id != 0xFFFFFFFF) {
            err_code = app_timer_stop(m_lock_timer_id);
            APP_ERROR_CHECK(err_code);
        } else {
            err_code = app_timer_create(&m_lock_timer_id, 
                                        APP_TIMER_MODE_SINGLE_SHOT, 
                                        lock_timeout_handler); 
            APP_ERROR_CHECK(err_code); 
        }
        err_code = app_timer_start(m_lock_timer_id, APP_TIMER_TICKS(APP_CFG_CHAR_LOCK_TIMEOUT, APP_TIMER_PRESCALER), NULL);
        APP_ERROR_CHECK(err_code);
    } 
    else 
    { 
        // Lock door
        LEDS_OFF((BSP_LED_3_MASK));
    } 
} 
예제 #26
0
void us_ticker_set_interrupt(timestamp_t timestamp)
{
    if (!us_ticker_inited) {
        us_ticker_init();
    }

    if (us_ticker_appTimerID == TIMER_NULL) {
        if (app_timer_create(&us_ticker_appTimerID, APP_TIMER_MODE_SINGLE_SHOT, us_ticker_app_timer_callback) != NRF_SUCCESS) {
            /* placeholder to do something to recover from error */
            return;
        }
    }

    if (us_ticker_appTimerRunning) {
        return;
    }

    timestamp_t currentCounter64;
    app_timer_cnt_get(&currentCounter64);
    uint32_t currentCounter = currentCounter64 & MAX_RTC_COUNTER_VAL;
    uint32_t targetCounter = ((uint32_t)((timestamp * (uint64_t)APP_TIMER_CLOCK_FREQ) / 1000000) + 1) & MAX_RTC_COUNTER_VAL;
    uint32_t ticksToCount = (targetCounter >= currentCounter) ?
                             (targetCounter - currentCounter) : (MAX_RTC_COUNTER_VAL + 1) - (currentCounter - targetCounter);
    if (ticksToCount > 0) {
        uint32_t rc;
        rc = app_timer_start(us_ticker_appTimerID, ticksToCount, NULL /*p_context*/);
        if (rc != NRF_SUCCESS) {
            /* placeholder to do something to recover from error */
            return;
        }
        us_ticker_appTimerRunning = true;
    }
}
uint32_t dfu_init(void)
{
    uint32_t              err_code;
    bootloader_settings_t bootloader_settings;
    dfu_update_status_t   update_status;
    
    m_storage_module_param.cb          = pstorage_callback_handler;
    
    // Clear swap area.
    uint32_t * p_bank_start_address = (uint32_t *)DFU_BANK_1_REGION_START; 
    
    m_init_packet_length  = 0;
    m_image_crc           = 0;    
           
    err_code = pstorage_raw_register(&m_storage_module_param, &m_storage_handle_app);
    if (err_code != NRF_SUCCESS)
    {
        m_dfu_state = DFU_STATE_INIT_ERROR;
        return err_code;
    }
    
    m_storage_handle_app.block_id   = CODE_REGION_1_START;
    m_storage_handle_swap           = m_storage_handle_app;
    m_storage_handle_swap.block_id += DFU_IMAGE_MAX_SIZE_BANKED;
    
    bootloader_settings_get(&bootloader_settings);
    if ((bootloader_settings.bank_1 != BANK_ERASED) || (*p_bank_start_address != EMPTY_FLASH_MASK))
    {
        err_code = pstorage_raw_clear(&m_storage_handle_swap, DFU_IMAGE_MAX_SIZE_BANKED);
        if (err_code != NRF_SUCCESS)
        {
            m_dfu_state = DFU_STATE_INIT_ERROR;
            return err_code;
        }
        
        update_status.status_code = DFU_BANK_1_ERASED;
        bootloader_dfu_update_process(update_status);
    }
    
    // Create the timer to monitor the activity by the peer doing the firmware update.
    err_code = app_timer_create(&m_dfu_timer_id,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                dfu_timeout_handler);
    APP_ERROR_CHECK(err_code);

    // Start the DFU timer.
    err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);

    // Size which indicates how large application DFU are able to handle.
    // The area is not erased but has been locked by the running application, and is considered
    // to be application data save space.
    m_new_app_max_size = DFU_IMAGE_MAX_SIZE_BANKED;
    
    m_app_data_received = 0;
    m_dfu_state         = DFU_STATE_IDLE;        

    return NRF_SUCCESS;
}
예제 #28
0
/**@brief Function for initializing the timer module and starting a timer with a handler that runs when it expires
 */
static void timer_init(void) {
	APP_TIMER_DEF(timer_id); //Macro takes care of variable declaration
	
	uint32_t err_code = app_timer_create(&timer_id, APP_TIMER_MODE_REPEATED, timer_handler);
	APP_ERROR_CHECK(err_code);
	err_code = app_timer_start(timer_id, APP_TIMER_TICKS(REFRESH_TIME, APP_TIMER_PRESCALER), NULL);
	APP_ERROR_CHECK(err_code);
}
예제 #29
0
/**@brief Function for the Timer initialization.
 *
 * @details Initializes the timer module.
 */
static void timers_init(void)
{
    // Initialize timer module, making it use the scheduler
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
    
    uint32_t err_code = app_timer_create(&m_advdata_update_timer, APP_TIMER_MODE_REPEATED, advdata_update_timer_timeout_handler);
    APP_ERROR_CHECK(err_code);
}
예제 #30
0
/**@brief Function for the Timer initialization.
 *
 * @details Initializes the timer module. This creates and starts application timers.
 */
static void timers_init(void)
{
    uint32_t err_code; 

    // Initialize timer module.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);

    // Create timer to control board LEDs.
    err_code = app_timer_create(&m_led_blink_timer, APP_TIMER_MODE_REPEATED, \
                                blink_timeout_handler);
    APP_ERROR_CHECK(err_code);

    // Create timer to control board LEDs when an echo response to the client is transmitted.
    err_code = app_timer_create(&m_echo_ind_timer, APP_TIMER_MODE_SINGLE_SHOT, \
                                response_ind_tout_handler);
    APP_ERROR_CHECK(err_code);
}