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

Option Explicit
'*****************************************************************************
' @Doc
' @Module        INSTALL.INC
'-----------------------------------------------------------------------------
' @Controllers   Infineon XC866 microcontroller
'
' @Description   This module contains global functions that must be used
'                to install the system.
'
'-----------------------------------------------------------------------------
' @History:
'            Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'            0.1 Sunil           06-10-04    initial version
'            0.2 Sunil           06-01-05    in "InstallPortPins" function the exclusive
'                                            property of EXINT0_0 alternate functions is changed.
'            0.3 Radhish         06-01-05    ADC and CCU6 module added
'            0.4 Sheshadri       21-11-05    CCU6 New pins added wrt B-Step
'*****************************************************************************

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

    If (Not m.AddHotspot("ADC", DefGetPath("Bitmaps") & "adc.bmp", 159, 231, 206, 286, 44, 76)) Then Exit Function
    If (Not m.AddHotspot("CCU6", DefGetPath("Bitmaps") & "cc6.bmp", 226, 240, 266, 288, 43, 73)) Then Exit Function
    If (Not m.AddHotspot("WDT", DefGetPath("Bitmaps") & "wdt.bmp", 349, 237, 389, 286, 43, 74)) Then Exit Function
    If (Not m.AddHotspot("IO", DefGetPath("Bitmaps") & "io.bmp", 491, 92, 520, 138, 58, 173)) Then Exit Function
    If (Not m.AddHotspot("IR", DefGetPath("Bitmaps") & "int.bmp", 150, 129, 210, 172, 68, 40)) Then Exit Function
    If (Not m.AddHotspot("PS", DefGetPath("Bitmaps") & "ps.bmp", 399, 235, 449, 284, 43, 75)) Then Exit Function
    If (Not m.AddHotspot("T01", DefGetPath("Bitmaps") & "t01.bmp", 265, 121, 326, 174, 68, 39)) Then Exit Function
    If (Not m.AddHotspot("T2", DefGetPath("Bitmaps") & "t2.bmp", 100, 240, 144, 284, 44, 75)) Then Exit Function
    If (Not m.AddHotspot("UART", DefGetPath("Bitmaps") & "uart.bmp", 240, 124, 282, 186, 44, 75)) Then Exit Function
    If (Not m.AddHotspot("SSC", DefGetPath("Bitmaps") & "ssc.bmp", 278, 233, 327, 285, 44, 77)) Then Exit Function
        
        InstallHotspots = 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    | Integer        | a parameter for the new script file
  ' ModuleWithCG      | Boolean        | indicates if the module has an codegenerator or not

       '------------------------------------------------------------------------------------------------------
       ' When calling the "UpdateProjectData" functions the first module within
       ' the collection is left out, because it is assumed that it is the main
       ' module which does not have a "UpdateProjectData" function implemented.
       
        If (Not AddModule(d, "MAIN", "Project Settings", "MAIN", 0, True)) Then Exit Function
       '------------------------------------------------------------------------------------------------------
                    
       If (Not AddModule(d, "IO", "GPIO", "IO", 0, True)) Then Exit Function
       If (Not AddModule(d, "IR", "Interrupt Unit", "Int", 0, True)) Then Exit Function
       If (Not AddModule(d, "UART", "UART (Serial Interface)", "UART", 0, True)) Then Exit Function
       If (Not AddModule(d, "T01", "Timer 0/1", "T01", 0, True)) Then Exit Function
       If (Not AddModule(d, "T2", "Timer 2", "T2", 0, True)) Then Exit Function
       If (Not AddModule(d, "WDT", "Watch Dog Timer", "wdt", 0, True)) Then Exit Function
       If (Not AddModule(d, "PS", "Power Saving Modes", "ps", 0, True)) Then Exit Function
       If (Not AddModule(d, "SSC", "High Speed Synchronous Serial Interface(SSC)", "SSC", 0, True)) Then Exit Function
       If (Not AddModule(d, "ADC", "Analog / Digital Converter (ADC)", "ADC", 0, True)) Then Exit Function
       If (Not AddModule(d, "CCU6", "Capture / Compare Unit 6 (CCU6)", "CC6", 6, True)) Then Exit Function
  InstallModule = 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

  ' for each interrupt in the system the function AddInterrupt must be called
  '
  ' AddInterrupt(c As DAvECollection, GroupNumber As Integer, IntName As String) As Boolean
  '
  ' c           | DAvECollection | the interrupt collection
  ' GroupNumber | String         | number of the interrupt group
  ' IntName     | String         | name of the associated interrupt(s)

  If (Not AddInterrupt(c, 1, "EXTERNAL_INT0")) Then Exit Function
  If (Not AddInterrupt(c, 2, "TIMER0_INT")) Then Exit Function
  If (Not AddInterrupt(c, 3, "EXTERNAL_INT1")) Then Exit Function
  If (Not AddInterrupt(c, 4, "TIMER1_INT")) Then Exit Function
  If (Not AddInterrupt(c, 5, "UART_INT")) Then Exit Function
  If (Not AddInterrupt(c, 6, "TIMER2_INT")) Then Exit Function
  If (Not AddInterrupt(c, 7, "ADC_INT")) Then Exit Function
  If (Not AddInterrupt(c, 8, "SSC_INT")) Then Exit Function
  If (Not AddInterrupt(c, 9, "EXTERNAL_INT2")) Then Exit Function
  If (Not AddInterrupt(c, 10, "EXTERNAL_INT3")) Then Exit Function
  If (Not AddInterrupt(c, 11, "CCU6NODE0_INT")) Then Exit Function
  If (Not AddInterrupt(c, 12, "CCU6NODE1_INT")) Then Exit Function
  If (Not AddInterrupt(c, 13, "CCU6NODE2_INT")) Then Exit Function
  If (Not AddInterrupt(c, 14, "CCU6NODE3_INT")) 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(cPorts As DAvECollection, iPortNumber As Integer, sPortDescription As String,
  '         iFirstPin As Integer, iLastPin As Integer) As Boolean
  '
  ' cPorts            | DAvECollection | the port collection
  ' iPortNumber       | Integer        | 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
  ' iAddr             | Integer        | Port address
  ' bInputDir         | Boolean        | True = Input direction supported
  ' bOutputDir        | Boolean        | True = Output direction supported

  If (Not AddPort(cPorts, 0, "Port 0", 0, 5, &H80, True, True)) Then Exit Function
  If (Not AddPort(cPorts, 1, "Port 1", 0, 7, &H90, True, True)) Then Exit Function
  If (Not AddPort(cPorts, 2, "Port 2", 0, 7, &HA0, True, False)) Then Exit Function
  If (Not AddPort(cPorts, 3, "Port 3", 0, 7, &HB0, True, True)) 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 GoTo ErrorInstallPortPins
  InstallPortPins = False

  ' for each Pin in the system the function AddPin must be called
  '
  ' AddPin(p As PortPin, iPort as Integer, iPin As Integer, bUse As Boolean,
  '        bExclusive As Boolean) As Boolean
  '
  ' p                 | PortPin    | class for the port pins
  ' iPort             | Integer    | number of the port
  ' iPin              | Integer    | number of the pin
  ' bUse              | Boolean    | flag that shows if the pin is available
  ' bExclusive        | Boolean    | flag that shows if the pin should be used exclusively

  ' for each alternate pin name in the system the function AddAlternateName must be
  ' called
  '
  ' AddAlternateName(p As PortPin, sAlternateName As String, sDescription As string,
  '                  bExclusive As Boolean) 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 exclusively

  '****************************** Port 1 *************************************

  If (Not AddPin(p, 0, 0, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "TCK_0", "JTAG Clock Input", True)) Then Exit Function
        If (Not AddAlternateName(p, "T12HR_1", "CCU6 Timer 12 Hardware Run Input", True)) Then Exit Function
        If (Not AddAlternateName(p, "CC61_1(Input)", "Input of Capture/Compare channel 1", True)) Then Exit Function
        If (Not AddAlternateName(p, "CC61_1(Output)", "Output of Capture/Compare channel 1", True)) Then Exit Function
        If (Not AddAlternateName(p, "CLKOUT", "10 MHz On-Chip OSC Clock Output", True)) Then Exit Function
        If (Not AddAlternateName(p, "RXDO_1", "UART Transmit Data Output in Mode 0 (RXDO_1)", True)) Then Exit Function
    
  If (Not AddPin(p, 0, 1, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "TDI_0", "JTAG Serial Data Input", True)) Then Exit Function
        If (Not AddAlternateName(p, "T13HR_1", "CCU6 Timer 13 Hardware Run Input", True)) Then Exit Function
        If (Not AddAlternateName(p, "RXD_1", "UART Receive Input", False)) Then Exit Function
        If (Not AddAlternateName(p, "RXD_1_(Wake-up)", "Wake-up from power down (RxD)", False)) Then Exit Function
        If (Not AddAlternateName(p, "COUT61_1", "Output of Capture/Compare channel 1", True)) Then Exit Function
        If (Not AddAlternateName(p, "EXF2_1", "Timer 2 External Flag Output", False)) Then Exit Function
  
  If (Not AddPin(p, 0, 2, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "#CTRAP_2", "CCU6 Trap Input", True)) Then Exit Function
        If (Not AddAlternateName(p, "TDO_0", "JTAG Serial Data Output", True)) Then Exit Function
        If (Not AddAlternateName(p, "TXD_1", "UART Transmit Output", True)) Then Exit Function
    
  If (Not AddPin(p, 0, 3, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "SCK_1(Input)", "SSC Clock Input", True)) Then Exit Function
        If (Not AddAlternateName(p, "SCK_1(Output)", "SSC Clock Output", True)) Then Exit Function
        If (Not AddAlternateName(p, "COUT63_1", "Output of Capture/Compare channel 3", True)) Then Exit Function
    
  If (Not AddPin(p, 0, 4, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "MTSR_1(Master_Transmit)", "SSC Master Transmit Output", True)) Then Exit Function
        If (Not AddAlternateName(p, "MTSR_1(Slave_Receive)", "SSC Slave Receive Input", True)) Then Exit Function
        If (Not AddAlternateName(p, "CC62_1(Input)", "Input of Capture/Compare channel 2", True)) Then Exit Function
        If (Not AddAlternateName(p, "CC62_1(Output)", "Output of Capture/Compare channel 2", True)) Then Exit Function
        
  If (Not AddPin(p, 0, 5, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "MRST_1(Master_Receive)", "SSC Master Receive Input", True)) Then Exit Function
        If (Not AddAlternateName(p, "MRST_1(Slave_Transmit)", "SSC Slave Transmit Output", True)) Then Exit Function
        If (Not AddAlternateName(p, "EXINT0_0", "External Interrupt Input 0", True)) Then Exit Function
        If (Not AddAlternateName(p, "EXINT0_0_(Wake-up)", "Wake-up from power down via External Interrupt Input 0", False)) Then Exit Function
        If (Not AddAlternateName(p, "EXINT0_0_(Gate)", "Timer 0 gate control (EXINT0_0)", True)) Then Exit Function
        If (Not AddAlternateName(p, "COUT62_1", "Output of Capture/Compare channel 2", True)) Then Exit Function
  
  If (Not AddPin(p, 1, 0, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "RXD_0", "UART Receive Input", False)) Then Exit Function
        If (Not AddAlternateName(p, "RXD_0_(Wake-up)", "Wake-up from power down (RxD)", False)) Then Exit Function
        If (Not AddAlternateName(p, "T2EX", "Timer 2 External Trigger Input", True)) Then Exit Function
        
  If (Not AddPin(p, 1, 1, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "EXINT3", "External Interrupt Input 3", True)) Then Exit Function
        If (Not AddAlternateName(p, "TDO_1", "JTAG Serial Data Output", True)) Then Exit Function
        If (Not AddAlternateName(p, "TXD_0", "UART Transmit Output", True)) Then Exit Function
        'Added by jag on 25.06.08 after confirmation from Lim Lay mui
        If (Not AddAlternateName(p, "T0", "Timer 0 Input", True)) Then Exit Function
        
        
'  If (Not AddPin(p, 1, 5, True, True)) Then Exit Function
'        If (Not AddAlternateName(p, "CCPOS0_1", "CCU6 Hall Input 0", True)) Then Exit Function
'        If (Not AddAlternateName(p, "EXINT5", "External Interrupt Input 5", True)) Then Exit Function
'        If (Not AddAlternateName(p, "EXF2_0", "Timer 2 External Flag Output", True)) Then Exit Function
'        If (Not AddAlternateName(p, "RXDO_0", "UART Transmit Data Output in Mode 0 (RXDO_0)", True)) Then Exit Function
'
'  If (Not AddPin(p, 1, 6, True, True)) Then Exit Function
'        If (Not AddAlternateName(p, "CCPOS1_1", "CCU6 Hall Input 1", True)) Then Exit Function
'        If (Not AddAlternateName(p, "T12HR_0", "CCU6 Timer 12 Hardware Run Input", True)) Then Exit Function
'        If (Not AddAlternateName(p, "EXINT6", "External Interrupt Input 6", True)) Then Exit Function
'
'  If (Not AddPin(p, 1, 7, True, True)) Then Exit Function
'        If (Not AddAlternateName(p, "CCPOS2_1", "CCU6 Hall Input 2", True)) Then Exit Function
'        If (Not AddAlternateName(p, "T13HR_0", "CCU6 Timer 13 Hardware Run Input", True)) Then Exit Function

  If (Not AddPin(p, 2, 0, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "CCPOS0_0", "CCU6 Hall Input 0", True)) Then Exit Function
        If (Not AddAlternateName(p, "EXINT1", "External Interrupt Input 1", True)) Then Exit Function
        If (Not AddAlternateName(p, "EXINT1_(Gate)", "Timer 1 gate control (EXINT1)", True)) Then Exit Function
        If (Not AddAlternateName(p, "T12HR_2", "CCU6 Timer 12 Hardware Run Input", True)) Then Exit Function
        If (Not AddAlternateName(p, "TCK_1", "JTAG Clock Input", True)) Then Exit Function
        If (Not AddAlternateName(p, "CC61_3(Input)", "Input of Capture/Compare channel 1", True)) Then Exit Function
        If (Not AddAlternateName(p, "AN0", "Analog Input 0", True)) Then Exit Function

  If (Not AddPin(p, 2, 1, True, True)) Then Exit Function
         If (Not AddAlternateName(p, "CCPOS1_0", "CCU6 Hall Input 1", True)) Then Exit Function
         If (Not AddAlternateName(p, "EXINT2", "External Interrupt Input 2", True)) Then Exit Function
         If (Not AddAlternateName(p, "T13HR_2", "CCU6 Timer 13 Hardware Run Input", True)) Then Exit Function
         If (Not AddAlternateName(p, "TDI_1", "JTAG Serial Data Input", True)) Then Exit Function
         If (Not AddAlternateName(p, "CC62_3(Input)", "Input of Capture/Compare channel 2", True)) Then Exit Function
         If (Not AddAlternateName(p, "AN1", "Analog Input 1", True)) Then Exit Function

  If (Not AddPin(p, 2, 2, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "CCPOS2_0", "CCU6 Hall Input 2", True)) Then Exit Function
        If (Not AddAlternateName(p, "#CTRAP_1", "CCU6 Trap Input", True)) Then Exit Function
        If (Not AddAlternateName(p, "CC60_3(Input)", "Input of Capture/Compare channel 0", True)) Then Exit Function
        If (Not AddAlternateName(p, "AN2", "Analog Input 2", True)) Then Exit Function

'  If (Not AddPin(p, 2, 3, True, True)) Then Exit Function
'        If (Not AddAlternateName(p, "AN3", "Analog Input 3", True)) Then Exit Function
'
'  If (Not AddPin(p, 2, 4, True, True)) Then Exit Function
'        If (Not AddAlternateName(p, "AN4", "Analog Input 4", True)) Then Exit Function
'
'  If (Not AddPin(p, 2, 5, True, True)) Then Exit Function
'        If (Not AddAlternateName(p, "AN5", "Analog Input 5", True)) Then Exit Function
'
'  If (Not AddPin(p, 2, 6, True, True)) Then Exit Function
'        If (Not AddAlternateName(p, "AN6", "Analog Input 6", True)) Then Exit Function
  
  If (Not AddPin(p, 2, 7, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "AN7", "Analog Input 7", True)) Then Exit Function
        
  If (Not AddPin(p, 3, 0, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "CC60_0(Input)", "Input of Capture/Compare channel 0", True)) Then Exit Function
        If (Not AddAlternateName(p, "CC60_0(Output)", "Output of Capture/Compare channel 0", True)) Then Exit Function
        If (Not AddAlternateName(p, "CCPOS1_2", "CCU6 Hall Input 0", True)) Then Exit Function

  If (Not AddPin(p, 3, 1, True, True)) Then Exit Function
        If (Not AddAlternateName(p, "CCPOS0_2", "CCU6 Hall Input 1", True)) Then Exit Function
        If (Not AddAlternateName(p, "CC61_2(Input)", "Input of Capture/Compare channel 2", True)) Then Exit Function
        If (Not AddAlternateName(p, "CC61_2(Output)", "Output of Capture/Compare channel 2", True)) Then Exit Function
        If (Not AddAlternateName(p, "COUT60_0", "Output of Capture/Compare channel 0", True)) Then Exit Function

'  If (Not AddPin(p, 3, 2, True, True)) Then Exit Function
'        If (Not AddAlternateName(p, "CC61_0(Input)", "Input of Capture/Compare channel 1", True)) Then Exit Function
'        If (Not AddAlternateName(p, "CC61_0(Output)", "Output of Capture/Compare channel 1", True)) Then Exit Function
'        If (Not AddAlternateName(p, "CCPOS2_2", "CCU6 Hall Input 2", True)) Then Exit Function
'
'  If (Not AddPin(p, 3, 3, True, True)) Then Exit Function
'        If (Not AddAlternateName(p, "COUT61_0", "Output of Capture/Compare channel 1", True)) Then Exit Function
'
'  If (Not AddPin(p, 3, 4, True, True)) Then Exit Function
'        If (Not AddAlternateName(p, "CC62_0(Input)", "Input of Capture/Compare channel 2", True)) Then Exit Function
'        If (Not AddAlternateName(p, "CC62_0(Output)", "Output of Capture/Compare channel 2", True)) Then Exit Function
'
'  If (Not AddPin(p, 3, 5, True, True)) Then Exit Function
'          If (Not AddAlternateName(p, "COUT62_0", "Output of Capture/Compare channel 2", True)) Then Exit Function
'
'  If (Not AddPin(p, 3, 6, True, True)) Then Exit Function
'          If (Not AddAlternateName(p, "#CTRAP_0", "CCU6 Trap Input", True)) Then Exit Function
'
'  If (Not AddPin(p, 3, 7, True, True)) Then Exit Function
'          If (Not AddAlternateName(p, "EXINT4", "External Interrupt Input 4", True)) Then Exit Function
'          If (Not AddAlternateName(p, "COUT63_0", "Output of Capture/Compare channel 3", True)) Then Exit Function
'
  If (Not p.Sort) Then Exit Function
  
  InstallPortPins = True
  
  Exit Function
  
ErrorInstallPortPins:
  Errorbox "Error InstallPortPins", Err.Description
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
  On Error GoTo ManulLinksError
  
  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 property 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, "Introduction")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Processor Architecture")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Memory Organization")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Flash Memory")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Interrupt System")) Then Exit Function
    
  sDefSection = "ADC"
  If (Not m.AddMenu("ADC\Dialog")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Analog-to-Digital Converter")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Functional Description")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Sequential Source Registers")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Parallel Source Registers")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Result Generation")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Interrupts")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Register Description")) Then Exit Function
    
  If (Not m.AddMenu("ADC\Channel")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Channel Control")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Channel Control Registers")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Channel Interrupts")) Then Exit Function

  sDefSection = "CC6"
  If (Not m.AddMenu("CC6\Dialog")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Capture/Compare Unit 6")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Timer T12")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Timer T13")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Modulation Control")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Trap Handling")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Multi-Channel Mode")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Hall Sensor Mode")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Register Description")) Then Exit Function
        
  If (Not m.AddMenu("CC6\CC6_CHANNEL_012")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Modulation Control")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Modulation Control Registers")) Then Exit Function
        
  If (Not m.AddMenu("CC6\CC6_CHANNEL_3")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Modulation Control")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Modulation Control Registers")) Then Exit Function
        
  If (Not m.AddMenu("CC6\CC6_INERRUPT_NODE")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Interrupt Control Registers")) Then Exit Function
        

  sDefSection = "WDT"
  If (Not m.AddMenu("WDT\Dialog")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Watchdog Timer")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Functional Description")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Register Map")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Register Description")) 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, "General Port Operation")) Then Exit Function
        If (Not m.AddLink(sDefSection, "General Register Description")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Alternate Functions")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Register Map")) Then Exit Function
         

  If (Not m.AddMenu("IO\Dialog0")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port 0")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port0 Registers")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port0 Funtions")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port0 Register Description")) Then Exit Function

  If (Not m.AddMenu("IO\Dialog1")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port 1")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port1 Registers")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port1 Funtions")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port1 Register Description")) Then Exit Function
        
  If (Not m.AddMenu("IO\Dialog2")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port 2")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port2 Registers")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port2 Funtions")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port2 Register Description")) Then Exit Function
        
  If (Not m.AddMenu("IO\Dialog3")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port 3")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port3 Registers")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port3 Funtions")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Port3 Register Description")) Then Exit Function

  sDefSection = "IR"
  If (Not m.AddMenu("IR\Dialog")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Interrupt System")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Interrupt Vector Addresses")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Interrupt Register Description")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Interrupt Handling")) Then Exit Function

  sDefSection = "PS"
  If (Not m.AddMenu("PS\Dialog")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Power Saving Modes")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Idle Mode")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Slow-Down Mode")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Power-Down Mode")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Peripheral Clock Management")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Register Description")) Then Exit Function

  sDefSection = "T01"
  If (Not m.AddMenu("T01\Dialog")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Timer 0 and Timer 1")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Timer Modes")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Register Description")) Then Exit Function

  sDefSection = "T2"
  If (Not m.AddMenu("T2\Dialog")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Timer 2")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Auto Reload Mode")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Capture Mode")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Register Description")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Register Map")) Then Exit Function
         
  sDefSection = "UART"
  If (Not m.AddMenu("UART\Dialog")) Then Exit Function
        If (Not m.AddLink(sDefSection, "UART")) Then Exit Function
        If (Not m.AddLink(sDefSection, "UART Modes")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Mode 0 Details")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Mode 1 Details")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Mode 2 Details")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Mode 3 Details")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Multiprocessor Communication")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Register Description")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Baudrate Generation", , True)) Then Exit Function
        If (Not m.AddLink(sDefSection, "Fractional Divider Mode")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Normal Divider Mode")) Then Exit Function
  
  sDefSection = "SSC"
  If (Not m.AddMenu("SSC\Dialog")) Then Exit Function
        If (Not m.AddLink(sDefSection, "High-Speed Synchronous Serial Interface")) Then Exit Function
        If (Not m.AddLink(sDefSection, "General Operation")) 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, "Interrupts")) Then Exit Function
        If (Not m.AddLink(sDefSection, "Register Description")) Then Exit Function
         
  InstallManualLinks = True
  Exit Function
  
