DolphinV4 API  1.6.1.0
Power functions
Collaboration diagram for Power functions:

Macros

#define CLR_WDT()   {pwr_resetSleepTimer(WATCHDOG_TIMER);}
#define SET_WDT(WDTPeriod)   pwr_setSleepTimer(WATCHDOG_TIMER,WDTPeriod,0)
#define CONV_COUNTER_TO_TIME(counter, timeUnit, timerClkPeriod)   ((uint32)counter * (uint32)timerClkPeriod) / timeUnit
#define CONV_TIME_TO_COUNTER(time, timeUnit, timerClkPeriod)

Functions

RETURN_TYPE pwr_disableSleepTimer (SLEEP_TIMER_TYPE timer)
void pwr_enableXTAL (XTAL_DIVIDER_TYPE u8Divider)
void pwr_selectXTAL ()
RETURN_TYPE pwr_getFlywheelTap (uint32 *pu32tapValue)
RETURN_TYPE pwr_getSleepTimerCounter (SLEEP_TIMER_TYPE timer, uint32 *pu32timerCounter)
RETURN_TYPE pwr_getSleepTimerPeriod (SLEEP_TIMER_TYPE timer, uint32 *pu32timerPeriod)
RETURN_TYPE pwr_getSleepTimerStatus (SLEEP_TIMER_TYPE timer, uint8 *pu8timerStatus)
RETURN_TYPE pwr_getSleepTimerStable (SLEEP_TIMER_TYPE timer, uint8 *pu8timerStable)
void pwr_getSystemReset (RESET_TYPE *pu8resetEvent)
void pwr_getThresholdVON (uint8 *pu8VON)
RETURN_TYPE pwr_resetSleepTimer (SLEEP_TIMER_TYPE timer)
RETURN_TYPE pwr_setSleepTimer (SLEEP_TIMER_TYPE timer, uint32 timerPeriod, SHORT_TERM_TYPE shortTermMode)
void pwr_standbySleep (WAKE_CFG_TYPE configWakeUpEvents, WAKE_TYPE *pu8wakeUpEvent)
WAKE_TYPE pwr_shortTermSleep (uint16 u16value, WAKE_CFG_TYPE wakeUpPinFlags)
void pwr_standbyST ()
void pwr_timerSleep (WAKE_CFG_TYPE wakeUpPinFlags, WAKE_TYPE *pu8wakeUpEvent)
void pwr_setFlywheelTap (uint32 tapValue)
void pwr_vddFailInitCB (void code *pu16FnPtr)
void pwr_vddFailEnableCB (uint8 u8Enable)
void pwr_isrShortTerm (uint16 timerPeriod)

Detailed Description

The PWR module is responsible for the power block control of the DOLPHIN. Using the PWR module several ultra low power timers can be activated/deactivated. These timers are used to control the sleep modes of the DOLPHIN. The PWR module has the responsibility to:

Be sure to read the chapter Ultra Low Power.


Macro Definition Documentation

#define CLR_WDT ( )    {pwr_resetSleepTimer(WATCHDOG_TIMER);}

Reinitialises the watchdog (WDT) timer counter .

Parameters:
-
Returns:
OK Function correctly executed.
Note:
The function should be called more frequently than 1/WDTperiod to prevent a WDT reset. A WDT reset wake-ups the CPU from any low power mode also.
The CLR_WDT sets the watchdog counter back. This operation takes at least ca. 30ms. The function returns immediately, but the counter will be actualised only after ca. 30 ms. Therefore if calling the SET_WDT and CLR_WDT functions in a row, CLR_WDT will have no effect.
See also:
SET_WDT, pwr_resetSleepTimer, watchdog_page
#define SET_WDT (   WDTPeriod)    pwr_setSleepTimer(WATCHDOG_TIMER,WDTPeriod,0)

Sets the watchdog timer period.

Parameters:
[in]WDTPeriodWatchdog timer period in the timer counter units
Returns:
OK Function correctly executed.
Note:
When the WDT timer reaches the period the CPU, if sleeping, wakes-up. In any other case the program execution jumps to the reset vector - i.e. the program will start from the beggining.
If no period is set, the WDT period register is 0xFFFFFF. This equals 46.6 hours
The SET_WDT sets the watchdog counter. This operation takes at least ca. 30ms. The function returns immediately, but the counter will be actualised only after ca. 30ms.Therefore it is not allowed to call the SET_WDT and CLR_WDT functions in a row. Also make sure the watchdog period is more than 30ms. Example:
//calculate timer period for 10 seconds and apply calibration factor
u32WatchdogPeriode = (uint32)(CONV_TIME_TO_COUNTER(10, SEC, WATCHDOG_CLK) * gModArea.val.u16CalibWatchdog)/WATCHDOG_CALIB_CONST;
SET_WDT(u32WatchdogCycle);
See also:
pwr_setSleepTimer, CLR_WDT, watchdog_page
#define CONV_COUNTER_TO_TIME (   counter,
  timeUnit,
  timerClkPeriod 
)    ((uint32)counter * (uint32)timerClkPeriod) / timeUnit

