Example #1
0
/**@brief Function for handling write events to the si7021 characteristic.
 *
 * @param[in] p_si7021  Instance of si7021 Service to which the write applies.
 * @param[in] led_state Written/desired state of the LED.
 */
static void blesi7021_write_handler(ble_si7021_t * p_si7021, ble_si7021_evt_t *evt) {
    uint32_t err_code;

    if (evt->evt_type == BLE_si7021_EVT_NOTIFICATION_ENABLED) {
    	NRF_LOG_INFO("BLE_si7021_EVT_NOTIFICATION_ENABLED\r\n");
        err_code = app_timer_start(m_si7021_timer_id, APP_TIMER_TICKS(p_si7021->interval, APP_TIMER_PRESCALER), NULL);
        APP_ERROR_CHECK(err_code);
        p_si7021->running=1;
    } else if (evt->evt_type == BLE_si7021_EVT_INTERVAL_CHANGE) {
    	NRF_LOG_INFO("BLE_si7021_EVT_INTERVAL_CHANGE %d\r\n",p_si7021->interval);
    	if (p_si7021->running==1) {
            err_code = app_timer_stop(m_si7021_timer_id);
            APP_ERROR_CHECK(err_code);
            p_si7021->running=0;

            err_code = app_timer_start(m_si7021_timer_id, APP_TIMER_TICKS(p_si7021->interval, APP_TIMER_PRESCALER), NULL);
            APP_ERROR_CHECK(err_code);
            p_si7021->running=1;
    	}
    } else { // BLE_si7021_EVT_NOTIFICATION_DISABLED | BLE_si7021_EVT_DISCONNECTED
    	NRF_LOG_INFO("BLE_si7021_EVT_NOTIFICATION_DISABLED\r\n");
        err_code = app_timer_stop(m_si7021_timer_id);
        APP_ERROR_CHECK(err_code);
        p_si7021->running=0;
    }
}
Example #2
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);
}
Example #3
0
error_t btle_gap_init(void)
{
    ble_gap_conn_params_t gap_conn_params = {0};

    gap_conn_params.min_conn_interval = msec_to_1_25msec(
                                            CFG_GAP_CONNECTION_MIN_INTERVAL_MS);  // in 1.25ms units
    gap_conn_params.max_conn_interval = msec_to_1_25msec(
                                            CFG_GAP_CONNECTION_MAX_INTERVAL_MS);  // in 1.25ms unit
    gap_conn_params.slave_latency     = CFG_GAP_CONNECTION_SLAVE_LATENCY;
    gap_conn_params.conn_sup_timeout  =
        CFG_GAP_CONNECTION_SUPERVISION_TIMEOUT_MS / 10; // in 10ms unit

    ble_gap_conn_sec_mode_t sec_mode;
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); // no security is needed

    // ASSERT_STATUS( sd_ble_gap_device_name_set(&sec_mode,   //_modify
                   // (const uint8_t *)
                   // CFG_GAP_LOCAL_NAME,
                   // strlen(CFG_GAP_LOCAL_NAME)));
    // ASSERT_STATUS( sd_ble_gap_appearance_set(CFG_GAP_APPEARANCE));
    // ASSERT_STATUS( sd_ble_gap_ppcp_set(&gap_conn_params));
    // ASSERT_STATUS( sd_ble_gap_tx_power_set(CFG_BLE_TX_POWER_LEVEL));
    nrf_err_check( sd_ble_gap_device_name_set(&sec_mode,  
                   (const uint8_t *)
                   CFG_GAP_LOCAL_NAME,
                   strlen(CFG_GAP_LOCAL_NAME)) );
    nrf_err_check( sd_ble_gap_appearance_set(CFG_GAP_APPEARANCE) );
    nrf_err_check( sd_ble_gap_ppcp_set(&gap_conn_params) );
    nrf_err_check( sd_ble_gap_tx_power_set(CFG_BLE_TX_POWER_LEVEL) );
    
    /* Connection Parameters */
    enum {
        FIRST_UPDATE_DELAY = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER),
        NEXT_UPDATE_DELAY  = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER),
        MAX_UPDATE_COUNT   = 3
    };

    ble_conn_params_init_t cp_init = {0};

    cp_init.p_conn_params                  = NULL;
    cp_init.first_conn_params_update_delay = FIRST_UPDATE_DELAY;
    cp_init.next_conn_params_update_delay  = NEXT_UPDATE_DELAY;
    cp_init.max_conn_params_update_count   = MAX_UPDATE_COUNT;
    cp_init.start_on_notify_cccd_handle    = BLE_GATT_HANDLE_INVALID;
    cp_init.disconnect_on_fail             = true;
    cp_init.evt_handler                    = NULL;
    cp_init.error_handler                  = error_callback;

    //ASSERT_STATUS ( ble_conn_params_init(&cp_init));   //_modify
    nrf_err_check( ble_conn_params_init(&cp_init) );
    
    return ERROR_NONE;
}
static void twi_light_sampling(void * p_context){
	UNUSED_PARAMETER(p_context);	
	static bool startup = true;
	static bool set_pin = true;
	uint32_t err_code;
	if(do_measurements){
		if(set_pin){
			set_pin = false;
			//TURN ON THE TRANSISTOR AND WAIT FOR IT TO STABILIZE
			nrf_gpio_pin_set(TSL2561_BASE_PIN);
			err_code = app_timer_start(iss_struct.meas_timer, APP_TIMER_TICKS(50, APP_TIMER_PRESCALER), NULL);
			APP_ERROR_CHECK(err_code);
		}else{
			uint8_t twi_data_tx[2] = {0,0};
			uint8_t twi_data_rx[2] = {0,0};
			uint8_t light_twi_command = TSL2561_COMMAND_BIT | TSL2561_CLEAR_BIT | TSL2561_WORD_BIT;
			if(startup){
				// POWER ON and wait 450 ms
				startup = false;
				twi_data_tx[0] = light_twi_command | TSL2561_REGISTER_CONTROL;
				twi_data_tx[1] = TSL2561_CONTROL_POWERON;
				err_code = !twi_master_write(light_sens_adr, twi_data_tx, 2,&my_twi_config);
				APP_ERROR_CHECK(err_code);
				err_code = app_timer_start(iss_struct.meas_timer, APP_TIMER_TICKS(450, APP_TIMER_PRESCALER), NULL);
				APP_ERROR_CHECK(err_code);
			}else{
				uint16_t ch0,ch1 = 0;
				twi_data_tx[0] = light_twi_command | TSL2561_REGISTER_CHAN0_LOW;	
				err_code = !twi_master_write_read(light_sens_adr, twi_data_tx, 1, twi_data_rx, 2,&my_twi_config);
				APP_ERROR_CHECK(err_code);
				ch0 = twi_data_rx[0];
				ch0 = ch0 | (((uint16_t)(twi_data_rx[1]))<<8);
				
				twi_data_tx[0] = light_twi_command | TSL2561_REGISTER_CHAN1_LOW;
				err_code = !twi_master_write_read(light_sens_adr, twi_data_tx, 1, twi_data_rx, 2,&my_twi_config);
				APP_ERROR_CHECK(err_code);
				ch1 = twi_data_rx[0];
				ch1 = ch1 | (((uint16_t)(twi_data_rx[1]))<<8);
				
				nrf_gpio_pin_clear(TSL2561_BASE_PIN);

				int32_t lux = calc_lux(ch0,ch1);
				err_code = update_iss_measurement(&iss_struct, &lux);
				APP_ERROR_CHECK(err_code);
				startup = true;
				set_pin = true;
				err_code = app_timer_start(iss_struct.meas_timer, APP_TIMER_TICKS(iss_struct.samp_freq_in_m_sec, APP_TIMER_PRESCALER), &iss_struct);
				APP_ERROR_CHECK(err_code);
			}	
		}		
	}
}
Example #5
0
File: main.c Project: tkadom/TWBLE
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    // Initialize.
    app_trace_init();
    ble_stack_init();
    device_manager_init();
    timers_init();
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);
    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
                        APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
                        NULL);
    APP_ERROR_CHECK(err_code);
    gap_params_init();
    advertising_init();
    services_init();
    sensor_simulator_init();
    conn_params_init();

    // Start execution.
    application_timers_start();
    advertising_start();

    // Enter main loop.
    for (;; )
    {
        power_manage();
    }
}
Example #6
0
/**
 * @brief Function for application main entry.
 * @return 0. int return type required by ANSI/ISO standard.
 */
int main(void)
{
    uint32_t err_code = NRF_SUCCESS;

    clock_initialization();
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);

    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);
    err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);

    // Set radio configuration parameters
    radio_configure();
    NRF_RADIO->PACKETPTR = (uint32_t)&packet;

    err_code = bsp_indication_set(BSP_INDICATE_USER_STATE_OFF);
    NRF_LOG_INFO("Wait for first packet\r\n");
    APP_ERROR_CHECK(err_code);
    NRF_LOG_FLUSH();    

    while (true)
    {
        uint32_t received = read_packet();

        err_code = bsp_indication_set(BSP_INDICATE_RCV_OK);
        NRF_LOG_INFO("Packet was received\r\n");
        APP_ERROR_CHECK(err_code);

        NRF_LOG_INFO("The contents of the package is %u\r\n", (unsigned int)received);
        NRF_LOG_FLUSH();
    }
}
Example #7
0
int main(void)
{
    uint32_t err_code;
    // Initialize.
    timers_init();
    err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);

    uart_init();
    ble_stack_init();

    twi_master_init();

    err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
    nrf_delay_ms(200);
    bsp_indication_set(BSP_INDICATE_IDLE);
    nrf_delay_ms(200);
    err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);

    update_sensor(0);
    start_advertising();
    timers_start();

    // Enter main loop.
    for (;; )
    {
        power_manage();
    }
}
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);

}
Example #9
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);
		
}
static void sensor_timer_start(uint16_t offset)
{
		uint32_t err_code;
		err_code = app_timer_start(iss_struct_h.meas_timer, APP_TIMER_TICKS(offset ? offset : iss_struct_h.samp_freq_in_m_sec, APP_TIMER_PRESCALER), NULL);
		APP_ERROR_CHECK(err_code);
		iss_struct_h.timer_running = true;
}
Example #11
0
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code = NRF_SUCCESS;

    // Initialize.
    ble_stack_init();
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);

    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
                        APP_TIMER_TICKS(APP_BUTTON_DETECTION_DELAY, APP_TIMER_PRESCALER),
                        bsp_event_handler);
    APP_ERROR_CHECK(err_code);

    // Initialize advertising.
    advertising_init();

    // Start execution.
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
    }
}
Example #12
0
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    // Initialize.
    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);
    ble_stack_init();
    advertising_init();

    // Start execution.
    NRF_LOG_INFO("BLE Beacon started\r\n");
    advertising_start();

    // Enter main loop.
    for (;; )
    {
        if (NRF_LOG_PROCESS() == false)
        {
            power_manage();
        }
    }
}
int main(void)
{
    uint32_t err_code;
    
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, NULL);
    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),NULL);
    APP_ERROR_CHECK(err_code);
    leds_init();
    timers_init();
    uart_init();
   
    ble_stack_init();
    device_manager_init();
    db_discovery_init();
    uart_c_init();
    
    printf("Scanning ...\r\n");
	
    // Start scanning for peripherals and initiate connection
    // with devices that advertise NUS UUID.
    scan_start();

    for (;;)
    {
        power_manage();
    }
}
Example #14
0
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    // Initialize.
    ble_stack_init();
    timers_init();
    APP_GPIOTE_INIT(1);
    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);
    device_manager_init();
    gap_params_init();
    advertising_init();
    services_init();
    sensor_simulator_init();
    conn_params_init();

    ble_evt_pool      = osPoolCreate(osPool(ble_evt_pool));
    ble_stack_msg_box = osMessageCreate(osMessageQ(ble_stack_msg_box), NULL);

    // Start execution.
    ble_stack_thread_id = osThreadCreate(osThread(ble_stack_thread), NULL);
    UNUSED_VARIABLE(ble_stack_thread_id);
    application_timers_start();
    advertising_start();

    // Enter main loop.
    for (;; )
    {
        UNUSED_VARIABLE(osDelay(1000));
    }
}
Example #15
0
/**@brief Function for handling NFC events.
 * Schedulers call to handler.
 */
void app_nfc_callback(void* p_context, nfc_t2t_event_t event, const uint8_t* p_data, size_t data_length)
{
  NRF_LOG_INFO("NFC\r\n");
  switch (event)
  {
    case NFC_T2T_EVENT_FIELD_ON:
      // NFC activation causes tag to hang sometimes. Fix this by reseting tag after a delay on NFC read.
      NRF_LOG_INFO("NFC Field detected \r\n");
      app_timer_start(reset_timer_id, APP_TIMER_TICKS(NFC_RESET_DELAY, RUUVITAG_APP_TIMER_PRESCALER), NULL);
      break;

    case NFC_T2T_EVENT_FIELD_OFF:
      NRF_LOG_INFO("NFC Field lost \r\n");
      app_sched_event_put (NULL, 0, reinit_nfc);
      if(APP_GATT_PROFILE_ENABLED)
      {
        app_sched_event_put (NULL, 0, become_connectable);
      }
      break;

    case NFC_T2T_EVENT_DATA_READ:
      NRF_LOG_INFO("Data read\r\n");
      break;
    
    default:
      break;
  }
}
Example #16
0
/**@brief Function for starting timers.
*/
static void timers_start(void)
{
    uint32_t err;
    
	err= app_timer_start(tmrOneSecondID, APP_TIMER_TICKS(1000, 0), NULL);
	APP_ERROR_CHECK(err);
}
Example #17
0
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;

    // Initialize.
    ble_stack_init();
    timers_init();

    err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);

    device_manager_init();
    gap_params_init();
    advertising_init();
    services_init();
    sensor_simulator_init();
    conn_params_init();
    
    beacon_scanner_init.evt_handler   = beacon_evt_handler;
    beacon_scanner_init.error_handler = beacon_scanner_error_handler;
    app_beacon_scanner_init(&beacon_scanner_init);
    app_beacon_scanner_start();

    // Start execution.
    application_timers_start();
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
/**@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[] =
    {
        {blink_timeout_handler,   LED_BLINK_INTERVAL_MS},
        {app_coap_time_tick,      COAP_TICK_INTERVAL_MS},
#ifdef COMMISSIONING_ENABLED
        {commissioning_time_tick, SEC_TO_MILLISEC(COMMISSIONING_TICK_INTERVAL_SEC)}
#endif // COMMISSIONING_ENABLED
    };

    // 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);

    // 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);
}
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));
    } 
} 
Example #20
0
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;

    clock_init();

    // Start APP_TIMER to generate timeouts.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);

    leds_init();

    err_code = bsp_init(BSP_INIT_BUTTONS,
                        APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
                        bsp_evt_handler);
    APP_ERROR_CHECK(err_code);

    nfc_init();

    m_active_led_mask = BSP_LED_0_MASK;
    err_code = led_softblink_start(m_active_led_mask);
    APP_ERROR_CHECK(err_code);

    while (true)
    {
        __WFE();
        softblink_led_update();
    }
}
Example #21
0
/**@brief  Application main function.
 */
