Пример #1
0
/** @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
int main(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);

    /* Configure LED-pins as outputs */
    LEDS_CONFIGURE(LEDS_MASK);
    LEDS_OFF(LEDS_MASK);

    /* Create task for LED0 blinking with priority set to 2 */
    UNUSED_VARIABLE(xTaskCreate(led_toggle_task_function, "LED0", configMINIMAL_STACK_SIZE + 200, NULL, 2, &led_toggle_task_handle));

    /* Start timer for LED1 blinking */
    led_toggle_timer_handle = xTimerCreate( "LED1", TIMER_PERIOD, pdTRUE, NULL, led_toggle_timer_callback);
    UNUSED_VARIABLE(xTimerStart(led_toggle_timer_handle, 0));

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

    /* Start FreeRTOS scheduler. */
    vTaskStartScheduler();

    while (true)
    {
        /* FreeRTOS should not be here... FreeRTOS goes back to the start of stack
         * in vTaskStartScheduler function. */
    }
}
Пример #4
0
int main(void)
{
    TaskHandle_t  xLed0Handle;       /**< Reference to LED0 toggling FreeRTOS task. */
    TimerHandle_t xLed1Handle;       /**< Reference to LED1 toggling FreeRTOS timer. */
    ret_code_t err_code;

    err_code = nrf_drv_clock_init(NULL);
    APP_ERROR_CHECK(err_code);

    // Configure LED-pins as outputs
    nrf_gpio_cfg_output(BSP_LED_0);
    nrf_gpio_cfg_output(BSP_LED_1);
    nrf_gpio_cfg_output(BSP_LED_2);
    nrf_gpio_cfg_output(BSP_LED_3);
    nrf_gpio_pin_set(BSP_LED_0);
    nrf_gpio_pin_set(BSP_LED_1);
    nrf_gpio_pin_set(BSP_LED_2);
    nrf_gpio_pin_set(BSP_LED_3);

    UNUSED_VARIABLE(xTaskCreate( vLed0Function, "L0", configMINIMAL_STACK_SIZE + 200, NULL, 2, &xLed0Handle ));    // LED0 task creation
    xLed1Handle = xTimerCreate( "L1", TIMER_PERIOD, pdTRUE, NULL, vLed1Callback );                                 // LED1 timer creation
    UNUSED_VARIABLE(xTimerStart( xLed1Handle, 0 ));                                                                // LED1 timer start

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

    // Start FreeRTOS scheduler.
    vTaskStartScheduler();

    while (true)
    {
        // FreeRTOS should not be here...
    }
}
Пример #5
0
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);
}
Пример #6
0
/**@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);
}
Пример #7
0
void nrf_drv_clock_on_sd_enable(void)
{
    CRITICAL_REGION_ENTER();
    /* Make sure that nrf_drv_clock module is initialized */
    if (!m_clock_cb.module_initialized)
    {
        (void)nrf_drv_clock_init();
    }
    /* SD is one of the LFCLK requesters, but it will enable it by itself. */
    ++(m_clock_cb.lfclk_requests);
    m_clock_cb.lfclk_on = true;
    CRITICAL_REGION_EXIT();
}
Пример #8
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;
}
Пример #9
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();
    }
}
Пример #10
0
/**@brief Function for application main entry.
 */
int main(void)
{
    ret_code_t err_code;
    err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);

    // Do not start any interrupt that uses system functions before system initialisation.
    // The best solution is to start the OS before any other initalisation.

    // Init a semaphore for the BLE thread.
    m_ble_event_ready = xSemaphoreCreateBinary();
    if (NULL == m_ble_event_ready)
    {
        APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    }

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

    // Start execution.
    if (pdPASS != xTaskCreate(ble_stack_thread, "BLE", 256, NULL, 2, &m_ble_stack_thread))
    {
        APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    }

#if NRF_LOG_ENABLED
    // Start execution.
    if (pdPASS != xTaskCreate(logger_thread, "LOGGER", 256, NULL, 1, &m_logger_thread))
    {
        APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    }
