コード例 #1
0
/**
 * Function for application main entry.
 */
int main(void)
{	
    init_leds();
    init_clock();

    uint32_t err_code;

    // Button configuration structure.
    static app_button_cfg_t p_button[] = {  {BUTTON_1, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler},
                                            {BUTTON_2, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler},
                                            {BUTTON_3, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler},
                                            {BUTTON_4, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}};
        
    // Macro for initializing the application timer module.
    // It will handle dimensioning and allocation of the memory buffer required by the timer, making sure that the buffer is correctly aligned. It will also connect the timer module to the scheduler (if specified).
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, NULL);

    // Macro for initializing the GPIOTE module.
    // It will handle dimensioning and allocation of the memory buffer required by the module, making sure that the buffer is correctly aligned.
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);

    // Initializing the buttons.
    err_code = app_button_init(p_button, sizeof(p_button) / sizeof(p_button[0]), BUTTON_DEBOUNCE_DELAY);
    APP_ERROR_CHECK(err_code);
                                            
    // Enabling the buttons.										
    err_code = app_button_enable();
    APP_ERROR_CHECK(err_code);

    while(true)
    {
        // Do nothing.
    }
}
コード例 #2
0
ファイル: main.c プロジェクト: Dalsoo/Project2_20151023
int main(void)
{

//	uint32_t err_code;

    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();
    sys_Initialize();
    sys_Timer_Handler_Init();


    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();
    sec_params_init();

    sys_printf("Gift Air Project Start\n\r");

    advertising_start();
    sys_Timer_Handler_Start();
    NRF_WDT->RR[0] = WDT_RR_RR_Reload;  //Reload watchdog register 0

    // Enter main loop
    for (;;)
    {


        power_manage();       //2sec, 200ms
    }
}
コード例 #3
0
ファイル: main.c プロジェクト: 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();
    }
}
コード例 #4
0
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    // Configure LED-pins as outputs
    nrf_gpio_cfg_output(LED_0);
    nrf_gpio_cfg_output(LED_1);
    nrf_gpio_cfg_sense_input(BUTTON_0, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);    
    err_code = app_gpiote_user_register(&m_app_gpiote_my_id, (1 << BUTTON_0), (1 << BUTTON_0), gpiote_event_handler);
    APP_ERROR_CHECK(err_code);
    
    err_code = app_gpiote_user_enable(m_app_gpiote_my_id);
    APP_ERROR_CHECK(err_code);
    while(true)
    {
        nrf_gpio_pin_set(LED_1);

        nrf_delay_ms(500);

        nrf_gpio_pin_clear(LED_1);   

        nrf_delay_ms(500);
    }
}
コード例 #5
0
ファイル: main.c プロジェクト: rpi-fongming/nolem_m2d
int main(void)
{
    // If transport layer is using UART with flow control we need to get one
    // GPIOTE user for the CTS wakeup pin.
    APP_GPIOTE_INIT(1);

    leds_init();

    // Indicate that the application has started up. This can be used to verify that
    // application resets if reset button is pressed or the chip has been reset with
    // a debugger. The led will be off during reset.
    nrf_gpio_pin_set(MAIN_FUNCTION_LED_PIN_NO);

    connectivity_chip_reset();

    bluetooth_init();

    // Enter main loop.
    for (;;)
    {
        uint32_t err_code;

        // Start/restart advertising.
        if (m_start_adv_flag)
        {
            err_code = sd_ble_gap_adv_start(&m_adv_params);
            APP_ERROR_CHECK(err_code);
            nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO);
            m_start_adv_flag = false;
        }

        // Power management.
        power_manage();
    }
}
コード例 #6
0
ファイル: main.c プロジェクト: inamuj/ble_app_uart
/**@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();
		}
}
コード例 #7
0
ファイル: main.c プロジェクト: tkadom/TWBLE
int main(void)
{

    LEDS_CONFIGURE(LEDS_MASK);
    LEDS_OFF(LEDS_MASK);
    nrf_gpio_cfg_output(WAVE_ON_PIN_NUMBER); // on this pin 2Hz wave will be generated

#ifdef BSP_BUTTON_0
    // configure pull-up on first button
    nrf_gpio_cfg_input(BSP_BUTTON_0, NRF_GPIO_PIN_PULLUP);
#endif

    APP_GPIOTE_INIT(1);

    uart_config();

    lpcomp_init();

    printf("\n\rLPCOMP driver usage example\r\n");

    while (true)
    {
        print_statistics();
        LEDS_ON(BSP_LED_1_MASK);
        NRF_GPIO->OUTCLR = (1 << WAVE_ON_PIN_NUMBER);
        nrf_delay_ms(100); // generate 100 ms pulse on selected pin
        print_statistics();
        LEDS_OFF(BSP_LED_1_MASK);
        NRF_GPIO->OUTSET = (1 << WAVE_ON_PIN_NUMBER);
        nrf_delay_ms(400);
    }
}
コード例 #8
0
ファイル: main.c プロジェクト: dhruvkakadiya/OpenSJ_Bluz
/**@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));
    }
}
コード例 #9
0
ファイル: main.c プロジェクト: dhruvkakadiya/OpenSJ_Bluz
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;

    // Initialize.
    app_trace_init();
    timers_init();
    APP_GPIOTE_INIT(1);

    const app_uart_comm_params_t comm_params =
       {
           RX_PIN_NUMBER,
           TX_PIN_NUMBER,
           RTS_PIN_NUMBER,
           CTS_PIN_NUMBER,
           APP_UART_FLOW_CONTROL_ENABLED,
           false,
           UART_BAUDRATE_BAUDRATE_Baud38400
       };

    APP_UART_FIFO_INIT(&comm_params,
                          UART_RX_BUF_SIZE,
                          UART_TX_BUF_SIZE,
                          uart_error_handle,
                          APP_IRQ_PRIORITY_LOW,
                          err_code);

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

    device_manager_init();
    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();
    }
}
コード例 #10
0
ファイル: main.c プロジェクト: dhruvkakadiya/OpenSJ_Bluz
/** @brief Function for main application entry.
 */
