1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-23 08:15:17 +03:00

Re #2681 and #2626: Power off refactoring, the 9XE RTC reset prevention code now active

This commit is contained in:
Damjan Adamic 2015-08-25 20:36:51 +02:00
parent e83b7c3a69
commit 77d3eae4d6
6 changed files with 78 additions and 55 deletions

View file

@ -1260,12 +1260,7 @@ void alert(const pm_char * t, const pm_char *s MESSAGE_SOUND_ARG)
#if defined(PCBTARANIS) && defined(REV9E) #if defined(PCBTARANIS) && defined(REV9E)
uint32_t pwr_check = pwrCheck(); uint32_t pwr_check = pwrCheck();
if (pwr_check == e_power_off) { if (pwr_check == e_power_off) {
// TODO this is quick & dirty boardOff();
lcdOff();
BACKLIGHT_OFF();
topLcdOff();
SysTick->CTRL = 0; // turn off systick
pwrOff();
} }
else if (pwr_check == e_power_press) { else if (pwr_check == e_power_press) {
refresh = true; refresh = true;
@ -1276,7 +1271,7 @@ void alert(const pm_char * t, const pm_char *s MESSAGE_SOUND_ARG)
} }
#else #else
if (pwrCheck() == e_power_off) { if (pwrCheck() == e_power_off) {
pwrOff(); // turn power off now boardOff(); // turn power off now
} }
#endif #endif
} }
@ -2577,7 +2572,7 @@ int main(void)
opentxClose(); opentxClose();
lcd_clear() ; lcd_clear() ;
lcdRefresh() ; lcdRefresh() ;
pwrOff(); // Only turn power off if necessary boardOff(); // Only turn power off if necessary
wdt_disable(); wdt_disable();
while(1); // never return from main() - there is no code to return back, if any delays occurs in physical power it does dead loop. while(1); // never return from main() - there is no code to return back, if any delays occurs in physical power it does dead loop.
#endif #endif

View file

@ -306,7 +306,13 @@ typedef const int8_t pm_int8_t;
#define cli() #define cli()
#define sei() #define sei()
extern void boardInit(); extern void boardInit();
#if defined(PCBTARANIS)
extern void boardOff();
#else #else
#define boardOff() pwrOff();
#endif
#else
#define boardOff() pwrOff();
#include <avr/io.h> #include <avr/io.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include "pgmtypes.h" #include "pgmtypes.h"

View file

@ -377,6 +377,7 @@ void eepromReadBlock (uint8_t * pointer_ram, uint32_t address, uint32_t size);
#define wdt_enable(...) sleep(1/*ms*/) #define wdt_enable(...) sleep(1/*ms*/)
#define wdt_reset() sleep(1/*ms*/) #define wdt_reset() sleep(1/*ms*/)
#define boardInit() #define boardInit()
#define boardOff()
#define OS_MutexID pthread_mutex_t #define OS_MutexID pthread_mutex_t
extern OS_MutexID audioMutex; extern OS_MutexID audioMutex;

View file

@ -187,7 +187,7 @@ void boardInit()
lcdRefreshWait(); lcdRefreshWait();
} }
if (duration < PWR_PRESS_DURATION_MIN || duration >= PWR_PRESS_DURATION_MAX) { if (duration < PWR_PRESS_DURATION_MIN || duration >= PWR_PRESS_DURATION_MAX) {
pwrOff(); boardOff();
} }
} }
else { else {
@ -198,8 +198,27 @@ void boardInit()
backlightInit(); backlightInit();
#endif #endif
} }
void boardOff()
{
BACKLIGHT_OFF();
#if defined(REV9E)
topLcdOff();
#endif #endif
#if defined(REV9E)
while (pwrPressed()) {
wdt_reset();
}
#endif
lcdOff();
SysTick->CTRL = 0; // turn off systick
pwrOff();
}
#endif // #if !defined(SIMU)
#if defined(USB_JOYSTICK) && !defined(SIMU) #if defined(USB_JOYSTICK) && !defined(SIMU)
extern USB_OTG_CORE_HANDLE USB_OTG_dev; extern USB_OTG_CORE_HANDLE USB_OTG_dev;

View file

@ -37,9 +37,6 @@
#include "board_taranis.h" #include "board_taranis.h"
#include "../../pwr.h" #include "../../pwr.h"
extern volatile uint32_t g_tmr10ms;
#define get_tmr10ms() g_tmr10ms
void pwrInit() void pwrInit()
{ {
// if any changes are done to the PWR PIN or pwrOn() function // if any changes are done to the PWR PIN or pwrOn() function
@ -87,13 +84,19 @@ void pwrOff()
{ {
GPIO_ResetBits(PWR_GPIO, PWR_GPIO_PIN_ON); GPIO_ResetBits(PWR_GPIO, PWR_GPIO_PIN_ON);
// disable interrupts
__disable_irq();
#if defined(REV9E) #if defined(REV9E)
// 9E needs watchdog reset because CPU is still running while the power // 9E needs watchdog reset because CPU is still running while
// key is held pressed by the user // the power key is held pressed by the user.
while (1) { // The power key should be released by now, but we must make sure
while (pwrPressed()) {
wdt_reset(); wdt_reset();
#if 0 }
// It doesn't work correctly, if we press long on the pwr button, the radio restarts when the button is released // Put the CPU into sleep to reduce the consumption,
// it might help with the RTC reset issue
PWR->CR |= PWR_CR_CWUF; PWR->CR |= PWR_CR_CWUF;
/* Select STANDBY mode */ /* Select STANDBY mode */
PWR->CR |= PWR_CR_PDDS; PWR->CR |= PWR_CR_PDDS;
@ -102,8 +105,12 @@ void pwrOff()
/* Request Wait For Event */ /* Request Wait For Event */
__WFE(); __WFE();
#endif #endif
while(1) {
wdt_reset();
} }
#endif
//this function must not return!
} }
#if defined(REV9E) #if defined(REV9E)

View file

@ -196,12 +196,7 @@ void menusTask(void * pdata)
#endif #endif
opentxClose(); opentxClose();
boardOff(); // Only turn power off if necessary
#if !defined(SIMU)
SysTick->CTRL = 0; // turn off systick
#endif
pwrOff(); // Only turn power off if necessary
} }
extern void audioTask(void* pdata); extern void audioTask(void* pdata);