Converts the value of a low power timer counter to time units.

Parameters:
[in]counterTimer counter value
[in]timeUnitTime unit of the result. See SEC, MSEC, USEC
[in]timerClkPeriodDuration of the low power timer counter to increment. See SLEEP_TIMER_CLK_TYPE
Returns:
Time expressed in timeUnit units

Example 1:
Getting the time elapsed in ms since FLYWHEEL timer initialisation

Note:
This function can be useful combined with pwr_getSleepTimerCounter and pwr_getSleepTimerPeriod, since these functions return the timer counter and timer counter period in timer tick units.
According to the timer clock period (SLEEP_TIMER_CLK_TYPE) select an appropriate time unit.
The converted timer units are NOT CALIBRATED. In order to get calibrate timer units you have to adjust the value with the calibration constant from the CFG_AREA. To see how to do this read the calibration section in the Ultra Low Power.
The result is always a natural number. The decimal part is truncated. Example: -if the result of the division is 2,01 you get actually 2. -if the result of the division is 2,99 you get actually 2.
See also:
CONV_TIME_TO_COUNTER, pwr_getSleepTimerCounter, pwr_getSleepTimerPeriod, Ultra Low Power
#define CONV_TIME_TO_COUNTER (   time,
  timeUnit,
  timerClkPeriod 
)
Value:
( \
(((uint32)time > 0xffff) || ((uint32)timeUnit > 0xffff)) ? \
/* Overflow in 32 bit mathematics possible */ \
( \
((uint32)time > (uint32)timeUnit) ? \
(((uint32)time / timerClkPeriod) * (uint32)timeUnit) \
: \
(((uint32)timeUnit / timerClkPeriod) * (uint32)time) \
) \
: \
/* No overflow in 32 bit mathematics possible */ \
(((uint32)time * (uint32)timeUnit) / timerClkPeriod) \
) \

Converts a time to a low power timer clock time units.

Parameters:
[in]timeTime to convert (no units)
[in]timeUnitTime units.
[in]timerClkPeriodDuration of the low power timer counter to increment.
Returns:
Time expressed in timeUnit

Example 1:
Setting a flywheel timer period of 2 seconds

// Use the FW calibration in FLASH (gModArea.val.f32CalibFlywheel) to correct the value to write in pwr_setSleepTimer() in order to obtain FLYWHEEL_PERIOD
u32FlywheelPeriod = (uint32)(CONV_TIME_TO_COUNTER(3, SEC, FLYWHEEL_CLK)* gModArea.val.f32CalibFlywheel);
pwr_setSleepTimer(FLYWHEEL_TIMER, u32FlywheelPeriod ,0);
Note:
This function can be useful to calculate the input parameter of the pwr_setSleepTimer.
As timeUnit use one of the constants SEC, MSEC, USEC.
As timerClkPeriod use one of the period values defined in SLEEP_TIMER_CLK_TYPE
Flywheel timer counter is incremented every 976,5625 usec and macro works only with integer values. The recommended FLYWHEEL_CLK constant is 976 - compared to 976,5625 this is 576 ppm difference. For exacter results please use your own conversation routine using float operations.
The converted counter units are NOT CALIBRATED. In order to calibrate the counter you have to adjust the value with the calibration constant from the CFG_AREA. To know how to do this read the calibration section in the Ultra Low Power.
Absolute maximum values of the input parameter time, which depends from input parameter time_unit and the type of the timer:
Timer type time unit max. time value
WATCHDOG_TIMER USEC makes no sense
WATCHDOG_TIMER MSEC 100 663 290
WATCHDOG_TIMER SEC 100 663
FLYWHEEL_TIMER USEC makes no sense
FLYWHEEL_TIMER MSEC 16 777 215
FLYWHEEL_TIMER SEC 16 777
SHORT_TERM_TIMER USEC 39 321
SHORT_TERM_TIMER MSEC 39
SHORT_TERM_TIMER SEC not possible

