Commit 8a9dd032 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

added testing folder

parent 218fa8ff
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>multiboot</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>org.python.pydev.pythonNature</nature>
</natures>
<linkedResources>
<link>
<name>vbcp</name>
<type>2</type>
<location>/home/tstana/Projects/ctb-test/vbcp</location>
</link>
</linkedResources>
</projectDescription>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
</pydev_project>
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include vbcp/obj/subdir.mk
-include vbcp/subdir.mk
-include subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: multiboot
# Tool invocations
multiboot: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
gcc -o "multiboot" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(OBJS)$(C_DEPS)$(EXECUTABLES) multiboot
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
USER_OBJS :=
LIBS := -lrt
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
O_SRCS :=
C_SRCS :=
S_UPPER_SRCS :=
OBJ_SRCS :=
ASM_SRCS :=
OBJS :=
C_DEPS :=
EXECUTABLES :=
# Every subdirectory with source files must be described here
SUBDIRS := \
vbcp \
vbcp/obj \
. \
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../multiboot.c
OBJS += \
./multiboot.o
C_DEPS += \
./multiboot.d
# Each subdirectory must supply rules for building sources it contributes
%.o: ../%.c
@echo 'Building file: $<'
@echo 'Invoking: GCC C Compiler'
gcc -I../../vbcp -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
O_SRCS += \
/home/tstana/Projects/ctb-test/vbcp/obj/test.o
# Each subdirectory must supply rules for building sources it contributes
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
/home/tstana/Projects/ctb-test/vbcp/vbcp.c
OBJS += \
./vbcp/vbcp.o
C_DEPS += \
./vbcp/vbcp.d
# Each subdirectory must supply rules for building sources it contributes
vbcp/vbcp.o: /home/tstana/Projects/ctb-test/vbcp/vbcp.c
@echo 'Building file: $<'
@echo 'Invoking: GCC C Compiler'
gcc -I../../vbcp -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
This diff is collapsed.
This diff is collapsed.
/*
*==============================================================================
* CERN (BE-CO-HT)
* Source file for Multiboot
*==============================================================================
*
* author: Theodor Stana (t.stana@cern.ch)
*
* date of creation: 2013-09-12
*
* version: 1.0
*
* description:
*
* dependencies:
*
* references:
*
*==============================================================================
* GNU LESSER GENERAL PUBLIC LICENSE
*==============================================================================
* This source file is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version. This source is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details. You should have
* received a copy of the GNU Lesser General Public License along with this
* source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
*==============================================================================
* last changes:
* 2013-09-12 Theodor Stana t.stana@cern.ch File created
*==============================================================================
* TODO: -
*==============================================================================
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/time.h>
#include <math.h>
#include "vbcp.h"
static int vfd;
static uint64_t get_ticks()
{
struct timeval tv;
gettimeofday( &tv, NULL );
return (uint64_t) tv.tv_sec * 1000000ULL + (uint64_t) tv.tv_usec;
}
uint8_t spi_transfer(uint32_t cs, uint32_t dat)
{
int retval = 0;
vbcp_write(vfd, 4, 0x90, ((cs << 10) | 0x100) | dat);
while ( !(retval & (1<<9)) )
{
retval = vbcp_read(vfd, 4, 0x90);
}
return retval & 0xFF;
}
void flash_write(int nrbytes, uint32_t bytes, uint8_t *dat)
{
int i;
spi_transfer(0,0);
spi_transfer(1,0x06);
spi_transfer(0,0);
spi_transfer(1,0x02);
spi_transfer(1,(bytes & 0xFF0000) >> 16);
spi_transfer(1,(bytes & 0xFF00) >> 8);
spi_transfer(1,(bytes & 0xFF));
for ( i = 0; i < nrbytes; i++ )
{
spi_transfer(1,dat[i]);
}
spi_transfer(0,0);
}
void flash_read(int nrbytes, uint32_t bytes, uint8_t *dat)
{
int cnt = 0;
int i;
spi_transfer(0,0);
spi_transfer(1,0x0b);
spi_transfer(1,(bytes & 0xFF0000) >> 16);
spi_transfer(1,(bytes & 0xFF00) >> 8);
spi_transfer(1,(bytes & 0xFF));
spi_transfer(1,0);
for ( i = 0; i < nrbytes; i++ )
{
dat[i] = spi_transfer(1, 0);
}
spi_transfer(0,0);
}
void flash_serase(uint32_t bytes)
{
spi_transfer(0,0);
spi_transfer(1,0x06);
spi_transfer(0,0);
spi_transfer(1,0xD8);
spi_transfer(1,(bytes & 0xFF0000) >> 16);
spi_transfer(1,(bytes & 0xFF00) >> 8);
spi_transfer(1,(bytes & 0xFF));
spi_transfer(0,0);
}
uint8_t flash_rsr()
{
uint8_t retval;
spi_transfer(0,0);
spi_transfer(1,0x05);
retval = spi_transfer(1,0);
spi_transfer(0,0);
return retval;
}
int main()
{
uint64_t ts, tf, t0, t1;
double te[32], tw[6000];
double temean = 0,
twmean = 0;
int i = 0;
FILE *f;
char fdat[520];
uint8_t dat[256];
uint32_t x=0;
uint32_t pages = 0;
uint32_t erases = 0;
uint32_t addr = 0;
memset(dat,0,sizeof(dat));
ts = get_ticks();
vfd = vbcp_open();
if (vfd == -1) {
printf("VBCP not open!\n");
return -1;
}
t0 = get_ticks();
flash_read(256, addr, dat);
t1 = get_ticks();
for (i = 0; i < 256; i++)
{
printf("0x%02x ", dat[i]);
}
printf("\n\n");
printf("\n");
// printf("t0: %lld\n", t0);
// printf("t1: %lld\n", t1);
printf("read time : %2.6f s\n", (double)(t1 - t0) / pow(10,6));
f = fopen("conv.txt", "r");
t0 = get_ticks();
while (pages<256)
{
// while (!feof(f))
// {
printf("addr=%x\n", addr);
fgets(fdat, 520, f);
// printf("%s\n", fdat);
for (i=0;i<256;i++)
{
if (strlen(fdat) < 512 && i==strlen(fdat)/2)
break;
sscanf(&fdat[2*i], "%2hhx", &dat[i]);
// printf("%02x",dat[i]);
// printf("%d\n",strlen(fdat));
// printf("%d\n", bytes);
}
if ( addr % 0x10000 == 0 )
{
printf("erase\n");
t0 = get_ticks();
flash_serase(addr);
while ( flash_rsr() & 0x01 )
;
t1 = get_ticks();
// printf("t0: %lld\n", t0);
// printf("t1: %lld\n", t1);
printf("erase time: %2.6f s\n", (double)(t1 - t0) / pow(10,6));
te[erases] = (double)(t1 - t0) / pow(10,6);
erases++;
}
t0 = get_ticks();
flash_write(i, addr, dat);
while ( flash_rsr() & 0x01 )
;
t1 = get_ticks();
// printf("t0: %lld\n", t0);
// printf("t1: %lld\n", t1);
printf("write time: %2.6f s\n", (double)(t1 - t0) / pow(10,6));
tw[pages] = (double)(t1 - t0) / pow(10,6);
pages++;
addr += 256;
// printf("\n");
// printf("%d\n", bytes);
}
t1 = get_ticks();
fclose(f);
printf("erases: %d\n", erases);
printf("pages: %d\n", pages);
for (i = 0; i < erases; i++)
{
temean += te[i];
}
temean = temean / erases;
for (i = 0; i < pages; i++)
{
twmean += tw[i];
}
twmean = twmean / pages;
printf("mean erase time: %2.6f s\n", temean);
printf("mean write time: %2.6f s\n", twmean);
tf = get_ticks();
printf("time: %2.6f s\n", (double)(tf - ts) / pow(10,6));
vbcp_close(vfd);
return 0;
}
#===============================================================================
# CERN (BE-CO-HT)
# Register test for CONV-TTL-BLO
#===============================================================================
# author: Theodor Stana (t.stana@cern.ch)
#
# date of creation: 2013-08-13
#
# version: 1.0
#
# description:
#
# dependencies:
#
# references:
#===============================================================================
# GNU LESSER GENERAL PUBLIC LICENSE
#===============================================================================
# This source file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation; either version 2.1 of the License, or (at your
# option) any later version. This source is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with this
# source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
#===============================================================================
# last changes:
# 2013-08-13 Theodor Stana t.stana@cern.ch File created
#===============================================================================
# TODO: -
#===============================================================================
import random
import sys
import time
sys.path.append("../vbcp")
from vbcp import *
def spi_transfer(cs, dat):
retval = 0;
ctb.write(0x90, (((cs << 10) | 0x100) | dat))
while (retval & (1 << 9) == 0):
retval = ctb.read(0x90)
return retval & 0xFF
def flash_write(addr, dat):
spi_transfer(0,0)
spi_transfer(1,0x06)
spi_transfer(0,0)
spi_transfer(1,0x02)
spi_transfer(1,(addr & 0xFF0000) >> 16)
spi_transfer(1,(addr & 0xFF00) >> 8)
spi_transfer(1,(addr & 0xFF))
for i in range(len(dat)):
spi_transfer(1,dat[i])
spi_transfer(0,0)
def flash_read(addr, nrbytes):
ret = []
spi_transfer(0,0)
spi_transfer(1,0x0b)
spi_transfer(1,(addr & 0xFF0000) >> 16)
spi_transfer(1,(addr & 0xFF00) >> 8)
spi_transfer(1,(addr & 0xFF))
spi_transfer(1,0)
for i in range(nrbytes):
ret.append(spi_transfer(1,0))
spi_transfer(0,0)
return ret
def flash_serase(addr):
ret = []
spi_transfer(0,0)
spi_transfer(1,0x06)
spi_transfer(0,0)
spi_transfer(1,0xd8)
spi_transfer(1,(addr & 0xFF0000) >> 16)
spi_transfer(1,(addr & 0xFF00) >> 8)
spi_transfer(1,(addr & 0xFF))
spi_transfer(0,0)
def flash_berase():
spi_transfer(0,0)
spi_transfer(1,0x06)
spi_transfer(0,0)
spi_transfer(1,0xc7)
spi_transfer(0,0)
def flash_rsr():
spi_transfer(0,0)
spi_transfer(1,0x05)
ret = spi_transfer(1,0)
spi_transfer(0,0)
return ret
if __name__ == "__main__":
ip = "192.168.20.22" # raw_input("Crate IP? ")
user = "admin" # raw_input("Username? ")
pwd = "ADMIN" # raw_input("Password? ")
# Wait for proper slot number
while 1:
try:
slot = 4
#slot = raw_input("Slot no.? ")
#slot = int(slot)
ctb = VBCP(ip, user, pwd, slot)
break
except TypeError as e:
print "Please input a decimal slot number."
except SlotError as e:
print e.strerror
except KeyboardInterrupt:
sys.exit();
except:
print "Unexpected error: ", sys.exc_info()[0]
# Open VBCP connection
ctb.open_conn()
# Init counters
#wexcep_cnt = 0
#rexcep_cnt = 0
#mismatch_cnt = 0
# print "erasing"
#
# flash_berase()
# while (flash_rsr() & 0x01):
# pass
#
# print "done!"
# read from flash
print "BEFORE"
tr0 = time.time()
rd = flash_read(0x000000,256)
tr1 = time.time()
rd = "".join(["0x%02X " % b for b in rd])
print rd
tr2 = time.time()
rd = flash_read(0x000100,256)
tr3 = time.time()
rd = "".join(["0x%02X " % b for b in rd])
print rd
print "ERASE"
te1 = time.time()
flash_serase(0x0010)
while (flash_rsr() & 0x01):
pass
te2 = time.time()
print "erase time: %2.6f" % (te2-te1)
print "WRITE"
f = open("conv.txt",'r')
addr = 0
tdat = []
twr = []
twa = []
for fdata in f:
print addr
data = []
try:
t1 = time.time()
for i in xrange(256):
data.append(int(fdata[0:2],16))
fdata = fdata[2:]
t2 = time.time()
except ValueError:
print "reached end"
break
finally:
t3 = time.time()
flash_write(addr, data)
t4 = time.time()
while (flash_rsr() & 0x01):
pass
t5 = time.time()
addr += 256
if (addr == 256**2):
break;
tdat.append(t2-t1)
twr.append(t4-t3)
twa.append(t5-t4)
#print data
#print len(data)
# Close file handle
f.close()
print "DONE!"
print "read1 time: %2.6f" % float(tr1-tr0)
print "read2 time: %2.6f" % float(tr3-tr2)
print "data time: %2.6f" % float(sum(tdat)/len(tdat))
print "write time: %2.6f" % float(sum(twr)/len(twr)) #(t4-t3)
print "wait time: %2.6f" % float(sum(twa)/len(twa)) #(t5-t4)
# Close VBCP connection and print final values
ctb.close_conn()
#!/usr/bin/expect
log_user 0
proc transf {cs dat} {
#puts [format "writereg 4 37 %x\r\n" [expr {(($cs << 10) | 0x100 ) | $dat}]]
send [format "writereg 4 37 %x\r\n" [expr {(($cs << 10) | 0x100 ) | $dat}]]
expect "%>"
while 1 {
send "readreg 4 37\r\n"
expect "%>"
set resp [split $expect_out(buffer) "\r\n"]
set resp [lindex $resp 2]
set resp [split $resp]
set resp [lindex $resp 3]
#puts $resp
if {$resp & [expr {0x20}]} {
} else {
break
}
}
return [expr {$resp & [expr {0xFF}]}]
}
proc flse {addr} {
transf 0 0
transf 1 [expr {0x06}]
transf 0 0
transf 1 [expr {0xd8}]
transf 1 [expr {($addr & 0xFF0000) >> 16}]
transf 1 [expr {($addr & 0xFF00) >> 8}]
transf 1 [expr {($addr & 0xFF)}]
transf 0 0
}
proc flrsr {} {
transf 0 0
transf 1 [expr {0x05}]
set ret [transf 1 0]
transf 0 0
return $ret
}
proc flw {addr dat} {
transf 0 0
transf 1 [expr {0x06}]
transf 0 0
transf 1 [expr {0x02}]
transf 1 [expr {($addr & 0xFF0000) >> 16}]
transf 1 [expr {($addr & 0xFF00) >> 8}]
transf 1 [expr {($addr & 0xFF)}]
for {set i 0} {$i < 256} {incr i} {
transf 1 [lindex $dat $i]
}
transf 0 0
}
spawn telnet elma
expect "login:"
send "admin\r\n"
expect "password:"
send "ADMIN\r\n"
expect "%>"
set dat {0 1 2}
for {set i 3} {$i < 256} {incr i} {
lappend dat $i
}
puts "ERASE"
set t0 [
time {
flse 0
set wip [expr {0x01}]
while {[expr {$wip & 0x01}]} {
set wip [flrsr]
}
}
]
puts "WRITE"
set addr 0
while {[expr {$addr != [expr {256*256}]}]} {
puts $addr
set t1 [
time {
flw $addr $dat
set wip [expr {0x01}]
while {[expr {$wip & 0x01}]} {
set wip [flrsr]
}
set addr [expr {$addr + 256}]
}
]
}
send \x1D
expect "telnet>"
send "q\n"
expect eof
puts $t0
puts $t1
This diff is collapsed.
import time
import sys
import time
sys.path.append("../vbcp")
from vbcp import *
IDREG = 0x00
FWVREG = 0x04
C1IREG = 0x100
C1OREG = 0x104
C2IREG = 0x108
C2OREG = 0x10C
C3IREG = 0x110
C3OREG = 0x114
C4IREG = 0x118
C4OREG = 0x11C
C5IREG = 0x120
C5OREG = 0x124
C6IREG = 0x128
C6OREG = 0x12C
CNTRST = 0X130
CHENREG = 0x200
C1DELREG = 0x204
C2DELREG = 0x208
C3DELREG = 0x20C
C4DELREG = 0x210
C5DELREG = 0x214
C6DELREG = 0x218
C1WDTHREG = 0x21C
C2WDTHREG = 0x220
C3WDTHREG = 0x224
C4WDTHREG = 0x228
C5WDTHREG = 0x22C
C6WDTHREG = 0x230
C1FREQREG = 0x234
C2FREQREG = 0x238
C3FREQREG = 0x23C
C4FREQREG = 0x240
C5FREQREG = 0x244
C6FREQREG = 0x248
if __name__ == "__main__":
ip = "elma" # raw_input("Crate IP? ")
user = "admin" # raw_input("Username? ")
pwd = "ADMIN" # raw_input("Password? ")
# Wait for proper slot number
while 1:
try:
slot = raw_input("Slot no.? ")
slot = int(slot)
ctb = VBCP(ip, user, pwd, slot)
break
except TypeError as e:
print "Please input a decimal slot number."
except SlotError as e:
print e.strerror
except KeyboardInterrupt:
sys.exit()
except:
print "Unexpected error: ", sys.exc_info()[0]
# Open VBCP connection
ctb.open_conn()
bloid = ctb.read(0x00)
fwvers = ctb.read(0x04) & 0xFFFF
if ( bloid != 0x424c4f32 ) or ( fwvers != 0x9999 ):
print "Wrong version number (0x%04x)" % fwvers
sys.exit(1)
ctb.write(CHENREG, 0x00);
ctb.write(CNTRST, 1);
ctb.write(CNTRST, 0);
# First, setup the channel enable variable
chen = 0x00;
# Setup channel output pulse widths to 1.2us
ctb.write(C1WDTHREG, 0x96)
ctb.write(C2WDTHREG, 0x96)
ctb.write(C3WDTHREG, 0x96)
ctb.write(C4WDTHREG, 0x96)
ctb.write(C5WDTHREG, 0x96)
ctb.write(C6WDTHREG, 0x96)
# Setup channel delays and frequencies
farr = [0,0,0,0,0,0]
inp = ""
while (inp != 'y') and (inp != 'n'):
inp = raw_input("Enable channel 1? (y/n) ")
if (inp == 'y'):
chen |= (1 << 0);
freq = input(" freq (Hz): ")
farr[0] = freq
freq = (1/(8*(10**(-9))))/freq
ctb.write(C1FREQREG, int(freq))
#print freq
#print hex(int(freq))
inp = ""
while (inp != 'y') and (inp != 'n'):
inp = raw_input("Enable channel 2? (y/n) ")
if (inp == 'y'):
chen |= (1 << 1);
freq = input(" freq (Hz): ")
farr[1] = freq
freq = (1/(8*(10**(-9))))/freq
ctb.write(C2FREQREG, int(freq))
#print freq
#print hex(int(freq))
inp = ""
while (inp != 'y') and (inp != 'n'):
inp = raw_input("Enable channel 3? (y/n) ")
if (inp == 'y'):
chen |= (1 << 2);
freq = input(" freq (Hz): ")
farr[2] = freq
freq = (1/(8*(10**(-9))))/freq
ctb.write(C3FREQREG, int(freq))
#print freq
#print hex(int(freq))
inp = ""
while (inp != 'y') and (inp != 'n'):
inp = raw_input("Enable channel 4? (y/n) ")
if (inp == 'y'):
chen |= (1 << 3);
freq = input(" freq (Hz): ")
farr[3] = freq
freq = (1/(8*(10**(-9))))/freq
ctb.write(C4FREQREG, int(freq))
#print freq
#print hex(int(freq))
inp = ""
while (inp != 'y') and (inp != 'n'):
inp = raw_input("Enable channel 5? (y/n) ")
if (inp == 'y'):
chen |= (1 << 4);
freq = input(" freq (Hz): ")
farr[4] = freq
freq = (1/(8*(10**(-9))))/freq
ctb.write(C5FREQREG, int(freq))
#print freq
#print hex(int(freq))
inp = ""
while (inp != 'y') and (inp != 'n'):
inp = raw_input("Enable channel 6? (y/n) ")
if (inp == 'y'):
chen |= (1 << 5);
freq = input(" freq (Hz): ")
farr[5] = freq
freq = (1/(8*(10**(-9))))/freq
ctb.write(C6FREQREG, int(freq))
#print freq
#print hex(int(freq))
# Ask how long to run the test
print "How long would you like to run the test?"
while 1:
try:
hrs = raw_input(" hrs: ")
hrs = int(hrs)
if (hrs < 0):
raise Exception
break
except KeyboardInterrupt:
sys.exit()
except:
print " Hours must be a decimal number >= 0!"
while 1:
try:
mins = raw_input(" mins: ")
mins = int(mins)
if (mins < 0):
raise Exception
break
except KeyboardInterrupt:
sys.exit()
except:
print " Minutes must be a decimal number >= 0!"
while 1:
try:
secs = raw_input(" secs: ")
secs = int(secs)
if (secs < 0):
raise Exception
break
except KeyboardInterrupt:
sys.exit()
except:
print " Seconds must be a decimal number >= 0!"
# Compute test end time according to current time
#
# time.time() returns time since start of epoch
# in seconds, so add secs, mins and hrs to that
start_time = time.time()
end_time = start_time + secs + 60*mins + 3600*hrs
# Generate output file named according to current time
fname = time.strftime("p-%Y-%m-%d-%Hh%M", time.localtime()) + ".txt"
f = open(fname, "w")
# Write current time and start of test to output file
f.write("------------------------------------------------------------\r\n")
f.write("%s: starting test\n" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime()))
print "%s: starting test" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime())
f.write("------------------------------------------------------------\r\n")
# Enable the needed channels and start generating pulses
ctb.write(CHENREG, chen)
# Run test loop for the specified time
while time.time() < end_time:
pass
# Disable all channels
ctb.write(CHENREG, 0x00)
f.write("%s: ending test\n" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime()))
print "%s: ending test" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime())
f.write("------------------------------------------------------------\r\n")
secs = int(end_time - start_time)
print "pulses sent:"
print "ch 1: %d" % (secs * farr[0])
print "ch 2: %d" % (secs * farr[1])
print "ch 3: %d" % (secs * farr[2])
print "ch 4: %d" % (secs * farr[3])
print "ch 5: %d" % (secs * farr[4])
print "ch 6: %d" % (secs * farr[5])
f.write("pulses sent:\n")
f.write("ch 1: %d\n" % (secs * farr[0]))
f.write("ch 2: %d\n" % (secs * farr[1]))
f.write("ch 3: %d\n" % (secs * farr[2]))
f.write("ch 4: %d\n" % (secs * farr[3]))
f.write("ch 5: %d\n" % (secs * farr[4]))
f.write("ch 6: %d\n" % (secs * farr[5]))
f.write("------------------------------------------------------------\r\n")
# Read counter registers
i = ctb.read(C1IREG)
o = ctb.read(C1OREG)
f.write("ch %d / i: %d / o: %d\n" % (1, i, o))
i = ctb.read(C2IREG)
o = ctb.read(C2OREG)
f.write("ch %d / i: %d / o: %d\n" % (2, i, o))
i = ctb.read(C3IREG)
o = ctb.read(C3OREG)
f.write("ch %d / i: %d / o: %d\n" % (3, i, o))
i = ctb.read(C4IREG)
o = ctb.read(C4OREG)
f.write("ch %d / i: %d / o: %d\n" % (4, i, o))
i = ctb.read(C5IREG)
o = ctb.read(C5OREG)
f.write("ch %d / i: %d / o: %d\n" % (5, i, o))
i = ctb.read(C6IREG)
o = ctb.read(C6OREG)
f.write("ch %d / i: %d / o: %d\n" % (6, i, o))
ctb.close_conn()
f.write("------------------------------------------------------------\r\n")
# Close output file
f.close()
# Print output file name
print
print "Test results can be found in " + fname
#===============================================================================
# CERN (BE-CO-HT)
# Register test for CONV-TTL-BLO
#===============================================================================
# author: Theodor Stana (t.stana@cern.ch)
#
# date of creation: 2013-08-13
#
# version: 1.0
#
# description:
#
# dependencies:
#
# references:
#===============================================================================
# GNU LESSER GENERAL PUBLIC LICENSE
#===============================================================================
# This source file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation; either version 2.1 of the License, or (at your
# option) any later version. This source is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with this
# source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
#===============================================================================
# last changes:
# 2013-08-13 Theodor Stana t.stana@cern.ch File created
#===============================================================================
# TODO: -
#===============================================================================
import random
import sys
import time
sys.path.append("../vbcp")
from vbcp import *
RAMSTART = 0x100
RAMEND = 0x900
if __name__ == "__main__":
ip = "elma" # raw_input("Crate IP? ")
user = "admin" # raw_input("Username? ")
pwd = "ADMIN" # raw_input("Password? ")
# Wait for proper slot number
while 1:
try:
slot = raw_input("Slot no.? ")
slot = int(slot)
ctb = VBCP(ip, user, pwd, slot)
break
except TypeError as e:
print "Please input a decimal slot number."
except SlotError as e:
print e.strerror
except KeyboardInterrupt:
sys.exit()
except:
print "Unexpected error: ", sys.exc_info()[0]
# Ask how long to run the test
print "How long would you like to run the test?"
while 1:
try:
hrs = raw_input(" hrs: ")
hrs = int(hrs)
if (hrs < 0):
raise Exception
break
except KeyboardInterrupt:
sys.exit()
except:
print " Hours must be a decimal number >= 0!"
while 1:
try:
mins = raw_input(" mins: ")
mins = int(mins)
if (mins < 0):
raise Exception
break
except KeyboardInterrupt:
sys.exit()
except:
print " Minutes must be a decimal number >= 0!"
while 1:
try:
secs = raw_input(" secs: ")
secs = int(secs)
if (secs < 0):
raise Exception
break
except KeyboardInterrupt:
sys.exit()
except:
print " Seconds must be a decimal number >= 0!"
# Compute test end time according to current time
#
# time.time() returns time since start of epoch
# in seconds, so add secs, mins and hrs to that
end_time = time.time() + secs + 60*mins + 3600*hrs
# Generate output file named according to current time
fname = time.strftime("c-%Y-%m-%d-%Hh%M", time.localtime()) + ".txt"
f = open(fname, "w")
# Write current time and start of test to output file
f.write("------------------------------------------------------------\r\n")
f.write("%s: starting test\r\n" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime()))
print "%s: starting test" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime())
f.write("------------------------------------------------------------\r\n")
# Open VBCP connection
ctb.open_conn()
# Init counters
wexcep_cnt = 0
rexcep_cnt = 0
mismatch_cnt = 0
addr = RAMSTART
# Run test loop for the specified time
while time.time() < end_time:
# Increment regaddr, reset on overflow above 2^12
addr += 4
if (addr > RAMEND):
addr = RAMSTART
# Write the regaddress value to the register
wval = addr
#f.write("a:%x w:%x " % (addr, wval))
# Try a write to CONV-TTL-BLO, exception if unsuccessful
try:
ctb.write(addr, wval)
except VBCPException as e:
f.write("wex / %s / %s\r\n" % (time.strftime("%Y-%m-%d-%Hh%Mm%Ss",time.localtime()), e.strerror))
wexcep_cnt += 1
# Try a read from CONV-TTL-BLO, exception if unsuccessful
try:
rval = ctb.read(addr)
#f.write("r:%x\r\n" % rval)
# Check if read value is same as written value
if rval != wval:
mismatch_cnt += 1
except VBCPException as e:
f.write("rex / %s / %s\r\n" % (time.strftime("%Y-%m-%d-%Hh%Mm%Ss",time.localtime()), e.strerror))
rexcep_cnt += 1
# Close VBCP connection and print final values
ctb.close_conn()
f.write("------------------------------------------------------------\r\n")
f.write("%s: ending test\r\n" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime()))
print "%s: ending test" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime())
f.write("------------------------------------------------------------\r\n")
f.write("Write transactions: %d\r\n" % ctb.write_cnt)
f.write("Write exceptions: %d\r\n\r\n" % wexcep_cnt)
f.write("Read transactions: %d\r\n" % ctb.read_cnt)
f.write("Read exceptions: %d\r\n\r\n" % rexcep_cnt)
f.write("R/W mismatches: %d\r\n" % mismatch_cnt)
f.write("------------------------------------------------------------\r\n")
# Close output file
f.close()
# Print output file name
print
print "Test results can be found in " + fname
OBJ_DIR = obj
OUTPUT = test
OBJS = test.o
test: $(OBJS)
gcc -o test $(OBJ_DIR)/$(OBJS) -lrt
%.o: %.c
gcc -c $^ -o $(OBJ_DIR)/$@
clean:
rm -f $(OBJ_DIR)/$(OBJS) $(OUTPUT)
File added
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <time.h>
uint64_t get_ticks()
{
struct timeval tv;
gettimeofday( &tv, NULL );
return (uint64_t) tv.tv_sec * 1000000ULL + (uint64_t) tv.tv_usec;
}
int main()
{
// char s[32];
// char s1[32];
// char s2[32];
// int i;
// printf("s1: ");
// fgets(s, sizeof(s), stdin);
// printf("%s", s);
// printf("%d\n",strlen(s));
// for (i=0;i<strlen(s);i++)
// {
// printf("%02x", s[i]);
// }
// printf("\n");
// strcpy(s+(strlen(s)-1),"\r\n");
// //strcat(s1,"\r\n");
// printf("%s", s);
// for (i=0;s[i]!='\0';i++)
// {
// printf("%02x", s[i]);
// }
// printf("\n");
// //printf("s2: ");
// //fgets(s2, sizeof(s2), stdin);
// //printf("%s\n", s2);
// //if ( strstr(s2,s1) != NULL )
// // printf("found!\n");
// uint64_t t0, t1;
// t0 = get_ticks();
// usleep(2000000);
// t1 = get_ticks();
// printf("%lld\n", t0); //.tv_nsec);
// printf("%lld\n", t1); //.tv_nsec);
// printf("%lld\n", t1-t0);
return 0;
}
/*
*==============================================================================
* CERN (BE-CO-HT)
* Source file for VME Board Control Protocol
*==============================================================================
*
* author: Theodor Stana (t.stana@cern.ch)
*
* date of creation: 2013-09-11
*
* version: 1.0
*
* description:
*
* dependencies:
*
* references:
*
*==============================================================================
* GNU LESSER GENERAL PUBLIC LICENSE
*==============================================================================
* This source file is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version. This source is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details. You should have
* received a copy of the GNU Lesser General Public License along with this
* source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
*==============================================================================
* last changes:
* 2013-09-11 Theodor Stana t.stana@cern.ch File created
*==============================================================================
* TODO: -
*==============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#define handle_error(msg) \
do { perror(msg); return -1; } while (0)
#define BUFSIZE 64
#define INPSIZE 16
int
vbcp_open()
{
int sfd = -1;
char buf[BUFSIZE];
struct addrinfo hints;
struct addrinfo *res;
char input[INPSIZE];
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
hints.ai_addr = NULL;
hints.ai_canonname = NULL;
hints.ai_next = NULL;
if ( getaddrinfo("elma", "telnet", &hints, &res) != 0 )
handle_error("getaddrinfo");
sfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (sfd == -1 )
handle_error("init");
if ( connect(sfd, res->ai_addr, res->ai_addrlen) == -1 )
handle_error("connect");
memset(buf, 0, BUFSIZE);
if ( recv(sfd, buf, BUFSIZE, 0) == -1 )
handle_error("recv");
// printf("%s\n", buf);
if ( strstr(buf, "login") == NULL )
{
printf("login not found\n");
return -1;
}
while (1)
{
while (1)
{
memset(input, 0, INPSIZE);
printf("login: ");
fgets(input, INPSIZE, stdin);
strcpy(input + (strlen(input)-1), "\r\n");
if ( send(sfd, input, 7, 0) == -1 )
handle_error("account send");
memset(buf, 0, BUFSIZE);
if ( recv(sfd, buf, BUFSIZE, 0) == -1 )
handle_error("password");
// printf("%s\n",buf);
if ( strstr(buf, "Wrong username") != NULL )
{
printf("Wrong username\n");
}
else if ( strstr(buf, "password") != NULL )
{
break;
}
// memset(buf, 0, BUFSIZE);
// if ( recv(sfd, buf, BUFSIZE, 0) == -1 )
// handle_error("recv");
// if ( strstr(buf, "login") == NULL )
// {
// printf("%s", buf);
// }
// else
// {
// break;
// }
}
memset(input, 0, INPSIZE);
printf("password: ");
fgets(input, INPSIZE, stdin);
strcpy(input + (strlen(input)-1), "\r\n");
if ( send(sfd, input, 7, 0) == -1 )
handle_error("passwd send");
memset(buf, 0, BUFSIZE);
if ( recv(sfd, buf, BUFSIZE, 0) == -1 )
handle_error("cmdline");
if ( strstr(buf, "Wrong password") != NULL )
{
printf("Wrong password\n");
}
else if ( strstr(buf, "%>") != NULL )
{
break;
// printf("unexpected response: %s\n", buf);
// return -1;
}
}
return sfd;
}
int
vbcp_write(int vfd, uint32_t slot, uint32_t addr, uint32_t val)
{
char cmd[32];
char resp[32];
sprintf(cmd, "writereg %d %d %x\r\n", slot, (1+addr/4), val);
//printf("%s", cmd);
if ( send(vfd, cmd, strlen(cmd), 0) == -1 )
handle_error("write error");
if ( recv(vfd, resp, sizeof(resp), 0) == -1 )
handle_error("write resp error");
if ( strstr(resp, "Done!") == NULL )
printf("not a good reply: %s\n", resp);
return -1;
return 0;
}
int
vbcp_read(int vfd, uint32_t slot, uint32_t addr)
{
char cmd[32];
char resp[32];
char hex[16];
uint32_t retval;
sprintf(cmd, "readreg %d %d\r\n", slot, (1+addr/4));
//printf("cmd: %s", cmd);
// for (retval = 0; cmd[retval] != '\0'; retval++)
// {
// printf("%02x", cmd[retval]);
// }
// printf("\n");
if ( send(vfd, cmd, strlen(cmd), 0) == -1 )
handle_error("read error");
if ( recv(vfd, resp, sizeof(resp), 0) == -1 )
handle_error("read resp error");
if ( strstr(resp, "Read Data:") == NULL )
{
printf("not a good reply: %s\n", resp);
return -1;
}
else
{
//printf("resp: %s\n", resp);
strncpy(hex, resp+14, 8);
//printf("hex: %s\n", hex);
hex[8] = '\0';
//printf("stripped: %s\n", hex);
sscanf(hex, "%X", &retval);
//printf("%x\n", retval);
}
return retval;
}
void
vbcp_close(int vfd)
{
close(vfd);
}
//int main()
//{
// int vfd;
// int reg;
//
// vfd = vbcp_open();
// vbcp_write(vfd, 4, 0x8c, 0xaabbccdd);
// reg = vbcp_read(vfd, 4, 0x8c);
// printf("%x\n", reg);
// vbcp_close(vfd);
//
// return 0;
//}
/*
*==============================================================================
* CERN (BE-CO-HT)
* Header file for VME Board Control Protocol
*==============================================================================
*
* author: Theodor Stana (t.stana@cern.ch)
*
* date of creation: 2013-09-12
*
* version: 1.0
*
* description:
*
* dependencies:
*
* references:
*
*==============================================================================
* GNU LESSER GENERAL PUBLIC LICENSE
*==============================================================================
* This source file is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version. This source is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details. You should have
* received a copy of the GNU Lesser General Public License along with this
* source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
*==============================================================================
* last changes:
* 2013-09-12 Theodor Stana t.stana@cern.ch File created
*==============================================================================
* TODO: -
*==============================================================================
*/
#ifndef __VBCP_H_
#define __VBCP_H_
int vbcp_open();
int vbcp_write(int vfd, int slot, int addr, int val);
int vbcp_read(int vfd, int slot, int addr);
void vbcp_close(int vfd);
/*
*==============================================================================
* <your func name here>
*
* params:
* * <your func params here>
*
* returns:
* - <your func returns here>
*
* comments:
* <your comments here>
*==============================================================================
*/
#endif // __VBCP_H_
#===============================================================================
# CERN (BE-CO-HT)
# VME Board Control Protocol (VBCP) class
#===============================================================================
# author: Theodor Stana (t.stana@cern.ch)
#
# date of creation: 2013-08-13
#
# version: 1.0
#
# description:
#
# dependencies:
#
# references:
#===============================================================================
# GNU LESSER GENERAL PUBLIC LICENSE
#===============================================================================
# This source file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation; either version 2.1 of the License, or (at your
# option) any later version. This source is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with this
# source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
#===============================================================================
# last changes:
# 2013-08-13 Theodor Stana t.stana@cern.ch File created
#===============================================================================
# TODO: -
#===============================================================================
import socket
from vbcpexcept import *
class VBCP:
"""Access a VME crate through Telnet."""
def __init__(self, ip, user, pwd, slot):
"""Initialize VBCP class.
The arguments to init the class are mandatory:
ip -- IP address of VME crate
user -- username to login to VME crate
pwd -- password to login to VME crate
slot -- slot number of VME board
"""
self.ip = ip
self.user = user
self.pwd = pwd
if (slot <= 21):
self.slot = slot
else:
raise SlotError(slot)
self.write_cnt = 0
self.read_cnt = 0
def open_conn(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
s.connect((self.ip, 23))
s.recv(30)
s.send(self.user + "\r\n")
s.recv(30)
s.send(self.pwd + "\r\n")
s.recv(30)
self.handle = s
def close_conn(self):
self.handle.close()
def write(self, addr, val):
self.write_cnt += 1
reg = addr/4 + 1
cmd = "iic4wr %d %d %x\r\n" % (self.slot, reg, val)
self.handle.send(cmd)
_strip_resp(self.handle.recv(30))
def read(self, addr):
self.read_cnt += 1
reg = addr/4 + 1
cmd = "readreg %d %d\r\n" % (self.slot, reg)
self.handle.send(cmd)
resp = _strip_resp(self.handle.recv(30))
return resp
def _strip_resp(msg):
"""Strip useful message from SysMon response.
The response string from the SysMon is stripped of unnecessary characters
and a "useful" string is returned. In case one of the error messages appear,
the function raises one of the VBCP exceptions."""
#print msg.splitlines()
msg = msg.splitlines()[1]
if "Not Ack" in msg:
raise NAckError
if "Invalid register number!" in msg:
raise RegNumberError
if "Bad command!" in msg:
raise InvalidCmdError
if "Read Data:" in msg:
msg = msg.split(" ")[3]
msg = int(msg,16)
return msg
#===============================================================================
# CERN (BE-CO-HT)
# VBCP exceptions
#===============================================================================
# author: Theodor Stana (t.stana@cern.ch)
#
# date of creation: 2013-08-14
#
# version: 1.0
#
# description:
#
# dependencies:
#
# references:
#===============================================================================
# GNU LESSER GENERAL PUBLIC LICENSE
#===============================================================================
# This source file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation; either version 2.1 of the License, or (at your
# option) any later version. This source is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with this
# source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
#===============================================================================
# last changes:
# 2013-08-14 Theodor Stana t.stana@cern.ch File created
#===============================================================================
# TODO: -
#===============================================================================
#===============================================================================
# Main exception class
#===============================================================================
class VBCPException(Exception):
"""Throw VBCP exceptions.
Subclasses:
* SlotError
* NAckError
"""
pass
#===============================================================================
# Slot value exception
#===============================================================================
class SlotError(VBCPException):
"""Throw a slot exception if slot number greater than 21."""
def __init__(self, value):
self.value = value
self.strerror = "Input slot number (%d) is greater than 21" % value
def __str__(self):
return self.strerror
#===============================================================================
# Not Acknowledged exception
#===============================================================================
class NAckError(VBCPException):
"""Throw NACK exception when the module does not acknowledge."""
strerror = "VBCP NACK received."
def __str__(self):
return self.strerror
#===============================================================================
# Register number exception
#===============================================================================
class RegNumberError(VBCPException):
"""Throw register number exception."""
strerror = "Invalid register number."
def __str__(self):
return self.strerror
#===============================================================================
# Invalid command exception
#===============================================================================
class InvalidCmdError(VBCPException):
"""Throw invalid command exception."""
strerror = "Bad command exception."
def __str__(self):
return self.strerror
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