BMS_CAN2_Tools.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. ///##############################################################################
  2. //
  3. // FILE: BMS_CAN2_Tools.c
  4. //
  5. // TITLE: CAN 2
  6. // CAN_Tx_BMU_DICO
  7. // CAN_Tx_BMU1_EVCU1
  8. // check_and_save_Status
  9. // check_and_save_UI
  10. // check_and_save_Temperature
  11. // check_Voltage_Border
  12. // check_Status_Border
  13. // check_UI_Border
  14. // check_Temperature_Border
  15. // Sum_Cell_Voltage
  16. // Test_MAX_LOAD_CELL_VOLTAGE
  17. // Search_MIN_CELL_VOLTAGE
  18. // Test_Slave_Presents
  19. //
  20. //
  21. //##############################################################################
  22. //
  23. //==============================================================================
  24. // Change History:
  25. //==============================================================================
  26. // Datum: | Name | Version:| Change / Cause: | No
  27. //------------------------------------------------------------------------------
  28. // | | | | 002
  29. //------------------------------------------------------------------------------
  30. // | | | | 001
  31. //------------------------------------------------------------------------------
  32. // 31.07.13 | TM | 1.0 | New Build | 000
  33. //==============================================================================
  34. //==============================================================================
  35. // Comment Change / Cause:
  36. //==============================================================================
  37. // Change: 003 // 003
  38. //----------------------
  39. //
  40. //
  41. //==============================================================================
  42. // Change: 002 // 002
  43. //----------------------
  44. //
  45. //
  46. //==============================================================================
  47. // Change: 001 // 001
  48. //----------------------
  49. //
  50. //
  51. //==============================================================================
  52. #include "BMS_Master.h"
  53. extern asm void __startup(register int argc, register char **argv, register char **envp);
  54. // ***** CAN_Tx_BMU1_EVCU1 *******************************************************
  55. uint16_t CAN_Tx_BMU1_EVCU1( void )
  56. {
  57. uint8_t Data[4];
  58. uint16_t ReturnResult = CAN_OK;
  59. uint16_t gISO_R_Dummy;
  60. Data[0] = MF__STANDBY; // Default Mode: StandBy
  61. if( gEvent >= EV__DRIVE_START_1 )
  62. if( gEvent <= EV__SHUT_DOWN_DRIVE )
  63. Data[0] = MF__DRIVE; // Drive
  64. if( gEvent >= EV__CHARGE )
  65. if( gEvent <= EV__SHUT_DOWN_CHARGE )
  66. Data[0] = MF__CHARGE; // Charge
  67. if( gErrorEvent )
  68. Data[0] = MF__ERROR; // Error
  69. Data[1] = 0;
  70. if( gBSD.BlockVoltage[gBSD.r_UI] > 4608 ) // 70% MAX_UI_VOLTAGE
  71. Data[1] |= MF__END_OF_CHARGE; // End of Charge
  72. // Erweiterung ISO in BMUI_EVCU
  73. gISO_R_Dummy = (unsigned short)(gISO_R >> 1); // ISO/2 cause 2^17 Bit
  74. Data[2] = (unsigned char)gISO_R_Dummy; // Low Byte first
  75. Data[3] = (unsigned char)(gISO_R_Dummy >> 8); // High Byte second
  76. //ReturnResult = CAN_Write( &CAN_TxMB_BMU1_EVCU1_18FF9E1E, &Data[0] );
  77. return ReturnResult;
  78. }
  79. // ***** check_and_save_DICO1_EVCU *********************************************
  80. uint16_t check_and_save_DICO1_EVCU( CAN_MAILBOX *p_MBox )
  81. {
  82. uint8_t Data[8]; // Receive Dummy
  83. DICO1_EVCU_t DICO1_EVCU;
  84. if( CAN_Read(p_MBox, &Data[0] ) != CAN_ERROR )
  85. {
  86. DICO1_EVCU.b_StatusByte_1_DCU.R = Data[0];
  87. DICO1_EVCU.b_StatusByte_2_DCU.R = Data[1];
  88. DICO1_EVCU.rpmSys = (uint16_t)((Data[2]<<8) + Data[3]);
  89. DICO1_EVCU.tqRefSys = Data[4];
  90. DICO1_EVCU.tqSys = Data[5];
  91. DICO1_EVCU.powerBR_fb = Data[6];
  92. DICO1_EVCU.b_ErrorBufferIndication.R = Data[7];
  93. if( gEvent == EV__STAND_BY ) // switch out of StandBy only
  94. {
  95. if( DICO1_EVCU.b_StatusByte_2_DCU.B.b_PC_Rq ) // PreCharge Contractor Request
  96. gEvent = EV__DRIVE_START_1;
  97. if( DICO1_EVCU.b_StatusByte_2_DCU.B.b_MC_Rq ) // Main Contractor Request
  98. gEvent = EV__DRIVE_START_3;
  99. }
  100. }
  101. }
  102. // ***** check_and_save_DICO2_EVCU *********************************************
  103. uint16_t check_and_save_DICO2_EVCU( CAN_MAILBOX *p_MBox )
  104. {
  105. uint8_t Data[8]; // Receive Dummy
  106. DICO2_EVCU_t DICO2_EVCU;
  107. if( CAN_Read(p_MBox, &Data[0] ) != CAN_ERROR )
  108. {
  109. DICO2_EVCU.b_DiagnosticInverter1.R = Data[0];
  110. DICO2_EVCU.b_DiagnosticInverter2.R = Data[1];
  111. DICO2_EVCU.b_DiagnosticInverter3.R = Data[2];
  112. DICO2_EVCU.b_Current_HEV_Mode.R = Data[3];
  113. DICO2_EVCU.powerGenerator1Fb = (uint16_t)((Data[4]<<8) + Data[5]);
  114. DICO2_EVCU.rpmGenerator1Fb = (uint16_t)((Data[6]<<8) + Data[7]);
  115. if( DICO2_EVCU.b_DiagnosticInverter2.B.emergency_MC_Off ) // Emergency Main Contractor Off
  116. {
  117. gErrorEvent |= EEV__SHUT_DOWN_EMERGENCY;
  118. }
  119. }
  120. }
  121. // ***** check_and_save_EVCU1_BMU *********************************************
  122. uint16_t check_and_save_EVCU1_BMU( CAN_MAILBOX *p_MBox )
  123. {
  124. uint8_t Data[8]; // Receive Dummy
  125. if( CAN_Read(p_MBox, &Data[0] ) != CAN_ERROR )
  126. {
  127. if(Data[7])
  128. gCANErrorInsert = Data[7]; //!! 1.5-3
  129. else
  130. {
  131. gCANErrorInsert = 0;
  132. Data[0] &= 0x03; // Mask first two Bit for Mode Request
  133. switch( Data[0] )
  134. {
  135. case MR__STANDBY :
  136. if( gEvent > EV__INITIALISE )
  137. {
  138. if( gEvent < EV__CHARGE )
  139. gEvent = EV__SHUT_DOWN_DRIVE;
  140. else
  141. gEvent = EV__SHUT_DOWN_CHARGE;
  142. }
  143. if( gEvent == EV__STAND_BY)
  144. {
  145. if( READ_INPIN( PIN_REGNR_RELAIS_PRECHA ))
  146. gEvent = EV__SHUT_DOWN_DRIVE;
  147. if( READ_INPIN( PIN_REGNR_RELAIS_SLAVE ))
  148. gEvent = EV__SHUT_DOWN_CHARGE;
  149. }
  150. break;
  151. case MR__DRIVE :
  152. if( gEvent == EV__STAND_BY ) // switch out of StandBy only
  153. if( READ_INPIN( PIN_REGNR_RELAIS_PRECHA ))
  154. gEvent = EV__DRIVE_START_3;
  155. else
  156. gEvent = EV__DRIVE_START_1;
  157. break;
  158. case MR__CHARGE :
  159. if( gEvent == EV__STAND_BY ) // switch out of StandBy only
  160. {
  161. if( !READ_INPIN( PIN_REGNR_RELAIS_PRECHA )) // not during DRIVE Start Sequence
  162. gEvent = EV__CHARGE;
  163. }
  164. break;
  165. default :
  166. break;
  167. }
  168. if( Data[1] )
  169. {
  170. ME.MCTL.R = 0x00005AF0; // Software Reset (Functional Reset)
  171. ME.MCTL.R = 0x0000A50F;
  172. while (ME.IS.B.I_MTC != 1) {} /* Wait Until transition completed */
  173. ME.IS.B.I_MTC = 1; /* Clear flag */
  174. }
  175. }
  176. }
  177. }
  178. // ***** End BMS_CAN2_Tools.c **************************************************