Consider, that the result has to be converted to a calibrated value for exact timing. This final value may not exceed 24 bits for watchdog and flywheel timer and 16 bit for shortterm timer.

See also:
CONV_COUNTER_TO_TIME, SET_WDT, pwr_setSleepTimer, Ultra Low Power

Function Documentation

RETURN_TYPE pwr_disableSleepTimer ( SLEEP_TIMER_TYPE  timer)

Stops the indicated low power timer.

Parameters:
[in]timerLow power timer to stop. Only FLYWHEEL_TIMER and SHORT_TERM_TIMER are allowed
Returns:
OK Function correctly executed.
NOT_VALID_PARAM Wrong input parameter.

Example 1:
The short term timer is stopped here.

//This saves energy when not using this timer.

Example 2:
It is NOT possible to stop the watchdog timer. The function returns an error if trying to do so

if(return == OK);
{
//The code here will not be entered
}
Note:
This function is allowed to be used in an interrupt callback function ONLY if it is ensured that it is not used at the same time from the main program!
See also:
pwr_setSleepTimer, pwr_timerSleep, pwr_resetSleepTimer, Ultra Low Power
void pwr_enableXTAL ( XTAL_DIVIDER_TYPE  u8Divider)

Starts the 16.384MHz crystal oscillator (XTAL). It takes 1.3ms until the crystal oscillator is stable and prepared to be selected as the system clock. While the crystal oscillator startup the system clock is still supplied from the RC oscillator which is min:11.7 typ:16 max:22.8Mhz . While running with the CRCO all the sw modules can be used except the RADIO module. The timings of functions are unprecise. To switch from CRCO to XTAL call the pwr_selectXTAL.

Parameters:
u8Dividernot used any more
Returns:
-
Note:
If running from RC oscillator it is not possible to:
  • use the radio block for radio communication
  • all the timings (UART, SPI, system timer) will be not precise
This function is allowed to be used in an interrupt callback function ONLY if it is ensured that it is not used at the same time from the main program!
See also:
pwr_selectXTAL
void pwr_selectXTAL ( )

Waits until the 16.384 MHz crystal oscillator is stable (XTAL) and then selects it. While waiting the CPU goes to standby mode to save energy. After the time has passed and XTAL selected the ShortTerm timer is deactivated.

Parameters:
-
Returns:
-
Note:
Use this function together with pwr_enableXTAL.
This function is allowed to be used in an interrupt callback function ONLY if it is ensured that it is not used at the same time from the main program!
See also:
pwr_enableXTAL
RETURN_TYPE pwr_getFlywheelTap ( uint32 *  pu32tapValue)

Returns the previously set flywheel tap value.

Parameters:
[out]*pu32tapValueValue set in the FW tap register
Returns:
OK Function correctly executed.
OK Function correctly executed.
NOT_VALID_PARAM Wrong input parameter.

Example 1:

pwr_getFlywheelTap(&tapValue); //tapValue must be 50
Note:
When the flywheel counter reaches the tap value the CPU wakes-up. The flywheel counter is not modified by this event, and it counts up to the FW period. The tap is useful to wake up the CPU between FW period intervals.
See also:
pwr_setFlywheelTap, pwr_setSleepTimer, Ultra Low Power
RETURN_TYPE pwr_getSleepTimerCounter ( SLEEP_TIMER_TYPE  timer,
uint32 *  pu32timerCounter 
)

Obtains the timer counter of the indicated low power timer.

Parameters:
[in]timerLow power timer to get the information from
[out]*pu32timerCounterTimer counter value.
Returns:
OK Function correctly executed.
NOT_VALID_PARAM Wrong input parameter.

Example 1:
Get the counter of the watchdog timer.

Note:
The short term timer and the watchdog counters decrement while counting. The flywheel timer counter is incremented while counting.
The short-term and flywheel timers are active (their counter changes) from the moment the function pwr_setSleepTimer is called. The watchdog timer is always active and cannot be deactivated
The counter units are NOT CALIBRATED. In order to calibrate the counter value you have to adjust the constant with the calibration constant from the CFG_AREA. To know how to do this read the calibration section in the Ultra Low Power.
See also:
pwr_resetSleepTimer, pwr_setSleepTimer, pwr_getSleepTimerPeriod, pwr_getSleepTimerStatus, Ultra Low Power
RETURN_TYPE pwr_getSleepTimerPeriod ( SLEEP_TIMER_TYPE  timer,
uint32 *  pu32timerPeriod 
)