ManulLinksError:
    Errorbox "Error ManulLinks", Err.Description
End Function

'*****************************************************************************
' @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   | GroupNumber | Integer | number of the interrupt group
' @bparm   | IntName | String | name of the associated interrupt(s)
'
'*****************************************************************************
Public Function AddInterrupt(c As DAvECollection, GroupNumber As Integer, IntName As String) As Boolean
  On Error Resume Next
  AddInterrupt = False

  Dim ir As InterruptClass

  Set ir = New InterruptClass
  ir.GroupNumber = GroupNumber
  ir.IntName = IntName
  c.Add ir

  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 | Integer | 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 Integer, 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   | iPortNumber | Integer | 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   | iAddr | Integer | Port address
' @bparm   | bInputDir | Boolean | True = Input direction supported
' @bparm   | bOutputDir | Boolean | True = Output direction supported
'
'*****************************************************************************
Public Function AddPort(p As DAvECollection, iPortNumber As Integer, sPortDescription As String, iFirstPin As Integer, _
                        iLastPin As Integer, iAddr As Integer, bInputDir As Boolean, bOutputDir As Boolean) As Boolean
  On Error Resume Next
  AddPort = False

  Dim newPort As Port

  Set newPort = New Port

  newPort.PortNumber = iPortNumber
  newPort.Description = sPortDescription
  newPort.FirstPin = iFirstPin
  newPort.LastPin = iLastPin
  newPort.Addr = iAddr
  newPort.InputDir = bInputDir
  newPort.OutputDir = bOutputDir
  p.Add newPort, "P" & iPortNumber

  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|
'
'-----------------------------------------------------------------------------
' @bparm   | p     | PortPin | object of the class for the port pins
' @bparm   | iPort | Integer | number of the port
' @bparm   | iPin  | Integer | number of the pin
' @bparm   | bUse  | Boolean | flag that shows if the pin is available
' @bparm   | bExclusive | Boolean | flag that shows if the pin should be used exclusively
'
'*****************************************************************************
Public Function AddPin(p As PortPin, iPort As Integer, iPin As Integer, bUse As Boolean, bExclusive As Boolean) As Boolean
  On Error GoTo ErrorAddPin
  
  AddPin = False

  Dim s As String

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

  AddPin = True
  Exit Function
  
ErrorAddPin:
    Errorbox "error add pin", Err.Description
    Exit Function
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
' @bparm   | bExclusive | Boolean | flag that shows if the pin should be used exclusively
'
'*****************************************************************************
Public Function AddAlternateName(p As PortPin, sAlternateName As String, sDescription As String, bExclusive As Boolean) As Boolean
  On Error Resume Next
  
  AddAlternateName = False
        
        If (Not p.AddAlternateName(sAlternateName, sDescription, bExclusive)) Then Exit Function

  AddAlternateName = True
  
  Exit Function

End Function
