Attribute VB_Name = "Module1"
'#Uses "..\classes\InterruptClass.cls"
'#Uses "..\classes\ModuleClass.cls"
'#Uses "..\classes\Port.cls"
'#Uses "..\classes\PortPin.cls"
'#Uses "..\classes\ManualLinkClass.cls"
'#Uses "Global.inc"

Option Explicit
'*****************************************************************************
' Module:
'
'-----------------------------------------------------------------------------
' Description:
'                This module contains global functions that must be used
'                to install the system.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0   ahe         31.07.00     final version for C164CS
'
'        1.1   ahe         08.08.02     - change AddInterrupt()
'                                       - change names of interrupts
'
'
'        1.2   ahe         30.08.02     - change CAN_RxDB_2 to CAN_RxDB_1
'                                       - change CAN_TxDB_2 to CAN_TxDB_1
'-----------------------------------------------------------------------------
'       1.3   sunil/shesh   16.06.05    - change in CC60 AltO/p Pin : Parameter
'                                           "iFunction" of AddAlternateName changed from 0 to 1
'    If (Not AddAlternateName(p, "CCU6_CC60_O", "CAPCOM6 output (CC60)", True, 1)) Then Exit Function
'
'*****************************************************************************


'*****************************************************************************
' @bfunc   Public | InstallBackimage | |
'
'-----------------------------------------------------------------------------
'          This function loades the first bitmap.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' @bparm   | gc | GraphicConfigure |
'
'*****************************************************************************
Public Function InstallBackimage(gc As GraphicConfigure) As Boolean
  On Error Resume Next
  InstallBackimage = False

  If (Not gc.LoadBackimage(DefGetPath("Bitmaps") & "Main.bmp", 680, 400)) Then Exit Function

  InstallBackimage = True
End Function


'*****************************************************************************
' @bfunc   Public | InstallModule | Boolean |
'
'-----------------------------------------------------------------------------
'          For each module that should be used in the system a line
'          "Call AddModule .." must be insert in this function.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' @bparm   | d | DAvECollection | the collection of the modules
'
'*****************************************************************************
Public Function InstallModule(d As DAvECollection) As Boolean
  On Error Resume Next
  InstallModule = False

  ' for each module in the system the function AddModule must be called
  '
  ' AddModule(c As DAvECollection, ModuleName As String, ModuleDescription As String,
  '           ModuleDirectory As String, ParameterValue As Integer, ModuleWithCG As Boolean) As Boolean
  '
  ' c                 | DAvECollection | the module collection
  ' ModuleName        | String         | identifier of the module
  ' ModuleDescription | String         | name of the module
  ' ModuleDirectory   | String         | sub directory name of this module
  ' ParameterValue    | Variant        | a parameter for the new script file
  ' ModuleWithCG      | Boolean        | indicates if the module has an codegenerator or not

  If (Not AddModule(d, "MAIN", "Project Settings", "MAIN", "", True)) Then Exit Function

  If (Not AddModule(d, "IO", "Parallel Ports", "IO", "", True)) Then Exit Function

  If (Not AddModule(d, "ASC0", "Asynchronous/Synchronous Serial Interface (ASC0)", "ASCx", 0, True)) Then Exit Function
  If (Not AddModule(d, "ASC1", "Asynchronous/Synchronous Serial Interface (ASC1)", "ASCx", 1, True)) Then Exit Function
  If (Not AddModule(d, "SSC0", "High-Speed Synchronous Serial Interface 0 (SSC0)", "SSCx", 0, True)) Then Exit Function
  If (Not AddModule(d, "SSC1", "High-Speed Synchronous Serial Interface 1 (SSC1)", "SSCx", 1, True)) Then Exit Function
  If (Not AddModule(d, "GPT1", "General Purpose Timer Unit (GPT1)", "GPT1", "", True)) Then Exit Function
  If (Not AddModule(d, "GPT2", "General Purpose Timer Unit (GPT2)", "GPT2", "", True)) Then Exit Function
  If (Not AddModule(d, "CC2", "Capture / Compare Unit 2 (CAPCOM2)", "CCx", 2, True)) Then Exit Function
  If (Not AddModule(d, "CCU6", "Capture / Compare Unit 6 (CCU6)", "CC6", 6, True)) Then Exit Function
  If (Not AddModule(d, "ADC", "Analog / Digital Converter (ADC)", "ADC", "", True)) Then Exit Function
  If (Not AddModule(d, "RTC", "Real Timer Clock (RTC)", "RTC", "", True)) Then Exit Function
  If (Not AddModule(d, "CAN", "TwinCAN Module (CAN)", "CAN", "", True)) Then Exit Function
  If (Not AddModule(d, "INT", "Interrupt Controller (INT)", "INT", "", True)) Then Exit Function
  If (Not AddModule(d, "WDT", "Watchdog Timer (WDT)", "WDT", "", True)) Then Exit Function
  If (Not AddModule(d, "SCU", "System Control Unit (SCU)", "SCU", "", True)) Then Exit Function
  If (Not AddModule(d, "LIN", "Local Interconnect Network (LIN)", "LIN", "", True)) Then Exit Function
  InstallModule = True


End Function


