#%TITLE% CUB.mac
#
#%NAME% CUB / PUDS utility functions and macros
#
#%CATEGORY% Other hardware, Generic I/O
#
#%DESCRIPTION%
# Set of primary functions and macros to be used to control and
# access CUB and PUDS mezzanines
#%SETUP%
# TODO - to be documented
#%LOG%
# $Revision: 1.1 $
#
# $Log: CUB.mac,v $
# Revision 1.1 2008/02/27 16:27:52 domingue
# Initial revision
#
#
# $Date: 2008/02/27 16:27:52 $
# $Source: /segfs/bliss/source/spec/macros/RCS/CUB.mac,v $
#%END%
#===============================================================
# bagdad:/users/blissadm/local/spec/macros % ll CUB.mac
# -rw-r--r-- 1 homsrego bliss 2167 Jun 19 13:10 CUB.mac
#===============================================================
#===============================================================
#===============================================================
#%UU%
#%MDESC%
#MACRO: print the defined device server functions for the device
#%END%
def cubFuncs'{
local val
if($# != 0) {
p "usage: cubFuncs"
exit
}
val = esrf_io(CUB_ARR["dev"],"?")
printf("esrf_io return [%d]\n", val)
}'
#===============================================================
#===============================================================
#%UU% <device>
#%MDESC%
#MACRO: set the global variable with <device> value
#%END%
def cubInit'{
global CUB_ARR
if($# != 1) {
p "usage: cubInit <device>"
exit
}
CUB_ARR["dev"] = "$1"
printf("--- cubInit: set CUB_ARR[\"dev\"] [%s]\n", CUB_ARR["dev"]);
#--------- timeout to load (seconds)
CUB_ARR["timeoutLoad"] = 20
CUB_ARR["BITdir"] = "/segfs/linux/csel/hard/puds/BIT"
}'
#===============================================================
#===============================================================
#%IU% (<bit filename>)
#%MDESC%
#MACRO: get complete path-filename of the bit file
#%END%
def cub_get_bit_path_filename(filename)'{
return sprintf("%s/%s", CUB_ARR["BITdir"], filename)
}'
#===============================================================
#===============================================================
#%IU% (seg, addr)
#%MDESC%
#FUNCTION: returns the 32 bit register value at <seg> space and <addr> position
#%END%
def cub_r32(seg, addr)'{
local myp val
myp[0] = seg
myp[1] = addr
val = esrf_io(CUB_ARR["dev"],"DevReadReg32",myp)
return val
}'
#===============================================================
#===============================================================
#%IU% (seg, addr)
#%MDESC%
#FUNCTION: returns the 16 bit register value at <seg> space and <addr> position
#%END%
def cub_r16(seg, addr)'{
local myp val
myp[0] = seg
myp[1] = addr
val = esrf_io(CUB_ARR["dev"],"DevReadReg16",myp)
return val
}'
#===============================================================
#===============================================================
#%IU% (seg, addr)
#%MDESC%
#FUNCTION: returns the 8 bit register value at <seg> space and <addr> position
#%END%
def cub_r8(seg, addr)'{
local myp val
myp[0] = seg
myp[1] = addr
val = esrf_io(CUB_ARR["dev"],"DevReadReg8",myp)
return val
}'
#===============================================================
#===============================================================
#%UU% <seg> <addr>
#%MDESC%
#MACRO: print the 32 bit register value at <seg> space and <addr> position
#%END%
def cubR32'{
local myp val
if($# != 2) {
p "usage: cubR32 <segment [1,2]> <index [0..255]>"
exit
}
myp[0] = $1
myp[1] = $2
val = esrf_io(CUB_ARR["dev"],"DevReadReg32",myp)
printf("--- cubR32: seg: [%d] addr: [0x%x] val: [0x%08x]\n", \
myp[0], myp[1], val)
}'
#===============================================================
#===============================================================
#%UU% <seg> <addr>
#%MDESC%
#MACRO: print the 16 bit register value at <seg> space and <addr> position
#%END%
def cubR16'{
local myp val
if($# != 2) {
p "usage: cubR16 <segment [1,2]> <index [0..255]>"
exit
}
myp[0] = $1
myp[1] = $2
val = esrf_io(CUB_ARR["dev"],"DevReadReg16",myp)
printf("--- cubR16: seg: [%d] addr: [0x%x] val: [0x%04x]\n", \
myp[0], myp[1], val)
}'
#===============================================================
#===============================================================
#%UU% <seg> <addr>
#%MDESC%
#MACRO: print the 8 bit register value at <seg> space and <addr> position
#%END%
def cubR8'{
local myp val
if($# != 2) {
p "usage: cubR8 <segment [1,2]> <index [0..255]>"
exit
}
myp[0] = $1
myp[1] = $2
val = esrf_io(CUB_ARR["dev"],"DevReadReg8",myp)
printf("--- cubR8: seg: [%d] addr: [0x%x] val: [0x%02x]\n", \
myp[0], myp[1], val)
}'
#===============================================================
#===============================================================
#%UU% <seg> <addr> <val>
#%MDESC%
#MACRO: write the value <val> in the 32 bit register at <seg> space
#and <addr> position
#%END%
def cubW32'{
local myp
if($# != 3) {
p "usage: cubW32 <segment [1,2]> <index [0..255]> <value>"
exit
}
myp[0] = $1
myp[1] = $2
myp[2] = $3
esrf_io(CUB_ARR["dev"],"DevWriteReg32",myp)
}'
#===============================================================
#===============================================================
#%UU% <seg> <addr> <val>
#%MDESC%
#MACRO: write the value <val> in the 16 bit register at <seg> space
#and <addr> position
#%END%
def cubW16'{
local myp
if($# != 3) {
p "usage: cubW16 <segment [1,2]> <index [0..255]> <value>"
exit
}
myp[0] = $1
myp[1] = $2
myp[2] = $3
esrf_io(CUB_ARR["dev"],"DevWriteReg16",myp)
}'
#===============================================================
#===============================================================
#%UU% <seg> <addr> <val>
#%MDESC%
#MACRO: write the value <val> in the 8 bit register at <seg> space
#and <addr> position
#%END%
def cubW8'{
local myp
if($# != 3) {
p "usage: cubW8 <segment [1,2]> <index [0..255]> <value>"
exit
}
myp[0] = $1
myp[1] = $2
myp[2] = $3
esrf_io(CUB_ARR["dev"],"DevWriteReg8",myp)
}'
#===============================================================
#===============================================================
#%UU%
#%MDESC%
#MACRO: erase all FPGA's, set sensitive bit to 0
#(segment 2, address 4, bit 23)
#%END%
def cubReset'{
if($# != 0) {
p "usage: cubReset "
exit
}
esrf_io(CUB_ARR["dev"],"DevReset")
}'
#===============================================================
#===============================================================
#%IU% (seg, addr, val)
#%MDESC%
#FUNCTION: writes the value <val> in the 32 bit register at <seg> space
#and <addr> position. returns the result of esrf_io operation.
#%END%
def cub_w32(seg, addr, val)'{
local myp
myp[0] = seg
myp[1] = addr
myp[2] = val
return esrf_io(CUB_ARR["dev"],"DevWriteReg32",myp)
}'
#===============================================================
#===============================================================
#%IU% (seg, addr, val)
#%MDESC%
#FUNCTION: writes the value <val> in the 16 bit register at <seg> space
#and <addr> position. returns the result of esrf_io operation.
#%END%
def cub_w16(seg, addr, val)'{
local myp
myp[0] = seg
myp[1] = addr
myp[2] = val
return esrf_io(CUB_ARR["dev"],"DevWriteReg16",myp)
}'
#===============================================================
#===============================================================
#%IU% (seg, addr, val)
#%MDESC%
#FUNCTION: writes the value <val> in the 8 bit register at <seg> space
#and <addr> position. returns the result of esrf_io operation.
#%END%
def cub_w8(seg, addr, val)'{
local myp
myp[0] = seg
myp[1] = addr
myp[2] = val
return esrf_io(CUB_ARR["dev"],"DevWriteReg8",myp)
}'
#===============================================================
#===============================================================
#%IU% (val)
#%MDESC%
#FUNCTION: sets the remote procedure call (RPC) of SPEC the
#value <val> in seconds. return the value set in seconds.
#%END%
def cub_set_timeout(val) '{
return esrf_io(CUB_ARR["dev"],"timeout", val)
}'
#===============================================================
#===============================================================
#%IU% ()
#%MDESC%
#FUNCTION: restore the remote procedure call (RPC) of SPEC the default
#value. returns the default value set in seconds.
#%END%
def cub_restore_timeout() '{
return esrf_io(CUB_ARR["dev"],"timeout", 0)
}'
#===============================================================
#===============================================================
#%UU% <bit file>
#%MDESC%
#MACRO: loads the CUB Virtex file <bit file> to FPGA
#%END%
def cubLoadVirtex'{
local bitFile
if ($# != 1) {
p "usage: cubLoadVirtex <bit file>"
exit
}
bitFile = cub_get_bit_path_filename("$1")
printf("--- cubLoadVirtex: [%s]\n", bitFile);
cub_set_timeout( CUB_ARR["timeoutLoad"] )
esrf_io(CUB_ARR["dev"],"DevLoadVirtex", bitFile)
cub_restore_timeout()
}'
#===============================================================
#===============================================================
#%UU% <list file>
#%MDESC%
#MACRO: loads the PUDS Spartan files <list file> to FPGA. The <list file>
#contains the complete path-filename of the files to be loaded, one
#per line
#%END%
def cubLoadSpartanList'{
local bitFileList
if ($# != 1) {
p "usage: cubLoadSpartanList <list file>"
exit
}
bitFileList = cub_get_bit_path_filename("$1")
printf("--- cubLoadSpartanList: [%s]\n", bitFileList);
cub_set_timeout( CUB_ARR["timeoutLoad"] )
esrf_io(CUB_ARR["dev"],"DevLoadSpartanList",bitFileList)
cub_restore_timeout()
}'
#===============================================================
#===============================================================
#%UU% <bit file>
#%MDESC%
#MACRO: loads the PUDS Spartan file <bit file> to FPGA.
#%END%
def cubLoadSpartan'{
local bitFile
if ($# != 1) {
p "usage: cubLoadSpartan <bit file>"
exit
}
bitFile = cub_get_bit_path_filename("$1")
printf("--- cubLoadSpartan: [%s]\n", bitFile);
cub_set_timeout( CUB_ARR["timeoutLoad"] )
esrf_io(CUB_ARR["dev"],"DevLoadSpartan",bitFile)
cub_restore_timeout()
}'
#===============================================================
#===============================================================
#%UU%
#%MDESC%
#MACRO: test macro: loads a predefined CUB Virtex bitfile and reads
#some registers
#%END%
def cubTest'{
if($# != 0) {
p "usage: cubTest"
exit
}
cubInit MCD/cub/1
p "--- Loading Virtex"
# cubLoadVirtex /segfs/dserver/classes++/c353/virtex/c353.bit
cubLoadVirtex "cub_puds_i0_0.bit"
printf("--- loading Virtex finished\n")
cubR32 1 0
cubR16 1 0
cubR8 1 0
cubR32 1 4
cubR16 1 4
cubR8 1 4
}'
#===============================================================
#===============================================================
#%IU% (seg, addr, val)
#%MDESC%
#FUNCTION: test function: writes and read a value <val> in the 32 bit register
#at <seg> space and <addr> position. print the results. return if there
#was a discrepance (1 -> error)
#%END%
def cub_test_rw32_1(seg, addr, val) '{
local valR, retval
cub_w32(seg, addr, val)
valR = cub_r32(seg, addr)
# if(val == valR) return 0
printf("--- cub_test_rw32_1: seg: [%d] addr: [0x%x] val: [0x%08x] ", \
seg, addr, val)
if(val != valR) {
printf("[0x%08x]\n", valR)
retval = 1
} else {
printf("OK\n")
retval = 0
}
return retval
}'
#===============================================================
#===============================================================
#%IU% (seg, addr, val)
#%MDESC%
#FUNCTION: test function: writes and read a value <val> in the 16 bit register
#at <seg> space and <addr> position. print the results. return if there
#was a discrepance (1 -> error)
#%END%
def cub_test_rw16_1(seg, addr, val) '{
local valR, retval
cub_w16(seg, addr, val)
valR = cub_r16(seg, addr)
# if(val == valR) return 0
printf("--- cub_test_rw16_1: seg: [%d] addr: [0x%x] val: [0x%04x] ", \
seg, addr, val)
if(val != valR) {
printf("[0x%04x]\n", valR)
retval = 1
} else {
printf("OK\n")
retval = 0
}
return retval
}'
#===============================================================
#===============================================================
#%IU% (seg, addr, val)
#%MDESC%
#FUNCTION: test function: writes and read a value <val> in the 8 bit register
#at <seg> space and <addr> position. print the results. return if there
#was a discrepance (1 -> error)
#%END%
def cub_test_rw8_1(seg, addr, val) '{
local valR, retval
cub_w8(seg, addr, val)
valR = cub_r8(seg, addr)
# if(val == valR) return 0
printf("--- cub_test_rw8_1: seg: [%d] addr: [0x%x] val: [0x%02x] ", \
seg, addr, val)
if(val != valR) {
printf("[0x%02x]\n", valR)
retval = 1
} else {
printf("OK\n")
retval = 0
}
return retval
}'
#===============================================================
#===============================================================
#%IU% (seg, addr)
#%MDESC%
#FUNCTION: test function: perform a W/R bit-shifting test in the 32 bit
#register at <seg> space and <addr> position. print the results.
#return if there was a discrepance (1 -> error)
#%END%
def cub_test_rw32(seg, addr) '{
local val, i, retval
val = 1
retval = 0
for(i = 0 ; i < 32; i++) {
retval |= cub_test_rw32_1(seg, addr, val) ;
val = val << 1
sleep(1)
}
return retval
}'
#===============================================================
#===============================================================
#%IU% (seg, addr)
#%MDESC%
#FUNCTION: test function: perform a W/R bit-shifting test in the 16 bit
#register at <seg> space and <addr> position. print the results.
#return if there was a discrepance (1 -> error)
#%END%
def cub_test_rw16(seg, addr) '{
local val, i, retval
val = 1
retval = 0
for(i = 0 ; i < 16; i++) {
retval |= cub_test_rw16_1(seg, addr, val) ;
val = val << 1
sleep(1)
}
return retval
}'
#===============================================================
#===============================================================
#%IU% (seg, addr)
#%MDESC%
#FUNCTION: test function: perform a W/R bit-shifting test in the 8 bit
#register at <seg> space and <addr> position. print the results.
#return if there was a discrepance (1 -> error)
#%END%
def cub_test_rw8(seg, addr) '{
local val, i, retval
val = 1
retval = 0
for(i = 0 ; i < 8; i++) {
retval |= cub_test_rw8_1(seg, addr, val) ;
val = val << 1
sleep(1)
}
return retval
}'
#===============================================================
#===============================================================
#%UU%
#%MDESC%
#MACRO: test macro: loads a predefined PUDS SPARTAN bitfile list.
#%END%
def cubTestSpartanList'{
if($# != 0) {
p "usage: cubTestSpartanList"
exit
}
cubLoadSpartanList "mylist"
}'
#===============================================================
#===============================================================
#%UU%
#%MDESC%
#MACRO: test macro: loads a predefined PUDS SPARTAN bitfile.
#%END%
def cubTestSpartan'{
if($# != 0) {
p "usage: cubTestSpartan"
exit
}
cubLoadSpartan "i04_mr1.bit"
}'
#===============================================================
#===============================================================
#%UU%
#%MDESC%
#MACRO: test macro: loads a predefined CUB Virtex bitfile.
#%END%
def cubTestVirtex'{
if($# != 0) {
p "usage: cubTestVirtex "
exit
}
cubLoadVirtex "cub_puds_mi0_3.bit"
}'
#===============================================================
#===============================================================
#%UU% <str>
#%MDESC%
#MACRO: special test macro / NOT DOCUMENTED / NOT USE
#%END%
def cubHello'{
if($# != 1) {
p "usage: cubHello <str>"
exit
}
esrf_io(CUB_ARR["dev"],"DevHello", "$1")
return val
}'
#===============================================================
#===============================================================
#%UU%
#%MDESC%
#MACRO: test RW 32-bit registers
#%END%
def cubTestRW32'{
if($# != 0) {
p "usage: cubTestRW32"
exit
}
p "---"
cub_test_rw32(2, 0x20)
p "---"
cub_test_rw32(2, 0x50)
p "---"
cub_test_rw32(2, 0x54)
p "---"
cub_test_rw32(2, 0x58)
p "---"
cub_test_rw32(2, 0x5C)
p "---"
}'
#===============================================================
#===============================================================
#%UU%
#%MDESC%
#MACRO: test RW 16-bit registers
#%END%
def cubTestRW16'{
if($# != 0) {
p "usage: cubTestRW16"
exit
}
p "---"
cub_test_rw16(2, 0x20)
p "---"
cub_test_rw16(2, 0x50)
p "---"
cub_test_rw16(2, 0x54)
p "---"
cub_test_rw16(2, 0x58)
p "---"
cub_test_rw16(2, 0x5C)
p "---"
}'
#===============================================================
#===============================================================
#%UU%
#%MDESC%
#MACRO: test RW 8-bit registers
#%END%
def cubTestRW8'{
if($# != 0) {
p "usage: cubTestRW8"
exit
}
p "---"
cub_test_rw8(2, 0x20)
p "---"
cub_test_rw8(2, 0x50)
p "---"
cub_test_rw8(2, 0x54)
p "---"
cub_test_rw8(2, 0x58)
p "---"
cub_test_rw8(2, 0x5C)
p "---"
}'
#%UU%
#%MDESC% print RCS version
#%END%
def cubversion '{
local strrcs, arr, arr1
if($# != 0) {
p "--- ERROR: Usage: coilctrlversion"
exit
}
strrcs = "$RCSfile: CUB.mac,v $ $Revision: 1.1 $ $Date: 2008/02/27 16:27:52 $"
split(strrcs, arr)
split(arr["1"], arr1, ",")
printf("%s Rev %s (%s %s)\n", arr1["0"], arr["4"], arr["7"], arr["8"])
}'
#===============================================================
#===============================================================
#%MACROS%
#%IMACROS%
#%TOC%
#%AUTHOR% BLISS - ESRF (2007) rh mcd
#%END%
|