Beispiel #1
0
void conn_interval_select(void)
{
    NRF_LOG_INFO("Select a connection interval:\r\n");
    NRF_LOG_INFO(" 1) 7.5 ms\r\n");
    NRF_LOG_INFO(" 2) 50 ms\r\n");
    NRF_LOG_INFO(" 3) 400 ms\r\n");
    NRF_LOG_FLUSH();

    switch (NRF_LOG_GETCHAR())
    {
        case ONE:
        default:
            m_test_params.conn_interval = (uint16_t)(MSEC_TO_UNITS(7.5, UNIT_1_25_MS));
            break;

        case TWO:
            m_test_params.conn_interval = (uint16_t)(MSEC_TO_UNITS(50, UNIT_1_25_MS));
            break;

        case THREE:
            m_test_params.conn_interval = (uint16_t)(MSEC_TO_UNITS(400, UNIT_1_25_MS));
            break;
    }

    NRF_LOG_INFO("Connection interval set to 0x%x.\r\n", m_test_params.conn_interval);
    NRF_LOG_FLUSH();
}
Beispiel #2
0
void att_mtu_select(void)
{
    NRF_LOG_INFO("Select an ATT MTU size:\r\n");
    NRF_LOG_INFO(" 1) 23 bytes.\r\n");
    NRF_LOG_INFO(" 2) 158 bytes.\r\n");
    NRF_LOG_INFO(" 3) 247 bytes.\r\n");
    NRF_LOG_FLUSH();

    switch (NRF_LOG_GETCHAR())
    {
        case ONE:
        default:
            m_test_params.att_mtu = 23;
            break;

        case TWO:
            m_test_params.att_mtu = 158;
            break;

        case THREE:
            m_test_params.att_mtu = 247;
            break;
    }

    gatt_mtu_set(m_test_params.att_mtu);

    NRF_LOG_INFO("ATT MTU set to %u bytes.\r\n", m_test_params.att_mtu);
    NRF_LOG_FLUSH();
}
Beispiel #3
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();
    }
}
Beispiel #4
0
void data_len_ext_select(void)
{
    NRF_LOG_INFO("Turn on Data Length Extension? (y/n)\r\n");
    NRF_LOG_FLUSH();

    char answer = NRF_LOG_GETCHAR();
    NRF_LOG_INFO("Data Length Extension is %s\r\n", (answer == YES) ?
                 (uint32_t) "ON" :
                 (uint32_t) "OFF");
    NRF_LOG_FLUSH();

    m_test_params.data_len_ext_enabled = (answer == YES) ? 1 : 0;

    data_len_ext_set(m_test_params.data_len_ext_enabled);
}
void nrf_bootloader_app_start(void)
{
    uint32_t start_addr = MBR_SIZE; // Always boot from end of MBR. If a SoftDevice is present, it will boot the app.
    NRF_LOG_DEBUG("Running nrf_bootloader_app_start with address: 0x%08x", start_addr);
    uint32_t err_code;

    // Disable and clear interrupts
    // Notice that this disables only 'external' interrupts (positive IRQn).
    NRF_LOG_DEBUG("Disabling interrupts. NVIC->ICER[0]: 0x%x", NVIC->ICER[0]);

    NVIC->ICER[0]=0xFFFFFFFF;
    NVIC->ICPR[0]=0xFFFFFFFF;
#if defined(__NRF_NVIC_ISER_COUNT) && __NRF_NVIC_ISER_COUNT == 2
    NVIC->ICER[1]=0xFFFFFFFF;
    NVIC->ICPR[1]=0xFFFFFFFF;
#endif

    err_code = nrf_dfu_mbr_irq_forward_address_set();
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("Failed running nrf_dfu_mbr_irq_forward_address_set()");
    }

    NRF_LOG_FLUSH();
    nrf_bootloader_app_start_final(start_addr);
}
Beispiel #6
0
/** @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();

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));

    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. */

        NRF_LOG_INFO("Actual temperature: %d\r\n", (int)temp);
        nrf_delay_ms(500);

        NRF_LOG_FLUSH();
    }
}
Beispiel #7
0
void test_param_adjust(void)
{
    bool done = false;

    while (!done)
    {
        NRF_LOG_RAW_INFO("\r\n");
        NRF_LOG_INFO("Adjust test parameters:\r\n");
        NRF_LOG_INFO(" 1) Select ATT MTU size.\r\n");
        NRF_LOG_INFO(" 2) Select connection interval.\r\n");
        NRF_LOG_INFO(" 3) Turn on/off Data length extension (DLE).\r\n");
        NRF_LOG_INFO("Press ENTER when finished.\r\n");
        NRF_LOG_FLUSH();

        switch (NRF_LOG_GETCHAR())
        {
            case ONE:
                att_mtu_select();
                break;

            case TWO:
                conn_interval_select();
                break;

            case THREE:
                data_len_ext_select();
                break;

            case ENTER:
            default:
                done = true;
                break;
        }
    }
}
Beispiel #8
0
void menu_print(void)
{
    bool begin_test = false;

    while (!begin_test)
    {
        test_params_print();
        NRF_LOG_INFO("Throughput example:\r\n");
        NRF_LOG_INFO(" 1) Run test.\r\n");
        NRF_LOG_INFO(" 2) Adjust test parameters.\r\n");
        NRF_LOG_FLUSH();

        switch (NRF_LOG_GETCHAR())
        {
            case ONE:
            default:
                begin_test = true;
                test_begin();
                break;

            case TWO:
                test_param_adjust();
                break;
        }
    }

    m_print_menu = false;
}
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    LEDS_CONFIGURE(LEDS_MASK);                       //Configure all leds
    LEDS_OFF(LEDS_MASK);                             //Turn off all leds
	
    NRF_POWER->DCDCEN = 1;                           //Enabling the DCDC converter for lower current consumption
	