'*****************************************************************************
' @bfunc   Public | InstallHotspots | Boolean |
'
'-----------------------------------------------------------------------------
'          For each hotspot on the backimage a line "m.AddHotspot .."
'          must be insert in this function.
'
'          NOTE:
'          The identifiere of the hotspot must be have the same name as the
'          identifiere of the module which was added with the function
'          AddModule.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' @bparm   | gc | GraphicConfigure |
'
'*****************************************************************************
Public Function InstallHotspots(gc As GraphicConfigure) As Boolean
  On Error Resume Next
  InstallHotspots = False


    If (Not gc.AddHotspot("CCU6", DefGetPath("Bitmaps") & "cc6.bmp", 196, 216, 233, 245, 35, 65)) Then Exit Function
    If (Not gc.AddHotspot("ASC0", DefGetPath("Bitmaps") & "Asc0.bmp", 400, 190, 452, 245, 35, 65)) Then Exit Function
    If (Not gc.AddHotspot("GPT2", DefGetPath("Bitmaps") & "gpt2.bmp", 370, 190, 408, 245, 35, 65)) Then Exit Function
    If (Not gc.AddHotspot("GPT1", DefGetPath("Bitmaps") & "gpt1.bmp", 320, 190, 365, 245, 35, 65)) Then Exit Function
    If (Not gc.AddHotspot("SSC1", DefGetPath("Bitmaps") & "ssc1.bmp", 270, 190, 321, 245, 35, 65)) Then Exit Function
    If (Not gc.AddHotspot("SSC0", DefGetPath("Bitmaps") & "ssc0.bmp", 230, 190, 277, 245, 35, 65)) Then Exit Function
    If (Not gc.AddHotspot("CC2", DefGetPath("Bitmaps") & "cc2.bmp", 150, 196, 190, 245, 35, 65)) Then Exit Function
    If (Not gc.AddHotspot("ADC", DefGetPath("Bitmaps") & "adc.bmp", 100, 207, 144, 245, 45, 65)) Then Exit Function
    If (Not gc.AddHotspot("RTC", DefGetPath("Bitmaps") & "rtc.bmp", 60, 215, 100, 245, 45, 65)) Then Exit Function
    If (Not gc.AddHotspot("CAN", DefGetPath("Bitmaps") & "can.bmp", 10, 190, 56, 245, 45, 65)) Then Exit Function
    If (Not gc.AddHotspot("SCU", DefGetPath("Bitmaps") & "scu.bmp", 490, 70, 533, 124, 35, 63)) Then Exit Function
    If (Not gc.AddHotspot("WDT", DefGetPath("Bitmaps") & "wdt.bmp", 522, 147, 575, 182, 65, 36)) Then Exit Function
    If (Not gc.AddHotspot("INT", DefGetPath("Bitmaps") & "int.bmp", 207, 80, 281, 135, 121, 32)) Then Exit Function
    If (Not gc.AddHotspot("IO", DefGetPath("Bitmaps") & "io.bmp", 120, 300, 203, 332, 270, 47)) Then Exit Function
    If (Not gc.AddHotspot("ASC1", DefGetPath("Bitmaps") & "Asc1.bmp", 446, 213, 495, 245, 38, 65)) Then Exit Function
    If (Not gc.AddHotspot("LIN", DefGetPath("Bitmaps") & "lin.bmp", 540, 201, 587, 245, 38, 65)) Then Exit Function
  
  InstallHotspots = True
End Function