#endif //NRF_LOG_ENABLED

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

    // Start FreeRTOS scheduler.
    vTaskStartScheduler();

    while (true)
    {
        APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN);
    }
}
Пример #11
0
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;

}
Пример #12
0
/**
 * @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();
    }
}
Пример #13
0
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) */
}
Пример #14
0
/*====================================================================================================*/
void NRF51_CKOCK_Config( void )
{
  nrf_drv_clock_init();
}
Пример #15
0
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);
}
Пример #16
0
/*====================================================================================================*/
void Clock_Config( void )
{
  nrf_drv_clock_init();
}
Пример #17
0
/** @brief Function for main application entry.
 */
int main(void)
{
	  TaskHandle_t  compress_task_handle;
	  TimerHandle_t spi_timer_handle;
	
	
	  uint32_t err_code;
	
	  err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);
	
    // Setup bsp module.
    //bsp_configuration();

    //uart initialization
    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);
			
		//nrf_drv_gpiote_out_config_t config = GPIOTE_CONFIG_OUT_TASK_HIGH;
		//config.init_state = true;
		//err_code = nrf_drv_gpiote_out_init(20, &config);

		//while(app_uart_put(65) != NRF_SUCCESS);
		//printf("1 ms = %d\n", pdMS_TO_TICKS(1));
		intan_setup();
		//while(app_uart_put(65) != NRF_SUCCESS);
			
		compression_init();
			
		uesb_config_t uesb_config = UESB_DEFAULT_CONFIG;
		uesb_config.event_handler = uesb_event_handler;
		if (uesb_init(&uesb_config)!= UESB_SUCCESS) {
				printf("ESB init messed up\r\n");
		}
		tx_payload.length = UESB_CORE_MAX_PAYLOAD_LENGTH;
		tx_payload.pipe = 0;
		
		while(app_uart_put(66) != NRF_SUCCESS);
			
	  //printf("yo\n");
		UNUSED_VARIABLE(xTaskCreate(compress_task, "c_task", configMINIMAL_STACK_SIZE + 200, NULL, 1, &compress_task_handle));
			
		if(compress_task_handle == NULL)
		{
			printf("compression task init messed up\r\n");
		}
		while(app_uart_put(67) != NRF_SUCCESS);
		
		//Test read intan company ID timer
		//spi_timer_handle = xTimerCreate("s_timer", 1, pdTRUE, NULL, spi_intan_id_handler);
		
		// Sample timer
    spi_timer_handle = xTimerCreate("s_timer", 1, pdTRUE, NULL, spi_data_collection_evt_handler);                                 // LED1 timer creation
    
		if(spi_timer_handle == NULL)
		{
			printf("SPI timer init messed up\r\n");
		}
		while(app_uart_put(68) != NRF_SUCCESS);
		
		if(xTimerStart(spi_timer_handle, 0) != pdPASS)
		{
			printf("Timer could not be started\r\n");
		}
		while(app_uart_put(69) != NRF_SUCCESS);
			
		/* Activate deep sleep mode */
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

    // Start FreeRTOS scheduler.
    vTaskStartScheduler();
			
		//timers_init();
		//while(app_uart_put(67) != NRF_SUCCESS);
			
		//data_collection_timers_start();
		//while(app_uart_put(68) != NRF_SUCCESS);

    for (;;)
    {
			  printf("Messed up\r\n");
			  //power_manage();
        /*if (m_transfer_completed)
        {
					  //while(app_uart_put(72) != NRF_SUCCESS);
            m_transfer_completed = false;

            intan_convert(m_tx_data_spi, m_rx_data_spi,intan_convert_channel);
					  //while(app_uart_put(73) != NRF_SUCCESS);
            intan_convert_channel ++;
            intan_convert_channel = intan_convert_channel % 32;
            //print m_rx_data_spi results
            switch_state();
					  //while(app_uart_put(74) != NRF_SUCCESS);
					  //for (int i; i< RX_MSG_LENGTH; i++){
						//	while(app_uart_put(m_rx_data_spi[i]) != NRF_SUCCESS);
						//}
            nrf_delay_ms(DELAY_MS);
						//while(app_uart_put(75) != NRF_SUCCESS);
        }*/
				//while(app_uart_put(76) != NRF_SUCCESS);
    }
}