]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/commitdiff
Add Overrun simulink block
authorKarel Kočí <cynerd@email.cz>
Mon, 25 Aug 2014 16:38:29 +0000 (18:38 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 28 Aug 2014 16:09:52 +0000 (18:09 +0200)
Added block for overrun detection.

Now overrun is not reported as error to model, but when is detected,
OVERRUN_FLAG is seted and Overrun block is executing connected
simulink function.

rpp/blocks/rpp_lib.slx
rpp/blocks/sfunction_ovrn.c [new file with mode: 0644]
rpp/blocks/tlc_c/sfunction_ovrn.tlc [new file with mode: 0644]
rpp/rpp/rpp_srmain.tlc

index 587a1807c31ccbe7b501602e2c8a8fcac84bbc55..548edec2b6814c6427e5f6ac2072d77cba2d1b48 100644 (file)
Binary files a/rpp/blocks/rpp_lib.slx and b/rpp/blocks/rpp_lib.slx differ
diff --git a/rpp/blocks/sfunction_ovrn.c b/rpp/blocks/sfunction_ovrn.c
new file mode 100644 (file)
index 0000000..9e25399
--- /dev/null
@@ -0,0 +1,72 @@
+/* Copyright (C) 2013 Czech Technical University in Prague
+ *
+ * Authors:
+ *
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
+ *
+ * File : sfunction_ovrn.c
+ * Abstract:
+ *     C-MEX S-function block for RPP overrun.
+ *
+ * References:
+ *     header.c
+ *     trailer.c
+ *
+ * Compile with:
+ *     <matlabroot>/bin/mex sfunction_ovrn.c
+ */
+
+
+#define S_FUNCTION_NAME sfunction_ovrn
+#include "header.c"
+
+
+static void mdlInitializeSizes(SimStruct *S)
+{
+    /*
+     * Configure parameters: 0
+     */
+    if (!rppSetNumParams(S, 0)) {
+        return;
+    }
+
+    /*
+     * Configure input ports: 0
+     */
+    if (!ssSetNumInputPorts(S, 0)) {
+        return;
+    }
+
+    /*
+     * Configure output ports: 1
+     *  - Owerrun.
+     */
+    if (!ssSetNumOutputPorts(S, 1)) {
+        return;
+    }
+       rppAddOutputPort(S, 0, SS_FCN_CALL);
+
+    /* Set standard options for this block */
+    rppSetStandardOptions(S);
+}
+
+
+static void mdlInitializeSampleTimes(SimStruct *S)
+{
+    ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
+    ssSetOffsetTime(S, 0, 0.0);
+    #if defined(ssSetModelReferenceSampleTimeDefaultInheritance)
+    ssSetModelReferenceSampleTimeDefaultInheritance(S);
+    #endif
+
+    ssSetCallSystemOutput(S,0);
+}
+
+
+#define UNUSED_MDLCHECKPARAMETERS
+#define UNUSED_MDLOUTPUTS
+#define UNUSED_MDLTERMINATE
+#include "trailer.c"
diff --git a/rpp/blocks/tlc_c/sfunction_ovrn.tlc b/rpp/blocks/tlc_c/sfunction_ovrn.tlc
new file mode 100644 (file)
index 0000000..a7627ca
--- /dev/null
@@ -0,0 +1,69 @@
+%% Copyright (C) 2013, 2014 Czech Technical University in Prague
+%%
+%% Authors:
+%%
+%% This document contains proprietary information belonging to Czech
+%% Technical University in Prague. Passing on and copying of this
+%% document, and communication of its contents is not permitted
+%% without prior written authorization.
+%%
+%% File : sfunction_ovrn.tlc
+%% Abstract:
+%%     TLC file for inlining RPP Overrun block.
+%%
+%% References:
+%%     BlockTypeSetup() : rtw_tlc.pdf p. 277
+%%     Start()          : rtw_tlc.pdf p. 279
+%%     Outputs()        : rtw_tlc.pdf p. 281
+
+
+%implements sfunction_ovrn "C"
+
+%include "common.tlc"
+
+
+%% Function: BlockTypeSetup ====================================================
+%function BlockTypeSetup(block, system) void
+
+    %% Ensure required header files are included
+    %<RppCommonBlockTypeSetup(block, system)>
+
+%endfunction
+
+
+%% Function: Start =============================================================
+%function Start(block, system) Output
+
+    %if !SLibCodeGenForSim()
+    %endif
+
+%endfunction
+
+
+%% Function: Outputs ===========================================================
+%function Outputs(block, system) Output
+
+    %if !SLibCodeGenForSim()
+
+        %if EXISTS("rpp_ovrn_extern_def") == 0
+            %assign ::rpp_ovrn_extern_def = 1
+            extern boolean_t OVERRUN_FLAG;
+        %endif
+
+
+        if (OVERRUN_FLAG) {
+                       %% Call a function subsystem
+                       %foreach callIdx = NumSFcnSysOutputCalls
+                         %if LibIsEqual(SFcnSystemOutputCall[callIdx].BlockToCall,"unconnected")
+                               %continue
+                         %endif
+                       %% call the downstream system
+                         %<LibBlockExecuteFcnCall(block, callIdx)>\
+                       %endforeach
+        }
+
+    %endif
+
+%endfunction
+
+%% [EOF]
index 265fe0a944e862e7ba14ce1886fd3f182e5d86fe..4e6713a818ecc0e6784408a75d472177180eb58d 100644 (file)
@@ -77,6 +77,7 @@
     %endif
     static uint32_t steps_control = 0;
     static uint32_t steps_working = 0;
+    boolean_t OVERRUN_FLAG = FALSE;
 
     %closefile tmpBuf
     %<LibSetSourceFileSection(cFile, "Declarations", tmpBuf)>
 
             if (WORKING) {
                 /* Overrun detected */
-                %<LibSetRTModelErrorStatus("\"Overrun\"")>;
-                /* FIXME: Call overrun routine or set some overrun flag. */
+                OVERRUN_FLAG = TRUE;
             } else {
+                OVERRUN_FLAG = FALSE;
                 /* Release semaphore */
                 xSemaphoreGive(step_signal);
             }