kopia lustrzana https://github.com/SP8EBC/ParaTNC
some changes around and related to power saving
rodzic
0c367465de
commit
ae49c447fa
|
@ -24,9 +24,9 @@ C_SRCS += \
|
|||
../src/pwr_switch.c \
|
||||
../src/rte_main.c \
|
||||
../src/rte_pv.c \
|
||||
../src/rte_pwr.c \
|
||||
../src/rte_rtu.c \
|
||||
../src/rte_wx.c \
|
||||
../src/rtu_pwr.c \
|
||||
../src/wx_handler.c \
|
||||
../src/wx_handler_humidity.c \
|
||||
../src/wx_handler_pressure.c \
|
||||
|
@ -53,9 +53,9 @@ OBJS += \
|
|||
./src/pwr_switch.o \
|
||||
./src/rte_main.o \
|
||||
./src/rte_pv.o \
|
||||
./src/rte_pwr.o \
|
||||
./src/rte_rtu.o \
|
||||
./src/rte_wx.o \
|
||||
./src/rtu_pwr.o \
|
||||
./src/wx_handler.o \
|
||||
./src/wx_handler_humidity.o \
|
||||
./src/wx_handler_pressure.o \
|
||||
|
@ -82,9 +82,9 @@ C_DEPS += \
|
|||
./src/pwr_switch.d \
|
||||
./src/rte_main.d \
|
||||
./src/rte_pv.d \
|
||||
./src/rte_pwr.d \
|
||||
./src/rte_rtu.d \
|
||||
./src/rte_wx.d \
|
||||
./src/rtu_pwr.d \
|
||||
./src/wx_handler.d \
|
||||
./src/wx_handler_humidity.d \
|
||||
./src/wx_handler_pressure.d \
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="ilg.gnumcueclipse.debug.gdbjtag.openocd.launchConfigurationType">
|
||||
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.PERIPHERALS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <peripherals> <peripheral name="ADC1"/> </peripherals> "/>
|
||||
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.PERIPHERALS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <peripherals> <peripheral name="ADC1"/> <peripheral name="RCC"/> <peripheral name="RTC"/> </peripherals> "/>
|
||||
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doContinue" value="true"/>
|
||||
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doDebugInRam" value="false"/>
|
||||
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doFirstReset" value="true"/>
|
||||
|
|
|
@ -43,6 +43,24 @@ inline void io_12v_sw___cntrl_vbat_g_disable(void) {
|
|||
|
||||
}
|
||||
|
||||
inline uint8_t io_get_5v_isol_sw___cntrl_vbat_s(void) {
|
||||
if ((GPIOB->ODR & (1 << 8)) != 0) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline uint8_t io_get_12v_sw___cntrl_vbat_g(void) {
|
||||
if ((GPIOA->ODR & (1 << 6)) != 0) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline void io___cntrl_vbat_r_enable(void) {
|
||||
;
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
#include "config_data.h"
|
||||
|
||||
#define SW_VER "EA00"
|
||||
#define SW_DATE "31082021"
|
||||
#define SW_DATE "11092021"
|
||||
|
||||
#define SYSTICK_TICKS_PER_SECONDS 100
|
||||
#define SYSTICK_TICKS_PERIOD 10
|
||||
|
|
|
@ -98,22 +98,22 @@
|
|||
|
||||
#if defined(STM32L471xx)
|
||||
|
||||
void pwr_save_init(void);
|
||||
void pwr_save_init(config_data_powersave_mode_t mode);
|
||||
void pwr_save_enter_stop2(void);
|
||||
void pwr_save_exit_from_stop2(void);
|
||||
void pwr_save_switch_mode_to_c0(void);
|
||||
void pwr_save_switch_mode_to_c1(void);
|
||||
int pwr_save_switch_mode_to_c0(void);
|
||||
int pwr_save_switch_mode_to_c1(void);
|
||||
void pwr_save_switch_mode_to_c2(void);
|
||||
void pwr_save_switch_mode_to_c3(void);
|
||||
void pwr_save_switch_mode_to_m4(void);
|
||||
int pwr_save_switch_mode_to_m4(void);
|
||||
void pwr_save_switch_mode_to_i5(void);
|
||||
void pwr_save_switch_mode_to_l6(uint16_t sleep_time);
|
||||
void pwr_save_switch_mode_to_l7(uint16_t sleep_time);
|
||||
void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t * timers, int16_t minutes_to_wx); // this should be called from 10 seconds pooler
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
uint8_t pwr_save_get_inhibit_pwr_switch_periodic(void);
|
||||
|
||||
|
||||
#endif /* PWR_SAVE_H_ */
|
||||
|
|
|
@ -105,7 +105,7 @@ volatile const config_data_mode_t config_data_mode_default = {
|
|||
#endif
|
||||
|
||||
#if (defined _POWERSAVE_NORMAL)
|
||||
.powersave = PWSAVE_NONE,
|
||||
.powersave = PWSAVE_NORMAL,
|
||||
#elif (defined _POWERSAVE_AGGRESIVE)
|
||||
.powersave = PWSAVE_AGGRESV,
|
||||
#else
|
||||
|
|
|
@ -109,7 +109,7 @@ const config_data_mode_t __attribute__((section(".config_section_first.mode")))
|
|||
#endif
|
||||
|
||||
#if (defined _POWERSAVE_NORMAL)
|
||||
.powersave = PWSAVE_NONE,
|
||||
.powersave = PWSAVE_NORMAL,
|
||||
#elif (defined _POWERSAVE_AGGRESIVE)
|
||||
.powersave = PWSAVE_AGGRESV,
|
||||
#else
|
||||
|
|
|
@ -103,7 +103,7 @@ const config_data_mode_t __attribute__((section(".config_section_second.mode")))
|
|||
#endif
|
||||
|
||||
#if (defined _POWERSAVE_NORMAL)
|
||||
.powersave = PWSAVE_NONE,
|
||||
.powersave = PWSAVE_NORMAL,
|
||||
#elif (defined _POWERSAVE_AGGRESIVE)
|
||||
.powersave = PWSAVE_AGGRESV,
|
||||
#else
|
||||
|
|
|
@ -278,8 +278,6 @@ int main(int argc, char* argv[]){
|
|||
|
||||
system_clock_configure_rtc_l4();
|
||||
|
||||
system_clock_configure_auto_wakeup_l4(300);
|
||||
|
||||
RCC->APB1ENR1 |= (RCC_APB1ENR1_TIM2EN | RCC_APB1ENR1_TIM3EN | RCC_APB1ENR1_TIM4EN | RCC_APB1ENR1_TIM7EN | RCC_APB1ENR1_USART2EN | RCC_APB1ENR1_USART3EN | RCC_APB1ENR1_DAC1EN | RCC_APB1ENR1_I2C1EN);
|
||||
RCC->APB2ENR |= (RCC_APB2ENR_TIM1EN | RCC_APB2ENR_USART1EN);
|
||||
RCC->AHB1ENR |= (RCC_AHB1ENR_CRCEN | RCC_AHB1ENR_DMA1EN);
|
||||
|
@ -443,7 +441,7 @@ int main(int argc, char* argv[]){
|
|||
|
||||
#if defined(STM32L471xx)
|
||||
// initialize all powersaving functions
|
||||
pwr_save_init();
|
||||
pwr_save_init(main_config_data_mode->powersave);
|
||||
#endif
|
||||
|
||||
// initalizing separated Open Collector output
|
||||
|
@ -832,7 +830,6 @@ int main(int argc, char* argv[]){
|
|||
io_ext_watchdog_service();
|
||||
|
||||
#if defined(PARAMETEO)
|
||||
// test
|
||||
pwr_save_switch_mode_to_c0();
|
||||
#endif
|
||||
|
||||
|
|
176
src/pwr_save.c
176
src/pwr_save.c
|
@ -14,8 +14,15 @@
|
|||
#include "pwr_switch.h"
|
||||
#include "io.h"
|
||||
#include "packet_tx_handler.h"
|
||||
#include "wx_handler.h"
|
||||
#include "main.h"
|
||||
|
||||
#include "drivers/analog_anemometer.h"
|
||||
|
||||
|
||||
#define REGISTER RTC->BKP0R
|
||||
|
||||
#define INHIBIT_PWR_SWITCH_PERIODIC_H 1
|
||||
#define IN_STOP2_MODE (1 << 1)
|
||||
#define IN_C0_STATE (1 << 2)
|
||||
#define IN_C1_STATE (1 << 3)
|
||||
|
@ -28,18 +35,25 @@
|
|||
|
||||
#define ALL_STATES_BITMASK (0xFF << 2)
|
||||
|
||||
#define REGISTER RTC->BKP0R
|
||||
|
||||
#if defined(STM32L471xx)
|
||||
|
||||
int8_t pwr_save_seconds_to_wx = 0;
|
||||
int16_t pwr_save_sleep_time_in_seconds = -1;
|
||||
|
||||
static void pwr_save_unclock_rtc_backup_regs(void) {
|
||||
// enable access to backup domain
|
||||
PWR->CR1 |= PWR_CR1_DBP;
|
||||
}
|
||||
|
||||
static void pwr_save_lock_rtc_backup_regs(void) {
|
||||
PWR->CR1 &= (0xFFFFFFFF ^ PWR_CR1_DBP);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function initializes everything related to power saving features
|
||||
* including programming Flash memory option bytes
|
||||
*/
|
||||
void pwr_save_init(void) {
|
||||
void pwr_save_init(config_data_powersave_mode_t mode) {
|
||||
|
||||
// make a pointer to option byte
|
||||
uint32_t* option_byte = (uint32_t*)0x1FFF7800;
|
||||
|
@ -82,6 +96,23 @@ void pwr_save_init(void) {
|
|||
|
||||
}
|
||||
|
||||
pwr_save_unclock_rtc_backup_regs();
|
||||
|
||||
// reset a status register
|
||||
REGISTER = 0;
|
||||
|
||||
// switch power switch handler inhibition if it is needed
|
||||
switch (mode) {
|
||||
case PWSAVE_NONE:
|
||||
break;
|
||||
case PWSAVE_NORMAL:
|
||||
case PWSAVE_AGGRESV:
|
||||
REGISTER |= INHIBIT_PWR_SWITCH_PERIODIC_H;
|
||||
break;
|
||||
}
|
||||
|
||||
pwr_save_lock_rtc_backup_regs();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,9 +131,13 @@ void pwr_save_enter_stop2(void) {
|
|||
RTC->WPR = 0xCA;
|
||||
RTC->WPR = 0x53;
|
||||
|
||||
pwr_save_unclock_rtc_backup_regs();
|
||||
|
||||
// save an information that STOP2 mode has been applied
|
||||
RTC->BKP0R |= IN_STOP2_MODE;
|
||||
|
||||
pwr_save_lock_rtc_backup_regs();
|
||||
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
DBGMCU->CR &= (0xFFFFFFFF ^ (DBGMCU_CR_DBG_SLEEP_Msk | DBGMCU_CR_DBG_STOP_Msk | DBGMCU_CR_DBG_STANDBY_Msk));
|
||||
|
@ -158,10 +193,10 @@ void pwr_save_exit_from_stop2(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void pwr_save_switch_mode_to_c0(void) {
|
||||
int pwr_save_switch_mode_to_c0(void) {
|
||||
|
||||
if ((REGISTER & ALL_STATES_BITMASK) == IN_C0_STATE) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// turn ON +5V_S (and internal VHF radio module in HW-RevB)
|
||||
|
@ -173,19 +208,27 @@ void pwr_save_switch_mode_to_c0(void) {
|
|||
// turn ON +4V_G
|
||||
io_12v_sw___cntrl_vbat_g_enable();
|
||||
|
||||
// unlock access to backup registers
|
||||
pwr_save_unclock_rtc_backup_regs();
|
||||
|
||||
// clear all previous powersave indication bits
|
||||
REGISTER &= 0xFFFFFFFF ^ ALL_STATES_BITMASK;
|
||||
|
||||
// set for C0 mode
|
||||
REGISTER |= IN_C0_STATE;
|
||||
|
||||
// lock access to backup
|
||||
pwr_save_lock_rtc_backup_regs();
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
// in HW-RevB this will disable external VHF radio!!
|
||||
void pwr_save_switch_mode_to_c1(void) {
|
||||
int pwr_save_switch_mode_to_c1(void) {
|
||||
|
||||
if ((REGISTER & ALL_STATES_BITMASK) == IN_C1_STATE) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// turn ON +5V_S (and internal VHF radio module in HW-RevB)
|
||||
|
@ -197,11 +240,19 @@ void pwr_save_switch_mode_to_c1(void) {
|
|||
// turn OFF +4V_G
|
||||
io_12v_sw___cntrl_vbat_g_disable();
|
||||
|
||||
// unlock access to backup registers
|
||||
pwr_save_unclock_rtc_backup_regs();
|
||||
|
||||
// clear all previous powersave indication bits
|
||||
REGISTER &= (0xFFFFFFFF ^ ALL_STATES_BITMASK);
|
||||
|
||||
// set for C0 mode
|
||||
REGISTER |= IN_C1_STATE;
|
||||
|
||||
// lock access to backup
|
||||
pwr_save_lock_rtc_backup_regs();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// this mode is not avaliable in HW Revision B as internal radio
|
||||
|
@ -222,11 +273,18 @@ void pwr_save_switch_mode_to_c2(void) {
|
|||
// turn OFF +4V_G
|
||||
io_12v_sw___cntrl_vbat_g_disable();
|
||||
|
||||
// unlock access to backup registers
|
||||
pwr_save_unclock_rtc_backup_regs();
|
||||
|
||||
// clear all previous powersave indication bits
|
||||
REGISTER &= (0xFFFFFFFF ^ ALL_STATES_BITMASK);
|
||||
|
||||
// set for C2 mode
|
||||
REGISTER |= IN_C2_STATE;
|
||||
|
||||
// lock access to backup
|
||||
pwr_save_lock_rtc_backup_regs();
|
||||
|
||||
}
|
||||
|
||||
void pwr_save_switch_mode_to_c3(void) {
|
||||
|
@ -244,18 +302,25 @@ void pwr_save_switch_mode_to_c3(void) {
|
|||
// turn ON +4V_G
|
||||
io_12v_sw___cntrl_vbat_g_enable();
|
||||
|
||||
// unlock access to backup registers
|
||||
pwr_save_unclock_rtc_backup_regs();
|
||||
|
||||
// clear all previous powersave indication bits
|
||||
REGISTER &= (0xFFFFFFFF ^ ALL_STATES_BITMASK);
|
||||
|
||||
// set for C3 mode
|
||||
REGISTER |= IN_C3_STATE;
|
||||
|
||||
// lock access to backup
|
||||
pwr_save_lock_rtc_backup_regs();
|
||||
|
||||
}
|
||||
|
||||
// in HW-RevB this will keep internal VHF radio module working!
|
||||
void pwr_save_switch_mode_to_m4(void) {
|
||||
int pwr_save_switch_mode_to_m4(void) {
|
||||
|
||||
if ((REGISTER & ALL_STATES_BITMASK) == IN_M4_STATE) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// turn ON +5V_S (and internal VHF radio module in HW-RevB)
|
||||
|
@ -267,11 +332,19 @@ void pwr_save_switch_mode_to_m4(void) {
|
|||
// turn OFF +4V_G
|
||||
io_12v_sw___cntrl_vbat_g_disable();
|
||||
|
||||
// unlock access to backup registers
|
||||
pwr_save_unclock_rtc_backup_regs();
|
||||
|
||||
// clear all previous powersave indication bits
|
||||
REGISTER &= (0xFFFFFFFF ^ ALL_STATES_BITMASK);
|
||||
|
||||
// set for C3 mode
|
||||
REGISTER |= IN_M4_STATE;
|
||||
|
||||
// lock access to backup
|
||||
pwr_save_lock_rtc_backup_regs();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void pwr_save_switch_mode_to_i5(void) {
|
||||
|
@ -289,12 +362,18 @@ void pwr_save_switch_mode_to_i5(void) {
|
|||
// turn OFF +4V_G
|
||||
io_12v_sw___cntrl_vbat_g_disable();
|
||||
|
||||
// unlock access to backup registers
|
||||
pwr_save_unclock_rtc_backup_regs();
|
||||
|
||||
// clear all previous powersave indication bits
|
||||
REGISTER &= (0xFFFFFFFF ^ ALL_STATES_BITMASK);
|
||||
|
||||
// set for C3 mode
|
||||
REGISTER |= IN_I5_STATE;
|
||||
|
||||
// lock access to backup
|
||||
pwr_save_lock_rtc_backup_regs();
|
||||
|
||||
}
|
||||
|
||||
// this will keep external VHF radio working in HW-RevB
|
||||
|
@ -313,16 +392,23 @@ void pwr_save_switch_mode_to_l6(uint16_t sleep_time) {
|
|||
// turn ON +4V_G
|
||||
io_12v_sw___cntrl_vbat_g_enable();
|
||||
|
||||
// unlock access to backup registers
|
||||
pwr_save_unclock_rtc_backup_regs();
|
||||
|
||||
// clear all previous powersave indication bits
|
||||
REGISTER &= (0xFFFFFFFF ^ ALL_STATES_BITMASK);
|
||||
|
||||
// set for C3 mode
|
||||
REGISTER |= IN_L6_STATE;
|
||||
|
||||
// lock access to backup
|
||||
pwr_save_lock_rtc_backup_regs();
|
||||
|
||||
system_clock_configure_auto_wakeup_l4(sleep_time);
|
||||
|
||||
pwr_save_enter_stop2();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void pwr_save_switch_mode_to_l7(uint16_t sleep_time) {
|
||||
|
@ -340,12 +426,18 @@ void pwr_save_switch_mode_to_l7(uint16_t sleep_time) {
|
|||
// turn OFF +4V_G
|
||||
io_12v_sw___cntrl_vbat_g_disable();
|
||||
|
||||
// unlock access to backup registers
|
||||
pwr_save_unclock_rtc_backup_regs();
|
||||
|
||||
// clear all previous powersave indication bits
|
||||
REGISTER &= (0xFFFFFFFF ^ ALL_STATES_BITMASK);
|
||||
|
||||
// set for C3 mode
|
||||
REGISTER |= IN_L7_STATE;
|
||||
|
||||
// lock access to backup
|
||||
pwr_save_lock_rtc_backup_regs();
|
||||
|
||||
// configure how long micro should sleep
|
||||
system_clock_configure_auto_wakeup_l4(sleep_time);
|
||||
|
||||
|
@ -358,6 +450,7 @@ void pwr_save_switch_mode_to_l7(uint16_t sleep_time) {
|
|||
void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t * timers, int16_t minutes_to_wx) {
|
||||
// this function should be called from 10 seconds pooler
|
||||
|
||||
int reinit_sensors = 0;
|
||||
|
||||
packet_tx_counter_values_t counters;
|
||||
|
||||
|
@ -396,16 +489,16 @@ void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t *
|
|||
|
||||
// if digipeater is enabled
|
||||
if (config->digi == 1) { // DIGI + WX + GSM
|
||||
pwr_save_switch_mode_to_c0();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c0();
|
||||
}
|
||||
else { // WX + GSM
|
||||
pwr_save_switch_mode_to_c0();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c0();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if digipeater is enabled
|
||||
if (config->digi == 1) { // DIGI + WX
|
||||
pwr_save_switch_mode_to_c1();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c1();
|
||||
}
|
||||
else { // WX
|
||||
if (minutes_to_wx > 1) {
|
||||
|
@ -414,7 +507,7 @@ void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t *
|
|||
}
|
||||
else {
|
||||
if (pwr_save_seconds_to_wx <= 30) {
|
||||
pwr_save_switch_mode_to_c1();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c1();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -447,7 +540,7 @@ void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t *
|
|||
pwr_save_switch_mode_to_c2();
|
||||
}
|
||||
else {
|
||||
pwr_save_switch_mode_to_c0();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c0();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -455,16 +548,16 @@ void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t *
|
|||
pwr_save_switch_mode_to_c3();
|
||||
}
|
||||
else {
|
||||
pwr_save_switch_mode_to_c0();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c0();
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // WX + GSM
|
||||
if (minutes_to_wx > 1) {
|
||||
pwr_save_switch_mode_to_m4();
|
||||
reinit_sensors = pwr_save_switch_mode_to_m4();
|
||||
}
|
||||
else {
|
||||
pwr_save_switch_mode_to_c0();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c0();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -475,17 +568,17 @@ void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t *
|
|||
pwr_save_switch_mode_to_c2();
|
||||
}
|
||||
else {
|
||||
pwr_save_switch_mode_to_c1();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c1();
|
||||
}
|
||||
}
|
||||
else { // WX
|
||||
if (minutes_to_wx > 1) {
|
||||
// if there is more than one minute to send wx packet
|
||||
pwr_save_switch_mode_to_m4();
|
||||
reinit_sensors = pwr_save_switch_mode_to_m4();
|
||||
}
|
||||
else {
|
||||
if (pwr_save_seconds_to_wx <= 30) {
|
||||
pwr_save_switch_mode_to_c1();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c1();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -513,7 +606,7 @@ void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t *
|
|||
pwr_save_switch_mode_to_c2();
|
||||
}
|
||||
else {
|
||||
pwr_save_switch_mode_to_c0();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c0();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -528,11 +621,11 @@ void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t *
|
|||
else {
|
||||
if (pwr_save_seconds_to_wx <= 30) {
|
||||
// if there is 30 seconds or less to next wx packet
|
||||
pwr_save_switch_mode_to_c0();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c0();
|
||||
}
|
||||
else {
|
||||
// if there is 30 to 60 seconds to next wx packet
|
||||
pwr_save_switch_mode_to_m4();
|
||||
reinit_sensors = pwr_save_switch_mode_to_m4();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -543,7 +636,7 @@ void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t *
|
|||
pwr_save_switch_mode_to_l6((timers->wx_transmit_period * 60) - 60); // TODO: !!!
|
||||
}
|
||||
else {
|
||||
pwr_save_switch_mode_to_c0();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c0();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -555,17 +648,17 @@ void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t *
|
|||
pwr_save_switch_mode_to_c2();
|
||||
}
|
||||
else {
|
||||
pwr_save_switch_mode_to_c1();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c1();
|
||||
}
|
||||
}
|
||||
else { // WX
|
||||
if (minutes_to_wx > 1) {
|
||||
// if there is more than one minute to send wx packet
|
||||
pwr_save_switch_mode_to_m4();
|
||||
reinit_sensors= pwr_save_switch_mode_to_m4();
|
||||
}
|
||||
else {
|
||||
if (pwr_save_seconds_to_wx <= 30) {
|
||||
pwr_save_switch_mode_to_c1();
|
||||
reinit_sensors = pwr_save_switch_mode_to_c1();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -578,7 +671,36 @@ void pwr_save_pooling_handler(config_data_mode_t * config, config_data_basic_t *
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (reinit_sensors != 0) {
|
||||
// reinitialize all i2c sensors
|
||||
wx_force_i2c_sensor_reset = 1;
|
||||
|
||||
// reset anemometer direction handler
|
||||
analog_anemometer_direction_reset();
|
||||
|
||||
// reset anemometer windspeed handler
|
||||
analog_anemometer_timer_irq();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint8_t pwr_save_get_inhibit_pwr_switch_periodic(void) {
|
||||
|
||||
if ((REGISTER & INHIBIT_PWR_SWITCH_PERIODIC_H) != 0){
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
uint8_t pwr_save_get_inhibit_pwr_switch_periodic(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "rte_wx.h"
|
||||
#include "wx_handler.h"
|
||||
#include "io.h"
|
||||
#include "pwr_save.h"
|
||||
|
||||
|
||||
#ifdef STM32F10X_MD_VL
|
||||
|
@ -25,10 +26,16 @@
|
|||
|
||||
wx_pwr_state_t wx_pwr_state;
|
||||
|
||||
#define REGISTER RTC->BKP0R
|
||||
|
||||
#define WX_WATCHDOG_PERIOD (SYSTICK_TICKS_PER_SECONDS * SYSTICK_TICKS_PERIOD * 90)
|
||||
#define WX_WATCHDOG_RESET_DURATION (SYSTICK_TICKS_PER_SECONDS * SYSTICK_TICKS_PERIOD * 3)
|
||||
|
||||
void wx_pwr_switch_case_under_reset_parameteo() {
|
||||
|
||||
if (pwr_save_get_inhibit_pwr_switch_periodic() == 1)
|
||||
return;
|
||||
|
||||
io_5v_isol_sw___cntrl_vbat_s_enable();
|
||||
|
||||
wx_force_i2c_sensor_reset = 1;
|
||||
|
@ -53,6 +60,9 @@ void wx_pwr_switch_case_under_reset_paratnc() {
|
|||
|
||||
void wx_pwr_switch_case_off_parameteo() {
|
||||
|
||||
if (pwr_save_get_inhibit_pwr_switch_periodic() == 1)
|
||||
return;
|
||||
|
||||
// Turn on the +5V_ISOL (VDD_SW) voltage
|
||||
io_5v_isol_sw___cntrl_vbat_s_enable();
|
||||
|
||||
|
|
|
@ -65,15 +65,16 @@ void wx_check_force_i2c_reset(void) {
|
|||
if (wx_force_i2c_sensor_reset == 1) {
|
||||
wx_force_i2c_sensor_reset = 0;
|
||||
|
||||
#if defined (_SENSOR_BME280)
|
||||
if (main_config_data_mode->wx_ms5611_or_bme == 0) {
|
||||
ms5611_reset(&rte_wx_ms5611_qf);
|
||||
ms5611_read_calibration(SensorCalData, &rte_wx_ms5611_qf);
|
||||
ms5611_trigger_measure(0, 0);
|
||||
}
|
||||
else if (main_config_data_mode->wx_ms5611_or_bme == 1) {
|
||||
bme280_reset(&rte_wx_bme280_qf);
|
||||
bme280_setup();
|
||||
#endif
|
||||
|
||||
#if defined (_SENSOR_MS5611)
|
||||
ms5611_reset(&rte_wx_ms5611_qf);
|
||||
ms5611_trigger_measure(0, 0);
|
||||
#endif
|
||||
bme280_read_calibration(bme280_calibration_data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,6 +84,11 @@ void wx_get_all_measurements(const config_data_wx_sources_t * const config_sourc
|
|||
int32_t parameter_result = 0; // stores which parameters have been retrieved successfully. this is used for failsafe handling
|
||||
int32_t backup_parameter_result = 0; // uses during retrieving backup
|
||||
|
||||
if (io_get_5v_isol_sw___cntrl_vbat_s() == 0) {
|
||||
// inhibit any measurement when power is not applied to sensors
|
||||
return;
|
||||
}
|
||||
|
||||
parameter_result |= wx_get_temperature_measurement(config_sources, config_mode, config_umb, config_rtu);
|
||||
parameter_result |= wx_get_pressure_measurement(config_sources, config_mode, config_umb, config_rtu);
|
||||
parameter_result |= wx_get_humidity_measurement(config_sources, config_mode, config_umb, config_rtu);
|
||||
|
@ -170,11 +176,15 @@ void wx_pool_anemometer(const config_data_wx_sources_t * const config_sources, c
|
|||
uint8_t average_ln;
|
||||
|
||||
int32_t modbus_retval;
|
||||
uint16_t scaled_windspeed = 0;
|
||||
|
||||
if (io_get_5v_isol_sw___cntrl_vbat_s() == 0) {
|
||||
// inhibit any measurement when power is not applied to sensors
|
||||
return;
|
||||
}
|
||||
|
||||
wx_wind_pool_call_counter++;
|
||||
|
||||
uint16_t scaled_windspeed = 0;
|
||||
|
||||
// internal sensors
|
||||
if (config_sources->wind == WX_SOURCE_INTERNAL) {
|
||||
// this windspeed is scaled * 10. Example: 0.2 meters per second is stored as 2
|
||||
|
|
|
@ -24,7 +24,7 @@ typedef enum analog_wind_qf {
|
|||
#define DIRECTION_REGULAR 1
|
||||
#define DIRECTION_SPARKFUN 2
|
||||
|
||||
#if defined(_ANEMOMETER_ANALOGUE) || defined(_ANEMOMETER_ANALOGUE_SPARKFUN)
|
||||
//#if defined(_ANEMOMETER_ANALOGUE) || defined(_ANEMOMETER_ANALOGUE_SPARKFUN)
|
||||
|
||||
extern uint16_t analog_anemometer_windspeed_pulses_time[ANALOG_ANEMOMETER_SPEED_PULSES_N];
|
||||
extern uint16_t analog_anemometer_time_between_pulses[ANALOG_ANEMOMETER_SPEED_PULSES_N];
|
||||
|
@ -46,6 +46,6 @@ int16_t analog_anemometer_direction_sparkfun(uint32_t timer_value);
|
|||
void analog_anemometer_direction_reset(void);
|
||||
analog_wind_qf_t analog_anemometer_get_qf(void);
|
||||
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
#endif /* INCLUDE_DRIVERS_ANALOG_ANEMOMETER_H_ */
|
||||
|
|
|
@ -365,6 +365,10 @@ int system_clock_configure_l4(void)
|
|||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
|
||||
// select MSI as system clock cource
|
||||
// RCC_CFGR_SW_MSI
|
||||
RCC->CFGR &= (0xFFFFFFFF ^ RCC_CFGR_SW_Msk);
|
||||
|
||||
// turn on high speed external quartz oscilator
|
||||
RCC->CR |= RCC_CR_HSEON;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "main.h"
|
||||
#include "wx_handler.h"
|
||||
#include "LedConfig.h"
|
||||
#include "io.h"
|
||||
|
||||
#ifdef STM32F10X_MD_VL
|
||||
#include <stm32f10x_tim.h>
|
||||
|
@ -523,6 +524,10 @@ int16_t analog_anemometer_direction_handler(void) {
|
|||
|
||||
uint16_t downscaled_angle = 0;
|
||||
|
||||
if (io_get_5v_isol_sw___cntrl_vbat_s() == 0) {
|
||||
return rte_wx_winddirection_last;
|
||||
}
|
||||
|
||||
|
||||
#ifdef STM32F10X_MD_VL
|
||||
TIM_Cmd(TIM3, DISABLE);
|
||||
|
|
Ładowanie…
Reference in New Issue