Attribute VB_Name = "modBootOptions" Option Explicit 'Boot option selections storage Public DP5BootFlags As Integer 'DP5 Boot Flags Public BootFlagsSet As Boolean Public Const BootFlagsDefault = &H28 Private SetBits(0 To 31) As Long Public Const MIN_INT As Long = -32768 Public Const MAX_INT As Long = 32767 Public PC5HV As Integer 'PC5 HV Public PC5TECTemp As Integer 'PC5 TEC temperature Public DP5InputOffset As Integer 'DP5 input offset Public DP5uCtrADC As Integer 'DP5 microcontroller ADC/Temperature calibration (TBD) Public DP5SpectrumOffset As Integer 'DP5 spectrum offset Public Enum BootFlags BootFlagsD0 BootFlagsD1 BootFlagsD2 BootFlagsD3 BootFlagsD4 BootFlagsD5 BootFlagsD6 BootFlagsD7 BootFlagsD8 BootFlagsD9 BootFlagsD10 BootFlagsD11 BootFlagsD12 BootFlagsD13 BootFlagsD14 BootFlagsD15 End Enum Public Const FirstBootFlag = BootFlagsD0 Public Const LastBootFlag = BootFlagsD9 Public Function GetBootOptStr(BootOpt As Integer, strOpt As String, str0 As String, str1 As String) As String Dim strMsg As String strMsg = strOpt & vbNewLine If (BootOpt) Then strMsg = strMsg & "----" & str1 & vbNewLine Else strMsg = strMsg & "----" & str0 & vbNewLine End If GetBootOptStr = strMsg End Function Public Function DisplayBootFlags(DP5BootFlags As Integer) As String Dim strMsg As String Dim strBootOpt As String Dim m_bhBootOpt(15) As Integer UpdateDP5BootFlags True, DP5BootFlags, m_bhBootOpt() strMsg = "DP5 boot flags" & vbNewLine strBootOpt = GetBootOptStr(m_bhBootOpt(BootFlagsD7), "Boot device mode", "PX4", "DP4") strMsg = strMsg & strBootOpt & vbNewLine strBootOpt = GetBootOptStr(m_bhBootOpt(BootFlagsD6), "Boot configuration state", "Boot unconfigured", "Use nonvolatile configuration") strMsg = strMsg & strBootOpt & vbNewLine strBootOpt = GetBootOptStr(m_bhBootOpt(BootFlagsD5), "RS232 baud rate", "57,600 baud", "115,200 baud") strMsg = strMsg & strBootOpt & vbNewLine strBootOpt = GetBootOptStr(m_bhBootOpt(BootFlagsD4), "FPGA clock", "20MHz", "80MHz") strMsg = strMsg & strBootOpt & vbNewLine strBootOpt = GetBootOptStr(m_bhBootOpt(BootFlagsD3), "HV Polarity", "Negative", "Positive") strMsg = strMsg & strBootOpt & vbNewLine strBootOpt = GetBootOptStr(m_bhBootOpt(BootFlagsD2), "ADC invert", "Inverting", "Non-inverting") strMsg = strMsg & strBootOpt & vbNewLine strBootOpt = GetBootOptStr(m_bhBootOpt(BootFlagsD1), "Spectrum offset", "None", "Use Offset") strMsg = strMsg & strBootOpt & vbNewLine strBootOpt = GetBootOptStr(m_bhBootOpt(BootFlagsD0), "Fast channel shaping", "Normal", "4x Slower") strMsg = strMsg & strBootOpt & vbNewLine strBootOpt = GetBootOptStr(m_bhBootOpt(BootFlagsD9), "MCA channel", "Slow channel (normal operation)", "Fast channel") strMsg = strMsg & strBootOpt & vbNewLine strBootOpt = GetBootOptStr(m_bhBootOpt(BootFlagsD8), "Peak detect", "Max only (normal operation)", "Max and min") strMsg = strMsg & strBootOpt & vbNewLine DisplayBootFlags = strMsg End Function 'void CAppDlg::UpdateIni(BOOL bFromIni) '{ ' CIni ini( _T("TEST.INI"), "Settings") ' ini.SER_GET(bFromIni,m_bhBootOptD7) ' ini.SER_GET(bFromIni,m_bhBootOptD6) ' ini.SER_GET(bFromIni,m_bhBootOptD5) ' ini.SER_GET(bFromIni,m_bhBootOptD4) ' ini.SER_GET(bFromIni,m_bhBootOptD3) ' ini.SER_GET(bFromIni,m_bhBootOptD2) ' ini.SER_GET(bFromIni,DP5BootFlags) '} ' D7 Boot device mode ' D6 Boot configuration state ' D5 RS232 baud rate ' D4 FPGA clock ' D3 HV Polarity ' D2 ADC invert Public Sub UpdateDP5BootFlags(ByVal bCreateBits As Boolean, ByRef DP5BootFlags As Integer, ByRef m_bhBootOpt() As Integer) Dim idxBootFlag As Integer Dim Mask As Integer If (bCreateBits) Then For idxBootFlag = LastBootFlag To FirstBootFlag Step -1 Mask = BitMaskShort(idxBootFlag) m_bhBootOpt(idxBootFlag) = ShiftRight((DP5BootFlags And Mask), idxBootFlag) Next Else DP5BootFlags = 0 For idxBootFlag = LastBootFlag To FirstBootFlag Step -1 DP5BootFlags = DP5BootFlags + ShiftLeft((m_bhBootOpt(idxBootFlag) And &H1), idxBootFlag) Next End If End Sub Function BitMaskShort(ByVal Bit As Integer) As Integer Dim idxBit As Long Dim Mask As Long If ((Bit < 0) Or (Bit > 15)) Then BitMaskShort = 0 ElseIf Bit = 15 Then BitMaskShort = &H8000 Else Mask = 1 For idxBit = 1 To Bit Mask = Mask + Mask Next idxBit BitMaskShort = Mask End If End Function Private Function ShiftLeft(ByVal value As Long, ByVal Shift As Integer) As Long If (Shift = 0) Then 'shifting 0 returns unshifted value ShiftLeft = value ElseIf (Shift = 31) Then 'shifting 31 causes vb overflow error If ((value And &H1) = 0) Then ShiftLeft = 0 Else ShiftLeft = &H80000000 End If ElseIf (Shift > 31) Then 'shifting 31 causes vb overflow error ShiftLeft = 0 Else SaveSetBits If (value And (2 ^ (31 - Shift))) Then GoTo OverFlow ShiftLeft = ((value And SetBits(31 - Shift)) * (2 ^ Shift)) End If Exit Function OverFlow: ShiftLeft = ((value And SetBits(31 - (Shift + 1))) * (2 ^ (Shift))) Or &H80000000 End Function Private Function ShiftRight(ByVal value As Long, ByVal Shift As Integer) As Long Dim hi As Long If (Shift = 0) Then 'shifting 0 returns unshifted value ShiftRight = value ElseIf (Shift = 31) Then 'shifting 31 causes vb overflow error ShiftRight = IntBool(Not ((value And &H80000000) = 0)) ElseIf (Shift > 31) Then 'shifting 31 causes vb overflow error ShiftRight = 0 Else SaveSetBits If (value And &H80000000) Then hi = &H40000000 ShiftRight = (value And &H7FFFFFFE) \ (2 ^ Shift) ShiftRight = (ShiftRight Or (hi \ (2 ^ (Shift - 1)))) End If End Function Private Sub SaveSetBits() Dim i As Integer Dim value As Long For i = 0 To 30 value = value + (2 ^ i) SetBits(i) = value Next i SetBits(i) = value + &H80000000 End Sub Private Function IntBool(vbBool As Boolean) As Integer If (vbBool) Then IntBool = 1 Else IntBool = 0 End If End Function