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.
Reply
  • 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.
Children
  • 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?

  • Seems like your code looks good now.

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

    If you have enable tickless idle in FreeRTOSConfig.h file, then you do not explicitly do anything as tickless idle will handle sleep for you, but if you are not using tickless idle, then you need to call the power_manage function to make the chip go to sleep in idle states.

  • Hi Susheel,

    I'm not sure. It seems I have not enable tickless idle in FreeRTOSConfig.h file.

    Which is the macro definition in FreeRTOSConfig.h file? Attachment is my file.

    4667.FreeRTOSConfig.h

  • seems like you did enable it

    #define configUSE_TICKLESS_IDLE 1

Related