mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-09 22:49:53 +08:00
[settings] Support functions (#2880)
* [chibios] Add reboot functionality * [modules] Add power switch module
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
telemetry="telemetry/fixedwing_flight_recorder.xml"
|
||||
flight_plan="flight_plans/basic.xml"
|
||||
settings="settings/fixedwing_basic.xml"
|
||||
settings_modules="modules/ahrs_float_dcm.xml modules/gps.xml modules/guidance_basic_fw.xml modules/imu_common.xml modules/nav_basic_fw.xml modules/stabilization_attitude_fw.xml"
|
||||
settings_modules="modules/ahrs_float_dcm.xml modules/gps.xml modules/guidance_basic_fw.xml modules/imu_common.xml modules/nav_basic_fw.xml modules/power_switch.xml modules/stabilization_attitude_fw.xml"
|
||||
gui_color="blue"
|
||||
/>
|
||||
<aircraft
|
||||
@@ -73,7 +73,7 @@
|
||||
telemetry="telemetry/default_fixedwing_imu.xml"
|
||||
flight_plan="flight_plans/basic.xml"
|
||||
settings="settings/fixedwing_basic.xml [settings/nps.xml]"
|
||||
settings_modules="modules/ahrs_float_dcm.xml modules/airspeed_adc.xml modules/gps.xml [modules/gps_ubx_ucenter.xml] modules/guidance_full_pid_fw.xml modules/imu_common.xml modules/ins_float_invariant.xml modules/nav_basic_fw.xml modules/stabilization_adaptive_fw.xml"
|
||||
settings_modules="modules/ahrs_float_dcm.xml modules/airspeed_adc.xml modules/gps.xml [modules/gps_ubx_ucenter.xml] modules/guidance_full_pid_fw.xml modules/imu_common.xml modules/ins_float_invariant.xml modules/nav_basic_fw.xml modules/power_switch.xml modules/stabilization_adaptive_fw.xml"
|
||||
gui_color="#ffff7d7d0000"
|
||||
/>
|
||||
<aircraft
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@
|
||||
telemetry="telemetry/fixedwing_flight_recorder.xml"
|
||||
flight_plan="flight_plans/basic.xml"
|
||||
settings="settings/fixedwing_basic.xml"
|
||||
settings_modules="modules/ahrs_float_dcm.xml modules/gps.xml modules/guidance_basic_fw.xml modules/imu_common.xml modules/nav_basic_fw.xml modules/stabilization_attitude_fw.xml"
|
||||
settings_modules="modules/ahrs_float_dcm.xml modules/gps.xml modules/guidance_basic_fw.xml modules/imu_common.xml modules/nav_basic_fw.xml modules/power_switch.xml modules/stabilization_attitude_fw.xml"
|
||||
gui_color="blue"
|
||||
/>
|
||||
<aircraft
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</description>
|
||||
</doc>
|
||||
<dep>
|
||||
<depends>i2c,baro_board_common</depends>
|
||||
<depends>i2c,baro_board_common,power_switch</depends>
|
||||
<provides>baro</provides>
|
||||
</dep>
|
||||
<makefile target="!sim|nps|fbw">
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</description>
|
||||
</doc>
|
||||
<dep>
|
||||
<depends>i2c,baro_board_common,hard_fault_recovery</depends>
|
||||
<depends>i2c,baro_board_common,hard_fault_recovery,power_switch</depends>
|
||||
<provides>baro</provides>
|
||||
</dep>
|
||||
<makefile target="!sim|nps|fbw">
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<depends>spi_master,baro_ms5611_spi</depends>
|
||||
</dep>
|
||||
<makefile target="!sim|nps|fbw">
|
||||
<define name="USE_RTC_BACKUP" value="TRUE"/>
|
||||
<configure name="SDLOG_USE_RTC" value="FALSE"/>
|
||||
<configure name="MS5611_SPI_DEV" value="spi1"/> <!-- spi4 -->
|
||||
<configure name="MS5611_SLAVE_IDX" value="SPI_SLAVE6"/> <!-- SPI_SLAVE4 -->
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<depends>spi_master,baro_board</depends>
|
||||
</dep>
|
||||
<makefile target="!sim|nps|fbw">
|
||||
<define name="USE_RTC_BACKUP" value="TRUE"/>
|
||||
<configure name="SDLOG_USE_RTC" value="FALSE"/>
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
|
||||
<module name="power_switch" dir="boards">
|
||||
<doc>
|
||||
<description>Simple power switch module to set a specific GPIO pin</description>
|
||||
</doc>
|
||||
<settings>
|
||||
<dl_settings>
|
||||
<dl_settings NAME="Board">
|
||||
<dl_setting var="power_switch_status" min="0" step="1" max="1" shortname="pwr_switch" values="OFF|ON" handler="set" module="boards/power_switch"/>
|
||||
</dl_settings>
|
||||
</dl_settings>
|
||||
</settings>
|
||||
<header>
|
||||
<file name="power_switch.h"/>
|
||||
</header>
|
||||
<init fun="power_switch_init()"/>
|
||||
<makefile>
|
||||
<file name="power_switch.c"/>
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
@@ -23,5 +23,9 @@
|
||||
<dl_setting MAX="1" MIN="0" STEP="1" VAR="autopilot.kill_throttle"/>
|
||||
</dl_settings>
|
||||
|
||||
<dl_settings NAME="mcu">
|
||||
<dl_setting var="mcu_reboot" shortname="reboot" min="0" step="1" max="3" values="NORMAL|POWEROFF|FAST|BOOTLOADER" handler="reboot" module="mcu" type="fun"/>
|
||||
</dl_settings>
|
||||
|
||||
</dl_settings>
|
||||
</settings>
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<!DOCTYPE settings SYSTEM "settings.dtd">
|
||||
|
||||
<settings>
|
||||
<dl_settings NAME="Power switch control">
|
||||
<dl_settings NAME="Power switch">
|
||||
<dl_setting MAX="1" MIN="0" STEP="1" VAR="autopilot.power_switch" module="autopilot" handler="SetPowerSwitch">
|
||||
<strip_button name="Switch on" icon="on.png" value="1" group="power_switch"/>
|
||||
<strip_button name="Switch off" icon="off.png" value="0" group="power_switch"/>
|
||||
</dl_setting>
|
||||
</dl_settings>
|
||||
</dl_settings>
|
||||
</settings>
|
||||
@@ -6,11 +6,8 @@
|
||||
<dl_settings NAME="System">
|
||||
<dl_setting var="autopilot_mode_auto2" min="0" step="1" max="19" module="autopilot" shortname="auto2" values="KILL|Fail|HOME|Rate|Att|Rate_rcC|Att_rcC|Att_C|Rate_Z|Att_Z|Hover|Hover_C|Hover_Z|Nav|RC_D|CareFree|Forward|Module|Flip|Guided"/>
|
||||
<dl_setting var="autopilot.kill_throttle" min="0" step="1" max="1" module="autopilot" values="Resurrect|Kill" handler="KillThrottle"/>
|
||||
<dl_setting var="autopilot.power_switch" min="0" step="1" max="1" module="autopilot" values="OFF|ON" handler="SetPowerSwitch">
|
||||
<strip_button name="POWER ON" icon="on.png" value="1" group="power_switch"/>
|
||||
<strip_button name="POWER OFF" icon="off.png" value="0" group="power_switch"/>
|
||||
</dl_setting>
|
||||
<dl_setting var="autopilot.mode" min="0" step="1" max="19" module="autopilot" shortname="mode" values="KILL|Fail|HOME|Rate|Att|Rate_rcC|Att_rcC|Att_C|Rate_Z|Att_Z|Hover|Hover_C|Hover_Z|Nav|RC_D|CareFree|Forward|Module|Flip|Guided" handler="SetModeHandler"/>
|
||||
<dl_setting var="mcu_reboot" shortname="reboot" min="0" step="1" max="3" values="NORMAL|POWEROFF|FAST|BOOTLOADER" handler="reboot" module="mcu" type="fun"/>
|
||||
</dl_settings>
|
||||
|
||||
</dl_settings>
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<!DOCTYPE settings SYSTEM "settings.dtd">
|
||||
|
||||
<settings target="ap|nps">
|
||||
<dl_settings>
|
||||
|
||||
<dl_settings NAME="System">
|
||||
<dl_setting var="autopilot_mode_auto2" min="0" step="1" max="19" module="autopilot" shortname="auto2" values="KILL|Fail|HOME|Rate|Att|Rate_rcC|Att_rcC|Att_C|Rate_Z|Att_Z|Hover|Hover_C|Hover_Z|Nav|RC_D|CareFree|Forward|Module|Flip|Guided"/>
|
||||
<dl_setting var="autopilot.kill_throttle" min="0" step="1" max="1" module="autopilot" values="Resurrect|Kill" handler="KillThrottle"/>
|
||||
<dl_setting var="autopilot.power_switch" min="0" step="1" max="1" module="autopilot" values="OFF|ON" handler="SetPowerSwitch">
|
||||
<strip_button name="POWER ON" icon="on.png" value="1" group="power_switch"/>
|
||||
<strip_button name="POWER OFF" icon="off.png" value="0" group="power_switch"/>
|
||||
</dl_setting>
|
||||
<dl_setting var="autopilot.mode" min="0" step="1" max="19" module="autopilot" shortname="mode" values="KILL|Fail|HOME|Rate|Att|Rate_rcC|Att_rcC|Att_C|Rate_Z|Att_Z|Hover|Hover_C|Hover_Z|Nav|RC_D|CareFree|Forward|Module|Flip|Guided" handler="SetModeHandler"/>
|
||||
<dl_setting var="multi_gps_mode" min="0" step="1" max="2" module="modules/gps/gps" shortname="gpsmode" values="AUTO|PRIMARY|SECONDARY">
|
||||
<strip_button name="AUTO" icon="gps.png" value="0" group="gps_mode"/>
|
||||
<strip_button name="PRIMARY" icon="gps1.png" value="1" group="gps_mode_setting"/>
|
||||
<strip_button name="SECONDARY" icon="gps2.png" value="2" group="gps_mode_setting"/>
|
||||
</dl_setting>
|
||||
</dl_settings>
|
||||
|
||||
</dl_settings>
|
||||
</settings>
|
||||
@@ -5,11 +5,8 @@
|
||||
|
||||
<dl_settings NAME="System">
|
||||
<dl_setting var="autopilot.kill_throttle" min="0" step="1" max="1" module="autopilot" values="Resurrect|Kill" handler="KillThrottle"/>
|
||||
<dl_setting var="autopilot.power_switch" min="0" step="1" max="1" module="autopilot" values="OFF|ON" handler="SetPowerSwitch">
|
||||
<strip_button name="POWER ON" icon="on.png" value="1" group="power_switch"/>
|
||||
<strip_button name="POWER OFF" icon="off.png" value="0" group="power_switch"/>
|
||||
</dl_setting>
|
||||
<dl_setting var="autopilot.mode" min="0" step="1" max="19" module="autopilot" shortname="mode" handler="SetModeHandler"/>
|
||||
<dl_setting var="mcu_reboot" shortname="reboot" min="0" step="1" max="3" values="NORMAL|POWEROFF|FAST|BOOTLOADER" handler="reboot" module="mcu" type="fun"/>
|
||||
</dl_settings>
|
||||
|
||||
</dl_settings>
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<!DOCTYPE settings SYSTEM "settings.dtd">
|
||||
|
||||
<settings>
|
||||
<dl_settings NAME="Power switch control">
|
||||
<dl_settings NAME="Power switch">
|
||||
<dl_setting MAX="1" MIN="0" STEP="1" VAR="autopilot.power_switch" module="autopilot" handler="SetPowerSwitch">
|
||||
<strip_button name="Switch on" icon="on.png" value="0" group="switch_light"/>
|
||||
<strip_button name="Switch off" icon="off.png" value="1" group="switch_light"/>
|
||||
</dl_setting>
|
||||
</dl_settings>
|
||||
</dl_settings>
|
||||
</settings>
|
||||
@@ -289,7 +289,6 @@ bool sdc_lld_is_write_protected(SDCDriver *sdcp)
|
||||
*/
|
||||
bool mmc_lld_is_card_inserted(MMCDriver *mmcp)
|
||||
{
|
||||
|
||||
(void)mmcp;
|
||||
/* TODO: Fill the implementation.*/
|
||||
return true;
|
||||
@@ -300,7 +299,6 @@ bool mmc_lld_is_card_inserted(MMCDriver *mmcp)
|
||||
*/
|
||||
bool mmc_lld_is_write_protected(MMCDriver *mmcp)
|
||||
{
|
||||
|
||||
(void)mmcp;
|
||||
/* TODO: Fill the implementation.*/
|
||||
return false;
|
||||
|
||||
@@ -57,31 +57,31 @@ IN_BCKP_SECTION(volatile bool hard_fault);
|
||||
CH_IRQ_HANDLER(HardFault_Handler)
|
||||
{
|
||||
hard_fault = true;
|
||||
NVIC_SystemReset();
|
||||
mcu_reboot(MCU_REBOOT_FAST);
|
||||
}
|
||||
|
||||
CH_IRQ_HANDLER(NMI_Handler)
|
||||
{
|
||||
hard_fault = true;
|
||||
NVIC_SystemReset();
|
||||
mcu_reboot(MCU_REBOOT_FAST);
|
||||
}
|
||||
|
||||
CH_IRQ_HANDLER(MemManage_Handler)
|
||||
{
|
||||
hard_fault = true;
|
||||
NVIC_SystemReset();
|
||||
mcu_reboot(MCU_REBOOT_FAST);
|
||||
}
|
||||
|
||||
CH_IRQ_HANDLER(BusFault_Handler)
|
||||
{
|
||||
hard_fault = true;
|
||||
NVIC_SystemReset();
|
||||
mcu_reboot(MCU_REBOOT_FAST);
|
||||
}
|
||||
|
||||
CH_IRQ_HANDLER(UsageFault_Handler)
|
||||
{
|
||||
hard_fault = true;
|
||||
NVIC_SystemReset();
|
||||
mcu_reboot(MCU_REBOOT_FAST);
|
||||
}
|
||||
|
||||
bool recovering_from_hard_fault;
|
||||
@@ -99,12 +99,27 @@ bool recovering_from_hard_fault;
|
||||
#error Hard fault recovery not supported
|
||||
#endif
|
||||
|
||||
#endif /* USE_HARD_FAULT_RECOVERY */
|
||||
|
||||
/**
|
||||
* @brief RTC backup register values
|
||||
*/
|
||||
enum rtc_boot_magic {
|
||||
RTC_BOOT_OFF = 0, ///< Normal boot
|
||||
RTC_BOOT_HOLD = 0xb0070001, ///< Hold in bootloader, do not boot application
|
||||
RTC_BOOT_FAST = 0xb0070002, ///< No timeout in bootloader
|
||||
RTC_BOOT_CANBL = 0xb0080000, ///< CAN bootloader, ORd with 8 bit local node ID
|
||||
RTC_BOOT_FWOK = 0xb0093a26 ///< indicates FW ran for 30s
|
||||
};
|
||||
|
||||
/* Local functions */
|
||||
static void mcu_deep_sleep(void);
|
||||
#if defined(USE_RTC_BACKUP)
|
||||
static void mcu_set_rtcbackup(uint32_t val);
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* SCB_VTOR has to be relocated if Luftboot is used
|
||||
* The new SCB_VTOR location is defined in the board makefile
|
||||
/**
|
||||
* @brief Initialize the specific archittecture functions
|
||||
*/
|
||||
void mcu_arch_init(void)
|
||||
{
|
||||
@@ -143,14 +158,41 @@ void mcu_arch_init(void)
|
||||
RCC->CSR = RCC_CSR_RMVF;
|
||||
// end of reset bit probing
|
||||
#endif /* USE_HARD_FAULT_RECOVERY */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reboot the MCU
|
||||
* - POWEROFF will go the deep sleep
|
||||
* - NORMAL will do a normal reboot (also to bootloader)
|
||||
* - FAST will try to skip the bootloader
|
||||
* - BOOTLOADER will try to keep the MCU in bootloader
|
||||
* @param reboot_state The sate to reboot to
|
||||
*/
|
||||
void mcu_reboot(enum reboot_state_t reboot_state)
|
||||
{
|
||||
// Powering off/deep sleep instead
|
||||
if(reboot_state == MCU_REBOOT_POWEROFF) {
|
||||
mcu_deep_sleep();
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(USE_RTC_BACKUP)
|
||||
// Set the RTC backup register if possible
|
||||
if(reboot_state == MCU_REBOOT_FAST)
|
||||
mcu_set_rtcbackup(RTC_BOOT_FAST);
|
||||
else if(reboot_state == MCU_REBOOT_BOOTLOADER)
|
||||
mcu_set_rtcbackup(RTC_BOOT_HOLD);
|
||||
#endif
|
||||
|
||||
// Restart the MCU
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Save energy for performing operations on shutdown
|
||||
* Used for example to shutdown SD-card logging
|
||||
*/
|
||||
void mcu_periph_energy_save(void)
|
||||
void mcu_energy_save(void)
|
||||
{
|
||||
#if defined(ENERGY_SAVE_INPUTS)
|
||||
BOARD_GROUP_DECLFOREACH(input_line, ENERGY_SAVE_INPUTS) {
|
||||
@@ -164,3 +206,75 @@ void mcu_periph_energy_save(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Put MCU into deep sleep mode
|
||||
*
|
||||
* This can be used when closing the SD log files
|
||||
* right after a power down to save the remaining
|
||||
* energy for the SD card internal MCU
|
||||
*
|
||||
* Never call this during flight!
|
||||
*/
|
||||
static void mcu_deep_sleep(void)
|
||||
{
|
||||
#if defined(STM32F4XX)
|
||||
/* clear PDDS and LPDS bits */
|
||||
PWR->CR &= ~(PWR_CR_PDDS | PWR_CR_LPDS);
|
||||
/* set LPDS and clear */
|
||||
PWR->CR |= (PWR_CR_LPDS | PWR_CR_CSBF | PWR_CR_CWUF);
|
||||
#elif defined(STM32F7XX)
|
||||
/* clear PDDS and LPDS bits */
|
||||
PWR->CR1 &= ~(PWR_CR1_PDDS | PWR_CR1_LPDS);
|
||||
/* set LPDS and clear */
|
||||
PWR->CR1 |= (PWR_CR1_LPDS | PWR_CR1_CSBF);
|
||||
#elif defined(STM32H7XX)
|
||||
/* clear LPDS */
|
||||
PWR->CR1 &= ~PWR_CR1_LPDS;
|
||||
/* set LPDS */
|
||||
PWR->CR1 |= PWR_CR1_LPDS;
|
||||
#endif
|
||||
|
||||
/* Setup the deepsleep mask */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
__disable_irq();
|
||||
|
||||
__SEV();
|
||||
__WFE();
|
||||
__WFE();
|
||||
|
||||
__enable_irq();
|
||||
|
||||
/* clear the deepsleep mask */
|
||||
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
|
||||
}
|
||||
|
||||
#if defined(USE_RTC_BACKUP)
|
||||
/**
|
||||
* @brief Set the RTC backup register
|
||||
* This sets the first register in the RTC backup register, used for bootloader
|
||||
* @param val The value to set in the register
|
||||
*/
|
||||
static void mcu_set_rtcbackup(uint32_t val) {
|
||||
#if !defined(STM32F1)
|
||||
if ((RCC->BDCR & RCC_BDCR_RTCEN) == 0) {
|
||||
RCC->BDCR |= STM32_RTCSEL;
|
||||
RCC->BDCR |= RCC_BDCR_RTCEN;
|
||||
}
|
||||
#ifdef PWR_CR_DBP
|
||||
PWR->CR |= PWR_CR_DBP;
|
||||
#else
|
||||
PWR->CR1 |= PWR_CR1_DBP;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(STM32F1)
|
||||
volatile uint32_t *dr = (volatile uint32_t *)&BKP->DR1;
|
||||
dr[0] = (val) & 0xFFFF;
|
||||
dr[1] = (val) >> 16;
|
||||
#elif defined(STM32G4)
|
||||
((volatile uint32_t *)&TAMP->BKP0R)[0] = val;
|
||||
#else
|
||||
((volatile uint32_t *)&RTC->BKP0R)[0] = val;
|
||||
#endif
|
||||
}
|
||||
#endif /* USE_RTC_BACKUP */
|
||||
|
||||
@@ -39,60 +39,4 @@ extern void mcu_arch_init(void);
|
||||
extern bool recovering_from_hard_fault;
|
||||
#endif
|
||||
|
||||
#include <ch.h>
|
||||
|
||||
/** Put MCU into deep sleep mode
|
||||
*
|
||||
* This can be used when closing the SD log files
|
||||
* right after a power down to save the remaining
|
||||
* energy for the SD card internal MCU
|
||||
*
|
||||
* Never call this during flight!
|
||||
*/
|
||||
static inline void mcu_deep_sleep(void)
|
||||
{
|
||||
#if defined(STM32F4XX)
|
||||
/* clear PDDS and LPDS bits */
|
||||
PWR->CR &= ~(PWR_CR_PDDS | PWR_CR_LPDS);
|
||||
/* set LPDS and clear */
|
||||
PWR->CR |= (PWR_CR_LPDS | PWR_CR_CSBF | PWR_CR_CWUF);
|
||||
#elif defined(STM32F7XX)
|
||||
/* clear PDDS and LPDS bits */
|
||||
PWR->CR1 &= ~(PWR_CR1_PDDS | PWR_CR1_LPDS);
|
||||
/* set LPDS and clear */
|
||||
PWR->CR1 |= (PWR_CR1_LPDS | PWR_CR1_CSBF);
|
||||
#elif defined(STM32H7XX)
|
||||
/* clear LPDS */
|
||||
PWR->CR1 &= ~PWR_CR1_LPDS;
|
||||
/* set LPDS */
|
||||
PWR->CR1 |= PWR_CR1_LPDS;
|
||||
#endif
|
||||
|
||||
/* Setup the deepsleep mask */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
__disable_irq();
|
||||
|
||||
__SEV();
|
||||
__WFE();
|
||||
__WFE();
|
||||
|
||||
__enable_irq();
|
||||
|
||||
/* clear the deepsleep mask */
|
||||
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
|
||||
}
|
||||
|
||||
/** Request a software reset of the MCU
|
||||
*/
|
||||
static inline void mcu_reset(void)
|
||||
{
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
/** Call board specific energy saving
|
||||
* Can be necessary for closing on power off
|
||||
*/
|
||||
extern void mcu_periph_energy_save(void);
|
||||
|
||||
#endif /* CHIBIOS_MCU_ARCH_H */
|
||||
|
||||
@@ -116,15 +116,6 @@ void autopilot_init(void)
|
||||
autopilot.ground_detected = false;
|
||||
autopilot.detect_ground_once = false;
|
||||
autopilot.use_rc = true;
|
||||
autopilot.power_switch = false;
|
||||
#ifdef POWER_SWITCH_GPIO
|
||||
gpio_setup_output(POWER_SWITCH_GPIO);
|
||||
#ifdef POWER_SWITCH_ENABLE
|
||||
autopilot_set_power_switch(POWER_SWITCH_ENABLE); // set initial status
|
||||
#else
|
||||
gpio_clear(POWER_SWITCH_GPIO); // by default POWER OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// call firmware specific init
|
||||
autopilot_firmware_init();
|
||||
@@ -300,20 +291,6 @@ bool autopilot_in_flight(void)
|
||||
return autopilot.in_flight;
|
||||
}
|
||||
|
||||
/** set power switch
|
||||
*/
|
||||
void autopilot_set_power_switch(bool power_switch)
|
||||
{
|
||||
#ifdef POWER_SWITCH_GPIO
|
||||
if (power_switch) {
|
||||
gpio_set(POWER_SWITCH_GPIO);
|
||||
} else {
|
||||
gpio_clear(POWER_SWITCH_GPIO);
|
||||
}
|
||||
#endif
|
||||
autopilot.power_switch = power_switch;
|
||||
}
|
||||
|
||||
/** store settings
|
||||
*/
|
||||
void autopilot_store_settings(void)
|
||||
|
||||
@@ -70,7 +70,6 @@ struct pprz_autopilot {
|
||||
bool in_flight; ///< in flight status
|
||||
bool launch; ///< request launch
|
||||
bool use_rc; ///< enable/disable RC input
|
||||
bool power_switch; ///< enable/disable power from power switch (if any)
|
||||
bool ground_detected; ///< automatic detection of landing
|
||||
bool detect_ground_once; ///< enable automatic detection of ground (one shot)
|
||||
};
|
||||
@@ -173,15 +172,6 @@ extern bool autopilot_in_flight(void);
|
||||
*/
|
||||
extern void autopilot_reset_in_flight_counter(void);
|
||||
|
||||
/** Set power switch state
|
||||
* This will actually enable the switch if POWER_SWITCH_GPIO is defined
|
||||
* Also provide macro for dl_setting backward compatibility
|
||||
*
|
||||
* @param[in] power_switch true to enable, false to disable
|
||||
*/
|
||||
extern void autopilot_set_power_switch(bool power_switch);
|
||||
#define autopilot_SetPowerSwitch(_ps) autopilot_set_power_switch(_ps)
|
||||
|
||||
/** Store marked settings in flash
|
||||
* Try to make sure that we don't write to flash while flying
|
||||
* Also provide macro for dl_setting backward compatibility
|
||||
|
||||
@@ -84,6 +84,16 @@ void WEAK board_init2(void)
|
||||
/* default board init function does nothing... */
|
||||
}
|
||||
|
||||
void WEAK mcu_reboot(enum reboot_state_t reboot_state __attribute__((unused)))
|
||||
{
|
||||
/* default reboot function does nothing... */
|
||||
}
|
||||
|
||||
void WEAK mcu_energy_save(void)
|
||||
{
|
||||
/* default power saving function does nothing... */
|
||||
}
|
||||
|
||||
void mcu_init(void)
|
||||
{
|
||||
/* If we have a board specific init function, call it.
|
||||
|
||||
@@ -36,6 +36,16 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The requested reboot states
|
||||
*/
|
||||
enum reboot_state_t {
|
||||
MCU_REBOOT_NORMAL, ///< Normal reboot
|
||||
MCU_REBOOT_POWEROFF, ///< Poweroff the device
|
||||
MCU_REBOOT_FAST, ///< Fast reboot (skip bootloader)
|
||||
MCU_REBOOT_BOOTLOADER ///< Go to bootloader
|
||||
};
|
||||
|
||||
/**
|
||||
* Microcontroller peripherals initialization.
|
||||
* This function is responisble for setting up the microcontroller
|
||||
@@ -49,6 +59,20 @@ extern void mcu_init(void);
|
||||
*/
|
||||
extern void mcu_event(void);
|
||||
|
||||
/**
|
||||
* Reboot the MCU
|
||||
* Should not be called during flight or ciritcal operations
|
||||
* @param state The state to reboot towards
|
||||
*/
|
||||
extern void mcu_reboot(enum reboot_state_t reboot_state);
|
||||
|
||||
/**
|
||||
* Puts the MCU in energy save mode
|
||||
* This disables features of the MCU to save energy. This is used for
|
||||
* example to quickly write to the SD card while powering off.
|
||||
*/
|
||||
extern void mcu_energy_save(void);
|
||||
|
||||
/**
|
||||
* Optional board init function called at the start of mcu_init().
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) Freek van Tienen <freek.v.tienen@gmail.com>
|
||||
*
|
||||
* This file is part of paparazzi
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file "modules/boards/power_switch.c"
|
||||
* @author F. van Tienen
|
||||
* Simple GPIO power switch module
|
||||
*/
|
||||
#include "power_switch.h"
|
||||
#include "mcu_periph/gpio.h"
|
||||
#include "generated/airframe.h"
|
||||
bool power_switch_status = false;
|
||||
|
||||
#if !defined(POWER_SWITCH_GPIO)
|
||||
#error "The power switch module needs POWER_SWITCH_GPIO to be defined"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Intialize the power switch pins
|
||||
* This sets the power switch pins to te initial state
|
||||
*/
|
||||
void power_switch_init(void) {
|
||||
gpio_setup_output(POWER_SWITCH_GPIO);
|
||||
#ifdef POWER_SWITCH_ENABLE
|
||||
power_switch_set(POWER_SWITCH_ENABLE);
|
||||
#else
|
||||
gpio_clear(POWER_SWITCH_GPIO);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the power switch to enable/disable
|
||||
*
|
||||
* @param val True enables the pin, False disables the pin
|
||||
*/
|
||||
void power_switch_set(bool val) {
|
||||
if(val) {
|
||||
gpio_set(POWER_SWITCH_GPIO);
|
||||
} else {
|
||||
gpio_clear(POWER_SWITCH_GPIO);
|
||||
}
|
||||
|
||||
power_switch_status = val;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) Freek van Tienen <freek.v.tienen@gmail.com>
|
||||
*
|
||||
* This file is part of paparazzi
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file "modules/boards/power_switch.h"
|
||||
* @author F. van Tienen
|
||||
* Simple GPIO power switch module
|
||||
*/
|
||||
#include "std.h"
|
||||
|
||||
extern bool power_switch_status;
|
||||
extern void power_switch_init(void);
|
||||
extern void power_switch_set(bool val);
|
||||
@@ -198,7 +198,7 @@ void sdlog_chibios_finish(const bool flush)
|
||||
if (pprzLogFile != -1) {
|
||||
// disable all required periph to save energy and maximize chance to flush files
|
||||
// to mass storage and avoid infamous dirty bit on filesystem
|
||||
mcu_periph_energy_save();
|
||||
mcu_energy_save();
|
||||
|
||||
// if a FF_FS_REENTRANT is true, we can umount fs without closing
|
||||
// file, fatfs lock will assure that umount is done after a write,
|
||||
@@ -327,7 +327,7 @@ static void thd_bat_survey(void *arg)
|
||||
|
||||
// Only put to deep sleep in case there is no power on the USB
|
||||
if (palReadPad(SDLOG_USB_VBUS_PORT, SDLOG_USB_VBUS_PIN) == PAL_LOW) {
|
||||
mcu_deep_sleep();
|
||||
mcu_reboot(MCU_REBOOT_POWEROFF);
|
||||
}
|
||||
chThdSleep(TIME_INFINITE);
|
||||
while (true); // never goes here, only to avoid compiler warning: 'noreturn' function does return
|
||||
|
||||
@@ -157,7 +157,7 @@ static void thdUsbStorage(void *arg)
|
||||
|
||||
chThdSleepMilliseconds(500);
|
||||
|
||||
mcu_reset();
|
||||
mcu_reboot(MCU_REBOOT_FAST);
|
||||
}
|
||||
|
||||
bool usbStorageIsItRunning(void)
|
||||
|
||||
@@ -90,13 +90,16 @@ let print_dl_settings = fun out settings settings_xml ->
|
||||
try
|
||||
let h = ExtXml.attrib s "handler" in
|
||||
begin
|
||||
let t = ExtXml.attrib_or_default s "type" "" in
|
||||
let m1 = ExtXml.attrib_or_default s "module" "" in
|
||||
let m2 = ExtXml.attrib_or_default s "header" "" in
|
||||
match m1, m2 with
|
||||
| "", "" -> prerr_endline (sprintf "Error: You need to specify the header (or module for legacy) attribute for setting %s to use the handler %s" v h); exit 1
|
||||
| "", _ -> lprintf out "case %d: %s_%s( _value ); _value = %s; break;\\\n" !idx (Filename.basename m2) h v
|
||||
| _, "" -> lprintf out "case %d: %s_%s( _value ); _value = %s; break;\\\n" !idx (Filename.basename m1) h v
|
||||
| _, _ -> prerr_endline (sprintf "Error: You can't specify both module and header attributes for setting %s to use the handler %s" v h); exit 1
|
||||
match m1, m2, t with
|
||||
| "", "", _ -> prerr_endline (sprintf "Error: You need to specify the header (or module for legacy) attribute for setting %s to use the handler %s" v h); exit 1
|
||||
| "", _, "fun" -> lprintf out "case %d: %s_%s( _value ); break;\\\n" !idx (Filename.basename m2) h
|
||||
| _, "", "fun" -> lprintf out "case %d: %s_%s( _value ); break;\\\n" !idx (Filename.basename m1) h
|
||||
| "", _, _ -> lprintf out "case %d: %s_%s( _value ); _value = %s; break;\\\n" !idx (Filename.basename m2) h v
|
||||
| _, "", _ -> lprintf out "case %d: %s_%s( _value ); _value = %s; break;\\\n" !idx (Filename.basename m1) h v
|
||||
| _, _, _ -> prerr_endline (sprintf "Error: You can't specify both module and header attributes for setting %s to use the handler %s" v h); exit 1
|
||||
end;
|
||||
with
|
||||
ExtXml.Error e -> lprintf out "case %d: %s = _value; break;\\\n" !idx v
|
||||
@@ -123,8 +126,12 @@ let print_dl_settings = fun out settings settings_xml ->
|
||||
right ();
|
||||
List.iter
|
||||
(fun s ->
|
||||
let t = ExtXml.attrib_or_default s "type" "" in
|
||||
let v = ExtXml.attrib s "var" in
|
||||
lprintf out "case %d: var = %s; break;\\\n" !idx v; incr idx)
|
||||
match t with
|
||||
| "fun" -> lprintf out "case %d: var = 0; break;\\\n" !idx; incr idx
|
||||
| _ -> lprintf out "case %d: var = %s; break;\\\n" !idx v; incr idx
|
||||
)
|
||||
settings_xml;
|
||||
lprintf out "default: var = 0.; break;\\\n";
|
||||
left ();
|
||||
@@ -143,8 +150,12 @@ let print_dl_settings = fun out settings settings_xml ->
|
||||
right ();
|
||||
List.iter
|
||||
(fun s ->
|
||||
let t = ExtXml.attrib_or_default s "type" "" in
|
||||
let v = ExtXml.attrib s "var" in
|
||||
lprintf out "case %d: return %s;\n" !idx v; incr idx)
|
||||
match t with
|
||||
| "fun" -> lprintf out "case %d: return 0;\n" !idx; incr idx
|
||||
| _ -> lprintf out "case %d: return %s;\n" !idx v; incr idx
|
||||
)
|
||||
settings_xml;
|
||||
lprintf out "default: return 0.;\n";
|
||||
left ();
|
||||
|
||||
Reference in New Issue
Block a user