コード例 #1
0
ファイル: rtc_blinky.c プロジェクト: pcbreflux/nordic
/** @brief Function initialization and configuration of RTC driver instance.
 */
static void rtc_config(void) {
    uint32_t err_code;

    //Initialize RTC instance
    err_code = nrf_drv_rtc_init(&rtc1, NULL, rtc1_handler);
    APP_ERROR_CHECK(err_code);

    //Disable tick event & interrupt
    nrf_drv_rtc_tick_enable(&rtc1,false);

    /*
            |----|                              |----|
            |    |                              |    |
	____|    |______________________..._____|    |____...
         1s   1s             8s              1s   1s
    */

    //Set compare channel 0 to trigger interrupt after RTC1_CC_VALUE*125ms
    err_code = nrf_drv_rtc_cc_set(&rtc1,0,RTC1_CC_VALUE,true);
    APP_ERROR_CHECK(err_code);

    //Set compare channel 1 to trigger interrupt after RTC1_CC_VALUE*125ms*2
    err_code = nrf_drv_rtc_cc_set(&rtc1,1,RTC1_CC_VALUE*2,true);
    APP_ERROR_CHECK(err_code);

    //Set compare channel 2 to trigger interrupt after RTC1_CC_VALUE*125ms*9
    err_code = nrf_drv_rtc_cc_set(&rtc1,2,RTC1_CC_VALUE*10,true);
    APP_ERROR_CHECK(err_code);

    //Power on RTC instance
    nrf_drv_rtc_enable(&rtc1);
}
コード例 #2
0
ファイル: test.c プロジェクト: kkiningh/nrf-crypto-tests
int main(void) {
    uint32_t err_code;
    uint32_t time0, time1;

    LOG("Starting LFCLK");
    err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_clock_lfclk_request(NULL);

    LOG("Starting RTC");
    err_code = nrf_drv_rtc_init(&rtc, NULL, &rtc_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_rtc_tick_enable(&rtc, false);
    nrf_drv_rtc_enable(&rtc);

    LOG("Starting RNG");
    err_code = nrf_drv_rng_init(NULL);
    APP_ERROR_CHECK(err_code);

    while (1) {
        /* get a random key */
        time0 = nrf_drv_rtc_counter_get(&rtc);
        uECC_make_key(public_key, private_key); 
        time1 = nrf_drv_rtc_counter_get(&rtc);
        
        LOG("Key time was %u ", time1 - time0);

        /* use the key to sign the hash */
        time0 = nrf_drv_rtc_counter_get(&rtc);
        uECC_sign(private_key, hash, signature);
        time1 = nrf_drv_rtc_counter_get(&rtc);

        LOG("Sig Time was %u ", time1 - time0);

        /* verify the signature */
        time0 = nrf_drv_rtc_counter_get(&rtc);
        uECC_verify(public_key, hash, signature);
        time1 = nrf_drv_rtc_counter_get(&rtc);

        LOG("Verify Time was %u ", time1 - time0);
        
        time0 = nrf_drv_rtc_counter_get(&rtc);
        uECC_shared_secret(public_key, private_key, secret);
        time1 = nrf_drv_rtc_counter_get(&rtc);

        LOG("SS Time was %u ", time1 - time0);

        time0 = nrf_drv_rtc_counter_get(&rtc);
        sha256_init(&context);
        sha256_update(&context, message, 20);
        sha256_final(&context, shahash);
        time1 = nrf_drv_rtc_counter_get(&rtc);

        LOG("SHA Time was %u ", time1 - time0);
    }

    return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: dhruvkakadiya/OpenSJ_Bluz
void setup_example(void)
{
    uint32_t event;
    nrf_ppi_channel_t ppi_channel;
    uint32_t err_code;

    nrf_gpio_cfg_output(BSP_LED_0);

    err_code = nrf_drv_rtc_init(&rtc, NULL, rtc_evt_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_rtc_tick_enable(&rtc, false);
    event = nrf_drv_rtc_event_address_get(&rtc, NRF_RTC_EVENT_TICK);

    nrf_gpiote_task_config(0, BSP_LED_0, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);

    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_alloc(&ppi_channel);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_assign(ppi_channel,event,(uint32_t)&NRF_GPIOTE->TASKS_OUT[0]);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_enable(ppi_channel);
    APP_ERROR_CHECK(err_code);

    nrf_drv_rtc_enable(&rtc);
}
コード例 #4
0
ファイル: main.c プロジェクト: jrlitzenberger/pocketLab2
static void rtc_config(void)
{
    uint32_t err_code;

    // Initialize RTC instance with default configuration.
    err_code = nrf_drv_rtc_init(&m_rtc, NULL, rtc_handler);
    APP_ERROR_CHECK(err_code);

    // Enable tick event and interrupt.
    nrf_drv_rtc_tick_enable(&m_rtc, true);

    // Power on RTC instance.
    nrf_drv_rtc_enable(&m_rtc);
}
コード例 #5
0
static void rtc_config(void)
{

    uint32_t err_code;

    //Initialize RTC instance
    nrf_drv_rtc_config_t rtc_config;
    rtc_config.prescaler = RTC_FREQ_TO_PRESCALER(RTC_FREQUENCY);
    err_code = nrf_drv_rtc_init(&rtc, &rtc_config, rtc_handler);              //Initialize the RTC with callback function rtc_handler. The rtc_handler must be implemented in this applicaiton. Passing NULL here for RTC configuration means that configuration will be taken from the sdk_config.h file.
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_rtc_cc_set(&rtc,0,RTC_CC_VALUE,true);           //Set RTC compare value to trigger interrupt. Configure the interrupt frequency by adjust RTC_CC_VALUE and RTC_FREQUENCY constant in top of main.c
    APP_ERROR_CHECK(err_code);

    //Power on RTC instance
    nrf_drv_rtc_enable(&rtc);                                          //Enable RTC
}
コード例 #6
0
ファイル: main.c プロジェクト: IOIOI/nRF51
void setup_example(void)
{
    uint32_t event;
    nrf_ppi_channel_t ppi_channel;
    uint32_t err_code;

    nrf_gpio_cfg_output(BSP_LED_0);

    err_code = nrf_drv_rtc_init(&rtc, NULL, rtc_evt_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_rtc_tick_enable(&rtc, false);
    event = nrf_drv_rtc_event_address_get(&rtc, NRF_RTC_EVENT_TICK);

    if (!nrf_drv_gpiote_is_init())
    {
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code);
    }
    
    nrf_drv_gpiote_out_config_t pin_out_config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(false);
    err_code = nrf_drv_gpiote_out_init(BSP_LED_0,&pin_out_config);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_out_task_enable(BSP_LED_0);

    uint32_t gpiote_task_addr = nrf_drv_gpiote_out_task_addr_get(BSP_LED_0);

    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_alloc(&ppi_channel);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_assign(ppi_channel,event,gpiote_task_addr);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_enable(ppi_channel);
    APP_ERROR_CHECK(err_code);

    nrf_drv_rtc_enable(&rtc);
}
コード例 #7
0
ファイル: main.c プロジェクト: lyncxy119/Sentry
/** @brief Function initialization and configuration of RTC driver instance.
 */
static void rtc_config(void)
{
    uint32_t err_code;

    //Initialize RTC instance
    nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG;
    config.prescaler = 4095;
    err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler);
    APP_ERROR_CHECK(err_code);

    //Enable tick event & interrupt
    nrf_drv_rtc_tick_enable(&rtc,true);

    //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds
    err_code = nrf_drv_rtc_cc_set(&rtc,0,COMPARE_COUNTERTIME * 8,true);
    APP_ERROR_CHECK(err_code);

    //Power on RTC instance
    nrf_drv_rtc_enable(&rtc);
}
コード例 #8
0
ファイル: rtx.c プロジェクト: hexanoid/polymcu
int os_tick_init(void) {
	uint32_t err_code;

	// Initialize the clock
    err_code = nrf_drv_clock_init(NULL);
    assert(err_code == NRF_SUCCESS);
    nrf_drv_clock_lfclk_request();

    // Initialize RTC instance
    err_code = nrf_drv_rtc_init(&rtc1, NULL, NULL);
    assert(err_code == NRF_SUCCESS);

    // Enable tick event & interrupt
    nrf_drv_rtc_tick_enable(&rtc1, true);

    // Enable overflow
    nrf_drv_rtc_overflow_enable(&rtc1, false);

    // Power on RTC instance
    nrf_drv_rtc_enable(&rtc1);

    // Return -1 to prevent RTC touching NVIC
    return -1;  /* Return IRQ number of timer (0..239) */
}