Commit 33254a7d authored by Jan Pospisil's avatar Jan Pospisil

fixed integer division in DAC functions; added errors report in SV trace debug;…

fixed integer division in DAC functions; added errors report in SV trace debug; added Enable/Disable and Start/Stop functions
parent 6778f778
......@@ -21,7 +21,7 @@ class ConColors:
m = encoreio.Module.get_instance('fmc_fpg', 0)
WB_DEBUG = True
WB_DEBUG_2_SV = True
WB_DEBUG_2_SV = False
WB_DEBUG_2_SV_FILE = 'wb_trace.svh'
###################################################################
......@@ -30,7 +30,9 @@ WB_DEBUG_2_SV_FILE = 'wb_trace.svh'
if WB_DEBUG_2_SV:
WB_DEBUG_2_SV_FP = open(WB_DEBUG_2_SV_FILE, 'w')
WB_DEBUG_2_SV_FP.write('uint32_t dataOut; // how to not-to-use output port from task?\n\n')
WB_DEBUG_2_SV_FP.write('uint32_t dataOut;\n')
WB_DEBUG_2_SV_FP.write('int errors = 0;\n')
WB_DEBUG_2_SV_FP.write('\n')
###################################################################
## WishBone access overlay
......@@ -43,7 +45,10 @@ def WbRead(register):
if WB_DEBUG_2_SV:
address = int(m[register]['offset'], 16)
WB_DEBUG_2_SV_FP.write('WbRead('+str(address)+', dataOut, "WB_READ: '+register+':");\n')
WB_DEBUG_2_SV_FP.write('assert (dataOut == '+str(result)+') else $error("WB_READ different, result should be '+hex(int(result))+'!");\n')
WB_DEBUG_2_SV_FP.write('assert (dataOut == '+str(result)+') else begin\n')
WB_DEBUG_2_SV_FP.write(' $error("WB_READ different, result should be '+hex(int(result))+'!");\n')
WB_DEBUG_2_SV_FP.write(' errors = errors + 1;\n')
WB_DEBUG_2_SV_FP.write('end\n')
return result
def WbWrite(register, data):
......@@ -70,7 +75,10 @@ def WbReadMulti(register, start = 0, to = -1):
to = int(m[register]['depth'], 16)
for i in range(start, to):
WB_DEBUG_2_SV_FP.write('WbRead('+str(address+i*4)+', dataOut, "WB_READ_MULTI: '+register+'['+str(i)+']:");\n')
WB_DEBUG_2_SV_FP.write('assert (dataOut == '+str(result[i])+') else $error("WB_READ_MULTI different, result should be '+hex(int(result[i]))+'!");\n')
WB_DEBUG_2_SV_FP.write('assert (dataOut == '+str(result[i])+') else begin\n')
WB_DEBUG_2_SV_FP.write(' $error("WB_READ_MULTI different, result should be '+hex(int(result[i]))+'!");\n')
WB_DEBUG_2_SV_FP.write(' errors = errors + 1;\n')
WB_DEBUG_2_SV_FP.write('end\n')
return result
def WbWriteMulti(register, data, start = 0, to = -1):
......@@ -196,7 +204,7 @@ def SelectClock(clock):
def SetTriggerThreshold(voltage):
vdd = 5
bits = 16
code = int((voltage/vdd) * (2**bits))
code = int((voltage/float(vdd)) * (2**bits))
code &= (2**bits)-1
WbWrite('trig_threshold', code)
......@@ -204,8 +212,8 @@ def SetTriggerThreshold(voltage):
def SetVcxoFrequency(compensation):
vdd = 3.3
bits = 16
voltage = vdd * (compensation + 1) / 2
code = int((voltage/5) * (2**bits))
voltage = vdd * (compensation + 1) / 2.0
code = int((voltage/float(5)) * (2**bits))
code &= (2**bits)-1
WbWrite('vcxo_voltage', code)
......@@ -307,6 +315,28 @@ def Control():
PrintBit(control, 8, 'LEDs', 'blinking', 'normal operation')
PrintBit(control, 9, 'AD9512', 'in reset', 'running')
def Enable(channel):
channel -= 1
channel %= 2
WbSetBits('control', 0x4<<channel, 0x4<<channel) # set output enable
def Disable(channel):
channel -= 1
channel %= 2
WbSetBits('control', 0x4<<channel, 0) # set output disable
def Start(channel):
channel -= 1
channel %= 2
channel *= 2
WbSetBits('control', 0x30<<channel, 0x10<<channel) # set mode CONT.
def Stop(channel):
channel -= 1
channel %= 2
channel *= 2
WbSetBits('control', 0x30<<channel, 0) # set mode STOP
###################################################################
## Test functions
###################################################################
......@@ -315,7 +345,7 @@ def Init():
WbWrite('control', 0)
SpiInit()
Ad9512Init()
SetTriggerThreshold(1)
SetTriggerThreshold(0.5)
SelectClock(0)
SetVcxoFrequency(-0.2105) # 125.0000 MHz
ClearMemory(0, '*')
......@@ -328,16 +358,20 @@ def TestPulse(channel = 1):
start = 5
length = 20
stop = start + length
CreatePulse(channel, start + 2*channel, stop + 2*channel)
start += 1
CreatePulse(channel, start + 2*channel, stop + 2*channel)
start += 1
CreatePulse(channel, start + 2*channel, stop + 2*channel)
start += 1
CreatePulse(channel, start + 2*channel, stop + 2*channel)
start += 1
CreatePulse(channel, start + 2*channel, stop + 2*channel)
# CreatePulse(channel, 0, 0, 1)
# CreatePulse(channel, start + 2*channel, stop + 2*channel)
# start += 1
# CreatePulse(channel, start + 2*channel, stop + 2*channel)
# start += 1
# CreatePulse(channel, start + 2*channel, stop + 2*channel)
# start += 1
# CreatePulse(channel, start + 2*channel, stop + 2*channel)
# start += 1
# CreatePulse(channel, start + 2*channel, stop + 2*channel)
CreatePulse(channel, 10, 20)
CreatePulse(channel, 11, 21)
CreatePulse(channel, 12, 22)
CreatePulse(channel, 13, 23)
CreatePulse(channel, 14, 24)
# CreatePulse(channel, 5, 10)
# CreatePulse(channel, 25, 30)
......@@ -345,12 +379,9 @@ def TestPulse(channel = 1):
WbWrite('ch'+str(channel)+'_delay_set', 100)
WbWrite('ch'+str(channel)+'_delay_res', 500)
# start channel
channel -= 1
channel %= 2
WbSetBits('control', 0x4<<channel, 0x4<<channel) # set output enable
channel *= 2
WbSetBits('control', 0x30<<channel, 0x10<<channel) # set mode CONT.
Enable(channel)
Start(channel)
Init()
Control()
......@@ -359,3 +390,12 @@ TestPulse(1)
# TestPulse(2)
Control()
Status()
###################################################################
## debug ending
###################################################################
if WB_DEBUG_2_SV:
WB_DEBUG_2_SV_FP.write('\n')
WB_DEBUG_2_SV_FP.write('$display("Error count: %0d\\n", errors);\n')
WB_DEBUG_2_SV_FP.close()
Markdown is supported
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