'*****************************************************************************
' @bfunc   Public | InstallInterrupts | Boolean |
'
'-----------------------------------------------------------------------------
'          For each interrupt that should be used in the system a line
'          "Call AddInterrupt .." must be inserted in this function.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' @bparm   | c | DAvECollection | the collection of the interrupts
'
'*****************************************************************************
Public Function InstallInterrupts(c As DAvECollection) As Boolean
  On Error Resume Next
  
  InstallInterrupts = False
  
  Dim v As Variant
  Dim i As Integer

  ' for each interrupt in the system the function AddInterrupt must be called
  '
  ' AddInterrupt(c As DAvECollection, IntName As String, LevelName As String,
  '              GroupName As String) As Boolean
  '
  ' c         | DAvECollection | the interrupt collection
  ' IntName   | String         | name of the interrupt
  ' LevelName | String         | name of the level bit field
  ' GroupName | String         | name of the group bit field
  ' Enabled   | String         | name of the int. enabled bit
  ' RegName   | String         | name of the interupt control register; now bit name

  'GPT1 Interrupts
  v = "GPT12E_T2IC"
  If (Not AddInterrupt(c, "GPT1 T2 INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "GPT12E_T3IC"
  If (Not AddInterrupt(c, "GPT1 T3 INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "GPT12E_T4IC"
  If (Not AddInterrupt(c, "GPT1 T4 INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  'GPT2 Interrupts
  v = "GPT12E_CRIC"
  If (Not AddInterrupt(c, "GPT2 CAPREL INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "GPT12E_T5IC"
  If (Not AddInterrupt(c, "GPT2 T5 INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "GPT12E_T6IC"
  If (Not AddInterrupt(c, "GPT2 T6 INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function


  ' SSCx Interrupts
  For i = 0 To 1
      v = "SSC" & i & "_EIC"
      If (Not AddInterrupt(c, "SSC" & i & " error INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
      v = "SSC" & i & "_RIC"
      If (Not AddInterrupt(c, "SSC" & i & " Rx INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
      v = "SSC" & i & "_TIC"
      If (Not AddInterrupt(c, "SSC" & i & " Tx INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  Next i

  ' ASC0 Interrupts
  v = "ASC0_EIC"
  If (Not AddInterrupt(c, "ASC0 error INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "ASC0_RIC"
  If (Not AddInterrupt(c, "ASC0 Rx INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "ASC0_TIC"
  If (Not AddInterrupt(c, "ASC0 Tx INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "ASC0_TBIC"
  If (Not AddInterrupt(c, "ASC0 TB INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "ASC0_ABIC"
  If (Not AddInterrupt(c, "ASC0 AB INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
' ASC1 Interrupts
  v = "ASC1_EIC"
  If (Not AddInterrupt(c, "ASC1 error INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "ASC1_RIC"
  If (Not AddInterrupt(c, "ASC1 Rx INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "ASC1_TIC"
  If (Not AddInterrupt(c, "ASC1 Tx INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "ASC1_TBIC"
  If (Not AddInterrupt(c, "ASC1 Tx buffer INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  v = "ASC1_ABIC"
  If (Not AddInterrupt(c, "ASC1 autobaud INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  'PEC Interrupt
  v = "EOPIC"
  If (Not AddInterrupt(c, "EOP INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  'RTC Interrupt
  v = "RTC_IC"
  If (Not AddInterrupt(c, "RTC INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  'ADC Interrupts
  v = "ADC_CIC"
  If (Not AddInterrupt(c, "ADC Conv INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  v = "ADC_EIC"
  If (Not AddInterrupt(c, "ADC Error INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  'CC timer Interrupts
'  v = "CC1_T0IC"
'  If (Not AddInterrupt(c, "CC1 T0 INT", v & "_ILVL", v & "_GLVL" , v & "_IE", v)) Then Exit Function
'
'  v = "CC1_T1IC"
'  If (Not AddInterrupt(c, "CC1 T1 INT", v & "_ILVL", v & "_GLVL" , v & "_IE", v)) Then Exit Function

  v = "CC2_T7IC"
  If (Not AddInterrupt(c, "CC2 T7 INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  v = "CC2_T8IC"
  If (Not AddInterrupt(c, "CC2 T8 INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  'CCx Interrupts
'  For i = 0 To 5
'      v = "CC1_CC" & i & "IC"
'      If (Not AddInterrupt(c, "CC1 Ch" & i & " INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
'  Next i

  For i = 8 To 13
      v = "CC1_CC" & i & "IC"
      If (Not AddInterrupt(c, "Ext " & i - 8 & " Ch " & i & " INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  Next i

  For i = 16 To 31
      v = "CC2_CC" & i & "IC"
      If (Not AddInterrupt(c, "CC2 Ch" & i & " INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  Next i

  'CC6 Interrupts
  v = "CCU6_IC"
  If (Not AddInterrupt(c, "CCU6 I0 INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  v = "CCU6_EIC"
  If (Not AddInterrupt(c, "CCU6 I1 INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  v = "CCU6_T12IC"
  If (Not AddInterrupt(c, "CCU6 I2 INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  v = "CCU6_T13IC"
  If (Not AddInterrupt(c, "CCU6 I3 INT", v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function

  For i = 0 To 7
    'CAN Interrupt
    v = "CAN_" & i & "IC"
    If (Not AddInterrupt(c, "CAN INT " & i, v & "_ILVL", v & "_GLVL", v & "_IE", v)) Then Exit Function
  Next i


  InstallInterrupts = True
End Function


'*****************************************************************************
' @bfunc   Public | InstallPorts | Boolean |
'
'-----------------------------------------------------------------------------
'          For each Port which should be used in the system a line
'          "Call AddPort .." must be insert in this function.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' @bparm   | cPorts | DAvECollection | the collection of the ports
'
'*****************************************************************************
Public Function InstallPorts(cPorts As DAvECollection) As Boolean
  On Error Resume Next
  InstallPorts = False

  ' for each port in the system the function AddPort must be called
  '
  'AddPort(p As DAvECollection, vPortNumber As Variant, sPortDescription As String, iFirstPin As Integer, _
  '        iLastPin As Integer, Optional iInputThresholdType As Integer = 0, Optional iOutputEdgeType As Integer = 0, _
  '        Optional iOutputDriverType As Integer = 0) As Boolean
  '
  ' cPorts              | DAvECollection | the port collection
  ' vPortNumber         | Variant        | number of the port
  ' sPortDescription    | String         | name (description) of the port
  ' iFirstPin           | Integer        | number of the first pin that should be shown in the mask
  ' iLastPin            | Integer        | number of the last pin that should be shown in the mask

  ' iInputThresholdType | Integer        | the input threshold type can be configured pin- (1), nible- (2),
  '                                        byte- (3) or port-wise (4)
  ' iOutputEdgeType     | Integer        | the output edge characteristic can be configured pin- (1), nible- (2),
  '                                        byte- (3) or port-wise (4)
  ' iOutputDriverType   | Integer        | the output driver characteristic can be configured pin- (1), nible- (2),
  '                                        byte- (3) or port-wise (4)



  If (Not AddPort(cPorts, "1H", "Port 1H", 0, 5, 0, 2, 2)) Then Exit Function
  If (Not AddPort(cPorts, "1L", "Port 1L", 0, 7, 0, 2, 2)) Then Exit Function
  If (Not AddPort(cPorts, 3, "Port 3", 0, 15, 3, 2, 2)) Then Exit Function
  If (Not AddPort(cPorts, 5, "Port 5", 0, 15, 0, 0, 0)) Then Exit Function
  If (Not AddPort(cPorts, 9, "Port 9", 0, 5, 3, 2, 2)) Then Exit Function




  InstallPorts = True
End Function


'*****************************************************************************
' @bfunc   Public | InstallPortPins | Boolean |
'
'-----------------------------------------------------------------------------
'          For each Pin which should be used in the system a line
'          "Call AddPin .." must be insert in this function.
'          For each alternate pin name that should be used in the system a
'          line "Call AddAlternateName .." must be insert in this function.
'
'          Note:
'          For each added pin a project variable with the name "MuxFor_Px_y"
'          must be exist in the *.vars file. And for each alternate pin name
'          a project variable with the name "MuxFor_AlternateName" must be
'          exist.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' @bparm   | p | DAvECollection | the collection of the pins
'
'*****************************************************************************
Public Function InstallPortPins(p As PortPin) As Boolean
  On Error Resume Next
  InstallPortPins = False

  Dim i As Integer

  ' for each Pin in the system the function AddPin must be called
  '
  ' AddPin(p As PortPin, vPort as Variant, iPin As Integer, bUse As Boolean, Optional bExclusive As Boolean = False) As Boolean
  '
  ' p                 | PortPin    | class for the port pins
  ' vPort             | Variant    | number of the port
  ' iPin              | Integer    | number of the pin
  ' bUse              | Boolean    | flag that shows if the pin is availible
  ' bExclusive        | Boolean    | flag that shows if the pin should be used exclusive


  ' for each alternate pin name in the system the function AddAlternateName must be
  ' called
  '
  ' AddAlternateName(p As PortPin, sAlternateName As String, sDescription As String, _
  '                  Optional bExclusive As Boolean = False, Optional iFunction As Integer = 1) As Boolean

  '
  ' p                 | PortPin    | object of the class for the port pins
  ' sAlternateName    | String     | alternate name of a pin (used as identifier)
  ' sDescription      | String     | description of the alternate pin function
  ' bExclusive        | Boolean    | flag that shows if the pin should be used exclusive
  ' iFunction         | Integer    | number of the alternate output function of this pin
  '                                  (used for the ALTSEL registers), -1 means the pin is input
  

  '---------------------------------------------------------------------------------------------
  'Port 1L
  '---------------------------------------------------------------------------------------------
  i = 0
  If (Not AddPin(p, "1L", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_CC60_I", "CAPCOM6 input (CC60)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_CC60_O", "CAPCOM6 output (CC60)", True, 1)) Then Exit Function

  i = 1
  If (Not AddPin(p, "1L", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_COUT60_O", "CAPCOM6 output (COUT60)", True, 1)) Then Exit Function

  i = 2
  If (Not AddPin(p, "1L", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_CC61_I", "CAPCOM6 input (CC61)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_CC61_O", "CAPCOM6 output (CC61)", True, 1)) Then Exit Function

  i = 3
  If (Not AddPin(p, "1L", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_COUT61_O", "CAPCOM6 output (COUT61)", True, 1)) Then Exit Function

  i = 4
  If (Not AddPin(p, "1L", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_CC62_I", "CAPCOM6 input (CC62)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_CC62_O", "CAPCOM6 output (CC62)", True, 1)) Then Exit Function

  i = 5
  If (Not AddPin(p, "1L", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_COUT62_O", "CAPCOM6 output (COUT62)", True, 1)) Then Exit Function

  i = 6
  If (Not AddPin(p, "1L", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_COUT63_O", "CAPCOM6 output (COUT63)", True, 1)) Then Exit Function

  i = 7
  If (Not AddPin(p, "1L", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_CTRAP_I", "CAPCOM6 input (#CTRAP)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CC2_CC22IO_I", "CAPCOM2 Input  (CC22IO)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CC2_CC22IO_O", "CAPCOM2 Output (CC22IO)", True, 1)) Then Exit Function

  '---------------------------------------------------------------------------------------------
  'Port 1H
  '---------------------------------------------------------------------------------------------
  i = 0
  If (Not AddPin(p, "1H", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CC2_CC23IO_I", "CAPCOM2 Input (CC23IO)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CC2_CC23IO_O", "CAPCOM2 Output (CC23IO)", True, 1)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_CC6POS0_I", "CAPCOM6 input (#CC6POS0)", True)) Then Exit Function
    If (Not AddAlternateName(p, "EX" & i & "IN", "Fast External Interrupt " & i & " Input (EX" & i & "IN)", True)) Then Exit Function
  
  i = 1
  If (Not AddPin(p, "1H", i, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "SSC1_MRST_I", "SSC1 Master Receive (SSC1_MRST)", True)) Then Exit Function
        If (Not AddAlternateName(p, "SSC1_MRST_O", "SSC1 Slave Transmit (SSC1_MRST)", True, 1)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_CC6POS1_I", "CAPCOM6 input (#CC6POS1)", True)) Then Exit Function
    If (Not AddAlternateName(p, "EX" & i & "IN", "Fast External Interrupt " & i & " Input (EX" & i & "IN)", True)) Then Exit Function
  
  i = 2
  If (Not AddPin(p, "1H", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "SSC1_MTSR_O", "SSC1 Master Transmit (SSC1_MTSR)", True, 1)) Then Exit Function
    If (Not AddAlternateName(p, "SSC1_MTSR_I", "SSC1 Slave Receive (SSC1_MTSR)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CCU6_CC6POS2_I", "CAPCOM6 input (#CC6POS2)", True)) Then Exit Function
    If (Not AddAlternateName(p, "EX" & i & "IN", "Fast External Interrupt " & i & " Input (EX" & i & "IN)", True)) Then Exit Function
  
  i = 3
  If (Not AddPin(p, "1H", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "SSC1_SCLK_I", "SSC1 Shift Clock Input (SSC1_SCLK)", True)) Then Exit Function
    If (Not AddAlternateName(p, "SSC1_SCLK_O", "SSC1 Shift Clock Output (SSC1_SCLK)", True, 1)) Then Exit Function
    If (Not AddAlternateName(p, "EX" & i & "IN", "Fast External Interrupt " & i & " Input (EX" & i & "IN)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CC2_T7IN", "CAPCOM2 Timer T7 Input (T7IN)", True)) Then Exit Function
  
  i = 4
  If (Not AddPin(p, "1H", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CC2_CC" & i + 20 & "IO_I", "CAPCOM2 Input (CC" & i + 20 & "IO)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CC2_CC" & i + 20 & "IO_O", "CAPCOM2 Output (CC" & i + 20 & "IO)", True, 1)) Then Exit Function
    If (Not AddAlternateName(p, "EX" & i & "IN", "Fast External Interrupt " & i & " Input (EX" & i & "IN)", True)) Then Exit Function

  i = 5
  If (Not AddPin(p, "1H", i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CC2_CC" & i + 20 & "IO_I", "CAPCOM2 Input (CC" & i + 20 & "IO)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CC2_CC" & i + 20 & "IO_O", "CAPCOM2 Output (CC" & i + 20 & "IO)", True, 1)) Then Exit Function
    If (Not AddAlternateName(p, "EX" & i & "IN", "Fast External Interrupt " & i & " Input (EX" & i & "IN)", True)) Then Exit Function
  '---------------------------------------------------------------------------------------------
  'Port 3
  '---------------------------------------------------------------------------------------------
  If (Not AddPin(p, 3, 0, False, True)) Then Exit Function

  If (Not AddPin(p, 3, 1, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "T6OUT", "Timer 6 Toggle Latch Output (T6OUT)", True, 2)) Then Exit Function
         If (Not AddAlternateName(p, "ASC1_RxD_1_O", "ASC1 Receive data Output (RxDA1)", True, 3)) Then Exit Function
         If (Not AddAlternateName(p, "ASC1_RxD_1_I", "ASC1 Receive data Input (RxDA1)", True)) Then Exit Function

  If (Not AddPin(p, 3, 2, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "CAPIN", "Capture Input (CAPIN)", True)) Then Exit Function

  If (Not AddPin(p, 3, 3, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "T3OUT", "Timer 3 Toggle Latch Output (T3OUT)", True, 1)) Then Exit Function

  If (Not AddPin(p, 3, 4, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "T3EUD", "Timer 3 ext. Up/Down Input (T3EUD)", False)) Then Exit Function
'         If (Not AddAlternateName(p, "TMS", "Debug System: JTAG Test Mode Selection(TMS)", True)) Then Exit Function

  If (Not AddPin(p, 3, 5, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "T4IN", "Timer 4 Count Input (T4IN)", True)) Then Exit Function
         If (Not AddAlternateName(p, "ASC1_TxD_1", "ASC1 Transmit Data Output (TxDA1)", True, 1)) Then Exit Function

  If (Not AddPin(p, 3, 6, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "T3IN", "Timer 3 Count Input (T3IN)", False)) Then Exit Function

  If (Not AddPin(p, 3, 7, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "T2IN", "Timer 2 Count Input (T2IN)", True)) Then Exit Function

  If (Not AddPin(p, 3, 8, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "SSC0_MRST_I", "SSC0 Master Receive (SSC0_MRST)", True)) Then Exit Function
         If (Not AddAlternateName(p, "SSC0_MRST_O", "SSC0 Slave Transmit (SSC0_MRST)", True, 1)) Then Exit Function

  If (Not AddPin(p, 3, 9, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "SSC0_MTSR_O", "SSC0 Master Transmit (SSC0_MTSR)", True, 1)) Then Exit Function
         If (Not AddAlternateName(p, "SSC0_MTSR_I", "SSC0 Slave Receive (SSC0_MTSR)", True)) Then Exit Function

  If (Not AddPin(p, 3, 10, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "ASC0_TxD_1", "ASC Transmit Data Output (TxDA0)", True, 1)) Then Exit Function

  If (Not AddPin(p, 3, 11, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "ASC0_RxD_1_O", "ASC0 Receive data Output (RxDA0)", True, 1)) Then Exit Function
         If (Not AddAlternateName(p, "ASC0_RxD_1_I", "ASC0 Receive data Input (RxDA0)", True)) Then Exit Function

  If (Not AddPin(p, 3, 12, False, True)) Then Exit Function

  If (Not AddPin(p, 3, 13, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "SSC0_SCLK_I", "SSC0 Shift Clock Input (SSC0_SCLK)", True)) Then Exit Function
         If (Not AddAlternateName(p, "SSC0_SCLK_O", "SSC0 Shift Clock Output (SSC0_SCLK)", True, 1)) Then Exit Function

  If (Not AddPin(p, 3, 14, False, True)) Then Exit Function

  If (Not AddPin(p, 3, 15, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "CLKOUT", "System Clock Output (CLKOUT)", True, 0)) Then Exit Function
         If (Not AddAlternateName(p, "FOUT", "Programmable Clock Output (FOUT)", True, 0)) Then Exit Function



  '---------------------------------------------------------------------------------------------
  'Port 5
  '---------------------------------------------------------------------------------------------
  For i = 0 To 7
    If (Not AddPin(p, 5, i, True, True)) Then Exit Function
      If (Not AddAlternateName(p, "AN" & i, "Analog Input Pin (AN" & i & ")", True)) Then Exit Function
  Next i

  For i = 8 To 9
      If (Not AddPin(p, 5, i, False, True)) Then Exit Function
  Next i
  
  If (Not AddPin(p, 5, 10, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "T6EUD", "Timer 6 ext. Up/Down Input (T6EUD)", True)) Then Exit Function
    If (Not AddAlternateName(p, "AN10", "Analog Input Pin (AN10)", True)) Then Exit Function
  If (Not AddPin(p, 5, 11, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "T5EUD", "Timer 5 ext. Up/Down Input (T5EUD)", True)) Then Exit Function
    If (Not AddAlternateName(p, "AN11", "Analog Input Pin (AN11)", True)) Then Exit Function
  If (Not AddPin(p, 5, 12, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "AN12", "Analog Input Pin (AN12)", True)) Then Exit Function
    If (Not AddAlternateName(p, "T6IN", "Timer 6 Count Input (T6IN)", True)) Then Exit Function
  If (Not AddPin(p, 5, 13, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "AN13", "Analog Input Pin (AN13)", True)) Then Exit Function
    If (Not AddAlternateName(p, "T5IN", "Timer 5 Count Input (T5IN)", True)) Then Exit Function
  If (Not AddPin(p, 5, 14, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "AN14", "Analog Input Pin (AN14)", True)) Then Exit Function
    If (Not AddAlternateName(p, "T4EUD", "Timer 4 ext. Up/Down Input (T4EUD)", True)) Then Exit Function
  If (Not AddPin(p, 5, 15, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "AN15", "Analog Input Pin (AN15)", True)) Then Exit Function
    If (Not AddAlternateName(p, "T2EUD", "Timer 2 ext. Up/Down Input (T2EUD)", True)) Then Exit Function

  '---------------------------------------------------------------------------------------------
  'Port 9
  '---------------------------------------------------------------------------------------------
  i = 16 'for CC2 Pins
  If (Not AddPin(p, 9, 0, True, True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_I", "CAPCOM2 Input (CC" & i & "IO)", True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_O", "CAPCOM2 Output (CC" & i & "IO)", True, 2)) Then Exit Function
     'If (Not AddAlternateName(p, "CAN_RxDB_2", "CAN Interface Input (RXDCB)", True)) Then Exit Function
     If (Not AddAlternateName(p, "CAN_RxDB_1", "CAN Interface Input (RXDCB)", True)) Then Exit Function

  i = 17 'for CC2 Pins
  If (Not AddPin(p, 9, 1, True, True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_I", "CAPCOM2 Input (CC" & i & "IO)", True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_O", "CAPCOM2 Output (CC" & i & "IO)", True, 2)) Then Exit Function
     'If (Not AddAlternateName(p, "CAN_TxDB_2", "CAN Interface Output (TXDCB)", True, 3)) Then Exit Function
     If (Not AddAlternateName(p, "CAN_TxDB_1", "CAN Interface Output (TXDCB)", True, 3)) Then Exit Function

  i = 18 'for CC2 Pins
  If (Not AddPin(p, 9, 2, True, True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_I", "CAPCOM2 Input (CC" & i & "IO)", True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_O", "CAPCOM2 Output (CC" & i & "IO)", True, 2)) Then Exit Function
    If (Not AddAlternateName(p, "CAN_RxDA_3", "CAN Interface Input (RXDCA)", True)) Then Exit Function

  i = 19 'for CC2 Pins
  If (Not AddPin(p, 9, 3, True, True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_I", "CAPCOM2 Input (CC" & i & "IO)", True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_O", "CAPCOM2 Output (CC" & i & "IO)", True, 2)) Then Exit Function
    If (Not AddAlternateName(p, "CAN_TxDA_2", "CAN Interface Output (TXDCA)", True, 3)) Then Exit Function

  i = 20 'for CC2 Pins
  If (Not AddPin(p, 9, 4, True, True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_I", "CAPCOM2 Input (CC" & i & "IO)", True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_O", "CAPCOM2 Output (CC" & i & "IO)", True, 2)) Then Exit Function
  
  i = 21 'for CC2 Pins
  If (Not AddPin(p, 9, 5, True, True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_I", "CAPCOM2 Input (CC" & i & "IO)", True)) Then Exit Function
     If (Not AddAlternateName(p, "CC2_CC" & i & "IO_O", "CAPCOM2 Output (CC" & i & "IO)", True, 2)) Then Exit Function


        If (Not p.Sort) Then Exit Function

  InstallPortPins = True
End Function

'*****************************************************************************
' @bfunc   Public | InstallManualLinks | Boolean |
'
'-----------------------------------------------------------------------------
'          For each Script which has a Manual Link menu a line
'          ".. AddMenu .." must be inserted in this function.
'          For each Link in this menu a
'          line ".. AddLink .." must be inserted in this function.
'
'          Note:
'          For each added Link a entry with the link key must be inserted in
'          the *.def file under the specified section.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' @bparm   | p | DAvECollection | the collection of the pins
'
'*****************************************************************************
Public Function InstallManualLinks(m As ManualLinkClass) As Boolean
  On Error Resume Next
  InstallManualLinks = False
 
  Dim sDefSection As String

  ' for each Script which has a Manual Link menu the property AddMenu must be called
  '
  ' AddMenu(sScriptName As String) As Boolean
  '
  ' sScriptName  | String   | name and subdirectory of the scriptfile (e.g. "SSCx\Dialog")


  ' for each Link in the menu the proberty AddLink must be called
  '
  ' AddLink(sDefSection As String, sLinkName As String, Optional sKeyName As String = "", Optional bGroup As Boolean = False) As Boolean

  '
  ' sDefSection  | String   | name of the section in the *.def file
  ' sLinkName    | String   | caption of the manual link which shows in the menu
  ' sKeyName     | String   | name of the link entry in the *.def file under the section
  '                           specified with sDefSection. This name can be the same as sLinkName.
  '                           If this an empty string then the name from sLinkName are used automatically.
  ' bGroup       | Boolean  | if true then a new group (line) in the menu was created

  sDefSection = "MAIN"
  If (Not m.AddMenu("Main\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Architectural Overview")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Clock Generation Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Central Processing Unit (CPU)", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Memory Organization", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "System Reset", , True)) Then Exit Function


  sDefSection = "INT"
  If (Not m.AddMenu("INT\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt and Trap Functions")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt System Structure", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Arbitration and Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Vector Table")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Prioritization of Interrupt and PEC Service Requests", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Context Switching and Saving Status")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Node Sharing")) Then Exit Function
         If (Not m.AddLink(sDefSection, "External Interrupts")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Service Request Latency ")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Trap Functions")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Operation of the Peripheral Event Controller Channels", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "The PEC Source and Destination Pointers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "PEC Transfer Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Channel Link Mode for Data Chaining")) Then Exit Function
         If (Not m.AddLink(sDefSection, "PEC Interrupt Control")) Then Exit Function

  sDefSection = "INT"
  If (Not m.AddMenu("PEC\PEC")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Operation of the Peripheral Event Controller Channels")) Then Exit Function
         If (Not m.AddLink(sDefSection, "The PEC Source and Destination Pointers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "PEC Transfer Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Channel Link Mode for Data Chaining")) Then Exit Function
         If (Not m.AddLink(sDefSection, "PEC Interrupt Control")) Then Exit Function

  sDefSection = "SCU"
  If (Not m.AddMenu("SCU\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "The System Control Unit")) Then Exit Function
         If (Not m.AddLink(sDefSection, "System Control in Power Saving Modes", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Programmable Frequency Output Signal", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Register Security Mechanism", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Power Management Control Block", , True)) Then Exit Function


  sDefSection = "WDT"
  If (Not m.AddMenu("WDT\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Watchdog Timer")) Then Exit Function

  sDefSection = "IO"
  If (Not m.AddMenu("IO\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Parallel Ports")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Input Threshold Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Output Driver Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Alternate Port Functions")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Port 1")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Port 3")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Port 5")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Port 9")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Dedicated Pins", , True)) Then Exit Function

  sDefSection = "IO"
  If (Not m.AddMenu("IO\Port1L")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Parallel Ports")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Input Threshold Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Output Driver Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Alternate Port Functions")) Then Exit Function
         If (Not m.AddLink(sDefSection, "PORT1", , True)) Then Exit Function

  sDefSection = "IO"
  If (Not m.AddMenu("IO\Port1H")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Parallel Ports")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Input Threshold Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Output Driver Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Alternate Port Functions")) Then Exit Function
         If (Not m.AddLink(sDefSection, "PORT1", , True)) Then Exit Function

  sDefSection = "IO"
  If (Not m.AddMenu("IO\Port3")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Parallel Ports")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Input Threshold Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Output Driver Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Alternate Port Functions")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Port 3", , True)) Then Exit Function

  sDefSection = "IO"
  If (Not m.AddMenu("IO\Port5")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Parallel Ports")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Input Threshold Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Output Driver Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Alternate Port Functions")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Port 5", , True)) Then Exit Function

  sDefSection = "IO"
  If (Not m.AddMenu("IO\Port9")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Parallel Ports")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Input Threshold Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Output Driver Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Alternate Port Functions")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Port 9", , True)) Then Exit Function
  
  sDefSection = "RTC"
  If (Not m.AddMenu("RTC\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Real Time Clock")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Defining the RTC Time Base")) Then Exit Function
         If (Not m.AddLink(sDefSection, "RTC Run Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "RTC Operating Modes")) Then Exit Function
         If (Not m.AddLink(sDefSection, "RTC Interrupt Generation", , True)) Then Exit Function

  sDefSection = "ADC"
  If (Not m.AddMenu("ADC\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Analog Digital Converter (ADC)")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Mode Selection and Operation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Fixed Channel Conversion Modes")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Auto Scan Conversion Modes")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Wait for DAT Read Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Channel Injection Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Standard Conversion Timing Control", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Improved Conversion Timing Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Power-Up Calibration")) Then Exit Function
         If (Not m.AddLink(sDefSection, "A/D Converter Interrupt Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "A/D Converter Kernel Register", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Register Set in Compatibility Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Register Set in Enhanced Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "ADC Module Implementation", , True)) Then Exit Function

  sDefSection = "ADC"
  If (Not m.AddMenu("ADC\NormalControl")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Mode Selection and Operation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Fixed Channel Conversion Modes")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Auto Scan Conversion Modes")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Wait for DAT Read Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Channel Injection Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Standard Conversion Timing Control", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Improved Conversion Timing Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Power-Up Calibration")) Then Exit Function
         If (Not m.AddLink(sDefSection, "A/D Converter Interrupt Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "A/D Converter Kernel Register", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Register Set in Compatibility Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Register Set in Enhanced Mode")) Then Exit Function

  sDefSection = "ADC"
  If (Not m.AddMenu("ADC\EnhancedControl")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Mode Selection and Operation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Fixed Channel Conversion Modes")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Auto Scan Conversion Modes")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Wait for DAT Read Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Channel Injection Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Standard Conversion Timing Control", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Improved Conversion Timing Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Power-Up Calibration")) Then Exit Function
         If (Not m.AddLink(sDefSection, "A/D Converter Interrupt Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "A/D Converter Kernel Register", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Register Set in Compatibility Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Register Set in Enhanced Mode")) Then Exit Function

  sDefSection = "CCx"
  If (Not m.AddMenu("CCx\Channel_x")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Capture Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Compare Modes")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Double-Register Compare Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "I/O Control Register and Enhanced Features")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Single Event Mode")) Then Exit Function

  sDefSection = "CCx"
  If (Not m.AddMenu("CCx\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Capture/Compare Units 1/2")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Operational Overview")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Functional Overview", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "The Timers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer Interrupt")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Capture Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Compare Modes")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Double-Register Compare Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "I/O Control Register and Enhanced Features")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Node")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Single Event Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Registers", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupts", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "XC164 Module Implementation Details", , True)) Then Exit Function

  sDefSection = "SSC"
  If (Not m.AddMenu("SSCx\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "High-Speed Synchronous Serial Interface (SSC)")) Then Exit Function
         If (Not m.AddLink(sDefSection, "General Operation", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Operating Mode Selection")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Full-Duplex Operation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Half-Duplex Operation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Continuous Transfers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Baudrate Generation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Error Detection Mechanisms")) Then Exit Function
         If (Not m.AddLink(sDefSection, "SSC Kernel Registers", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupts", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "XC164 Module Implementation Details", , True)) Then Exit Function

  sDefSection = "GPT1"
  If (Not m.AddMenu("GPT1\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "General Purpose Timer Unit")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Functional Description of Timer Block 1", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Core Timer T3")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Auxiliary Timers T2 and T4")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer Concatenation", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interfaces of the GPT12E Module", , True)) Then Exit Function

  sDefSection = "GPT2"
  If (Not m.AddMenu("GPT2\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "General Purpose Timer Unit")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Functional Description of Timer Block 2", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Auxiliary Timer T5")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Core Timer T6")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer Concatenation", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interfaces of the GPT12E Module", , True)) Then Exit Function

  sDefSection = "ASC"
  If (Not m.AddMenu("ASCx\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Asynchronous/Synchronous Serial Interface (ASC)")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Operational Overview")) Then Exit Function
         If (Not m.AddLink(sDefSection, "General Operation", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Asynchronous Operation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "RXD/TXD Data Path Selection in Asynchronous Modes")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Synchronous Operation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Baudrate Generation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Autobaud Detection")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Hardware Error Detection Capabilities")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Registers", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupts", , True)) Then Exit Function

  sDefSection = "ASC"
  If (Not m.AddMenu("ASCx\BaudRateTable")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Autobaud Detection")) Then Exit Function

  sDefSection = "CAN"
  If (Not m.AddMenu("CAN\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "TwinCAN Module")) Then Exit Function
         If (Not m.AddLink(sDefSection, "TwinCAN Control Shell")) Then Exit Function
         If (Not m.AddLink(sDefSection, "CAN Node Control Logic")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Message Handling Unit")) Then Exit Function
         If (Not m.AddLink(sDefSection, "CAN Message Object Buffer (FIFO)")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Gateway Message Handling")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Programming the TwinCAN Module")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Loop-back Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Single Transmission Try Functionality")) Then Exit Function
         If (Not m.AddLink(sDefSection, "TwinCAN Register Description", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "XC164 Module Implementation Details", , True)) Then Exit Function

  sDefSection = "CAN"
  If (Not m.AddMenu("CAN\Nodex")) Then Exit Function
         If (Not m.AddLink(sDefSection, "CAN Node Control Logic")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Message Handling Unit")) Then Exit Function
         If (Not m.AddLink(sDefSection, "CAN Message Object Buffer (FIFO)")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Gateway Message Handling")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Programming the TwinCAN Module")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Loop-back Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Single Transmission Try Functionality")) Then Exit Function
         If (Not m.AddLink(sDefSection, "TwinCAN Register Description", , True)) Then Exit Function

  sDefSection = "CAN"
  If (Not m.AddMenu("CAN\Objx")) Then Exit Function
         If (Not m.AddLink(sDefSection, "CAN Node Control Logic")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Message Handling Unit")) Then Exit Function
         If (Not m.AddLink(sDefSection, "CAN Message Object Buffer (FIFO)")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Gateway Message Handling")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Programming the TwinCAN Module")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Single Transmission Try Functionality")) Then Exit Function
         If (Not m.AddLink(sDefSection, "TwinCAN Register Description", , True)) Then Exit Function

  sDefSection = "CC6"
  If (Not m.AddMenu("CC6\Dialog")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Capture/Compare Unit 6 (CCU6)")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer T12", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer T13")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Multi-channel Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Trap Handling")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Modulation Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Hall Sensor Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Generation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Suspend Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer12 - Related Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer13 - Related Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Capture/Compare Control Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Modulation Control Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Control Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Pegasus Module Implementation Details", , True)) Then Exit Function

  sDefSection = "CC6"
  If (Not m.AddMenu("CC6\CC6_CHANNEL_012")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Capture/Compare Unit 6 (CCU6)")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer T12", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Multi-channel Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Modulation Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Hall Sensor Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Generation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Suspend Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer12 - Related Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer13 - Related Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Capture/Compare Control Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Modulation Control Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Control Registers")) Then Exit Function

  sDefSection = "CC6"
  If (Not m.AddMenu("CC6\CC6_CHANNEL_3")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Capture/Compare Unit 6 (CCU6)")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer T13", , True)) Then Exit Function
         If (Not m.AddLink(sDefSection, "Multi-channel Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Modulation Control")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Hall Sensor Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Generation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Suspend Mode")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer12 - Related Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Timer13 - Related Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Capture/Compare Control Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Modulation Control Registers")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Control Registers")) Then Exit Function

  sDefSection = "CC6"
  If (Not m.AddMenu("CC6\CC6_INERRUPT_NODE")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Generation")) Then Exit Function
         If (Not m.AddLink(sDefSection, "Interrupt Control Registers")) Then Exit Function
         
'  sDefSection = "LIN"
'  If (Not m.AddMenu("LIN\Dialog")) Then Exit Function

  InstallManualLinks = True
End Function


'*****************************************************************************
'*****************************************************************************
'                    Do not change the following code !!
'*****************************************************************************
'*****************************************************************************


'*****************************************************************************
' @bfunc   Public | AddInterrupt | |
'
'-----------------------------------------------------------------------------
'          This function adds a new interrupt source to a collection. Each
'          interrupt which should be displayed on the interrupt page must be
'          added with this function.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' @bparm   | c | DAvECollection | the interrupt collection
' @bparm   | IntName | String | name of the interrupt
' @bparm   | LevelName | String | name of the level bit field
' @bparm   | GroupName | String | name of the group bit field
' @bparm   | Enabled   | String | name of the enabled bit
' @bparm   | RegName           | String | name of the interrupt control register; now bit name
'
'*****************************************************************************
Public Function AddInterrupt(c As DAvECollection, IntName As String, LevelName As String, GroupName As String, Enabled As String, RegName As String) As Boolean
  On Error Resume Next
  AddInterrupt = False

  Dim ir As InterruptClass

  Set ir = New InterruptClass
  ir.LevelName = LevelName
  ir.GroupName = GroupName
  ir.IntName = IntName
  ir.Enabled = Enabled
  ir.RegName = Enabled
  
  'ahe 07.08.2002
  ir.GPXName = RegName & "_GPX"

  c.Add ir, IntName

  AddInterrupt = True
End Function


'*****************************************************************************
' @bfunc   Public | AddModule | Boolean |
'
'-----------------------------------------------------------------------------
'          This function adds a new module to a collection. Each module which
'          should be used in the system must be added with this function.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' @bparm   | c | DAvECollection | the module collection
' @bparm   | ModuleName | String | identifier of the module
' @bparm   | ModuleDescription | String | name of the module
' @bparm   | ModuleDirectory   | String  | sub directory name of this module
' @bparm   | ParameterValue    | Variant | a parameter for the new script file
' @bparm   | ModuleWithCG      | Boolean | indicates if the module has an codegenerator or not
'
'*****************************************************************************
Public Function AddModule(c As DAvECollection, ModuleName As String, ModuleDescription As String, _
                          ModuleDirectory As String, ParameterValue As Variant, Optional ModuleWithCG As Boolean = True) As Boolean
  On Error GoTo AddModuleError
  AddModule = False

  Dim mo As ModuleClass

  Set mo = New ModuleClass
  mo.ModuleName = ModuleName
  mo.ModuleDescription = ModuleDescription
  mo.ModuleDirectory = ModuleDirectory
  mo.ParameterValue = ParameterValue
  mo.ModuleWithCG = ModuleWithCG
  c.Add mo, ModuleName

  AddModule = True
  Exit Function

AddModuleError:
  ErrorBox "Can not install modules", Err.Description
  Exit Function
End Function


'*****************************************************************************
' @bfunc   Public | AddPort | Boolean |
'
'-----------------------------------------------------------------------------
'          This function adds a new Port to a collection. Each Port which
'          should be used in the system must be added with this function.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' @bparm   | p                   | DAvECollection | the port collection
' @bparm   | vPortNumber         | Variant | number of the port
' @bparm   | sPortDescription    | String  | name of the port (description)
' @bparm   | iFirstPin           | Integer | number of the first pin that should be shown in the mask
' @bparm   | iLastPin            | Integer | number of the last pin that should be shown in the mask
' @bparm   | iInputThresholdType | Integer | the input threshold type can be configured pin- (1), nible- (2),
'                                            byte- (3) or port-wise (4)
' @bparm   | iOutputEdgeType     | Integer | the output edge characteristic can be configured pin- (1), nible- (2),
'                                            byte- (3) or port-wise (4)
' @bparm   | iOutputDriverType   | Integer | the output driver characteristic can be configured pin- (1), nible- (2),
'                                            byte- (3) or port-wise (4)
'
'*****************************************************************************
Public Function AddPort(p As DAvECollection, vPortNumber As Variant, sPortDescription As String, iFirstPin As Integer, _
                        iLastPin As Integer, Optional iInputThresholdType As Integer = 0, Optional iOutputEdgeType As Integer = 0, _
                        Optional iOutputDriverType As Integer = 0) As Boolean
  On Error Resume Next
  AddPort = False

  Dim newPort As Port

  Set newPort = New Port

  newPort.PortNumber = vPortNumber
  newPort.Description = sPortDescription
  newPort.FirstPin = iFirstPin
  newPort.LastPin = iLastPin

  newPort.InputThresholdType = iInputThresholdType
  newPort.OutputEdgeType = iOutputEdgeType
  newPort.OutputDriverType = iOutputDriverType

  p.Add newPort, "P" & vPortNumber

  AddPort = True
End Function


'*****************************************************************************
' @bfunc   Public | AddPin | Boolean |
'
'-----------------------------------------------------------------------------
'          This function adds a new Pin to the system. Each Pin which
'          should be used in the system must be added with this function.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' p          object of the class for the port pins
' vPort      number of the port
' iPin       number of the pin
' bUse       flag that shows if the pin is availible
' bExclusive flag that shows if the pin should be used exclusive
'
'*****************************************************************************
Public Function AddPin(p As PortPin, vPort As Variant, iPin As Integer, bUse As Boolean, Optional bExclusive As Boolean = False) As Boolean
  On Error Resume Next
  AddPin = False

  Dim s As String

  If bUse Then
    s = "Use P" & vPort & "." & iPin & " as general IO"
  Else
    s = "P" & vPort & "." & iPin & " no pin assigned"
  End If
        If (Not p.Add("P" & vPort & "_" & iPin, vPort, iPin, s, bUse, bExclusive)) Then Exit Function

  AddPin = True
End Function


'*****************************************************************************
' @bfunc   Public | AddAlternateName | Boolean |
'
'-----------------------------------------------------------------------------
'          This function adds a new alternate name to a Pin. Each alternate
'          name which should be used in the system must be added with this
'          function.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    True |
' @flag    False|
'
'-----------------------------------------------------------------------------
' @bparm   | p     | PortPin | object of the class for the port pins
' @bparm   | sAlternateName | String | alternate name of a pin (used as identifier)
' @bparm   | sDescription | String | description of the alternate pin function
'        bExclusive      flag that shows if the pin should be used exclusive
'        iFunction       number of the alternate output function of this pin
'                        (used for the ALTSEL registers), -1 means the pin is input
'
'*****************************************************************************
Public Function AddAlternateName(p As PortPin, sAlternateName As String, sDescription As String, _
                                 Optional bExclusive As Boolean = False, Optional iFunction As Integer = -1) As Boolean
  On Error Resume Next
  AddAlternateName = False

        If (Not p.AddAlternateName(sAlternateName, sDescription, bExclusive, iFunction)) Then Exit Function

  AddAlternateName = True
End Function
