Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 11 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, 11 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 29 Dec 2015