Commit 4adc8cc1 authored by Tiago Jorge's avatar Tiago Jorge
Browse files

Add support for Simulink blocks deployment on the Brave (and resulting new...

Add support for Simulink blocks deployment on the Brave (and resulting new multiple definition errors solved).
parent 08c450d9
......@@ -37,6 +37,9 @@ TSource = TypeVar('TSource')
TDestin = TypeVar('TDestin')
brave_seen = {}
fpgaSuffix = ''
dispatcherSuffix = "_Brave_Dispatch"
genHwDevDrv = False
class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
......@@ -106,6 +109,14 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
outputDir: str,
maybeFVname: str,
useOSS: bool) -> None:
global genHwDevDrv
global fpgaSuffix
genHwDevDrv = subProgram._fpgaConfigurations is not '' and ((subProgramImplementation.lower() == "c" or subProgramImplementation.lower() == "simulink") and modelingLanguage == "vhdl");
if genHwDevDrv:
fpgaSuffix = "_Brave_Fpga"
else:
fpgaSuffix = ''
if modelingLanguage == "QGenAda":
self.dir = outputDir
self.useOSS = useOSS
......@@ -171,8 +182,6 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.C_HeaderFile.write("#ifndef __%s_H__\n" % ID)
self.C_HeaderFile.write("#define __%s_H__\n\n" % ID)
self.C_HeaderFile.write("#include <stdlib.h> /* for size_t */\n")
if subProgramImplementation.lower() == "c" and subProgram._fpgaConfigurations is not '':
self.C_HeaderFile.write("#include \"C_ASN1_Types.h\"\n")
self.C_HeaderFile.write("\n")
self.C_SourceFile.write("#ifdef __unix__\n")
......@@ -206,6 +215,8 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
param: Param,
leafTypeDict: AST_Leaftypes,
names: AST_Lookup) -> None:
global fpgaSuffix
if encoding.lower() not in self.supportedEncodings:
panic(str(self.__class__) + ": in (%s), encoding can be one of %s (not '%s')" % ( # pragma: no cover
subProgram._id + "." + subProgramImplementation, self.supportedEncodings, encoding)) # pragma: no cover
......@@ -242,7 +253,7 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
" end Ada_%s;\n\n" % tmpSpName)
else:
self.C_HeaderFile.write(
"int %s(void *pBuffer, size_t iMaxBufferSize);\n" % tmpSpName)
"int %s%s(void *pBuffer, size_t iMaxBufferSize);\n" % (tmpSpName, fpgaSuffix))
self.ADA_HeaderFile.write(
"procedure Ada_%s(pBuffer : in Interfaces.C.char_array; iMaxBufferSize : in Integer; bytesWritten : out Integer);\n" % tmpSpName)
self.ADA_SourceFile.write(
......@@ -257,7 +268,7 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.ADA_SourceFile.write(
"end Ada_%s;\n\n" % tmpSpName)
self.C_SourceFile.write(
"int %s(void *pBuffer, size_t iMaxBufferSize)\n{\n" % tmpSpName)
"int %s%s(void *pBuffer, size_t iMaxBufferSize)\n{\n" % (tmpSpName, fpgaSuffix))
if self.useOSS and encoding.lower() == "uper":
self.C_SourceFile.write(
......@@ -342,6 +353,8 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
param: Param,
leafTypeDict: AST_Leaftypes,
names: AST_Lookup) -> None:
global fpgaSuffix
tmpSpName = "Convert_From_%s_To_%s_In_%s_%s" % \
(encoding.lower(),
self.CleanNameAsADAWants(nodeTypename),
......@@ -378,7 +391,7 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
(subProgram._id + "." + subProgramImplementation, self.supportedEncodings, encoding)) # pragma: no cover
self.C_HeaderFile.write(
"int %s(void *pBuffer, size_t iBufferSize);\n" % tmpSpName)
"int %s%s(void *pBuffer, size_t iBufferSize);\n" % (tmpSpName, fpgaSuffix))
self.ADA_HeaderFile.write(
"procedure Ada_%s(pBuffer : Interfaces.C.char_array; iBufferSize : Integer);\n" % tmpSpName)
......@@ -394,7 +407,7 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.ADA_SourceFile.write(
"end Ada_%s;\n\n" % tmpSpName)
self.C_SourceFile.write(
"int %s(void *pBuffer, size_t iBufferSize)\n{\n" % tmpSpName)
"int %s%s(void *pBuffer, size_t iBufferSize)\n{\n" % (tmpSpName, fpgaSuffix))
if self.useOSS and encoding.lower() == "uper":
self.C_SourceFile.write(" int pdutype = OSS_%s_PDU;\n" % self.CleanNameAsToolWants(nodeTypename))
......@@ -513,7 +526,10 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
def OnShutdown(self, modelingLanguage: str, asnFile: str, sp: ApLevelContainer, subProgramImplementation: str, maybeFVname: str) -> None:
# Check if Function Block will exist both as SW and HW
isSwHw = subProgramImplementation.lower() == "c" and sp._fpgaConfigurations is not '';
global genHwDevDrv
global fpgaSuffix
global dispatcherSuffix
if modelingLanguage == "QGenAda":
self.ADA_HeaderFile.write(" procedure Execute_%s (" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
self.ADA_SourceFile.write(" procedure Execute_%s (" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
......@@ -576,23 +592,20 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
else:
# Check if Function Block will exist both as SW and HW. If yes append suffix to avoid multiple definition errors.
fpgaSuffix = ''
dispatcherSuffix = "_Brave_Dispatch"
if isSwHw:
fpgaSuffix = "_Brave_Fpga"
if genHwDevDrv:
if maybeFVname not in brave_seen:
brave_seen[maybeFVname] = 'no_init_yet';
else:
brave_seen[maybeFVname] = 'with_init_already'
if isSwHw:
self.C_HeaderFile.write("int Execute_%s();\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
if genHwDevDrv:
self.C_HeaderFile.write("int Execute_%s%s();\n" % (self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation), fpgaSuffix))
else:
self.C_HeaderFile.write("void Execute_%s();\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
if maybeFVname != "":
if not (isSwHw and maybeFVname in brave_seen and brave_seen[maybeFVname] is 'with_init_already'):
if not (genHwDevDrv and maybeFVname in brave_seen and brave_seen[maybeFVname] is 'with_init_already'):
self.C_HeaderFile.write("void init_%s%s();\n" % (self.CleanNameAsADAWants(maybeFVname), fpgaSuffix))
if isSwHw:
if genHwDevDrv:
self.C_HeaderFile.write("int %s_%s%s(" % (self.CleanNameAsADAWants(maybeFVname), self.CleanNameAsADAWants(sp._id), fpgaSuffix))
else:
self.C_HeaderFile.write("void %s_%s%s(" % (self.CleanNameAsADAWants(maybeFVname), self.CleanNameAsADAWants(sp._id), fpgaSuffix))
......@@ -609,7 +622,7 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.C_HeaderFile.write(");\n")
# Check if Function Block will exist both as SW and HW. If yes generate dispatcher function (to delegate to SW or HW).
if isSwHw:
if genHwDevDrv:
if maybeFVname != "":
self.C_HeaderFile.write("int %s_%s%s(" % (self.CleanNameAsADAWants(maybeFVname), self.CleanNameAsADAWants(sp._id), dispatcherSuffix))
else: # pragma: no cover
......@@ -625,19 +638,19 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.C_HeaderFile.write("\n#endif\n")
if isSwHw:
self.C_SourceFile.write("int Execute_%s()\n{\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
if genHwDevDrv:
self.C_SourceFile.write("int Execute_%s%s()\n{\n" % (self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation), fpgaSuffix))
else:
self.C_SourceFile.write("void Execute_%s()\n{\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
self.ExecuteBlock(modelingLanguage, asnFile, sp, subProgramImplementation, maybeFVname)
self.C_SourceFile.write("}\n\n")
if maybeFVname != "":
if not (isSwHw and maybeFVname in brave_seen and brave_seen[maybeFVname] is 'with_init_already'):
if not (genHwDevDrv and maybeFVname in brave_seen and brave_seen[maybeFVname] is 'with_init_already'):
self.C_SourceFile.write("void init_%s%s()\n" % (self.CleanNameAsADAWants(maybeFVname), fpgaSuffix))
else: # pragma: no cover
self.C_SourceFile.write("void %s_init()\n" % self.CleanNameAsADAWants(sp._id)) # pragma: no cover
if not (isSwHw and maybeFVname in brave_seen and brave_seen[maybeFVname] is 'with_init_already'):
if not (genHwDevDrv and maybeFVname in brave_seen and brave_seen[maybeFVname] is 'with_init_already'):
self.C_SourceFile.write("{\n")
self.InitializeBlock(modelingLanguage, asnFile, sp, subProgramImplementation, maybeFVname)
# self.C_SourceFile.write(" extern void InitializeGlue();\n")
......@@ -645,7 +658,7 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.C_SourceFile.write("}\n\n")
if maybeFVname != "":
if isSwHw:
if genHwDevDrv:
self.C_SourceFile.write("int %s_%s%s(" % (self.CleanNameAsADAWants(maybeFVname), self.CleanNameAsADAWants(sp._id), fpgaSuffix))
else:
self.C_SourceFile.write("void %s_%s%s(" % (self.CleanNameAsADAWants(maybeFVname), self.CleanNameAsADAWants(sp._id), fpgaSuffix))
......@@ -660,7 +673,7 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.C_SourceFile.write('void *p' + self.CleanNameAsToolWants(param._id) + ', size_t *pSize_' + self.CleanNameAsToolWants(param._id))
self.C_SourceFile.write(")\n{\n")
if isSwHw:
if genHwDevDrv:
self.C_SourceFile.write(' // Check if FPGA is ready.\n')
self.C_SourceFile.write(' extern const char globalFpgaStatus_%s[];\n' % (self.CleanNameAsADAWants(maybeFVname)))
self.C_SourceFile.write(' if(strcmp(globalFpgaStatus_%s, FPGA_READY)){\n' % (self.CleanNameAsADAWants(maybeFVname)))
......@@ -671,11 +684,12 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
for param in sp._params:
nodeTypename = param._signal._asnNodename
encoding = param._sourceElement._encoding
tmpSpName = "Convert_From_%s_To_%s_In_%s_%s" % \
tmpSpName = "Convert_From_%s_To_%s_In_%s_%s%s" % \
(encoding.lower(),
self.CleanNameAsADAWants(nodeTypename),
self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation),
self.CleanNameAsADAWants(param._id))
self.CleanNameAsADAWants(param._id),
fpgaSuffix)
if isinstance(param, InParam):
self.C_SourceFile.write(' %s(p%s, size_%s);\n' %
(tmpSpName,
......@@ -688,8 +702,8 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.CleanNameAsToolWants(param._id))) # pragma: no cover
# Do functional work
if isSwHw:
self.C_SourceFile.write(" if(Execute_%s()) return -1;\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
if genHwDevDrv:
self.C_SourceFile.write(" if(Execute_%s%s()) return -1;\n" % (self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation), fpgaSuffix))
else:
self.C_SourceFile.write(" Execute_%s();\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
......@@ -697,23 +711,24 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
for param in sp._params:
nodeTypename = param._signal._asnNodename
encoding = param._sourceElement._encoding
tmpSpName = "Convert_From_%s_To_%s_In_%s_%s" % \
tmpSpName = "Convert_From_%s_To_%s_In_%s_%s%s" % \
(self.CleanNameAsADAWants(nodeTypename),
encoding.lower(),
self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation),
param._id)
param._id,
fpgaSuffix)
if isinstance(param, InOutParam) or isinstance(param, OutParam):
self.C_SourceFile.write(' *pSize_%s = %s(p%s, %s);\n' %
(self.CleanNameAsToolWants(param._id),
tmpSpName,
self.CleanNameAsToolWants(param._id),
param._signal._asnSize))
if isSwHw:
if genHwDevDrv:
self.C_SourceFile.write(" return 0;\n")
self.C_SourceFile.write("}\n\n")
# Check if Function Block will exist both as SW and HW. If yes generate dispatcher function (to delegate to SW or HW).
if isSwHw:
if genHwDevDrv:
if maybeFVname != "":
self.C_SourceFile.write("int %s_%s%s(" % (self.CleanNameAsADAWants(maybeFVname), self.CleanNameAsADAWants(sp._id), dispatcherSuffix))
else: # pragma: no cover
......
......@@ -391,10 +391,10 @@ def ProcessCustomBackends(
else:
panic("Unexpected call of getCustomBackends...") # pragma: no cover
for si in [x for x in SystemsAndImplementations if x[2] is not None and (x[2].lower() in ["gui_ri", "gui_pi", "vhdl"] or (x[2].lower() == "c" and len(x)>4 and x[4] is not ''))]:
for si in [x for x in SystemsAndImplementations if x[2] is not None and (x[2].lower() in ["gui_ri", "gui_pi", "vhdl"] or ((x[2].lower() == "c" or x[2].lower() == "simulink") and len(x)>4 and x[4] is not ''))]:
# We do, start the work
spName, sp_impl, lang, maybeFVname = si[0], si[1], si[2], si[3]
if si[2].lower() == "c" and len(si)>4 and si[4] is not '':
if (si[2].lower() == "c" or si[2].lower() == "simulink") and len(si)>4 and si[4] is not '':
lang = "vhdl"
sp = commonPy.aadlAST.g_apLevelContainers[spName]
if len(sp._params) == 0:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment