BOOL CChangeRegisters::nCalculateRegValues ( struct sCOLUMNS* psColListCtrl, WORD wNbt,WORD wBrp,UINT* puwIndex, INT nSample ) { WORD wSJW = 0; WORD wTSEG1 = 0; WORD wTSEG2 = 0; WORD wTSEG2min = 0; WORD wTSEG2max = 0; WORD wSampling = 0; INT k = 0; for(INT i=0; i<defMAX_SJW; i++) { wSJW = (BYTE)(i+1); k = 0; // Calculate Maximum and Minimum value of TSEG2. wTSEG2max = (BYTE)(defmcMIN2(defMAX_TSEG2,wNbt - defMIN_TSEG1 - 1)); wTSEG2min = (BYTE)(defmcMAX3(defMIN_TSEG2,wSJW,wNbt - defMAX_TSEG1 - 1)); for (INT j = wTSEG2min; j<wTSEG2max+1; j++) { wTSEG2 = (BYTE)(j); k++; //Calculate Sampling = ((NBT-TSEG2)/NBT) *100 wSampling = (BYTE)( ( (FLOAT)( wNbt - wTSEG2) / wNbt)*100 ); // Only if sampling is greater then 50%, the value is stored in list. if(wSampling >=defMIN_SAMPLING) { // Calculate TSEG1 = NBT-TSEG2-1 wTSEG1 = (BYTE)(wNbt - wTSEG2 - 1 ); *puwIndex +=1; //Fill the structure with BRP, Sampling, NBT,SJW values for display psColListCtrl[*puwIndex-1].sBRPNBTSampNSJW.usBRP = wBrp ; psColListCtrl[*puwIndex-1].sBRPNBTSampNSJW.usSampling = wSampling ; psColListCtrl[*puwIndex-1].sBRPNBTSampNSJW.usNBT = wNbt ; psColListCtrl[*puwIndex-1].sBRPNBTSampNSJW.usSJW = wSJW ; //Pack the register BTR0 its bit BRPbit = BRP -1; SJWbit = SJW -1; psColListCtrl[*puwIndex-1].uBTRReg0.sBTR0Bit.ucBRPbit = wBrp - 1 ; psColListCtrl[*puwIndex-1].uBTRReg0.sBTR0Bit.ucSJWbit = wSJW - 1 ; //Pack the register BTR1 its bit TESG1bit=TSEG1-1;TSEG2bit=TSEG2 -1; psColListCtrl[*puwIndex-1].uBTRReg1.sBTR1Bit.ucTSEG1bit= wTSEG1 - 1; psColListCtrl[*puwIndex-1].uBTRReg1.sBTR1Bit.ucTSEG2bit= wTSEG2 - 1; //Pack the register BTR1 its bit SAMbit=1 or 0 if(nSample == 3) { psColListCtrl[*puwIndex-1].uBTRReg1.sBTR1Bit.ucSAMbit = 1; } else { psColListCtrl[*puwIndex-1].uBTRReg1.sBTR1Bit.ucSAMbit = 0; } } } } return 1; }
bool CChangeRegisters_ES581::bCalculateES581RegValues(WORD wNbt, WORD wBrp, UINT *puwIndex, INT nSample) { bool bContinue = (defREG_VALUE_LIST_COUNT_MAX > *puwIndex); WORD wMinPropDelay = defPropDelayES581; WORD wMaxPropDelay = defmcMIN2(defMAXPropDelay, (wNbt - defMIN_TSEG1_ES581 - defMIN_TSEG2 - 1)); for (INT i = wMinPropDelay; (i <= wMaxPropDelay) && bContinue; i++) { sBRP_NBT_SAMP_n_SJW CurrEntry; CurrEntry.usBRP = wBrp; CurrEntry.usNBT = wNbt; CurrEntry.usPropDelay = (USHORT)i; CurrEntry.usSample = (USHORT)nSample; bContinue = bCalculateES581Params(CurrEntry, *puwIndex, SJW_TS1_TS2); } return bContinue; }
bool CChangeRegisters_ES581::bCalculateES581Params(sBRP_NBT_SAMP_n_SJW& CurEntry, UINT& unCurrIndex, BYTE bOption) { bool bContinue = true; switch (bOption) { case TS1_TS2: { WORD wNbt = CurEntry.usNBT; WORD wBrp = CurEntry.usBRP; INT nSample = CurEntry.usSample; WORD wSJW = CurEntry.usSJW; WORD wPropDelay = CurEntry.usPropDelay; WORD wTSEG1 = 0; WORD wTSEG2 = 0; WORD wTSEG2min = 0; WORD wTSEG2max = 0; WORD wSampling = 0; bContinue = (defREG_VALUE_LIST_COUNT_MAX > unCurrIndex); wTSEG2max = (BYTE)(defmcMIN2(defMAX_TSEG2, wNbt - defMIN_TSEG1_ES581 - 1 - wPropDelay)); wTSEG2min = (BYTE)(defmcMAX3(defMIN_TSEG2, 0, wNbt - defMAX_TSEG1_ES81 - 1 - wPropDelay)); for (INT j = wTSEG2min; (j < wTSEG2max + 1) && bContinue; j++) { wTSEG2 = (BYTE)(j); //Calculate Sampling = ((NBT-TSEG2)/NBT) *100 wSampling = (BYTE)(((FLOAT)(wNbt - wTSEG2) / wNbt)*100); //calculate TSEG1 wTSEG1 = (BYTE)(wNbt - wTSEG2 - 1 - wPropDelay); // Only if sampling is greater then 50%, the value is stored in list. & // having the condition (TSEG1 + PD) > TSEG2 if ((wSampling >= defMIN_SAMPLING) && ((wTSEG1 + wPropDelay) > wTSEG2)) { // First initialize all m_asColListCtrl[unCurrIndex].uCNFReg1.ucCNF1 = 0x0; m_asColListCtrl[unCurrIndex].uCNFReg2.ucCNF2 = 0x0; m_asColListCtrl[unCurrIndex].uCNFReg3.ucCNF3 = 0x0; // Calculate TSEG1 = NBT-TSEG2-1 //Fill the structure with BRP, Sampling, NBT,SJW values for display m_asColListCtrl[unCurrIndex].sBRPNBTSampNSJW.usBRP = wBrp; m_asColListCtrl[unCurrIndex].sBRPNBTSampNSJW.usSampling = wSampling; m_asColListCtrl[unCurrIndex].sBRPNBTSampNSJW.usNBT = wNbt; m_asColListCtrl[unCurrIndex].sBRPNBTSampNSJW.usSJW = wSJW; //Pack the register CNF1 its bit BRPbit = BRP -1; SJWbit = SJW -1; m_asColListCtrl[unCurrIndex].uCNFReg1.sCNF1Bit.ucBRPbit = wBrp - 1; m_asColListCtrl[unCurrIndex].uCNFReg1.sCNF1Bit.ucSJWbit = wSJW - 1; //Pack the register CNF2 its bit TESG1bit=TSEG1-1;TSEG2bit=TSEG2 -1; m_asColListCtrl[unCurrIndex].uCNFReg2.sCNF2Bit.ucFLAGbit = 0x1; m_asColListCtrl[unCurrIndex].uCNFReg2.sCNF2Bit.ucSAMbit = (nSample == 3); m_asColListCtrl[unCurrIndex].uCNFReg2.sCNF2Bit.ucTSEG1bit = wTSEG1 - 1; m_asColListCtrl[unCurrIndex].uCNFReg2.sCNF2Bit.ucPropDelaybit = wPropDelay - 1; //Pack the register CNF3 its bit TESG2bit=TSEG2-1; m_asColListCtrl[unCurrIndex].uCNFReg3.sCNF3Bit.ucTSEG2bit = wTSEG2 - 1; unCurrIndex += 1; bContinue = (defREG_VALUE_LIST_COUNT_MAX > unCurrIndex); } } } break; case PD_TS1_TS2: { WORD wMinPropDelay = defPropDelayES581; WORD wMaxPropDelay = defmcMIN2(defMAXPropDelay, (CurEntry.usNBT - defMIN_TSEG1_ES581 - defMIN_TSEG2 - 1)); for (INT i = wMinPropDelay; (i <= wMaxPropDelay) && bContinue; i++) { CurEntry.usPropDelay = (USHORT)i; bContinue = bCalculateES581Params(CurEntry, unCurrIndex, TS1_TS2); } } break; case SJW_TS1_TS2: { for (INT i = 0; (i < defMAX_SJW) && bContinue; i++) { CurEntry.usSJW = (BYTE)(i + 1); bContinue = bCalculateES581Params(CurEntry, unCurrIndex, TS1_TS2); } } break; default: { bContinue = false; } break; } return bContinue; }