Indicates the period set in the corresponding low power timer

Parameters:
[in]timerLow power timer to get the period from.
[out]*pu32timerPeriodPeriod value in timer counter units.
Returns:
OK Function correctly executed.
NOT_VALID_PARAM Timer not valid.

Example 1:
Getting the FW timer period in milliseconds.

if(return == OK)
{
time = CONV_COUNTER_TO_TIME(timerPeriod,MSEC,FLYWHEEL_CLK);
}
Note:
The timer period is NOT CALIBRATED. In order to calibrate the timer period units you have to adjust the value with the calibration constant from the CFG_AREA. To know how to do this read the calibration section in the Ultra Low Power.
See also:
pwr_timerSleep, pwr_setSleepTimer, Ultra Low Power
RETURN_TYPE pwr_getSleepTimerStatus ( SLEEP_TIMER_TYPE  timer,
uint8 *  pu8timerStatus 
)

Indicates if the timer is active or not.

Parameters:
[in]timerLow power timer whose state is to be read.
[out]*pu8timerStatusON, the timer clock is active. OFF, the timer is stopped
Returns:
OK Function correctly executed.
NOT_VALID_PARAM Timer not valid.

Example 1:
This function is useful to configure the flywheel just once in the program execution life.

return = pwr_getSleepTimerStatus(FLYWHEEL_TIMER, &timerStatus) ;
if( (return == OK) && (timerStatus == OFF) )
{
pwr_setSleepTimer(FLYWHEEL_TIMER, 10000,0); // The FW timer starts running from this moment.
SET_WDT(100000); // The WDT period must be bigger than the FW period.
// Otherwise WDT reset happens while sleeping
}
//Rest of the program here
do
{
// Additionally, the WDT counter must be cleared. Otherwise WDT reset happens.
}
while (u8Stable == FALSE); // Dependent of the hardware it can take up to 10 seconds till flywheel is stable
// Go to sleep with the activated timers FW and WDT. No wake-up pin activated (0x00)
pwr_timerSleep(0x00,&value);
// When FW timer counter reaches the period the CPU restarts execution at the reset vector.
// FW timer status \ref ON until a pwr_disableSleepTimer() call is made.
Note:
After setting a timer through pwr_setSleepTimer, the function returns ON. Similarly, when stopping a timer using pwr_disableSleepTimer, the function returns OFF
The tap value is NOT CALIBRATED. In order to calibrate the timer tap value you have to adjust the value with the calibration constant from the CFG_AREA. To know how to do this read the calibration section in the Ultra Low Power.
This function is allowed to be used in an interrupt callback function ONLY if it is ensured that it is not used at the same time from the main program!
See also:
pwr_setSleepTimer, pwr_disableSleepTimer, Ultra Low Power
RETURN_TYPE pwr_getSleepTimerStable ( SLEEP_TIMER_TYPE  timer,
uint8 *  pu8timerStable 
)

Indicates if the timer is stable and all data is captured.

Parameters:
[in]timerLow power timer whose stability is to be read.
[out]*pu8timerStatusTRUE, the timer runs stable and all data is captured. FALSE, the timer is not ready to use
Returns:
OK Function correctly executed.
NOT_VALID_PARAM Timer not valid.
Note:
This function is allowed to be used in an interrupt callback function ONLY if it is ensured that it is not used at the same time from the main program!
See also:
pwr_setSleepTimer, pwr_disableSleepTimer, Ultra Low Power
void pwr_getSystemReset ( RESET_TYPE pu8resetEvent)

Reports the cause of the CPU reset.

Parameters:
[out]*pu8resetEventEvent that cause the CPU to jump to reset vector. RESET_TYPE
Returns:
-

Example 1:
Depending on the reset event detected, perform an action.

pwr_getSystemReset(&resetEvent);
switch (resetEvent)
{
case VDD_RESET: break; //Action when VDD drop/power-up detection.
case WATCHDOG_RESET: break; //Action for watchdog timer reset.
case FLYWHEEL_RESET: break; //Action for flywheel timer time-out.
case PIN_RESET: break; //Action for reset pin pressed.
}
Note:
The function can be called as often as needed from any place of the application and returns always the last reset cause. The function will only provide a correct reset cause after pwr_enableXTAL was called once.
See also:
pwr_selectXTAL, Ultra Low Power
void pwr_getThresholdVON ( uint8 *  pu8VON)

