123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- /*
- * BMS_Clear_Error_States.c
- *
- * Created on: Nov 8, 2016
- * Author: le8041
- */
- #include "BMS_Master.h"
- uint32_t BMS_Clear_Error_Buffer(MASTER_CAN0_STRUCT_t* s,uint8_t ErrorClass) {
- uint8_t i;
- if(ErrorClass == BMS_ERROR_CLASS_1) {
- // go though Error buffer 1 and check if Errors still apply
- // if no clear Error Flag
- for(i=0;i<s->ErrorBuffer.ES1_ErrorCounter;i++) {
- if(s->ErrorBuffer.ES1_Error[i].Word & 0x00000001) {
- // Error still applies
- if(s->ErrorBuffer.ES1_Error[i].Master.SubsystemNr==BMS_ERROR_MASTER_ID) {
- // Error is master Error
- BMS_Clear_Error_State_Master(s,&(s->ErrorBuffer.ES1_Error[i]),i,ErrorClass);
- }
- else if(s->ErrorBuffer.ES1_Error[i].Master.SubsystemNr==BMS_ERROR_UI_ID) {
- // Error is UI Error
-
- }
- else{
- // Error is Slave Error
- BMS_Clear_Error_State_Slave(s,&(s->ErrorBuffer.ES1_Error[i])) ;
- }
- }
- }
- }
-
- else if(ErrorClass == BMS_ERROR_CLASS_2) {
- // go though Error buffer 2 and check if Errors still apply
- // if no clear Error Flag
- for(i=0;i<s->ErrorBuffer.ES2_ErrorCounter;i++) {
- if(s->ErrorBuffer.ES2_Error[i].Word & 0x00000001) {
- // Error still applies
- if(s->ErrorBuffer.ES2_Error[i].Master.SubsystemNr==BMS_ERROR_MASTER_ID) {
- // Error is master Error
- BMS_Clear_Error_State_Master(s,&(s->ErrorBuffer.ES2_Error[i]),i,ErrorClass);
- }
- else if(s->ErrorBuffer.ES2_Error[i].Master.SubsystemNr==BMS_ERROR_UI_ID) {
- // Error is UI Error
-
- }
- else{
- // Error is Slave Error
- BMS_Clear_Error_State_Slave(s,&(s->ErrorBuffer.ES2_Error[i])) ;
- }
- }
- }
- }
-
- else {
- // go though Error buffer 3 and check if Errors still apply
- // if no clear Error Flag
- for(i=0;i<s->ErrorBuffer.ES3_ErrorCounter;i++) {
- if(s->ErrorBuffer.ES3_Error[i].Word & 0x00000001) {
- // Error still applies
- if(s->ErrorBuffer.ES3_Error[i].Master.SubsystemNr==BMS_ERROR_MASTER_ID) {
- // Error is master Error
- BMS_Clear_Error_State_Master(s,&(s->ErrorBuffer.ES3_Error[i]),i,ErrorClass);
- }
- else if(s->ErrorBuffer.ES3_Error[i].Master.SubsystemNr==BMS_ERROR_UI_ID) {
- // Error is UI Error
-
- }
- else{
- // Error is Slave Error
-
- }
- }
- }
- }
- return TRUE;
- }
- /*
- * @brief check if error still applies, if no return false if yes return true and invalidate error
- */
- uint32_t BMS_Clear_Error_State_Master(MASTER_CAN0_STRUCT_t* s,BMS_ERROR_STATE_t* error_state,uint8_t Error_nr,uint8_t Error_class) {
- uint8_t SlaveSelect;
- if(error_state->Master.ErrorCode==BMS_ERROR_STACK_MASTER_UMIN_1) {
- // check if Umin1 error still applies
- if(s->inverterState.startupPwr >20 ) {
- // PV Supplies more than 20W Start recharging battery
- // give inverter time to start charging battery
- if(Error_class ==BMS_ERROR_CLASS_1) {
- // use Error class 1
- if(s->ErrorBuffer.ES1_Error_Recovery[Error_nr].recoveryPending== FALSE) {
- // not yet trying to recover from Error
- s->ErrorBuffer.ES1_Error_Recovery[Error_nr].recoveryPending= TRUE;
- s->ErrorBuffer.ES1_Error_Recovery[Error_nr].recoveryTimestamp =Global_1msCounter ;
- return TRUE;
- }
- else {
- // System already trying to recover from error
- if(s->inverterState.inverterIsCharging == TRUE) {
- // system is charging => Error can be completely revoked
- error_state->Master.active=0;
- s->ErrorBuffer.ES1_Error_Recovery[Error_nr].recoveryPending= FALSE;
- return TRUE;
- }
- else if(s->ErrorBuffer.ES1_Error_Recovery[Error_nr].recoveryPending== TRUE) {
- // check if timeout occured
- if(s->ErrorBuffer.ES1_Error_Recovery[Error_nr].recoveryTimestamp +BMS_ERROR_RESTORE_TIMEOUT < Global_1msCounter) {
- // timeout occured
- error_state->Master.active=1;
- s->ErrorBuffer.ES1_Error_Recovery[Error_nr].recoveryPending= FALSE;
- return FALSE;
- }
- else {
- // no timeout;
- return TRUE;
- }
- }
- }
- }
- else if(Error_class ==BMS_ERROR_CLASS_2) {
- // use Error class 2
- // up date if umin1 should become error class 2
- return FALSE;
- }
- else {
- // Error class 3 has no recovery function
- error_state->Master.active=1;
- return FALSE;
- }
- return FALSE;
- }
- else {
- error_state->Master.active=1;
- return FALSE;
- }
- }
- else if(error_state->Master.ErrorCode==BMS_ERROR_STACK_MASTER_UMIN_2 ) {
- // check if Umin2 error still applies
- if(s->inverterState.startupPwr >20 ) {
- // PV Supplies more than 20W Start recharging battery
- // give inverter time to start charging battery
- if(Error_class ==BMS_ERROR_CLASS_2) {
- // use Error class 2
- if(s->ErrorBuffer.ES2_Error_Recovery[Error_nr].recoveryPending== FALSE) {
- // not yet trying to recover from Error
- s->ErrorBuffer.ES2_Error_Recovery[Error_nr].recoveryPending= TRUE;
- s->ErrorBuffer.ES2_Error_Recovery[Error_nr].recoveryTimestamp =Global_1msCounter ;
- return TRUE;
- }
- else {
- // System already trying to recover from error
- if(s->inverterState.inverterIsCharging == TRUE) {
- // system is charging => Error can be completely revoked
- error_state->Master.active=0;
- s->ErrorBuffer.ES2_Error_Recovery[Error_nr].recoveryPending= FALSE;
- return TRUE;
- }
- else if(s->ErrorBuffer.ES2_Error_Recovery[Error_nr].recoveryPending== TRUE) {
- // check if timeout occured
- if(s->ErrorBuffer.ES2_Error_Recovery[Error_nr].recoveryTimestamp +BMS_ERROR_RESTORE_TIMEOUT < Global_1msCounter) {
- // timeout occured
- error_state->Master.active=1;
- s->ErrorBuffer.ES2_Error_Recovery[Error_nr].recoveryPending= FALSE;
- return FALSE;
- }
- else {
- // no timeout;
- return TRUE;
- }
- }
- }
- }
- else {
- // Error class 3 has no recovery function
- error_state->Master.active=1;
- return FALSE;
- }
- return FALSE;
- }
-
- }
- else if(error_state->Master.ErrorCode==BMS_ERROR_STACK_MASTER_UMIN_3) {
- // check if Umin1 error still applies
- // error state can only removed from external technician
- return FALSE;
- }
- else if(error_state->Master.ErrorCode==BMS_ERROR_STACK_MASTER_UMAX_2) {
- // check if Umax2 error still applies
- if(s->maxCellVoltage <= BMS_SOC_UMAX_2) {
- // error no longer applies
- error_state->Master.active=0;
- return TRUE;
- }
- else {
- return FALSE;
- }
- }
- else if(error_state->Master.ErrorCode==BMS_ERROR_STACK_MASTER_I_MAX_DISCHARGE_OP) {
- // not clear how to revoke error because relais are open and therefore current is 0A
-
- error_state->Master.active=0;
- return TRUE;
-
- }
- else if(error_state->Master.ErrorCode==BMS_ERROR_STACK_MASTER_I_MAX_CHARGE_OP) {
- // not clear how to revoke error because relais are open and therefore current is 0A
-
- error_state->Master.active=0;
- return TRUE;
-
- }
- else if( error_state->Master.ErrorCode==BMS_ERROR_STACK_MASTER_EXTERN_CAN_ERROR) {
- // simply revoke Error when no more Timeouts are detected
- if(s->CAN1_fsmStruct.timeoutCyclesCnt==0) {
- error_state->Master.active = 0;
- return TRUE;
- }
- return FALSE;
- }
-
- else{
- // invalid state
- return FALSE;
- }
-
- }
- /*
- * @brief check if error still applies, if no return false if yes return true and invalidate error
- */
- uint32_t BMS_Clear_Error_State_Slave(MASTER_CAN0_STRUCT_t* s,BMS_ERROR_STATE_t* error_state) {
- uint8_t SlaveSelect;
- if(error_state->Slave.ErrorType == BMS_ERROR_STACK_SLAVE_CAN_ERROR) {
- SlaveSelect=error_state->Slave.SubsystemNr;
- if(s->Slave[SlaveSelect].SlaveCanCommuniationError.FailedComCnt==0) {
- // connection is good again
- error_state->Slave.active=0;
- return TRUE;
- }
- else {
- return FALSE;
- }
- }
- else{
- // invalid state
- return FALSE;
- }
- }
- uint32_t BMS_Clear_Error_init_recovery_struct(MASTER_CAN0_STRUCT_t* s) {
- uint8_t i;
- for(i=0;i<BMS_ERROR_ERROR_STACK_SIZE;i++) {
- s->ErrorBuffer.ES1_Error_Recovery[i].recoveryPending=0;
- s->ErrorBuffer.ES1_Error_Recovery[1].recoveryTimestamp=0;
- s->ErrorBuffer.ES2_Error_Recovery[i].recoveryPending=0;
- s->ErrorBuffer.ES2_Error_Recovery[1].recoveryTimestamp=0;
- }
-
- }
|