]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/commitdiff
Fixed setup file and added step implementation in the main function.
authorCarlos Jenkins <carlos@jenkins.co.cr>
Tue, 14 May 2013 15:50:13 +0000 (17:50 +0200)
committerCarlos Jenkins <carlos@jenkins.co.cr>
Tue, 14 May 2013 15:50:13 +0000 (17:50 +0200)
rpp/rpp/rpp_setup.m
rpp/rpp/rpp_srmain.tlc

index c28ce8a38e8b2d7d0ecc6a20ccbdabce5e70b742..5b23c4ad45a29c663451de302cdbd27b0cabe16f 100644 (file)
@@ -38,11 +38,12 @@ function rpp_setup()
     addpath(fullfile(tgtpath, 'rpp'));
     addpath(fullfile(tgtpath, 'demos'));
     addpath(fullfile(tgtpath, 'blocks'));
-    #addpath(fullfile(tgtpath, 'help'));
+    %addpath(fullfile(tgtpath, 'help'));
     savepath();
 
     % Ask user setup variables
-    CompilerRoot = fix_slash(uigetdir(CCSRoot,'CCS Compiler root directory: (<ccs_root>/tools/compiler/arm_5.X.X)'));
+    PossiblePath = '/usr/local/ti/ccsv5/tools/compiler/arm_5.0.1';
+    CompilerRoot = fix_slash(uigetdir(PossiblePath, 'CCS Compiler root directory: (<ccs_root>/tools/compiler/arm_5.X.X)'));
 
     % Save preferences
     if ispref('rpp')
@@ -52,11 +53,13 @@ function rpp_setup()
     addpref('rpp', 'TargetRoot', fix_slash(curpath));
 
     % Generate blocks
-    cd('../blocks');
-    lct_genblocks();
-    cd(curpath);
+    % FIXME: Implement blocks autobuild
+    %cd('../blocks');
+    %lct_genblocks();
+    %cd(curpath);
 
     % Generate help
+    % FIXME: Write and generate help
     %cd('../help/source');
     %genhelp();
     %cd(curpath);
@@ -64,8 +67,8 @@ function rpp_setup()
     % Apply changes and finish
     sl_refresh_customizations();
     disp('<strong>RPP</strong> Target setup is complete!');
-    disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/demos''])">demos</a> directory.');
-    #disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/demos''])">demos</a> directory and access <a href="matlab:doc -classic">documentation</a>');
+    disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/../demos''])">demos</a> directory.');
+    %disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/demos''])">demos</a> directory and access <a href="matlab:doc -classic">documentation</a>');
 end
 
 
index 48e66c34adf76c2558ac3ec965470ca23c33abeb..2b709bcf019f569e86c8df238f61ff475bcd84dc 100644 (file)
 
 %function FcnSingleTaskingMain() void
 
