Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
adi_bms_2950data.cpp
00001 /** 00002 ******************************************************************************** 00003 * 00004 * @file: adi_bms_2950data.c 00005 * 00006 * @brief: This file contains 2950 data function implementation. 00007 * 00008 * @details: 00009 * 00010 ******************************************************************************* 00011 Copyright(c) 2020 Analog Devices, Inc. All Rights Reserved. This software is 00012 proprietary & confidential to Analog Devices, Inc. and its licensors. By using 00013 this software you agree to the terms of the associated Analog Devices License 00014 Agreement. 00015 ******************************************************************************* 00016 */ 00017 /*! \addtogroup BMS_Driver 00018 * @{ 00019 */ 00020 00021 /*! \addtogroup Data_Management 00022 * @{ 00023 */ 00024 00025 #include "adbms2950.h" 00026 //#include "pal.h" 00027 /** 00028 ******************************************************************************* 00029 * Function: adBms2950_Adi1 00030 * @brief ADI1 Command. 00031 * 00032 * @details Send ADI1 command to start Current1 ADC Conversion. 00033 * 00034 * Parameters: 00035 * @param [in] RD Enum type Read bit 00036 * 00037 * @param [in] CONT Enum type continuous measurement bit 00038 * 00039 * @param [in] ow Enum type open wire bit 00040 * 00041 * @return None 00042 * 00043 ******************************************************************************* 00044 */ 00045 void adBms2950_Adi1(RD rd, CONT cont, OW ow) 00046 { 00047 uint8_t cmd[2]; 00048 cmd[0] = 0x02 + rd; 00049 cmd[1] = (cont<<7) + (ow & 0x03) + 0x60; 00050 spiSendCmd(cmd); 00051 } 00052 00053 /** 00054 ******************************************************************************* 00055 * Function: adBms2950_Adi2 00056 * @brief ADI2 Command. 00057 * 00058 * @details Send ADI2 command to start Current2 ADC Conversion. 00059 * 00060 * Parameters: 00061 * @param [in] cont Enum type continuous measurement bit 00062 * 00063 * @param [in] ow Enum type open wire 00064 * 00065 * @return None 00066 * 00067 ******************************************************************************* 00068 */ 00069 void adBms2950_Adi2(CONT cont, OW ow) 00070 { 00071 uint8_t cmd[2]; 00072 cmd[0] = 0x01; 00073 cmd[1] = (cont<<7) + (ow &0x03) + 0x68; 00074 spiSendCmd(cmd); 00075 } 00076 00077 /** 00078 ******************************************************************************* 00079 * Function: adBms2950_Adv 00080 * @brief ADV Command. 00081 * 00082 * @details Send ADV command to start Voltage ADC Conversion. 00083 * 00084 * Parameters: 00085 * @param [in] ow Enum type open wire bits 00086 * 00087 * @param [in] vch Enum type open VCH channel 00088 * 00089 * @return None 00090 * 00091 ******************************************************************************* 00092 */ 00093 void adBms2950_Adv(OW ow, VCH vch) 00094 { 00095 uint8_t cmd[2]; 00096 cmd[0] = 0x04; 00097 cmd[1] = (ow << 7) + 0x30 + (vch & 0x0F); 00098 spiSendCmd(cmd); 00099 } 00100 00101 /** 00102 ******************************************************************************* 00103 * Function: adBms2950_Adaux 00104 * @brief ADAUX Command. 00105 * 00106 * @details Send ADAUX command to start aux ADC Conversion. 00107 * 00108 * Parameters: 00109 * @param [in] ach Enum type ACH channel 00110 * 00111 * @return None 00112 * 00113 ******************************************************************************* 00114 */ 00115 void adBms2950_Adaux(ACH ach) 00116 { 00117 uint8_t cmd[2]; 00118 cmd[0] = 0x05; 00119 cmd[1] = 0x30 + (ach & 0x03); 00120 spiSendCmd(cmd); 00121 } 00122 00123 /** 00124 ******************************************************************************* 00125 * Function: adBms2950_Stcomm 00126 * @brief Send command to Start I2C/SPI Communication. 00127 * 00128 * @details Send command to start I2C/SPI communication. 00129 * 00130 * @return None 00131 * 00132 ******************************************************************************* 00133 */ 00134 void adBms2950_Stcomm(void) 00135 { 00136 adBmsCsLow(); 00137 spiWriteBytes(&STCOMM [0], 13); 00138 adBmsCsHigh(); 00139 } 00140 00141 /** 00142 ******************************************************************************* 00143 * Function: adBms2950ConfigA_Flag 00144 * @brief Config A Flag Bits. 00145 * 00146 * @details This function Set configuration A flag bits. 00147 * 00148 * Parameters: 00149 * 00150 * @param [in] flag_d Enum type flag bit. 00151 * 00152 * @param [in] flag Enum type set or clr flag. 00153 * 00154 * @return Flag_value 00155 * 00156 ******************************************************************************* 00157 */ 00158 uint8_t adBms2950ConfigA_Flag(FLAG_D flag_d, CFGA_FLAG flag) 00159 { 00160 uint8_t flag_value; 00161 if(flag == FLAG_SET) 00162 { 00163 flag_value = (1 << flag_d); 00164 } 00165 else 00166 { 00167 flag_value = (0 << flag_d); 00168 } 00169 return(flag_value); 00170 } 00171 00172 /** 00173 ******************************************************************************* 00174 * Function: adBms2950ConfigA_Gpio 00175 * @brief Config Gpio Pull High/Low. 00176 * 00177 * @details This function Set configuration gpio as pull high/Low. 00178 * 00179 * Parameters: 00180 * 00181 * @param [in] gpio Enum type GPIO Pin. 00182 * 00183 * @param [in] set_clr Enum type gpio set (Low or High). 00184 * 00185 * @return Gpio_value 00186 * 00187 ******************************************************************************* 00188 */ 00189 uint8_t adBms2950ConfigA_Gpio(GPIO gpio, CFGA_GPIO set_clr) 00190 { 00191 uint8_t gpoivalue; 00192 if(set_clr == GPIO_SET) 00193 { 00194 gpoivalue = (1 << gpio); 00195 } 00196 else 00197 { 00198 gpoivalue = (0 << gpio); 00199 } 00200 return(gpoivalue); 00201 } 00202 00203 /** 00204 ******************************************************************************* 00205 * Function: adBms2950ConfigA_Gpo 00206 * @brief Set config GPO Pull High/Low. 00207 * 00208 * @details This function Set configuration gpo as pull high/Low. 00209 * 00210 * Parameters: 00211 * 00212 * @param [in] gpo Enum type GPO Pin. 00213 * 00214 * @param [in] set_clr Enum type gpo set (Low or High). 00215 * 00216 * @return Gpo_value 00217 * 00218 ******************************************************************************* 00219 */ 00220 uint8_t adBms2950ConfigA_Gpo(GPO gpo, CFGA_GPO set_clr) 00221 { 00222 uint8_t gpovalue; 00223 if(set_clr == GPO_SET) 00224 { 00225 gpovalue = (1 << gpo); 00226 } 00227 else 00228 { 00229 gpovalue = (0 << gpo); 00230 } 00231 return(gpovalue); 00232 } 00233 00234 /** 00235 ******************************************************************************* 00236 * Function: adBms2950ParseConfiga 00237 * @brief Parse the recived Configuration register A data 00238 * 00239 * @details This function Parse the recived Configuration register A data. 00240 * 00241 * Parameters: 00242 * 00243 * @param [in] tIC Total IC 00244 * 00245 * @param [in] *ic cell_asic ic structure pointer 00246 * 00247 * @param [in] *data Data pointer 00248 * 00249 * @return None 00250 * 00251 ******************************************************************************* 00252 */ 00253 void adBms2950ParseConfiga(uint8_t tIC, cell_asic *ic, uint8_t *data) 00254 { 00255 uint8_t address = 0; 00256 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00257 { 00258 memcpy(&ic[curr_ic].configa.rx_data[0], &data[address], RX_DATA); /* dst , src , size */ 00259 address = ((curr_ic+1) * (RX_DATA)); 00260 00261 ic[curr_ic].rx_cfga.vs10 = (ic[curr_ic].configa.rx_data[0] & 0x01); 00262 ic[curr_ic].rx_cfga.vs1 = (ic[curr_ic].configa.rx_data[0] & 0x06) >> 1; 00263 ic[curr_ic].rx_cfga.refon = (ic[curr_ic].configa.rx_data[0] & 0x80) >> 7; 00264 00265 ic[curr_ic].rx_cfga.flag_d = (ic[curr_ic].configa.rx_data[1] & 0xFF); 00266 00267 ic[curr_ic].rx_cfga.soak = (ic[curr_ic].configa.rx_data[2] & 0x38) >> 3; 00268 ic[curr_ic].rx_cfga.vs6 = (((ic[curr_ic].configa.rx_data[2] & 0x40) >> 6)); 00269 ic[curr_ic].rx_cfga.vs7 = (((ic[curr_ic].configa.rx_data[2] & 0x80) >> 7)); 00270 00271 ic[curr_ic].rx_cfga.gpio = (ic[curr_ic].configa.rx_data[3] & 0x1E); 00272 ic[curr_ic].rx_cfga.gpo = ((ic[curr_ic].configa.rx_data[3] & 0xE0) >> 4) | ((ic[curr_ic].configa.rx_data[4] & 0x03) << 4) | (ic[curr_ic].configa.rx_data[3] & 0x01) ; 00273 00274 ic[curr_ic].rx_cfga.snap_st = ((ic[curr_ic].configa.rx_data[5] & 0x20) >> 5); 00275 ic[curr_ic].rx_cfga.comm_bk = ((ic[curr_ic].configa.rx_data[5] & 0x08) >> 3); 00276 ic[curr_ic].rx_cfga.vs5 = ((ic[curr_ic].configa.rx_data[5] & 0x04) >> 2); 00277 ic[curr_ic].rx_cfga.vs4 = ((ic[curr_ic].configa.rx_data[5] & 0x02) >> 1); 00278 ic[curr_ic].rx_cfga.vs3 = (ic[curr_ic].configa.rx_data[5] & 0x01); 00279 } 00280 } 00281 00282 /** 00283 ******************************************************************************* 00284 * Function: adBms2950ParseConfigb 00285 * @brief Parse the recived Configuration register B data 00286 * 00287 * @details This function Parse the recived Configuration register B data. 00288 * 00289 * Parameters: 00290 * 00291 * @param [in] tIC Total IC 00292 * 00293 * @param [in] *ic cell_asic ic structure pointer 00294 * 00295 * @param [in] *data Data pointer 00296 * 00297 * @return None 00298 * 00299 ******************************************************************************* 00300 */ 00301 void adBms2950ParseConfigb(uint8_t tIC, cell_asic *ic, uint8_t *data) 00302 { 00303 uint8_t address = 0; 00304 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00305 { 00306 memcpy(&ic[curr_ic].configb.rx_data[0], &data[address], RX_DATA); /* dst , src , size */ 00307 address = ((curr_ic+1) * (RX_DATA)); 00308 00309 ic[curr_ic].rx_cfgb.oc1th = (ic[curr_ic].configb.rx_data[0] & 0x7F); 00310 ic[curr_ic].rx_cfgb.vs2 = (((ic[curr_ic].configb.rx_data[0] & 0x80) >> 7) << 1); /* VS2[1] MSB bit */ 00311 00312 ic[curr_ic].rx_cfgb.oc2th = (ic[curr_ic].configb.rx_data[1] & 0x7F); 00313 ic[curr_ic].rx_cfgb.vs2 = (ic[curr_ic].configb.rx_data[1] & 0x80) >> 7; /* VS2[0] LSB bit */ 00314 00315 ic[curr_ic].rx_cfgb.dg1th = (ic[curr_ic].configb.rx_data[2] & 0x07); 00316 ic[curr_ic].rx_cfgb.dg2th = (ic[curr_ic].configb.rx_data[2] & 0x38) >> 3; 00317 ic[curr_ic].rx_cfgb.vs8 = (ic[curr_ic].configb.rx_data[2] & 0xC0) >> 6; 00318 ic[curr_ic].rx_cfgb.vs9 = (ic[curr_ic].configb.rx_data[2] & 0xC0) >> 7; 00319 } 00320 } 00321 00322 /** 00323 ******************************************************************************* 00324 * Function: adBms2950ParseConfig 00325 * @brief Parse the recived Configuration register A & B data 00326 * 00327 * @details This function Parse the recived Configuration register A & B data. 00328 * 00329 * Parameters: 00330 * 00331 * @param [in] tIC Total IC 00332 * 00333 * @param [in] *ic cell_asic ic structure pointer 00334 * 00335 * @param [in] grp Enum type register group 00336 * 00337 * @param [in] *data Data pointer 00338 * 00339 * @return None 00340 * 00341 ******************************************************************************* 00342 */ 00343 void adBms2950ParseConfig(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *data) 00344 { 00345 switch (grp) 00346 { 00347 case A: 00348 adBms2950ParseConfiga(tIC, &ic[0], &data[0]); 00349 break; 00350 00351 case B: 00352 adBms2950ParseConfigb(tIC, &ic[0], &data[0]); 00353 break; 00354 00355 default: 00356 break; 00357 } 00358 } 00359 00360 /** 00361 ******************************************************************************* 00362 * Function: adBms2950ParseCurrentRegData 00363 * @brief Parse Current Register data 00364 * 00365 * @details This function Parse the received current register data. 00366 * 00367 * Parameters: 00368 * 00369 * @param [in] tIC Total IC 00370 * 00371 * @param [in] *ic cell_asic ic structure pointer 00372 * 00373 * @param [in] *i_data Current data pointer 00374 * 00375 * @return None 00376 * 00377 ******************************************************************************* 00378 */ 00379 void adBms2950ParseCurrentRegData(uint8_t tIC, cell_asic *ic, uint8_t *i_data) 00380 { 00381 uint8_t address = 0; 00382 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00383 { 00384 memcpy(&ic[curr_ic].reg.rx_data[0], &i_data[address], RX_DATA); /* dst , src , size */ 00385 address = ((curr_ic+1) * (RX_DATA)); 00386 ic[curr_ic].i.i1 = ic[curr_ic].reg.rx_data[0] + (ic[curr_ic].reg.rx_data[1] << 8) + (ic[curr_ic].reg.rx_data[2] << 16); 00387 ic[curr_ic].i.i2 = ic[curr_ic].reg.rx_data[3] + (ic[curr_ic].reg.rx_data[4] << 8) + (ic[curr_ic].reg.rx_data[5] << 16); 00388 } 00389 } 00390 00391 /** 00392 ******************************************************************************* 00393 * Function: adBms2950ParseVbatRegData 00394 * @brief Parse Battery Voltage Register Data 00395 * 00396 * @details This function Parse the received battery voltage register data. 00397 * 00398 * Parameters: 00399 * 00400 * @param [in] tIC Total IC 00401 * 00402 * @param [in] *ic cell_asic ic structure pointer 00403 * 00404 * @param [in] *vbat_data Vbat data pointer 00405 * 00406 * @return None 00407 * 00408 ******************************************************************************* 00409 */ 00410 void adBms2950ParseVbatRegData(uint8_t tIC, cell_asic *ic, uint8_t *vbat_data) 00411 { 00412 uint8_t address = 0; 00413 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00414 { 00415 memcpy(&ic[curr_ic].reg.rx_data[0], &vbat_data[address], RX_DATA); /* dst , src , size */ 00416 address = ((curr_ic+1) * (RX_DATA)); 00417 ic[curr_ic].vbat.vbat1 = ic[curr_ic].reg.rx_data[2] + (ic[curr_ic].reg.rx_data[3] << 8); 00418 ic[curr_ic].vbat.vbat2 = ic[curr_ic].reg.rx_data[4] + (ic[curr_ic].reg.rx_data[5] << 8); 00419 } 00420 } 00421 00422 /** 00423 ******************************************************************************* 00424 * Function: adBms2950ParseIVbatRegData 00425 * @brief Parse Current and Battery Voltage Register Data. 00426 * 00427 * @details This function Parse the received current and battery voltage register data. 00428 * 00429 * Parameters: 00430 * 00431 * @param [in] tIC Total IC 00432 * 00433 * @param [in] *ic cell_asic ic structure pointer 00434 * 00435 * @param [in] *ivbat_data ivbat data pointer 00436 * 00437 * @return None 00438 * 00439 ******************************************************************************* 00440 */ 00441 void adBms2950ParseIVbatRegData(uint8_t tIC, cell_asic *ic, uint8_t *ivbat_data) 00442 { 00443 uint8_t address = 0; 00444 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00445 { 00446 memcpy(&ic[curr_ic].reg.rx_data[0], &ivbat_data[address], RX_DATA); /* dst , src , size */ 00447 address = ((curr_ic+1) * (RX_DATA)); 00448 ic[curr_ic].ivbat.i1 = ic[curr_ic].reg.rx_data[0] + (ic[curr_ic].reg.rx_data[1] << 8) + (ic[curr_ic].reg.rx_data[2] << 16); 00449 ic[curr_ic].ivbat.vbat1 = ic[curr_ic].reg.rx_data[4] + (ic[curr_ic].reg.rx_data[5] << 8); 00450 } 00451 } 00452 00453 /** 00454 ******************************************************************************* 00455 * Function: adBms2950ParseOcRegData 00456 * @brief Parse Overcurrent Register Data. 00457 * 00458 * @details This function Parse the received overcurrent adc register. 00459 * 00460 * Parameters: 00461 * 00462 * @param [in] tIC Total IC 00463 * 00464 * @param [in] *ic cell_asic ic structure pointer 00465 * 00466 * @param [in] *oc_data Oc data pointer 00467 * 00468 * @return None 00469 * 00470 ******************************************************************************* 00471 */ 00472 void adBms2950ParseOcRegData(uint8_t tIC, cell_asic *ic, uint8_t *oc_data) 00473 { 00474 uint8_t address = 0; 00475 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00476 { 00477 memcpy(&ic[curr_ic].reg.rx_data[0], &oc_data[address], RX_DATA); /* dst , src , size */ 00478 address = ((curr_ic+1) * (RX_DATA)); 00479 ic[curr_ic].oc.oc1r = (ic[curr_ic].reg.rx_data[0]); 00480 ic[curr_ic].oc.oc2r = (ic[curr_ic].reg.rx_data[1]); 00481 } 00482 } 00483 00484 /** 00485 ******************************************************************************* 00486 * Function: adBms2950ParseAvgCurrentRegData 00487 * @brief Parse Average Current Register Data. 00488 * 00489 * @details This function Parse the received average current register data. 00490 * 00491 * Parameters: 00492 * 00493 * @param [in] tIC Total IC 00494 * 00495 * @param [in] *ic cell_asic ic structure pointer 00496 * 00497 * @param [in] *iavg_data Average current data pointer 00498 * 00499 * @return None 00500 * 00501 ******************************************************************************* 00502 */ 00503 void adBms2950ParseAvgCurrentRegData(uint8_t tIC, cell_asic *ic, uint8_t *iavg_data) 00504 { 00505 uint8_t address = 0; 00506 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00507 { 00508 memcpy(&ic[curr_ic].reg.rx_data[0], &iavg_data[address], RX_DATA); /* dst , src , size */ 00509 address = ((curr_ic+1) * (RX_DATA)); 00510 ic[curr_ic].iavg.i1avg = ic[curr_ic].reg.rx_data[0] + (ic[curr_ic].reg.rx_data[1] << 8) + ((ic[curr_ic].reg.rx_data[2]) << 16); 00511 ic[curr_ic].iavg.i2avg = ic[curr_ic].reg.rx_data[3] + (ic[curr_ic].reg.rx_data[4] << 8) + ((ic[curr_ic].reg.rx_data[5]) << 16); 00512 } 00513 } 00514 00515 /** 00516 ******************************************************************************* 00517 * Function: adBms2950ParseAvgVbatRegData 00518 * @brief Parse Average Batter Voltage Register Data. 00519 * 00520 * @details This function Parse the received average batter voltage register data. 00521 * 00522 * Parameters: 00523 * 00524 * @param [in] tIC Total IC 00525 * 00526 * @param [in] *ic cell_asic ic structure pointer 00527 * 00528 * @param [in] *avgvbat_data avgvbat data pointer 00529 * 00530 * @return None 00531 * 00532 ******************************************************************************* 00533 */ 00534 void adBms2950ParseAvgVbatRegData(uint8_t tIC, cell_asic *ic, uint8_t *avgvbat_data) 00535 { 00536 uint8_t address = 0; 00537 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00538 { 00539 memcpy(&ic[curr_ic].reg.rx_data[0], &avgvbat_data[address], RX_DATA); /* dst , src , size */ 00540 address = ((curr_ic+1) * (RX_DATA)); 00541 ic[curr_ic].vbavg.vb1avg = ic[curr_ic].reg.rx_data[0] + (ic[curr_ic].reg.rx_data[1] << 8) + (ic[curr_ic].reg.rx_data[2] << 16); 00542 ic[curr_ic].vbavg.vb2avg = ic[curr_ic].reg.rx_data[3] + (ic[curr_ic].reg.rx_data[4] << 8) + (ic[curr_ic].reg.rx_data[5] << 16); 00543 } 00544 } 00545 00546 /** 00547 ******************************************************************************* 00548 * Function: adBms2950ParseAvgIVbatRegData 00549 * @brief Parse Average Current and Battery Voltage Register Data. 00550 * 00551 * @details This function Parse the received average current and battery voltage register data. 00552 * 00553 * Parameters: 00554 * 00555 * @param [in] tIC Total IC 00556 * 00557 * @param [in] *ic cell_asic ic structure pointer 00558 * 00559 * @param [in] *avgivbat_data avgivbat data pointer 00560 * 00561 * @return None 00562 * 00563 ******************************************************************************* 00564 */ 00565 void adBms2950ParseAvgIVbatRegData(uint8_t tIC, cell_asic *ic, uint8_t *avgivbat_data) 00566 { 00567 uint8_t address = 0; 00568 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00569 { 00570 memcpy(&ic[curr_ic].reg.rx_data[0], &avgivbat_data[address], RX_DATA); /* dst , src , size */ 00571 address = ((curr_ic+1) * (RX_DATA)); 00572 ic[curr_ic].i_vbavg.i1avg = ic[curr_ic].reg.rx_data[0] + (ic[curr_ic].reg.rx_data[1] << 8) + (ic[curr_ic].reg.rx_data[2] << 16); 00573 ic[curr_ic].i_vbavg.vb1avg = ic[curr_ic].reg.rx_data[3] + (ic[curr_ic].reg.rx_data[4] << 8) + (ic[curr_ic].reg.rx_data[5] << 16); 00574 } 00575 } 00576 00577 /** 00578 ******************************************************************************* 00579 * Function: adBms2950VrParseData 00580 * @brief Parse Voltage Register Data. 00581 * 00582 * @details This function Parse the received voltage register data. 00583 * 00584 * Parameters: 00585 * 00586 * @param [in] tIC Total IC 00587 * 00588 * @param [in] *ic cell_asic ic structure pointer 00589 * 00590 * @param [in] grp Enum type register group 00591 * 00592 * @param [in] *vr_data Volatge reg. data pointer 00593 * 00594 * @return None 00595 * 00596 ******************************************************************************* 00597 */ 00598 void adBms2950VrParseData(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *vr_data) 00599 { 00600 uint8_t *data, data_size, address = 0; 00601 if(grp == ALL_GRP){data_size = ALLVR_SIZE;} 00602 else {data_size = RX_DATA;} 00603 data = (uint8_t *)calloc(data_size, sizeof(uint8_t)); 00604 if(data == NULL) 00605 { 00606 printMsg("Failed to allocate parse vr memory"); 00607 exit(0); 00608 } 00609 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00610 { 00611 memcpy(&data[0], &vr_data[address], data_size); /* dst , src , size */ 00612 address = ((curr_ic+1) * (data_size)); 00613 switch (grp) 00614 { 00615 case A: /* VR Register group A */ 00616 ic[curr_ic].vr.v_codes[0] = (data[0] + (data[1] << 8)); 00617 ic[curr_ic].vr.v_codes[1] = (data[2] + (data[3] << 8)); 00618 ic[curr_ic].vr.v_codes[2] = (data[4] + (data[5] << 8)); 00619 break; 00620 00621 case B: /* VR Register group B */ 00622 ic[curr_ic].vr.v_codes[3] = (data[0] + (data[1] << 8)); 00623 ic[curr_ic].vr.v_codes[4] = (data[2] + (data[3] << 8)); 00624 ic[curr_ic].vr.v_codes[5] = (data[4] + (data[5] << 8)); 00625 break; 00626 00627 case C: /* VR Register group C */ 00628 ic[curr_ic].vr.v_codes[6] = (data[0] + (data[1] << 8)); 00629 ic[curr_ic].vr.v_codes[7] = (data[2] + (data[3] << 8)); 00630 ic[curr_ic].vr.v_codes[8] = (data[4] + (data[5] << 8)); 00631 break; 00632 00633 case D: /* VR Register group D */ 00634 ic[curr_ic].vr.v_codes[9] = (data[0] + (data[1] << 8)); 00635 ic[curr_ic].vr.v_codes[10] = (data[2] + (data[3] << 8)); 00636 ic[curr_ic].vr.v_codes[11] = (data[4] + (data[5] << 8)); 00637 break; 00638 00639 case ALL_GRP: /* VR Register group ALL */ 00640 ic[curr_ic].vr.v_codes[0] = (data[0] + (data[1] << 8)); 00641 ic[curr_ic].vr.v_codes[1] = (data[2] + (data[3] << 8)); 00642 ic[curr_ic].vr.v_codes[2] = (data[4] + (data[5] << 8)); 00643 ic[curr_ic].vr.v_codes[3] = (data[6] + (data[7] << 8)); 00644 ic[curr_ic].vr.v_codes[4] = (data[8] + (data[9] << 8)); 00645 ic[curr_ic].vr.v_codes[5] = (data[10] + (data[11] << 8)); 00646 ic[curr_ic].vr.v_codes[6] = (data[12] + (data[13] << 8)); 00647 ic[curr_ic].vr.v_codes[7] = (data[14] + (data[15] << 8)); 00648 ic[curr_ic].vr.v_codes[8] = (data[16] + (data[17] << 8)); 00649 ic[curr_ic].vr.v_codes[9] = (data[18] + (data[19] << 8)); 00650 ic[curr_ic].vr.v_codes[10] = (data[20] + (data[21] << 8)); 00651 ic[curr_ic].vr.v_codes[11] = (data[22] + (data[23] << 8)); 00652 break; 00653 00654 default: 00655 break; 00656 } 00657 } 00658 free(data); 00659 } 00660 00661 /** 00662 ******************************************************************************* 00663 * Function: adBms2950VrxParseData 00664 * @brief Parse Voltage Register X Data. 00665 * 00666 * @details This function Parse the received voltage register x data. 00667 * 00668 * Parameters: 00669 * 00670 * @param [in] tIC Total IC 00671 * 00672 * @param [in] *ic cell_asic ic structure pointer 00673 * 00674 * @param [in] grp Enum type register group 00675 * 00676 * @param [in] *vrx_data Volatge reg. data pointer 00677 * 00678 * @return None 00679 * 00680 ******************************************************************************* 00681 */ 00682 void adBms2950VrxParseData(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *vrx_data) 00683 { 00684 uint8_t *data, data_size, address = 0; 00685 if(grp == ALL_GRP){} 00686 else {data_size = RX_DATA;} 00687 data = (uint8_t *)calloc(data_size, sizeof(uint8_t)); 00688 if(data == NULL) 00689 { 00690 printMsg("Failed to allocate parse vrx memory"); 00691 exit(0); 00692 } 00693 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00694 { 00695 memcpy(&data[0], &vrx_data[address], data_size); /* dst , src , size */ 00696 address = ((curr_ic+1) * (data_size)); 00697 switch (grp) 00698 { 00699 case X: /* VRX Register group X */ 00700 ic[curr_ic].vrx.vx_codes[0] = (data[0] + (data[1] << 8)); 00701 ic[curr_ic].vrx.vx_codes[1] = (data[2] + (data[3] << 8)); 00702 ic[curr_ic].vrx.vx_codes[2] = (data[4] + (data[5] << 8)); 00703 break; 00704 00705 case Y: /* VRX Register group Y */ 00706 ic[curr_ic].vrx.vx_codes[3] = (data[0] + (data[1] << 8)); 00707 ic[curr_ic].vrx.vx_codes[4] = (data[2] + (data[3] << 8)); 00708 ic[curr_ic].vrx.vx_codes[5] = (data[4] + (data[5] << 8)); 00709 break; 00710 00711 case Z: /* VRX Register group Z */ 00712 ic[curr_ic].vrx.vx_codes[3] = (data[0] + (data[1] << 8)); 00713 break; 00714 00715 case ALL_GRP: /* VRX Register group ALL */ 00716 ic[curr_ic].vrx.vx_codes[0] = (data[0] + (data[1] << 8)); 00717 ic[curr_ic].vrx.vx_codes[1] = (data[2] + (data[3] << 8)); 00718 ic[curr_ic].vrx.vx_codes[2] = (data[4] + (data[5] << 8)); 00719 ic[curr_ic].vrx.vx_codes[3] = (data[6] + (data[7] << 8)); 00720 ic[curr_ic].vrx.vx_codes[4] = (data[8] + (data[9] << 8)); 00721 ic[curr_ic].vrx.vx_codes[5] = (data[10] + (data[11] << 8)); 00722 break; 00723 00724 default: 00725 break; 00726 } 00727 } 00728 free(data); 00729 } 00730 00731 /** 00732 ******************************************************************************* 00733 * Function: adBms2950RedVrParseData 00734 * @brief Parse Redundant Voltage Register Data. 00735 * 00736 * @details This function Parse the received Redundant voltage register data. 00737 * 00738 * Parameters: 00739 * 00740 * @param [in] tIC Total IC 00741 * 00742 * @param [in] *ic cell_asic ic structure pointer 00743 * 00744 * @param [in] grp Enum type register group 00745 * 00746 * @param [in] *redvr_data Redundant volatge reg. data pointer 00747 * 00748 * @return None 00749 * 00750 ******************************************************************************* 00751 */ 00752 void adBms2950RedVrParseData(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *redvr_data) 00753 { 00754 uint8_t *data, data_size, address = 0; 00755 if(grp == ALL_GRP){data_size = ALLREDVR_SIZE;} 00756 else {data_size = RX_DATA;} 00757 data = (uint8_t *)calloc(data_size, sizeof(uint8_t)); 00758 if(data == NULL) 00759 { 00760 printMsg("Failed to allocate parse redvr memory"); 00761 exit(0); 00762 } 00763 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00764 { 00765 memcpy(&data[0], &redvr_data[address], data_size); /* dst , src , size */ 00766 address = ((curr_ic+1) * (data_size)); 00767 switch (grp) 00768 { 00769 case A: /* RedVR Register group A */ 00770 ic[curr_ic].rvr.redv_codes[0] = (data[0] + (data[1] << 8)); 00771 ic[curr_ic].rvr.redv_codes[1] = (data[2] + (data[3] << 8)); 00772 ic[curr_ic].rvr.redv_codes[2] = (data[4] + (data[5] << 8)); 00773 break; 00774 00775 case B: /* RedVR Register group B */ 00776 ic[curr_ic].rvr.redv_codes[3] = (data[0] + (data[1] << 8)); 00777 ic[curr_ic].rvr.redv_codes[4] = (data[2] + (data[3] << 8)); 00778 ic[curr_ic].rvr.redv_codes[5] = (data[4] + (data[5] << 8)); 00779 break; 00780 00781 case ALL_GRP: /* RedVR Register group ALL */ 00782 ic[curr_ic].rvr.redv_codes[0] = (data[0] + (data[1] << 8)); 00783 ic[curr_ic].rvr.redv_codes[1] = (data[2] + (data[3] << 8)); 00784 ic[curr_ic].rvr.redv_codes[2] = (data[4] + (data[5] << 8)); 00785 ic[curr_ic].rvr.redv_codes[3] = (data[6] + (data[7] << 8)); 00786 ic[curr_ic].rvr.redv_codes[4] = (data[8] + (data[9] << 8)); 00787 ic[curr_ic].rvr.redv_codes[5] = (data[10] + (data[11] << 8)); 00788 break; 00789 00790 default: 00791 break; 00792 } 00793 } 00794 free(data); 00795 } 00796 00797 /** 00798 ******************************************************************************* 00799 * Function: adBms2950ParseStatusA 00800 * @brief Parse status A register data 00801 * 00802 * @details This function Parse the recived status A register data. 00803 * 00804 * Parameters: 00805 * 00806 * @param [in] tIC Total IC 00807 * 00808 * @param [in] *ic cell_asic ic structure pointer 00809 * 00810 * @param [in] *data data pointer 00811 * 00812 * @return None 00813 * 00814 ******************************************************************************* 00815 */ 00816 void adBms2950ParseStatusA(uint8_t tIC, cell_asic *ic, uint8_t *data) 00817 { 00818 uint8_t address = 0; 00819 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00820 { 00821 memcpy(&ic[curr_ic].sta.rx_data[0], &data[address], RX_DATA); /* dst , src , size */ 00822 address = ((curr_ic+1) * (RX_DATA)); 00823 ic[curr_ic].stata.vref1p25 = (ic[curr_ic].sta.rx_data[0] | (ic[curr_ic].sta.rx_data[1] << 8)); 00824 ic[curr_ic].stata.itmp = (ic[curr_ic].sta.rx_data[2] | (ic[curr_ic].sta.rx_data[3] << 8)); 00825 ic[curr_ic].stata.vreg2 = (ic[curr_ic].sta.rx_data[4] | (ic[curr_ic].sta.rx_data[5] << 8)); 00826 } 00827 } 00828 00829 /** 00830 ******************************************************************************* 00831 * Function: adBms2950ParseStatusB 00832 * @brief Parse status B register data 00833 * 00834 * @details This function Parse the recived status B register data. 00835 * 00836 * Parameters: 00837 * 00838 * @param [in] tIC Total IC 00839 * 00840 * @param [in] *ic cell_asic ic structure pointer 00841 * 00842 * @param [in] *data data pointer 00843 * 00844 * @return None 00845 * 00846 ******************************************************************************* 00847 */ 00848 void adBms2950ParseStatusB(uint8_t tIC, cell_asic *ic, uint8_t *data) 00849 { 00850 uint8_t address = 0; 00851 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00852 { 00853 memcpy(&ic[curr_ic].stb.rx_data[0], &data[address], RX_DATA); /* dst , src , size */ 00854 address = ((curr_ic+1) * (RX_DATA)); 00855 ic[curr_ic].statb.oc1min = ic[curr_ic].stb.rx_data[0]; 00856 ic[curr_ic].statb.oc1max = ic[curr_ic].stb.rx_data[1]; 00857 ic[curr_ic].statb.oc2min = ic[curr_ic].stb.rx_data[2]; 00858 ic[curr_ic].statb.oc2max = ic[curr_ic].stb.rx_data[3]; 00859 } 00860 } 00861 00862 /** 00863 ******************************************************************************* 00864 * Function: adBms2950ParseStatusC 00865 * @brief Parse status C register data 00866 * 00867 * @details This function Parse the recived status C register data. 00868 * 00869 * Parameters: 00870 * 00871 * @param [in] tIC Total IC 00872 * 00873 * @param [in] *ic cell_asic ic structure pointer 00874 * 00875 * @param [in] *data data pointer 00876 * 00877 * @return None 00878 * 00879 ******************************************************************************* 00880 */ 00881 void adBms2950ParseStatusC(uint8_t tIC, cell_asic *ic, uint8_t *data) 00882 { 00883 uint8_t address = 0; 00884 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00885 { 00886 memcpy(&ic[curr_ic].stc.rx_data[0], &data[address], RX_DATA); /* dst , src , size */ 00887 address = ((curr_ic+1) * (RX_DATA)); 00888 /* OCA bits */ 00889 ic[curr_ic].statc.oc1a = (ic[curr_ic].stc.rx_data[0] & 0x01); 00890 ic[curr_ic].statc.oc1a_inv = ((ic[curr_ic].stc.rx_data[0] & 0x02) >> 1); 00891 ic[curr_ic].statc.oc2a = (ic[curr_ic].stc.rx_data[1] & 0x01); 00892 ic[curr_ic].statc.oc2a_inv = ((ic[curr_ic].stc.rx_data[1] & 0x02) >> 1); 00893 /* ct and cts */ 00894 ic[curr_ic].statc.ct = (((ic[curr_ic].stc.rx_data[2] & 0x1F) << 6) | ((ic[curr_ic].stc.rx_data[3] & 0xFC) >> 2)); 00895 ic[curr_ic].statc.cts = (ic[curr_ic].stc.rx_data[3] & 0x03); 00896 /* flag bits */ 00897 ic[curr_ic].statc.otp2_med = (ic[curr_ic].stc.rx_data[4] & 0x01); 00898 ic[curr_ic].statc.otp2_ed = ((ic[curr_ic].stc.rx_data[4] & 0x02) >> 1); 00899 ic[curr_ic].statc.otp1_med = ((ic[curr_ic].stc.rx_data[4] & 0x04) >> 2); 00900 ic[curr_ic].statc.otp1_ed = ((ic[curr_ic].stc.rx_data[4] & 0x08) >> 3); 00901 ic[curr_ic].statc.vd_uv = ((ic[curr_ic].stc.rx_data[4] & 0x10) >> 4); 00902 ic[curr_ic].statc.vd_ov = ((ic[curr_ic].stc.rx_data[4] & 0x20) >> 5); 00903 ic[curr_ic].statc.va_uv = ((ic[curr_ic].stc.rx_data[4] & 0x40) >> 6); 00904 ic[curr_ic].statc.va_ov = ((ic[curr_ic].stc.rx_data[4] & 0x80) >> 7); 00905 ic[curr_ic].statc.oscchk = (ic[curr_ic].stc.rx_data[5] & 0x01); 00906 ic[curr_ic].statc.tmodchk = ((ic[curr_ic].stc.rx_data[5] & 0x02) >> 1); 00907 ic[curr_ic].statc.thsd = ((ic[curr_ic].stc.rx_data[5] & 0x04) >> 2); 00908 ic[curr_ic].statc.sleep = ((ic[curr_ic].stc.rx_data[5] & 0x08) >> 3); 00909 ic[curr_ic].statc.spiflt = ((ic[curr_ic].stc.rx_data[5] & 0x10) >> 4); 00910 ic[curr_ic].statc.insync = ((ic[curr_ic].stc.rx_data[5] & 0x20) >> 5); 00911 ic[curr_ic].statc.vdel = ((ic[curr_ic].stc.rx_data[5] & 0x40) >> 6); 00912 ic[curr_ic].statc.vde = ((ic[curr_ic].stc.rx_data[5] & 0x80) >> 7); 00913 } 00914 } 00915 00916 /** 00917 ******************************************************************************* 00918 * Function: adBms2950ParseStatusD 00919 * @brief Parse status D register data 00920 * 00921 * @details This function Parse the recived status D register data. 00922 * 00923 * Parameters: 00924 * 00925 * @param [in] tIC Total IC 00926 * 00927 * @param [in] *ic cell_asic ic structure pointer 00928 * 00929 * @param [in] *data data pointer 00930 * 00931 * @return None 00932 * 00933 ******************************************************************************* 00934 */ 00935 void adBms2950ParseStatusD(uint8_t tIC, cell_asic *ic, uint8_t *data) 00936 { 00937 uint8_t address = 0; 00938 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00939 { 00940 memcpy(&ic[curr_ic].std.rx_data[0], &data[address], RX_DATA); /* dst , src , size */ 00941 address = ((curr_ic+1) * (RX_DATA)); 00942 /* oc_cntr */ 00943 ic[curr_ic].statd.oc_cntr = (ic[curr_ic].std.rx_data[5]); 00944 } 00945 } 00946 00947 /** 00948 ******************************************************************************* 00949 * Function: adBms2950ParseStatusE 00950 * @brief Parse status E register data 00951 * 00952 * @details This function Parse the recived status E register data. 00953 * 00954 * Parameters: 00955 * 00956 * @param [in] tIC Total IC 00957 * 00958 * @param [in] *ic cell_asic ic structure pointer 00959 * 00960 * @param [in] *data data pointer 00961 * 00962 * @return None 00963 * 00964 ******************************************************************************* 00965 */ 00966 void adBms2950ParseStatusE(uint8_t tIC, cell_asic *ic, uint8_t *data) 00967 { 00968 uint8_t address = 0; 00969 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 00970 { 00971 memcpy(&ic[curr_ic].ste.rx_data[0], &data[address], RX_DATA); /* dst , src , size */ 00972 address = ((curr_ic+1) * (RX_DATA)); 00973 ic[curr_ic].state.gpio = ((ic[curr_ic].ste.rx_data[4] & 0x1E)); 00974 ic[curr_ic].state.gpo = ((ic[curr_ic].ste.rx_data[5] & 0x03) << 4 | ((ic[curr_ic].ste.rx_data[4] & 0xE0) >> 4) | (ic[curr_ic].ste.rx_data[4] & 0x01)); 00975 ic[curr_ic].state.rev = ((ic[curr_ic].ste.rx_data[5] & 0xF0) >> 4); 00976 } 00977 } 00978 00979 /** 00980 ******************************************************************************* 00981 * Function: adBms2950ParseStatus 00982 * @brief Parse status register data 00983 * 00984 * @details This function Parse the recived status register data. 00985 * 00986 * Parameters: 00987 * 00988 * @param [in] tIC Total IC 00989 * 00990 * @param [in] *ic cell_asic ic structure pointer 00991 * 00992 * @param [in] *data data pointer 00993 * 00994 * @return None 00995 * 00996 ******************************************************************************* 00997 */ 00998 void adBms2950ParseStatus(uint8_t tIC, cell_asic *ic, GRP grp, uint8_t *data) 00999 { 01000 switch (grp) 01001 { 01002 case A: /* Status Register group A */ 01003 adBms2950ParseStatusA(tIC, &ic[0], &data[0]); 01004 break; 01005 01006 case B: /* Status Register group B */ 01007 adBms2950ParseStatusB(tIC, &ic[0], &data[0]); 01008 break; 01009 01010 case C: /* Status Register group C */ 01011 adBms2950ParseStatusC(tIC, &ic[0], &data[0]); 01012 break; 01013 01014 case D: /* Status Register group D */ 01015 adBms2950ParseStatusD(tIC, &ic[0], &data[0]); 01016 break; 01017 01018 case E: /* Status Register group E */ 01019 adBms2950ParseStatusE(tIC, &ic[0], &data[0]); 01020 break; 01021 01022 case ALL_GRP: /* Status Register group ALL */ 01023 // TBD 01024 break; 01025 01026 default: 01027 break; 01028 } 01029 } 01030 01031 /** 01032 ******************************************************************************* 01033 * Function: adBms2950ParseComm 01034 * @brief Parse comm register 01035 * 01036 * @details This function Parse the recived comm register data. 01037 * 01038 * Parameters: 01039 * 01040 * @param [in] tIC Total IC 01041 * 01042 * @param [in] *ic cell_asic ic structure pointer 01043 * 01044 * @param [in] *data data pointer 01045 * 01046 * @return None 01047 * 01048 ******************************************************************************* 01049 */ 01050 void adBms2950ParseComm(uint8_t tIC, cell_asic *ic, uint8_t *data) 01051 { 01052 uint8_t address = 0; 01053 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 01054 { 01055 memcpy(&ic[curr_ic].com.rx_data[0], &data[address], RX_DATA); /* dst , src , size */ 01056 address = ((curr_ic+1) * (RX_DATA)); 01057 ic[curr_ic].rx_comm.icomm[0] = ((ic[curr_ic].com.rx_data[0] & 0xF0) >> 4); 01058 ic[curr_ic].rx_comm.fcomm[0] = (ic[curr_ic].com.rx_data[0] & 0x0F); 01059 ic[curr_ic].rx_comm.data[0] = (ic[curr_ic].com.rx_data[1]); 01060 ic[curr_ic].rx_comm.icomm[1] = ((ic[curr_ic].com.rx_data[2] & 0xF0) >> 4); 01061 ic[curr_ic].rx_comm.data[1] = (ic[curr_ic].com.rx_data[3]); 01062 ic[curr_ic].rx_comm.fcomm[1] = (ic[curr_ic].com.rx_data[2] & 0x0F); 01063 ic[curr_ic].rx_comm.icomm[2] = ((ic[curr_ic].com.rx_data[4] & 0xF0) >> 4); 01064 ic[curr_ic].rx_comm.data[2] = (ic[curr_ic].com.rx_data[5]); 01065 ic[curr_ic].rx_comm.fcomm[2] = (ic[curr_ic].com.rx_data[4] & 0x0F); 01066 } 01067 } 01068 01069 /** 01070 ******************************************************************************* 01071 * Function: adBms2950ParseSID 01072 * @brief Parse SID register 01073 * 01074 * @details This function Parse the recived sid register data. 01075 * 01076 * Parameters: 01077 * 01078 * @param [in] tIC Total IC 01079 * 01080 * @param [in] *ic cell_asic ic structure pointer 01081 * 01082 * @param [in] *data data pointer 01083 * 01084 * @return None 01085 * 01086 ******************************************************************************* 01087 */ 01088 void adBms2950ParseSID(uint8_t tIC, cell_asic *ic, uint8_t *data) 01089 { 01090 uint8_t address = 0; 01091 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 01092 { 01093 memcpy(&ic[curr_ic].rsid.rx_data[0], &data[address], RX_DATA); /* dst , src , size */ 01094 address = ((curr_ic+1) * (RX_DATA)); 01095 ic[curr_ic].sid.sid[0] = ic[curr_ic].rsid.rx_data[0]; 01096 ic[curr_ic].sid.sid[1] = ic[curr_ic].rsid.rx_data[1]; 01097 ic[curr_ic].sid.sid[2] = ic[curr_ic].rsid.rx_data[2]; 01098 ic[curr_ic].sid.sid[3] = ic[curr_ic].rsid.rx_data[3]; 01099 ic[curr_ic].sid.sid[4] = ic[curr_ic].rsid.rx_data[4]; 01100 ic[curr_ic].sid.sid[5] = ic[curr_ic].rsid.rx_data[5]; 01101 } 01102 } 01103 01104 /** 01105 ******************************************************************************* 01106 * Function: adBms2950CreateConfiga 01107 * @brief Create the configation A write buffer 01108 * 01109 * @details This function create the configation A write buffer. 01110 * 01111 * Parameters: 01112 * 01113 * @param [in] tIC Total IC 01114 * 01115 * @param [in] *ic cell_asic ic structure pointer 01116 * 01117 * @return None 01118 * 01119 ******************************************************************************* 01120 */ 01121 void adBms2950CreateConfiga(uint8_t tIC, cell_asic *ic) 01122 { 01123 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 01124 { 01125 ic[curr_ic].configa.tx_data[0] = (((ic[curr_ic].tx_cfga.refon & 0x01) << 7) | ((ic[curr_ic].tx_cfga.vs1 & 0x03) << 1) |(ic[curr_ic].tx_cfga.vs10)); 01126 ic[curr_ic].configa.tx_data[1] = (ic[curr_ic].tx_cfga.flag_d & 0xFF); 01127 ic[curr_ic].configa.tx_data[2] = (((ic[curr_ic].tx_cfga.vs7 & 0x01) << 7) | ((ic[curr_ic].tx_cfga.vs6 & 0x01) << 6) | ((ic[curr_ic].tx_cfga.soak & 0x07) << 3)); 01128 ic[curr_ic].configa.tx_data[3] = (((ic[curr_ic].tx_cfga.gpo & 0x0E) << 4) | ((ic[curr_ic].tx_cfga.gpio & 0x0F) << 1) | (ic[curr_ic].tx_cfga.gpo & 0x01)); /* GPO1 is at position 0 */ 01129 ic[curr_ic].configa.tx_data[4] = ((ic[curr_ic].tx_cfga.gpo & 0x30) >> 4); 01130 ic[curr_ic].configa.tx_data[5] = (((ic[curr_ic].tx_cfga.snap_st & 0x01) << 5) | ((ic[curr_ic].tx_cfga.comm_bk & 0x01) << 3) | ((ic[curr_ic].tx_cfga.vs5 & 0x01) << 2) | ((ic[curr_ic].tx_cfga.vs4 & 0x01) << 1) | (ic[curr_ic].tx_cfga.vs3 & 0x01)); 01131 } 01132 } 01133 01134 /** 01135 ******************************************************************************* 01136 * Function: adBms2950CreateConfigb 01137 * @brief Create the configation B write buffer 01138 * 01139 * @details This function create the configation B write buffer. 01140 * 01141 * Parameters: 01142 * 01143 * @param [in] tIC Total IC 01144 * 01145 * @param [in] *ic cell_asic ic structure pointer 01146 * 01147 * @return None 01148 * 01149 ******************************************************************************* 01150 */ 01151 void adBms2950CreateConfigb(uint8_t tIC, cell_asic *ic) 01152 { 01153 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 01154 { 01155 ic[curr_ic].configb.tx_data[0] = (((ic[curr_ic].tx_cfgb.vs2 & 0x02) << 7) | (ic[curr_ic].tx_cfgb.oc1th & 0x7F)); 01156 ic[curr_ic].configb.tx_data[1] = (((ic[curr_ic].tx_cfgb.vs2 & 0x01) << 7) | (ic[curr_ic].tx_cfgb.oc2th & 0x7F)); 01157 ic[curr_ic].configb.tx_data[2] = (((ic[curr_ic].tx_cfgb.vs9 & 0x01) << 7) | ((ic[curr_ic].tx_cfgb.vs8 & 0x01) << 6)|((ic[curr_ic].tx_cfgb.dg2th & 0x07) << 3) | (ic[curr_ic].tx_cfgb.dg1th & 0x07)); 01158 ic[curr_ic].configb.tx_data[3] = 0x00; 01159 ic[curr_ic].configb.tx_data[4] = 0x00; 01160 ic[curr_ic].configb.tx_data[5] = 0x00; 01161 } 01162 } 01163 01164 /** 01165 ******************************************************************************* 01166 * Function: adBms2950CreateClrflagData 01167 * @brief Create the clear flag write buffer 01168 * 01169 * @details This function create the clear flag write buffer. 01170 * 01171 * Parameters: 01172 * 01173 * @param [in] tIC Total IC 01174 * 01175 * @param [in] *ic cell_asic ic structure pointer 01176 * 01177 * @return None 01178 * 01179 ******************************************************************************* 01180 */ 01181 void adBms2950CreateClrflagData(uint8_t tIC, cell_asic *ic) 01182 { 01183 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 01184 { 01185 ic[curr_ic].clrflag.tx_data[0] = (((ic[curr_ic].clflag.cl_oc1m & 0x01) << 1) | (ic[curr_ic].clflag.cl_oc1a & 0x01)); 01186 ic[curr_ic].clrflag.tx_data[1] = (((ic[curr_ic].clflag.cl_oc2m & 0x01) << 1) | (ic[curr_ic].clflag.cl_oc2a & 0x01)); 01187 ic[curr_ic].clrflag.tx_data[2] = 0x00; 01188 ic[curr_ic].clrflag.tx_data[3] = 0x00; 01189 ic[curr_ic].clrflag.tx_data[4] = ((ic[curr_ic].clflag.cl_vaov << 7) | (ic[curr_ic].clflag.cl_vauv << 6) | (ic[curr_ic].clflag.cl_vdov << 5) | (ic[curr_ic].clflag.cl_vduv << 4) 01190 |(ic[curr_ic].clflag.cl_opt1_ed << 3)| (ic[curr_ic].clflag.cl_opt1_med << 2) | (ic[curr_ic].clflag.cl_opt2_ed << 1) | (ic[curr_ic].clflag.cl_opt2_med)); 01191 ic[curr_ic].clrflag.tx_data[5] = ((ic[curr_ic].clflag.cl_vde << 7) | (ic[curr_ic].clflag.cl_vdel << 6) | (ic[curr_ic].clflag.cl_spiflt << 4) |(ic[curr_ic].clflag.cl_sleep << 3) 01192 | (ic[curr_ic].clflag.cl_thsd << 2) | (ic[curr_ic].clflag.cl_tmode << 1) | (ic[curr_ic].clflag.cl_oscchk)); 01193 } 01194 } 01195 01196 /** 01197 ******************************************************************************* 01198 * Function: adBms2950CreateComm 01199 * @brief Create the configation comm write buffer 01200 * 01201 * @details This function create the configation comm write buffer. 01202 * 01203 * Parameters: 01204 * 01205 * @param [in] tIC Total IC 01206 * 01207 * @param [in] *ic cell_asic ic structure pointer 01208 * 01209 * @return None 01210 * 01211 ******************************************************************************* 01212 */ 01213 void adBms2950CreateComm(uint8_t tIC, cell_asic *ic) 01214 { 01215 for(uint8_t curr_ic = 0; curr_ic < tIC; curr_ic++) 01216 { 01217 ic[curr_ic].com.tx_data[0] = ((ic[curr_ic].tx_comm.icomm[0] & 0x0F) << 4 | (ic[curr_ic].tx_comm.fcomm[0] & 0x0F)); 01218 ic[curr_ic].com.tx_data[1] = ((ic[curr_ic].tx_comm.data[0] )); 01219 ic[curr_ic].com.tx_data[2] = ((ic[curr_ic].tx_comm.icomm[1] & 0x0F) << 4 ) | (ic[curr_ic].tx_comm.fcomm[1] & 0x0F); 01220 ic[curr_ic].com.tx_data[3] = ((ic[curr_ic].tx_comm.data[1])); 01221 ic[curr_ic].com.tx_data[4] = ((ic[curr_ic].tx_comm.icomm[2] & 0x0F) << 4 | (ic[curr_ic].tx_comm.fcomm[2] & 0x0F)); 01222 ic[curr_ic].com.tx_data[5] = ((ic[curr_ic].tx_comm.data[2])); 01223 } 01224 } 01225 01226 /** @}*/ 01227 /** @}*/
Generated on Thu Oct 13 2022 07:45:26 by