int main(void)
{
    // This function contains workaround for PAN_028 rev2.0A anomalies 28, 29,30 and 31.
    int32_t volatile temp;

    nrf_temp_init();
    uint32_t err_code;
    APP_GPIOTE_INIT(1);
    const app_uart_comm_params_t comm_params =
     {
         RX_PIN_NUMBER,
         TX_PIN_NUMBER,
         RTS_PIN_NUMBER,
         CTS_PIN_NUMBER,
         APP_UART_FLOW_CONTROL_ENABLED,
         false,
         UART_BAUDRATE_BAUDRATE_Baud38400
     };

    APP_UART_FIFO_INIT(&comm_params,
                    UART_RX_BUF_SIZE,
                    UART_TX_BUF_SIZE,
                    uart_error_handle,
                    APP_IRQ_PRIORITY_LOW,
                    err_code);

    APP_ERROR_CHECK(err_code);

    while (true)
    {
        NRF_TEMP->TASKS_START = 1; /** Start the temperature measurement. */

        /* Busy wait while temperature measurement is not finished, you can skip waiting if you enable interrupt for DATARDY event and read the result in the interrupt. */
        /*lint -e{845} // A zero has been given as right argument to operator '|'" */
        while (NRF_TEMP->EVENTS_DATARDY == 0)
        {
            // Do nothing.
        }
        NRF_TEMP->EVENTS_DATARDY = 0;

        /**@note Workaround for PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register. */
        temp = (nrf_temp_read() / 4);

        /**@note Workaround for PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs. */
        NRF_TEMP->TASKS_STOP = 1; /** Stop the temperature measurement. */

        printf("Actual temperature: %d\n\r", (int)temp);
        nrf_delay_ms(500);
    }
}
コード例 #11
0
ファイル: board_pca10001.c プロジェクト: Jaden-J/IntroToBLE
void boardInit(void)
{
  uint32_t error;
  static app_button_cfg_t button_cfg[BOARD_BUTTON_NUM];

  /* Configure and enable the timer app */
	APP_TIMER_INIT(CFG_TIMER_PRESCALER, CFG_TIMER_MAX_INSTANCE, CFG_TIMER_OPERATION_QUEUE_SIZE, CFG_SCHEDULER_ENABLE);

  /* Initialise GPIOTE */
  APP_GPIOTE_INIT(CFG_GPIOTE_MAX_USERS);

  /* LED Settings */
  for(uint8_t i=0; i<BOARD_LED_NUM; i++)
  {
    nrf_gpio_cfg_output( led_gpio[i] );
  }

  /* Button Settings */
  for(uint8_t i=0; i<BOARD_BUTTON_NUM; i++)
  {
    /* Pins are configued with pullups since none are present on the PCB */
    button_cfg[i] = (app_button_cfg_t)
                    {
                      .pin_no = button_gpio[i],
                      .active_state = BOARD_BUTTON_ACTIVE_STATE ? true : false,
                      .pull_cfg = NRF_GPIO_PIN_PULLUP,
                      .button_handler = button_event_handler
                    };
  };

  APP_BUTTON_INIT(button_cfg, BOARD_BUTTON_NUM,
                  APP_TIMER_TICKS(BOARD_BUTTON_DETECTION_INTERVAL_MS, CFG_TIMER_PRESCALER), false);

  /* UART Settings */
  app_uart_comm_params_t para_uart =
  {
    .rx_pin_no    = BOARD_UART_RXD_PIN,
    .tx_pin_no    = BOARD_UART_TXD_PIN,
    .rts_pin_no   = BOARD_UART_RTS_PIN,
    .cts_pin_no   = BOARD_UART_CTS_PIN,
    .flow_control = APP_UART_FLOW_CONTROL_ENABLED,
    .use_parity   = false,
    .baud_rate    = get_baudrate(CFG_UART_BAUDRATE)
  };

  /* Initialise the UART FIFO */
  APP_UART_FIFO_INIT( &para_uart, CFG_UART_BUFSIZE, CFG_UART_BUFSIZE, board_uart_event_handler, APP_IRQ_PRIORITY_LOW, error);
  ASSERT_STATUS_RET_VOID( (error_t) error );
}
コード例 #12
0
ファイル: main.c プロジェクト: tkadom/TWBLE
int main(void)
{
    // Initialization of various modules.
    uint32_t err_code;

    const app_uart_comm_params_t comm_params =
       {
           RX_PIN_NUMBER,
           TX_PIN_NUMBER,
           RTS_PIN_NUMBER,
           CTS_PIN_NUMBER,
           APP_UART_FLOW_CONTROL_ENABLED,
           false,
           UART_BAUDRATE_BAUDRATE_Baud38400
       };

    APP_UART_FIFO_INIT(&comm_params,
                          UART_RX_BUF_SIZE,
                          UART_TX_BUF_SIZE,
                          uart_error_handle,
                          APP_IRQ_PRIORITY_LOW,
                          err_code);

    APP_ERROR_CHECK(err_code);
    app_trace_init();
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, NULL);
    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);

    printf("Heart rate collector example\r\n");
    ble_stack_init();
    device_manager_init();
    db_discovery_init();
    hrs_c_init();
    bas_c_init();

    // Start scanning for peripherals and initiate connection
    // with devices that advertise Heart Rate UUID.
    scan_start();

    for (;; )
    {
        power_manage();
    }
}
コード例 #13
0
uint32_t debug_init(void)
{
  uint32_t err_code;
    
    nrf_gpio_cfg_output(14);
  
    app_uart_comm_params_t params;
    params.baud_rate = UART_BAUDRATE_BAUDRATE_Baud38400;
    params.flow_control = APP_UART_FLOW_CONTROL_DISABLED;
    params.tx_pin_no = 17;
    params.rx_pin_no = 16;
    params.use_parity = false;
    
    APP_GPIOTE_INIT(1);
    
    //app_gpiote_user_enable()
    
    APP_UART_INIT(&params, uart_evt_handler, APP_IRQ_PRIORITY_HIGH, err_code);
    return err_code;
}
コード例 #14
0
ファイル: main.c プロジェクト: 451506709/automated_machine
static void bsp_configuration()
{
    // Start oscillator for app_timer
    NRF_CLOCK->LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART    = 1;

    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
    {
        // Do nothing.
    }

    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
    APP_GPIOTE_INIT(1);

    uint32_t err_code;
    err_code = bsp_init(BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), bsp_evt_handler);
    err_code = bsp_buttons_enable( (1 << BUTTON_PREV_ID) | (1 << BUTTON_NEXT_ID) );
    APP_ERROR_CHECK(err_code);
}
コード例 #15
0
ファイル: main.c プロジェクト: Abdellbar/nrf51
/**@brief Application main function.
 */
