📄 simple_lookup.adb
字号:
return; end if; end loop; end; exception when E : others => if ssGetErrorStatus(S) = "" then ssSetErrorStatus(S, "Exception occured in mdlCheckParameters. " & "Name: " & Exception_Name(E) & ", " & "Message: " & Exception_Message(E) & " and " & "Information: " & Exception_Information(E)); end if; end mdlCheckParameters; ----------------------------------------------------- -- Procedure: mdlInitializeSizes -------------------------------------------- -- Abstract:: -- Configure this S-Function block's attrubutes. -- procedure mdlInitializeSizes(S : in SimStruct) is begin -- The X and Y values can be changed during simulation ssSetParameterTunable(S, X_VALUES_PRM_IDX, TRUE); ssSetParameterName(S, X_VALUES_PRM_IDX, "XValues"); ssSetParameterTunable(S, Y_VALUES_PRM_IDX, TRUE); ssSetParameterName(S, Y_VALUES_PRM_IDX, "YValues"); -- Lookup method parameter cannot be changed once simulation starts ssSetParameterTunable(S, LOOKUP_MTH_PRM_IDX, FALSE); ssSetParameterName(S, LOOKUP_MTH_PRM_IDX, "LookupMethod"); -- Set Size Information ssSetNumContStates(S, 0); -- This S-Function has one input port ssSetNumInputPorts( S, 1); -- Set the input port attributes ssSetInputPortWidth( S, 0, DYNAMICALLY_SIZED); ssSetInputPortDataType( S, 0, SS_DOUBLE); ssSetInputPortDirectFeedThrough(S, 0, TRUE); ssSetInputPortOptimizationLevel(S, 0, 3); ssSetInputPortOverWritable( S, 0, TRUE); -- This S-Function has two output ports ssSetNumOutputPorts( S, 2); -- The first output port signal is the looked up table value ssSetOutputPortWidth( S, 0, DYNAMICALLY_SIZED); ssSetOutputPortDataType( S, 0, SS_DOUBLE); ssSetOutputPortOptimizationLevel(S, 0, 3); -- The second output port signal is the index into table corresponding to -- the looked up value. In addition, the lookup algorithm uses the last -- index to start search, so the last index value has to be persistent, -- hence mark this signal as not reusable ssSetOutputPortWidth( S, 1, DYNAMICALLY_SIZED); ssSetOutputPortDataType( S, 1, SS_INT32); ssSetInputPortOptimizationLevel(S, 0, 0); -- Set the block sample time ssSetSampleTime(S, INHERITED_SAMPLE_TIME); exception when E : others => if ssGetErrorStatus(S) = "" then ssSetErrorStatus(S, "Exception occured in mdlInitializeSizes. " & "Name: " & Exception_Name(E) & ", " & "Message: " & Exception_Message(E) & " and " & "Information: " & Exception_Information(E)); end if; end mdlInitializeSizes; ----------------------------------------------------- -- Procedure: mdlStart ------------------------------------------------------ -- Abstract:: -- Initialize block specific data at simulation start. For this block, -- this involves setting the persistent output to a reasonable value. -- Note that we should (and need) not initialize the first output port -- signal because it is not persistent, and to correctly initialize it -- we need to know the value of the input signal, which is not available -- at this point. -- procedure mdlStart(S : in SimStruct) is Y1Width : Integer := ssGetOutputPortWidth(S,1); Y1 : array(0 .. Y1Width-1) of Int_T; for Y1'Address use ssGetOutputPortSignalAddress(S,1); MidPoint : Integer := (ssGetParameterWidth(S,0)+1)/2; begin -- Initalize the second output port signal, which holds the -- index into the lookup table, to the middle of the table. for I in 0 .. Y1Width-1 loop Y1(I) := MidPoint; end loop; exception when E : others => if ssGetErrorStatus(S) = "" then ssSetErrorStatus(S, "Exception occured in mdlStart. " & "Name: " & Exception_Name(E) & ", " & "Message: " & Exception_Message(E) & " and " & "Information: " & Exception_Information(E)); end if; end mdlStart; --------------------------------------------------------------- -- Procedure: mdlOutputs ---------------------------------------------------- -- Abstract:: -- Compute the block output port signals. Note that this is just a -- "wrapper" function. The actual algorithms are implemented in a -- seperated package "lookup_methods", which is accessed both from -- here and Ada code generated using the RTW Ada Code. -- procedure mdlOutputs(S : in SimStruct; TID : in Integer) is BlockWidth : Integer := ssGetInputPortWidth(S,0); U : array(0 .. BlockWidth-1) of Standard.Long_Float; for U'Address use ssGetInputPortSignalAddress(S,0); Y0 : array(0 .. BlockWidth-1) of Standard.Long_Float; for Y0'Address use ssGetOutputPortSignalAddress(S,0); Y1 : array(0 .. BlockWidth-1) of Integer; for Y1'Address use ssGetOutputPortSignalAddress(S,1); TableLength : Integer := ssGetParameterWidth(S, X_VALUES_PRM_IDX); XVal : array(1 .. TableLength) of Standard.Long_Float; for XVal'Address use ssGetParameterAddress(S, X_VALUES_PRM_IDX); YVal : array(0 .. TableLength) of Standard.Long_Float; for YVal'Address use ssGetParameterAddress(S, Y_VALUES_PRM_IDX); LookupMth : String := ssGetStringParameter(S, LOOKUP_MTH_PRM_IDX); begin if LookupMth = "left" then Lookup_Methods.Left_Continuous_Lookup(Lookup_Methods.Dbl_Array(U), Lookup_Methods.Dbl_Array(Y0), Lookup_Methods.Int_Array(Y1), Lookup_Methods.Dbl_Array(XVal), Lookup_Methods.Dbl_Array(YVal)); elsif LookupMth = "right" then Lookup_Methods.Right_Continuous_Lookup(Lookup_Methods.Dbl_Array(U), Lookup_Methods.Dbl_Array(Y0), Lookup_Methods.Int_Array(Y1), Lookup_Methods.Dbl_Array(XVal), Lookup_Methods.Dbl_Array(YVal)); else ssSetErrorStatus(S, "Unexpected parameter value " & LookupMth & " encountered in mdlOutputs"); end if; exception when Lookup_Methods.Algorithm_Error => ssSetErrorStatus(S, "Algorithmic error in Lookup_Methods"); when E : others => if ssGetErrorStatus(S) = "" then ssSetErrorStatus(S, "Exception occured in mdlOutputs. " & "Name: " & Exception_Name(E) & ", " & "Message: " & Exception_Message(E) & " and " & "Information: " & Exception_Information(E)); end if; end mdlOutputs; -------------------------------------------------------------end Simple_Lookup;-- EOF: simple_lookup.adb
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -