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:
- control low power timer
- enabling/disabling XTAL switching
- fetch and control reset sources
Be sure to read the chapter
Ultra Low Power.
Macro Definition Documentation
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
Sets the watchdog timer period.
- Parameters:
-
[in] | WDTPeriod | Watchdog 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:
- 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] | counter | Timer counter value |
[in] | timeUnit | Time unit of the result. See SEC, MSEC, USEC |
[in] | timerClkPeriod | Duration 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)) ? \
\
( \
((uint32)time > (uint32)timeUnit) ? \
(((uint32)time / timerClkPeriod) * (uint32)timeUnit) \
: \
(((uint32)timeUnit / timerClkPeriod) * (uint32)time) \
) \
: \
\
(((uint32)time * (uint32)timeUnit) / timerClkPeriod) \
) \
Converts a time to a low power timer clock time units.
- Parameters:
-
[in] | time | Time to convert (no units) |
[in] | timeUnit | Time units. |
[in] | timerClkPeriod | Duration of the low power timer counter to increment. |
- Returns:
- Time expressed in timeUnit
Example 1:
Setting a flywheel timer period of 2 seconds
- 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
Stops the indicated low power timer.
- Parameters:
-
- Returns:
- OK Function correctly executed.
-
NOT_VALID_PARAM Wrong input parameter.
Example 1:
The short term timer is stopped here.
Example 2:
It is NOT possible to stop the watchdog timer. The function returns an error if trying to do so
- 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
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:
-
u8Divider | not 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
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] | *pu32tapValue | Value set in the FW tap register |
- Returns:
- OK Function correctly executed.
-
OK Function correctly executed.
-
NOT_VALID_PARAM Wrong input parameter.
Example 1:
- 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
Obtains the timer counter of the indicated low power timer.
- Parameters:
-
[in] | timer | Low power timer to get the information from |
[out] | *pu32timerCounter | Timer 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
Indicates the period set in the corresponding low power timer
- Parameters:
-
[in] | timer | Low power timer to get the period from. |
[out] | *pu32timerPeriod | Period 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.
- 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
Indicates if the timer is active or not.
- Parameters:
-
[in] | timer | Low power timer whose state is to be read. |
[out] | *pu8timerStatus | ON, 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.
if( (
return ==
OK) && (timerStatus ==
OFF) )
{
}
do
{
}
while (u8Stable == FALSE);
- 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
Indicates if the timer is stable and all data is captured.
- Parameters:
-
[in] | timer | Low power timer whose stability is to be read. |
[out] | *pu8timerStatus | TRUE, 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] | *pu8resetEvent | Event that cause the CPU to jump to reset vector. RESET_TYPE |
- Returns:
- -
Example 1:
Depending on the reset event detected, perform an action.
- 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] | *pu8VON | Returns 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!
Reinitialises the indicated low power timer counter to 0.
- Parameters:
-
[in] | timer | Low 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
Sets the period value of a low power timer and starts the timer.
- Parameters:
-
[in] | timer | One of the chip low power timers. SLEEP_TIMER_TYPE |
[in] | timerPeriod | Timer period in timer counter units. |
[in] | shortTermMode | Short 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)
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.
Example 3:
After a short term timer sleep the radio configuration is lost. Here it is shown how to reenable the radio.
void main()
{
uint8 u8Stable;
mainInit();
rTel2.raw.
bytes[0] = 0x21;
rTel2.raw.
bytes[5] = 0xAB;
while(1)
{
do
{
}
while (u8Stable == FALSE);
radio_init_asm(1);
}
}
Example 4:
if( (result ==
OK) && (value ==
OFF) )
{
}
do
{
}
while (u8Stable == FALSE);
Example 5:
- 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
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] | configWakeUpEvents | Configures some events that can wake-up the CPU from standby. See WAKE_CFG_TYPE |
[out] | *pu8wakeUpEvent | Indicates 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
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] | configWakeUpEvents | Configures some events that can wake-up the CPU from standby. See WAKE_CFG_TYPE |
[in] | u16value | Raw 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
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
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] | wakeUpPinFlags | Configures WAKE pin events that can wake-up the CPU rom standby. See WAKE_CFG_TYPE for more information. |
[out] | *pu8wakeUpEvent | Indicates 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 ()
{
uint16 u16value;
uint8 u8Stable;
mainInit();
do
{
}
while (u8Stable == FALSE);
switch (wakeUpEvent)
{
{
}
{
}
}
}
- 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] | tapValue | Value 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!!
if( (result ==
OK) && (value ==
OFF) )
{
}
if(FWcounter < 50)
{
}
else if(FWcounter < 150)
{
}
else
{
}
do
{
}
while (u8Stable == FALSE);
-
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] | *pu16FnPtr | Pointer 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] | u8Enable | TRUE, 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
void vdd_callback()
{
....
}
void main()
{
mainInit();
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] | u16TimerPeriode | Timer 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;
for (i=0;i<65;i++);
for (i=0;i<65;i++);
radio_init_asm(1);
}
void main()
{
mainInit();
while(1);
}
- See also:
- pwr_vddFailInitCB, pwr_vddFailEnableCB