int main(void)
{
    APP_GPIOTE_INIT(1); 
    connectivity_chip_reset();
    
    leds_init();
    buttons_init();    
    bond_manager_init();
    ble_stack_init();
    ble_error_log_init();
    timers_init();
    nrf_gpio_pin_set(NRF6310_LED_5);
    gap_params_init();
    nrf_gpio_pin_clear(NRF6310_LED_5);
    advertising_init();
    services_init();
    sensor_sim_init();
    conn_params_init();
    sec_params_init();
    radio_notification_init();
   
    // Start execution
    application_timers_start();
    //m_start_adv_flag = true;
    advertising_start();
    
    // Enter main loop
    for (;;)
    {
//         uint32_t err_code;
//         // Start/restart advertising.
//         if (m_start_adv_flag)
//         {
//             err_code = sd_ble_gap_adv_start(&m_adv_params);
//             APP_ERROR_CHECK(err_code);
//             nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO);
//             m_start_adv_flag = false;
//         }
        power_manage();
    }
}
コード例 #16
0
ファイル: dfu_transport_serial.c プロジェクト: tkadom/TWBLE
uint32_t dfu_transport_update_start(void)
{
    uint32_t err_code;

    // Initialize data buffer queue.
    data_queue_init();

    dfu_register_callback(dfu_cb_handler);

    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);

    // Open transport layer.
    err_code = hci_transport_open();
    APP_ERROR_CHECK(err_code);

    // Register callback to be run when commands have been received by the transport layer.
    err_code = hci_transport_evt_handler_reg(rpc_transport_event_handler);
    APP_ERROR_CHECK(err_code);

    return NRF_SUCCESS;
}
コード例 #17
0
ファイル: main.c プロジェクト: tkadom/TWBLE
/**@brief Function for initializing buttons.
 */
