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')
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);
% 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
%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