/*
 * ADBMS_Abstraction.h
 *
 *  Created on: 14.07.2022
 *      Author: max
 */

#ifndef INC_ADBMS_ABSTRACTION_H_
#define INC_ADBMS_ABSTRACTION_H_

#include "ADBMS_LL_Driver.h"
#include "ADBMS_CMD_MAKROS.h"
#include "main.h"

#define MAXIMUM_CELL_VOLTAGES 18
#define MAXIMUM_AUX_VOLTAGES 10
#define MAXIMUM_GPIO 10

#define DEFAULT_UV 1562//(VUV + 1)*16*100uV 	Default Setting 2.5V
#define DEFAULT_OV 2625//(VOV)*16*100uV		Default Setting 4.2V

typedef struct
{
	uint16 cellVoltages[MAXIMUM_CELL_VOLTAGES];
	uint16 auxVoltages[MAXIMUM_AUX_VOLTAGES];

	uint16 internalDieTemp;
	uint16 analogSupplyVoltage;
	uint16 digitalSupplyVoltage;
	uint16 sumOfCellMeasurements;
	uint16 refVoltage;

	uint16 GPIO_Values[MAXIMUM_GPIO];

	uint32 overVoltage;
	uint32 underVoltage;

} Cell_Module;



uint8 initAMS(SPI_HandleTypeDef* hspi, uint8 numofcells, uint8 numofaux);
uint8 amsWakeUp();

uint8 amsCellMeasurement(Cell_Module *module);
uint8 amsConfigCellMeasurement(uint8 numberofChannels);

uint8 amsAuxMeasurement(Cell_Module *module);
uint8 amsConfigAuxMeasurement(uint16 Channels);

uint8 amsInternalStatusMeasurement(Cell_Module *module);

uint8 amsConfigGPIO(uint16 gpios);
uint8 amsSetGPIO(uint16 gpios);
uint8 readGPIO(Cell_Module* module);

uint8 amsConfigBalancing(uint32 Channels);
uint8 amsStartBalancing(uint8 dutyCycle);
uint8 amsStopBalancing();

uint8 amsSelfTest();

uint8 amsConfigUnderVoltage(uint16 underVoltage);

uint8 amsCheckUnderOverVoltage(Cell_Module *module);
uint8 amsConfigOverVoltage(uint16 overVoltage);

uint8 amscheckOpenCellWire(Cell_Module *module);

uint8 amsClearStatus();
uint8 amsClearAux();
uint8 amsClearCells();

uint8 amsSendWarning();
uint8 amsSendError();

uint8 amsClearWarning();
uint8 amsClearError();

uint8 amsReadCellVoltages(Cell_Module *module);

#endif /* INC_ADBMS_ABSTRACTION_H_ */