void button_init(void)
{
    // Initialize timer module.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, NULL);

    // Initialize GPIOTE module.
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);

    // Initialize and enable button handler module.
    static app_button_cfg_t buttons[] =
    {
        {BSP_BUTTON_0, false, BUTTON_PULL, button_event_handler},
        {BSP_BUTTON_1, false, BUTTON_PULL, button_event_handler},
    };

    uint32_t err_code = app_button_init(buttons,
                                        sizeof(buttons) / sizeof(buttons[0]),
                                        BUTTON_DETECTION_DELAY);
    APP_ERROR_CHECK(err_code);

    err_code = app_button_enable();
    APP_ERROR_CHECK(err_code);
}
コード例 #18
0
/**@brief Function for initializing the GPIOTE handler module.
 */
static void gpiote_init(void)
{
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);
}
コード例 #19
0
void bicycle_power_rx_main_loop_run(void)
{
    uint32_t err_code;

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

    // Initialize GPIOTE module.
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);

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

    m_calibration_not_active = true;

    // Open ANT channel.
    bicycle_power_channel_open();

    bicycle_power_rx_init();

    bp_rx_calibration_cb_register(calibration_process_cb_handle);

    uint8_t                ant_channel;
    uint8_t                event_message_buffer[ANT_EVENT_MSG_BUFFER_MIN_SIZE];
    uint32_t               events;
    antplus_event_return_t antplus_event;

    // @note: When it is passed as a parameter to methods, the 32 bit type is used for events
    //        instead of the API defined 8 bit type due to performance reasons.
    uint32_t event = NO_EVENT;
    for (;;)
    {
        err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);

        // @note: Use local copy of event flags instead of the original one in order to allow the
        //        compiler more freedom to optimize the code as non-volatile variables do not need
        //        to be fetched from memory before each access.
        events = m_event_flags;
        while (events != 0)
        {
            // Check for button state event and execute handling if needed.
            if (events & EVT_BUTTON_0)
            {
                m_event_flags &= ~EVT_BUTTON_0;

                button_press_handle();
            }
            // Check for ANT stack IRQ event and execute handling if needed.
            if (events & EVT_ANT_STACK)
            {
                m_event_flags &= ~EVT_ANT_STACK;

                while (sd_ant_event_get(&ant_channel, (uint8_t*)&event, event_message_buffer)
                       == NRF_SUCCESS)
                {
                    if (bp_rx_channel_event_handle(event, event_message_buffer, &antplus_event))
                    {
                        // We have a pending profile -> application event to be processed.
                        profile_event_handle(&antplus_event);
                    }
                }
            }
            // Check for calibration response timeout event and execute handling if needed.
            if (events & EVT_CALIBRATION_RESPONSE_TIMEOUT)
            {
                m_event_flags &= ~EVT_CALIBRATION_RESPONSE_TIMEOUT;
                bp_rx_calibration_tout_handle();
            }
            // Take a fresh snapshot of possible new events, which require processing.
            events = m_event_flags;
        }
    }
}
コード例 #20
0
ファイル: main.c プロジェクト: Aidan-zhang/nRF51SDK
/**@brief Function for application main entry, does not return.
 */
