This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using freeRTOS to control BLE and FPU caculation and how to do low power

Hi,

I got the example http://github.com/NordicPlayground/nrf52-ble-multi-link-multi-role and the demo is OK. 

We are doing a game project using nRF52840 base on nRF52 SDK v15.2.
We have a lot of caculation with FPU,so I add freeRTOS to my code(base on ble_aggregator example) refer to ble_app_hrs_freertos example in the nRF52 SDK.
One task for BLE and one task for data caculation.

static void ble_task(void *arg)
{	
		advertising_start(); 	
		scan_start();                         
}
static void AppTask_demo(void * pvParameter)
{	
		if (pdPASS != xTimerStart(m_test_timer, OSTIMER_WAIT_FOR_QUEUE))
		{
				APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
		}					
		while(1)
		{
			  process_ble_commands();  	
		}
}
int main(void)
{
    ....
    ....
    ....
	nrf_sdh_freertos_init(ble_task, NULL);	                                 // Create a FreeRTOS task for the BLE stack.

    if (pdPASS != xTaskCreate(AppTask_demo, "123", 128, NULL, 1, &m_app_thread))
    {
        NRF_LOG_ERROR("Failed to create task.\n");
    }
    else
    {
        uart_printf("SPT FreeRTOS created.\n");
    }
		
    vTaskStartScheduler();
		
    uart_printf("Multilink example Target_periph_name \"%s\"\r\n", m_target_periph_name);

		
    for (;;)
    {	
		APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN);
    }
}

Now it runs good. But I'm afraid is this way good because Ihave not done data caculation now.  Besides, is there anywhere I need to pay more attention?


Another question, how to do low power to save power?

BR

Bruse

Parents
  • Hi Zhong,

    The basic design is simple and correct. Few points to remember though

    1. using uart_printf should only be a debug option and should not be included in release versions since uart logging is power intense as it uses HFCLK
    2. AppTask_demo does not seem to be yielding. Look at  taskYield. Everytask that you create must yield at some point to make the idle thread run at some point so that your device can enter low power states.
  • Thanks!

    I have add taskYield to the AppTask_demo task as follow. In the process_ble_commands, it also would calll API function to send data to APP or  forward data to APP from peripheral, or send data to peripheral, or forward data to peripheral from APP.  Would it be a problem although it works well now.

    static void AppTask_demo(void * pvParameter)
    {	
    		if (pdPASS != xTimerStart(m_test_timer, OSTIMER_WAIT_FOR_QUEUE))
    		{
    				APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    		}					
    		while(1)
    		{
    			  process_ble_commands();  	
    				taskYIELD();
    		}
    }

    By the way, power_manage function has not been called, do I need to call it somewhere to enter low power states?

Reply
  • Thanks!

    I have add taskYield to the AppTask_demo task as follow. In the process_ble_commands, it also would calll API function to send data to APP or  forward data to APP from peripheral, or send data to peripheral, or forward data to peripheral from APP.  Would it be a problem although it works well now.

    static void AppTask_demo(void * pvParameter)
    {	
    		if (pdPASS != xTimerStart(m_test_timer, OSTIMER_WAIT_FOR_QUEUE))
    		{
    				APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    		}					
    		while(1)
    		{
    			  process_ble_commands();  	
    				taskYIELD();
    		}
    }

    By the way, power_manage function has not been called, do I need to call it somewhere to enter low power states?

Children
Related