Init
This commit is contained in:
commit
487aef3651
|
|
@ -0,0 +1,199 @@
|
||||||
|
//
|
||||||
|
// Created by xemon on 29.08.22.
|
||||||
|
//
|
||||||
|
#include <CmsisRtosThreadUtils.h>
|
||||||
|
#include <LoggerInterface.h>
|
||||||
|
#include "PowerManagement.h"
|
||||||
|
#include "SystemDelayInterface.h"
|
||||||
|
#include "Gpios.h"
|
||||||
|
|
||||||
|
#define LOG_SIGN "Питание"
|
||||||
|
#define LOGGER env->logger
|
||||||
|
|
||||||
|
void Pwm_StandbyOn(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_StandbyOff(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_Rs485Enable(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_GsmAndGnssStartup(tPowerManagement *env) {
|
||||||
|
PwmLe910_StartUp(&env->pins->telit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_BipShutdown(tPowerManagement *env) {
|
||||||
|
GpioPinDisable(&env->pins->bip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_GsmAndBipStartUp(tPowerManagement *env) {
|
||||||
|
GpioPinDisable(&env->pins->bip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_GsmAndGnssShutdown(tPowerManagement *env) {
|
||||||
|
#ifdef USE_GSM_AND_GNSS_TELIT
|
||||||
|
PwmLe910_ShutDown(&env->pins->telit);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_GSM_AND_GNSS_SIMCOM
|
||||||
|
PwmSim68_Startup(&env->pins->sim68);
|
||||||
|
PwmSim7600e_Startup(&env->pins->sim7600);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_Init(
|
||||||
|
tPowerManagement *env,
|
||||||
|
tPowerPins *pins,
|
||||||
|
tAdcIO *batteryMeasure,
|
||||||
|
bool *positiveMute
|
||||||
|
) {
|
||||||
|
env->pins = pins;
|
||||||
|
env->shutdownDelay = 15000;
|
||||||
|
env->batteryMeasure = batteryMeasure;
|
||||||
|
env->positiveMute = positiveMute;
|
||||||
|
env->logger = NULL;
|
||||||
|
|
||||||
|
//Инициализируем поток
|
||||||
|
InitThreadAtrStatic(&env->thread.attr, "Pwm", env->thread.controlBlock, env->thread.stack, osPriorityNormal);
|
||||||
|
env->thread.id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_BatteryOn(tPowerManagement *env) {
|
||||||
|
GpioPinEnable(&env->pins->battery.enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Pwm_BatteryOff(tPowerManagement *env) {
|
||||||
|
GpioPinDisable(&env->pins->battery.enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_OnDeviceInit(tPowerManagement *env) {
|
||||||
|
Pwm_StandbyOn(env);
|
||||||
|
Pwm_BatteryOn(env);
|
||||||
|
Pwm_Rs485Enable(env);
|
||||||
|
Pwm_GsmAndGnssStartup(env);
|
||||||
|
|
||||||
|
Pwm_SetMute(env, false);
|
||||||
|
GpioPinDisable(&env->pins->main.garage);
|
||||||
|
GpioPinDisable(&env->pins->main.ecall);
|
||||||
|
env->currentPwrSaveState = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_Blackout(tPowerManagement *env) {
|
||||||
|
Pwm_ChargeDisable(env);
|
||||||
|
Pwm_BatteryOff(env);
|
||||||
|
Pwm_StandbyOff(env);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Pwm_StandbyOn(tPowerManagement *env) {
|
||||||
|
GpioPinEnable(&env->pins->main.standby);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_StandbyOff(tPowerManagement *env) {
|
||||||
|
GpioPinDisable(&env->pins->main.standby);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_Rs485Enable(tPowerManagement *env) {
|
||||||
|
GpioPinEnable(&env->pins->comInt485);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_Rs485Disable(tPowerManagement *env) {
|
||||||
|
GpioPinDisable(&env->pins->comInt485);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_PowerSavingEnable(tPowerManagement *env) {
|
||||||
|
env->currentPwrSaveState = true;
|
||||||
|
Pwm_AudioDisable(env);
|
||||||
|
SystemDelayMs(500);
|
||||||
|
Pwm_GsmAndGnssShutdown(env);
|
||||||
|
SystemDelayMs(500);
|
||||||
|
Pwm_ChargeDisable(env);
|
||||||
|
SystemDelayMs(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_PowerSavingDisable(tPowerManagement *env) {
|
||||||
|
env->currentPwrSaveState = false;
|
||||||
|
Pwm_GsmAndGnssStartup(env);
|
||||||
|
Pwm_GsmAndBipStartUp(env);
|
||||||
|
Pwm_ChargeEnable(env);
|
||||||
|
Pwm_AudioEnable(env);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_AudioEnable(tPowerManagement *env) {
|
||||||
|
tAudioPower *audio = &env->pins->audio;
|
||||||
|
GpioPinEnable(&audio->shutdownB);
|
||||||
|
GpioPinEnable(&audio->shutdownD);
|
||||||
|
GpioPinEnable(&audio->mic);
|
||||||
|
GpioPinEnable(&audio->gain);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_AudioDisable(tPowerManagement *env) {
|
||||||
|
tAudioPower *audio = &env->pins->audio;
|
||||||
|
GpioPinDisable(&audio->shutdownB);
|
||||||
|
GpioPinDisable(&audio->shutdownD);
|
||||||
|
// GpioPinDisable(&audio->mic);
|
||||||
|
GpioPinDisable(&audio->gain);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_SetMute(tPowerManagement *env, bool value) {
|
||||||
|
if (*env->positiveMute) {
|
||||||
|
if (value) {
|
||||||
|
GpioPinDisable(&env->pins->main.muteN);
|
||||||
|
GpioPinEnable(&env->pins->main.muteP);
|
||||||
|
} else {
|
||||||
|
GpioPinDisable(&env->pins->main.muteP);
|
||||||
|
GpioPinEnable(&env->pins->main.muteN);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GpioPinDisable(&env->pins->main.muteP);
|
||||||
|
if (value) {
|
||||||
|
GpioPinEnable(&env->pins->main.muteN);
|
||||||
|
} else {
|
||||||
|
GpioPinDisable(&env->pins->main.muteN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_ChargeEnable(tPowerManagement *env) {
|
||||||
|
env->currentChargeState = true;
|
||||||
|
GpioPinEnable(&env->pins->battery.charge);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pwm_ChargeDisable(tPowerManagement *env) {
|
||||||
|
env->currentChargeState = false;
|
||||||
|
GpioPinDisable(&env->pins->battery.charge);
|
||||||
|
}
|
||||||
|
|
||||||
|
static _Noreturn void Pwm_Thread(tPowerManagement *env) {
|
||||||
|
Pwm_ChargeEnable(env);
|
||||||
|
bool ignition;
|
||||||
|
for (;;) {
|
||||||
|
ignition = GpioPinGet(&env->pins->main.ignition);
|
||||||
|
|
||||||
|
if (ignition) {
|
||||||
|
env->lastIgnEnabled = SystemGetMs();
|
||||||
|
}
|
||||||
|
|
||||||
|
env->currentBatVoltage = AdcGet(env->batteryMeasure, 50);
|
||||||
|
|
||||||
|
SystemDelayMs(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerManagement_StartThread(tPowerManagement *env) {
|
||||||
|
if (!env->thread.id) {
|
||||||
|
env->thread.id = osThreadNew((osThreadFunc_t) (Pwm_Thread), (void *) (env), &env->thread.attr);
|
||||||
|
} else {
|
||||||
|
osThreadResume(env->thread.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Pwm_IsShutdownRequired(tPowerManagement *env) {
|
||||||
|
uint32_t thisTime = SystemGetMs();
|
||||||
|
uint32_t time = env->lastIgnEnabled + env->shutdownDelay;
|
||||||
|
|
||||||
|
if(time < thisTime){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,138 @@
|
||||||
|
//
|
||||||
|
// Created by xemon on 29.08.22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef UVEOS_DEMO_ON_NIIET_MCU_POWERMANAGEMENT_H
|
||||||
|
#define UVEOS_DEMO_ON_NIIET_MCU_POWERMANAGEMENT_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <SerialPorts.h>
|
||||||
|
#include "GpioPin.h"
|
||||||
|
#include "UserInput.h"
|
||||||
|
#include "UserIndication.h"
|
||||||
|
#include "SpiPorts.h"
|
||||||
|
#include "Adc.h"
|
||||||
|
#include "LoggerInterface.h"
|
||||||
|
|
||||||
|
#ifdef USE_GSM_AND_GNSS_TELIT
|
||||||
|
|
||||||
|
#include "PwmLe910.h"
|
||||||
|
//#include "Gpios.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_GSM_AND_GNSS_SIMCOM
|
||||||
|
#include "PwmSim68m.h"
|
||||||
|
#include "PwmSim7600e.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if USE_POLAR_DEPENDENT_BIP
|
||||||
|
typedef struct {
|
||||||
|
tGpioPin ignitionOn;
|
||||||
|
tGpioPin bacLightOn;
|
||||||
|
} tPowerBip;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tGpioPin shutdownB;
|
||||||
|
tGpioPin shutdownD;
|
||||||
|
tGpioPin gain;
|
||||||
|
tGpioPin mic;
|
||||||
|
} tAudioPower;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tGpioPin ignition;
|
||||||
|
tGpioPin standby;
|
||||||
|
tGpioPin garage;
|
||||||
|
tGpioPin ecall;
|
||||||
|
tGpioPin muteP;
|
||||||
|
tGpioPin muteN;
|
||||||
|
tGpioPin inAnt;
|
||||||
|
|
||||||
|
} tMainPower;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tGpioPin enable;
|
||||||
|
tGpioPin charge;
|
||||||
|
} tBatteryPower;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tGpioPin bip;
|
||||||
|
tGpioPin comInt485;
|
||||||
|
tGpioPin usb;
|
||||||
|
tAudioPower audio;
|
||||||
|
tBatteryPower battery;
|
||||||
|
tMainPower main;
|
||||||
|
|
||||||
|
#ifdef USE_GSM_AND_GNSS_TELIT
|
||||||
|
tTelitPower telit;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
} tPowerPins;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tLoggerInterface *logger;
|
||||||
|
tPowerPins *pins;
|
||||||
|
bool *positiveMute;
|
||||||
|
tAdcIO *batteryMeasure;
|
||||||
|
uint32_t shutdownDelay;
|
||||||
|
|
||||||
|
uint32_t lastIgnEnabled;
|
||||||
|
int32_t currentBatVoltage;
|
||||||
|
bool currentChargeState;
|
||||||
|
bool currentPwrSaveState;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
osThreadId_t id;
|
||||||
|
uint32_t stack[256];
|
||||||
|
StaticTask_t controlBlock;
|
||||||
|
osThreadAttr_t attr;
|
||||||
|
} thread;
|
||||||
|
|
||||||
|
} tPowerManagement;
|
||||||
|
|
||||||
|
void Pwm_Init(tPowerManagement *env, tPowerPins *pins, tAdcIO *batteryMeasure, bool *positiveMute);
|
||||||
|
|
||||||
|
void PowerManagement_StartThread(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_OnDeviceInit(tPowerManagement *env);
|
||||||
|
|
||||||
|
bool Pwm_IsShutdownRequired(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_Blackout(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_AudioEnable(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_AudioDisable(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_LedtUp(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_LedBoardDown(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_ChargeDisable(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_ChargeEnable(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_PowerSavingEnable(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_PowerSavingDisable(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_SetMute(tPowerManagement *env, bool value);
|
||||||
|
|
||||||
|
void Pwm_GsmAndGnssShutdown(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_BipShutdown(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_GsmAndBipStartUp(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_GsmAndGnssStartup(tPowerManagement *env);
|
||||||
|
|
||||||
|
void Pwm_Rs485Disable(tPowerManagement *env);
|
||||||
|
|
||||||
|
//void PowerManagementTelitShutdown(tPowerManagement *env);
|
||||||
|
|
||||||
|
|
||||||
|
#endif //UVEOS_DEMO_ON_NIIET_MCU_POWERMANAGEMENT_H
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
{
|
||||||
|
"dep": [
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
|
||||||
|
"repo": "GpioPin_NATION_N32G45X"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
|
||||||
|
"repo": "SystemDelay_CMSIS_RTOS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
|
||||||
|
"repo": "UveosOnNation_VEGA_SerialPorts"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
|
||||||
|
"repo": "UveosOnNation_VEGA_UserIndication"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
|
||||||
|
"repo": "UveosOnNation_VEGA_UserInput"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
|
||||||
|
"repo": "UveosOnNation_VEGA_SpiPorts"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
|
||||||
|
"repo": "UveosOnNation_VEGA_PWM_LE910"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
|
||||||
|
"repo": "UveosOnNation_VEGA_PWM_SIM68M"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
|
||||||
|
"repo": "UveosOnNation_VEGA_PWM_SIM7600E"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cmake": {
|
||||||
|
"inc_dirs": [
|
||||||
|
"./"
|
||||||
|
],
|
||||||
|
"srcs": [
|
||||||
|
"PowerManagement.c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue