'#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:
'        ADC
'-----------------------------------------------------------------------------
' 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 C161JC
'             
'
'
'*****************************************************************************


'*****************************************************************************
' @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, "SSC", "High-Speed Synchronous Serial Interface (SSC)", "SSC", "", 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, "EBC", "External Bus Controller (EBC)", "EBC", "", False)) 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, "RTC", "Real Timer Clock (RTC)", "RTC", "", True)) Then Exit Function
  If (Not AddModule(d, "OSC", "OSC / PLL (OSC)", "OSC", "", True)) Then Exit Function
  If (Not AddModule(d, "ADC", "Analog / Digital Converter (ADC)", "ADC", "", True)) Then Exit Function
  If (Not AddModule(d, "CC1", "Capture / Compare Unit 1 (CAPCOM1)", "CAPCOMx", 1, True)) Then Exit Function
  If (Not AddModule(d, "CC2", "Capture / Compare Unit 2 (CAPCOM2)", "CAPCOMx", 2, True)) Then Exit Function
  If (Not AddModule(d, "ASC1", "Asynchronous/Synchronous Serial Interface (ASC1)", "ASC1", 1, True)) Then Exit Function
  If (Not AddModule(d, "CAN1", "On-Chip CAN Interface 1 (CAN1)", "CANx", 1, True)) Then Exit Function
  If (Not AddModule(d, "I2C", "On-Chip I2C Bus Interface (I2C)", "I2C", "", True)) Then Exit Function
  If (Not AddModule(d, "SDLM", "Serial Data Link Module (SDLM)", "SDLM", "", True)) Then Exit Function
  If (Not AddModule(d, "PM", "Power Management (PM)", "PM", "", 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("IO", DefGetPath("Bitmaps") & "IO.bmp", 122, 300, 203, 324, 271, 42)) Then Exit Function

    if (Not gc.AddHotspot("I2C", DefGetPath("Bitmaps") & "I2C.bmp",    60, 60,  113,  91, 47, 30)) Then Exit Function
    if (Not gc.AddHotspot("ASC1", DefGetPath("Bitmaps") & "ASC1.bmp",  60, 80,  113, 124, 47, 30)) Then Exit Function
    if (Not gc.AddHotspot("SDLM", DefGetPath("Bitmaps") & "SDLM.bmp",  60, 120, 113, 156, 47, 30)) Then Exit Function
    if (Not gc.AddHotspot("CAN1", DefGetPath("Bitmaps") & "CAN1.bmp",  60, 150, 113, 188, 47, 30)) Then Exit Function

    if (Not gc.AddHotspot("EBC", DefGetPath("Bitmaps") & "EBC.bmp",    79, 189, 130, 228, 40, 70)) Then Exit Function
    if (Not gc.AddHotspot("ADC", DefGetPath("Bitmaps") & "ADC.bmp",   130, 189, 179, 228, 40, 70)) Then Exit Function
    if (Not gc.AddHotspot("GPT1", DefGetPath("Bitmaps") & "GPT1.bmp", 200, 179, 233, 228, 45, 34)) Then Exit Function
    if (Not gc.AddHotspot("GPT2", DefGetPath("Bitmaps") & "GPT2.bmp", 180, 201, 232, 263, 45, 34)) Then Exit Function
    if (Not gc.AddHotspot("ASC0", DefGetPath("Bitmaps") & "ASC0.bmp",  247, 170, 303, 228, 40, 70)) Then Exit Function
    if (Not gc.AddHotspot("SSC", DefGetPath("Bitmaps") & "SSC.bmp",    289, 170, 352, 228, 40, 70)) Then Exit Function
    if (Not gc.AddHotspot("CC1", DefGetPath("Bitmaps") & "CAPCOM1.bmp", 341, 169, 401, 228, 40, 70)) Then Exit Function
    if (Not gc.AddHotspot("CC2", DefGetPath("Bitmaps") & "CAPCOM2.bmp", 399, 170, 450, 228, 40, 70)) Then Exit Function
    if (Not gc.AddHotspot("PM", DefGetPath("Bitmaps") & "PM.bmp",      450, 140, 518, 172, 45, 28)) Then Exit Function
    if (Not gc.AddHotspot("OSC", DefGetPath("Bitmaps") & "OSC.bmp",    448, 109, 518, 140, 45, 28)) Then Exit Function
    if (Not gc.AddHotspot("RTC", DefGetPath("Bitmaps") & "RTC.bmp",    449, 81, 518, 108, 45, 28)) Then Exit Function
    if (Not gc.AddHotspot("WDT", DefGetPath("Bitmaps") & "WDT.bmp",    451, 50, 518, 76, 45, 28)) Then Exit Function
    if (Not gc.AddHotspot("INT", DefGetPath("Bitmaps") & "INT.bmp",    209, 121, 277, 159, 121, 28)) 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 insert 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 = "T2IC"
  If (Not AddInterrupt(c, "GPT1 Timer 2 INT", v & "_ILVL", v & "_GLVL", v & "_T2IE", "T2IE")) Then Exit Function  
  v = "T3IC"
  If (Not AddInterrupt(c, "GPT1 Timer 3 INT", v & "_ILVL", v & "_GLVL", v & "_T3IE", "T3IE")) Then Exit Function  
  v = "T4IC"
  If (Not AddInterrupt(c, "GPT1 Timer 4 INT", v & "_ILVL", v & "_GLVL", v & "_T4IE", "T4IE")) Then Exit Function  

  'GPT2 Interrupts
  v = "CRIC"
  If (Not AddInterrupt(c, "GPT2 CAPREL INT", v & "_ILVL", v & "_GLVL", v & "_CRIE", "CRIE")) Then Exit Function  
  v = "T5IC"
  If (Not AddInterrupt(c, "GPT2 Timer 5 INT", v & "_ILVL", v & "_GLVL", v & "_T5IE", "T5IE")) Then Exit Function  
  v = "T6IC"
  If (Not AddInterrupt(c, "GPT2 Timer 6 INT", v & "_ILVL", v & "_GLVL", v & "_T6IE", "T6IE")) Then Exit Function  


  ' SSC Interrupts
  v = "SSCEIC"
  If (Not AddInterrupt(c, "SSC error INT", v & "_ILVL", v & "_GLVL" , v & "_SSCEIE", "SSCEIE")) Then Exit Function
  v = "SSCRIC"
  If (Not AddInterrupt(c, "SSC Rx INT", v & "_ILVL", v & "_GLVL", v & "_SSCRIE", "SSCRIE")) Then Exit Function
  v = "SSCTIC"
  If (Not AddInterrupt(c, "SSC Tx INT", v & "_ILVL", v & "_GLVL", v & "_SSCTIE", "SSCTIE")) Then Exit Function

  ' ASC0 Interrupts
  v = "S0EIC"
  If (Not AddInterrupt(c, "ASC0 error INT", v & "_ILVL", v & "_GLVL" , v & "_S0EIE", "S0EIE")) Then Exit Function
  v = "S0RIC"
  If (Not AddInterrupt(c, "ASC0 Rx INT", v & "_ILVL", v & "_GLVL", v & "_S0RIE", "S0RIE")) Then Exit Function
  v = "S0TIC"
  If (Not AddInterrupt(c, "ASC0 Tx INT", v & "_ILVL", v & "_GLVL", v & "_S0TIE", "S0TIE")) Then Exit Function
  v = "S0TBIC"
  If (Not AddInterrupt(c, "ASC0 Tx buffer INT", v & "_ILVL", v & "_GLVL", v & "_S0TBIE", "S0TBIE")) Then Exit Function

  ' ASC1 Interrupts
  v = "XP6IC"
  If (Not AddInterrupt(c, "ASC1 error INT", v & "_ILVL", v & "_GLVL" , v & "_XP6IE", "XP6IE")) Then Exit Function
  v = "XP5IC"
  If (Not AddInterrupt(c, "ASC1 Rx INT", v & "_ILVL", v & "_GLVL", v & "_XP5IE", "XP5IE")) Then Exit Function
  v = "XP4IC"
  If (Not AddInterrupt(c, "ASC1 Tx INT", v & "_ILVL", v & "_GLVL", v & "_XP4IE", "XP4IE")) Then Exit Function

  ' Fast Ext. Interrupts
  For i = 0 To 7
    v = "CC" & i + 8 & "IC"
    If (Not AddInterrupt(c, "Ext " & i & " _ CC1 Ch " & i + 8 & " INT", v & "_ILVL", v & "_GLVL" , v & "_CC" & i + 8 & "IE", "CC" & i + 8 & "IE")) Then Exit Function
  Next i

  'RTC Interrupt
  v = "XP3IC"
  If (Not AddInterrupt(c, "RTC_PLL_OWD INT", v & "_ILVL", v & "_GLVL" , v & "_XP3IE", "XP3IE")) Then Exit Function

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

  v = "ADEIC"
  If (Not AddInterrupt(c, "ADC Error INT", v & "_ILVL", v & "_GLVL" , v & "_ADEIE", "ADEIE")) Then Exit Function

  'CC timer Interrupts
  v = "T0IC"
  If (Not AddInterrupt(c, "CC1 Timer 0 INT", v & "_ILVL", v & "_GLVL" , v & "_T0IE", "T0IE")) Then Exit Function

  v = "T1IC"
  If (Not AddInterrupt(c, "CC1 Timer 1 INT", v & "_ILVL", v & "_GLVL" , v & "_T1IE", "T1IE")) Then Exit Function

  v = "T7IC"
  If (Not AddInterrupt(c, "CC2 Timer 7 INT", v & "_ILVL", v & "_GLVL" , v & "_T7IE", "T7IE")) Then Exit Function

  v = "T8IC"
  If (Not AddInterrupt(c, "CC2 Timer 8 INT", v & "_ILVL", v & "_GLVL" , v & "_T8IE", "T8IE")) Then Exit Function

  'CCx Interrupts
  For i = 0 To 7
      v = "CC" & i & "IC"
      If (Not AddInterrupt(c, "CC1 Channel " & i & " INT", v & "_ILVL", v & "_GLVL" , v & "_CC" & i & "IE", "CC" & i & "IE")) Then Exit Function
  Next i

  For i = 16 To 31
      v = "CC" & i & "IC"
      If (Not AddInterrupt(c, "CC2 Channel " & i & " INT", v & "_ILVL", v & "_GLVL" , v & "_CC" & i & "IE", "CC" & i & "IE")) Then Exit Function
  Next i

  'CAN Interrupt
  v = "XP2IC"
  If (Not AddInterrupt(c, "CAN1 INT", v & "_ILVL", v & "_GLVL" , v & "_XP2IE", "XP2IE")) Then Exit Function

  'I2C Interrupts
  v = "XP0IC"
  If (Not AddInterrupt(c, "I2C DataTransfer INT", v & "_ILVL", v & "_GLVL" , v & "_XP0IE", "XP0IE")) Then Exit Function
  v = "XP1IC"
  If (Not AddInterrupt(c, "I2C Protocol INT", v & "_ILVL", v & "_GLVL" , v & "_XP1IE", "XP1IE")) Then Exit Function

'  v = "XP1IC"
'  If (Not AddInterrupt(c, "CAN2 INT", v & "_ILVL", v & "_GLVL" , v & "_XP1IE", "XP1IE")) Then Exit Function

  'SDLM Interrupt
  v = "XP7IC"
  If (Not AddInterrupt(c, "SDLM INT", v & "_ILVL", v & "_GLVL" , v & "_XP7IE", "XP7IE")) Then Exit Function


  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, 0, "Port 0", 0, 15, 4, 4, 4)) Then Exit Function


  If (Not AddPort (cPorts, "0H", "Port 0H", 0, 7,  0, 2, 2)) Then Exit Function
  If (Not AddPort (cPorts, "0L", "Port 0L", 0, 7,  0, 2, 2)) Then Exit Function
  If (Not AddPort (cPorts, "1H", "Port 1H", 0, 7,  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, 2, "Port 2",     8, 15, 3, 2, 2)) Then Exit Function
  If (Not AddPort (cPorts, 3, "Port 3",     0, 15, 3, 2, 2)) Then Exit Function
  If (Not AddPort (cPorts, 4, "Port 4",     0, 7,  0, 2, 2)) Then Exit Function
  If (Not AddPort (cPorts, 5, "Port 5",     0, 15, 0, 0, 0)) Then Exit Function
  If (Not AddPort (cPorts, 6, "Port 6",     0, 7,  3, 2, 2)) Then Exit Function
  If (Not AddPort (cPorts, 7, "Port 7",     4, 7,  3, 2, 2)) Then Exit Function
  If (Not AddPort (cPorts, 9, "Port 9",     0, 5,  0, 0, 0)) 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 0L
  '---------------------------------------------------------------------------------------------
  For i = 0 To 7
    If (Not AddPin(p, "0L", i, True, True)) Then Exit Function
      If (Not AddAlternateName(p, "AD" & i, "Port Pin (AD" & i & ")", True, 0)) Then Exit Function
  Next i

  '---------------------------------------------------------------------------------------------
  'Port 0H
  '---------------------------------------------------------------------------------------------
  For i = 0 To 7
    If (Not AddPin(p, "0H", i, True, True)) Then Exit Function
      If (Not AddAlternateName(p, "AD" & i + 8, "Port Pin (AD" & i + 8 & ")", True, 0)) Then Exit Function
  Next i

  '---------------------------------------------------------------------------------------------
  'Port 1L
  '---------------------------------------------------------------------------------------------
  For i = 0 To 7
    If (Not AddPin(p, "1L", i, True, True)) Then Exit Function
      If (Not AddAlternateName(p, "A" & i, "Port Pin (A" & i & ")", True, 0)) Then Exit Function
  Next i

  '---------------------------------------------------------------------------------------------
  'Port 1H
  '---------------------------------------------------------------------------------------------
  For i = 0 To 3
    If (Not AddPin(p, "1H", i, True, True)) Then Exit Function
      If (Not AddAlternateName(p, "A" & i + 8, "Port Pin (A" & i + 8 & ")", True, 0)) Then Exit Function
  Next i

  For i = 4 To 7
    If (Not AddPin(p, "1H", i, True, True)) Then Exit Function
      If (Not AddAlternateName(p, "A" & i + 8, "Port Pin (A" & i + 8 & ")", True, 0)) Then Exit Function
      If (Not AddAlternateName(p, "CC" & i + 20 & "IO_I", "CAPCOM2 Input (CC" & i + 20 & "IO)", True)) Then Exit Function
      If (Not AddAlternateName(p, "CC" & i + 20 & "IO_O", "CAPCOM2 Output (CC" & i + 20 & "IO)", True, 0)) Then Exit Function
  Next i

  '---------------------------------------------------------------------------------------------
  'Port 2
  '---------------------------------------------------------------------------------------------
  For i = 8 To 14
    If (Not AddPin(p, 2, i, True, True)) Then Exit Function
      If (Not AddAlternateName(p, "CC" & i & "IO_I", "CAPCOM1 Input (CC" & i & "IO)", True)) Then Exit Function
      If (Not AddAlternateName(p, "CC" & i & "IO_O", "CAPCOM1 Output (CC" & i & "IO)", True, 0)) Then Exit Function
      If (Not AddAlternateName(p, "EX" & i - 8 & "IN", "Fast External Interrupt " & i - 8 & " Input (EX" & i - 8 & "IN)", True)) Then Exit Function
  Next i

  i = 15
    If (Not AddPin(p, 2, i, True, True)) Then Exit Function
      If (Not AddAlternateName(p, "CC" & i & "IO_I", "CAPCOM1 Input (CC" & i & "IO)", True)) Then Exit Function
      If (Not AddAlternateName(p, "CC" & i & "IO_O", "CAPCOM1 Output (CC" & i & "IO)", True, 0)) Then Exit Function
      If (Not AddAlternateName(p, "EX" & i - 8 & "IN", "Fast External Interrupt " & i - 8 & " Input (EX" & i - 8 & "IN)", True)) Then Exit Function
      If (Not AddAlternateName(p, "T7IN", "CAPCOM2 Timer T7 Input (T7IN)", True)) Then Exit Function

  '---------------------------------------------------------------------------------------------
  'Port 3
  '---------------------------------------------------------------------------------------------
  If (Not AddPin(p, 3, 0, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "T0IN", "Timer 0 Count Input (T0IN)", True)) Then Exit Function
  	 If (Not AddAlternateName(p, "TxD1", "ASC1 Transmit Data Output (TxD1)", True, 0)) 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, 0)) Then Exit Function
  	 If (Not AddAlternateName(p, "RxD1_O", "ASC1 Receive data Output (RxD1)", True, 0)) Then Exit Function
     If (Not AddAlternateName(p, "RxD1_I", "ASC1 Receive data Input (RxD1)", 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 Output (T3OUT)", True, 0)) Then Exit Function

  If (Not AddPin(p, 3, 4, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "T3EUD", "Timer 3 Count Input (T3EUD)", False)) Then Exit Function
  	 If (Not AddAlternateName(p, "T3EUD_CAP", "Capture Input (T3EUD)", False)) 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 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 AddAlternateName(p, "T3IN_CAP", "Capture 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, "MRST_I", "SSC Master Receive (MRST)", True)) Then Exit Function
  	 If (Not AddAlternateName(p, "MRST_O", "SSC Slave Transmit (MRST)", True, 0)) Then Exit Function

  If (Not AddPin(p, 3, 9, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "MTSR_I", "SSC Slave Receive (MTSR)", True)) Then Exit Function
  	 If (Not AddAlternateName(p, "MTSR_O", "SSC Master Transmit (MTSR)", True, 0)) Then Exit Function

  If (Not AddPin(p, 3, 10, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "TxD0", "ASC Transmit Data Output (TxD0)", True, 0)) Then Exit Function

  If (Not AddPin(p, 3, 11, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "RxD0_O", "ASC Receive data Output (RxD0)", True, 0)) Then Exit Function
     If (Not AddAlternateName(p, "RxD0_I", "ASC Receive data Input (RxD0)", True)) Then Exit Function

  If (Not AddPin(p, 3, 12, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "BHE_n", "Byte High Enable Output (BHE_n)", True, 0)) Then Exit Function
  	 If (Not AddAlternateName(p, "WRH_n", "Write High Output (WRH_n)", True, 0)) Then Exit Function

  If (Not AddPin(p, 3, 13, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "SCLK_I", "SSC Shift Clock Input (SCLK)", True)) Then Exit Function
  	 If (Not AddAlternateName(p, "SCLK_O", "SSC Shift Clock Output (SCLK)", True, 0)) 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 4
  '---------------------------------------------------------------------------------------------
  If (Not AddPin(p, 4, 0, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "A16", "Port Pin (A16)", True, 0)) Then Exit Function
  If (Not AddPin(p, 4, 1, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "A17", "Port Pin (A17)", True, 0)) Then Exit Function
  If (Not AddPin(p, 4, 2, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "A18", "Port Pin (A18)", True, 0)) Then Exit Function
  If (Not AddPin(p, 4, 3, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "A19", "Port Pin (A19)", True, 0)) Then Exit Function
  
  If (Not AddPin(p, 4, 4, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "A20", "Port Pin (A20)", True, 0)) Then Exit Function
    If (Not AddAlternateName(p, "SDL_RxD_0", "SDLM Interface Input (SDL_RxD)", True)) Then Exit Function
 
  If (Not AddPin(p, 4, 5, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "A21", "Port Pin (A21)", True, 0)) Then Exit Function
    If (Not AddAlternateName(p, "CAN1_RxD_1", "CAN1 Interface Input (CAN1_RxD)", True)) Then Exit Function
  
  If (Not AddPin(p, 4, 6, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "A22", "Port Pin (A22)", True, 0)) Then Exit Function
    If (Not AddAlternateName(p, "CAN1_TxD_1", "CAN1 Interface Output (CAN1_TxD)", True, 0)) Then Exit Function
    If (Not AddAlternateName(p, "SDL_RxD_1", "SDLM Interface Input (SDL_RxD)", True)) Then Exit Function
  
  If (Not AddPin(p, 4, 7, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "A23", "Port Pin (A23)", True, 0)) Then Exit Function
    If (Not AddAlternateName(p, "CAN1_RxD_0", "CAN1 Interface Input (CAN1_RxD)", True)) Then Exit Function
    If (Not AddAlternateName(p, "SDL_TxD_1", "SDLM Interface Output (SDL_TxD)", 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 11
      If (Not AddPin(p, 5, i, False, True)) Then Exit Function
  Next i

  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 6
  '---------------------------------------------------------------------------------------------
  If (Not AddPin(p, 6, 0, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CS0_n", "Chip select (CS0_n)", True, 0)) Then Exit Function
  If (Not AddPin(p, 6, 1, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CS1_n", "Chip select (CS1_n)", True, 0)) Then Exit Function
  If (Not AddPin(p, 6, 2, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CS2_n", "Chip select (CS2_n)", True, 0)) Then Exit Function
  If (Not AddPin(p, 6, 3, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CS3_n", "Chip select (CS3_n)", True, 0)) Then Exit Function
  If (Not AddPin(p, 6, 4, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CS4_n", "Chip select (CS4_n)", True, 0)) Then Exit Function
  If (Not AddPin(p, 6, 5, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "HOLD_n", "External hold request input (HOLD_n)", True)) Then Exit Function
  If (Not AddPin(p, 6, 6, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "HLDA_n_I", "Hold acknowledge input (HLDA_n)", True)) Then Exit Function
    If (Not AddAlternateName(p, "HLDA_n_O", "Hold acknowledge output (HLDA_n)", True, 0)) Then Exit Function
  If (Not AddPin(p, 6, 7, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "BREQ_n", "Bus request output (BREQ_n)", True, 0)) Then Exit Function

  '---------------------------------------------------------------------------------------------
  'Port 7
  '---------------------------------------------------------------------------------------------
  i = 4
  If (Not AddPin(p, 7, i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CC" & i + 24 & "IO_O", "Capture output " & i + 24 & " (CC" & i + 24 & "IO)", True, 0)) Then Exit Function
    If (Not AddAlternateName(p, "CC" & i + 24 & "IO_I", "Capture input " & i + 24 & " (CC" & i + 24 & "IO)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CAN1_RxD_2", "CAN1 Interface Input (CAN1_RxD)", True)) Then Exit Function
    If (Not AddAlternateName(p, "SDL_TxD_2", "SDLM Interface Output (SDL_TxD)", True, 0)) Then Exit Function

  i = 5
  If (Not AddPin(p, 7, i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CC" & i + 24 & "IO_O", "Capture output " & i + 24 & " (CC" & i + 24 & "IO)", True, 0)) Then Exit Function
    If (Not AddAlternateName(p, "CC" & i + 24 & "IO_I", "Capture input " & i + 24 & " (CC" & i + 24 & "IO)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CAN1_TxD_2", "CAN1 Interface Output (CAN1_TxD)", True, 0)) Then Exit Function
    If (Not AddAlternateName(p, "SDL_RxD_2", "SDLM Interface Input (SDL_RxD)", True)) Then Exit Function

  i = 6
  If (Not AddPin(p, 7, i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CC" & i + 24 & "IO_O", "Capture output " & i + 24 & " (CC" & i + 24 & "IO)", True, 0)) Then Exit Function
    If (Not AddAlternateName(p, "CC" & i + 24 & "IO_I", "Capture input " & i + 24 & " (CC" & i + 24 & "IO)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CAN1_RxD_3", "CAN1 Interface Input (CAN1_RxD)", True)) Then Exit Function
    If (Not AddAlternateName(p, "SDL_TxD_3", "SDLM Interface Output (SDL_TxD)", True, 0)) Then Exit Function

  i = 7
  If (Not AddPin(p, 7, i, True, True)) Then Exit Function
    If (Not AddAlternateName(p, "CC" & i + 24 & "IO_O", "Capture output " & i + 24 & " (CC" & i + 24 & "IO)", True, 0)) Then Exit Function
    If (Not AddAlternateName(p, "CC" & i + 24 & "IO_I", "Capture input " & i + 24 & " (CC" & i + 24 & "IO)", True)) Then Exit Function
    If (Not AddAlternateName(p, "CAN1_TxD_3", "CAN1 Interface Output (CAN1_TxD)", True, 0)) Then Exit Function
    If (Not AddAlternateName(p, "SDL_RxD_3", "SDLM Interface Input (SDL_RxD)", True)) Then Exit Function

  
  '---------------------------------------------------------------------------------------------
  'Port 9
  '---------------------------------------------------------------------------------------------
  If (Not AddPin(p, 9, 0, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "SDA0", "I2C Serial Data Line 0 (SDA0)", True, 0)) Then Exit Function

  If (Not AddPin(p, 9, 1, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "SCL0", "I2C Serial Clock Line 0 (SCL0)", True, 0)) Then Exit Function

  If (Not AddPin(p, 9, 2, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "SDA1", "I2C Serial Data Line 1 (SDA1)", True, 0)) Then Exit Function

  If (Not AddPin(p, 9, 3, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "SCL1", "I2C Serial Clock Line 1 (SCL1)", True, 0)) Then Exit Function

  If (Not AddPin(p, 9, 4, True, True)) Then Exit Function
  	 If (Not AddAlternateName(p, "SDA2", "I2C Serial Data Line 2 (SDA2)", True, 0)) Then Exit Function
  
  If (Not AddPin(p, 9, 5, True, True)) 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 insert in this function.
'          For each Link in this menu a  
'          line ".. AddLink .." must be insert in this function.
'
'          Note:
'          For each added Link a entry with the link key must be insert 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 proberty 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, "System Reset")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Reset Sources")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Status After Reset")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Application-Specific Initialization Routine")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "System Startup Configuration", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "External Bus Type")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Write Configuration")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Chip Select Lines")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Segment Address Lines")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Clock Generation Control")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "System Startup Configuration upon a Single-Chip Mode Reset", , True)) Then Exit Function

  sDefSection = "ADC"
  If (Not m.AddMenu("ADC\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Analog / Digital Converter")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Mode Selection and Operation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Fixed Channel Conversion Modes", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Auto Scan Conversion Modes")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Wait for ADDAT Read Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Channel Injection Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Conversion Timing Control", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "A/D Converter Interrupt Control")) Then Exit Function


  sDefSection = "ASC0"
  If (Not m.AddMenu("ASCx\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Asynchronous/Synchronous Serial Interface")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Asynchronous Operation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Asynchronous Data Frames")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Synchronous Operation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Hardware Error Detection Capabilities")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "ASC0 Baud Rate Generation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "ASC0 Interrupt Control")) Then Exit Function

  sDefSection = "ASC1"
  If (Not m.AddMenu("ASC1\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Async./Synchronous Serial Interface ASC1")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "ASC1 versus ASC0")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Asynchronous Operation", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Synchronous Operation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Hardware Error Detection Capabilities")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "ASC1 Baud Rate Generation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "ASC1 Port Control", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "ASC1 Interrupt Control")) Then Exit Function

  sDefSection = "CAN"
  If (Not m.AddMenu("CANx\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The On-Chip CAN Interface")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Functional Blocks of the CAN Module")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "General Functional Description", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "CAN Interrupt Handling")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Configuration of the Bit Timing")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Mask Registers")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Message Object", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Arbitration Registers")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Message Configuration")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Data Area")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Controlling the CAN Module", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Configuration Examples for Message Objects")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Second CAN Module CAN2")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The CAN Application Interface", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port Control")) Then Exit Function

  sDefSection = "Object_x"
  If (Not m.AddMenu("CANx\Object_x")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Message Object")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Arbitration Registers")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Message Configuration")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Data Area")) Then Exit Function

  sDefSection = "CAPCOM"
  If (Not m.AddMenu("CAPCOMx\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Capture / Compare Units")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The CAPCOM Timers")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer Mode", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Counter Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Reload")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "CAPCOM Unit Timer Interrupts", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Capture/Compare Registers")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Capture Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Compare Modes", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Compare Mode 0")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Compare Mode 1")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Compare Mode 2")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Compare Mode 3")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Capture/Compare Interrupts", , True)) Then Exit Function

  sDefSection = "Channel_x"
  If (Not m.AddMenu("CAPCOMx\Channel_x")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Capture / Compare Units")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Capture/Compare Registers")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Capture Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Compare Modes", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Compare Mode 0")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Compare Mode 1")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Compare Mode 2")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Compare Mode 3")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Capture/Compare Interrupts", , True)) Then Exit Function

  sDefSection = "EBC"
  If (Not m.AddMenu("EBC\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The External Bus Interface")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Single Chip Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "External Bus Modes")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Programmable Bus Characteristics", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "ALE Length Control")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Programmable Memory Cycle Time")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Programmable Memory Tri-State Time")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Read/Write Signal Delay")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Early #WR Signal Deactivation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "#READY Controlled Bus Cycles", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Controlling the External Bus Controller")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Definition of Address Areas")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Address Window Arbitration")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "EBC Idle State", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "External Bus Arbitration")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The XBUS Interface")) Then Exit Function

  sDefSection = "GPT1"
  If (Not m.AddMenu("GPT1\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The General Purpose Timer Units")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer Block GPT1")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "GPT1 Core Timer T3", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer 3 Run Bit")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Count Direction Control")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer 3 Output Toggle Latch")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer 3 in Timer Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer 3 in Gated Timer Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer 3 in Counter Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer 3 in Incremental Interface Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "GPT1 Auxiliary Timers T2 and T4", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Count Direction Control for Auxiliary Timers")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timers T2 and T4 in Timer Mode or Gated Timer Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timers T2 and T4 in Incremental Interface Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timers T2 and T4 in Counter Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer Concatenation", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Auxiliary Timer in Reload Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Auxiliary Timer in Capture Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Control for GPT1 Timers", , True)) Then Exit Function

  sDefSection = "GPT2"
  If (Not m.AddMenu("GPT2\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The General Purpose Timer Units")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer Block GPT2")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "GPT2 Core Timer T6", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer 6 Run Bit")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer 6 Output Toggle Latch")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer 6 in Timer Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer 6 in Gated Timer Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer 6 in Counter Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "GPT2 Auxiliary Timer T5", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer T5 in Timer Mode or Gated Timer Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer T5 in Counter Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Timer Concatenation", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "GPT2 Capture/Reload Register CAPREL in Capture Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "GPT2 Capture/Reload Register CAPREL in Reload Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "GPT2 Capture/Reload Register CAPREL in Capture-And-Reload Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Control for GPT2 Timers and CAPREL", , 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, "Normal Interrupt Processing")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Processing via the Peripheral Event Controller (PEC)")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Trap Functions")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "External Interrupt Processing")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt System Structure", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt System Register Description")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Control Registers")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Priority Level and Group Level")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Control Functions in the PSW")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "CPU Priority ILVL")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Enable bit IEN")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Operation of the PEC Channels", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The source and destination pointers")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Prioritization of Interrupt and PEC Service Requests", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Saving the Status during Interrupt Service")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Response Times", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "PEC Response Times")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Node Sharing")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "External Interrupts", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Fast External Interrupts")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "External Interrupt Source Control")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "External Interrupts During Sleep Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Trap Functions", , True)) 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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Alternate Port Functions", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 0", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 1")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 2")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 3")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 4")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 5")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 6")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 7")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 9")) Then Exit Function

  sDefSection = "Portx"
  If (Not m.AddMenu("IO\Port0L")) 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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 0", , True)) Then Exit Function

  sDefSection = "Portx"
  If (Not m.AddMenu("IO\Port0H")) 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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 0", , True)) Then Exit Function

  sDefSection = "Portx"
  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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 1", , True)) Then Exit Function

  sDefSection = "Portx"
  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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 1", , True)) Then Exit Function

  sDefSection = "Portx"
  If (Not m.AddMenu("IO\Port2")) 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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 2", , True)) Then Exit Function

  sDefSection = "Portx"
  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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 3", , True)) Then Exit Function

  sDefSection = "Portx"
  If (Not m.AddMenu("IO\Port4")) 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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 4", , True)) Then Exit Function

  sDefSection = "Portx"
  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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 5", , True)) Then Exit Function

  sDefSection = "Portx"
  If (Not m.AddMenu("IO\Port6")) 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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 6", , True)) Then Exit Function

  sDefSection = "Portx"
  If (Not m.AddMenu("IO\Port7")) 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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 7", , True)) Then Exit Function

  sDefSection = "Portx"
  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", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Open Drain Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Driver Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Edge Characteristic")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port 9", , True)) Then Exit Function

  sDefSection = "OSC"
  If (Not m.AddMenu("OSC\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Clock Generation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Oscillator Watchdog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Node Sharing", , True)) Then Exit Function

  sDefSection = "PEC"
  If (Not m.AddMenu("PEC\PEC")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Processing via the Peripheral Event Controller (PEC)")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Normal Interrupt Processing and PEC Service")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Operation of the PEC Channels", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The source and destination pointers")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Prioritization of Interrupt and PEC Service Requests")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Response Times", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "PEC Response Times")) Then Exit Function

  sDefSection = "PM"
  If (Not m.AddMenu("PM\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Power Management")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Idle Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Sleep Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Power Down Mode", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Status of Output Pins during Power Reduction Modes")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Slow Down Operation", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Flexible Peripheral Management")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Programmable Frequency Output Signal")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Security Mechanism")) Then Exit Function

  sDefSection = "RTC"
  If (Not m.AddMenu("RTC\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Real Time Clock")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "System Clock Operation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Cyclic Interrupt Generation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "48-bit Timer Operation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "RTC Register Access")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "RTC Interrupt Generation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Defining the RTC Time Base")) Then Exit Function

  sDefSection = "SSC"
  If (Not m.AddMenu("SSC\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The High-Speed Synchronous Serial Interface")) 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, "Port Control")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Baud Rate Generation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Error Detection Mechanisms")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "SSC Interrupt Control")) Then Exit Function

  sDefSection = "WDT"
  If (Not m.AddMenu("WDT\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Watchdog Timer (WDT)")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Operation of the Watchdog Timer")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Reset Source Indication")) Then Exit Function

  sDefSection = "I2C"
  If (Not m.AddMenu("I2C\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The IIC Bus Module")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "IIC Bus Conditions")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Physical IIC Bus Interface")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Operating the IIC Bus")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Operation in Master Mode", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Operation in Multimaster Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Operation in Slave Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "IIC Interrupt Control", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Programming Example", , True)) Then Exit Function

  sDefSection = "SDLM"
  If (Not m.AddMenu("SDLM\Dialog")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Serial Data Link Module (SDLM)")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "General SDLM Features")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Frame Format Basics")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Frame Arbitration")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "The Structure of the SDLM")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Message Operating Mode", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Receive Operation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Transmit Operation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "In-Frame Response (IFR) Operation")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Block Mode")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Flowcharts", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Handling")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Port Control")) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "SDLM Register Description", , True)) Then Exit Function
  	 If (Not m.AddLink(sDefSection, "Interrupt Node Control")) 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 weil die Registernamen neu sind muss das Bit nicht nur mit dem
'xIE in INT.H difiniert werden, sondern mit dem langen Namen.
'  ir.RegName = RegName

  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
