Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use timers to drive step function from main

  • Loading branch information...
commit ed1c1d488fcd6b4c857233f121139560d718bb1c 1 parent eb677a2
kyak authored
171 demos/ben_is_ben.mdl
... ... @@ -1,6 +1,6 @@
1 1 Model {
2 2 Name "ben_is_ben"
3   - Version 7.9
  3 + Version 8.0
4 4 MdlSubVersion 0
5 5 GraphicalInterface {
6 6 NumRootInports 1
@@ -16,7 +16,7 @@ Model {
16 16 Name "Out1"
17 17 }
18 18 ParameterArgumentNames ""
19   - ComputedModelVersion "1.26"
  19 + ComputedModelVersion "1.32"
20 20 NumModelReferences 0
21 21 NumTestPointedSignals 1
22 22 TestPointedSignal {
@@ -27,7 +27,7 @@ Model {
27 27 Decimation 2
28 28 }
29 29 }
30   - SavedCharacterEncoding "windows-1251"
  30 + SavedCharacterEncoding "UTF-8"
31 31 slprops.hdlmdlprops {
32 32 $PropName "HDLParams"
33 33 $ObjectID 1
@@ -49,15 +49,54 @@ Model {
49 49 MinMaxOverflowArchiveMode "Overwrite"
50 50 FPTRunName "Run 1"
51 51 MaxMDLFileLineLength 120
  52 + Object {
  53 + $PropName "BdWindowsInfo"
  54 + $ObjectID 2
  55 + $ClassName "Simulink.BDWindowsInfo"
  56 + Object {
  57 + $PropName "WindowsInfo"
  58 + $ObjectID 3
  59 + $ClassName "Simulink.WindowInfo"
  60 + IsActive [1]
  61 + Location [791.0, 115.0, 618.0, 20.0]
  62 + Object {
  63 + $PropName "ModelBrowserInfo"
  64 + $ObjectID 4
  65 + $ClassName "Simulink.ModelBrowserInfo"
  66 + Visible [0]
  67 + DockPosition "Left"
  68 + Width [50]
  69 + Height [50]
  70 + Filter [9]
  71 + }
  72 + Object {
  73 + $PropName "ExplorerBarInfo"
  74 + $ObjectID 5
  75 + $ClassName "Simulink.ExplorerBarInfo"
  76 + Visible [1]
  77 + }
  78 + Object {
  79 + $PropName "EditorsInfo"
  80 + $ObjectID 6
  81 + $ClassName "Simulink.EditorInfo"
  82 + IsActive [1]
  83 + ViewObjType "SimulinkTopLevel"
  84 + LoadSaveID "0"
  85 + Extents [593.0, 272.0]
  86 + ZoomFactor [1.0]
  87 + Offset [0.0, 0.0]
  88 + }
  89 + }
  90 + }
52 91 Created "Thu Oct 13 20:32:56 2011"
53 92 Creator "bas"
54 93 UpdateHistory "UpdateHistoryNever"
55 94 ModifiedByFormat "%<Auto>"
56 95 LastModifiedBy "bas"
57 96 ModifiedDateFormat "%<Auto>"
58   - LastModifiedDate "Sun Oct 07 14:40:56 2012"
59   - RTWModifiedTimeStamp 271521654
60   - ModelVersionFormat "1.%<AutoIncrement:26>"
  97 + LastModifiedDate "Fri Jan 04 16:54:34 2013"
  98 + RTWModifiedTimeStamp 279132714
  99 + ModelVersionFormat "1.%<AutoIncrement:32>"
61 100 ConfigurationManager "customverctrl"
62 101 SampleTimeColors off
63 102 SampleTimeAnnotations off
@@ -92,7 +131,7 @@ Model {
92 131 TryForcingSFcnDF off
93 132 Object {
94 133 $PropName "DataLoggingOverride"
95   - $ObjectID 2
  134 + $ObjectID 7
96 135 $ClassName "Simulink.SimulationData.ModelLoggingInfo"
97 136 model_ "ben_is_ben"
98 137 overrideMode_ [0.0]
@@ -151,18 +190,18 @@ Model {
151 190 Type "Handle"
152 191 Dimension 1
153 192 Simulink.ConfigSet {
154   - $ObjectID 3
155   - Version "1.12.0"
  193 + $ObjectID 8
  194 + Version "1.12.1"
156 195 Array {
157 196 Type "Handle"
158 197 Dimension 9
159 198 Simulink.SolverCC {
160   - $ObjectID 4
161   - Version "1.12.0"
  199 + $ObjectID 9
  200 + Version "1.12.1"
162 201 StartTime "0.0"
163 202 StopTime "10.0"
164 203 AbsTol "auto"
165   - FixedStep "auto"
  204 + FixedStep "0.1"
166 205 InitialStep "auto"
167 206 MaxNumMinSteps "-1"
168 207 MaxOrder 5
@@ -192,8 +231,8 @@ Model {
192 231 InsertRTBMode "Whenever possible"
193 232 }
194 233 Simulink.DataIOCC {
195   - $ObjectID 5
196   - Version "1.12.0"
  234 + $ObjectID 10
  235 + Version "1.12.1"
197 236 Decimation "1"
198 237 ExternalInput "[t, u]"
199 238 FinalStateName "xFinal"
@@ -224,8 +263,8 @@ Model {
224 263 Refine "1"
225 264 }
226 265 Simulink.OptimizationCC {
227   - $ObjectID 6
228   - Version "1.12.0"
  266 + $ObjectID 11
  267 + Version "1.12.1"
229 268 BlockReduction on
230 269 BooleanDataType on
231 270 ConditionallyExecuteInputs on
@@ -267,8 +306,8 @@ Model {
267 306 ParallelExecutionInRapidAccelerator on
268 307 }
269 308 Simulink.DebuggingCC {
270   - $ObjectID 7
271   - Version "1.12.0"
  309 + $ObjectID 12
  310 + Version "1.12.1"
272 311 RTPrefix "error"
273 312 ConsistencyChecking "none"
274 313 ArrayBoundsChecking "none"
@@ -317,7 +356,7 @@ Model {
317 356 UnnecessaryDatatypeConvMsg "none"
318 357 VectorMatrixConversionMsg "none"
319 358 InvalidFcnCallConnMsg "error"
320   - FcnCallInpInsideContextMsg "Enable All"
  359 + FcnCallInpInsideContextMsg "EnableAllAsWarning"
321 360 SignalLabelMismatchMsg "none"
322 361 UnconnectedInputMsg "warning"
323 362 UnconnectedOutputMsg "warning"
@@ -353,10 +392,12 @@ Model {
353 392 SFNoUnconditionalDefaultTransitionDiag "warning"
354 393 SFTransitionOutsideNaturalParentDiag "warning"
355 394 SFUnconditionalTransitionShadowingDiag "warning"
  395 + SFUndirectedBroadcastEventsDiag "warning"
  396 + SFTransitionActionBeforeConditionDiag "warning"
356 397 }
357 398 Simulink.HardwareCC {
358   - $ObjectID 8
359   - Version "1.12.0"
  399 + $ObjectID 13
  400 + Version "1.12.1"
360 401 ProdBitPerChar 8
361 402 ProdBitPerShort 16
362 403 ProdBitPerInt 32
@@ -392,8 +433,8 @@ Model {
392 433 ProdEqTarget on
393 434 }
394 435 Simulink.ModelReferenceCC {
395   - $ObjectID 9
396   - Version "1.12.0"
  436 + $ObjectID 14
  437 + Version "1.12.1"
397 438 UpdateModelReferenceTargets "IfOutOfDateOrStructuralChange"
398 439 CheckModelReferenceTargetMessage "error"
399 440 EnableParallelModelReferenceBuilds off
@@ -407,8 +448,8 @@ Model {
407 448 SupportModelReferenceSimTargetCustomCode off
408 449 }
409 450 Simulink.SFSimCC {
410   - $ObjectID 10
411   - Version "1.12.0"
  451 + $ObjectID 15
  452 + Version "1.12.1"
412 453 SFSimEnableDebug on
413 454 SFSimOverflowDetection on
414 455 SFSimEcho on
@@ -422,8 +463,8 @@ Model {
422 463 }
423 464 Simulink.RTWCC {
424 465 $BackupClass "Simulink.RTWCC"
425   - $ObjectID 11
426   - Version "1.12.0"
  466 + $ObjectID 16
  467 + Version "1.12.1"
427 468 Array {
428 469 Type "Cell"
429 470 Dimension 1
@@ -434,6 +475,7 @@ Model {
434 475 GenCodeOnly off
435 476 MakeCommand "make_rtw"
436 477 GenerateMakefile on
  478 + PackageGeneratedCodeAndArtifacts off
437 479 TemplateMakefile "nanonote.tmf"
438 480 Description "Ben NanoNote"
439 481 GenerateReport on
@@ -452,6 +494,13 @@ Model {
452 494 RTWUseSimCustomCode off
453 495 IncludeHyperlinkInReport on
454 496 LaunchReport off
  497 + PortableWordSizes on
  498 + GenerateErtSFunction off
  499 + CreateSILPILBlock "None"
  500 + CodeExecutionProfiling off
  501 + CodeExecutionProfileVariable "executionProfile"
  502 + CodeProfilingSaveOptions "SummaryOnly"
  503 + CodeProfilingInstrumentation off
455 504 TargetLang "C"
456 505 IncludeBusHierarchyInRTWFileBlockHierarchyMap off
457 506 IncludeERTFirstTime off
@@ -471,8 +520,8 @@ Model {
471 520 Type "Handle"
472 521 Dimension 2
473 522 Simulink.CodeAppCC {
474   - $ObjectID 12
475   - Version "1.12.0"
  523 + $ObjectID 17
  524 + Version "1.12.1"
476 525 ForceParamTrailComments off
477 526 GenerateComments on
478 527 IgnoreCustomStorageClasses off
@@ -482,6 +531,7 @@ Model {
482 531 PreserveName off
483 532 PreserveNameWithParent off
484 533 ShowEliminatedStatement off
  534 + OperatorAnnotations off
485 535 IncAutoGenComments off
486 536 SimulinkDataObjDesc off
487 537 SFDataObjDesc off
@@ -504,14 +554,15 @@ Model {
504 554 SimulinkBlockComments on
505 555 MATLABSourceComments off
506 556 EnableCustomComments off
  557 + InternalIdentifier "Classic"
507 558 InlinedPrmAccess "Literals"
508 559 ReqsInCode off
509 560 UseSimReservedNames off
510 561 }
511 562 Simulink.STFCustomTargetCC {
512 563 $BackupClass "Simulink.TargetCC"
513   - $ObjectID 13
514   - Version "1.12.0"
  564 + $ObjectID 18
  565 + Version "1.12.1"
515 566 Array {
516 567 Type "Cell"
517 568 Dimension 2
@@ -525,7 +576,6 @@ Model {
525 576 CodeReplacementLibrary "ANSI_C"
526 577 UtilityFuncGeneration "Auto"
527 578 ERTMultiwordTypeDef "System defined"
528   - CodeExecutionProfiling off
529 579 ERTMultiwordLength 256
530 580 MultiwordLength 2048
531 581 GenerateFullHeader on
@@ -556,7 +606,6 @@ Model {
556 606 SupportVariableSizeSignals off
557 607 EnableShiftOperators on
558 608 ParenthesesLevel "Nominal"
559   - PortableWordSizes on
560 609 ModelStepFunctionPrototypeControlCompliant off
561 610 CPPClassGenCompliant off
562 611 AutosarCompliant off
@@ -568,8 +617,8 @@ Model {
568 617 Dimension 1
569 618 Simulink.ERTTargetCC {
570 619 $BackupClass "Simulink.TargetCC"
571   - $ObjectID 14
572   - Version "1.12.0"
  620 + $ObjectID 19
  621 + Version "1.12.1"
573 622 Array {
574 623 Type "Cell"
575 624 Dimension 2
@@ -583,7 +632,6 @@ Model {
583 632 CodeReplacementLibrary "ANSI_C"
584 633 UtilityFuncGeneration "Auto"
585 634 ERTMultiwordTypeDef "System defined"
586   - CodeExecutionProfiling off
587 635 ERTMultiwordLength 256
588 636 MultiwordLength 2048
589 637 GenerateFullHeader on
@@ -614,15 +662,10 @@ Model {
614 662 SupportVariableSizeSignals off
615 663 EnableShiftOperators on
616 664 ParenthesesLevel "Nominal"
617   - PortableWordSizes on
618 665 ModelStepFunctionPrototypeControlCompliant off
619 666 CPPClassGenCompliant off
620 667 AutosarCompliant off
621 668 GRTInterface off
622   - GenerateErtSFunction off
623   - CreateSILPILBlock "None"
624   - CodeExecutionProfileVariable "executionProfile"
625   - CodeProfilingSaveOptions "SummaryOnly"
626 669 GenerateASAP2 off
627 670 ExtMode off
628 671 ExtModeTransport 0
@@ -646,7 +689,6 @@ Model {
646 689 ERTDataSrcFileTemplate "ert_code_template.cgt"
647 690 ERTDataHdrFileTemplate "ert_code_template.cgt"
648 691 ERTCustomFileTemplate "nanonote_main.tlc"
649   - CoverageDialogOpen "off"
650 692 EnableDataOwnership off
651 693 SignalDisplayLevel 10
652 694 ParamTuneLevel 10
@@ -688,22 +730,21 @@ Model {
688 730 MemSecFuncInitTerm "Default"
689 731 MemSecFuncExecute "Default"
690 732 MemSecFuncSharedUtil "Default"
691   - CodeProfilingInstrumentation off
692 733 }
693 734 PropName "Components"
694 735 }
695 736 CustomProperty {
696 737 DataType "slbool"
697 738 Name "NANONOTE_DOWNLOAD"
698   - Value on
  739 + Value off
699 740 }
700 741 }
701 742 PropName "Components"
702 743 }
703 744 }
704 745 hdlcoderui.hdlcc {
705   - $ObjectID 15
706   - Version "1.12.0"
  746 + $ObjectID 20
  747 + Version "1.12.1"
707 748 Description "HDL Coder custom configuration component"
708 749 Name "HDL Coder"
709 750 Array {
@@ -717,14 +758,25 @@ Model {
717 758 PropName "Components"
718 759 }
719 760 Name "Configuration"
720   - CurrentDlgPage "Code Generation"
721   - ConfigPrmDlgPosition [ 199, 65, 1081, 720 ]
  761 + ExtraOptions "-aGenerateTraceInfo=1 -aIgnoreTestpoints=0 "
  762 + CurrentDlgPage "Solver"
  763 + ConfigPrmDlgPosition [ 717, 192, 1599, 847 ]
722 764 }
723 765 PropName "ConfigurationSets"
724 766 }
725 767 Simulink.ConfigSet {
726 768 $PropName "ActiveConfigurationSet"
727   - $ObjectID 3
  769 + $ObjectID 8
  770 + }
  771 + Object {
  772 + $PropName "DataTransfer"
  773 + $ObjectID 21
  774 + $ClassName "Simulink.GlobalDataTransfer"
  775 + DefaultTransitionBetweenSyncTasks "Ensure deterministic transfer (maximum delay)"
  776 + DefaultTransitionBetweenAsyncTasks "Ensure data integrity only"
  777 + DefaultTransitionBetweenContTasks "Ensure deterministic transfer (minimum delay)"
  778 + DefaultExtrapolationMethodBetweenContTasks "None"
  779 + AutoInsertRateTranBlk [0]
728 780 }
729 781 ExplicitPartitioning off
730 782 BlockDefaults {
@@ -758,6 +810,25 @@ Model {
758 810 FontWeight "normal"
759 811 FontAngle "normal"
760 812 }
  813 + MaskDefaults {
  814 + SelfModifiable "off"
  815 + IconFrame "on"
  816 + IconOpaque "on"
  817 + RunInitForIconRedraw "off"
  818 + IconRotate "none"
  819 + PortRotate "default"
  820 + IconUnits "autoscale"
  821 + }
  822 + MaskParameterDefaults {
  823 + Evaluate "on"
  824 + Tunable "on"
  825 + NeverSave "off"
  826 + Internal "off"
  827 + ReadOnly "off"
  828 + Enabled "on"
  829 + Visible "on"
  830 + ToolTip "on"
  831 + }
761 832 BlockParameterDefaults {
762 833 Block {
763 834 BlockType Gain
@@ -812,7 +883,7 @@ Model {
812 883 }
813 884 System {
814 885 Name "ben_is_ben"
815   - Location [371, 205, 951, 465]
  886 + Location [791, 115, 1409, 135]
816 887 Open on
817 888 ModelBrowserVisibility off
818 889 ModelBrowserWidth 200
2  nanonote/nanonote.tmf
@@ -13,7 +13,7 @@ CXXDEBUG =
13 13
14 14 # Linker command and options
15 15 LD = STAGING_DIR=$(STAGING_DIR) "$(TOOLCHAIN_PREFIX)gcc"
16   -LDFLAGS = -lc -lm
  16 +LDFLAGS = -lc -lm -lrt -lpthread -ldl
17 17 LDDEBUG = -g
18 18 LDOUTPUTFLAG = -o
19 19
78 nanonote/nanonote_srmain.tlc
@@ -21,7 +21,22 @@
21 21
22 22 %openfile tmpBuf
23 23 #include "%<LibGetMdlPubHdrBaseName()>.h"
  24 + #include <signal.h> /* for sigaction() */
  25 + #include <time.h> /* for timer_*() */
24 26 #include <stdio.h> /* for printf() */
  27 + #include <unistd.h> /*for exit() */
  28 + #include <stdlib.h> /* for EXIT_FAILURE */
  29 + %if %<CompiledModel.FundamentalStepSize> < 1e-6
  30 + %warning Model step size must be bigger than 1 microsecond, defaulting to 1 second
  31 + #define STEP_SIZE_S 1
  32 + #define STEP_SIZE_US 0
  33 + %else
  34 + %assign SAMPLE_TIME_S = CAST("Number",FEVAL("floor",%<CompiledModel.FundamentalStepSize>))
  35 + #define STEP_SIZE_S %<SAMPLE_TIME_S>
  36 + %assign SAMPLE_TIME_FRAC = FEVAL("mod",%<CompiledModel.FundamentalStepSize>,%<SAMPLE_TIME_S>)
  37 + %assign SAMPLE_TIME_NS = CAST("Number",SAMPLE_TIME_FRAC*1000000000)
  38 + #define STEP_SIZE_NS %<SAMPLE_TIME_NS>
  39 + %endif
25 40 %closefile tmpBuf
26 41
27 42 %<LibSetSourceFileSection(cFile, "Includes", tmpBuf)>
@@ -55,7 +70,7 @@
55 70 %endif
56 71
57 72 %<LibCallModelStep(0)>\
58   -
  73 +
59 74 %assign varsbuf = LibWriteModelOutputs()
60 75 %if varsbuf != ""
61 76 /* Remove conditional, and get model outputs here */
@@ -68,7 +83,29 @@
68 83 /* Restore FPU context here (if necessary) */
69 84 /* Enable interrupts here */
70 85 }
71   -
  86 +
  87 + #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0)
  88 +
  89 + void timer_handler (int sig, siginfo_t *si, void *uc)
  90 + {
  91 + //static int counter = 0;
  92 + timer_t *tidp;
  93 + int or;
  94 + //printf("Caught signal %d\n", sig);
  95 + tidp = si->si_value.sival_ptr;
  96 +
  97 + //printf(" sival_ptr = %p; ", si->si_value.sival_ptr);
  98 + //printf(" *sival_ptr = 0x%lx\n", (long) *tidp);
  99 +
  100 + or = timer_getoverrun(*tidp);
  101 + if (or == -1 || or > 0)
  102 + OverrunFlag++;
  103 + //printf("timer_getoverrun: %d's step\n",++counter);
  104 +
  105 + rt_OneStep();
  106 + //sleep(1);
  107 + }
  108 +
72 109 %assign fcnReturns = "int_T"
73 110 %assign fcnName = "main"
74 111 %assign fcnParams = "int_T argc, const char_T *argv[]"
@@ -84,14 +121,39 @@
84 121 %<LibCallModelInitialize()>\
85 122
86 123 /* Associate rt_OneStep() with a timer that executes at the base rate of the model */
  124 + timer_t timerid;
  125 + struct sigevent sev;
  126 + struct itimerspec its;
  127 + struct sigaction sa;
  128 +
  129 + /* Establish handler for timer signal */
  130 + //printf("Establishing handler for signal %d\n", SIGRTMIN);
  131 + sa.sa_flags = SA_SIGINFO;
  132 + sa.sa_sigaction = timer_handler;
  133 + sigemptyset(&sa.sa_mask);
  134 + if (sigaction(SIGRTMIN, &sa, NULL) == -1)
  135 + errExit("sigaction");
  136 +
  137 + /* Create the timer */
  138 + sev.sigev_notify = SIGEV_SIGNAL;
  139 + sev.sigev_signo = SIGRTMIN;
  140 + sev.sigev_value.sival_ptr = &timerid;
  141 + if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1)
  142 + errExit("timer_create");
  143 + //printf("timer ID is 0x%lx\n", (long) timerid);
87 144
88   - int i;
89   - for (i = 0; i++; i<2000)
  145 + /* Start the timer */
  146 + its.it_value.tv_sec = STEP_SIZE_S;
  147 + its.it_value.tv_nsec = STEP_SIZE_NS;
  148 + its.it_interval.tv_sec = its.it_value.tv_sec;
  149 + its.it_interval.tv_nsec = its.it_value.tv_nsec;
  150 + if (timer_settime(timerid, 0, &its, NULL) == -1)
  151 + errExit("timer_settime");
  152 +
  153 + while(1)
90 154 {
91   - rt_OneStep();
92 155 }
93   -
94   - printf("Good job!\n");
  156 +
95 157 %<LibCallModelTerminate()>\
96 158 return 0;
97 159 }
@@ -107,4 +169,4 @@
107 169 %assign mdlName = LibGetModelName()
108 170 %assign mainFileName = "main_%<mdlName>"
109 171 %<FcnSingleTaskingMain(mainFileName)>
110   -%endif
  172 +%endif

0 comments on commit ed1c1d4

Please sign in to comment.
Something went wrong with that request. Please try again.