Returns the status of the VON threshold.

Parameters:
[out]*pu8VONReturns the threshold detector status. It equals 1 when VDD > VON, otherwise it is 0.
Returns:
-
Note:
This function is allowed to be used in an interrupt callback function ONLY if it is ensured that it is not used at the same time from the main program!
RETURN_TYPE pwr_resetSleepTimer ( SLEEP_TIMER_TYPE  timer)

Reinitialises the indicated low power timer counter to 0.

Parameters:
[in]timerLow power timer counter to reinitialise.
Returns:
OK Function correctly executed.
NOT_VALID_PARAM Timer not valid.
TIME_OUT Only watchdog: Last reset of timer was still not captured, it was not necessary to reset timer.

Example 1:
The clear watchdog timer macro uses this function.

Note:
If the corresponding timer clok was already activated, the timer counter starts counting from its initial value. In case that the timer clock is not active when calling this function, the counter will be reinitialised, but will not increment.
This function is allowed to be used in an interrupt callback function ONLY if it is ensured that it is not used at the same time from the main program!
See also:
pwr_setSleepTimer, pwr_getSleepTimerCounter, Ultra Low Power
RETURN_TYPE pwr_setSleepTimer ( SLEEP_TIMER_TYPE  timer,
uint32  timerPeriod,
SHORT_TERM_TYPE  shortTermMode 
)

Sets the period value of a low power timer and starts the timer.

Parameters:
[in]timerOne of the chip low power timers. SLEEP_TIMER_TYPE
[in]timerPeriodTimer period in timer counter units.
[in]shortTermModeShort term timer one shot or continuous mode. Only applies to SHORT_TERM_TIMER
Returns:
OK Function correctly executed.
NOT_VALID_PARAM Wrong input parameter.

Example 1:
This piece of code shows how to count 100 flywheel timer clock ticks (counter units)

pwr_setSleepTimer(FLYWHEEL_TIMER, 100,0); //100 is not a time. It indicates that the FW counter must count to 100

the flywheel timer uses as clock signal the external crystal WXTAL. This crystal must be activated for the FW to work. To activate the crystal configure the pins WXIDIO and WXODIO as crystal pins. To do that use Dolphin APIConfigurator, marking these two pins as WXTAL. Copy the generated initialization to your configuration file EO3100I_CFG.h

Example 2:
If you want to set a timer period in time units, you can do like this.

u32FlywheelPeriod = (uint32)(CONV_TIME_TO_COUNTER(3, SEC, FLYWHEEL_CLK)* gModArea.val.f32CalibFlywheel);
// Setting the FW period cycle and starting the FW timer
pwr_setSleepTimer(FLYWHEEL_TIMER, u32FlywheelPeriod ,0);

Example 3:
After a short term timer sleep the radio configuration is lost. Here it is shown how to reenable the radio.

void main()
{
RETURN_TYPE result;
pTel.p_tx.u8SubTelNum = 1;
pTel.p_tx.u32DestinationId = 0;
uint8 u8Stable;
// Init configuration: I/Os, radio, interrupts...
mainInit();
// Initialising a radio 1BS telegram to be sent.
rTel2.raw.bytes[0] = 0x21; // Header: Only 32 bit Originator-ID, 1BS, no extended Header
rTel2.raw.bytes[1] = 0; // Id
rTel2.raw.bytes[2] = 0; // Id
rTel2.raw.bytes[3] = 0; // Id
rTel2.raw.bytes[4] = 0; // Id
rTel2.raw.bytes[5] = 0xAB; // DATA
rTel2.raw.u8Length = 7; // Place for the CRC byte also in the telegram
// Config the short-term timer for the sleep. The timer runs continously. Period = 0xFFFF * 10 us ~= 0.65 s
while(1)
{
//Wait till shortterm timer runs stable and all registers are captured
do
{
}
while (u8Stable == FALSE);
//Go to sleep, without wake-up pins active (0x00). &value returns the wake-up event.
pwr_timerSleep(0x00,&value);
// After short-term, the radio config is lost. It is needed to reconfigure the radio before sending
// extern XTAL enable
// Loading the radio parameters in the HW radio module
radio_init_asm(1);
// System uses the external crystal (the radio HW only works with this clock source)
// Sending the radio telegram
radio_sendTelegram2(&rTel2,NULL);
}
}

Example 4:

// Setting a sleep with the flywheel timer waking up the CPU.
// The CPU wakes up every 200th count of the flywheel timer --> every 200ms.
// Note: The CPU does not continue execution at the point it went to sleep.
// Every time that the CPU wakes up, it starts executing from the reset vector. The FW counter is restarted automatically
// Setting the WDT and FW only once during the life of the program.
// Therefore, check if the FW is active. If not, set the timers.
if( (result == OK) && (value == OFF) )
{
result = pwr_setSleepTimer(FLYWHEEL_TIMER,200,0); // The third parameter in the function (0) is only needed when the short-term timer is used.
result = pwr_setSleepTimer(WATCHDOG_TIMER,0xFFFF,0); // Setting a big WDT period.
}
//Wait till flywheel timer runs stable and all registers are captured
do
{
}
while (u8Stable == FALSE);
//No wake through wake-up pins possible.
pwr_timerSleep(0x00,&value);
// After this line, no code would be executed. After a flywheel wake event the program starts execution from the reset vector.

Example 5:

// Setting a program to deep sleep: the watchdog timer wakes up the CPU.
// The CPU wakes up every 200th count of the watchdog timer --> every 2 seconds.
// Note: every time that the CPU wakes up, it starts executing from the reset vector.
// The CPU does not continue execution at the point it went to sleep.
// Setting the WDT only once during the life of the program.
// Therefore, check if a watchdog timer is the cause of the reset.
if( value != WATCHDOG_RESET )
{
}
//No wake through wake-up pins possible.
pwr_timerSleep(0x00,&value);
// After this line, no code would be executed. After a watchdog timer wake event the program starts execution from the reset vector.
Note:
When the flywheel or the watchdog counter reaches the period the CPU starts execution from the program reset vector.
In the case of short term timer, remember that the timer will be already running when pwr_setSleepTimer function is returned. Therfore, place the pwr_setSleepTimer and pwr_timerSleep as near as possible in your code. But do not forget to check if the timer runs stable and all registers are captured using pwr_getSleepTimerStable before going to sleep!
The timer period is NOT CALIBRATED. In order to calibrate the timer period you have to adjust the value with the calibration constants from the CFG_AREA. To know how to do this read the calibration section in the Ultra Low Power.
The startup time of the watchdog timer is maximum 8 cycles. So the very first watchdog wakeup could be 80 ms longer as expected.
When using shortterm sleep for waiting between sub telegrams be sure that the sleep time is longer than the sub telegram need to be sent. Otherwise when initializing radio parameters after wakeup too early the telegram could be breaked and the TX statemachine could be set into an errorness state.
\sa   pwr_disableSleepTimer, pwr_timerSleep, pwr_resetSleepTimer, pwr_getSleepTimerStable \ref ultra_low_power
void pwr_standbySleep ( WAKE_CFG_TYPE  configWakeUpEvents,
WAKE_TYPE pu8wakeUpEvent 
)

This function puts the CPU in standby mode. The CPU can wake up from standby mode using the wakepins or other interrupt sources. Be sure to read the Ultra Low Power

Parameters:
[in]configWakeUpEventsConfigures some events that can wake-up the CPU from standby. See WAKE_CFG_TYPE
[out]*pu8wakeUpEventIndicates the cause of the wake up. See WAKE_TYPE
Returns:
-
Note:
The WAKE_CFG_TYPE does not specifies all the wake events. Wake events like RX_RADIO_TEL_WAKE, TX_RADIO_TEL_WAKE etc. are triggered by interrupts
If you don't want to be wake up by radio Rx interrupt switch off the RadioRx
To avoid perodically waking up the CPU each ms, the scheduler interrupt is switched off in this function. This can be override using the TIMER0_WAKE_FLAG
Be sure there is no ongoing Tx or Rx operation if you don't wan to woken up by RX_RADIO_TEL or TX_RADIO_TEL_WAKE when entering to standby. You can proove this using radio_getOngoingRxTx function.
This function is allowed to be used in an interrupt callback function ONLY if it is ensured that it is not used at the same time from the main program!
See also:
pwr_setSleepTimer, pwr_timerSleep, Ultra Low Power
WAKE_TYPE pwr_shortTermSleep ( uint16  u16value,
WAKE_CFG_TYPE  wakeUpPinFlags 
)

This function puts the CPU in shortterm mode. The CPU can wake up using the wakepins or other interrupt sources. Be sure to read the Ultra Low Power

