last = genDegree for i in range(0, last + 1): if (i == last) and (generator[i] == "1"): generatorString.append("1") elif (i == last - 1) and (generator[i] == "1"): generatorString.append("x") elif (generator[i] == "1"): generatorString.append("x^{" + str(last - i) + "}") generatorString = "+".join(generatorString) clockCycles = msgLen + 3 #clock cycles after which CRC has to be valid exampleMSG = Bits(uint=randrange(0, 2**msgLen), length=msgLen).bin exampleCRC = genCRC(exampleMSG, generator) ########################################### # SET PARAMETERS FOR DESCRIPTION TEMPLATE # ########################################### paramsDesc.update({ "CRCWIDTH": str(genDegree), "GENSTRING": generatorString, "MSGLEN": str(msgLen), "GENDEG": str(genDegree), "GENBIN": "".join(generator), "CLOCKCYCLES": clockCycles, "EXAMPLEMSG": exampleMSG, "EXAMPLECRC": exampleCRC }) paramsDesc.update({"TASKNR": str(taskNr), "SUBMISSIONEMAIL": submissionEmail})
msgLen, genDegree, generator = taskParameters.split('|') crcWidth=len(generator)-1 msgLen=int(msgLen) #print(str(msgLen)+" "+str(genDegree)+" " +str(generator)+" "+genString) ########################################## ######## GENERATE THE TESTVECTORS ######## ########################################## numVectors = randrange(10,20); testVectors=[] for i in range(0,numVectors): msg= Bits(uint=randrange(0,2**msgLen),length=msgLen).bin; crc= genCRC(msg,generator) testVectors.append('("{0}","{1}")'.format(msg,crc)) for i in range(numVectors-1): testVectors[i]+="," testPattern=("\n"+12*" ").join(testVectors) #format and join ########################################## ## SET PARAMETERS FOR TESTBENCH TEMPLATE # ########################################## params.update({"CRCWIDTH":crcWidth,"MSGLEN":msgLen,"TESTPATTERN":testPattern}) ############################ ## FILL TESTBENCH TEMPLATE #
msgLen, genDegree, generator = taskParameters.split('|') crcWidth = len(generator) - 1 msgLen = int(msgLen) #print(str(msgLen)+" "+str(genDegree)+" " +str(generator)+" "+genString) ########################################## ######## GENERATE THE TESTVECTORS ######## ########################################## numVectors = randrange(10, 20) testVectors = [] for i in range(0, numVectors): msg = Bits(uint=randrange(0, 2**msgLen), length=msgLen).bin crc = genCRC(msg, generator) testVectors.append('("{0}","{1}")'.format(msg, crc)) for i in range(numVectors - 1): testVectors[i] += "," testPattern = ("\n" + 12 * " ").join(testVectors) #format and join ########################################## ## SET PARAMETERS FOR TESTBENCH TEMPLATE # ########################################## params.update({ "CRCWIDTH": crcWidth, "MSGLEN": msgLen, "TESTPATTERN": testPattern,
last=genDegree for i in range(0,last+1): if (i==last) and (generator[i]=="1"): generatorString.append("1") elif (i==last-1) and (generator[i]=="1"): generatorString.append("x") elif (generator[i]=="1") : generatorString.append("x^{"+str(last-i)+"}") generatorString= "+".join(generatorString) clockCycles=msgLen+3 #clock cycles after which CRC has to be valid exampleMSG=Bits(uint=randrange(0,2**msgLen),length=msgLen).bin exampleCRC=genCRC(exampleMSG,generator) ########################################### # SET PARAMETERS FOR DESCRIPTION TEMPLATE # ########################################### paramsDesc.update({"CRCWIDTH":str(genDegree),"GENSTRING":generatorString,"MSGLEN":str(msgLen),"GENDEG":str(genDegree),"GENBIN":"".join(generator),"CLOCKCYCLES":clockCycles,"EXAMPLEMSG":exampleMSG,"EXAMPLECRC":exampleCRC}) paramsDesc.update({"TASKNR":str(taskNr),"SUBMISSIONEMAIL":submissionEmail}) ############################# # FILL DESCRIPTION TEMPLATE # ############################# filename ="templates/task_description_template.tex" with open (filename, "r") as template_file: data=template_file.read() filename ="tmp/desc_{0}_Task{1}.tex".format(userId,taskNr)