示例#1
0
文件: main.c 项目: lyncxy119/Sentry
/** @brief Function starting the internal LFCLK XTAL oscillator.
 */
static void lfclk_config(void)
{
    ret_code_t err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_clock_lfclk_request(NULL);
}
示例#2
0
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
文件: alarm.c 项目: aeliot/openthread
void nrf5AlarmInit(void)
{
    sTimeOffset = 0;
    memset(sTimerData, 0, sizeof(sTimerData));

    // Setup low frequency clock.
    nrf_drv_clock_lfclk_request(NULL);

    while (!nrf_drv_clock_lfclk_is_running()) {}

    // Setup RTC timer.
    NVIC_SetPriority(RTC_IRQN, RTC_IRQ_PRIORITY);
    NVIC_ClearPendingIRQ(RTC_IRQN);
    NVIC_EnableIRQ(RTC_IRQN);

    nrf_rtc_prescaler_set(RTC_INSTANCE, 0);

    nrf_rtc_event_clear(RTC_INSTANCE, NRF_RTC_EVENT_OVERFLOW);
    nrf_rtc_event_enable(RTC_INSTANCE, RTC_EVTEN_OVRFLW_Msk);
    nrf_rtc_int_enable(RTC_INSTANCE, NRF_RTC_INT_OVERFLOW_MASK);

    for (uint32_t i = 0; i < kNumTimers; i++)
    {
        nrf_rtc_event_clear(RTC_INSTANCE, sChannelData[i].mCompareEvent);
        nrf_rtc_event_disable(RTC_INSTANCE, sChannelData[i].mCompareEventMask);
        nrf_rtc_int_disable(RTC_INSTANCE, sChannelData[i].mCompareInt);
    }

    nrf_rtc_task_trigger(RTC_INSTANCE, NRF_RTC_TASK_START);
}
示例#4
0
文件: main.c 项目: lyncxy119/Sentry
static void clock_init(void)
{
    uint32_t err_code;
    err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_clock_lfclk_request(NULL);
}
/**@brief Ladybug_Flash uses an app timer.  App timers require the low frequency clock to be ticking.
 * Initialize the timer module.
 * \callgraph
 */
static void timers_init(void){
  // Initialize the low frequency clock.
  uint32_t err_code = nrf_drv_clock_init(NULL);
  APP_ERROR_CHECK(err_code);
  nrf_drv_clock_lfclk_request();
  // Initialize the timer queue.
  APP_TIMER_INIT(m_app_timer_prescaler, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
}
/*
 * Setup the RTC time to generate the tick interrupts at the required
 * frequency.
 */
void vPortSetupTimerInterrupt( void )
{
    /* Request LF clock */
    nrf_drv_clock_lfclk_request();

    /* Configure SysTick to interrupt at the requested rate. */
    nrf_rtc_prescaler_set(portNRF_RTC_REG, portNRF_RTC_PRESCALER);
    nrf_rtc_int_enable   (portNRF_RTC_REG, RTC_INTENSET_TICK_Msk);
    nrf_rtc_task_trigger (portNRF_RTC_REG, NRF_RTC_TASK_CLEAR);
    nrf_rtc_task_trigger (portNRF_RTC_REG, NRF_RTC_TASK_START);

    NVIC_SetPriority(portNRF_RTC_IRQn, configKERNEL_INTERRUPT_PRIORITY);
    NVIC_EnableIRQ(portNRF_RTC_IRQn);
}
示例#7
0
/** 
 * @brief Function for starting the internal LFCLK XTAL oscillator.
 *
 * Note that when using a SoftDevice, LFCLK is always on.
 *
 * @return Values returned by @ref nrf_drv_clock_init.
 */
static ret_code_t clock_config(void)
{
    ret_code_t err_code;

    err_code = nrf_drv_clock_init();
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    nrf_drv_clock_lfclk_request(NULL);

    return NRF_SUCCESS;
}
示例#8
0
文件: main.c 项目: IOIOI/nRF51
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);
    setup_example();

    while (true)
    {
        nrf_delay_ms(1000);
        nrf_drv_clock_lfclk_request(NULL);

        nrf_delay_ms(1000);
        nrf_drv_clock_lfclk_release();
    }
}
示例#9
0
文件: rhinorun.c 项目: wosayttn/aos
void soc_init(void)
{
    ret_code_t err_code;
	
    /* Initialize clock driver for better time accuracy in FREERTOS */
    err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);
	nrf_drv_clock_lfclk_request(NULL);
	app_timer_init();
    /* Configure LED-pins as outputs */
    bsp_board_leds_init();
	
	/* Init systick driver */
    nrf_drv_systick_init();

    /* Activate deep sleep mode */
//    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

}
示例#10
0
文件: main.c 项目: BlueSkyGjj/nRF52
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    uint32_t err_code = NRF_SUCCESS;
    
    //BSP configuration for button support: button pushing will feed the dog.
    err_code = nrf_drv_clock_init(NULL);
    APP_ERROR_CHECK(err_code);
    nrf_drv_clock_lfclk_request();

    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
    err_code = bsp_init(BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), bsp_event_callback);
    APP_ERROR_CHECK(err_code);
    
    //Configure all LEDs on board.
    LEDS_CONFIGURE(LEDS_MASK);
    LEDS_OFF(LEDS_MASK);
    
    //Indicate program start on LEDs.
    for(uint32_t i = 0; i < LEDS_NUMBER; i++)
    {   nrf_delay_ms(200);
        LEDS_ON(BSP_LED_0_MASK << i);
    }
     err_code = bsp_buttons_enable();
     APP_ERROR_CHECK(err_code);
    
    //Configure WDT.
    nrf_drv_wdt_config_t config = NRF_DRV_WDT_DEAFULT_CONFIG;
    err_code = nrf_drv_wdt_init(&config, wdt_event_handler);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_wdt_channel_alloc(&m_channel_id);
    APP_ERROR_CHECK(err_code);
    nrf_drv_wdt_enable();

    while(1)
    {
        __SEV();
        __WFE();
        __WFE();
    }
}
示例#11
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) */
}
static void lfclk_config(void)
{
    ret_code_t err_code = nrf_drv_clock_init();                        //Initialize the clock source specified in the nrf_drv_config.h file, i.e. the CLOCK_CONFIG_LF_SRC constant
    APP_ERROR_CHECK(err_code);
    nrf_drv_clock_lfclk_request(NULL);
}