Busy loop for hardware watchdog

4 posts / 0 new
Last post
oren
Offline
Last seen:1 year 7 months ago
Expert
Joined:2014-06-28 22:03
Busy loop for hardware watchdog

Hi,
We have a problem in our modules - ~5% of the modules do not start advertising right when the battery is inserted, and reset is needed - i.e. removing the battery and reinserting it.

We were advised to add the following line at the beginning of the main_func(void) in arch_main.c:
SetBits16(BANDGAP_REG, LDO_RET_TRIM, 0x08);

This did not work, so we were also advised to add a ~100ms sleep beforehand.
我知道如何使用app_easy_timerwhen my app is running, but I think it should not be used in main_func(void) - the data is not initialized for that....

How can I do a 100ms "busy-loop" sleep?
I could do something like:
for (int x = 0; x < LIMIT; x++) {
// do nothing
}

What should be LIMIT if I want the time to be ~100ms?

Regards,
Oren

Keywords:
Device:
MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
Joined:2015-06-08 11:34
Hi oren,

Hi oren,

I need a few clarifications on that, you need to add a 100ms delay before which point ? before any kind of BLE operation starts (in the main_func() just before the main while) ? Also using the for loop that you ve mentioned means that the device is going to be awake, this kind of delay needs the M0 awake, and also there is a default setting of delaying the sleep for about two seconds in order for the XTAL32 to settle so if you need to spend some time at that point there is no option for sleeping at least with the default settings. Regarding the value in the for loop you can measure it either with some toggling GPIOs or by using the arch_set_pxact_gpio() and the power profiler, i measure about 100ms with 320000 in the for loop, using GPIO toggling and a logic analyser.

Thanks MT_dialog

oren
Offline
Last seen:1 year 7 months ago
Expert
Joined:2014-06-28 22:03
OK,

OK,
I think I found a similar function to do what I need in adc.c:


void adc_usDelay(uint32_t nof_us)
{
while( nof_us-- ){
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
}
}

Yes, I need to do the sleep in the main_func before system_init (which is even before the while loop).

Thanks,
Oren

MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
Joined:2015-06-08 11:34
Hi oren,

Hi oren,

Yes, this should do as well, just to be clear, when you do this the device wont be sleeping, you wont be able to sleep before the device enters the main while loop and before the 2 seconds of settling XTAL32 have passed.

Thanks MT_dialog