Attribute VB_Name = "Module1"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Const.inc"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\classes\FunctionClass.cls""
'#Uses "..\include\Port.inc"

Option Explicit

'*****************************************************************************
' Module:
'        INT
'-----------------------------------------------------------------------------
' Description:
'        This module contains all functions that are used in the
'        ASC dialog script and in the ASC codegenerator script.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        1.0  ahe            27.04.00     final version for C165UTAH
'
'        ----------------------------------------------------------------------
'        2.0  ahe            15.06.00     final version for C167CS
'
'        ----------------------------------------------------------------------
'        2.1  ahe            20.10.00     final version for C167CS
'                                         - no changes
'
'        ----------------------------------------------------------------------
'             ahe            26.10.00     final version for
'                                           C167CS
'                                           C161PI
'                                           C167CR/SR r2
'
'        ----------------------------------------------------------------------
'        7.0  ahe            24.04.01     final version for Pegasus
'
'        7.1  ahe            08.08.02     no changes
'        7.2  ste            20.12.02     spelling correction
'        ----------------------------------------------------------------------
'             ste            24.11.03     new function _viSOFTBRKTrap added
'                                         function _viClassBTrap changed
'
'*****************************************************************************
Type CourceControl
  saCon(0 To 2) As String
End Type

Dim saSource(0 To 5) As CourceControl


'*****************************************************************************
' Constants
'*****************************************************************************

'*****************************************************************************
'Description:
'        For each function which should be used for this module a line
'        "If (Not func.AddFunction .." must be insert in this function.
'        For each parameter that should be used for this function a
'        line "If (Not func.AddParameter .." must be insert in this function.
'
'        Note:
'        For each added function a project variable with the name
'        "ASC_NAME_Functionname" must be exist in the *.vars file.
'-----------------------------------------------------------------------------
'Parameters:
'        func             reference to the FunctionClass object
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function RefreshFunctionDescriptions(vIndex As Variant, func As FunctionClass, r As ProjectData) As Boolean
  On Error Resume Next

  Dim sDescription  As String
  Dim sReturnValue  As String
  Dim sVarPre       As String
  Dim sName         As String
  Dim i             As Integer
  
  sVarPre = "INT" & vIndex

  RefreshFunctionDescriptions = False

  ' for each function of this module the property AddFunction must be called
  '
  ' AddFunction(sFuncName As String, sFuncType As String, sFuncDescription As String,
  '             sReturnvalue As String, lSort As Long) As Boolean
  '
  ' sFuncName          | String | function name as key (use the name of the variable
  '                               for the function name e.g. SSC_NAME_Init)
  ' sFuncType          | String | type of the function
  ' sFuncDescription   | String | description of the function
  ' sReturnvalue       | String | description of the return value
  ' lSort              | Long   | ' sort of the function (0 => macro, 1 => function, 2 => ISR, 3 => TRAP)

    ' for each parameter of a function the property AddParameter must be called
    '
    'AddParameter(sParName As String, sPar As String, sParType As String, sParDescription As String) As Boolean
    '
    ' sParName         | String | parameter name (key)
    ' sPar             | String | parameter name
    ' sParType         | String | type of the parameter
    ' sParDescription  | String | description of the parameter


  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_Init
  '------------------------------------------------------------------------------------------------
  sDescription = GetGeneralInitDescription(sVarPre)
  sReturnValue = "None"
  If (Not func.AddFunction("INT_NAME_Init", "void", sDescription, sReturnValue, 1)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "EnableInterrupt"
  sDescription = "This macro enables the selected interrupt source." & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "Enable only those interrupt sources for which a service " & _
                 "routine is installed." & vbCrLf & _
                 "Available definitions for IntName see in the header file"

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of Interrupt (see @Defines in the header file)"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "IntName", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "DisableInterrupt"
  sDescription = "This macro disables the selected interrupt source." & vbCrLf & _
                 "Available definitions for IntName see in the header file"

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of Interrupt (see @Defines in the header file)"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "IntName", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "SetPecCount"
  sDescription = "This macro loads the COUNT field of PECCx with the parameter value." & vbCrLf & _
                 "During each PEC transfer this counter is decremented " & _
                 "(if 0xFF > COUNT > 0). If the counter reaches 0, the normal " & _
                 "interrupt service routine is executed, in which the PEC " & _
                 "counter then can be reloaded with this function. If COUNT " & _
                 "is set at 0xFF the PEC counter is switched off."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "number of PEC channel (0 to 7) whose count value is to be changed"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "Nr", "", sDescription)) Then Exit Function
    sDescription = "8-bit value for the PEC transfer counter field (0 .. 255)"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par2", "Value", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "SetPecSrcP"
  sDescription = "This macro sets the source pointer for the chosen PEC channel." & vbCrLf & _
                 ""

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "number of PEC channel (0 to 7) whose source address is to be set"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "Nr", "", sDescription)) Then Exit Function
    sDescription = "24-bit source address of the chosen PEC channel"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par2", "Address", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "SetPecDesP"
  sDescription = "This macro sets the destination pointer for the chosen PEC channel." & vbCrLf & _
                 ""
  
  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "number of PEC channel (0 to 7) whose source address is to be set"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "Nr", "", sDescription)) Then Exit Function
    sDescription = "24-bit destination address of the chosen PEC channel"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par2", "Address", "", sDescription)) Then Exit Function


  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ... interrupt
  '------------------------------------------------------------------------------------------------