Parameters:
[in]configWakeUpEventsConfigures some events that can wake-up the CPU from standby. See WAKE_CFG_TYPE
[in]u16valueRaw value used for short term timer
Returns:
*pu8wakeUpEvent Indicates the cause of the wake up. See WAKE_TYPE
Note:
The WAKE_CFG_TYPE does not specifies all the wake events. Wake events like RX_RADIO_TEL_WAKE, TX_RADIO_TEL_WAKE etc. are triggered by interrupts
If you don't want to be wake up by radio Rx interrupt switch off the RadioRx
Be sure there is no ongoing Tx or Rx operation if you don't wan to woken up by RX_RADIO_TEL or TX_RADIO_TEL_WAKE when entering to standby. You can proove this using radio_getOngoingRxTx function.
See also:
pwr_setSleepTimer, pwr_timerSleep, Ultra Low Power
void pwr_standbyST ( )

This function puts the CPU in standby mode. The CPU can wake up from standby mode only by short term timer

Parameters:
-
Returns:
-
Note:
This function is allowed to be used in an interrupt callback function ONLY if it is ensured that it is not used at the same time from the main program!
See also:
pwr_setSleepTimer, pwr_timerSleep, Ultra Low Power
void pwr_timerSleep ( WAKE_CFG_TYPE  wakeUpPinFlags,
WAKE_TYPE pu8wakeUpEvent 
)

Enters the CPU in low power mode with a low power timer controlling the wake-up."SET TO SLEEP". Be sure to read the Ultra Low Power

Parameters:
[in]wakeUpPinFlagsConfigures WAKE pin events that can wake-up the CPU rom standby. See WAKE_CFG_TYPE for more information.
[out]*pu8wakeUpEventIndicates the cause of the wake up. See WAKE_TYPE for more information.
Returns:
-

Example 1:
Enter in sleep for 10ms with the short term timer.

void main ()
{
WAKE_TYPE wakeUpEvent;
uint16 u16value;
uint8 u8Stable;
mainInit();
//enter Short Term sleep between subtelegrams
//Wait till shortterm timer runs stable and all registers are captured
do
{
}
while (u8Stable == FALSE);
pwr_timerSleep(wakeUpPinFlags, &wakeUpEvent);
switch (wakeUpEvent)
{
{
//Action for wake-up pin 0 event
}
{
//Short term timeout
}
}
}
Note:
More than one low power timer can run at the same time. The first timer to time-out wakes the CPU. It must be remembered that the watchdog timer is ALWAYS running, and can cause unexpected CPU reset if its counter is not clear periodically.
A flywheel or watchdog timer time-out causes the CPU to wake up and start executing from the reset vector, while a short term timer time-out will wake-up the CPU and continue execution. In all three cases the radio settings are lost and must be reinitialised if needed.
This function switches the radio receiving off and is deactivated after leaving this function.
In Deep Sleep, Flywheel Sleep, and Short Term Sleep mode DVDD is switched off! Please take care to avoid reverse supply via IOVDD!
If the wake up event is not needed to know the second parameter can be NULL.
Be sure to use pwr_getSleepTimerStable before entering sleep mode to be sure that your timer runs stable and all settings are captured.
When using shortterm sleep for waiting between sub telegrams be sure that the sleep time is longer than the sub telegram need to be sent. Otherwise when initializing radio parameters after wakeup too early the telegram could be breaked and the TX statemachine could be set into an errorness state.
It is not possible to enter to DeepSleep if pwr_enableXTAL was but pwr_selectXTAL was not called. In pwr_selectXTAL the program enters to ShortTerm sleep thus reconfiguring the DeepSleep target. pwr_selectXTAL restores these settings.
See also:
pwr_setSleepTimer, pwr_disableSleepTimer, pwr_resetSleepTimer, pwr_getSystemReset, Ultra Low Power
void pwr_setFlywheelTap ( uint32  tapValue)

Sets a flywheel timer counter value that wakes up the CPU.

Note:
the flywheel counter is not affected.Intermediate Wakup after reach TAP.
Parameters:
[in]tapValueValue of the flywheel timer counter that wakes-up the CPU.
Returns:
-

Example 1:
This piece of code shows how set 2 wake events within a flywheel period. Through the usage of the pwr_setFlywheelTap the flywheel timer counter runs always without being rewritten.