#ifdef UART_PRINTING_ENABLED
    uint32_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);                       //Configure Logging. LOGGING is used to show the SAADC sampled result. Default is UART, but RTT can be configured in sdk_config.h
    NRF_LOG_INFO("\n\rSAADC Low Power Example.\r\n");	
#endif //UART_PRINTING_ENABLED	

    lfclk_config();                                  //Configure low frequency 32kHz clock
    rtc_config();                                    //Configure RTC. The RTC will generate periodic interrupts. Requires 32kHz clock to operate.

    saadc_init();                                    //Initialize and start SAADC
    
    while (1)
    {
        if(m_saadc_calibrate == true)
        {
#ifdef UART_PRINTING_ENABLED
            NRF_LOG_INFO("SAADC calibration starting...  \r\n");    //Print on UART
#endif //UART_PRINTING_ENABLED	
            while(nrf_drv_saadc_calibrate_offset() != NRF_SUCCESS); //Trigger calibration task
            m_saadc_calibrate = false;
        }
        nrf_pwr_mgmt_run();
#ifdef UART_PRINTING_ENABLED
        NRF_LOG_FLUSH();
#endif //UART_PRINTING_ENABLED
    }
}
Beispiel #10
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    ret_code_t err_code;
    char config;
    
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    
    bsp_board_leds_init();

    err_code = clock_config();
    APP_ERROR_CHECK(err_code);
    
    APP_TIMER_INIT(APP_TIMER_PRESCALER, OP_QUEUES_SIZE, NULL);

    
    NRF_LOG_INFO("Capacitive sensing driver example.\r\n");
    
    csense_initialize();    

    NRF_LOG_INFO("Do you want to enter configuration mode to set thresholds?(y/n)\r\n");
    NRF_LOG_FLUSH();
    
    config = NRF_LOG_GETCHAR();
    
    conf_mode = (config == 'y') ? true : false;
    
    if (conf_mode)
    {
        configure_thresholds();
        conf_mode = false;
    }

    NRF_LOG_INFO("Module ready.\r\n");
    
    start_app_timer();    

    while (1)
    {
        NRF_LOG_FLUSH();
        __WFI();
    }
}
Beispiel #11
0
void test_run(void)
{
    NRF_LOG_RAW_INFO("\r\n");
    NRF_LOG_INFO("Test is ready. Press any key to run.\r\n");
    NRF_LOG_FLUSH();

    (void) NRF_LOG_GETCHAR();

    counter_start();
    nrf_ble_amts_notif_spam(&m_amts);
}
Beispiel #12
0
/**@brief Thread for handling the logger.
 *
 * @details This thread is responsible for processing log entries if logs are deferred.
 *          Thread flushes all log entries and suspends. It is resumed by idle task hook.
 *
 * @param[in]   arg   Pointer used for passing some arbitrary information (context) from the
 *                    osThreadCreate() call to the thread.
 */
