]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blobdiff - rpp/rpp/rpp_srmain.tlc
demo: Uncheck "Download to RPP"
[jenkicar/rpp-simulink.git] / rpp / rpp / rpp_srmain.tlc
index 005aa1a0f225c242c18681382897a47c5bedaf4e..5491f846af1ad57bc18411a192769acf17d61de2 100644 (file)
@@ -1,4 +1,4 @@
-%% Copyright (C) 2013-2014 Czech Technical University in Prague
+%% Copyright (C) 2013-2015 Czech Technical University in Prague
 %%
 %% Authors:
 %%     - Carlos Jenkins <carlos@jenkins.co.cr>
@@ -16,6 +16,9 @@
 %%     This file generates the "main" file for the RPP target on top of the RPP
 %%     library and the FreeRTOS operating system.
 %%
+%%     The sr prefix is standard to mark Single Tasking main, which is the case. See 
+%%     rpp_file_process.m description above for more information about this.
+%%
 %% References:
 %%     Example in <matlabroot>/rtw/c/tlc/mw/bareboard_srmain.tlc
 
     %%%%%%%%
     %openfile tmpBuf
 
-    /* RPP includes */
-    #include "rpp/rpp.h"
-
     /* Model includes */
     #include "%<LibGetMdlPubHdrBaseName()>.h"
 
+    /* RPP runtime includes */
+    #include "rpp_simulink_runtime.h"
+
     %if extMode == 1
       /* External mode header file */
       #include "ext_work.h"
@@ -56,7 +59,7 @@
     %openfile tmpBuf
 
     /* Definitions */
-    #define STEP_SIZE_MILLIS %<CompiledModel.FundamentalStepSize>*1000.0
+    #define STEP_SIZE_MILLIS (%<CompiledModel.FundamentalStepSize>*1000.0)
     #define CONTROL_PRIORITY 3
     #define WORKING_PRIORITY 2
     #define EXTMODE_PRIORITY 1
@@ -77,7 +80,7 @@
     %endif
     static uint32_t steps_control = 0;
     static uint32_t steps_working = 0;
-    boolean_t OVERRUN_FLAG = FALSE;
+    boolean_t overrun_flag = FALSE;
 
     %closefile tmpBuf
     %<LibSetSourceFileSection(cFile, "Declarations", tmpBuf)>
         static const portTickType freq_ticks = STEP_SIZE_MILLIS / portTICK_RATE_MS;
         portTickType last_wake_time = xTaskGetTickCount();
 
+    %% This condition has been added because of the warning:
+    %% "ert_main.c", line 46: warning #238-D: controlling expression is constant
+    %% caused by the expression (void*) 0 passed to the while statement. The rtmGetStopRequested
+    %% macro is defined to this constant if and only if the GenerateSampleERTMain is not set. So
+    %% The condition is not needed in this case as well.
+    %%
+    %% See <MATLAB_ROOT>/rtw/c/tlc/mw/rtmspecmacs.tlc at line 198.
+
+    %if !GenerateSampleERTMain
+        while (rtmGetErrorStatus(%<modelName>_M) == NULL) {
+    %else
         while (rtmGetErrorStatus(%<modelName>_M) == NULL && !rtmGetStopRequested(%<modelName>_M)) {
-
+    %endif
             /* Wait until next step */
             vTaskDelayUntil(&last_wake_time, freq_ticks);
 
                 /* Overrun detected */
                 overrun_flag = TRUE;
             } else {
-                overrun_flag = FALSE;
                 /* Release semaphore */
                 xSemaphoreGive(step_signal);
             }
     {
         /* Initialize model */
         %<LibCallModelInitialize()>\
-
+        /* Step the model for any subrate */
         xSemaphoreGive(initialized_signal);
 
         while (1) {
-
-            /* Lock semaphore */
             if (xSemaphoreTake(step_signal, portMAX_DELAY)) {
                 working = TRUE;
                 %<LibCallModelStep(0)>\
             }
         }
 
-        /* In case of shutdown, delete this task */
-        vTaskDelete(NULL);
+       %% /* In case of shutdown, delete this task */
+       %% vTaskDelete(NULL);
     }
 
     %if extMode == 1
     void main(void)
     {
         /* Initialize RPP board */
-        rpp_init();
+        %if EXISTS(::rpp_ain_present)
+            rpp_adc_init();
+        %endif
+        %if EXISTS(::rpp_aout_present)
+            rpp_dac_init();
+        %endif
+        %if EXISTS(::rpp_din_present)
+            rpp_din_init();
+        %endif
+        %if EXISTS(::rpp_hbr_present)
+            rpp_hbr_init();
+        %endif
+        %if EXISTS(::rpp_irc_present)
+            rpp_irc_init();
+        %endif
+        %if EXISTS(::rpp_lout_present)
+            rpp_lout_init();
+        %endif
+        %if EXISTS(::rpp_mout_present)
+            rpp_mout_init();
+        %endif
+        %if EXISTS(::rpp_sdr_present)
+            rpp_sdr_init();
+        %endif
+        %if EXISTS(::rpp_gio_in_present) || EXISTS(::rpp_gio_out_present)
+            rpp_gio_init(RPP_GIO_PORT_ALL);
+        %endif
+        rpp_sci_init();
 
         // Speed up the SCI
         rpp_sci_setup(115200);