int main(void)
{
	//printf("main");
    uint8_t start_string[] = START_STRING;
    uint32_t err_code;
    
    // Initialize.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);
    ble_stack_init();
    //uart_init();
    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
                        APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
                        NULL);
    APP_ERROR_CHECK(err_code);
    err_code = bsp_buttons_enable(1 << WAKEUP_BUTTON_ID);
    APP_ERROR_CHECK(err_code);
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();
    sec_params_init();
    
    printf("%s",start_string);
    advertising_start();
		
		init_leds();
	
		
    for (;;)
    {
        power_manage();
		}
}
Example #22
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);
}
Example #23
0
/**@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_coap_time_tick,    COAP_TICK_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);

    // 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);
}
Example #24
0
File: main.c Project: tkadom/TWBLE
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    // Initialize.
    app_trace_init();
    timers_init();
    gpiote_init();
    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
                        APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
                        button_event_handler);
    APP_ERROR_CHECK(err_code);
    ble_stack_init();
    adc_configure();
    device_manager_init();
    gap_params_init();
    advertising_init(BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE);
    services_init();
    conn_params_init();

    // Start execution.
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
Example #25
0
/**@brief Function for the timer, tracer, and BSP initialization.
 */
static void utils_setup(void)
{
    uint32_t err_code;

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

#if MODIFICATION_TYPE == MODIFICATION_TYPE_AUTO
    err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
#else
    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
                        APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
                        bsp_evt_handler);
#endif
    APP_ERROR_CHECK(err_code);
}
/**@brief Function for starting the advertising interval timer.*/
static void adv_interval_timer_start(void)
{
    ret_code_t err_code;
    intervals_calculate();
    err_code = app_timer_start(m_eddystone_adv_interval_timer,APP_TIMER_TICKS(m_intervals.adv_intrvl,APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);
}
Example #27
0
/**@brief Function for starting timers.
*/
static void timers_start(void)
{
    
    uint32_t err_code;

    err_code = app_timer_start(m_my_timer_id, APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER) , NULL);
    APP_ERROR_CHECK(err_code);
}
Example #28
0
/**@brief Function for initializing bsp module.
 */
void bsp_init_app(void)
{
    uint32_t err_code;
    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);
}
Example #29
0
void sys_Timer_Handler_Start(void)
{
    uint32_t err_code;

    err_code  =app_timer_start(m_Main_timer_id, APP_TIMER_TICKS(MAIN_TIMER_TICK, APP_TIMER_PRESCALER),NULL);
    APP_ERROR_CHECK(err_code);

}
Example #30
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);
}