diff options
Diffstat (limited to 'Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led')
25 files changed, 1969 insertions, 0 deletions
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink Binary files differnew file mode 100755 index 0000000..3953004 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink.hex b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink.hex new file mode 100755 index 0000000..89858ca --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink.hex @@ -0,0 +1,114 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C942A0142
+:100020000C9451000C9451000C9451000C94F90064
+:100030000C9451000C9451000C94C8000C94510085
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E4EFF6E002C0EA
+:1000800005900D92A031B107D9F711E0A0E1B1E0E0
+:1000900001C01D92A531B107E1F70E9478010C94CF
+:1000A00078030C940000CF92DF92EF92FF920F93AF
+:1000B0001F93CF93DF93EC01C880D980EA80FB8047
+:1000C00020E030E040E05FE3C701B6010E94F102AA
+:1000D0000E9449029B01AC010E94A8019B01AC0156
+:1000E000C701B6010E94A70101E010E020E030E066
+:1000F00040E85FE30E94ED0287FF02C000E010E0ED
+:100100001D830C838E859F858230910561F083303D
+:10011000910599F00197C9F416BC80916E00826038
+:1001200080936E0016C0109285001092840080911A
+:100130006F00826080936F000CC01092B2008091BB
+:10014000700082608093700004C081E090E00E94A3
+:10015000780378949FB7F894809112019FBF882309
+:10016000C9F310921201EA85FB858C819D81892B50
+:1001700019F08081806202C080818F7D8083DF9151
+:10018000CF911F910F91FF90EF90DF90CF90089546
+:100190001F920F920FB60F9211242F933F938F93BC
+:1001A0009F938091100190911101019690931101FC
+:1001B0008093100180911201813091F02091100103
+:1001C0003091110180911301909114012817390782
+:1001D00038F081E080931201109211011092100109
+:1001E0009F918F913F912F910F900FBE0F901F9075
+:1001F00018951F920F920FB60F9211242F933F93D1
+:100200008F939F938091100190911101019690938B
+:1002100011018093100180911201813091F02091A1
+:100220001001309111018091130190911401281750
+:10023000390738F081E08093120110921101109279
+:1002400010019F918F913F912F910F900FBE0F90B2
+:100250001F9018951F920F920FB60F9211242F9393
+:100260003F938F939F93809110019091110101967C
+:10027000909311018093100180911201813091F0CF
+:10028000209110013091110180911301909114017E
+:100290002817390738F081E080931201109211017C
+:1002A000109210019F918F913F912F910F900FBE4F
+:1002B0000F901F901895FC0185B5836085BD81E086
+:1002C00090E09587848722E030E0309314012093FA
+:1002D000130124B5226024BD29EF27BD97878687A7
+:1002E000259A85E290E09387828780E090E00895E8
+:1002F000CF92DF92EF92FF9280E091E00E945B014B
+:10030000C12CD12C760160E070E0CB01609300013C
+:1003100070930101809302019093030180E091E0CA
+:100320000E9453008FEFC81AD80AE80AF80AC701DA
+:10033000B6010E940C022FE632E143E05BE30E942B
+:10034000F10220E030E0A9010E94A801DFCF50585F
+:10035000BB27AA270ED0F0C0E1D030F0E6D020F0C5
+:1003600031F49F3F11F41EF4D6C00EF4E095E7FB84
+:10037000A3C0E92FF2D080F3BA176207730784078E
+:10038000950718F071F49EF521C10EF4E0950B2E3F
+:10039000BA2FA02D0B01B90190010C01CA01A001D7
+:1003A0001124FF27591B99F0593F50F4503E68F132
+:1003B0001A16F040A22F232F342F4427585FF3CF73
+:1003C000469537952795A795F0405395C9F77EF444
+:1003D0001F16BA0B620B730B840BBAF09150A1F08D
+:1003E000FF0FBB1F661F771F881FC2F70EC0BA0F13
+:1003F000621F731F841F48F4879577956795B7959B
+:10040000F7959E3F08F0B3CF9395880F08F0992792
+:10041000EE0F979587950895E89409C097FB3EF4F1
+:1004200090958095709561957F4F8F4F9F4F992341
+:10043000A9F0F92F96E9BB279395F69587957795BF
+:100440006795B795F111F8CFFAF4BB0F11F460FF7F
+:100450001BC06F5F7F4F8F4F9F4F16C0882311F0D7
+:1004600096E911C0772321F09EE8872F762F05C0EB
+:10047000662371F096E8862F70E060E02AF09A9586
+:10048000660F771F881FDAF7880F9695879597F97B
+:10049000089585D080F09F3740F491110EF097C0F9
+:1004A00060E070E080E89FEB089526F41B16611D64
+:1004B000711D811D07C021C097F99F6780E870E01A
+:1004C00060E00895882371F4772321F09850872BFA
+:1004D000762F07C0662311F499270DC09051862B03
+:1004E00070E060E02AF09A95660F771F881FDAF7B0
+:1004F000880F9695879597F908959F3F31F0915011
+:1005000020F4879577956795B795880F911D9695F7
+:10051000879597F908959FEF80EC089500240A9439
+:100520001616170618060906089500240A941216CE
+:100530001306140605060895092E0394000C11F401
+:10054000882352F0BB0F40F4BF2B11F460FF04C0AE
+:100550006F5F7F4F8F4F9F4F089557FD9058440F07
+:10056000551F59F05F3F71F04795880F97FB991F12
+:1005700061F09F3F79F087950895121613061406CF
+:10058000551FF2CF4695F1DF08C01616170618065C
+:10059000991FF1CF86957105610508940895E5DFEF
+:1005A000A0F0BEE7B91788F4BB279F3860F4161691
+:1005B000B11D672F782F8827985FF7CF869577959D
+:1005C0006795B11D93959639C8F30895E894BB27B4
+:1005D00066277727CB0197F9089566D008F48FEF47
+:1005E00008950BD0A9CF9ADF28F09FDF18F095234C
+:1005F00009F062CF90CF1124EACFAFDFA0F3959F2F
+:10060000D1F3950F50E0551F629FF001729FBB27F9
+:10061000F00DB11D639FAA27F00DB11DAA1F649FA5
+:100620006627B00DA11D661F829F2227B00DA11D58
+:10063000621F739FB00DA11D621F839FA00D611DDE
+:10064000221F749F3327A00D611D231F849F600DFF
+:10065000211D822F762F6A2F11249F5750408AF038
+:10066000E1F088234AF0EE0FFF1FBB1F661F771FC4
+:10067000881F91505040A9F79E3F510570F01CCF44
+:10068000A6CF5F3FECF3983EDCF3869577956795B0
+:10069000B795F795E7959F5FC1F7FE2B880F911DE2
+:1006A0009695879597F90895990F0008550FAA0B0D
+:1006B000E0E8FEEF16161706E807F907C0F0121675
+:1006C0001306E407F50798F0621B730B840B950B78
+:1006D00039F40A2661F0232B242B252B21F40895CD
+:1006E0000A2609F4A140A6958FEF811D811D08956A
+:0406F000F894FFCFAC
+:1006F4000000000000006F12033B00000000000037
+:00000001FF
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink.sh b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink.sh new file mode 100755 index 0000000..cd9e818 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_blink.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_blink.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_blink_main.c -o led_blink -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_blink led_blink.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_blink.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink_main.c b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink_main.c new file mode 100755 index 0000000..bcf2661 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blink_main.c @@ -0,0 +1,212 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_blink_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_blink_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[3]; +} led_blink_fmi2Component; + +led_blink_fmi2Component led_blink_component = { + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component led_blink_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_blink_component; +} + +fmi2Status led_blink_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_blink_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 6); + return fmi2OK; +} + +fmi2Status led_blink_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_blink_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_blink_functionOutputs(fmi2Component comp) +{ + comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */ = (om_mod(comp->currentTime,2.0))>=(1.0); /* equation 3 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 6, comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */); +} + +fmi2Status led_blink_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_blink_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_blink_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_blink_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_blink_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_blink_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_blink_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue Binary files differnew file mode 100755 index 0000000..75a1347 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue.hex b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue.hex new file mode 100755 index 0000000..05d7448 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue.hex @@ -0,0 +1,93 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E50088
+:100020000C9451000C9451000C9451000C94B400A9
+:100030000C9451000C9451000C9483000C945100CA
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0EAEAF5E002C0EA
+:1000800005900D92A031B107D9F721E0A0E1B1E0D0
+:1000900001C01D92A531B207E1F70E9433010C9413
+:1000A000D3020C9400008230910561F083309105F9
+:1000B00099F00197C9F416BC80916E00826080931C
+:1000C0006E0016C0109285001092840080916F001F
+:1000D000826080936F000CC01092B200809170001B
+:1000E00082608093700004C081E090E00E94D3029F
+:1000F00078949FB7F894809112019FBF8823C9F329
+:100100001092120108951F920F920FB60F921124B0
+:100110002F933F938F939F938091100190911101A2
+:10012000019690931101809310018091120181300A
+:1001300091F0209110013091110180911301909163
+:1001400014012817390738F081E0809312011092CA
+:100150001101109210019F918F913F912F910F905B
+:100160000FBE0F901F9018951F920F920FB60F920F
+:1001700011242F933F938F939F938091100190911F
+:100180001101019690931101809310018091120149
+:10019000813091F020911001309111018091130173
+:1001A000909114012817390738F081E080931201EB
+:1001B00010921101109210019F918F913F912F91F8
+:1001C0000F900FBE0F901F9018951F920F920FB6B1
+:1001D0000F9211242F933F938F939F93809110013F
+:1001E00090911101019690931101809310018091DB
+:1001F0001201813091F02091100130911101809114
+:100200001301909114012817390738F081E0809389
+:10021000120110921101109210019F918F913F9144
+:100220002F910F900FBE0F901F901895FC01219AEF
+:1002300085E290E09387828785B5836085BD21E064
+:1002400030E03587248782E090E09093140180931A
+:10025000130184B5826084BD89EF87BD3787268707
+:1002600080E090E00895CF92DF92EF92FF9280E0DD
+:1002700091E00E941601C12CD12C760160E070E063
+:10028000CB01609300017093010180930201909370
+:10029000030180910E0190910F010E945300E091A3
+:1002A0000A01F0910B018081826080838FEFC81A70
+:1002B000D80AE80AF80AC701B6010E94D8012FE659
+:1002C00032E143E05BE30E94660220E030E0A901F6
+:1002D0000E946C01D6CF5058BB27AA270E948301E9
+:1002E0000C942C020E941E0238F00E94250220F07D
+:1002F00039F49F3F19F426F40C941B020EF4E09598
+:10030000E7FB0C941502E92F0E943D0258F3BA173F
+:10031000620773078407950720F079F4A6F50C941B
+:100320005F020EF4E0950B2EBA2FA02D0B01B90140
+:1003300090010C01CA01A0011124FF27591B99F05B
+:10034000593F50F4503E68F11A16F040A22F232F67
+:10035000342F4427585FF3CF469537952795A795B7
+:10036000F0405395C9F77EF41F16BA0B620B730B5E
+:10037000840BBAF09150A1F0FF0FBB1F661F771FCF
+:10038000881FC2F70EC0BA0F621F731F841F48F484
+:10039000879577956795B795F7959E3F08F0B0CF0D
+:1003A0009395880F08F09927EE0F979587950895F4
+:1003B000E89409C097FB3EF49095809570956195FF
+:1003C0007F4F8F4F9F4F9923A9F0F92F96E9BB27B5
+:1003D0009395F695879577956795B795F111F8CF31
+:1003E000FAF4BB0F11F460FF1BC06F5F7F4F8F4F9C
+:1003F0009F4F16C0882311F096E911C0772321F092
+:100400009EE8872F762F05C0662371F096E8862F29
+:1004100070E060E02AF09A95660F771F881FDAF780
+:10042000880F9695879597F9089597F99F6780E8C3
+:1004300070E060E008959FEF80EC089500240A9436
+:100440001616170618060906089500240A941216AF
+:100450001306140605060895092E0394000C11F4E2
+:10046000882352F0BB0F40F4BF2B11F460FF04C08F
+:100470006F5F7F4F8F4F9F4F089557FD9058440FE8
+:10048000551F59F05F3F71F04795880F97FB991FF3
+:1004900061F09F3F79F087950895121613061406B0
+:1004A000551FF2CF4695F1DF08C01616170618063D
+:1004B000991FF1CF86957105610508940895E89418
+:1004C000BB2766277727CB0197F908950E94790209
+:1004D0000C942C020E941E0238F00E94250220F08B
+:1004E000952311F00C9415020C941B0211240C940A
+:1004F00060020E943D0270F3959FC1F3950F50E09A
+:10050000551F629FF001729FBB27F00DB11D639FC5
+:10051000AA27F00DB11DAA1F649F6627B00DA11D6B
+:10052000661F829F2227B00DA11D621F739FB00D11
+:10053000A11D621F839FA00D611D221F749F332781
+:10054000A00D611D231F849F600D211D822F762F1A
+:100550006A2F11249F5750409AF0F1F088234AF0F7
+:10056000EE0FFF1FBB1F661F771F881F9150504063
+:10057000A9F79E3F510580F00C9415020C9460027F
+:100580005F3FE4F3983ED4F3869577956795B795EA
+:10059000F795E7959F5FC1F7FE2B880F911D969504
+:0A05A000879597F90895F894FFCFAE
+:1005AA000000000000006F12033B00000000000082
+:00000001FF
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue.sh b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue.sh new file mode 100755 index 0000000..b2a9b7d --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_blue.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_blue.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_blue_main.c -o led_blue -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_blue led_blue.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_blue.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay Binary files differnew file mode 100755 index 0000000..154b3fe --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay.hex b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay.hex new file mode 100755 index 0000000..eaa1eaa --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay.hex @@ -0,0 +1,100 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C940E015E
+:100020000C9451000C9451000C9451000C94DD0080
+:100030000C9451000C9451000C94AC000C945100A1
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E6E1F6E002C0F6
+:1000800005900D92A031B107D9F711E0A0E1B1E0E0
+:1000900001C01D92A531B107E1F70E945C010C94EB
+:1000A00009030C9400000F931F93CF93DF93EC018F
+:1000B00001E010E020E030E040EA50E4688179811E
+:1000C0008A819B810E94F00187FD02C000E010E060
+:1000D0001D830C838E859F858230910561F083306E
+:1000E000910599F00197C9F416BC80916E00826069
+:1000F00080936E0016C0109285001092840080914B
+:100100006F00826080936F000CC01092B2008091EB
+:10011000700082608093700004C081E090E00E94D3
+:10012000090378949FB7F894809112019FBF8823A8
+:10013000C9F310921201EA85FB858C819D81892B80
+:1001400019F08081826002C080818D7F8083DF9181
+:10015000CF911F910F9108951F920F920FB60F929A
+:1001600011242F933F938F939F938091100190912F
+:100170001101019690931101809310018091120159
+:10018000813091F020911001309111018091130183
+:10019000909114012817390738F081E080931201FB
+:1001A00010921101109210019F918F913F912F9108
+:1001B0000F900FBE0F901F9018951F920F920FB6C1
+:1001C0000F9211242F933F938F939F93809110014F
+:1001D00090911101019690931101809310018091EB
+:1001E0001201813091F02091100130911101809124
+:1001F0001301909114012817390738F081E080939A
+:10020000120110921101109210019F918F913F9154
+:100210002F910F900FBE0F901F9018951F920F9265
+:100220000FB60F9211242F933F938F939F9380913A
+:10023000100190911101019690931101809310018A
+:1002400080911201813091F02091100130911101C3
+:1002500080911301909114012817390738F081E03B
+:100260008093120110921101109210019F918F91B1
+:100270003F912F910F900FBE0F901F901895FC018A
+:10028000219A85E290E09387828785B5836085BD5A
+:1002900081E090E09587848722E030E0309314017C
+:1002A0002093130124B5226024BD29EF27BD978731
+:1002B000868780E090E00895CF92DF92EF92FF92E0
+:1002C00080E091E00E943F01C12CD12C760160E0DA
+:1002D00070E0CB01609300017093010180930201F3
+:1002E0009093030180E091E00E9453008FEFC81AC1
+:1002F000D80AE80AF80AC701B6010E94F4012FE6FD
+:1003000032E143E05BE30E94A60220E030E0A90175
+:100310000E948C01DFCF5058BB27AA270ED0DCC02B
+:10032000CDD030F0D2D020F031F49F3F11F41EF444
+:10033000C2C00EF4E095E7FBB8C0E92FDED080F331
+:10034000BA17620773078407950718F071F49EF5D2
+:10035000F6C00EF4E0950B2EBA2FA02D0B01B901BB
+:1003600090010C01CA01A0011124FF27591B99F02B
+:10037000593F50F4503E68F11A16F040A22F232F37
+:10038000342F4427585FF3CF469537952795A79587
+:10039000F0405395C9F77EF41F16BA0B620B730B2E
+:1003A000840BBAF09150A1F0FF0FBB1F661F771F9F
+:1003B000881FC2F70EC0BA0F621F731F841F48F454
+:1003C000879577956795B795F7959E3F08F0B3CFDA
+:1003D0009395880F08F09927EE0F979587950895C4
+:1003E00040D008F481E00895E89409C097FB3EF4FA
+:1003F00090958095709561957F4F8F4F9F4F992372
+:10040000A9F0F92F96E9BB279395F69587957795EF
+:100410006795B795F111F8CFFAF4BB0F11F460FFAF
+:100420001BC06F5F7F4F8F4F9F4F16C0882311F007
+:1004300096E911C0772321F09EE8872F762F05C01B
+:10044000662371F096E8862F70E060E02AF09A95B6
+:10045000660F771F881FDAF7880F9695879597F9AB
+:100460000895990F0008550FAA0BE0E8FEEF161645
+:100470001706E807F907C0F012161306E407F50798
+:1004800098F0621B730B840B950B39F40A2661F00C
+:10049000232B242B252B21F408950A2609F4A140AF
+:1004A000A6958FEF811D811D089597F99F6780E8BC
+:1004B00070E060E008959FEF80EC089500240A94B6
+:1004C0001616170618060906089500240A9412162F
+:1004D0001306140605060895092E0394000C11F462
+:1004E000882352F0BB0F40F4BF2B11F460FF04C00F
+:1004F0006F5F7F4F8F4F9F4F089557FD9058440F68
+:10050000551F59F05F3F71F04795880F97FB991F72
+:1005100061F09F3F79F0879508951216130614062F
+:10052000551FF2CF4695F1DF08C0161617061806BC
+:10053000991FF1CF86957105610508940895E89497
+:10054000BB2766277727CB0197F908950BD0C4CF37
+:10055000B5DF28F0BADF18F0952309F0A6CFABCFAE
+:100560001124EECFCADFA0F3959FD1F3950F50E091
+:10057000551F629FF001729FBB27F00DB11D639F55
+:10058000AA27F00DB11DAA1F649F6627B00DA11DFB
+:10059000661F829F2227B00DA11D621F739FB00DA1
+:1005A000A11D621F839FA00D611D221F749F332711
+:1005B000A00D611D231F849F600D211D822F762FAA
+:1005C0006A2F11249F5750408AF0E1F088234AF0A7
+:1005D000EE0FFF1FBB1F661F771F881F91505040F3
+:1005E000A9F79E3F510570F060CFAACF5F3FECF3B3
+:1005F000983EDCF3869577956795B795F795E795DF
+:100600009F5FC1F7FE2B880F911D9695879597F9EF
+:060610000895F894FFCFED
+:100616000000000001006F12033B00000000000014
+:00000001FF
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay.sh b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay.sh new file mode 100755 index 0000000..53c7838 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_blue_delay.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_blue_delay.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_blue_delay_main.c -o led_blue_delay -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_blue_delay led_blue_delay.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_blue_delay.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay_main.c b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay_main.c new file mode 100755 index 0000000..80930a6 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_delay_main.c @@ -0,0 +1,212 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_blue_delay_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_blue_delay_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[3]; +} led_blue_delay_fmi2Component; + +led_blue_delay_fmi2Component led_blue_delay_component = { + .fmi2BooleanVars = { + fmi2True /*booleanExpression1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component led_blue_delay_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_blue_delay_component; +} + +fmi2Status led_blue_delay_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_blue_delay_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status led_blue_delay_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_blue_delay_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_blue_delay_functionOutputs(fmi2Component comp) +{ + comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */ = (comp->currentTime)<(5.0); /* equation 3 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */); +} + +fmi2Status led_blue_delay_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_blue_delay_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_blue_delay_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_blue_delay_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_blue_delay_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_blue_delay_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_blue_delay_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_main.c b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_main.c new file mode 100755 index 0000000..048f6c8 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_main.c @@ -0,0 +1,212 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_blue_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_blue_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[3]; +} led_blue_fmi2Component; + +led_blue_fmi2Component led_blue_component = { + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component led_blue_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_blue_component; +} + +fmi2Status led_blue_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_blue_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status led_blue_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_blue_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_blue_functionOutputs(fmi2Component comp) +{ + Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, fmi2True); +} + +fmi2Status led_blue_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_blue_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_blue_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_blue_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_blue_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_blue_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_blue_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red Binary files differnew file mode 100755 index 0000000..c608b41 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red.hex b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red.hex new file mode 100755 index 0000000..e95094d --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red.hex @@ -0,0 +1,108 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94340138
+:100020000C9451000C9451000C9451000C94030159
+:100030000C9451000C9451000C94D2000C9451007B
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0EEE8F6E002C0E7
+:1000800005900D92A431B107D9F721E0A4E1B1E0C8
+:1000900001C01D92A931B207E1F70E9485010C94BD
+:1000A00045030C940000CF92DF92EF92FF920F93E2
+:1000B0001F93CF93DF93EC01C880D980EA80FB8047
+:1000C00001E010E020E030E040EA50E4C701B60172
+:1000D0000E94210287FD02C000E010E01D830C8316
+:1000E00001E010E020E030E040E051E4C701B6015B
+:1000F0000E94210287FD02C000E010E01F830E83F2
+:100100008A899B898230910561F08330910599F04D
+:100110000197C9F416BC80916E00826080936E00D6
+:1001200016C0109285001092840080916F0082604A
+:1001300080936F000CC01092B200809170008260BA
+:100140008093700004C081E090E00E9445037894A1
+:100150009FB7F894809116019FBF8823C9F310922E
+:100160001601EC85FD858C819D81892B19F080819C
+:10017000826002C080818D7F8083EE85FF858E81C5
+:100180009F81892B19F08081886002C08081877FE0
+:100190008083DF91CF911F910F91FF90EF90DF90BF
+:1001A000CF9008951F920F920FB60F9211242F93A4
+:1001B0003F938F939F938091140190911501019625
+:1001C000909315018093140180911601813091F074
+:1001D000209114013091150180911701909118011F
+:1001E0002817390738F081E0809316011092150125
+:1001F000109214019F918F913F912F910F900FBEFC
+:100200000F901F9018951F920F920FB60F92112406
+:100210002F933F938F939F93809114019091150199
+:1002200001969093150180931401809116018130FD
+:1002300091F0209114013091150180911701909156
+:1002400018012817390738F081E0809316011092C1
+:100250001501109214019F918F913F912F910F9052
+:100260000FBE0F901F9018951F920F920FB60F920E
+:1002700011242F933F938F939F938091140190911A
+:100280001501019690931501809314018091160138
+:10029000813091F020911401309115018091170166
+:1002A000909118012817390738F081E080931601E2
+:1002B00010921501109214019F918F913F912F91EF
+:1002C0000F900FBE0F901F901895FC01239A25E206
+:1002D00030E03787268785B5836085BD41E050E0F3
+:1002E000518B408B82E090E090931801809317012E
+:1002F00084B5826084BD89EF87BD538B428B219A80
+:100300003587248780E090E00895CF92DF92EF92C6
+:10031000FF9280E091E00E946501C12CD12C760112
+:1003200060E070E0CB016093000170930101809365
+:1003300002019093030180E091E00E9453008FEF4F
+:10034000C81AD80AE80AF80AC701B6010E942602AC
+:100350002FE632E143E05BE30E94D80220E030E088
+:10036000A9010E94B501DFCF5058BB27AA270E94E0
+:10037000CC010C949E020E94900238F00E949702D9
+:1003800020F039F49F3F19F426F40C948D020EF4FA
+:10039000E095E7FB0C948702E92F0E94AF0258F327
+:1003A000BA17620773078407950720F079F4A6F55A
+:1003B0000C94D1020EF4E0950B2EBA2FA02D0B0158
+:1003C000B90190010C01CA01A0011124FF27591B9A
+:1003D00099F0593F50F4503E68F11A16F040A22FA0
+:1003E000232F342F4427585FF3CF46953795279511
+:1003F000A795F0405395C9F77EF41F16BA0B620B10
+:10040000730B840BBAF09150A1F0FF0FBB1F661F56
+:10041000771F881FC2F70EC0BA0F621F731F841F99
+:1004200048F4879577956795B795F7959E3F08F0BF
+:10043000B0CF9395880F08F09927EE0F9795879581
+:1004400008950E94630208F481E00895E89409C0C9
+:1004500097FB3EF490958095709561957F4F8F4FF7
+:100460009F4F9923A9F0F92F96E9BB279395F6950D
+:10047000879577956795B795F111F8CFFAF4BB0F8B
+:1004800011F460FF1BC06F5F7F4F8F4F9F4F16C0EF
+:10049000882311F096E911C0772321F09EE8872F79
+:1004A000762F05C0662371F096E8862F70E060E035
+:1004B0002AF09A95660F771F881FDAF7880F9695AE
+:1004C000879597F90895990F0008550FAA0BE0E852
+:1004D000FEEF16161706E807F907C0F01216130606
+:1004E000E407F50798F0621B730B840B950B39F446
+:1004F0000A2661F0232B242B252B21F408950A26AC
+:1005000009F4A140A6958FEF811D811D089597F9EB
+:100510009F6780E870E060E008959FEF80EC0895A9
+:1005200000240A94161617061806090608950024D2
+:100530000A9412161306140605060895092E03944C
+:10054000000C11F4882352F0BB0F40F4BF2B11F4C0
+:1005500060FF04C06F5F7F4F8F4F9F4F089557FD1F
+:100560009058440F551F59F05F3F71F04795880F21
+:1005700097FB991F61F09F3F79F0879508951216B8
+:1005800013061406551FF2CF4695F1DF08C0161664
+:1005900017061806991FF1CF869571056105089415
+:1005A0000895E894BB2766277727CB0197F908952C
+:1005B0000E94EB020C949E020E94900238F00E946E
+:1005C000970220F0952311F00C9487020C948D0271
+:1005D00011240C94D2020E94AF0270F3959FC1F3D4
+:1005E000950F50E0551F629FF001729FBB27F00DE1
+:1005F000B11D639FAA27F00DB11DAA1F649F662736
+:10060000B00DA11D661F829F2227B00DA11D621F84
+:10061000739FB00DA11D621F839FA00D611D221F3E
+:10062000749F3327A00D611D231F849F600D211D22
+:10063000822F762F6A2F11249F5750409AF0F1F0A5
+:1006400088234AF0EE0FFF1FBB1F661F771F881F0E
+:1006500091505040A9F79E3F510580F00C948702BD
+:100660000C94D2025F3FE4F3983ED4F386957795DD
+:100670006795B795F795E7959F5FC1F7FE2B880FB4
+:0E068000911D9695879597F90895F894FFCFF0
+:10068E0000000000010001006F12033B000000009B
+:04069E000000000058
+:00000001FF
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red.sh b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red.sh new file mode 100755 index 0000000..7de1e2c --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_blue_red.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_blue_red.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_blue_red_main.c -o led_blue_red -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_blue_red led_blue_red.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_blue_red.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red_main.c b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red_main.c new file mode 100755 index 0000000..c9668e8 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_blue_red_main.c @@ -0,0 +1,215 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_blue_red_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_blue_red_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[2]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[4]; +} led_blue_red_fmi2Component; + +led_blue_red_fmi2Component led_blue_red_component = { + .fmi2BooleanVars = { + fmi2True /*booleanExpression1._y*/, + fmi2True /*booleanExpression2._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component led_blue_red_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_blue_red_component; +} + +fmi2Status led_blue_red_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_blue_red_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[1] /* digitalWriteBoolean2._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 4); + comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + return fmi2OK; +} + +fmi2Status led_blue_red_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_blue_red_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_blue_red_functionOutputs(fmi2Component comp) +{ + comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */ = (comp->currentTime)<(5.0); /* equation 4 */ + comp->fmi2BooleanVars[1] /* booleanExpression2._y DISCRETE */ = (comp->currentTime)<(8.0); /* equation 5 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean2._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 4, comp->fmi2BooleanVars[1] /* booleanExpression2._y DISCRETE */); +} + +fmi2Status led_blue_red_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_blue_red_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_blue_red_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_blue_red_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_blue_red_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_blue_red_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_blue_red_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink Binary files differnew file mode 100755 index 0000000..424aaf8 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink.hex b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink.hex new file mode 100755 index 0000000..d512cd3 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink.hex @@ -0,0 +1,131 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C942C0140
+:100020000C9451000C9451000C9451000C94FB0062
+:100030000C9451000C9451000C94CA000C94510083
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0ECE0F8E002C0EF
+:1000800005900D92A031B107D9F721E0A0E1B1E0D0
+:1000900001C01D92A531B207E1F70E947A010C94CC
+:1000A00004040C940000CF92DF92EF92FF920F9322
+:1000B0001F93CF93DF93EC01C880D980EA80FB8047
+:1000C0002DEC3CEC4CE45EE3C701B6010E94160245
+:1000D0000E94C5022DEC3CEC4CE45EE30E947303ED
+:1000E0009B01AC01C701B6010E94A90101E010E02B
+:1000F0002DEC3CEC4CEC5DE30E946E0387FF02C0EC
+:1001000000E010E01D830C838E859F858230910571
+:1001100061F08330910599F00197C9F416BC809184
+:100120006E00826080936E0016C01092850010925F
+:10013000840080916F00826080936F000CC01092E9
+:10014000B2008091700082608093700004C081E0F2
+:1001500090E00E94040478949FB7F8948091120173
+:100160009FBF8823C9F310921201EA85FB858C8119
+:100170009D81892B19F08081826002C080818D7FF2
+:100180008083DF91CF911F910F91FF90EF90DF90CF
+:10019000CF9008951F920F920FB60F9211242F93B4
+:1001A0003F938F939F93809110019091110101963D
+:1001B000909311018093100180911201813091F090
+:1001C000209110013091110180911301909114013F
+:1001D0002817390738F081E080931201109211013D
+:1001E000109210019F918F913F912F910F900FBE10
+:1001F0000F901F9018951F920F920FB60F92112417
+:100200002F933F938F939F938091100190911101B1
+:100210000196909311018093100180911201813019
+:1002200091F0209110013091110180911301909172
+:1002300014012817390738F081E0809312011092D9
+:100240001101109210019F918F913F912F910F906A
+:100250000FBE0F901F9018951F920F920FB60F921E
+:1002600011242F933F938F939F938091100190912E
+:100270001101019690931101809310018091120158
+:10028000813091F020911001309111018091130182
+:10029000909114012817390738F081E080931201FA
+:1002A00010921101109210019F918F913F912F9107
+:1002B0000F900FBE0F901F901895FC0185B58360BD
+:1002C00085BD21E030E03587248782E090E090937F
+:1002D00014018093130184B5826084BD89EF87BDCA
+:1002E00037872687219A85E290E09387828780E08E
+:1002F00090E00895CF92DF92EF92FF9280E091E03C
+:100300000E945D01C12CD12C760160E070E0CB0130
+:1003100060930001709301018093020190930301A7
+:1003200080E091E00E9453008FEFC81AD80AE80AD3
+:10033000F80AC701B6010E9488022FE632E143E0C5
+:100340005BE30E94730320E030E0A9010E94AA0150
+:10035000DFCF5058BB27AA270E94C1010C941C0371
+:100360000E940E0338F00E94150320F039F49F3FDD
+:1003700019F426F40C940B030EF4E095E7FB0C94AF
+:10038000DC02E92F0E942D0358F3BA1762077307A6
+:100390008407950720F079F4A6F50C9467030EF412
+:1003A000E0950B2EBA2FA02D0B01B90190010C0185
+:1003B000CA01A0011124FF27591B99F0593F50F49D
+:1003C000503E68F11A16F040A22F232F342F4427F5
+:1003D000585FF3CF469537952795A795F0405395ED
+:1003E000C9F77EF41F16BA0B620B730B840BBAF0BD
+:1003F0009150A1F0FF0FBB1F661F771F881FC2F728
+:100400000EC0BA0F621F731F841F48F4879577953B
+:100410006795B795F7959E3F08F0B0CF9395880FF5
+:1004200008F09927EE0F9795879508950E942A0264
+:100430000C941C030E94150358F00E940E0340F018
+:1004400029F45F3F29F00C94DC0251110C946803ED
+:100450000C940B030E942D0368F39923B1F35523E9
+:1004600091F3951B550BBB27AA27621773078407C7
+:1004700038F09F5F5F4F220F331F441FAA1FA9F35D
+:1004800035D00E2E3AF0E0E832D091505040E6954B
+:10049000001CCAF72BD0FE2F29D0660F771F881FAC
+:1004A000BB1F261737074807AB07B0E809F0BB0B9F
+:1004B000802DBF01FF2793585F4F3AF09E3F5105B3
+:1004C00078F00C94DC020C9468035F3FE4F3983EF0
+:1004D000D4F3869577956795B795F7959F5FC9F79C
+:1004E000880F911D9695879597F90895E1E0660F1D
+:1004F000771F881FBB1F621773078407BA0720F096
+:10050000621B730B840BBA0BEE1F88F7E0950895FE
+:10051000E89409C097FB3EF490958095709561959D
+:100520007F4F8F4F9F4F9923A9F0F92F96E9BB2753
+:100530009395F695879577956795B795F111F8CFCF
+:10054000FAF4BB0F11F460FF1BC06F5F7F4F8F4F3A
+:100550009F4F16C0882311F096E911C0772321F030
+:100560009EE8872F762F05C0662371F096E8862FC8
+:1005700070E060E02AF09A95660F771F881FDAF71F
+:10058000880F9695879597F908950E944F0390F0EC
+:100590009F3748F4911116F00C94680360E070E006
+:1005A00080E89FEB089526F41B16611D711D811DC7
+:1005B0000C94E2020C94FD0297F99F6780E870E0CA
+:1005C00060E00895882371F4772321F09850872BF9
+:1005D000762F07C0662311F499270DC09051862B02
+:1005E00070E060E02AF09A95660F771F881FDAF7AF
+:1005F000880F9695879597F908959F3F31F0915010
+:1006000020F4879577956795B795880F911D9695F6
+:10061000879597F908959FEF80EC089500240A9438
+:100620001616170618060906089500240A941216CD
+:100630001306140605060895092E0394000C11F400
+:10064000882352F0BB0F40F4BF2B11F460FF04C0AD
+:100650006F5F7F4F8F4F9F4F089557FD9058440F06
+:10066000551F59F05F3F71F04795880F97FB991F11
+:1006700061F09F3F79F087950895121613061406CE
+:10068000551FF2CF4695F1DF08C01616170618065B
+:10069000991FF1CF869571056105089408950E9410
+:1006A0003503A0F0BEE7B91788F4BB279F3860F484
+:1006B0001616B11D672F782F8827985FF7CF86957C
+:1006C00077956795B11D93959639C8F30895E89489
+:1006D000BB2766277727CB0197F908950E94E0038F
+:1006E00008F48FEF08950E9486030C941C030E9467
+:1006F0000E0338F00E94150320F0952311F00C949E
+:10070000DC020C940B0311240C9468030E942D034B
+:1007100070F3959FC1F3950F50E0551F629FF00154
+:10072000729FBB27F00DB11D639FAA27F00DB11D6D
+:10073000AA1F649F6627B00DA11D661F829F2227F6
+:10074000B00DA11D621F739FB00DA11D621F839F7D
+:10075000A00D611D221F749F3327A00D611D231F53
+:10076000849F600D211D822F762F6A2F11249F57A1
+:1007700050409AF0F1F088234AF0EE0FFF1FBB1FA4
+:10078000661F771F881F91505040A9F79E3F510563
+:1007900080F00C94DC020C9468035F3FE4F3983E15
+:1007A000D4F3869577956795B795F795E7959F5F0D
+:1007B000C1F7FE2B880F911D9695879597F908959F
+:1007C000990F0008550FAA0BE0E8FEEF1616170662
+:1007D000E807F907C0F012161306E407F50798F0CA
+:1007E000621B730B840B950B39F40A2661F0232BE3
+:1007F000242B252B21F408950A2609F4A140A6955F
+:0C0800008FEF811D811D0895F894FFCF3B
+:10080C000000000000006F12033B0000000000001D
+:00000001FF
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink.sh b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink.sh new file mode 100755 index 0000000..a30543c --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_green_blink.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_green_blink.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_green_blink_main.c -o led_green_blink -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_green_blink led_green_blink.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_green_blink.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink_main.c b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink_main.c new file mode 100755 index 0000000..5999083 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/led_green_blink_main.c @@ -0,0 +1,212 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_green_blink_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_green_blink_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[3]; +} led_green_blink_fmi2Component; + +led_green_blink_fmi2Component led_green_blink_component = { + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component led_green_blink_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_green_blink_component; +} + +fmi2Status led_green_blink_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_green_blink_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + return fmi2OK; +} + +fmi2Status led_green_blink_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_green_blink_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_green_blink_functionOutputs(fmi2Component comp) +{ + comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */ = (om_mod(comp->currentTime,0.2))>=(0.1); /* equation 3 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */); +} + +fmi2Status led_green_blink_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_green_blink_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_green_blink_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_green_blink_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_green_blink_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_green_blink_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_green_blink_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blink.mos b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blink.mos new file mode 100755 index 0000000..0ff4be4 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blink.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blink, fileNamePrefix="led_blink"); +getErrorString(); diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blue.mos b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blue.mos new file mode 100755 index 0000000..8b26945 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blue.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blue, fileNamePrefix="led_blue"); +getErrorString(); diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blue_delay.mos b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blue_delay.mos new file mode 100755 index 0000000..62b9250 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blue_delay.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blue_delay, fileNamePrefix="led_blue_delay"); +getErrorString(); diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blue_red.mos b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blue_red.mos new file mode 100755 index 0000000..f60dfc6 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_blue_red.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blue_red, fileNamePrefix="led_blue_red"); +getErrorString(); diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_green_blink.mos b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_green_blink.mos new file mode 100755 index 0000000..eeb79c1 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/led/runMDD_led_green_blink.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_green_blink, fileNamePrefix="led_green_blink"); +getErrorString(); |