8 years, 2 months ago.

Is there documentation on how to call/set blocksleepmode in the mbed sleep.c routine?

I have a routine where I have written my own LETIMER and ADC routines. To insure that I do not go into the wrong sleep mode while the ADC is running, I need to block the sleep.c routine from entering EM2.

Is there documentation on how to call/set blocksleepmode in the mbed sleep.c routine?

1 Answer

8 years, 2 months ago.

Hi Keith, sadly, the sleep mode API is not standardized across mbed. This means that code targeting the EFM32s using blockSleepMode() will only work on EFM32. However, considering that you're using the LETIMER, your code is probably pretty EFM32 dependent anyway.

There is documentation for the block/unblockSleepMode functions inline in sleep.c: https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/sleep.c#L80

In summary, call blockSleepMode(EM1); to prevent going deeper than EM1 (i.e. block EM2, EM3 and EM4), etc. Every call to blockSleepMode() should have a corresponding call to unblockSleepMode() when the resource is freed. You need to include sleepmodes.h in order to use these functions in your library.

Please note, however, that these functions are part of the EFM32 target-dependent mbed HAL implementation. Like all parts of the mbed HAL, there are no guarantees of API stability (see https://developer.mbed.org/handbook/mbed-library-internals#mbed-hal-api).

There appears to be some timing dependency between calling blockSleepMode(EM1) and requesting the start of an ADC conversion, ADC_Start(ADC0, adcStartSingle). If I do not have the following delay, I get an intermittent bad value out of the ADC, for(j=0;j<64;j++); With the "for loop", the code appears to be solid. The code also works if I tune down the CPU clock from 28MHz to 1MHz. From looking at the blockSleepMode() routine, the only line of code I could image that would have some sort of timing dependency would be the last line of code, INT_Enable(), but I do not understand why it would. Do you know why there is a timing dependency, and is there a way that I could read a register or another deterministic way that I could determine to move onto the ADC_Start(ADC0, adcStartSingle) command than some "for loop?"

posted by Keith Graham 29 Dec 2015

Hi Keith, could you post a code example of code that fails? The delay you are mentioning sounds like it would be enough to make the ADC conversion finish even before going to sleep...

posted by Steven Cooreman 04 Jan 2016