This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

creating my own low power delay, using app_timer

Hi there Devs,

My app is based on ble_app_blinky_c where I added a couple TWI sensors where check periodically every 10s and also scan for peripherals about every 10s 

Then I have to wait for certain time between 10-80ms in some cases for when I start a communication with a TWI sensor until it returns some data

there I implement a LowPowerDelay, where every time it is called calls sd_app_evt_wait until the time is elapse and exits from the sleep mode, which is supposed to be in the main context and not blocking others IRQs.

Is it assumption right?? because some times my device freezes and it is still a unknown source for me what is producing this behavior, I believe it could be related to the low power delay and the loop calling sd_app_evt_wait

 

#include "LowPowerDelay.h"

bool LowPowerDelay::delay;

LowPowerDelay::LowPowerDelay()
{
	app_timer_create(&LPDelay, APP_TIMER_MODE_SINGLE_SHOT, &LowPowerDelay::DelayCb);
}

void LowPowerDelay::DelayCb(void *p_context){	
	LowPowerDelay::delay = true;
}

void LowPowerDelay::Delay(uint32_t ms)
{
	LowPowerDelay::delay = false;
	app_timer_start(LPDelay, APP_TIMER_TICKS(ms), NULL);
	
	while (!LowPowerDelay::delay){
			APP_ERROR_CHECK(sd_app_evt_wait());
	}
}

#ifndef _LOWPOWERDELAY
#define _LOWPOWERDELAY
#include "Headers.h"
#include "Timer.h"

APP_TIMER_DEF(LPDelay);

class LowPowerDelay
{
	public:
	LowPowerDelay();
	
		static LowPowerDelay * Instance()
		{
			static LowPowerDelay instance;
			return &instance;
		}	
	
	static void DelayCb(void *p_context);
	void Delay(uint32_t ms);
		
	static bool delay;
};
#endif

nRF52832 SDK13

Parents Reply
  • Hi  I think I got what you said about LowPowerDelay:: is being called in two different context.

    but it does not mean I have to call LowPowerDelay:: disabling the interruptions? also when LowPowerDelay::Delay() calls sd_app_evt_wait a BLE event can occurs, which have more priority and is going to be proceeded, then returning to the Delay Function until the timer fires calling the handler quickly

    (1) Every LowPowerDelay::Delay() it is being called from the main context after being fired a scheduler queue event

    (2) LowPowerDelay::DelayCb(void *p_context) the handler for the timer event, it is being called from itself interrupt context

Children
Related