mirror of
https://github.com/opentx/opentx.git
synced 2025-07-19 14:25:11 +03:00
Bsongis/issue 3600 emergency shutdown (#3602)
* [ARM] Fixes #3600 - Emergency shutdown * Compilation fix * Function renamed * Compilation fix * Compilation fix * Compilation fix * Suggestion from projectkk2glider
This commit is contained in:
parent
238943f4a2
commit
4445f7cdec
7 changed files with 89 additions and 41 deletions
|
@ -265,7 +265,7 @@ elseif(PCB STREQUAL SKY9X OR PCB STREQUAL 9XRPRO OR PCB STREQUAL AR9X)
|
|||
add_definitions(-DEEPROM_VARIANT=0)
|
||||
set(GUI_SRC ${GUI_SRC} ${9X_GUI_SRC} menu_general_hardware.cpp view_telemetry.cpp view_text.cpp view_about.cpp)
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} core_cm3.c board_lowlevel.c crt.c vectors_sam3s.c)
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} lcd_driver.cpp
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} lcd_driver.cpp pwr_driver.cpp
|
||||
usb/device/core/USBD_UDP.c usb/device/core/USBDDriver.c
|
||||
usb/device/massstorage/MSDDriver.c usb/device/massstorage/MSDDStateMachine.c usb/device/massstorage/MSDLun.c
|
||||
usb/device/massstorage/MSDDriverDescriptors.c usb/device/massstorage/SBCMethods.c usb/common/core/USBEndpointDescriptor.c
|
||||
|
@ -278,7 +278,6 @@ elseif(PCB STREQUAL SKY9X OR PCB STREQUAL 9XRPRO OR PCB STREQUAL AR9X)
|
|||
board_sky9x.cpp
|
||||
telemetry_driver.cpp
|
||||
serial2_driver.cpp
|
||||
pwr_driver.cpp
|
||||
adc_driver.cpp
|
||||
eeprom_driver.cpp
|
||||
pulses_driver.cpp
|
||||
|
|
|
@ -1310,15 +1310,18 @@ int lcdRestoreBackupBuffer()
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(PWR_BUTTON_DELAY)
|
||||
uint32_t pwrPressed() { return false; }
|
||||
#elif defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS)
|
||||
uint32_t pwroffPressed() { return false; }
|
||||
|
||||
#if defined(CPUARM) && !defined(PWR_BUTTON_DELAY)
|
||||
uint32_t pwrCheck() { return true; }
|
||||
#endif
|
||||
|
||||
#if defined(CPUARM)
|
||||
void pwrOff() { }
|
||||
#endif
|
||||
|
||||
#if defined(CPUSTM32)
|
||||
void pwrInit() { }
|
||||
void pwrOff() { }
|
||||
int usbPlugged() { return false; }
|
||||
void USART_DeInit(USART_TypeDef* ) { }
|
||||
ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct) { return SUCCESS; }
|
||||
|
|
|
@ -264,6 +264,7 @@ void btPushByte(uint8_t data);
|
|||
void pwrInit();
|
||||
void pwrOff();
|
||||
uint32_t pwrCheck();
|
||||
uint32_t pwroffPressed();
|
||||
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
|
||||
|
||||
// EEPROM driver
|
||||
|
|
|
@ -18,7 +18,16 @@
|
|||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "../../opentx.h"
|
||||
#include "opentx.h"
|
||||
|
||||
uint32_t pwroffPressed()
|
||||
{
|
||||
#if defined(SIMU) || defined(REVA)
|
||||
return false;
|
||||
#else
|
||||
return !(PIOC->PIO_PDSR & PIO_PC17);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t pwrCheck()
|
||||
{
|
||||
|
@ -32,7 +41,7 @@ uint32_t pwrCheck()
|
|||
else
|
||||
return e_power_on;
|
||||
#elif defined(REVB)
|
||||
if (PIOC->PIO_PDSR & PIO_PC17)
|
||||
if (!pwroffPressed())
|
||||
return e_power_on;
|
||||
else if (usbPlugged())
|
||||
return e_power_usb;
|
||||
|
@ -41,7 +50,7 @@ uint32_t pwrCheck()
|
|||
else
|
||||
return e_power_off;
|
||||
#else
|
||||
if (PIOC->PIO_PDSR & PIO_PC17)
|
||||
if (!pwroffPressed())
|
||||
return e_power_on;
|
||||
else if (PIOA->PIO_PDSR & PIO_PA8)
|
||||
return e_power_trainer;
|
||||
|
|
|
@ -286,6 +286,9 @@ void pwrOff(void);
|
|||
#if defined(REV9E)
|
||||
uint32_t pwrPressed(void);
|
||||
uint32_t pwrPressedDuration(void);
|
||||
#define pwroffPressed() pwrPressed()
|
||||
#else
|
||||
uint32_t pwroffPressed(void);
|
||||
#endif
|
||||
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "../../pwr.h"
|
||||
#include "pwr.h"
|
||||
#include "board_taranis.h"
|
||||
|
||||
void pwrInit()
|
||||
|
@ -87,7 +87,7 @@ void pwrOff()
|
|||
}
|
||||
#endif
|
||||
}
|
||||
//this function must not return!
|
||||
// this function must not return!
|
||||
}
|
||||
|
||||
#if defined(REV9E)
|
||||
|
@ -95,20 +95,21 @@ uint32_t pwrPressed()
|
|||
{
|
||||
return GPIO_ReadInputDataBit(PWR_GPIO, PWR_SWITCH_GPIO_PIN) == Bit_RESET;
|
||||
}
|
||||
#else
|
||||
uint32_t pwroffPressed()
|
||||
{
|
||||
return GPIO_ReadInputDataBit(PWR_GPIO, PWR_SWITCH_GPIO_PIN) != Bit_RESET;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(REV9E)
|
||||
uint32_t pwrCheck()
|
||||
{
|
||||
#if defined(SIMU)
|
||||
return e_power_on;
|
||||
#else
|
||||
if (GPIO_ReadInputDataBit(PWR_GPIO, PWR_SWITCH_GPIO_PIN) == Bit_RESET)
|
||||
if (!pwroffPressed())
|
||||
return e_power_on;
|
||||
else if (usbPlugged())
|
||||
return e_power_usb;
|
||||
else
|
||||
return e_power_off;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -91,6 +91,32 @@ uint16_t stackAvailable()
|
|||
}
|
||||
#endif
|
||||
|
||||
volatile uint16_t timeForcePowerOffPressed = 0;
|
||||
|
||||
void resetForcePowerOffRequest()
|
||||
{
|
||||
timeForcePowerOffPressed = 0;
|
||||
}
|
||||
|
||||
bool isForcePowerOffRequested()
|
||||
{
|
||||
if (pwroffPressed()) {
|
||||
if (timeForcePowerOffPressed == 0) {
|
||||
timeForcePowerOffPressed = get_tmr10ms();
|
||||
}
|
||||
else {
|
||||
uint16_t delay = (uint16_t)get_tmr10ms() - timeForcePowerOffPressed;
|
||||
if (delay > 1000/*10s*/) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
resetForcePowerOffRequest();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t nextMixerTime[NUM_MODULES];
|
||||
|
||||
void mixerTask(void * pdata)
|
||||
|
@ -111,6 +137,10 @@ void mixerTask(void * pdata)
|
|||
|
||||
CoTickDelay(1);
|
||||
|
||||
if (isForcePowerOffRequested()) {
|
||||
pwrOff();
|
||||
}
|
||||
|
||||
uint32_t now = CoGetOSTime();
|
||||
bool run = false;
|
||||
if ((now - lastRunTime) > 10) { // run at least every 20ms
|
||||
|
@ -197,6 +227,8 @@ void menusTask(void * pdata)
|
|||
CoTickDelay(MENU_TASK_PERIOD_TICKS - runtime);
|
||||
}
|
||||
|
||||
resetForcePowerOffRequest();
|
||||
|
||||
#if defined(SIMU)
|
||||
if (main_thread_running == 0)
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue