'#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
'        ----------------------------------------------------------------------
'        2.0  ahe            15.06.00     final version for C167CS
'
'        ----------------------------------------------------------------------
'        6.0  ahe            04.08.00     final version for C161CS/JC/JI
'                                         - no changes
'
'
'*****************************************************************************


'*****************************************************************************
' 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 & _
                 "Note:" & vbCrLf & _
                 "The address of the variable must be in segment 0 (data page 0 through 3)."

  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 = "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 & _
                 "Note:" & vbCrLf & _
                 "The address of the variable must be in segment 0 (data page 0 through 3)."
  
  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 = "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 7  
    sDescription = "This is the interrupt service routine for the external interrupt " & i & " EX" & i & "IN " & _
                   "(" & GetPinName("EX" & i & "IN") & "). " & _
                   "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 NMI Trap." & vbcrlf & vbcrlf & _
                 "It is called whenever a high to low transition on the " & _
                 "dedicated external NMI pin 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 Class B Trap." & vbcrlf & vbcrlf & _
                 "It is called whenever an undefined opcode, a protection fault, " & _
                 "an illegal word operand access, an illegal instruction access " & _
                 "or an illegal external bus access is detected." & vbcrlf & _
                 TOOLTIP_ISR_USERCODE 

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_ClassBTrap", "void", sDescription, sReturnValue, 3)) 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

