build_cmake/OMCompiler/Compiler/generated-mo/Template/CodegenESP32.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | encapsulated package CodegenESP32 | ||
| 2 | " | ||
| 3 | file: CodegenESP32.mo | ||
| 4 | package: CodegenESP32 | ||
| 5 | description: Generated by Susan. | ||
| 6 | " | ||
| 7 | |||
| 8 | public import Tpl; | ||
| 9 | |||
| 10 | public import SimCodeVar; | ||
| 11 | public import HashTableCrefSimVar; | ||
| 12 | public import SimCode; | ||
| 13 | public import SimCodeFunction; | ||
| 14 | public import SimCodeCodegenUtil; | ||
| 15 | public import SimCodeFunctionUtil; | ||
| 16 | public import BackendDAE; | ||
| 17 | public import System; | ||
| 18 | public import Autoconf; | ||
| 19 | protected import Absyn; | ||
| 20 | protected import AbsynUtil; | ||
| 21 | public import MMath; | ||
| 22 | public import DAE; | ||
| 23 | public import ClassInf; | ||
| 24 | public import ClassInfUtil; | ||
| 25 | protected import SCode; | ||
| 26 | protected import SCodeDump; | ||
| 27 | public import StringUtil; | ||
| 28 | public import Util; | ||
| 29 | public import List; | ||
| 30 | public import ComponentReferenceBasics; | ||
| 31 | public import ComponentReference; | ||
| 32 | public import Expression; | ||
| 33 | protected import ExpressionDump; | ||
| 34 | public import ExpressionBasics; | ||
| 35 | public import Config; | ||
| 36 | public import Testsuite; | ||
| 37 | public import Flags; | ||
| 38 | public import FlagsUtil; | ||
| 39 | public import Settings; | ||
| 40 | public import Patternm; | ||
| 41 | public import Error; | ||
| 42 | public import Values; | ||
| 43 | public import ValuesUtil; | ||
| 44 | public import DAEDump; | ||
| 45 | public import Algorithm; | ||
| 46 | protected import ElementSource; | ||
| 47 | public import DAEUtil; | ||
| 48 | public import TypesDump; | ||
| 49 | public import Types; | ||
| 50 | public import HashTableCrIListArray; | ||
| 51 | public import BackendVariable; | ||
| 52 | public import HpcOmSimCode; | ||
| 53 | public import HpcOmCodegenUtil; | ||
| 54 | public import FMI; | ||
| 55 | public import CodegenUtil; | ||
| 56 | public import CodegenUtilSimulation; | ||
| 57 | public import CodegenEmbeddedC; | ||
| 58 | |||
| 59 | protected function fun_50 | ||
| 60 | input Tpl.Text in_txt; | ||
| 61 | input SimCode.SimCode in_a_simCode; | ||
| 62 | input Tpl.Text in_a_modelNamePrefixStr; | ||
| 63 | |||
| 64 | output Tpl.Text out_txt; | ||
| 65 | algorithm | ||
| 66 | out_txt := | ||
| 67 | match(in_txt, in_a_simCode, in_a_modelNamePrefixStr) | ||
| 68 | local | ||
| 69 | Tpl.Text txt; | ||
| 70 | Tpl.Text a_modelNamePrefixStr; | ||
| 71 | Absyn.Path i_modelInfo_name; | ||
| 72 | |||
| 73 | case ( txt, | ||
| 74 | SimCode.SIMCODE(modelInfo = SimCode.MODELINFO(name = i_modelInfo_name)), | ||
| 75 | a_modelNamePrefixStr ) | ||
| 76 | algorithm | ||
| 77 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("# Generated by OpenModelica from ")); | |
| 78 | ✗ | txt := CodegenUtil.dotPath(txt, i_modelInfo_name); | |
| 79 | ✗ | txt := Tpl.softNewLine(txt); | |
| 80 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 81 | "cmake_minimum_required(VERSION 3.16)\n", | ||
| 82 | "\n", | ||
| 83 | "include($ENV{IDF_PATH}/tools/cmake/project.cmake)\n", | ||
| 84 | "project(" | ||
| 85 | }, false)); | ||
| 86 | ✗ | txt := Tpl.writeText(txt, a_modelNamePrefixStr); | |
| 87 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("_esp32 C)")); | |
| 88 | then txt; | ||
| 89 | |||
| 90 | case ( txt, | ||
| 91 | _, | ||
| 92 | _ ) | ||
| 93 | then txt; | ||
| 94 | end match; | ||
| 95 | end fun_50; | ||
| 96 | |||
| 97 | public function projectCMakeFile | ||
| 98 | input Tpl.Text txt; | ||
| 99 | input SimCode.SimCode a_simCode; | ||
| 100 | |||
| 101 | output Tpl.Text out_txt; | ||
| 102 | protected | ||
| 103 | Tpl.Text l_modelNamePrefixStr; | ||
| 104 | algorithm | ||
| 105 | ✗ | l_modelNamePrefixStr := CodegenUtilSimulation.modelNamePrefix(Tpl.emptyTxt, a_simCode); | |
| 106 | ✗ | out_txt := fun_50(txt, a_simCode, l_modelNamePrefixStr); | |
| 107 | end projectCMakeFile; | ||
| 108 | |||
| 109 | public function componentCMakeFile | ||
| 110 | input Tpl.Text txt; | ||
| 111 | input SimCode.SimCode a_simCode; | ||
| 112 | |||
| 113 | output Tpl.Text out_txt; | ||
| 114 | protected | ||
| 115 | Tpl.Text l_modelNamePrefixStr; | ||
| 116 | algorithm | ||
| 117 | ✗ | l_modelNamePrefixStr := CodegenUtilSimulation.modelNamePrefix(Tpl.emptyTxt, a_simCode); | |
| 118 | ✗ | out_txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 119 | "# Generated by OpenModelica\n", | ||
| 120 | "idf_component_register(SRCS \"main.c\" \"" | ||
| 121 | }, false)); | ||
| 122 | ✗ | out_txt := Tpl.writeText(out_txt, l_modelNamePrefixStr); | |
| 123 | ✗ | out_txt := Tpl.writeTok(out_txt, Tpl.ST_STRING_LIST({ | |
| 124 | "_model.c\"\n", | ||
| 125 | " INCLUDE_DIRS \".\")" | ||
| 126 | }, false)); | ||
| 127 | end componentCMakeFile; | ||
| 128 | |||
| 129 | public function sdkconfigFile | ||
| 130 | input Tpl.Text txt; | ||
| 131 | input SimCode.SimCode a_simCode; | ||
| 132 | |||
| 133 | output Tpl.Text out_txt; | ||
| 134 | algorithm | ||
| 135 | ✗ | out_txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 136 | "# Generated by OpenModelica\n", | ||
| 137 | "# The chip the model is built for. Override with `idf.py set-target <chip>`.\n", | ||
| 138 | "CONFIG_IDF_TARGET=\"esp32c6\"\n", | ||
| 139 | "# Print the results on UART0, which is the port the USB-serial bridge of the\n", | ||
| 140 | "# devkit is wired to, and therefore the same port the board is flashed over.\n", | ||
| 141 | "# Replace this with CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y to print them on the\n", | ||
| 142 | "# built in USB-Serial-JTAG port instead, which enumerates as a port of its own.\n", | ||
| 143 | "CONFIG_ESP_CONSOLE_UART_DEFAULT=y\n", | ||
| 144 | "# The reduced formatting of newlib-nano does not print doubles, and the whole\n", | ||
| 145 | "# output of the simulation is doubles.\n", | ||
| 146 | "CONFIG_NEWLIB_NANO_FORMAT=n\n", | ||
| 147 | "# The model is solved in floating point, so keep the FPU related optimizations\n", | ||
| 148 | "# and compile for speed rather than for size.\n", | ||
| 149 | "CONFIG_COMPILER_OPTIMIZATION_PERF=y" | ||
| 150 | }, false)); | ||
| 151 | end sdkconfigFile; | ||
| 152 | |||
| 153 | protected function fun_54 | ||
| 154 | input Tpl.Text in_txt; | ||
| 155 | input SimCode.SimCode in_a_simCode; | ||
| 156 | input Tpl.Text in_a_modelNamePrefixStr; | ||
| 157 | |||
| 158 | output Tpl.Text out_txt; | ||
| 159 | algorithm | ||
| 160 | out_txt := | ||
| 161 | match(in_txt, in_a_simCode, in_a_modelNamePrefixStr) | ||
| 162 | local | ||
| 163 | Tpl.Text txt; | ||
| 164 | Tpl.Text a_modelNamePrefixStr; | ||
| 165 | SimCode.VarInfo i_varInfo; | ||
| 166 | Real i_settings_stepSize; | ||
| 167 | Real i_settings_stopTime; | ||
| 168 | Real i_settings_startTime; | ||
| 169 | Absyn.Path i_modelInfo_name; | ||
| 170 | Integer ret_0; | ||
| 171 | |||
| 172 | case ( txt, | ||
| 173 | SimCode.SIMCODE(simulationSettingsOpt = NONE()), | ||
| 174 | _ ) | ||
| 175 | algorithm | ||
| 176 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenESP32.tpl", 118, 9), "Missing simulation settings"); | |
| 177 | then txt; | ||
| 178 | |||
| 179 | case ( txt, | ||
| 180 | SimCode.SIMCODE(modelInfo = SimCode.MODELINFO(varInfo = (i_varInfo as SimCode.VARINFO(numZeroCrossings = _)), name = i_modelInfo_name), simulationSettingsOpt = SOME(SimCode.SIMULATION_SETTINGS(startTime = i_settings_startTime, stopTime = i_settings_stopTime, stepSize = i_settings_stepSize))), | ||
| 181 | a_modelNamePrefixStr ) | ||
| 182 | algorithm | ||
| 183 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("/* Generated by OpenModelica from ")); | |
| 184 | ✗ | txt := CodegenUtil.dotPath(txt, i_modelInfo_name); | |
| 185 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 186 | " */\n", | ||
| 187 | "#ifndef OM_" | ||
| 188 | }, false)); | ||
| 189 | ✗ | txt := Tpl.writeText(txt, a_modelNamePrefixStr); | |
| 190 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 191 | "_MODEL_H\n", | ||
| 192 | "#define OM_" | ||
| 193 | }, false)); | ||
| 194 | ✗ | txt := Tpl.writeText(txt, a_modelNamePrefixStr); | |
| 195 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 196 | "_MODEL_H\n", | ||
| 197 | "\n", | ||
| 198 | "#define OM_MODEL_NAME \"" | ||
| 199 | }, false)); | ||
| 200 | ✗ | txt := CodegenUtil.dotPath(txt, i_modelInfo_name); | |
| 201 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 202 | "\"\n", | ||
| 203 | "#define OM_START_TIME (" | ||
| 204 | }, false)); | ||
| 205 | ✗ | txt := Tpl.writeStr(txt, realString(i_settings_startTime)); | |
| 206 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 207 | ")\n", | ||
| 208 | "#define OM_STOP_TIME (" | ||
| 209 | }, false)); | ||
| 210 | ✗ | txt := Tpl.writeStr(txt, realString(i_settings_stopTime)); | |
| 211 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 212 | ")\n", | ||
| 213 | "#define OM_STEP_SIZE (" | ||
| 214 | }, false)); | ||
| 215 | ✗ | txt := Tpl.writeStr(txt, realString(i_settings_stepSize)); | |
| 216 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 217 | ")\n", | ||
| 218 | "#define OM_NUM_REAL (" | ||
| 219 | }, false)); | ||
| 220 | ✗ | ret_0 := SimCodeCodegenUtil.nVariablesReal(i_varInfo); | |
| 221 | ✗ | txt := Tpl.writeStr(txt, intString(ret_0)); | |
| 222 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 223 | ")\n", | ||
| 224 | "\n", | ||
| 225 | "/* The same scalar types the embedded C target uses, so that the equations and\n", | ||
| 226 | " the functions below are generated by the very same templates. They are\n", | ||
| 227 | " spelled out here instead of being included from fmi2TypesPlatform.h to keep\n", | ||
| 228 | " the generated project free of any OpenModelica include path. */\n", | ||
| 229 | "typedef double fmi2Real;\n", | ||
| 230 | "typedef int fmi2Integer;\n", | ||
| 231 | "typedef int fmi2Boolean;\n", | ||
| 232 | "typedef char fmi2Char;\n", | ||
| 233 | "typedef const fmi2Char* fmi2String;\n", | ||
| 234 | "\n", | ||
| 235 | "#define fmi2True 1\n", | ||
| 236 | "#define fmi2False 0\n", | ||
| 237 | "\n", | ||
| 238 | "typedef enum {\n", | ||
| 239 | " fmi2OK = 0,\n", | ||
| 240 | " fmi2Warning,\n", | ||
| 241 | " fmi2Discard,\n", | ||
| 242 | " fmi2Error,\n", | ||
| 243 | " fmi2Fatal,\n", | ||
| 244 | " fmi2Pending\n", | ||
| 245 | "} fmi2Status;\n", | ||
| 246 | "\n", | ||
| 247 | "typedef struct " | ||
| 248 | }, false)); | ||
| 249 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2Component_s"); | |
| 250 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 251 | "* fmi2Component;\n", | ||
| 252 | "\n", | ||
| 253 | "/* Names of the real variables, in the order " | ||
| 254 | }, false)); | ||
| 255 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "getReal"); | |
| 256 | ✗ | txt := Tpl.softNewLine(txt); | |
| 257 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 258 | " indexes them: the states first, then the state derivatives, then the\n", | ||
| 259 | " algebraic and the discrete real variables. */\n", | ||
| 260 | "extern const char * const " | ||
| 261 | }, false)); | ||
| 262 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "realNames"); | |
| 263 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 264 | "[OM_NUM_REAL];\n", | ||
| 265 | "\n", | ||
| 266 | "/* The single statically allocated instance of the model. There is no heap\n", | ||
| 267 | " allocation anywhere in the generated code. */\n", | ||
| 268 | "fmi2Component " | ||
| 269 | }, false)); | ||
| 270 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "instantiate"); | |
| 271 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 272 | "(void);\n", | ||
| 273 | "/* Sets the time and evaluates the equations once, so that the variables are\n", | ||
| 274 | " consistent before the first step is taken. */\n", | ||
| 275 | "fmi2Status " | ||
| 276 | }, false)); | ||
| 277 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "initialize"); | |
| 278 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 279 | "(fmi2Component comp, fmi2Real startTime);\n", | ||
| 280 | "/* One explicit Euler step of size stepSize, taken from currentTime. */\n", | ||
| 281 | "fmi2Status " | ||
| 282 | }, false)); | ||
| 283 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "step"); | |
| 284 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 285 | "(fmi2Component comp, fmi2Real currentTime, fmi2Real stepSize);\n", | ||
| 286 | "fmi2Real " | ||
| 287 | }, false)); | ||
| 288 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "getTime"); | |
| 289 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 290 | "(fmi2Component comp);\n", | ||
| 291 | "fmi2Real " | ||
| 292 | }, false)); | ||
| 293 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "getReal"); | |
| 294 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 295 | "(fmi2Component comp, int index);\n", | ||
| 296 | "\n", | ||
| 297 | "#endif /* OM_" | ||
| 298 | }, false)); | ||
| 299 | ✗ | txt := Tpl.writeText(txt, a_modelNamePrefixStr); | |
| 300 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("_MODEL_H */")); | |
| 301 | then txt; | ||
| 302 | |||
| 303 | case ( txt, | ||
| 304 | _, | ||
| 305 | _ ) | ||
| 306 | then txt; | ||
| 307 | end match; | ||
| 308 | end fun_54; | ||
| 309 | |||
| 310 | public function modelHeaderFile | ||
| 311 | input Tpl.Text txt; | ||
| 312 | input SimCode.SimCode a_simCode; | ||
| 313 | |||
| 314 | output Tpl.Text out_txt; | ||
| 315 | protected | ||
| 316 | Tpl.Text l_modelNamePrefixStr; | ||
| 317 | algorithm | ||
| 318 | ✗ | l_modelNamePrefixStr := CodegenUtilSimulation.modelNamePrefix(Tpl.emptyTxt, a_simCode); | |
| 319 | ✗ | out_txt := fun_54(txt, a_simCode, l_modelNamePrefixStr); | |
| 320 | end modelHeaderFile; | ||
| 321 | |||
| 322 | protected function fun_56 | ||
| 323 | input Tpl.Text in_txt; | ||
| 324 | input Integer in_mArg; | ||
| 325 | |||
| 326 | output Tpl.Text out_txt; | ||
| 327 | algorithm | ||
| 328 | out_txt := | ||
| 329 | match(in_txt, in_mArg) | ||
| 330 | local | ||
| 331 | Tpl.Text txt; | ||
| 332 | Integer i_n; | ||
| 333 | |||
| 334 | case ( txt, | ||
| 335 | 0 ) | ||
| 336 | then txt; | ||
| 337 | |||
| 338 | case ( txt, | ||
| 339 | i_n ) | ||
| 340 | algorithm | ||
| 341 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Real fmi2RealVars[")); | |
| 342 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 343 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 344 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 345 | then txt; | ||
| 346 | end match; | ||
| 347 | end fun_56; | ||
| 348 | |||
| 349 | protected function fun_57 | ||
| 350 | input Tpl.Text in_txt; | ||
| 351 | input Integer in_a_varInfo_numIntAlgVars; | ||
| 352 | |||
| 353 | output Tpl.Text out_txt; | ||
| 354 | algorithm | ||
| 355 | out_txt := | ||
| 356 | match(in_txt, in_a_varInfo_numIntAlgVars) | ||
| 357 | local | ||
| 358 | Tpl.Text txt; | ||
| 359 | Integer i_n; | ||
| 360 | |||
| 361 | case ( txt, | ||
| 362 | 0 ) | ||
| 363 | then txt; | ||
| 364 | |||
| 365 | case ( txt, | ||
| 366 | i_n ) | ||
| 367 | algorithm | ||
| 368 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Integer fmi2IntegerVars[")); | |
| 369 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 370 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 371 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 372 | then txt; | ||
| 373 | end match; | ||
| 374 | end fun_57; | ||
| 375 | |||
| 376 | protected function fun_58 | ||
| 377 | input Tpl.Text in_txt; | ||
| 378 | input Integer in_a_varInfo_numBoolAlgVars; | ||
| 379 | |||
| 380 | output Tpl.Text out_txt; | ||
| 381 | algorithm | ||
| 382 | out_txt := | ||
| 383 | match(in_txt, in_a_varInfo_numBoolAlgVars) | ||
| 384 | local | ||
| 385 | Tpl.Text txt; | ||
| 386 | Integer i_n; | ||
| 387 | |||
| 388 | case ( txt, | ||
| 389 | 0 ) | ||
| 390 | then txt; | ||
| 391 | |||
| 392 | case ( txt, | ||
| 393 | i_n ) | ||
| 394 | algorithm | ||
| 395 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Boolean fmi2BooleanVars[")); | |
| 396 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 397 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 398 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 399 | then txt; | ||
| 400 | end match; | ||
| 401 | end fun_58; | ||
| 402 | |||
| 403 | protected function fun_59 | ||
| 404 | input Tpl.Text in_txt; | ||
| 405 | input Integer in_a_varInfo_numStringAlgVars; | ||
| 406 | |||
| 407 | output Tpl.Text out_txt; | ||
| 408 | algorithm | ||
| 409 | out_txt := | ||
| 410 | match(in_txt, in_a_varInfo_numStringAlgVars) | ||
| 411 | local | ||
| 412 | Tpl.Text txt; | ||
| 413 | |||
| 414 | case ( txt, | ||
| 415 | 0 ) | ||
| 416 | then txt; | ||
| 417 | |||
| 418 | case ( txt, | ||
| 419 | _ ) | ||
| 420 | algorithm | ||
| 421 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenESP32.tpl", 215, 16), "String variables not supported yet"); | |
| 422 | then txt; | ||
| 423 | end match; | ||
| 424 | end fun_59; | ||
| 425 | |||
| 426 | protected function fun_60 | ||
| 427 | input Tpl.Text in_txt; | ||
| 428 | input Integer in_a_varInfo_numParams; | ||
| 429 | |||
| 430 | output Tpl.Text out_txt; | ||
| 431 | algorithm | ||
| 432 | out_txt := | ||
| 433 | match(in_txt, in_a_varInfo_numParams) | ||
| 434 | local | ||
| 435 | Tpl.Text txt; | ||
| 436 | Integer i_n; | ||
| 437 | |||
| 438 | case ( txt, | ||
| 439 | 0 ) | ||
| 440 | then txt; | ||
| 441 | |||
| 442 | case ( txt, | ||
| 443 | i_n ) | ||
| 444 | algorithm | ||
| 445 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Real fmi2RealParameter[")); | |
| 446 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 447 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 448 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 449 | then txt; | ||
| 450 | end match; | ||
| 451 | end fun_60; | ||
| 452 | |||
| 453 | protected function fun_61 | ||
| 454 | input Tpl.Text in_txt; | ||
| 455 | input Integer in_a_varInfo_numIntParams; | ||
| 456 | |||
| 457 | output Tpl.Text out_txt; | ||
| 458 | algorithm | ||
| 459 | out_txt := | ||
| 460 | match(in_txt, in_a_varInfo_numIntParams) | ||
| 461 | local | ||
| 462 | Tpl.Text txt; | ||
| 463 | Integer i_n; | ||
| 464 | |||
| 465 | case ( txt, | ||
| 466 | 0 ) | ||
| 467 | then txt; | ||
| 468 | |||
| 469 | case ( txt, | ||
| 470 | i_n ) | ||
| 471 | algorithm | ||
| 472 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Integer fmi2IntegerParameter[")); | |
| 473 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 474 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 475 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 476 | then txt; | ||
| 477 | end match; | ||
| 478 | end fun_61; | ||
| 479 | |||
| 480 | protected function fun_62 | ||
| 481 | input Tpl.Text in_txt; | ||
| 482 | input Integer in_a_varInfo_numBoolParams; | ||
| 483 | |||
| 484 | output Tpl.Text out_txt; | ||
| 485 | algorithm | ||
| 486 | out_txt := | ||
| 487 | match(in_txt, in_a_varInfo_numBoolParams) | ||
| 488 | local | ||
| 489 | Tpl.Text txt; | ||
| 490 | Integer i_n; | ||
| 491 | |||
| 492 | case ( txt, | ||
| 493 | 0 ) | ||
| 494 | then txt; | ||
| 495 | |||
| 496 | case ( txt, | ||
| 497 | i_n ) | ||
| 498 | algorithm | ||
| 499 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Boolean fmi2BooleanParameter[")); | |
| 500 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 501 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 502 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 503 | then txt; | ||
| 504 | end match; | ||
| 505 | end fun_62; | ||
| 506 | |||
| 507 | protected function fun_63 | ||
| 508 | input Tpl.Text in_txt; | ||
| 509 | input Integer in_mArg; | ||
| 510 | |||
| 511 | output Tpl.Text out_txt; | ||
| 512 | algorithm | ||
| 513 | out_txt := | ||
| 514 | match(in_txt, in_mArg) | ||
| 515 | local | ||
| 516 | Tpl.Text txt; | ||
| 517 | Integer i_n; | ||
| 518 | |||
| 519 | case ( txt, | ||
| 520 | 0 ) | ||
| 521 | then txt; | ||
| 522 | |||
| 523 | case ( txt, | ||
| 524 | i_n ) | ||
| 525 | algorithm | ||
| 526 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("void* extObjs[")); | |
| 527 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 528 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 529 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 530 | then txt; | ||
| 531 | end match; | ||
| 532 | end fun_63; | ||
| 533 | |||
| 534 | protected function lm_64 | ||
| 535 | input output Tpl.Text txt; | ||
| 536 | input list<SimCodeVar.SimVar> items; | ||
| 537 | algorithm | ||
| 538 | ✗ | for lstElt_64 in items loop | |
| 539 | txt := match lstElt_64 | ||
| 540 | local | ||
| 541 | SimCodeVar.SimVar i_var; | ||
| 542 | |||
| 543 | case i_var | ||
| 544 | algorithm | ||
| 545 | ✗ | txt := CodegenEmbeddedC.startValue(txt, i_var); | |
| 546 | then txt; | ||
| 547 | end match; | ||
| 548 | end for; | ||
| 549 | end lm_64; | ||
| 550 | |||
| 551 | protected function lm_65 | ||
| 552 | input output Tpl.Text txt; | ||
| 553 | input list<SimCodeVar.SimVar> items; | ||
| 554 | algorithm | ||
| 555 | ✗ | for lstElt_65 in items loop | |
| 556 | txt := match lstElt_65 | ||
| 557 | local | ||
| 558 | SimCodeVar.SimVar i_var; | ||
| 559 | |||
| 560 | case i_var | ||
| 561 | algorithm | ||
| 562 | ✗ | txt := CodegenEmbeddedC.startValue(txt, i_var); | |
| 563 | then txt; | ||
| 564 | end match; | ||
| 565 | end for; | ||
| 566 | end lm_65; | ||
| 567 | |||
| 568 | protected function lm_66 | ||
| 569 | input output Tpl.Text txt; | ||
| 570 | input list<SimCodeVar.SimVar> items; | ||
| 571 | algorithm | ||
| 572 | ✗ | for lstElt_66 in items loop | |
| 573 | txt := match lstElt_66 | ||
| 574 | local | ||
| 575 | SimCodeVar.SimVar i_var; | ||
| 576 | |||
| 577 | case i_var | ||
| 578 | algorithm | ||
| 579 | ✗ | txt := CodegenEmbeddedC.startValue(txt, i_var); | |
| 580 | then txt; | ||
| 581 | end match; | ||
| 582 | end for; | ||
| 583 | end lm_66; | ||
| 584 | |||
| 585 | protected function lm_67 | ||
| 586 | input output Tpl.Text txt; | ||
| 587 | input list<SimCodeVar.SimVar> items; | ||
| 588 | algorithm | ||
| 589 | ✗ | for lstElt_67 in items loop | |
| 590 | txt := match lstElt_67 | ||
| 591 | local | ||
| 592 | SimCodeVar.SimVar i_var; | ||
| 593 | |||
| 594 | case i_var | ||
| 595 | algorithm | ||
| 596 | ✗ | txt := CodegenEmbeddedC.startValue(txt, i_var); | |
| 597 | then txt; | ||
| 598 | end match; | ||
| 599 | end for; | ||
| 600 | end lm_67; | ||
| 601 | |||
| 602 | protected function lm_68 | ||
| 603 | input output Tpl.Text txt; | ||
| 604 | input list<SimCodeVar.SimVar> items; | ||
| 605 | algorithm | ||
| 606 | ✗ | for lstElt_68 in items loop | |
| 607 | txt := match lstElt_68 | ||
| 608 | local | ||
| 609 | SimCodeVar.SimVar i_var; | ||
| 610 | |||
| 611 | case i_var | ||
| 612 | algorithm | ||
| 613 | ✗ | txt := CodegenEmbeddedC.startValue(txt, i_var); | |
| 614 | then txt; | ||
| 615 | end match; | ||
| 616 | end for; | ||
| 617 | end lm_68; | ||
| 618 | |||
| 619 | protected function lm_69 | ||
| 620 | input output Tpl.Text txt; | ||
| 621 | input list<SimCodeVar.SimVar> items; | ||
| 622 | algorithm | ||
| 623 | ✗ | for lstElt_69 in items loop | |
| 624 | txt := match lstElt_69 | ||
| 625 | local | ||
| 626 | SimCodeVar.SimVar i_var; | ||
| 627 | |||
| 628 | case i_var | ||
| 629 | algorithm | ||
| 630 | ✗ | txt := CodegenEmbeddedC.startValue(txt, i_var); | |
| 631 | then txt; | ||
| 632 | end match; | ||
| 633 | end for; | ||
| 634 | end lm_69; | ||
| 635 | |||
| 636 | protected function fun_70 | ||
| 637 | input Tpl.Text in_txt; | ||
| 638 | input Integer in_mArg; | ||
| 639 | input list<SimCodeVar.SimVar> in_a_vars_realOptimizeFinalConstraintsVars; | ||
| 640 | input list<SimCodeVar.SimVar> in_a_vars_realOptimizeConstraintsVars; | ||
| 641 | input list<SimCodeVar.SimVar> in_a_vars_discreteAlgVars; | ||
| 642 | input list<SimCodeVar.SimVar> in_a_vars_algVars; | ||
| 643 | input list<SimCodeVar.SimVar> in_a_vars_derivativeVars; | ||
| 644 | input list<SimCodeVar.SimVar> in_a_vars_stateVars; | ||
| 645 | |||
| 646 | output Tpl.Text out_txt; | ||
| 647 | algorithm | ||
| 648 | out_txt := | ||
| 649 | match(in_txt, in_mArg, in_a_vars_realOptimizeFinalConstraintsVars, in_a_vars_realOptimizeConstraintsVars, in_a_vars_discreteAlgVars, in_a_vars_algVars, in_a_vars_derivativeVars, in_a_vars_stateVars) | ||
| 650 | local | ||
| 651 | Tpl.Text txt; | ||
| 652 | list<SimCodeVar.SimVar> a_vars_realOptimizeFinalConstraintsVars; | ||
| 653 | list<SimCodeVar.SimVar> a_vars_realOptimizeConstraintsVars; | ||
| 654 | list<SimCodeVar.SimVar> a_vars_discreteAlgVars; | ||
| 655 | list<SimCodeVar.SimVar> a_vars_algVars; | ||
| 656 | list<SimCodeVar.SimVar> a_vars_derivativeVars; | ||
| 657 | list<SimCodeVar.SimVar> a_vars_stateVars; | ||
| 658 | |||
| 659 | case ( txt, | ||
| 660 | 0, | ||
| 661 | _, | ||
| 662 | _, | ||
| 663 | _, | ||
| 664 | _, | ||
| 665 | _, | ||
| 666 | _ ) | ||
| 667 | then txt; | ||
| 668 | |||
| 669 | case ( txt, | ||
| 670 | _, | ||
| 671 | a_vars_realOptimizeFinalConstraintsVars, | ||
| 672 | a_vars_realOptimizeConstraintsVars, | ||
| 673 | a_vars_discreteAlgVars, | ||
| 674 | a_vars_algVars, | ||
| 675 | a_vars_derivativeVars, | ||
| 676 | a_vars_stateVars ) | ||
| 677 | algorithm | ||
| 678 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2RealVars = {\n")); | |
| 679 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 680 | ✗ | txt := lm_64(txt, a_vars_stateVars); | |
| 681 | ✗ | txt := Tpl.softNewLine(txt); | |
| 682 | ✗ | txt := lm_65(txt, a_vars_derivativeVars); | |
| 683 | ✗ | txt := Tpl.softNewLine(txt); | |
| 684 | ✗ | txt := lm_66(txt, a_vars_algVars); | |
| 685 | ✗ | txt := Tpl.softNewLine(txt); | |
| 686 | ✗ | txt := lm_67(txt, a_vars_discreteAlgVars); | |
| 687 | ✗ | txt := Tpl.softNewLine(txt); | |
| 688 | ✗ | txt := lm_68(txt, a_vars_realOptimizeConstraintsVars); | |
| 689 | ✗ | txt := Tpl.softNewLine(txt); | |
| 690 | ✗ | txt := lm_69(txt, a_vars_realOptimizeFinalConstraintsVars); | |
| 691 | ✗ | txt := Tpl.softNewLine(txt); | |
| 692 | ✗ | txt := Tpl.popBlock(txt); | |
| 693 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 694 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 695 | then txt; | ||
| 696 | end match; | ||
| 697 | end fun_70; | ||
| 698 | |||
| 699 | protected function lm_71 | ||
| 700 | input output Tpl.Text txt; | ||
| 701 | input list<SimCodeVar.SimVar> items; | ||
| 702 | algorithm | ||
| 703 | ✗ | for lstElt_71 in items loop | |
| 704 | txt := match lstElt_71 | ||
| 705 | local | ||
| 706 | SimCodeVar.SimVar i_var; | ||
| 707 | |||
| 708 | case i_var | ||
| 709 | algorithm | ||
| 710 | ✗ | txt := CodegenEmbeddedC.startValue(txt, i_var); | |
| 711 | then txt; | ||
| 712 | end match; | ||
| 713 | end for; | ||
| 714 | end lm_71; | ||
| 715 | |||
| 716 | protected function fun_72 | ||
| 717 | input Tpl.Text in_txt; | ||
| 718 | input Integer in_a_varInfo_numIntAlgVars; | ||
| 719 | input list<SimCodeVar.SimVar> in_a_vars_intAlgVars; | ||
| 720 | |||
| 721 | output Tpl.Text out_txt; | ||
| 722 | algorithm | ||
| 723 | out_txt := | ||
| 724 | match(in_txt, in_a_varInfo_numIntAlgVars, in_a_vars_intAlgVars) | ||
| 725 | local | ||
| 726 | Tpl.Text txt; | ||
| 727 | list<SimCodeVar.SimVar> a_vars_intAlgVars; | ||
| 728 | |||
| 729 | case ( txt, | ||
| 730 | 0, | ||
| 731 | _ ) | ||
| 732 | then txt; | ||
| 733 | |||
| 734 | case ( txt, | ||
| 735 | _, | ||
| 736 | a_vars_intAlgVars ) | ||
| 737 | algorithm | ||
| 738 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2IntegerVars = {\n")); | |
| 739 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 740 | ✗ | txt := lm_71(txt, a_vars_intAlgVars); | |
| 741 | ✗ | txt := Tpl.softNewLine(txt); | |
| 742 | ✗ | txt := Tpl.popBlock(txt); | |
| 743 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 744 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 745 | then txt; | ||
| 746 | end match; | ||
| 747 | end fun_72; | ||
| 748 | |||
| 749 | protected function lm_73 | ||
| 750 | input output Tpl.Text txt; | ||
| 751 | input list<SimCodeVar.SimVar> items; | ||
| 752 | algorithm | ||
| 753 | ✗ | for lstElt_73 in items loop | |
| 754 | txt := match lstElt_73 | ||
| 755 | local | ||
| 756 | SimCodeVar.SimVar i_var; | ||
| 757 | |||
| 758 | case i_var | ||
| 759 | algorithm | ||
| 760 | ✗ | txt := CodegenEmbeddedC.startValue(txt, i_var); | |
| 761 | then txt; | ||
| 762 | end match; | ||
| 763 | end for; | ||
| 764 | end lm_73; | ||
| 765 | |||
| 766 | protected function fun_74 | ||
| 767 | input Tpl.Text in_txt; | ||
| 768 | input Integer in_a_varInfo_numBoolAlgVars; | ||
| 769 | input list<SimCodeVar.SimVar> in_a_vars_boolAlgVars; | ||
| 770 | |||
| 771 | output Tpl.Text out_txt; | ||
| 772 | algorithm | ||
| 773 | out_txt := | ||
| 774 | match(in_txt, in_a_varInfo_numBoolAlgVars, in_a_vars_boolAlgVars) | ||
| 775 | local | ||
| 776 | Tpl.Text txt; | ||
| 777 | list<SimCodeVar.SimVar> a_vars_boolAlgVars; | ||
| 778 | |||
| 779 | case ( txt, | ||
| 780 | 0, | ||
| 781 | _ ) | ||
| 782 | then txt; | ||
| 783 | |||
| 784 | case ( txt, | ||
| 785 | _, | ||
| 786 | a_vars_boolAlgVars ) | ||
| 787 | algorithm | ||
| 788 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2BooleanVars = {\n")); | |
| 789 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 790 | ✗ | txt := lm_73(txt, a_vars_boolAlgVars); | |
| 791 | ✗ | txt := Tpl.softNewLine(txt); | |
| 792 | ✗ | txt := Tpl.popBlock(txt); | |
| 793 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 794 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 795 | then txt; | ||
| 796 | end match; | ||
| 797 | end fun_74; | ||
| 798 | |||
| 799 | protected function lm_75 | ||
| 800 | input output Tpl.Text txt; | ||
| 801 | input list<SimCodeVar.SimVar> items; | ||
| 802 | algorithm | ||
| 803 | ✗ | for lstElt_75 in items loop | |
| 804 | txt := match lstElt_75 | ||
| 805 | local | ||
| 806 | SimCodeVar.SimVar i_var; | ||
| 807 | |||
| 808 | case i_var | ||
| 809 | algorithm | ||
| 810 | ✗ | txt := CodegenEmbeddedC.startValue(txt, i_var); | |
| 811 | then txt; | ||
| 812 | end match; | ||
| 813 | end for; | ||
| 814 | end lm_75; | ||
| 815 | |||
| 816 | protected function fun_76 | ||
| 817 | input Tpl.Text in_txt; | ||
| 818 | input Integer in_a_varInfo_numParams; | ||
| 819 | input list<SimCodeVar.SimVar> in_a_vars_paramVars; | ||
| 820 | |||
| 821 | output Tpl.Text out_txt; | ||
| 822 | algorithm | ||
| 823 | out_txt := | ||
| 824 | match(in_txt, in_a_varInfo_numParams, in_a_vars_paramVars) | ||
| 825 | local | ||
| 826 | Tpl.Text txt; | ||
| 827 | list<SimCodeVar.SimVar> a_vars_paramVars; | ||
| 828 | |||
| 829 | case ( txt, | ||
| 830 | 0, | ||
| 831 | _ ) | ||
| 832 | then txt; | ||
| 833 | |||
| 834 | case ( txt, | ||
| 835 | _, | ||
| 836 | a_vars_paramVars ) | ||
| 837 | algorithm | ||
| 838 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2RealParameter = {\n")); | |
| 839 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 840 | ✗ | txt := lm_75(txt, a_vars_paramVars); | |
| 841 | ✗ | txt := Tpl.softNewLine(txt); | |
| 842 | ✗ | txt := Tpl.popBlock(txt); | |
| 843 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 844 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 845 | then txt; | ||
| 846 | end match; | ||
| 847 | end fun_76; | ||
| 848 | |||
| 849 | protected function lm_77 | ||
| 850 | input output Tpl.Text txt; | ||
| 851 | input list<SimCodeVar.SimVar> items; | ||
| 852 | algorithm | ||
| 853 | ✗ | for lstElt_77 in items loop | |
| 854 | txt := match lstElt_77 | ||
| 855 | local | ||
| 856 | SimCodeVar.SimVar i_var; | ||
| 857 | |||
| 858 | case i_var | ||
| 859 | algorithm | ||
| 860 | ✗ | txt := CodegenEmbeddedC.startValue(txt, i_var); | |
| 861 | then txt; | ||
| 862 | end match; | ||
| 863 | end for; | ||
| 864 | end lm_77; | ||
| 865 | |||
| 866 | protected function fun_78 | ||
| 867 | input Tpl.Text in_txt; | ||
| 868 | input Integer in_a_varInfo_numIntParams; | ||
| 869 | input list<SimCodeVar.SimVar> in_a_vars_intParamVars; | ||
| 870 | |||
| 871 | output Tpl.Text out_txt; | ||
| 872 | algorithm | ||
| 873 | out_txt := | ||
| 874 | match(in_txt, in_a_varInfo_numIntParams, in_a_vars_intParamVars) | ||
| 875 | local | ||
| 876 | Tpl.Text txt; | ||
| 877 | list<SimCodeVar.SimVar> a_vars_intParamVars; | ||
| 878 | |||
| 879 | case ( txt, | ||
| 880 | 0, | ||
| 881 | _ ) | ||
| 882 | then txt; | ||
| 883 | |||
| 884 | case ( txt, | ||
| 885 | _, | ||
| 886 | a_vars_intParamVars ) | ||
| 887 | algorithm | ||
| 888 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2IntegerParameter = {\n")); | |
| 889 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 890 | ✗ | txt := lm_77(txt, a_vars_intParamVars); | |
| 891 | ✗ | txt := Tpl.softNewLine(txt); | |
| 892 | ✗ | txt := Tpl.popBlock(txt); | |
| 893 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 894 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 895 | then txt; | ||
| 896 | end match; | ||
| 897 | end fun_78; | ||
| 898 | |||
| 899 | protected function lm_79 | ||
| 900 | input output Tpl.Text txt; | ||
| 901 | input list<SimCodeVar.SimVar> items; | ||
| 902 | algorithm | ||
| 903 | ✗ | for lstElt_79 in items loop | |
| 904 | txt := match lstElt_79 | ||
| 905 | local | ||
| 906 | SimCodeVar.SimVar i_var; | ||
| 907 | |||
| 908 | case i_var | ||
| 909 | algorithm | ||
| 910 | ✗ | txt := CodegenEmbeddedC.startValue(txt, i_var); | |
| 911 | then txt; | ||
| 912 | end match; | ||
| 913 | end for; | ||
| 914 | end lm_79; | ||
| 915 | |||
| 916 | protected function fun_80 | ||
| 917 | input Tpl.Text in_txt; | ||
| 918 | input Integer in_a_varInfo_numBoolParams; | ||
| 919 | input list<SimCodeVar.SimVar> in_a_vars_boolParamVars; | ||
| 920 | |||
| 921 | output Tpl.Text out_txt; | ||
| 922 | algorithm | ||
| 923 | out_txt := | ||
| 924 | match(in_txt, in_a_varInfo_numBoolParams, in_a_vars_boolParamVars) | ||
| 925 | local | ||
| 926 | Tpl.Text txt; | ||
| 927 | list<SimCodeVar.SimVar> a_vars_boolParamVars; | ||
| 928 | |||
| 929 | case ( txt, | ||
| 930 | 0, | ||
| 931 | _ ) | ||
| 932 | then txt; | ||
| 933 | |||
| 934 | case ( txt, | ||
| 935 | _, | ||
| 936 | a_vars_boolParamVars ) | ||
| 937 | algorithm | ||
| 938 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2BooleanParameter = {\n")); | |
| 939 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 940 | ✗ | txt := lm_79(txt, a_vars_boolParamVars); | |
| 941 | ✗ | txt := Tpl.softNewLine(txt); | |
| 942 | ✗ | txt := Tpl.popBlock(txt); | |
| 943 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 944 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 945 | then txt; | ||
| 946 | end match; | ||
| 947 | end fun_80; | ||
| 948 | |||
| 949 | protected function lm_81 | ||
| 950 | input output Tpl.Text txt; | ||
| 951 | input list<SimCodeVar.SimVar> items; | ||
| 952 | algorithm | ||
| 953 | ✗ | for lstElt_81 in items loop | |
| 954 | txt := match lstElt_81 | ||
| 955 | local | ||
| 956 | SimCodeVar.SimVar i_var; | ||
| 957 | |||
| 958 | case i_var | ||
| 959 | algorithm | ||
| 960 | ✗ | txt := realVarName(txt, i_var); | |
| 961 | then txt; | ||
| 962 | end match; | ||
| 963 | end for; | ||
| 964 | end lm_81; | ||
| 965 | |||
| 966 | protected function lm_82 | ||
| 967 | input output Tpl.Text txt; | ||
| 968 | input list<SimCodeVar.SimVar> items; | ||
| 969 | algorithm | ||
| 970 | ✗ | for lstElt_82 in items loop | |
| 971 | txt := match lstElt_82 | ||
| 972 | local | ||
| 973 | SimCodeVar.SimVar i_var; | ||
| 974 | |||
| 975 | case i_var | ||
| 976 | algorithm | ||
| 977 | ✗ | txt := realVarName(txt, i_var); | |
| 978 | then txt; | ||
| 979 | end match; | ||
| 980 | end for; | ||
| 981 | end lm_82; | ||
| 982 | |||
| 983 | protected function lm_83 | ||
| 984 | input output Tpl.Text txt; | ||
| 985 | input list<SimCodeVar.SimVar> items; | ||
| 986 | algorithm | ||
| 987 | ✗ | for lstElt_83 in items loop | |
| 988 | txt := match lstElt_83 | ||
| 989 | local | ||
| 990 | SimCodeVar.SimVar i_var; | ||
| 991 | |||
| 992 | case i_var | ||
| 993 | algorithm | ||
| 994 | ✗ | txt := realVarName(txt, i_var); | |
| 995 | then txt; | ||
| 996 | end match; | ||
| 997 | end for; | ||
| 998 | end lm_83; | ||
| 999 | |||
| 1000 | protected function lm_84 | ||
| 1001 | input output Tpl.Text txt; | ||
| 1002 | input list<SimCodeVar.SimVar> items; | ||
| 1003 | algorithm | ||
| 1004 | ✗ | for lstElt_84 in items loop | |
| 1005 | txt := match lstElt_84 | ||
| 1006 | local | ||
| 1007 | SimCodeVar.SimVar i_var; | ||
| 1008 | |||
| 1009 | case i_var | ||
| 1010 | algorithm | ||
| 1011 | ✗ | txt := realVarName(txt, i_var); | |
| 1012 | then txt; | ||
| 1013 | end match; | ||
| 1014 | end for; | ||
| 1015 | end lm_84; | ||
| 1016 | |||
| 1017 | protected function lm_85 | ||
| 1018 | input output Tpl.Text txt; | ||
| 1019 | input list<SimCodeVar.SimVar> items; | ||
| 1020 | algorithm | ||
| 1021 | ✗ | for lstElt_85 in items loop | |
| 1022 | txt := match lstElt_85 | ||
| 1023 | local | ||
| 1024 | SimCodeVar.SimVar i_var; | ||
| 1025 | |||
| 1026 | case i_var | ||
| 1027 | algorithm | ||
| 1028 | ✗ | txt := realVarName(txt, i_var); | |
| 1029 | then txt; | ||
| 1030 | end match; | ||
| 1031 | end for; | ||
| 1032 | end lm_85; | ||
| 1033 | |||
| 1034 | protected function lm_86 | ||
| 1035 | input output Tpl.Text txt; | ||
| 1036 | input list<SimCodeVar.SimVar> items; | ||
| 1037 | algorithm | ||
| 1038 | ✗ | for lstElt_86 in items loop | |
| 1039 | txt := match lstElt_86 | ||
| 1040 | local | ||
| 1041 | SimCodeVar.SimVar i_var; | ||
| 1042 | |||
| 1043 | case i_var | ||
| 1044 | algorithm | ||
| 1045 | ✗ | txt := realVarName(txt, i_var); | |
| 1046 | then txt; | ||
| 1047 | end match; | ||
| 1048 | end for; | ||
| 1049 | end lm_86; | ||
| 1050 | |||
| 1051 | protected function smf_87 | ||
| 1052 | input Tpl.Text in_txt; | ||
| 1053 | input SimCode.SimEqSystem in_it; | ||
| 1054 | |||
| 1055 | output Tpl.Text out_txt; | ||
| 1056 | algorithm | ||
| 1057 | out_txt := | ||
| 1058 | match(in_txt, in_it) | ||
| 1059 | local | ||
| 1060 | Tpl.Text txt; | ||
| 1061 | SimCode.SimEqSystem i_eq; | ||
| 1062 | |||
| 1063 | case ( txt, | ||
| 1064 | i_eq ) | ||
| 1065 | algorithm | ||
| 1066 | ✗ | txt := CodegenEmbeddedC.equation_(txt, i_eq); | |
| 1067 | then txt; | ||
| 1068 | end match; | ||
| 1069 | end smf_87; | ||
| 1070 | |||
| 1071 | protected function smf_88 | ||
| 1072 | input Tpl.Text in_txt; | ||
| 1073 | input SimCode.SimEqSystem in_it; | ||
| 1074 | |||
| 1075 | output Tpl.Text out_txt; | ||
| 1076 | algorithm | ||
| 1077 | out_txt := | ||
| 1078 | match(in_txt, in_it) | ||
| 1079 | local | ||
| 1080 | Tpl.Text txt; | ||
| 1081 | SimCode.SimEqSystem i_eq; | ||
| 1082 | |||
| 1083 | case ( txt, | ||
| 1084 | i_eq ) | ||
| 1085 | algorithm | ||
| 1086 | ✗ | txt := CodegenEmbeddedC.equation_(txt, i_eq); | |
| 1087 | then txt; | ||
| 1088 | end match; | ||
| 1089 | end smf_88; | ||
| 1090 | |||
| 1091 | protected function lm_89 | ||
| 1092 | input output Tpl.Text txt; | ||
| 1093 | input list<SimCode.SimEqSystem> items; | ||
| 1094 | algorithm | ||
| 1095 | ✗ | for lstElt_89 in items loop | |
| 1096 | txt := match lstElt_89 | ||
| 1097 | local | ||
| 1098 | SimCode.SimEqSystem i_eqs; | ||
| 1099 | |||
| 1100 | case i_eqs | ||
| 1101 | algorithm | ||
| 1102 | ✗ | txt := smf_88(txt, i_eqs); | |
| 1103 | ✗ | txt := Tpl.nextIter(txt); | |
| 1104 | then txt; | ||
| 1105 | end match; | ||
| 1106 | end for; | ||
| 1107 | end lm_89; | ||
| 1108 | |||
| 1109 | protected function fun_90 | ||
| 1110 | input Tpl.Text in_txt; | ||
| 1111 | input list<SimCode.SimEqSystem> in_a_allEquations; | ||
| 1112 | |||
| 1113 | output Tpl.Text out_txt; | ||
| 1114 | algorithm | ||
| 1115 | out_txt := | ||
| 1116 | match(in_txt, in_a_allEquations) | ||
| 1117 | local | ||
| 1118 | Tpl.Text txt; | ||
| 1119 | list<SimCode.SimEqSystem> i_allEquations; | ||
| 1120 | SimCode.SimEqSystem i_eqs; | ||
| 1121 | |||
| 1122 | case ( txt, | ||
| 1123 | {} ) | ||
| 1124 | then txt; | ||
| 1125 | |||
| 1126 | case ( txt, | ||
| 1127 | {i_eqs} ) | ||
| 1128 | algorithm | ||
| 1129 | ✗ | txt := smf_87(txt, i_eqs); | |
| 1130 | then txt; | ||
| 1131 | |||
| 1132 | case ( txt, | ||
| 1133 | i_allEquations ) | ||
| 1134 | algorithm | ||
| 1135 | ✗ | txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 1136 | ✗ | txt := lm_89(txt, i_allEquations); | |
| 1137 | ✗ | txt := Tpl.popIter(txt); | |
| 1138 | then txt; | ||
| 1139 | end match; | ||
| 1140 | end fun_90; | ||
| 1141 | |||
| 1142 | protected function fun_91 | ||
| 1143 | input Tpl.Text in_txt; | ||
| 1144 | input Integer in_a_varInfo_numStateVars; | ||
| 1145 | |||
| 1146 | output Tpl.Text out_txt; | ||
| 1147 | algorithm | ||
| 1148 | out_txt := | ||
| 1149 | match(in_txt, in_a_varInfo_numStateVars) | ||
| 1150 | local | ||
| 1151 | Tpl.Text txt; | ||
| 1152 | Integer i_varInfo_numStateVars; | ||
| 1153 | |||
| 1154 | case ( txt, | ||
| 1155 | 0 ) | ||
| 1156 | then txt; | ||
| 1157 | |||
| 1158 | case ( txt, | ||
| 1159 | i_varInfo_numStateVars ) | ||
| 1160 | algorithm | ||
| 1161 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1162 | "{\n", | ||
| 1163 | " int i;\n" | ||
| 1164 | }, true)); | ||
| 1165 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1166 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("for (i=0; i<")); | |
| 1167 | ✗ | txt := Tpl.writeStr(txt, intString(i_varInfo_numStateVars)); | |
| 1168 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("; i++) {\n")); | |
| 1169 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1170 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("comp->fmi2RealVars[i] += comp->fmi2RealVars[i+")); | |
| 1171 | ✗ | txt := Tpl.writeStr(txt, intString(i_varInfo_numStateVars)); | |
| 1172 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("]*stepSize;\n")); | |
| 1173 | ✗ | txt := Tpl.popBlock(txt); | |
| 1174 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("}\n")); | |
| 1175 | ✗ | txt := Tpl.popBlock(txt); | |
| 1176 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("}")); | |
| 1177 | then txt; | ||
| 1178 | end match; | ||
| 1179 | end fun_91; | ||
| 1180 | |||
| 1181 | protected function fun_92 | ||
| 1182 | input Tpl.Text in_txt; | ||
| 1183 | input Integer in_mArg; | ||
| 1184 | |||
| 1185 | output Tpl.Text out_txt; | ||
| 1186 | algorithm | ||
| 1187 | out_txt := | ||
| 1188 | match(in_txt, in_mArg) | ||
| 1189 | local | ||
| 1190 | Tpl.Text txt; | ||
| 1191 | |||
| 1192 | case ( txt, | ||
| 1193 | 0 ) | ||
| 1194 | algorithm | ||
| 1195 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1196 | "(void)comp;\n", | ||
| 1197 | "(void)index;\n", | ||
| 1198 | "return 0.0;" | ||
| 1199 | }, false)); | ||
| 1200 | then txt; | ||
| 1201 | |||
| 1202 | case ( txt, | ||
| 1203 | _ ) | ||
| 1204 | algorithm | ||
| 1205 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1206 | "if (index < 0 || index >= OM_NUM_REAL) {\n", | ||
| 1207 | " return 0.0;\n", | ||
| 1208 | "}\n", | ||
| 1209 | "return comp->fmi2RealVars[index];" | ||
| 1210 | }, false)); | ||
| 1211 | then txt; | ||
| 1212 | end match; | ||
| 1213 | end fun_92; | ||
| 1214 | |||
| 1215 | protected function fun_93 | ||
| 1216 | input Tpl.Text in_txt; | ||
| 1217 | input SimCode.SimCode in_a_simCode; | ||
| 1218 | input Tpl.Text in_a_modelNamePrefixStr; | ||
| 1219 | |||
| 1220 | output Tpl.Text out_txt; | ||
| 1221 | algorithm | ||
| 1222 | out_txt := | ||
| 1223 | match(in_txt, in_a_simCode, in_a_modelNamePrefixStr) | ||
| 1224 | local | ||
| 1225 | Tpl.Text txt; | ||
| 1226 | Tpl.Text a_modelNamePrefixStr; | ||
| 1227 | Integer i_varInfo_numStateVars; | ||
| 1228 | SimCode.ExtObjInfo i_extObjInfo; | ||
| 1229 | list<SimCode.SimEqSystem> i_allEquations; | ||
| 1230 | list<String> i_externalFunctionIncludes; | ||
| 1231 | list<DAE.Exp> i_literals; | ||
| 1232 | list<SimCodeFunction.Function> i_functions; | ||
| 1233 | list<SimCodeVar.SimVar> i_vars_boolParamVars; | ||
| 1234 | list<SimCodeVar.SimVar> i_vars_intParamVars; | ||
| 1235 | list<SimCodeVar.SimVar> i_vars_paramVars; | ||
| 1236 | list<SimCodeVar.SimVar> i_vars_boolAlgVars; | ||
| 1237 | list<SimCodeVar.SimVar> i_vars_intAlgVars; | ||
| 1238 | list<SimCodeVar.SimVar> i_vars_realOptimizeFinalConstraintsVars; | ||
| 1239 | list<SimCodeVar.SimVar> i_vars_realOptimizeConstraintsVars; | ||
| 1240 | list<SimCodeVar.SimVar> i_vars_discreteAlgVars; | ||
| 1241 | list<SimCodeVar.SimVar> i_vars_algVars; | ||
| 1242 | list<SimCodeVar.SimVar> i_vars_derivativeVars; | ||
| 1243 | list<SimCodeVar.SimVar> i_vars_stateVars; | ||
| 1244 | Real i_settings_startTime; | ||
| 1245 | list<SimCodeVar.SimVar> i_extObjVars; | ||
| 1246 | Integer i_varInfo_numBoolParams; | ||
| 1247 | Integer i_varInfo_numIntParams; | ||
| 1248 | Integer i_varInfo_numParams; | ||
| 1249 | Integer i_varInfo_numStringAlgVars; | ||
| 1250 | Integer i_varInfo_numBoolAlgVars; | ||
| 1251 | Integer i_varInfo_numIntAlgVars; | ||
| 1252 | SimCode.VarInfo i_varInfo; | ||
| 1253 | Absyn.Path i_modelInfo_name; | ||
| 1254 | Integer ret_3; | ||
| 1255 | Integer ret_2; | ||
| 1256 | Integer ret_1; | ||
| 1257 | Integer ret_0; | ||
| 1258 | |||
| 1259 | case ( txt, | ||
| 1260 | SimCode.SIMCODE(simulationSettingsOpt = NONE()), | ||
| 1261 | _ ) | ||
| 1262 | algorithm | ||
| 1263 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenESP32.tpl", 182, 9), "Missing simulation settings"); | |
| 1264 | then txt; | ||
| 1265 | |||
| 1266 | case ( txt, | ||
| 1267 | SimCode.SIMCODE(modelInfo = SimCode.MODELINFO(functions = i_functions, varInfo = (i_varInfo as SimCode.VARINFO(numIntAlgVars = i_varInfo_numIntAlgVars, numBoolAlgVars = i_varInfo_numBoolAlgVars, numStringAlgVars = i_varInfo_numStringAlgVars, numParams = i_varInfo_numParams, numIntParams = i_varInfo_numIntParams, numBoolParams = i_varInfo_numBoolParams, numStateVars = i_varInfo_numStateVars)), vars = SimCodeVar.SIMVARS(stateVars = i_vars_stateVars, derivativeVars = i_vars_derivativeVars, algVars = i_vars_algVars, discreteAlgVars = i_vars_discreteAlgVars, realOptimizeConstraintsVars = i_vars_realOptimizeConstraintsVars, realOptimizeFinalConstraintsVars = i_vars_realOptimizeFinalConstraintsVars, intAlgVars = i_vars_intAlgVars, boolAlgVars = i_vars_boolAlgVars, paramVars = i_vars_paramVars, intParamVars = i_vars_intParamVars, boolParamVars = i_vars_boolParamVars), name = i_modelInfo_name), extObjInfo = (i_extObjInfo as SimCode.EXTOBJINFO(vars = i_extObjVars)), simulationSettingsOpt = SOME(SimCode.SIMULATION_SETTINGS(startTime = i_settings_startTime)), literals = i_literals, externalFunctionIncludes = i_externalFunctionIncludes, allEquations = i_allEquations), | ||
| 1268 | a_modelNamePrefixStr ) | ||
| 1269 | algorithm | ||
| 1270 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("/* Generated by OpenModelica from ")); | |
| 1271 | ✗ | txt := CodegenUtil.dotPath(txt, i_modelInfo_name); | |
| 1272 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1273 | " */\n", | ||
| 1274 | "#include \"" | ||
| 1275 | }, false)); | ||
| 1276 | ✗ | txt := Tpl.writeText(txt, a_modelNamePrefixStr); | |
| 1277 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1278 | "_model.h\"\n", | ||
| 1279 | "\n", | ||
| 1280 | "#include <math.h>\n", | ||
| 1281 | "#include <stdarg.h>\n", | ||
| 1282 | "#include <stdio.h>\n", | ||
| 1283 | "\n", | ||
| 1284 | "void ModelicaFormatMessage(const char *fmt, ...)\n", | ||
| 1285 | "{\n", | ||
| 1286 | " va_list args;\n", | ||
| 1287 | " va_start(args, fmt);\n", | ||
| 1288 | " vprintf(fmt, args);\n", | ||
| 1289 | " va_end(args);\n", | ||
| 1290 | "}\n", | ||
| 1291 | "\n", | ||
| 1292 | "struct " | ||
| 1293 | }, false)); | ||
| 1294 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2Component_s"); | |
| 1295 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1296 | " {\n", | ||
| 1297 | " fmi2Real currentTime;\n" | ||
| 1298 | }, true)); | ||
| 1299 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1300 | ✗ | ret_0 := SimCodeCodegenUtil.nVariablesReal(i_varInfo); | |
| 1301 | ✗ | txt := fun_56(txt, ret_0); | |
| 1302 | ✗ | txt := fun_57(txt, i_varInfo_numIntAlgVars); | |
| 1303 | ✗ | txt := fun_58(txt, i_varInfo_numBoolAlgVars); | |
| 1304 | ✗ | txt := fun_59(txt, i_varInfo_numStringAlgVars); | |
| 1305 | ✗ | txt := fun_60(txt, i_varInfo_numParams); | |
| 1306 | ✗ | txt := fun_61(txt, i_varInfo_numIntParams); | |
| 1307 | ✗ | txt := fun_62(txt, i_varInfo_numBoolParams); | |
| 1308 | ✗ | ret_1 := listLength(i_extObjVars); | |
| 1309 | ✗ | txt := fun_63(txt, ret_1); | |
| 1310 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1311 | ✗ | txt := Tpl.popBlock(txt); | |
| 1312 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1313 | "};\n", | ||
| 1314 | "\n", | ||
| 1315 | "static struct " | ||
| 1316 | }, false)); | ||
| 1317 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2Component_s"); | |
| 1318 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" ")); | |
| 1319 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "component"); | |
| 1320 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(" = {\n")); | |
| 1321 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1322 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(".currentTime = ")); | |
| 1323 | ✗ | txt := Tpl.writeStr(txt, realString(i_settings_startTime)); | |
| 1324 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(",\n")); | |
| 1325 | ✗ | ret_2 := SimCodeCodegenUtil.nVariablesReal(i_varInfo); | |
| 1326 | ✗ | txt := fun_70(txt, ret_2, i_vars_realOptimizeFinalConstraintsVars, i_vars_realOptimizeConstraintsVars, i_vars_discreteAlgVars, i_vars_algVars, i_vars_derivativeVars, i_vars_stateVars); | |
| 1327 | ✗ | txt := fun_72(txt, i_varInfo_numIntAlgVars, i_vars_intAlgVars); | |
| 1328 | ✗ | txt := fun_74(txt, i_varInfo_numBoolAlgVars, i_vars_boolAlgVars); | |
| 1329 | ✗ | txt := fun_76(txt, i_varInfo_numParams, i_vars_paramVars); | |
| 1330 | ✗ | txt := fun_78(txt, i_varInfo_numIntParams, i_vars_intParamVars); | |
| 1331 | ✗ | txt := fun_80(txt, i_varInfo_numBoolParams, i_vars_boolParamVars); | |
| 1332 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1333 | ✗ | txt := Tpl.popBlock(txt); | |
| 1334 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1335 | "};\n", | ||
| 1336 | "\n", | ||
| 1337 | "const char * const " | ||
| 1338 | }, false)); | ||
| 1339 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "realNames"); | |
| 1340 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("[OM_NUM_REAL] = {\n")); | |
| 1341 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1342 | ✗ | txt := lm_81(txt, i_vars_stateVars); | |
| 1343 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1344 | ✗ | txt := lm_82(txt, i_vars_derivativeVars); | |
| 1345 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1346 | ✗ | txt := lm_83(txt, i_vars_algVars); | |
| 1347 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1348 | ✗ | txt := lm_84(txt, i_vars_discreteAlgVars); | |
| 1349 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1350 | ✗ | txt := lm_85(txt, i_vars_realOptimizeConstraintsVars); | |
| 1351 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1352 | ✗ | txt := lm_86(txt, i_vars_realOptimizeFinalConstraintsVars); | |
| 1353 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1354 | ✗ | txt := Tpl.popBlock(txt); | |
| 1355 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1356 | "};\n", | ||
| 1357 | "\n", | ||
| 1358 | "/* TODO: Generate used builtin functions before SimCode */\n", | ||
| 1359 | "static inline double om_mod(double x, double y)\n", | ||
| 1360 | "{\n", | ||
| 1361 | " return x-floor(x/y)*y;\n", | ||
| 1362 | "}\n", | ||
| 1363 | "\n" | ||
| 1364 | }, true)); | ||
| 1365 | ✗ | txt := CodegenEmbeddedC.functionsFile(txt, i_functions, i_literals, i_externalFunctionIncludes); | |
| 1366 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1367 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1368 | "\n", | ||
| 1369 | "/* Evaluates every equation of the model for the current time and the current\n", | ||
| 1370 | " state, which leaves both the state derivatives and the algebraic variables\n", | ||
| 1371 | " up to date. */\n", | ||
| 1372 | "static fmi2Status " | ||
| 1373 | }, false)); | ||
| 1374 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "functionEquations"); | |
| 1375 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1376 | "(fmi2Component comp)\n", | ||
| 1377 | "{\n" | ||
| 1378 | }, true)); | ||
| 1379 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1380 | ✗ | txt := fun_90(txt, i_allEquations); | |
| 1381 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1382 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("return fmi2OK;\n")); | |
| 1383 | ✗ | txt := Tpl.popBlock(txt); | |
| 1384 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1385 | "}\n", | ||
| 1386 | "\n", | ||
| 1387 | "fmi2Component " | ||
| 1388 | }, false)); | ||
| 1389 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "instantiate"); | |
| 1390 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1391 | "(void)\n", | ||
| 1392 | "{\n" | ||
| 1393 | }, true)); | ||
| 1394 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1395 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("return &")); | |
| 1396 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "component"); | |
| 1397 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(";\n")); | |
| 1398 | ✗ | txt := Tpl.popBlock(txt); | |
| 1399 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1400 | "}\n", | ||
| 1401 | "\n", | ||
| 1402 | "fmi2Status " | ||
| 1403 | }, false)); | ||
| 1404 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "initialize"); | |
| 1405 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1406 | "(fmi2Component comp, fmi2Real startTime)\n", | ||
| 1407 | "{\n", | ||
| 1408 | " comp->currentTime = startTime;\n" | ||
| 1409 | }, true)); | ||
| 1410 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1411 | ✗ | txt := CodegenEmbeddedC.callExternalObjectConstructors(txt, i_extObjInfo); | |
| 1412 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1413 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("return ")); | |
| 1414 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "functionEquations"); | |
| 1415 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("(comp);\n")); | |
| 1416 | ✗ | txt := Tpl.popBlock(txt); | |
| 1417 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1418 | "}\n", | ||
| 1419 | "\n", | ||
| 1420 | "fmi2Status " | ||
| 1421 | }, false)); | ||
| 1422 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "step"); | |
| 1423 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1424 | "(fmi2Component comp, fmi2Real currentTime, fmi2Real stepSize)\n", | ||
| 1425 | "{\n", | ||
| 1426 | " fmi2Status status;\n", | ||
| 1427 | " comp->currentTime = currentTime;\n", | ||
| 1428 | " /* The derivatives are evaluated before the states are advanced, which makes\n", | ||
| 1429 | " the step below a plain explicit Euler step. */\n" | ||
| 1430 | }, true)); | ||
| 1431 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1432 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("status = ")); | |
| 1433 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "functionEquations"); | |
| 1434 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1435 | "(comp);\n", | ||
| 1436 | "if (status != fmi2OK) {\n", | ||
| 1437 | " return status;\n", | ||
| 1438 | "}\n" | ||
| 1439 | }, true)); | ||
| 1440 | ✗ | txt := fun_91(txt, i_varInfo_numStateVars); | |
| 1441 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1442 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1443 | "comp->currentTime = currentTime + stepSize;\n", | ||
| 1444 | "/* Report the algebraic variables at the time the states were advanced to. */\n", | ||
| 1445 | "return " | ||
| 1446 | }, false)); | ||
| 1447 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "functionEquations"); | |
| 1448 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("(comp);\n")); | |
| 1449 | ✗ | txt := Tpl.popBlock(txt); | |
| 1450 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1451 | "}\n", | ||
| 1452 | "\n", | ||
| 1453 | "fmi2Real " | ||
| 1454 | }, false)); | ||
| 1455 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "getTime"); | |
| 1456 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1457 | "(fmi2Component comp)\n", | ||
| 1458 | "{\n", | ||
| 1459 | " return comp->currentTime;\n", | ||
| 1460 | "}\n", | ||
| 1461 | "\n", | ||
| 1462 | "fmi2Real " | ||
| 1463 | }, false)); | ||
| 1464 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "getReal"); | |
| 1465 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1466 | "(fmi2Component comp, int index)\n", | ||
| 1467 | "{\n" | ||
| 1468 | }, true)); | ||
| 1469 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1470 | ✗ | ret_3 := SimCodeCodegenUtil.nVariablesReal(i_varInfo); | |
| 1471 | ✗ | txt := fun_92(txt, ret_3); | |
| 1472 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1473 | ✗ | txt := Tpl.popBlock(txt); | |
| 1474 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("}")); | |
| 1475 | then txt; | ||
| 1476 | |||
| 1477 | case ( txt, | ||
| 1478 | _, | ||
| 1479 | _ ) | ||
| 1480 | then txt; | ||
| 1481 | end match; | ||
| 1482 | end fun_93; | ||
| 1483 | |||
| 1484 | public function modelSourceFile | ||
| 1485 | input Tpl.Text txt; | ||
| 1486 | input SimCode.SimCode a_simCode; | ||
| 1487 | |||
| 1488 | output Tpl.Text out_txt; | ||
| 1489 | protected | ||
| 1490 | Tpl.Text l_modelNamePrefixStr; | ||
| 1491 | algorithm | ||
| 1492 | ✗ | l_modelNamePrefixStr := CodegenUtilSimulation.modelNamePrefix(Tpl.emptyTxt, a_simCode); | |
| 1493 | ✗ | out_txt := fun_93(txt, a_simCode, l_modelNamePrefixStr); | |
| 1494 | end modelSourceFile; | ||
| 1495 | |||
| 1496 | public function realVarName | ||
| 1497 | input Tpl.Text in_txt; | ||
| 1498 | input SimCodeVar.SimVar in_a_var; | ||
| 1499 | |||
| 1500 | output Tpl.Text out_txt; | ||
| 1501 | algorithm | ||
| 1502 | out_txt := | ||
| 1503 | match(in_txt, in_a_var) | ||
| 1504 | local | ||
| 1505 | Tpl.Text txt; | ||
| 1506 | DAE.ComponentRef i_name; | ||
| 1507 | String ret_1; | ||
| 1508 | Tpl.Text txt_0; | ||
| 1509 | |||
| 1510 | case ( txt, | ||
| 1511 | SimCodeVar.SIMVAR(name = i_name) ) | ||
| 1512 | algorithm | ||
| 1513 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("\"")); | |
| 1514 | ✗ | txt_0 := CodegenUtil.crefStr(Tpl.emptyTxt, i_name); | |
| 1515 | ✗ | ret_1 := Util.escapeModelicaStringToCString(Tpl.textString(txt_0)); | |
| 1516 | ✗ | txt := Tpl.writeStr(txt, ret_1); | |
| 1517 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("\",")); | |
| 1518 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 1519 | then txt; | ||
| 1520 | |||
| 1521 | case ( txt, | ||
| 1522 | _ ) | ||
| 1523 | then txt; | ||
| 1524 | end match; | ||
| 1525 | end realVarName; | ||
| 1526 | |||
| 1527 | protected function fun_96 | ||
| 1528 | input Tpl.Text in_txt; | ||
| 1529 | input SimCode.SimCode in_a_simCode; | ||
| 1530 | input Tpl.Text in_a_modelNamePrefixStr; | ||
| 1531 | |||
| 1532 | output Tpl.Text out_txt; | ||
| 1533 | algorithm | ||
| 1534 | out_txt := | ||
| 1535 | match(in_txt, in_a_simCode, in_a_modelNamePrefixStr) | ||
| 1536 | local | ||
| 1537 | Tpl.Text txt; | ||
| 1538 | Tpl.Text a_modelNamePrefixStr; | ||
| 1539 | Absyn.Path i_modelInfo_name; | ||
| 1540 | |||
| 1541 | case ( txt, | ||
| 1542 | SimCode.SIMCODE(modelInfo = SimCode.MODELINFO(name = i_modelInfo_name)), | ||
| 1543 | a_modelNamePrefixStr ) | ||
| 1544 | algorithm | ||
| 1545 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("/* Generated by OpenModelica from ")); | |
| 1546 | ✗ | txt := CodegenUtil.dotPath(txt, i_modelInfo_name); | |
| 1547 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1548 | " */\n", | ||
| 1549 | "#include <stdio.h>\n", | ||
| 1550 | "#include <stdint.h>\n", | ||
| 1551 | "#include <unistd.h>\n", | ||
| 1552 | "\n", | ||
| 1553 | "#include \"freertos/FreeRTOS.h\"\n", | ||
| 1554 | "#include \"freertos/task.h\"\n", | ||
| 1555 | "#include \"esp_timer.h\"\n", | ||
| 1556 | "\n", | ||
| 1557 | "#include \"" | ||
| 1558 | }, false)); | ||
| 1559 | ✗ | txt := Tpl.writeText(txt, a_modelNamePrefixStr); | |
| 1560 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1561 | "_model.h\"\n", | ||
| 1562 | "\n", | ||
| 1563 | "/* Print one line every OM_PRINT_EVERY steps. Printing every step of a model\n", | ||
| 1564 | " solved with a small step size floods the console and slows the solver down\n", | ||
| 1565 | " more than the solver itself costs. */\n", | ||
| 1566 | "#ifndef OM_PRINT_EVERY\n", | ||
| 1567 | "#define OM_PRINT_EVERY 1\n", | ||
| 1568 | "#endif\n", | ||
| 1569 | "\n", | ||
| 1570 | "/* Run the simulation in real time, that is, spend OM_STEP_SIZE seconds of\n", | ||
| 1571 | " wall clock time on every step. Set it to 0 to solve as fast as the chip\n", | ||
| 1572 | " can, which is what you want when the results are only printed. */\n", | ||
| 1573 | "#ifndef OM_REALTIME\n", | ||
| 1574 | "#define OM_REALTIME 0\n", | ||
| 1575 | "#endif\n", | ||
| 1576 | "\n", | ||
| 1577 | "/* Solve forever instead of stopping at OM_STOP_TIME. */\n", | ||
| 1578 | "#ifndef OM_RUN_FOREVER\n", | ||
| 1579 | "#define OM_RUN_FOREVER 0\n", | ||
| 1580 | "#endif\n", | ||
| 1581 | "\n", | ||
| 1582 | "/* The stack of the task the model is solved in. Every variable of the model\n", | ||
| 1583 | " is statically allocated, so this only has to hold the function calls. */\n", | ||
| 1584 | "#ifndef OM_TASK_STACK_SIZE\n", | ||
| 1585 | "#define OM_TASK_STACK_SIZE 8192\n", | ||
| 1586 | "#endif\n", | ||
| 1587 | "\n", | ||
| 1588 | "/* Hand the CPU back at least this often, in microseconds, so that the idle\n", | ||
| 1589 | " task gets to run and feed the task watchdog. How many steps that is depends\n", | ||
| 1590 | " on the model and on how fast the results are printed, which is why it is a\n", | ||
| 1591 | " time and not a number of steps. */\n", | ||
| 1592 | "#ifndef OM_YIELD_INTERVAL_US\n", | ||
| 1593 | "#define OM_YIELD_INTERVAL_US 200000\n", | ||
| 1594 | "#endif\n", | ||
| 1595 | "\n", | ||
| 1596 | "static void om_print_header(void)\n", | ||
| 1597 | "{\n", | ||
| 1598 | " int i;\n", | ||
| 1599 | " printf(\"time\");\n", | ||
| 1600 | " for (i=0; i<OM_NUM_REAL; i++) {\n" | ||
| 1601 | }, true)); | ||
| 1602 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(4)); | |
| 1603 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("printf(\",%s\", ")); | |
| 1604 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "realNames"); | |
| 1605 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("[i]);\n")); | |
| 1606 | ✗ | txt := Tpl.popBlock(txt); | |
| 1607 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1608 | " }\n", | ||
| 1609 | " printf(\"\\n\");\n", | ||
| 1610 | "}\n", | ||
| 1611 | "\n", | ||
| 1612 | "static void om_print_values(fmi2Component comp)\n", | ||
| 1613 | "{\n", | ||
| 1614 | " int i;\n" | ||
| 1615 | }, true)); | ||
| 1616 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1617 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("printf(\"%g\", (double)")); | |
| 1618 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "getTime"); | |
| 1619 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1620 | "(comp));\n", | ||
| 1621 | "for (i=0; i<OM_NUM_REAL; i++) {\n" | ||
| 1622 | }, true)); | ||
| 1623 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1624 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("printf(\",%g\", (double)")); | |
| 1625 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "getReal"); | |
| 1626 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("(comp, i));\n")); | |
| 1627 | ✗ | txt := Tpl.popBlock(txt); | |
| 1628 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1629 | "}\n", | ||
| 1630 | "printf(\"\\n\");\n" | ||
| 1631 | }, true)); | ||
| 1632 | ✗ | txt := Tpl.popBlock(txt); | |
| 1633 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1634 | "}\n", | ||
| 1635 | "\n", | ||
| 1636 | "static void om_simulation_task(void *arg)\n", | ||
| 1637 | "{\n", | ||
| 1638 | " fmi2Component comp;\n", | ||
| 1639 | " fmi2Status status = fmi2OK;\n", | ||
| 1640 | " double time = OM_START_TIME;\n", | ||
| 1641 | " const double h = OM_STEP_SIZE;\n", | ||
| 1642 | " uint32_t step = 0;\n", | ||
| 1643 | " int64_t wallClockStart;\n", | ||
| 1644 | " int64_t lastYield;\n", | ||
| 1645 | "\n", | ||
| 1646 | " (void)arg;\n", | ||
| 1647 | "\n" | ||
| 1648 | }, true)); | ||
| 1649 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1650 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("comp = ")); | |
| 1651 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "instantiate"); | |
| 1652 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1653 | "();\n", | ||
| 1654 | "if (comp == NULL) {\n", | ||
| 1655 | " printf(\"Failed to instantiate \" OM_MODEL_NAME \"\\n\");\n", | ||
| 1656 | " vTaskDelete(NULL);\n", | ||
| 1657 | " return;\n", | ||
| 1658 | "}\n", | ||
| 1659 | "\n", | ||
| 1660 | "printf(\"# OpenModelica \" OM_MODEL_NAME \" on %s\\n\", CONFIG_IDF_TARGET);\n" | ||
| 1661 | }, true)); | ||
| 1662 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "initialize"); | |
| 1663 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1664 | "(comp, OM_START_TIME);\n", | ||
| 1665 | "om_print_header();\n", | ||
| 1666 | "om_print_values(comp);\n", | ||
| 1667 | "\n", | ||
| 1668 | "wallClockStart = esp_timer_get_time();\n", | ||
| 1669 | "lastYield = wallClockStart;\n", | ||
| 1670 | "\n", | ||
| 1671 | "while (OM_RUN_FOREVER || time < OM_STOP_TIME) {\n" | ||
| 1672 | }, true)); | ||
| 1673 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1674 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("status = ")); | |
| 1675 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "step"); | |
| 1676 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1677 | "(comp, time, h);\n", | ||
| 1678 | "if (status != fmi2OK) {\n", | ||
| 1679 | " printf(\"# step failed at time %g\\n\", time);\n", | ||
| 1680 | " break;\n", | ||
| 1681 | "}\n", | ||
| 1682 | "step++;\n", | ||
| 1683 | "time = OM_START_TIME + h*(double)step;\n", | ||
| 1684 | "\n", | ||
| 1685 | "if ((step % OM_PRINT_EVERY) == 0) {\n", | ||
| 1686 | " om_print_values(comp);\n", | ||
| 1687 | "}\n", | ||
| 1688 | "\n", | ||
| 1689 | "if (OM_REALTIME) {\n", | ||
| 1690 | " /* Sleep until the wall clock has caught up with the simulated time. */\n", | ||
| 1691 | " int64_t due = wallClockStart + (int64_t)((time - OM_START_TIME)*1e6);\n", | ||
| 1692 | " int64_t now = esp_timer_get_time();\n", | ||
| 1693 | " if (due > now) {\n", | ||
| 1694 | " usleep((useconds_t)(due - now));\n", | ||
| 1695 | " lastYield = esp_timer_get_time();\n", | ||
| 1696 | " }\n", | ||
| 1697 | "}\n", | ||
| 1698 | "/* A step shorter than a tick does not sleep above, and solving as fast as\n", | ||
| 1699 | " possible never does, so give the idle task a tick of its own whenever it\n", | ||
| 1700 | " has been waiting for too long. */\n", | ||
| 1701 | "if (esp_timer_get_time() - lastYield >= OM_YIELD_INTERVAL_US) {\n", | ||
| 1702 | " vTaskDelay(1);\n", | ||
| 1703 | " lastYield = esp_timer_get_time();\n", | ||
| 1704 | "}\n" | ||
| 1705 | }, true)); | ||
| 1706 | ✗ | txt := Tpl.popBlock(txt); | |
| 1707 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1708 | "}\n", | ||
| 1709 | "\n", | ||
| 1710 | "printf(\"# done at time %g after %u steps\\n\", time, (unsigned)step);\n", | ||
| 1711 | "vTaskDelete(NULL);\n" | ||
| 1712 | }, true)); | ||
| 1713 | ✗ | txt := Tpl.popBlock(txt); | |
| 1714 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1715 | "}\n", | ||
| 1716 | "\n", | ||
| 1717 | "void app_main(void)\n", | ||
| 1718 | "{\n", | ||
| 1719 | " xTaskCreate(om_simulation_task, \"om_sim\", OM_TASK_STACK_SIZE, NULL, 5, NULL);\n", | ||
| 1720 | "}" | ||
| 1721 | }, false)); | ||
| 1722 | then txt; | ||
| 1723 | |||
| 1724 | case ( txt, | ||
| 1725 | _, | ||
| 1726 | _ ) | ||
| 1727 | then txt; | ||
| 1728 | end match; | ||
| 1729 | end fun_96; | ||
| 1730 | |||
| 1731 | public function appMainFile | ||
| 1732 | input Tpl.Text txt; | ||
| 1733 | input SimCode.SimCode a_simCode; | ||
| 1734 | |||
| 1735 | output Tpl.Text out_txt; | ||
| 1736 | protected | ||
| 1737 | Tpl.Text l_modelNamePrefixStr; | ||
| 1738 | algorithm | ||
| 1739 | ✗ | l_modelNamePrefixStr := CodegenUtilSimulation.modelNamePrefix(Tpl.emptyTxt, a_simCode); | |
| 1740 | ✗ | out_txt := fun_96(txt, a_simCode, l_modelNamePrefixStr); | |
| 1741 | end appMainFile; | ||
| 1742 | |||
| 1743 | protected function fun_98 | ||
| 1744 | input Tpl.Text in_txt; | ||
| 1745 | input SimCode.SimCode in_a_simCode; | ||
| 1746 | input Tpl.Text in_a_modelNamePrefixStr; | ||
| 1747 | |||
| 1748 | output Tpl.Text out_txt; | ||
| 1749 | algorithm | ||
| 1750 | out_txt := | ||
| 1751 | match(in_txt, in_a_simCode, in_a_modelNamePrefixStr) | ||
| 1752 | local | ||
| 1753 | Tpl.Text txt; | ||
| 1754 | Tpl.Text a_modelNamePrefixStr; | ||
| 1755 | Absyn.Path i_modelInfo_name; | ||
| 1756 | |||
| 1757 | case ( txt, | ||
| 1758 | SimCode.SIMCODE(modelInfo = SimCode.MODELINFO(name = i_modelInfo_name)), | ||
| 1759 | a_modelNamePrefixStr ) | ||
| 1760 | algorithm | ||
| 1761 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("# ")); | |
| 1762 | ✗ | txt := CodegenUtil.dotPath(txt, i_modelInfo_name); | |
| 1763 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1764 | " on an ESP32\n", | ||
| 1765 | "\n", | ||
| 1766 | "This is an [ESP-IDF](https://docs.espressif.com/projects/esp-idf) project\n", | ||
| 1767 | "generated by OpenModelica with `--simCodeTarget=ESP32`. It solves the model\n", | ||
| 1768 | "with a fixed step explicit Euler solver and prints the results as CSV on the\n", | ||
| 1769 | "console of the board. It needs neither the OpenModelica simulation runtime nor\n", | ||
| 1770 | "the FMI headers, only ESP-IDF itself.\n", | ||
| 1771 | "\n", | ||
| 1772 | "## Build and flash\n", | ||
| 1773 | "\n", | ||
| 1774 | "The default chip is the ESP32-C6, with the results printed on UART0, which is\n", | ||
| 1775 | "the port the USB-serial bridge of the devkit is wired to. It is the same port\n", | ||
| 1776 | "the board is flashed over: a `COMx` on Windows, a `/dev/ttyUSBx` on Linux.\n", | ||
| 1777 | "Boards with a built in USB-Serial-JTAG port enumerate a second port; set\n", | ||
| 1778 | "`CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y` in `sdkconfig.defaults` to print the\n", | ||
| 1779 | "results there instead.\n", | ||
| 1780 | "\n", | ||
| 1781 | "```\n", | ||
| 1782 | ". $IDF_PATH/export.sh\n", | ||
| 1783 | "idf.py set-target esp32c6\n", | ||
| 1784 | "idf.py build\n", | ||
| 1785 | "idf.py -p COM6 flash monitor\n", | ||
| 1786 | "```\n", | ||
| 1787 | "\n", | ||
| 1788 | "Use `idf.py set-target esp32` (or `esp32s3`, `esp32c3`, ...) for another chip.\n", | ||
| 1789 | "\n", | ||
| 1790 | "## What is generated\n", | ||
| 1791 | "\n", | ||
| 1792 | "| File | Contents |\n", | ||
| 1793 | "| ---- | -------- |\n", | ||
| 1794 | "| `main/" | ||
| 1795 | }, false)); | ||
| 1796 | ✗ | txt := Tpl.writeText(txt, a_modelNamePrefixStr); | |
| 1797 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1798 | "_model.h` | Model interface: the number of variables, the simulation settings and the functions below |\n", | ||
| 1799 | "| `main/" | ||
| 1800 | }, false)); | ||
| 1801 | ✗ | txt := Tpl.writeText(txt, a_modelNamePrefixStr); | |
| 1802 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1803 | "_model.c` | The statically allocated model state, the equations, the model functions and the solver step |\n", | ||
| 1804 | "| `main/main.c` | `app_main`, which solves the model in a FreeRTOS task and prints the results |\n", | ||
| 1805 | "\n", | ||
| 1806 | "## Tuning the application\n", | ||
| 1807 | "\n", | ||
| 1808 | "`main/main.c` starts with a handful of defines that you can change, or\n", | ||
| 1809 | "override from `main/CMakeLists.txt` with `target_compile_definitions`:\n", | ||
| 1810 | "\n", | ||
| 1811 | "| Define | Default | Meaning |\n", | ||
| 1812 | "| ------ | ------- | ------- |\n", | ||
| 1813 | "| `OM_PRINT_EVERY` | 1 | Print one line of results every N steps |\n", | ||
| 1814 | "| `OM_REALTIME` | 0 | Spend `OM_STEP_SIZE` seconds of wall clock time on every step |\n", | ||
| 1815 | "| `OM_RUN_FOREVER` | 0 | Keep solving instead of stopping at `OM_STOP_TIME` |\n", | ||
| 1816 | "| `OM_TASK_STACK_SIZE` | 8192 | Stack of the task the model is solved in |\n", | ||
| 1817 | "| `OM_YIELD_INTERVAL_US` | 200000 | Hand the CPU back at least this often, so the task watchdog stays fed |\n", | ||
| 1818 | "\n", | ||
| 1819 | "To drive the hardware from the model, read the variables with\n", | ||
| 1820 | "`" | ||
| 1821 | }, false)); | ||
| 1822 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "getReal"); | |
| 1823 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1824 | "` and write them to a peripheral\n", | ||
| 1825 | "instead of printing them. `" | ||
| 1826 | }, false)); | ||
| 1827 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "realNames"); | |
| 1828 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1829 | "`\n", | ||
| 1830 | "holds the name of every variable, in the same order.\n", | ||
| 1831 | "\n", | ||
| 1832 | "## Limitations\n", | ||
| 1833 | "\n", | ||
| 1834 | "The target inherits the limitations of the experimental embedded C target it\n", | ||
| 1835 | "shares its equation generation with: no algebraic loops, no events, no arrays,\n", | ||
| 1836 | "no records and no strings. Models that use them fail to generate." | ||
| 1837 | }, false)); | ||
| 1838 | then txt; | ||
| 1839 | |||
| 1840 | case ( txt, | ||
| 1841 | _, | ||
| 1842 | _ ) | ||
| 1843 | then txt; | ||
| 1844 | end match; | ||
| 1845 | end fun_98; | ||
| 1846 | |||
| 1847 | public function readmeFile | ||
| 1848 | input Tpl.Text txt; | ||
| 1849 | input SimCode.SimCode a_simCode; | ||
| 1850 | |||
| 1851 | output Tpl.Text out_txt; | ||
| 1852 | protected | ||
| 1853 | Tpl.Text l_modelNamePrefixStr; | ||
| 1854 | algorithm | ||
| 1855 | ✗ | l_modelNamePrefixStr := CodegenUtilSimulation.modelNamePrefix(Tpl.emptyTxt, a_simCode); | |
| 1856 | ✗ | out_txt := fun_98(txt, a_simCode, l_modelNamePrefixStr); | |
| 1857 | end readmeFile; | ||
| 1858 | |||
| 1859 | annotation(__OpenModelica_Interface="codegen"); | ||
| 1860 | end CodegenESP32; | ||
| 1861 |