static void logger_thread(void * arg)
{
    UNUSED_PARAMETER(arg);

    while(1)
    {
        NRF_LOG_FLUSH();

        vTaskSuspend(NULL); // Suspend myself
    }
}
Beispiel #13
0
void test_led(void)
{
  NRF_LOG_INFO("Turning LEDs on for a second\r\n");
  NRF_LOG_FLUSH();
  nrf_delay_ms(10);
  nrf_gpio_pin_clear(LED_RED);
  nrf_gpio_pin_clear(LED_GREEN);
  nrf_delay_ms(1000);
  nrf_gpio_pin_set(LED_RED);
  nrf_gpio_pin_set(LED_GREEN);
  nrf_delay_ms(10);
}
Beispiel #14
0
void test_params_print(void)
{
    NRF_LOG_RAW_INFO("\r\n");
    NRF_LOG_INFO("Current test configuration:\r\n");
    NRF_LOG_INFO("===============================\r\n");
    NRF_LOG_INFO("ATT MTU size: %u\r\n", m_test_params.att_mtu);
    NRF_LOG_INFO("Conn. interval: 0x%x\r\n", m_test_params.conn_interval);
    NRF_LOG_INFO("Data length extension (DLE): %s\r\n", m_test_params.data_len_ext_enabled ?
                 (uint32_t)"ON" :
                 (uint32_t)"OFF");
    NRF_LOG_DEBUG("Conn. event length ext.: %s\r\n", m_test_params.conn_evt_len_ext_enabled ?
                 (uint32_t)"ON" :
                 (uint32_t)"OFF");
    NRF_LOG_INFO("===============================\r\n");
    NRF_LOG_RAW_INFO("\r\n");
    NRF_LOG_FLUSH();
}
Beispiel #15
0
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    /** @snippet [NFC Launch App usage_1] */
    uint32_t len;
    uint32_t err_code;
    /** @snippet [NFC Launch App usage_1] */

    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    /* Configure LED-pins as outputs */
    bsp_board_leds_init();

    /* Set up NFC */
    err_code = nfc_t2t_setup(nfc_callback, NULL);
    APP_ERROR_CHECK(err_code);

    /** @snippet [NFC Launch App usage_2] */
    /*  Provide information about available buffer size to encoding function. */
    len = sizeof(m_ndef_msg_buf);

    /* Encode launchapp message into buffer */
    err_code = nfc_launchapp_msg_encode(m_android_package_name,
                                        sizeof(m_android_package_name),
                                        m_windows_application_id,
                                        sizeof(m_windows_application_id),
                                        m_ndef_msg_buf,
                                        &len);

    APP_ERROR_CHECK(err_code);
    /** @snippet [NFC Launch App usage_2] */

    /* Set created message as the NFC payload */
    err_code = nfc_t2t_payload_set(m_ndef_msg_buf, len);
    APP_ERROR_CHECK(err_code);

    /* Start sensing NFC field */
    err_code = nfc_t2t_emulation_start();
    APP_ERROR_CHECK(err_code);

    while (1)
    {
        NRF_LOG_FLUSH();
    }
}
Beispiel #16
0
int main(void)
{
    // Enable the constant latency sub power mode to minimize the time it takes
    // for the SPIS peripheral to become active after the CSN line is asserted
    // (when the CPU is in sleep mode).
    NRF_POWER->TASKS_CONSTLAT = 1;

    LEDS_CONFIGURE(BSP_LED_0_MASK);
    LEDS_OFF(BSP_LED_0_MASK);

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_INFO("SPIS example\r\n");

    nrf_drv_spis_config_t spis_config = NRF_DRV_SPIS_DEFAULT_CONFIG;
    spis_config.csn_pin               = APP_SPIS_CS_PIN;
    spis_config.miso_pin              = APP_SPIS_MISO_PIN;
    spis_config.mosi_pin              = APP_SPIS_MOSI_PIN;
    spis_config.sck_pin               = APP_SPIS_SCK_PIN;

    APP_ERROR_CHECK(nrf_drv_spis_init(&spis, &spis_config, spis_event_handler));

    while (1)
    {
        memset(m_rx_buf, 0, m_length);
        spis_xfer_done = false;

        APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, m_length, m_rx_buf, m_length));

        while (!spis_xfer_done)
        {
            __WFE();
        }

        NRF_LOG_FLUSH();

        LEDS_INVERT(BSP_LED_0_MASK);
    }
}
Beispiel #17
0
void test_begin(void)
{
    NRF_LOG_INFO("Preparing the test.\r\n");
    NRF_LOG_FLUSH();

    switch (m_gap_role)
    {
        default:
            // If no connection was established, the role won't be either.
            // In this case, start both advertising and scanning.
            advertising_start();
            scan_start();
            break;

        case BLE_GAP_ROLE_PERIPH:
            advertising_start();
            break;

        case BLE_GAP_ROLE_CENTRAL:
            scan_start();
            break;
    }
}
Beispiel #18
0
int main(void)
{
    log_init();

    leds_init();
    timer_init();
    counter_init();
    buttons_init();

    ble_stack_init();

    gap_params_init();
    conn_params_init();
    gatt_init();
    advertising_data_set();

    server_init();
    client_init();

    // Default ATT MTU size and connection interval are set at compile time.
    gatt_mtu_set(m_test_params.att_mtu);
    // Data Length Extension (DLE) is on by default.
    // Enable the Connection Event Length Extension.
    conn_evt_len_ext_set(m_test_params.conn_evt_len_ext_enabled);

    NRF_LOG_INFO("ATT MTU example started.\r\n");
    NRF_LOG_INFO("Press button 3 on the board connected to the PC.\r\n");
    NRF_LOG_INFO("Press button 4 on other board.\r\n");
    NRF_LOG_FLUSH();

    board_role_select();

    if (m_board_role == BOARD_TESTER)
    {
        m_print_menu = true;
    }
    if (m_board_role == BOARD_DUMMY)
    {
        advertising_start();
        scan_start();
    }

    // Enter main loop.
    NRF_LOG_DEBUG("Entering main loop.\r\n");
    for (;;)
    {
        if (m_print_menu)
        {
            menu_print();
        }

        if (is_test_ready())
        {
            m_run_test = true;
            test_run();
        }

        if (!NRF_LOG_PROCESS())
        {
            wait_for_event();
        }

    }
}
Beispiel #19
0
/**
 * @brief Function for configuring pads threshold.
 */
