Skip to content

Commit

Permalink
Add default clock period to fix ticket:3752
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Apr 9, 2016
1 parent 5d18848 commit 900bb22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
6 changes: 5 additions & 1 deletion Compiler/Template/CodegenCpp.tpl
Expand Up @@ -9744,19 +9744,23 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
case CLOCKED_PARTITION(__) then
let &preExp = buffer "" /*BUFD*/
let intvl = daeExp(getClockInterval(baseClock), contextOther, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
let interval = match intvl case "0.0" then '1.0' else intvl
let warning = match intvl case "0.0" then
'ModelicaMessage("Using default Clock(1.0)!");'
let subClocks = (subPartitions |> subPartition =>
match subPartition
case SUBPARTITION(subClock=SUBCLOCK(factor=RATIONAL(nom=fnom, denom=fres), shift=RATIONAL(nom=snom, denom=sres))) then
<<
<%preExp%>
_clockInterval[<%i%>] = <%intvl%> * <%fnom%>.0 / <%fres%>.0;
_clockInterval[<%i%>] = <%interval%> * <%fnom%>.0 / <%fres%>.0;
_clockShift[<%i%>] = <%snom%>.0 / <%sres%>.0;
_clockTime[<%i%>] = _simTime + _clockShift[<%i%>] * _clockInterval[<%i%>];
<%i%> ++;
>>
; separator="\n")
<<
<%subClocks%>
<%warning%>
>>
; separator="\n")%>
>>
Expand Down
23 changes: 12 additions & 11 deletions SimulationRuntime/cpp/Core/Utils/Modelica/ModelicaUtilities.cpp
Expand Up @@ -17,16 +17,17 @@ extern "C" {

void ModelicaMessage(const char* string)
{
throw ModelicaSimulationError(UTILITY,"ModelicaMessage not implemented yet");
fprintf(stdout, string);
fflush(stdout);
}

void ModelicaVFormatMessage(const char*string, va_list args)
void ModelicaVFormatMessage(const char* string, va_list args)
{
vfprintf(stdout, string, args);
fflush(stdout);
}

void ModelicaFormatMessage(const char* string,...)
void ModelicaFormatMessage(const char* string, ...)
{
va_list args;
va_start(args, string);
Expand All @@ -36,22 +37,22 @@ void ModelicaFormatMessage(const char* string,...)

void ModelicaError(const char* string)
{
throw ModelicaSimulationError(UTILITY,string);
throw ModelicaSimulationError(UTILITY, string);
}

void ModelicaVFormatError(const char*string, va_list args)
void ModelicaVFormatError(const char* string, va_list args)
{
throw ModelicaSimulationError(UTILITY,"ModelicaVFormatError not implemented yet");
char buffer[256];
vsnprintf(buffer, 256, string, args);
ModelicaError(buffer);
}

void ModelicaFormatError(const char* text, ...)
void ModelicaFormatError(const char* string, ...)
{
char buffer[256];
va_list args;
va_start(args, text);
vsnprintf(buffer, 256, text, args);
va_start(args, string);
ModelicaVFormatError(string, args);
va_end(args);
ModelicaError(buffer);
}

static std::map<const char*, char*> _allocatedStrings;
Expand Down

0 comments on commit 900bb22

Please sign in to comment.