diff options
Diffstat (limited to 'Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push')
10 files changed, 782 insertions, 0 deletions
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button Binary files differnew file mode 100755 index 0000000..a9402e5 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button.hex b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button.hex new file mode 100755 index 0000000..0059548 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button.hex @@ -0,0 +1,94 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94FB0072
+:100020000C9451000C9451000C9451000C94CA0093
+:100030000C9451000C9451000C9499000C945100B4
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E6EAF5E002C0EE
+:1000800005900D92A631B107D9F711E0A6E1B1E0D4
+:1000900001C01D92AB31B107E1F70E944C010C94F5
+:1000A000D1020C940000DC0154968D919C915597DF
+:1000B0008230910561F08330910599F00197C9F480
+:1000C00016BC80916E00826080936E0016C0109204
+:1000D00085001092840080916F00826080936F0091
+:1000E0000CC01092B200809170008260809370000A
+:1000F00004C081E090E00E94D10278949FB7F89408
+:10010000809118019FBF8823C9F31092180150965F
+:10011000ED91FC91519718968D919C9119970097AC
+:1001200021F0808182608083089580818D7F80832B
+:1001300008951F920F920FB60F9211242F933F93A1
+:100140008F939F9380911601909117010196909340
+:1001500017018093160180911801813091F0209150
+:100160001601309117018091190190911A012817F9
+:10017000390738F081E0809318011092170110922E
+:1001800016019F918F913F912F910F900FBE0F906D
+:100190001F9018951F920F920FB60F9211242F9354
+:1001A0003F938F939F938091160190911701019631
+:1001B000909317018093160180911801813091F07E
+:1001C00020911601309117018091190190911A0127
+:1001D0002817390738F081E0809318011092170131
+:1001E000109216019F918F913F912F910F900FBE0A
+:1001F0000F901F9018951F920F920FB60F92112417
+:100200002F933F938F939F938091160190911701A5
+:100210000196909317018093160180911801813007
+:1002200091F0209116013091170180911901909160
+:100230001A012817390738F081E0809318011092CD
+:100240001701109216019F918F913F912F910F905E
+:100250000FBE0F901F901895FC01219A85E290E047
+:10026000918B808B24989787868785B5836085BD21
+:1002700081E090E0938B828B22E030E030931A0192
+:100280002093190124B5226024BD29EF27BD958B49
+:10029000848B80E090E00895CF92DF92EF92FF92FE
+:1002A00080E091E00E942C01C12CD12C760160E00D
+:1002B00070E0CB0160930001709301018093020113
+:1002C0009093030180E091E00E9453008FEFC81AE1
+:1002D000D80AE80AF80AC701B6010E94E0012FE631
+:1002E00032E143E05BE30E946E0220E030E0A901CE
+:1002F0000E947C01DFCF5058BB27AA270ED0B4C084
+:10030000A5D030F0AAD020F031F49F3F11F41EF4B4
+:100310009AC00EF4E095E7FB90C0E92FB6D080F3C9
+:10032000BA17620773078407950718F071F49EF5F2
+:10033000CEC00EF4E0950B2EBA2FA02D0B01B90103
+:1003400090010C01CA01A0011124FF27591B99F04B
+:10035000593F50F4503E68F11A16F040A22F232F57
+:10036000342F4427585FF3CF469537952795A795A7
+:10037000F0405395C9F77EF41F16BA0B620B730B4E
+:10038000840BBAF09150A1F0FF0FBB1F661F771FBF
+:10039000881FC2F70EC0BA0F621F731F841F48F474
+:1003A000879577956795B795F7959E3F08F0B3CFFA
+:1003B0009395880F08F09927EE0F979587950895E4
+:1003C000E89409C097FB3EF49095809570956195EF
+:1003D0007F4F8F4F9F4F9923A9F0F92F96E9BB27A5
+:1003E0009395F695879577956795B795F111F8CF21
+:1003F000FAF4BB0F11F460FF1BC06F5F7F4F8F4F8C
+:100400009F4F16C0882311F096E911C0772321F081
+:100410009EE8872F762F05C0662371F096E8862F19
+:1004200070E060E02AF09A95660F771F881FDAF770
+:10043000880F9695879597F9089597F99F6780E8B3
+:1004400070E060E008959FEF80EC089500240A9426
+:100450001616170618060906089500240A9412169F
+:100460001306140605060895092E0394000C11F4D2
+:10047000882352F0BB0F40F4BF2B11F460FF04C07F
+:100480006F5F7F4F8F4F9F4F089557FD9058440FD8
+:10049000551F59F05F3F71F04795880F97FB991FE3
+:1004A00061F09F3F79F087950895121613061406A0
+:1004B000551FF2CF4695F1DF08C01616170618062D
+:1004C000991FF1CF86957105610508940895E89408
+:1004D000BB2766277727CB0197F908950BD0C4CFA8
+:1004E000B5DF28F0BADF18F0952309F0A6CFABCF1F
+:1004F0001124EECFCADFA0F3959FD1F3950F50E002
+:10050000551F629FF001729FBB27F00DB11D639FC5
+:10051000AA27F00DB11DAA1F649F6627B00DA11D6B
+:10052000661F829F2227B00DA11D621F739FB00D11
+:10053000A11D621F839FA00D611D221F749F332781
+:10054000A00D611D231F849F600D211D822F762F1A
+:100550006A2F11249F5750408AF0E1F088234AF017
+:10056000EE0FFF1FBB1F661F771F881F9150504063
+:10057000A9F79E3F510570F060CFAACF5F3FECF323
+:10058000983EDCF3869577956795B795F795E7954F
+:100590009F5FC1F7FE2B880F911D9695879597F960
+:0605A0000895F894FFCF5E
+:1005A600000000000000000000006F12033B000086
+:0605B6000000000000003F
+:00000001FF
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button.sh b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button.sh new file mode 100755 index 0000000..1428171 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button.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_push_button.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_push_button.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_push_button_main.c -o led_push_button -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_push_button led_push_button.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_push_button.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button_main.c b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button_main.c new file mode 100755 index 0000000..7b155ad --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/led_push_button_main.c @@ -0,0 +1,234 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_push_button_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_push_button_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[3]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[4]; +} led_push_button_fmi2Component; + +led_push_button_fmi2Component led_push_button_component = { + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + fmi2False /*booleanExpression2._y*/, + fmi2False /*digitalReadBoolean1._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 fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin); +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_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_destructor(fmi2Component comp, void* om_digital); +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 fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin) +{ + fmi2Boolean om_b; + om_b = MDD_avr_digital_pin_read(om_port, om_pin); + return om_b; +} +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_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2False); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +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_push_button_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_push_button_component; +} + +fmi2Status led_push_button_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_push_button_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + comp->extObjs[0] /* digitalReadBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitRead */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(comp, 2, 5); + 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); + return fmi2OK; +} + +fmi2Status led_push_button_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_push_button_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_push_button_functionOutputs(fmi2Component comp) +{ + 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[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[2] /* digitalReadBoolean1._y DISCRETE */); +} + +fmi2Status led_push_button_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_push_button_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_push_button_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_push_button_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_push_button_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_push_button_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_push_button_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/push/push_button_status b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/push_button_status Binary files differnew file mode 100755 index 0000000..5b91980 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/push_button_status diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/push_button_status.hex b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/push_button_status.hex new file mode 100755 index 0000000..ab8dde5 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/push_button_status.hex @@ -0,0 +1,91 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E50088
+:100020000C9451000C9451000C9451000C94B400A9
+:100030000C9451000C9451000C9483000C945100CA
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E8E7F5E002C0EF
+:1000800005900D92A431B107D9F711E0A4E1B1E0D8
+:1000900001C01D92A931B107E1F70E9433010C9410
+:1000A000BA020C9400008230910561F08330910512
+:1000B00099F00197C9F416BC80916E00826080931C
+:1000C0006E0016C0109285001092840080916F001F
+:1000D000826080936F000CC01092B200809170001B
+:1000E00082608093700004C081E090E00E94BA02B8
+:1000F00078949FB7F894809116019FBF8823C9F325
+:100100001092160108951F920F920FB60F921124AC
+:100110002F933F938F939F9380911401909115019A
+:1001200001969093150180931401809116018130FE
+:1001300091F0209114013091150180911701909157
+:1001400018012817390738F081E0809316011092C2
+:100150001501109214019F918F913F912F910F9053
+:100160000FBE0F901F9018951F920F920FB60F920F
+:1001700011242F933F938F939F938091140190911B
+:100180001501019690931501809314018091160139
+:10019000813091F020911401309115018091170167
+:1001A000909118012817390738F081E080931601E3
+:1001B00010921501109214019F918F913F912F91F0
+:1001C0000F900FBE0F901F9018951F920F920FB6B1
+:1001D0000F9211242F933F938F939F93809114013B
+:1001E00090911501019690931501809314018091CF
+:1001F0001601813091F02091140130911501809108
+:100200001701909118012817390738F081E0809381
+:10021000160110921501109214019F918F913F9138
+:100220002F910F900FBE0F901F901895FC012498EE
+:1002300083E290E09787868785B5836085BD81E0FE
+:1002400090E0918B808B22E030E030931801209376
+:10025000170124B5226024BD29EF27BD938B828B23
+:1002600080E090E00895CF92DF92EF92FF9280E0DD
+:1002700091E00E941601C12CD12C760160E070E063
+:10028000CB01609300017093010180930201909370
+:10029000030180911201909113010E9453008FEF8E
+:1002A000C81AD80AE80AF80AC701B6010E94C901AB
+:1002B0002FE632E143E05BE30E94570220E030E0AA
+:1002C000A9010E946501DDCF5058BB27AA270ED097
+:1002D000B4C0A5D030F0AAD020F031F49F3F11F483
+:1002E0001EF49AC00EF4E095E7FB90C0E92FB6D05B
+:1002F00080F3BA17620773078407950718F071F443
+:100300009EF5CEC00EF4E0950B2EBA2FA02D0B015A
+:10031000B90190010C01CA01A0011124FF27591B4A
+:1003200099F0593F50F4503E68F11A16F040A22F50
+:10033000232F342F4427585FF3CF469537952795C1
+:10034000A795F0405395C9F77EF41F16BA0B620BC0
+:10035000730B840BBAF09150A1F0FF0FBB1F661F07
+:10036000771F881FC2F70EC0BA0F621F731F841F4A
+:1003700048F4879577956795B795F7959E3F08F070
+:10038000B3CF9395880F08F09927EE0F979587952F
+:100390000895E89409C097FB3EF490958095709578
+:1003A00061957F4F8F4F9F4F9923A9F0F92F96E9C1
+:1003B000BB279395F695879577956795B795F11136
+:1003C000F8CFFAF4BB0F11F460FF1BC06F5F7F4FD3
+:1003D0008F4F9F4F16C0882311F096E911C07723E5
+:1003E00021F09EE8872F762F05C0662371F096E8EE
+:1003F000862F70E060E02AF09A95660F771F881FBD
+:10040000DAF7880F9695879597F9089597F99F677A
+:1004100080E870E060E008959FEF80EC089500248C
+:100420000A941616170618060906089500240A9459
+:1004300012161306140605060895092E0394000CDF
+:1004400011F4882352F0BB0F40F4BF2B11F460FF6E
+:1004500004C06F5F7F4F8F4F9F4F089557FD905897
+:10046000440F551F59F05F3F71F04795880F97FB78
+:10047000991F61F09F3F79F0879508951216130632
+:100480001406551FF2CF4695F1DF08C01616170661
+:100490001806991FF1CF8695710561050894089596
+:1004A000E894BB2766277727CB0197F908950BD0EF
+:1004B000C4CFB5DF28F0BADF18F0952309F0A6CF36
+:1004C000ABCF1124EECFCADFA0F3959FD1F3950FE8
+:1004D00050E0551F629FF001729FBB27F00DB11DC8
+:1004E000639FAA27F00DB11DAA1F649F6627B00D58
+:1004F000A11D661F829F2227B00DA11D621F739F41
+:10050000B00DA11D621F839FA00D611D221F749F4E
+:100510003327A00D611D231F849F600D211D822F95
+:10052000762F6A2F11249F5750408AF0E1F08823DC
+:100530004AF0EE0FFF1FBB1F661F771F881F9150E9
+:100540005040A9F79E3F510570F060CFAACF5F3FA2
+:10055000ECF3983EDCF3869577956795B795F7951C
+:10056000E7959F5FC1F7FE2B880F911D96958795A4
+:0805700097F90895F894FFCFFC
+:1005780000000000000000006F12033B01000000B3
+:04058800000000006F
+:00000001FF
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/push_button_status.sh b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/push_button_status.sh new file mode 100755 index 0000000..404eced --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/push_button_status.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_push_button_status.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_push_button_status.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 push_button_status_main.c -o push_button_status -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 push_button_status push_button_status.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:push_button_status.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/push_button_status_main.c b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/push_button_status_main.c new file mode 100755 index 0000000..f732e8a --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/push_button_status_main.c @@ -0,0 +1,219 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct push_button_status_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 push_button_status_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[2]; + fmi2Real fmi2RealParameter[1]; + fmi2Boolean fmi2BooleanParameter[1]; + void* extObjs[3]; +} push_button_status_fmi2Component; + +push_button_status_fmi2Component push_button_status_component = { + .fmi2BooleanVars = { + fmi2False /*booleanValue1._active*/, + fmi2False /*digitalReadBoolean1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, + .fmi2BooleanParameter = { + fmi2True /*booleanValue1._use_activePort*/, + }, +}; + +#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 fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_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 fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin) +{ + fmi2Boolean om_b; + om_b = MDD_avr_digital_pin_read(om_port, om_pin); + return om_b; +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2False); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_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 push_button_status_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 &push_button_status_component; +} + +fmi2Status push_button_status_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status push_button_status_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* digitalReadBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitRead */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(comp, 2, 5); + 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 push_button_status_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status push_button_status_functionODE(fmi2Component comp) +{ +} + +static fmi2Status push_button_status_functionOutputs(fmi2Component comp) +{ + Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */); +} + +fmi2Status push_button_status_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + push_button_status_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 = push_button_status_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + push_button_status_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + push_button_status_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + push_button_status_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 = push_button_status_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/push/runMDD_led_push_button.mos b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/runMDD_led_push_button.mos new file mode 100755 index 0000000..3e2d70f --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/runMDD_led_push_button.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_push.MDD_led_push_button, fileNamePrefix="led_push_button"); +getErrorString(); diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/runMDD_push_button_status.mos b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/runMDD_push_button_status.mos new file mode 100755 index 0000000..c8b8d45 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/push/runMDD_push_button_status.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_push.MDD_push_button_status, fileNamePrefix="push_button_status"); +getErrorString(); |