int main(void)
{
    uint32_t err_code;
    
#ifdef TRACE_UART 
    // Configure and make UART ready for usage.
    const app_uart_comm_params_t comm_params =  
    {
        RX_PIN_NUMBER, 
        TX_PIN_NUMBER, 
        RTS_PIN_NUMBER, 
        CTS_PIN_NUMBER, 
        APP_UART_FLOW_CONTROL_DISABLED, 
        false, 
        UART_BAUDRATE_BAUDRATE_Baud38400
    }; 
        
    APP_UART_FIFO_INIT(&comm_params, 
                       UART_RX_BUF_SIZE, 
                       UART_TX_BUF_SIZE, 
                       uart_error_handle, 
                       APP_IRQ_PRIORITY_LOW,
                       err_code);
    APP_ERROR_CHECK(err_code);
#endif

    // Initialize timer module.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
      
    // Initialize GPIOTE module.  
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);
      
    // Initialize and enable button handler module. 
    static app_button_cfg_t buttons[] =
    {
        {BUTTON_0, false, BUTTON_PULL, button_event_handler},
        {BUTTON_1, false, BUTTON_PULL, button_event_handler},        
    };    
    APP_BUTTON_INIT(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY, false);    
        
    softdevice_setup();
        
    const antfs_params_t params =
    {
        ANTFS_CLIENT_SERIAL_NUMBER, 
        ANTFS_CLIENT_DEV_TYPE, 
        ANTFS_CLIENT_MANUF_ID, 
        ANTFS_LINK_FREQ,
        ANTFS_DEFAULT_BEACON | DATA_AVAILABLE_FLAG_MASK, 
        m_pass_key, 
        m_friendly_name
    };
    
    antfs_init(&params);
    antfs_channel_setup();

    m_pairing_state = PAIRING_OFF; 
    
    uint8_t event;
    uint8_t ant_channel;
    uint8_t event_message_buffer[ANT_EVENT_MSG_BUFFER_MIN_SIZE];  
    bool    allow_sleep;    
    for (;;)
    {
        allow_sleep = true;
        
        // Process ANT-FS event queue.
        if (antfs_event_extract(&m_antfs_event))
        {
            antfs_event_process(&m_antfs_event);
            allow_sleep = false;
        }

        // Process ANT event queue.
        if (sd_ant_event_get(&ant_channel, &event, event_message_buffer) == NRF_SUCCESS)
        {
            antfs_message_process(event_message_buffer);
            allow_sleep = false;
        }

        // Process user feedback for pairing authentication request.
        if (m_pairing_state != PAIRING_OFF)
        {
            pairing_user_feedback_handle();
            
            // Reset to default state as been processed.
            m_pairing_state = PAIRING_OFF;  
            allow_sleep     = false;
        }
        
        // Sleep if allowed.
        if (allow_sleep)
        {
            err_code = sd_app_evt_wait();
            APP_ERROR_CHECK(err_code);
        }
    }
}
コード例 #21
0
ファイル: main.c プロジェクト: tkadom/TWBLE
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    bool is_notification_mode    = false;
    bool is_non_connectable_mode = false;

    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);
#if BUTTONS_NUMBER > 2

    // Check button states.
    // Notification Start button.
    err_code = bsp_button_is_pressed(NOTIF_BUTTON_ID, &(is_notification_mode));
    APP_ERROR_CHECK(err_code);
    // Non-connectable advertisement start button.
    if (!is_notification_mode)
    {
        err_code = bsp_button_is_pressed(NON_CONN_ADV_BUTTON_ID, &(is_non_connectable_mode));
        APP_ERROR_CHECK(err_code);
    }
    // Un-configured button.
    else
    {
    }

#else
    is_notification_mode = true;
#endif

    // Initialize SoftDevice.
    ble_stack_init();

    if (!is_notification_mode && !is_non_connectable_mode)
    {
        // The startup was not because of button presses. This is the first start. 
        // Go into System-Off mode. Button presses will wake the chip up.
        err_code = sd_power_system_off();  
        APP_ERROR_CHECK(err_code);
    }
    
    // If we reach this point, the application was woken up by pressing one of the two configured
    // buttons.
    gap_params_init();

    if (is_notification_mode)
    {
        // Notification button is pressed. Start connectable advertisement.
        connectable_adv_init();
        service_add();
    }
    else
    {
        non_connectable_adv_init();
    }
    
    advertising_data_init();
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}