Note:
FWcounter has to a uint32 value otherwise the code can not work correct!!
//Get and clear the reset events
if( (result == OK) && (value == OFF) )
{
//Setting the flywheel timer period. This is only performed once in the execution cycle
}
//Writing the tap. The next wake setting depends on the current FW counter
if(FWcounter < 50)
{
//In this case the CPU was awoken because the counter reached the period value.
//Setting the next wake up when the FW counter will be 50
}
else if(FWcounter < 150)
{
//In this case the CPU was awoken because the counter reached the value 50.
//Setting the next wake up when the FW counter will be 150
}
else
{
//In this case the CPU was awoken due to the tap = 150. The FW period value, 600, will be next the wake event.
}
//Wait till flywheel timer runs stable and all registers are captured
do
{
}
while (u8Stable == FALSE);
//Go to sleep. No wake through wake-up pins possible.
pwr_timerSleep(0x00,&value);
A wake event will happen also when the FW counter reaches its period value.
In that moment, the FW counter starts to count from 0 again.
The tap value is NOT CALIBRATED. In order to calibrate the timer tap value you have to adjust the value with the calibration constant from the CFG_AREA. To know how to do this read the calibration section in the Ultra Low Power.
This function is allowed to be used in an interrupt callback function ONLY if it is ensured that it is not used at the same time from the main program!
See also:
pwr_getFlywheelTap, pwr_timerSleep, Ultra Low Power
void pwr_vddFailInitCB ( void code *  pu16FnPtr)

Sets function pointer for callback function in interrupt when VDD Failes, when VDD crosses threshold VON.

Parameters:
[in]*pu16FnPtrPointer to the callback function which will be called when VDD crosses downwards the VON threshold, i.e. VDD<VON
Returns:
-
Note:
In order to use this feature be sure to set the VDD Fail checkbox in I/O Configuration of DolphinV4 API Configurator
See also:
pwr_vddFailEnableCB, pwr_isrShortTerm
void pwr_vddFailEnableCB ( uint8  u8Enable)

Enables or disables callback in interrupt VDD Failes, when VDD crosses threshold VON

Parameters:
[in]u8EnableTRUE, callback enabled, FALSE, callback disabled
Returns:
-
Note:
Do not stay in the callback function too long (not more than 100us because that takes too much time away from the schedule)
The callback function will be called during an interrupt! Do not call other API functions than io_getDigital or io_getPort in callback function. Do not switch the registerbank. Do not use overlaying and optimizing in callback function. You are allowed to:
  • allocate local variables
  • you are allowed to read from flash using code[]
  • you are allowed to change global variables of the code but before be sure to set them to volatile
If you did not initialised callback function pointer and you enable callback function, then the interrupt occurs, but function cannot be called and interrupt returns without function. Program will not crash, but resources are used.
In order to use this feature be sure to set the VDD Fail checkbox in I/O Configuration of DolphinV4 API Configurator
//callback function
void vdd_callback()
{
....
}
void main()
{
mainInit();
io_setDigital(ADIO_0,0);
io_setDigital(ADIO_1,1);
//init VDD Fail interrupt
pwr_vddFailInitCB((void*)vdd_callback);
while(1);
}
See also:
pwr_vddFailInitCB, pwr_isrShortTerm
void pwr_isrShortTerm ( uint16  timerPeriod)

Shortterm sleep mode intended to be used from callback functions. This function initialises the timer, enters to shorterm sleep mode exists from sleep mode after the period and stops the shortterm timer.

Parameters:
[in]u16TimerPeriodeTimer period in shortterm timer counter units.
Returns:
-
Note:
Do not use this function from the main program. Use instead pwr_setSleepTimer and pwr_timerSleep. This function is intended to be used only from callback functions.
After returning from the function the xtal has to be started again and the radio has to be initialised.
void vdd_callback()
{
uint16 u16value;
uint32 i;
io_setDigital(ADIO_2,1);
//To save energy, go to short term sleep
io_setDigital(ADIO_0,1);
for (i=0;i<65;i++);
io_setDigital(ADIO_0,0);
pwr_isrShortTerm(u16value);
io_setDigital(ADIO_0,1);
for (i=0;i<65;i++);
io_setDigital(ADIO_0,0);
// After short-term, the radio config is lost. It is needed to reconfigure the radio before sending
// extern XTAL enable
// Loading the radio parameters in the HW radio module
radio_init_asm(1);
// System uses the external crystal (the radio HW only works with this clock source)
}
void main()
{
//Configuration
mainInit();
io_setDigital(ADIO_2,0);
io_setDigital(ADIO_1,1);
pwr_vddFailInitCB((void*)vdd_callback);
while(1);
}
See also:
pwr_vddFailInitCB, pwr_vddFailEnableCB