-  %if GenerateSampleERTMain
-    %assign CompiledModel.GenerateSampleERTMain = TLC_FALSE
-  %endif
-
-  %assign cFile = LibCreateSourceFile("Source", "Custom", "ert_main")
-  %openfile tmpBuf
-  %closefile tmpBuf
-
-  %<LibSetSourceFileSection(cFile, "Includes", tmpBuf)>
-  %openfile tmpBuf
-  /* OS includes */
-  #include "FreeRTOS.h"
-  #include "os_task.h"
-
-  /* Common includes */
-  #include "sys_common.h"
-  #include "system.h"
-
-  /* Library includes */
-  // FIXME: Implement conditional #include's
-  %% IF GIO (General Input/Outputs)
-  %% IF HOUT (PWM outputs)
-  %% IF MOUT (Motor outputs)
-  %% IF ADC (Analog to Digital Converter)
-  %% IF SCI (Serial Communication Interface)
-  %% IF CAN (CAN Bus)
-  %% IF SDRAM
-
-  /* Model includes */
-  #include "%<LibGetMdlPubHdrBaseName()>.h"
-  %closefile tmpBuf
-
-  %<LibSetSourceFileSection(cFile, "Declarations", tmpBuf)>
-  %openfile tmpBuf
+    %if GenerateSampleERTMain
+        %assign CompiledModel.GenerateSampleERTMain = TLC_FALSE
+    %endif
+
+    %assign cFile = LibCreateSourceFile("Source", "Custom", "ert_main")
+    %openfile tmpBuf
+    %closefile tmpBuf
+
+    %<LibSetSourceFileSection(cFile, "Includes", tmpBuf)>
+    %openfile tmpBuf
+
+    #define STEP_SIZE_MILLIS (%<CompiledModel.FundamentalStepSize>*1000)
+    #define CONTROL_PRIORITY 2
+    #define WORKING_PRIORITY 1
+
+    /* Standard includes */
+    #include <stdbool.h>
+
+    /* Kernel includes */
+    #include "FreeRTOS.h"
+    #include "task.h"
+    #include "semphr.h"
+
+    /* System includes */
+    #include "sys_common.h"
+    #include "system.h"
+
+    /* Library includes */
+    // FIXME: Implement conditional #include's
+    %% IF GIO (General Input/Outputs)
+    %% IF HOUT (PWM outputs)
+    %% IF MOUT (Motor outputs)
+    %% IF ADC (Analog to Digital Converter)
+    %% IF SCI (Serial Communication Interface)
+    %% IF CAN (CAN Bus)
+    %% IF SDRAM
+
+    /* Model includes */
+    #include "%<LibGetMdlPubHdrBaseName()>.h"
+    %closefile tmpBuf
+
+    %<LibSetSourceFileSection(cFile, "Declarations", tmpBuf)>
+    %openfile tmpBuf
+    bool WORKING = false;
+    bool SHUTDOWN = false;
+    xSemaphoreHandle step_signal = NULL;
+    %closefile tmpBuf
+
+    %<LibSetSourceFileSection(cFile, "Functions", tmpBuf)>
+    %openfile tmpBuf
+
+    void control_task(void *p) {
+
+        const portTickType freq_ticks = STEP_SIZE_MILLIS / portTICK_RATE_MS;
+        portTickType last_wake_time = xTaskGetTickCount();
+
+        while(!SHUTDOWN) {
+
+            // Wait until next step
+            vTaskDelayUntil(&last_wake_time, freq_ticks);
+
+            if(WORKING) {
+                // Overrun detected
+                // FIXME: Call overrun routine
+            } else {
+                // Release semaphore
+                xSemaphoreGive(step_signal);
+            }
+
+        }
+
+        /* In case of shutdown, delete this task */
+        vTaskDelete(NULL);
+    }
+
+    void working_task(void *p) {
+
+        while(!SHUTDOWN) {
+
+            // Lock semaphore
+            if(xSemaphoreTake(step_signal, portMAX_DELAY)) {
+                WORKING = true;
+                %<LibCallModelStep(0)>\
+                WORKING = false;
+            }
+        }
+
+        /* In case of shutdown, delete this task */
+        vTaskDelete(NULL);
+    }
+
 
     void main(void)
     {
         /* Initialize model */
         %<LibCallModelInitialize()>\
 
-        /* Create task to step model and start scheduler */
-        // FIXME: Implement OS task for model step
+        /* Create and lock semaphore */
+        vSemaphoreCreateBinary(step_signal);
+        xSemaphoreTake(step_signal, 0);
+
+        /* Create tasks to step model and start scheduler */
+        // FIXME: How to calculate / policy about model stack size
+        xTaskCreate(control_task, (signed char*) "control_task", 128,  NULL,
+            CONTROL_PRIORITY, NULL);
+        xTaskCreate(working_task, (signed char*) "working_task", 4096, NULL,
+            WORKING_PRIORITY, NULL);
         vTaskStartScheduler();
 
         // We should never get here
         %<LibCallModelTerminate()>\
-        while(1){
+        while(true) {
         }
     }
-  %closefile tmpBuf
 
-  %<LibSetSourceFileSection(cFile, "Functions", tmpBuf)>
+    %closefile tmpBuf
 
 %endfunction