diff options
Diffstat (limited to 'Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor')
10 files changed, 858 insertions, 0 deletions
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/runMDD_therm_buzzer.mos b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/runMDD_therm_buzzer.mos new file mode 100755 index 0000000..8164089 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/runMDD_therm_buzzer.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_thermistor.MDD_therm_buzzer, fileNamePrefix="therm_buzzer"); +getErrorString(); diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/runMDD_therm_read.mos b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/runMDD_therm_read.mos new file mode 100755 index 0000000..41b3c3a --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/runMDD_therm_read.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/siddharth/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/siddharth/OpenModelica_Tasks/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_thermistor.MDD_therm_read, fileNamePrefix="therm_read"); +getErrorString(); diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer Binary files differnew file mode 100755 index 0000000..4c841f2 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer.hex b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer.hex new file mode 100755 index 0000000..2517195 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer.hex @@ -0,0 +1,121 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C9431013B
+:100020000C9451000C9451000C9451000C9400015C
+:100030000C9451000C9451000C94CF000C9451007E
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E2E4F7E002C0F6
+:1000800005900D92A832B107D9F711E0A8E2B1E0CE
+:1000900001C01D92AD32B107E1F70E948A010C94B4
+:1000A0009F030C9400000F931F93CF93DF93EC01F9
+:1000B00080917C00857E846080937C0080917A00B2
+:1000C000806480937A0080917A0086FDFCCF6091F5
+:1000D00078007091790080E090E00E94860220E034
+:1000E00030E040E854E40E94180320E030EC4FE791
+:1000F00054E40E941E026C837D838E839F8301E003
+:1001000010E02A893B894C895D890E94140387FF8E
+:1001100002C000E010E0198B088B8EA19FA18230F5
+:10012000910561F08330910599F00197C9F416BCEF
+:1001300080916E00826080936E0016C010928500E0
+:100140001092840080916F00826080936F000CC0D9
+:100150001092B2008091700082608093700004C0A1
+:1001600081E090E00E949F0378949FB7F89480917B
+:100170002A019FBF8823C9F310922A01EAA1FBA19B
+:1001800088899989892B19F08081886002C08081D3
+:10019000877F8083DF91CF911F910F9108951F92E8
+:1001A0000F920FB60F9211242F933F938F939F932B
+:1001B00080912801909129010196909329018093C3
+:1001C000280180912A01813091F0209128013091FD
+:1001D000290180912B0190912C012817390738F0C3
+:1001E00081E080932A0110922901109228019F91A9
+:1001F0008F913F912F910F900FBE0F901F901895E8
+:100200001F920F920FB60F9211242F933F938F934B
+:100210009F93809128019091290101969093290143
+:100220008093280180912A01813091F0209128014A
+:100230003091290180912B0190912C0128173907C9
+:1002400038F081E080932A01109229011092280150
+:100250009F918F913F912F910F900FBE0F901F9004
+:1002600018951F920F920FB60F9211242F933F9360
+:100270008F939F93809128019091290101969093EB
+:1002800029018093280180912A01813091F02091E9
+:1002900028013091290180912B0190912C01281780
+:1002A000390738F081E080932A01109229011092D9
+:1002B00028019F918F913F912F910F900FBE0F902A
+:1002C0001F901895FC01539A8BE290E093A382A3B0
+:1002D00085B5836085BD81E090E095A384A32AE085
+:1002E00030E030932C0120932B0124B5226024BDF3
+:1002F00029EF27BD97A386A3ACE7B0E08C918C9340
+:10030000AAE7B0E08C9187688C9311A210A280E0DC
+:1003100090E00895CF92DF92EF92FF9280E091E01B
+:100320000E946201C12CD12C760160E070E0CB010B
+:100330006093000170930101809302019093030187
+:1003400080E091E00E9453008FEFC81AD80AE80AB3
+:10035000F80AC701B6010E9486022FE632E143E0A7
+:100360005BE30E94180320E030E0A9010E94BA017B
+:10037000DFCF5058BB27AA270ED01CC10DD130F0BB
+:1003800012D120F031F49F3F11F41EF402C10EF49B
+:10039000E095E7FBF8C0E92F1ED180F3BA1762079A
+:1003A00073078407950718F071F49EF536C10EF4B3
+:1003B000E0950B2EBA2FA02D0B01B90190010C0175
+:1003C000CA01A0011124FF27591B99F0593F50F48D
+:1003D000503E68F11A16F040A22F232F342F4427E5
+:1003E000585FF3CF469537952795A795F0405395DD
+:1003F000C9F77EF41F16BA0B620B730B840BBAF0AD
+:100400009150A1F0FF0FBB1F661F771F881FC2F717
+:100410000EC0BA0F621F731F841F48F4879577952B
+:100420006795B795F7959E3F08F0B3CF9395880FE2
+:1004300008F09927EE0F9795879508950CD0BAC0CC
+:10044000B2D040F0A9D030F021F45F3F19F09BC04A
+:100450005111E4C09EC0BFD098F39923C9F355232E
+:10046000B1F3951B550BBB27AA27621773078407A7
+:1004700038F09F5F5F4F220F331F441FAA1FA9F35D
+:1004800033D00E2E3AF0E0E830D091505040E6954F
+:10049000001CCAF729D0FE2F27D0660F771F881FB0
+:1004A000BB1F261737074807AB07B0E809F0BB0B9F
+:1004B000802DBF01FF2793585F4F2AF09E3F5105C3
+:1004C00068F061C0ABC05F3FECF3983EDCF386950B
+:1004D00077956795B795F7959F5FC9F7880F911D39
+:1004E0009695879597F90895E1E0660F771F881F25
+:1004F000BB1F621773078407BA0720F0621B730BD8
+:10050000840BBA0BEE1F88F7E0950895E89409C0B4
+:1005100097FB3EF490958095709561957F4F8F4F36
+:100520009F4F9923A9F0F92F96E9BB279395F6954C
+:10053000879577956795B795F111F8CFFAF4BB0FCA
+:1005400011F460FF1BC06F5F7F4F8F4F9F4F16C02E
+:10055000882311F096E911C0772321F09EE8872FB8
+:10056000762F05C0662371F096E8862F70E060E074
+:100570002AF09A95660F771F881FDAF7880F9695ED
+:10058000879597F9089597F99F6780E870E060E094
+:1005900008959FEF80EC089500240A94161617061C
+:1005A00018060906089500240A9412161306140664
+:1005B00005060895092E0394000C11F4882352F0C7
+:1005C000BB0F40F4BF2B11F460FF04C06F5F7F4F7F
+:1005D0008F4F9F4F089557FD9058440F551F59F066
+:1005E0005F3F71F04795880F97FB991F61F09F3F20
+:1005F00079F087950895121613061406551FF2CF49
+:100600004695F1DF08C0161617061806991FF1CF98
+:1006100086957105610508940895E894BB276627BF
+:100620007727CB0197F9089566D008F48FEF0895E6
+:100630000BD0C0CFB1DF28F0B6DF18F0952309F05A
+:10064000A2CFA7CF1124EACFC6DFA0F3959FD1F3A5
+:10065000950F50E0551F629FF001729FBB27F00D70
+:10066000B11D639FAA27F00DB11DAA1F649F6627C5
+:10067000B00DA11D661F829F2227B00DA11D621F14
+:10068000739FB00DA11D621F839FA00D611D221FCE
+:10069000749F3327A00D611D231F849F600D211DB2
+:1006A000822F762F6A2F11249F5750408AF0E1F055
+:1006B00088234AF0EE0FFF1FBB1F661F771F881F9E
+:1006C00091505040A9F79E3F510570F05CCFA6CFE6
+:1006D0005F3FECF3983EDCF3869577956795B79589
+:1006E000F795E7959F5FC1F7FE2B880F911D9695B3
+:1006F000879597F90895990F0008550FAA0BE0E820
+:10070000FEEF16161706E807F907C0F012161306D3
+:10071000E407F50798F0621B730B840B950B39F413
+:100720000A2661F0232B242B252B21F408950A2679
+:1007300009F4A140A6958FEF811D811D0895F894BD
+:02074000FFCFE9
+:1007420000000000000000000000000000000000A7
+:10075200000000806D440AD7233C02000100000023
+:0807620000000000000000008F
+:00000001FF
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer.sh b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer.sh new file mode 100755 index 0000000..b6782eb --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer.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_therm_buzzer.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_therm_buzzer.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 therm_buzzer_main.c -o therm_buzzer -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 therm_buzzer therm_buzzer.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:therm_buzzer.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer_main.c b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer_main.c new file mode 100755 index 0000000..d729be2 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_buzzer_main.c @@ -0,0 +1,253 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct therm_buzzer_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 therm_buzzer_fmi2Component_s { + fmi2Real currentTime; + fmi2Real fmi2RealVars[2]; + fmi2Boolean fmi2BooleanVars[3]; + fmi2Real fmi2RealParameter[2]; + fmi2Integer fmi2IntegerParameter[1]; + fmi2Boolean fmi2BooleanParameter[1]; + fmi2String fmi2StringParameter[1]; + void* extObjs[4]; +} therm_buzzer_fmi2Component; + +therm_buzzer_fmi2Component therm_buzzer_component = { + .fmi2RealVars = { + 0.0 /*adc._y*/, + 0.0 /*realValue1._number*/, + }, + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + fmi2False /*booleanExpression2._y*/, + fmi2False /*digitalWriteBoolean1._u*/, + }, + .fmi2RealParameter = { + 950.0 /*greaterEqualThreshold1._threshold*/, + 0.01 /*synchronizeRealtime1._actualInterval*/, + }, + .fmi2IntegerParameter = { + 2 /*realValue1._significantDigits*/, + }, + .fmi2BooleanParameter = { + fmi2True /*realValue1._use_numberPort*/, + }, +}; + +#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; +} + +static const char * const OMCLIT0 = "ElectricPotential"; +static const char * const OMCLIT1 = "V"; +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" +#include "MDDAVRAnalog.h" + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr); +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 fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution) +{ + fmi2Real om_value; + om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution); + return om_value; +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage) +{ + void* om_avr; + om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage); + return om_avr; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr) +{ + MDD_avr_analog_close(om_avr); +} +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 therm_buzzer_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 &therm_buzzer_component; +} + +fmi2Status therm_buzzer_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status therm_buzzer_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, 4, 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, 10); + comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 7, 1); + return fmi2OK; +} + +fmi2Status therm_buzzer_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status therm_buzzer_functionODE(fmi2Component comp) +{ +} + +static fmi2Status therm_buzzer_functionOutputs(fmi2Component comp) +{ + comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 5, 1024.0, 10); /* equation 7 */ + comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>=(comp->fmi2RealParameter[0] /* greaterEqualThreshold1._threshold PARAM */); /* equation 8 */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 */, 4, comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */); +} + +fmi2Status therm_buzzer_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + therm_buzzer_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 = therm_buzzer_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + therm_buzzer_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + therm_buzzer_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + therm_buzzer_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 = therm_buzzer_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/thermistor/therm_read b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_read Binary files differnew file mode 100755 index 0000000..a70feab --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_read diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_read.hex b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_read.hex new file mode 100755 index 0000000..c10a513 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_read.hex @@ -0,0 +1,114 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94130159
+:100020000C9451000C9451000C9451000C94E2007B
+:100030000C9451000C9451000C94B1000C9451009C
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E6EEF6E002C0E9
+:1000800005900D92AC31B107D9F721E0ACE1B1E0B8
+:1000900001C01D92A132B207E1F70E9468010C94E1
+:1000A00071030C940000CF93DF93EC0190917C00DE
+:1000B000957E956090937C0080917A008064809317
+:1000C0007A0080917A0086FDFCCF60917800709173
+:1000D000790080E090E00E94760220E030E040E885
+:1000E00054E40E94040320E030EC4FE754E40E9403
+:1000F00004026C837D838E839F838A8D9B8D8230E7
+:10010000910561F08330910599F00197C9F416BC0F
+:1001100080916E00826080936E0016C01092850000
+:100120001092840080916F00826080936F000CC0F9
+:100130001092B2008091700082608093700004C0C1
+:1001400081E090E00E94710378949FB7F8948091C9
+:100150001E019FBF8823C9F310921E01DF91CF912A
+:1001600008951F920F920FB60F9211242F933F9371
+:100170008F939F9380911C0190911D010196909304
+:100180001D0180931C0180911E01813091F020910E
+:100190001C0130911D0180911F01909120012817B1
+:1001A000390738F081E080931E0110921D011092F2
+:1001B0001C019F918F913F912F910F900FBE0F9037
+:1001C0001F9018951F920F920FB60F9211242F9324
+:1001D0003F938F939F9380911C0190911D010196F5
+:1001E00090931D0180931C0180911E01813091F03C
+:1001F00020911C0130911D0180911F0190912001DF
+:100200002817390738F081E080931E0110921D01F4
+:1002100010921C019F918F913F912F910F900FBED3
+:100220000F901F9018951F920F920FB60F921124E6
+:100230002F933F938F939F9380911C0190911D0169
+:10024000019690931D0180931C0180911E018130C5
+:1002500091F020911C0130911D0180911F0190911E
+:1002600020012817390738F081E080931E01109291
+:100270001D0110921C019F918F913F912F910F9022
+:100280000FBE0F901F901895FC01ACE7B0E08C9169
+:10029000806C8C93AAE7B0E08C9187688C93178A66
+:1002A000168A85B5836085BD21E030E0318F208FCF
+:1002B00082E090E09093200180931F0184B58260DA
+:1002C00084BD89EF87BD338F228F80E090E0089551
+:1002D000CF92DF92EF92FF9280E091E00E94440182
+:1002E000C12CD12C760160E070E0CB01609300015D
+:1002F00070930101809302019093030180E091E0EB
+:100300000E9453008FEFC81AD80AE80AF80AC701FA
+:10031000B6010E9476022FE632E143E05BE30E94E1
+:10032000040320E030E0A9010E949801DFCF50587B
+:10033000BB27AA270E94AF010C94CA020E94BC02EC
+:1003400038F00E94C30220F039F49F3F19F426F4DC
+:100350000C94B9020EF4E095E7FB0C94B302E92F7C
+:100360000E94DB0258F3BA176207730784079507E8
+:1003700020F079F4A6F50C94FD020EF4E0950B2E16
+:10038000BA2FA02D0B01B90190010C01CA01A001E7
+:100390001124FF27591B99F0593F50F4503E68F142
+:1003A0001A16F040A22F232F342F4427585FF3CF83
+:1003B000469537952795A795F0405395C9F77EF454
+:1003C0001F16BA0B620B730B840BBAF09150A1F09D
+:1003D000FF0FBB1F661F771F881FC2F70EC0BA0F23
+:1003E000621F731F841F48F4879577956795B795AB
+:1003F000F7959E3F08F0B0CF9395880F08F09927A6
+:10040000EE0F9795879508950E9418020C94CA02E2
+:100410000E94C30258F00E94BC0240F029F45F3FE2
+:1004200029F00C94B30251110C94FE020C94B90201
+:100430000E94DB0268F39923B1F3552391F3951BD6
+:10044000550BBB27AA2762177307840738F09F5FF5
+:100450005F4F220F331F441FAA1FA9F335D00E2E62
+:100460003AF0E0E832D091505040E695001CCAF7CF
+:100470002BD0FE2F29D0660F771F881FBB1F261792
+:1004800037074807AB07B0E809F0BB0B802DBF0169
+:10049000FF2793585F4F3AF09E3F510578F00C9438
+:1004A000B3020C94FE025F3FE4F3983ED4F38695CA
+:1004B00077956795B795F7959F5FC9F7880F911D59
+:1004C0009695879597F90895E1E0660F771F881F45
+:1004D000BB1F621773078407BA0720F0621B730BF8
+:1004E000840BBA0BEE1F88F7E0950895E89409C0D5
+:1004F00097FB3EF490958095709561957F4F8F4F57
+:100500009F4F9923A9F0F92F96E9BB279395F6956C
+:10051000879577956795B795F111F8CFFAF4BB0FEA
+:1005200011F460FF1BC06F5F7F4F8F4F9F4F16C04E
+:10053000882311F096E911C0772321F09EE8872FD8
+:10054000762F05C0662371F096E8862F70E060E094
+:100550002AF09A95660F771F881FDAF7880F96950D
+:10056000879597F9089597F99F6780E870E060E0B4
+:1005700008959FEF80EC089500240A94161617063C
+:1005800018060906089500240A9412161306140684
+:1005900005060895092E0394000C11F4882352F0E7
+:1005A000BB0F40F4BF2B11F460FF04C06F5F7F4F9F
+:1005B0008F4F9F4F089557FD9058440F551F59F086
+:1005C0005F3F71F04795880F97FB991F61F09F3F40
+:1005D00079F087950895121613061406551FF2CF69
+:1005E0004695F1DF08C0161617061806991FF1CFB9
+:1005F00086957105610508940895E894BB276627E0
+:100600007727CB0197F908950E9417030C94CA022B
+:100610000E94BC0238F00E94C30220F0952311F022
+:100620000C94B3020C94B90211240C94FE020E94A3
+:10063000DB0270F3959FC1F3950F50E0551F629F49
+:10064000F001729FBB27F00DB11D639FAA27F00D2B
+:10065000B11DAA1F649F6627B00DA11D661F829F52
+:100660002227B00DA11D621F739FB00DA11D621F37
+:10067000839FA00D611D221F749F3327A00D611D54
+:10068000231F849F600D211D822F762F6A2F112436
+:100690009F5750409AF0F1F088234AF0EE0FFF1F69
+:1006A000BB1F661F771F881F91505040A9F79E3FC0
+:1006B000510580F00C94B3020C94FE025F3FE4F30A
+:1006C000983ED4F3869577956795B795F795E79516
+:1006D0009F5FC1F7FE2B880F911D9695879597F91F
+:0606E0000895F894FFCF1D
+:1006E6000000000000000000000000006F12033B45
+:0C06F600020001000000000000000000F5
+:00000001FF
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_read.sh b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_read.sh new file mode 100755 index 0000000..2a02704 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_read.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_therm_read.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_therm_read.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 therm_read_main.c -o therm_read -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 therm_read therm_read.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -D -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:therm_read.hex +if [ $? -ne 0 ]; then + exit 1 +fi diff --git a/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_read_main.c b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_read_main.c new file mode 100755 index 0000000..2b38516 --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/thermistor/therm_read_main.c @@ -0,0 +1,226 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct therm_read_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 therm_read_fmi2Component_s { + fmi2Real currentTime; + fmi2Real fmi2RealVars[2]; + fmi2Real fmi2RealParameter[1]; + fmi2Integer fmi2IntegerParameter[1]; + fmi2Boolean fmi2BooleanParameter[1]; + fmi2String fmi2StringParameter[1]; + void* extObjs[3]; +} therm_read_fmi2Component; + +therm_read_fmi2Component therm_read_component = { + .fmi2RealVars = { + 0.0 /*adc._y*/, + 0.0 /*realValue1._number*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, + .fmi2IntegerParameter = { + 2 /*realValue1._significantDigits*/, + }, + .fmi2BooleanParameter = { + fmi2True /*realValue1._use_numberPort*/, + }, +}; + +#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; +} + +static const char * const OMCLIT0 = "ElectricPotential"; +static const char * const OMCLIT1 = "V"; +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRAnalog.h" + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr); +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 fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution) +{ + fmi2Real om_value; + om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution); + return om_value; +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage) +{ + void* om_avr; + om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage); + return om_avr; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr) +{ + MDD_avr_analog_close(om_avr); +} +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 therm_read_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 &therm_read_component; +} + +fmi2Status therm_read_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status therm_read_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 7, 4); + 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 therm_read_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status therm_read_functionODE(fmi2Component comp) +{ +} + +static fmi2Status therm_read_functionOutputs(fmi2Component comp) +{ + comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 6, 1024.0, 10); /* equation 4 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */); +} + +fmi2Status therm_read_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + therm_read_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 = therm_read_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + therm_read_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + therm_read_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + therm_read_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 = therm_read_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 +} + |