void configure_thresholds(void)
{
    ret_code_t err_code;
    uint32_t new_th_pad_1;
    uint32_t new_th_pad_2;
    
    for (int i = 0; i < 2; i++)
    {
        max_value[i] = 0;
        min_value[i] = UINT32_MAX;
    }
    
    NRF_LOG_INFO("Touch both pads.\r\n");
    NRF_LOG_FLUSH();
    nrf_delay_ms(1000);
    NRF_LOG_INFO("3...\r\n");
    NRF_LOG_FLUSH();
    nrf_delay_ms(1000);
    NRF_LOG_INFO("2...\r\n");
    NRF_LOG_FLUSH();
    nrf_delay_ms(1000);
    NRF_LOG_INFO("1...\r\n");
    NRF_LOG_FLUSH();
    
    err_code = nrf_drv_csense_sample();   
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_INFO("Busy.\n");
        return;
    }
    while (nrf_drv_csense_is_busy());
    
    NRF_LOG_INFO("Release both pads.\r\n");
    NRF_LOG_FLUSH();
    nrf_delay_ms(1000);
    NRF_LOG_INFO("3...\r\n");
    NRF_LOG_FLUSH();
    nrf_delay_ms(1000);
    NRF_LOG_INFO("2...\r\n");
    NRF_LOG_FLUSH();
    nrf_delay_ms(1000);
    NRF_LOG_INFO("1...\r\n");
    NRF_LOG_FLUSH();
    
    err_code = nrf_drv_csense_sample();   
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_INFO("Busy.\n");
        return;
    }
    while (nrf_drv_csense_is_busy());

    nrf_delay_ms(100);    
    new_th_pad_1 = max_value[PAD_ID_0];
    new_th_pad_1 += min_value[PAD_ID_0];
    new_th_pad_1 /= 2;
    new_th_pad_2 = max_value[PAD_ID_1];
    new_th_pad_2 += min_value[PAD_ID_1];
    new_th_pad_2 /= 2;
    threshold_value_pad1 = new_th_pad_1;
    threshold_value_pad2 = new_th_pad_2;
    NRF_LOG_INFO("New thresholds, AIN1: %d, AIN7: %d.\r\n", (unsigned int)new_th_pad_1,
                                                      (unsigned int)new_th_pad_2);
}