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
|
||||
|
|
|
@ -1,24 +1,33 @@
|
|||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "../../opentx.h"
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#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)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
|
@ -18,7 +18,7 @@
|
|||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "../../pwr.h"
|
||||
#include "pwr.h"
|
||||
#include "board_taranis.h"
|
||||
|
||||
void pwrInit()
|
||||
|
@ -43,12 +43,12 @@ void pwrInit()
|
|||
GPIO_InitStructure.GPIO_Pin = INTMODULE_PWR_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(INTMODULE_PWR_GPIO, &GPIO_InitStructure);
|
||||
|
||||
|
||||
GPIO_ResetBits(EXTMODULE_PWR_GPIO, EXTMODULE_PWR_GPIO_PIN);
|
||||
GPIO_InitStructure.GPIO_Pin = EXTMODULE_PWR_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(EXTMODULE_PWR_GPIO, &GPIO_InitStructure);
|
||||
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = TRAINER_GPIO_PIN_DETECT;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_Init(TRAINER_GPIO_DETECT, &GPIO_InitStructure);
|
||||
|
@ -71,7 +71,7 @@ void pwrOff()
|
|||
while(1) {
|
||||
wdt_reset();
|
||||
#if defined(REV9E)
|
||||
// 9E needs watchdog reset because CPU is still running while
|
||||
// 9E needs watchdog reset because CPU is still running while
|
||||
// the power key is held pressed by the user.
|
||||
// The power key should be released by now, but we must make sure
|
||||
if (!pwrPressed()) {
|
||||
|
@ -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
|
||||
|
@ -160,7 +190,7 @@ void mixerTask(void * pdata)
|
|||
|
||||
void scheduleNextMixerCalculation(uint8_t module, uint16_t delay)
|
||||
{
|
||||
// Schedule next mixer calculation time,
|
||||
// Schedule next mixer calculation time,
|
||||
// for now assume mixer calculation takes 2 ms.
|
||||
nextMixerTime[module] = (uint32_t)CoGetOSTime() + (delay)/2 - 1/*2ms*/;
|
||||
DEBUG_TIMER_STOP(debugTimerMixerCalcToUsage);
|
||||
|
@ -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