Api Hal OS/Power: split insomnia and return to where it belongs. (#393)

This commit is contained in:
あく 2021-03-31 20:55:00 +03:00 committed by GitHub
parent 5439e232cc
commit 81ace53cc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 16 deletions

View File

@ -39,8 +39,11 @@ void api_hal_power_insomnia_enter();
*/ */
void api_hal_power_insomnia_exit(); void api_hal_power_insomnia_exit();
/** Check if sleep availble */
bool api_hal_power_sleep_available();
/** Check if deep sleep availble */ /** Check if deep sleep availble */
bool api_hal_power_deep_available(); bool api_hal_power_deep_sleep_available();
/** Go to sleep */ /** Go to sleep */
void api_hal_power_sleep(); void api_hal_power_sleep();

View File

@ -12,7 +12,16 @@
#include <bq27220.h> #include <bq27220.h>
#include <bq25896.h> #include <bq25896.h>
volatile uint32_t api_hal_power_insomnia = 1; typedef struct {
volatile uint32_t insomnia;
volatile uint32_t deep_insomnia;
} ApiHalPower;
static volatile ApiHalPower api_hal_power = {
.insomnia = 0,
.deep_insomnia = 1,
};
const ParamCEDV cedv = { const ParamCEDV cedv = {
.full_charge_cap = 2100, .full_charge_cap = 2100,
.design_cap = 2100, .design_cap = 2100,
@ -48,19 +57,23 @@ void api_hal_power_init() {
} }
uint16_t api_hal_power_insomnia_level() { uint16_t api_hal_power_insomnia_level() {
return api_hal_power_insomnia; return api_hal_power.insomnia;
} }
void api_hal_power_insomnia_enter() { void api_hal_power_insomnia_enter() {
api_hal_power_insomnia++; api_hal_power.insomnia++;
} }
void api_hal_power_insomnia_exit() { void api_hal_power_insomnia_exit() {
api_hal_power_insomnia--; api_hal_power.insomnia--;
} }
bool api_hal_power_deep_available() { bool api_hal_power_sleep_available() {
return api_hal_bt_is_alive() && api_hal_power_insomnia == 0; return api_hal_power.insomnia == 0;
}
bool api_hal_power_deep_sleep_available() {
return api_hal_bt_is_alive() && api_hal_power.deep_insomnia == 0;
} }
void api_hal_power_light_sleep() { void api_hal_power_light_sleep() {
@ -112,7 +125,7 @@ void api_hal_power_deep_sleep() {
} }
void api_hal_power_sleep() { void api_hal_power_sleep() {
if(api_hal_power_deep_available()) { if(api_hal_power_deep_sleep_available()) {
api_hal_power_deep_sleep(); api_hal_power_deep_sleep();
} else { } else {
api_hal_power_light_sleep(); api_hal_power_light_sleep();

View File

@ -99,6 +99,11 @@ static inline uint32_t api_hal_os_sleep(TickType_t expected_idle_ticks) {
} }
void vPortSuppressTicksAndSleep(TickType_t expected_idle_ticks) { void vPortSuppressTicksAndSleep(TickType_t expected_idle_ticks) {
if(!api_hal_power_sleep_available()) {
__WFI();
return;
}
// Limit mount of ticks to maximum that timer can count // Limit mount of ticks to maximum that timer can count
if (expected_idle_ticks > API_HAL_OS_MAX_SLEEP) { if (expected_idle_ticks > API_HAL_OS_MAX_SLEEP) {
expected_idle_ticks = API_HAL_OS_MAX_SLEEP; expected_idle_ticks = API_HAL_OS_MAX_SLEEP;

View File

@ -13,7 +13,16 @@
#include <bq27220.h> #include <bq27220.h>
#include <bq25896.h> #include <bq25896.h>
volatile uint32_t api_hal_power_insomnia = 1; typedef struct {
volatile uint32_t insomnia;
volatile uint32_t deep_insomnia;
} ApiHalPower;
static volatile ApiHalPower api_hal_power = {
.insomnia = 0,
.deep_insomnia = 1,
};
const ParamCEDV cedv = { const ParamCEDV cedv = {
.full_charge_cap = 2100, .full_charge_cap = 2100,
.design_cap = 2100, .design_cap = 2100,
@ -49,19 +58,23 @@ void api_hal_power_init() {
} }
uint16_t api_hal_power_insomnia_level() { uint16_t api_hal_power_insomnia_level() {
return api_hal_power_insomnia; return api_hal_power.insomnia;
} }
void api_hal_power_insomnia_enter() { void api_hal_power_insomnia_enter() {
api_hal_power_insomnia++; api_hal_power.insomnia++;
} }
void api_hal_power_insomnia_exit() { void api_hal_power_insomnia_exit() {
api_hal_power_insomnia--; api_hal_power.insomnia--;
} }
bool api_hal_power_deep_available() { bool api_hal_power_sleep_available() {
return api_hal_bt_is_alive() && api_hal_power_insomnia == 0; return api_hal_power.insomnia == 0;
}
bool api_hal_power_deep_sleep_available() {
return api_hal_bt_is_alive() && api_hal_power.deep_insomnia == 0;
} }
void api_hal_power_light_sleep() { void api_hal_power_light_sleep() {
@ -113,7 +126,7 @@ void api_hal_power_deep_sleep() {
} }
void api_hal_power_sleep() { void api_hal_power_sleep() {
if(api_hal_power_deep_available()) { if(api_hal_power_deep_sleep_available()) {
api_hal_power_deep_sleep(); api_hal_power_deep_sleep();
} else { } else {
api_hal_power_light_sleep(); api_hal_power_light_sleep();
@ -186,7 +199,7 @@ float api_hal_power_get_battery_temperature(ApiHalPowerIC ic) {
} }
float api_hal_power_get_usb_voltage(){ float api_hal_power_get_usb_voltage(){
return (float)bq25896_get_vbus_voltage() / 1000.0f;; return (float)bq25896_get_vbus_voltage() / 1000.0f;
} }
void api_hal_power_dump_state(string_t buffer) { void api_hal_power_dump_state(string_t buffer) {