''''  For i = 0 To 5
       For i = 0 To 3
    sDescription = "This is the interrupt service routine for the interrupt input from external request unit (ERU_" & i & "A0)." & _
                   " It is called when the configured event is captured." & vbCrLf & _
                   TOOLTIP_ISR_USERCODE

    sReturnValue = "None"
    If (Not func.AddFunction(sVarPre & "_NAME_Ex" & i, "void", sDescription, sReturnValue, 2)) Then Exit Function
  Next i

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ... interrupt
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the End of PEC interrupt. " & _
                 "It is called when the configured PEC channel counter decrements from 0x01 to 0x00." & vbCrLf & _
                 TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_EOPIE", "void", sDescription, sReturnValue, 2)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ... interrupt
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the SR0 Trap." & vbCrLf & vbCrLf & _
                 "It is called whenever a high to low transition on the " & _
                 "respective CPU-input is detected." & vbCrLf & _
                 TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_NMITrap", "void", sDescription, sReturnValue, 3)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ... interrupt
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the STKOF Trap." & vbCrLf & vbCrLf & _
                 "It is called whenever the stack pointer is decremented to " & _
                 "a value wich is less than the value in the stack overflow " & _
                 "register STKOV." & vbCrLf & _
                 TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_STKOFTrap", "void", sDescription, sReturnValue, 3)) Then Exit Function
  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ... interrupt
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the STKUF Trap." & vbCrLf & vbCrLf & _
                 "It is called whenever the stack pointer is incremented to " & _
                 "a value wich is greater than the value in the stack underflow " & _
                 "register STKUN" & vbCrLf & _
                 TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_STKUFTrap", "void", sDescription, sReturnValue, 3)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ... interrupt
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the SOFTBRK Trap." & vbCrLf & vbCrLf & _
                 "It is called whenever the instruction currently being executed by the CPU " & _
                 "is a SBRK instruction" & vbCrLf & _
                 TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_SOFTBRKTrap", "void", sDescription, sReturnValue, 3)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ... interrupt
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the Class B Trap." & vbCrLf & vbCrLf & _
                 "It is called whenever a system request 1, undefined opcode, a programm memory interface access error, " & _
                 "a protection fault or an illegal word operand access is detected." & vbCrLf & _
                 TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_ClassBTrap", "void", sDescription, sReturnValue, 3)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ... interrupt
  '------------------------------------------------------------------------------------------------
  sName = "ConfigureFastISR"
  sDescription = "This function configures the selected fast interrupt. " & _
                 "For details of this interrupt refer to user's manual." & _
                 "" & vbCrLf & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "Use the function " & _
                 r.v(sVarPre & "_NAME_EnableFastISR") & " to enable " & _
                 "this interrupt." & vbCrLf

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Number of fast interrupt (0 or 1)"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "ubFastISR", "ubyte", sDescription)) Then Exit Function
    sDescription = "Group priority level (0 .. 7)"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par2", "ubGroupLevel", "ubyte", sDescription)) Then Exit Function
    sDescription = "Interrupt priority level (12 .. 15)"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par3", "ubIntLevel", "ubyte", sDescription)) Then Exit Function
    sDescription = "Segment number"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par4", "ubSEG", "ubyte", sDescription)) Then Exit Function
    sDescription = "Address"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par5", "uwAddress", "uword", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ... interrupt
  '------------------------------------------------------------------------------------------------
  sName = "EnableFastISR"
  sDescription = "This macro enables the selected fast interrupt."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of fast interrupt to be enabled (0 or 1)"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "ubFastISR", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for INT_NAME_ ... interrupt
  '------------------------------------------------------------------------------------------------
  sName = "DisableFastISR"
  sDescription = "This macro disables the selected fast interrupt."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of fast interrupt to be disabled (0 or 1)"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "ubFastISR", "", sDescription)) Then Exit Function

        If (Not func.Sort) Then Exit Function

  RefreshFunctionDescriptions = True
End Function

'*****************************************************************************
'Description:
'        For each parameter that should be used as a constant (on page "Parameters")
'        a line "If (Not func.AddParameter .." must be insert in this function.
'
'        Note:
'        For each added parameter a project variable with the name
'        "DUMMY_PARA_Parametername" must be exist in the *.vars file.
'-----------------------------------------------------------------------------
'Parameters:
'        vIndex           parameter of the module which was added with AddModule
'        func             reference to the FunctionClass object
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function RefreshParameterDescriptions(vIndex As Variant, para As ParameterClass, r As ProjectData) As Boolean
  On Error Resume Next

  RefreshParameterDescriptions = False

  Dim sDescription  As String
  Dim sVarPre       As String
  Dim sRegPre       As String
  Dim sParaName     As String
  Dim i             As Integer

  sVarPre = "INT" & vIndex
  sRegPre = sVarPre & "_"


  ' for each parameter of this module the property AddParameter must be called
  '
  ' AddParameter(sParameterName As String, sParameterDescription As String) As Boolean
  '
  ' sParameterName         | String | parameter name as key (use the name of the variable
  '                                   for the parameter name e.g. SSC_PARA_MODE)
  ' sParameterDescription  | String | description of the parameter


        If (Not para.Sort) Then Exit Function

  RefreshParameterDescriptions = True
End Function


