]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/commitdiff
Add support for multirate singlethread models
authorMichal Horn <hornmich@fel.cvut.cz>
Tue, 31 Mar 2015 08:35:12 +0000 (10:35 +0200)
committerMichal Horn <hornmich@fel.cvut.cz>
Tue, 31 Mar 2015 08:35:12 +0000 (10:35 +0200)
Fixes: #1009
rpp/demos/multirate_st.slx [new file with mode: 0644]
rpp/rpp/rpp_file_process.tlc
rpp/rpp/rpp_srmain.tlc

diff --git a/rpp/demos/multirate_st.slx b/rpp/demos/multirate_st.slx
new file mode 100644 (file)
index 0000000..eeccb64
Binary files /dev/null and b/rpp/demos/multirate_st.slx differ
index a28fed68d95305abab238b8f146e5fd7b2feba67..4797869509c80651ee9c0d7d9613bbc2133e77d2 100644 (file)
@@ -28,6 +28,7 @@
 %assign ::modelName = CompiledModel.Name
 %assign ::solverMode = CompiledModel.FixedStepOpts.SolverMode
 %assign ::fundamentalStepSize = CompiledModel.FundamentalStepSize
+%assign ::tid01Eq = CompiledModel.FixedStepOpts.TID01EQ
 %assign ::numSampleTimes = CompiledModel.NumSynchronousSampleTimes
 
 %% Need to set the template compliance flag before you can use the API
index 93051f608c315d146619f7d0fefc5955c6d7cb85..36715f9b58fc61c4109d42e85306c8428a39bafa 100644 (file)
     {
         /* Initialize model */
         %<LibCallModelInitialize()>\
-
+        /* Step the model for any subrate */
         xSemaphoreGive(initialized_signal);
+        %foreach idx = LibGetNumSyncPeriodicTasks()
+        %assign tid = idx + tid01Eq
+        %assign sampleTime = LibGetSampleTimePeriodAndOffset(tid,0)
+        %assign steps = FEVAL("round", sampleTime / CompiledModel.FundamentalStepSize)
+        #define STEPS_FOR_TID%<tid>   ((int)%<steps>)
+        %endforeach
 
         while (1) {
 
             /* Lock semaphore */
             if (xSemaphoreTake(step_signal, portMAX_DELAY)) {
                 working = TRUE;
-                %<LibCallModelStep(0)>\
-                steps_working++;
-                working = FALSE;
-            }
+                %if LibNumSynchronousSampleTimes() > 1
+                               int i;
+                       for (i = %<tid01Eq>; i < %<LibNumSynchronousSampleTimes()>; i++) {
+                           switch(i) {
+                               %foreach idx = LibGetNumSyncPeriodicTasks()
+                               %assign tid = idx + tid01Eq
+                                       case %<tid> :
+                                   %assign sampleTime = LibGetSampleTimePeriodAndOffset(tid,0)
+                                                       if ((steps_working % STEPS_FOR_TID%<tid>) == 0) {
+                                       %<LibCallModelStep(tid)>\
+                           }
+                                           break;
+                               %endforeach
+                               default : 
+                                   break;
+                               }
+                       }
+                %else
+                    %<LibCallModelStep(0)>\
+                %endif
+                       steps_working++;
+                       working = FALSE;
+                       }
         }
 
        %% /* In case of shutdown, delete this task */