Commit ab4607d6 authored by Tiago Jorge's avatar Tiago Jorge
Browse files

Update BRAVE device driver to check for FPGA status (done per Function) and return error.

parent d7ab3529
......@@ -427,7 +427,10 @@ class VHDLGlueGenerator(SynchronousToolGlueGeneratorGeneric[List[int], List[int]
#define BASE_ADDR 0x2000
#define FPGA_READY "ready"
#define FPGA_RECONFIGURING "reconfiguring"
#define FPGA_ERROR "error"
#define FPGA_DISABLED "disabled"
#ifdef _WIN32
......@@ -516,18 +519,30 @@ static void ErrorHandler(
self.C_SourceFile.write(" }*/\n")
# def ExecuteBlock(self, modelingLanguage, asnFile, sp, subProgramImplementation, maybeFVname):
def ExecuteBlock(self, unused_modelingLanguage: str, unused_asnFile: str, sp: ApLevelContainer, unused_subProgramImplementation: str, unused_maybeFVname: str) -> None:
def ExecuteBlock(self, unused_modelingLanguage: str, unused_asnFile: str, sp: ApLevelContainer, unused_subProgramImplementation: str, maybeFVname: str) -> None:
self.C_SourceFile.write(" unsigned char flag = 0;\n\n")
self.C_SourceFile.write(" // Now that the parameters are passed inside the FPGA, run the processing logic\n")
self.C_SourceFile.write(' /*\n')
self.C_SourceFile.write(' Check if FPGA is ready.\n')
self.C_SourceFile.write(' */\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)))
self.C_SourceFile.write(' return -1;\n')
self.C_SourceFile.write(' }\n')
#self.C_SourceFile.write(" ZestSC1WriteRegister(g_Handle, BASE_ADDR + %s, (unsigned char)1);\n" %
# hex(int(VHDL_Circuit.lookupSP[sp._id]._offset)))
self.C_SourceFile.write(" while (!flag) {\n")
self.C_SourceFile.write(" // Wait for processing logic to complete\n")
#self.C_SourceFile.write(" ZestSC1ReadRegister(g_Handle, BASE_ADDR + %s, &flag);\n" %
# hex(int(VHDL_Circuit.lookupSP[sp._id]._offset)))
self.C_SourceFile.write(" flag = 1; // a dummy BRAVE always work\n")
self.C_SourceFile.write(" }\n\n")
self.C_SourceFile.write(' return 0;\n')
# pylint: disable=no-self-use
class MapASN1ToVHDLCircuit(RecursiveMapperGeneric[str, str]):
......
......@@ -578,10 +578,16 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
if subProgramImplementation.lower() == "c" and sp._fpgaConfigurations is not '':
fpgaSuffix = "_Brave_Fpga"
self.C_HeaderFile.write("void Execute_%s();\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
if subProgramImplementation.lower() == "c" and sp._fpgaConfigurations is not '':
self.C_HeaderFile.write("asn1SccMyInteger Execute_%s();\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
else:
self.C_HeaderFile.write("void Execute_%s();\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
if maybeFVname != "":
self.C_HeaderFile.write("void init_%s%s();\n" % (self.CleanNameAsADAWants(maybeFVname), fpgaSuffix))
self.C_HeaderFile.write("void %s_%s%s(" % (self.CleanNameAsADAWants(maybeFVname), self.CleanNameAsADAWants(sp._id), fpgaSuffix))
if subProgramImplementation.lower() == "c" and sp._fpgaConfigurations is not '':
self.C_HeaderFile.write("asn1SccMyInteger %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))
else: # pragma: no cover
self.C_HeaderFile.write("void %s_init%s();\n" % (self.CleanNameAsADAWants(sp._id), fpgaSuffix)) # pragma: no cover
self.C_HeaderFile.write("void %s%s(" % (self.CleanNameAsADAWants(sp._id), fpgaSuffix)) # pragma: no cover
......@@ -611,7 +617,10 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.C_HeaderFile.write("\n#endif\n")
self.C_SourceFile.write("void Execute_%s()\n{\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
if subProgramImplementation.lower() == "c" and sp._fpgaConfigurations is not '':
self.C_SourceFile.write("asn1SccMyInteger Execute_%s()\n{\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
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")
......@@ -625,7 +634,10 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
# self.C_SourceFile.write(" InitializeGlue();\n")
self.C_SourceFile.write("}\n\n")
if maybeFVname != "":
self.C_SourceFile.write("void %s_%s%s(" % (self.CleanNameAsADAWants(maybeFVname), self.CleanNameAsADAWants(sp._id), fpgaSuffix))
if subProgramImplementation.lower() == "c" and sp._fpgaConfigurations is not '':
self.C_SourceFile.write("asn1SccMyInteger %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))
else: # pragma: no cover
self.C_SourceFile.write("void %s(" % self.CleanNameAsADAWants(sp._id)) # pragma: no cover
for param in sp._params:
......@@ -658,7 +670,10 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.CleanNameAsToolWants(param._id))) # pragma: no cover
# Do functional work
self.C_SourceFile.write(" Execute_%s();\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
if subProgramImplementation.lower() == "c" and sp._fpgaConfigurations is not '':
self.C_SourceFile.write(" if(Execute_%s()) return -1;\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
else:
self.C_SourceFile.write(" Execute_%s();\n" % self.CleanNameAsADAWants(sp._id + "_" + subProgramImplementation))
# Encode outputs
for param in sp._params:
......@@ -675,6 +690,8 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
tmpSpName,
self.CleanNameAsToolWants(param._id),
param._signal._asnSize))
if subProgramImplementation.lower() == "c" and sp._fpgaConfigurations is not '':
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).
......@@ -702,8 +719,8 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.C_SourceFile.write(' while( fConfig != NULL ) {\n')
self.C_SourceFile.write(' if(!strcmp(p_szGlobalState, fConfig)){\n')
self.C_SourceFile.write(' // delegate to HW\n')
self.C_SourceFile.write(' printf("[###### Dispatcher ######] Delegating to HW ... (to be implemented) \\n");\n')
self.C_SourceFile.write(" %s_%s%s(" % (self.CleanNameAsADAWants(maybeFVname), self.CleanNameAsADAWants(sp._id), fpgaSuffix))
self.C_SourceFile.write(' printf("[ <-?-> <-?-> <-?-> %s Dispatcher <-?-> <-?-> <-?-> ] Delegating to HW ... (to be implemented) \\n");\n' % (self.CleanNameAsADAWants(maybeFVname)))
self.C_SourceFile.write(" if(%s_%s%s(" % (self.CleanNameAsADAWants(maybeFVname), self.CleanNameAsADAWants(sp._id), fpgaSuffix))
for param in sp._params:
if param._id != sp._params[0]._id:
self.C_SourceFile.write(', ')
......@@ -711,13 +728,17 @@ class SynchronousToolGlueGeneratorGeneric(Generic[TSource, TDestin]):
self.C_SourceFile.write('p' + self.CleanNameAsToolWants(param._id) + ', size_' + self.CleanNameAsToolWants(param._id))
else:
self.C_SourceFile.write('p' + self.CleanNameAsToolWants(param._id) + ', pSize_' + self.CleanNameAsToolWants(param._id))
self.C_SourceFile.write(");\n")
self.C_SourceFile.write(")){\n")
self.C_SourceFile.write(' // HW error, return 2\n')
self.C_SourceFile.write(' printf("[ <-?-> <-?-> <-?-> %s Dispatcher <-?-> <-?-> <-?-> ] HW error!\\n");\n' % (self.CleanNameAsADAWants(maybeFVname)))
self.C_SourceFile.write(' return 2;\n')
self.C_SourceFile.write(' }\n')
self.C_SourceFile.write(' // delegated to HW, return 0\n')
self.C_SourceFile.write(' return 0;\n')
self.C_SourceFile.write(' }\n')
self.C_SourceFile.write(' fConfig = strtok(NULL, "_");\n')
self.C_SourceFile.write(' }\n')
self.C_SourceFile.write(' printf("[###### Dispatcher ######] Delegating to SW ...\\n");\n')
self.C_SourceFile.write(' printf("[ <-?-> <-?-> <-?-> %s Dispatcher <-?-> <-?-> <-?-> ] Delegating to SW ...\\n");\n' % (self.CleanNameAsADAWants(maybeFVname)))
self.C_SourceFile.write(' // delegate to SW, return 1\n')
self.C_SourceFile.write(' return 1;\n')
self.C_SourceFile.write("}\n\n")
......
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