123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- //##############################################################################
- //
- // BMS_Master - Battery Management System Master
- //
- // Firmware for
- // - Collecting and Checking Data of BMS_Slave and BMS_UI
- // - Flow Control for START, STOP, LOAD and DRIVE
- // - SOC/SOH computing
- // - Balancer computing
- // - Error Check
- // - Emergency Shut Off
- //
- //
- // CENTRAL - FILE
- //
- // - void Main( void )
- //
- //
- //##############################################################################
- //
- // Hardware Revision: V1
- //
- // uController: Freescale MPC5646C
- //
- // Autor: M. Maurer, V. Reiling, KIT Campus Nord, IPE
- //
- // Date: April 2012
- //
- // Built with: CodeWarrior Development Studio 10.4 ( Build Id: 130425 )
- //
- //##############################################################################
- //==============================================================================
- // History:
- //==============================================================================
- // Datum: | Name | Version:| Cause: | rev.:
- //------------------------------------------------------------------------------
- // 04.05.15 | VR | 1.5 | Change for BaSyTec | 005
- //------------------------------------------------------------------------------
- // 18.11.14 | VR | 1.4 | upgrade 2 CodeWarrior 10.6 id: 140329 | 004
- //------------------------------------------------------------------------------
- // 18.03.14 | VR | 1.3 | Error Handling changed, Derating added | 003
- //------------------------------------------------------------------------------
- // 07.02.14 | VR | 1.2 | upgrade 2 CodeWarrior 10.5 id: 130916 | 002
- //------------------------------------------------------------------------------
- // 05.07.13 | VR | 1.1 | BMS Master Project | 001
- //------------------------------------------------------------------------------
- // 20.04.12 | TM | 1.0 | Hardware Test Code & Drivers | 000
- //==============================================================================
- #include "BMS_Master.h"
- uint8_t const ucMainVersion = 0x1;
- uint8_t const ucSubVersion = 0x5;
- // ***** Global Variables *******************************************************************
- BSD_t gBSD; // Global Battery Management System Slave Data
- BSE_t gBSE; // Global Battery Management System Slave Errors
- uint8_t gMaxDischargeCurrent = 60; // Maximum Discharge Current = 120A / 2A per Bit
- uint64_t Global_1msCounter = 0; // Million Years till Overrun
- uint32_t gEvent; // Control of Main FSM
- uint32_t gErrorEvent; // Control of Error FSM
- uint32_t gISO_R = 0; // Resistance of Isolation
- uint8_t gCANErrorInsert = 0; // Automatic Test over CAN
- MASTER_CAN0_STRUCT_t gDUMMY_data_struct;
- void main(void)
- {
- /**
- * @brief Main Function of BMS Master
- */
- volatile uint16_t Vbat = 0;
- volatile uint16_t StartTryCounter = 0;
- volatile uint32_t DelayCount = 0;
- volatile uint32_t NextEvent = 0;
- volatile uint32_t CounterCheckVoltageMSG = 12000;
- volatile uint32_t CounterCheckStatusUIMSG = 12000;
- volatile uint32_t CounterCheckTemperatureMSG = 12000;
- volatile uint32_t Counter_20ms = 5000;
- volatile uint32_t Counter_50ms = 5000;
- volatile uint32_t Counter_100ms = 5000;
- volatile uint16_t Copy_r_Voltage = 200;
- volatile uint16_t Copy_r_Status = 200;
- volatile uint16_t Copy_r_Temperature = 200;
- volatile uint16_t Copy_r_UI = 200;
- volatile uint32_t ErrorTimeCount = 0;
- static float SoC_test;
-
- static uint64_t test_timestamp = 0;
- static uint8_t test_data_send[4] = {1,2,3,4};
- static MASTER_CAN0_STRUCT_t CAN0_fsm_state;
- static MASTER_CAN1_STRUCT_t CAN1_fsm_state;
- static BMS_MASTER_OPERATION_t operation_Fsm;
- static uint8_t active_states[2]= {4,15} ;
- static BMS_SLAVE_CONFIGURATION_t cellConfig[CAN0_MAX_NR_OF_SLAVES-1];
- static BMS_UI_CONFIGURATION_t uiConfig;
- static uint8_t fram_test[8] ={1,2,3,4,5,6,7,8};
- static uint8_t fram_rx_text[8] ={0,0,0,0,0,0,0,0};
-
-
-
-
-
- int32_t SOC = 0; // State of Charge for DICO in 0.4%
- uint32_t BalanceOn = 1; // Send empty Balancing
- uint32_t i = 0;
- uint32_t j = 0;
- uint32_t test = 0;
- uint16_t U12, U33; //!! Test der Betriebsspannung
-
-
- //-------------------------------------------------------------------------------------------
- init_Device(); // Device.h
- BoardPeriph_init(); // BoardPeripherals.h
-
- CAN0_init(); // CAN Master to Slave
- CAN1_init(); // CAN Master to INVERTER
- CAN1_init_tx_structure(&(CAN0_fsm_state.inverter.txStruct));
- //CAN2_init(); // CAN Master to DICO
-
- MultitaskOS_init(); // MultitaskOS.h
-
- enableIrq(); // Device.h
-
- BoardPeriph_test_init(); // BoardPeripherals.h
- gEvent = EV__INITIALISE; // Start Main FSM
- gErrorEvent = EEV__NO_ERROR; // Clear Error FSM
-
- SwitchRelais( PWR_SUPPLY, 0) ;// Activate PWR Supply by setting pin to low
- //CAN_Tx_BMU_DICO( );
- gen_data_initSlave(&gDUMMY_data_struct, 3600, 25, 36000, 1000);
-
- initCellConfig(cellConfig);
- initUiConfig(&uiConfig);
-
- CAN0_init_telegrams(&TelegramTxContainer[0],CAN0_MAX_NR_OF_SLAVES);
- init_master_CAN0_fsm(&CAN0_fsm_state,cellConfig,&uiConfig);
- Master_CAN1_fsm_init(&CAN1_fsm_state);
-
- BMS_Can_ID_init_init_startupConfig (&CAN0_fsm_state);
-
- //init_master_operation_fsm(&operation_Fsm);
-
- // read fram start State
-
-
- while(Global_1msCounter < DELAY_START)
- {
- }
-
- while(BMS_Can_ID_init_fsm (&CAN0_fsm_state) == BMS_CAN_ID_INIT_RETURN_RUNNING ) {
- // wait
- }
- //write_fram_clear_startup_state(&CAN0_fsm_state);
- write_fram_clear_error_buffer(&CAN0_fsm_state);
- //write_fram_set_SoC(0.03);
-
- while(Global_1msCounter < DELAY_START*2)
- {
- }
- CheckSupplyVoltages( &U12, &U33 ); //!! Test der Betriebsspannung
-
- read_fram_get_startup_state(&CAN0_fsm_state);
- read_fram_read_error_buffer(&CAN0_fsm_state);
-
- SoC_test= read_fram_get_SoC();
- test_timestamp=Global_1msCounter ;
- while(1) {
-
- Master_CAN0_fsm(&CAN0_fsm_state,Global_1msCounter);
- //Master_operation_fsm(&CAN0_fsm_state,Global_1msCounter,&operation_Fsm);
-
- //Master_CAN1_fsm(&CAN0_fsm_state,&CAN1_fsm_state,Global_1msCounter);
- //if(Global_1msCounter > 20000 + test_timestamp) {
- // SwitchRelais( PWR_SUPPLY, 1);
- //}
-
-
- }
-
- }
- // ***** End Main.c *************************************************************************
|