Attribute VB_Name = "Module1"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\CC6Format.inc"
'#Uses "..\classes\CC6FunctionClass.cls"
'#Uses "..\classes\CC6ParameterClass.cls
'#Uses "Include.inc"
'#Uses "..\include\Port.inc"
'#Uses "8BitAdapter.inc"


Sub GenerateCodeForNodes(f As Variant, r As ProjectData, vIndex As Variant, iNode As Integer, n As String, uc As UserCode)
    
    Dim sVarPre As String
    Dim sRegPre As String
    Dim s       As String
    Dim sfrset As Integer
    sfrset = 0
    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    If (r.v(sRegPre & "INPL_INPCC60") = iNode) Then
        s = "if ISL_ICC60R"
        If (r.v(sRegPre & "IENL_ENCC60R") = 1) Then
            sfrset = 1
              Call GenerateCodeForSST(f, r, iNode)
              Print #f, ""
            Print #f, "  if(CCU6_ISL & 0x01)   //" & s
            Print #f, "  {"
            s = "    //capture, compare match rising edge detection an channel 0" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISL_ICC60R"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRL = 0x01;             //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",10)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
        s = "if ISL_ICC60F"
        If (r.v(sRegPre & "IENL_ENCC60F") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISL & 0x02)   //" & s
            Print #f, "  {"
            s = "    //capture, compare match faling edge detection an channel 0" & vbCrLf
            Print #f, "" & s
            s = "clear flag IS_ICC60F"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRL = 0x02;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",11)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
    End If

    If (r.v(sRegPre & "INPL_INPCC61") = iNode) Then
        s = "if ISL_ICC61R"
        If (r.v(sRegPre & "IENL_ENCC61R") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISL & 0x04)   //" & s
            Print #f, "  {"
            s = "    //capture, compare match rising edge detection an channel 1" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISL_ICC61R"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRL = 0x04;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",12)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
        s = "if ISL_ICC61F"
        If (r.v(sRegPre & "IENL_ENCC61F") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISL & 0x08)   //" & s
            Print #f, "  {"
            s = "    //capture, compare match faling edge detection an channel 1" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISL_ICC61F"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRL = 0x08;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",13)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
    End If

    If (r.v(sRegPre & "INPL_INPCC62") = iNode) Then
        s = "if ISL_ICC62R"
        If (r.v(sRegPre & "IENL_ENCC62R") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISL & 0x10)   //" & s
            Print #f, "  {"
            s = "    //capture, compare match rising edge detection an channel 2" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISL_ICC62R"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRL = 0x10;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",14)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
        s = "if ISL_ICC62F"
        If (r.v(sRegPre & "IENL_ENCC62F") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, 0)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISL & 0x20)   //" & s
            Print #f, "  {"
            s = "    //capture, compare match faling edge detection an channel 2" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISL_ICC62F"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRL = 0x20;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",15)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
    End If

    If (r.v(sRegPre & "INPH_INPT12") = iNode) Then
        s = "if ISL_T12OM"
        If (r.v(sRegPre & "IENL_ENT12OM") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISL & 0x40)   //" & s
            Print #f, "  {"
            s = "    //timer T12 one match detection" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISL_T12OM"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRL = 0x40;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",16)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
        s = "if ISL_T12PM"
        If (r.v(sRegPre & "IENL_ENT12PM") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISL & 0x80)   //" & s
            Print #f, "  {"
            s = "    //timer T12 period match detection" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISL_T12PM"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRL = 0x80;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",17)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
    End If

    If (r.v(sRegPre & "INPH_INPT13") = iNode) Then
        s = "if ISH_T13CM"
        If (r.v(sRegPre & "IENH_ENT13CM") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISH & 0x01)   //" & s
            Print #f, "  {"
            s = "    //timer T13 compare match detection" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISH_T13CM"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRH = 0x01;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",18)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
        s = "if ISH_T13PM"
        If (r.v(sRegPre & "IENH_ENT13PM") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISH & 0x02)   //" & s
            Print #f, "  {"
            s = "    //timer T13 period match detection" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISH_T13PM"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRH = 0x02;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",19)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
    End If

    If (r.v(sRegPre & "INPH_INPERR") = iNode) Then
        s = "if ISH_TRPF"
        If (r.v(sRegPre & "IENH_ENTRPF") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISH & 0x04)   //" & s
            Print #f, "  {"
            s = "    //trap detection" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISH_TRPF"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRH = 0x04;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",20)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
        s = "if ISH_WHE"
        If (r.v(sRegPre & "IENH_ENWHE") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISH & 0x20)   //" & s
            Print #f, "  {"
            s = "    //wrong hall event detection" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISH_WHE"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRH = 0x20;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",21)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
        s = "if ISH_CCU_IDLE"
        If (r.v(sRegPre & "IENH_ENIDLE") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISH & 0x40)   //" & s
            Print #f, "  {"
            s = "    //idle state detection" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISH_CCU_IDLE"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRH = 0x40;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",22)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
    End If
    If (r.v(sRegPre & "INPL_INPCHE") = iNode) Then
        s = "if ISH_CHE"
        If (r.v(sRegPre & "IENH_ENCHE") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISH & 0x10)   //" & s
            Print #f, "  {"
            s = "    //correct hall event detection" & vbCrLf
            Print #f, "" & s
            s = "clear flag ISH_CHE"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRH = 0x10;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",23)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
        s = "if ISH_SSTR"
        If (r.v(sRegPre & "IENH_ENSTR") = 1) Then
            If (sfrset = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
            Else
              Call GenerateCodeForSST(f, r, iNode)
              sfrset = 1
            End If
              Print #f, ""
            Print #f, "  if(CCU6_ISH & 0x80)   //" & s
            Print #f, "  {"
            s = "    // shadow transfer has taken place." & vbCrLf
            Print #f, "" & s
            s = "clear flag ISH_SSTR"
            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            Print #f, ""
            Print #f, "    CCU6_ISRH = 0x80;  //" & s
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",24)", 4)
            Print #f, ""
            Print #f, "  }"
            Print #f, ""
        End If
    End If
        If (sfrset = 1) Then
            Print #f, ""
            sfrset = 0
        End If
 End Sub
 
 '*****************************************************************************
'Description:
'        This function generates code for storage page depending on interrupt priority.
'-----------------------------------------------------------------------------
'Parameters:
'        f
'        r                reference to the Registers object
'        iNode            number of node
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Sub GenerateCodeForSST(f As Variant, r As ProjectData, iNode As Integer)
 
      Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
End Sub
