SMART_COMPONENTS_PowerManag.../PowerManagment.h

170 lines
3.8 KiB
C

//
// Created by ilya on 25.03.24.
//
#ifndef SMART_COMPONENTS_POWERMANAGMENT_H
#define SMART_COMPONENTS_POWERMANAGMENT_H
#include <SerialPorts.h>
#include "GpioPin.h"
#include "UserInput.h"
#include "UserIndication.h"
#include "SpiPorts.h"
#include "Adc.h"
#include "LoggerInterface.h"
#include "PwmSim7600e.h"
#include "LoggerToSerialPort.h"
//#include "Amplifier.h"
#define PM_SHUTDOWN_DELAY 15000
typedef struct {
tGpioPin resetAmp;
} tAudioPower;
typedef struct {
tGpioPin ignition;
tGpioPin standby;
tGpioPin garage;
tGpioPin ecallOut;
tGpioPin muteP;
tGpioPin muteN;
tGpioPin inAnt;
tGpioPin Power12V;
} tMainPower;
typedef struct {
tGpioPin can1_standby;
tGpioPin can2_standby;
} tCanStandby;
typedef struct {
tGpioPin enable;
tGpioPin charge;
tAdcIO *batteryIo;
uint16_t currentBatVoltage;
uint64_t batTestTimer;
} tBatteryPower;
typedef struct {
tGpioPin PowerCheckSpkOn;
tGpioPin PowerTestSpkIn;
bool speakTestAcsess;
uint16_t lastTestTime;
} tSpekTestPower;
typedef struct {
tAdc *boardVoltage;
uint16_t currentBoardVoltage;
uint16_t currentBoardVoltageOfSerbisePO;
uint32_t boardVoltageTimer;
} tBoardPower;
typedef struct {
tSpekTestPower SpekTestPower;
tGpioPin PowerRS485;
tGpioPin usb;
tAudioPower audio;
tBatteryPower battery;
tMainPower main;
tSim7600ePower sim7600;
tCanStandby canStandby;
tBoardPower boardPower;
} tPowerSusystem;
typedef struct {
bool interAntBufVal;
tLoggerInterface *logger;
tPowerSusystem *powerSusystem;
bool *positiveMute;
uint32_t shutdownDelay;
uint32_t lastIgnEnabled;
bool currentChargeState;
bool currentPwrSaveState;
bool currentIgnState;
bool (*resetAmpLvl) (void *env);
tLoggerToSerialPort *slog;
osMutexId_t mux_accessPwrMan;
tGpioPin *sosButtonPin;
tGpioPin *serviceButtonPin;
struct {
osThreadId_t id;
uint32_t stack[256];
StaticTask_t controlBlock;
osThreadAttr_t attr;
} threadPwr;
} tPowerManagement;
#define PowerManagementProviderSetAmplVol(ENV) (ENV)->resetAmpLvl((ENV)->ampEnv)
void Pwm_Init(
tPowerManagement *env,
tPowerSusystem *powerSusystem,
tAdcIO *batteryIo,
tAdc *boardVoltag,
bool *positiveMute,
tLoggerToSerialPort *slog,
tGpioPin *sosButtonPin,
tGpioPin *serviceButtonPin
);
void PowerManagement_StartThread(tPowerManagement *env);
void Pwm_OnDeviceInit(tPowerManagement *env);
bool Pwm_IsShutdownRequired(tPowerManagement *env);
void Pwm_Blackout(tPowerManagement *env);
//void Pwm_MuteAmpOff(tPowerManagement *env);
void Pwm_AmpOn(tPowerManagement *env);
void Pwm_AmpOff(tPowerManagement *env);
void Pwm_ChargeDisable(tPowerManagement *env);
void Pwm_ChargeEnable(tPowerManagement *env);
void Pwm_LNA_setMode(tPowerManagement *env, bool state);
//void Pwm_MuteAmpOn(tPowerManagement *env);
void Pwm_PowerSavingEnable(tPowerManagement *env);
void Pwm_PowerSavingDisable(tPowerManagement *env);
void Pwm_SetMuteInCar(tPowerManagement *env, bool value);
void Pwm_BipShutdown(tPowerManagement *env);
void Pwm_GsmAndBipStartUp(tPowerManagement *env);
void Pwm_GsmAndGnssStartup(tPowerManagement *env);
bool Pwm_GsmAndGnssShutDown(tPowerManagement *env);
void Pwm_Rs485Disable(tPowerManagement *env);
bool Pwm_GetMuteInCarState(tPowerManagement *env);
void Pwm_Shutdown(tPowerManagement *env);
void Pwm_SetPMuteInCar(tPowerManagement *env, bool value);
void Pwm_SetNMuteInCar(tPowerManagement *env, bool value);
void Pwm_SetEcallSignalOutInCar(tPowerManagement *env, bool value);
void Pwm_SetServiseSignalOutInCar(tPowerManagement *env, bool value);
bool Pwm_GetSosButtonState(tPowerManagement *env);
bool Pwm_GetServiseButtonState(tPowerManagement *env);
#endif //SMART_COMPONENTS_POWERMANAGMENT_H