SuperKEKB XRM system  Not logged in ELOG logo
Message ID: 2     Entry time: Sun May 1 01:45:45 2016
Author: James Bynes 
Type: Instructions 
Subject: Setting up Ubuntu 14.04 to take data from XRM boardstack 
This ELOG shows how to obtain data from XRM boardstack from a fresh install of Ubuntu 14.04

i) Freshly install Ubuntu 14.04

Once installation is finished, update all packages:
'sudo apt-get update'
'sudo apt-get upgrade'
'sudo apt-get update'


ii) Add a softlink so that gmake points to make:

'sudo ln -s /usr/bin/make /usr/bin/gmake'

iii) Install the following via 'sudo apt-get install <package>'

libxml2-dev
g++
libbz2-dev
libqt4-dev
python-dev
lib32z1-dev
vim
subversion
tsch


iv) Download software package and make:
Directory: /home/
'svn co https://www.phys.hawaii.edu/repos/belle2/itop/electronics/branches/XRM'
Directory: ~/XRM/software/gigE/
'source setup_env_template.sh'
'make clean'
'make'
(should make with no errors)

v) Install Vivado 2014.4 using web pack (used Design edition since limited in space)
'chmod +x Xilinx_installation_file.bin'
'sudo ./Xilinx_installation_file.bin'

install to /opt/Xilinx/...
allow write permissions to Xilinx folder:
'sudo chmod 777 -R /opt/Xilinx/'
'sudo chmod 777 -R ~/.Xilinx'

Open ~/.bashrc in your favorite text editor and add the following:
____________________________________________________
XILINXD_LICENSE_FILE=<your_license>
LM_LICENSE_FILE=<your_license>
export XILINXD_LICENSE_FILE
export LM_LICENSE_FILE
source /opt/Xilinx/Vivado/2014.4/settings64.sh
____________________________________________________
Now show be able to run vivado by typing vivado from xterm

vi) Setting up network for communication with boardstack:
The firmware has been setup to communicate with a workstation using point-to-point topologies.
First, connect a SFP module from the SCROD to a media converter, then connect the Ethernet cable to your workstation.
Workstation IP
From Network Connections, add a new Ethernet connection
From the Ethernet tab, select your network adapter Device MAC Address
Statically set IP address:
On IPv4 tab, select Manual from drop-down list
Click on Add and add the following:
Address: 192.168.10.200
Subnet mask: 255.255.255.0
Gateway: 0.0.0.0
SCROD firmware IP
The firmware is currently set to use IP address 192.168.10.***
where the last 3 digits is the ID of the SCROD. This IP will come in handy when launching the communication GUI.

vii) Program FPGA

Directory: ~/XRM/
Upload bitfiles to FPGAs on chain ‘xmd -tcl program-bit-and-elf-and-go.xmd.tcl’

viii) Run GUI
Directory: ~/XRM/software/gigE/
'Source setup_env_template.sh'
Now run GUI: ‘bin/develTest 192.168.10.101’
**Note** 101 is the SCROD board ID, this should be on the SCROD itself on a whitish label.
To test whether or not link to SCROD is up, from configuration tab on GUI, click “Read Configuration” button on the bottom

ix) Configure boardstack
Open a new terminal window and source setup_env_template.sh again
Directory: ~/XRM/software/gigE/pnnl/
Open configure_boardstack.csh with your favorite text editor
On the line 'foreach carrier(...)', starting from 0, sequential add numbers for the amount of carriers on the boardstack
Example: 'foreach carrier(0 1 2)' is used for 3 carriers on the boardstack
Save and run the file: './configure_boardstack.csh'
On the GUI from the configuration tab, change the following parameters:
trigMask -> 0xe (for 1 carrier), 0xc (for 2 carriers), 0x8 (for 3 carriers)
featureExtractionMode -> Passthrough


x) Pull Data
Directory: ~/XRM/software/gigE/pnnl/
'/.runtest.csh'

xi) Parse Data
Directory: ~/XRM/software/gigE/pnnl/data
Download file attached to this ELOG to directory
Compile: 'gcc -o XRMdataExtractor XRMdataExtractor.c'
Parse data: 'XRMdataExtractor test_c0_1.bin'
Open XRM_data_test_c0_1.bin.txt using your favorite text editor to look at the data

xii) Future Additions

XRMpedExtractor - This program will determine pedestals
Attachment 1: XRMdataExtractor.c  4 kB  Uploaded Sun May 1 02:48:25 2016  | Hide | Hide all
/******************************************************************
 * Author: James Bynes
 * Date: 04-19-2016
 * XRMdataExtractor.c
 * Description: Extracts data taken from ASIC and outputs to
 *		readable format.
 ******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

unsigned int data_ch[8][64];
int mm = 0;
int carrier = 0;
int asic = 0;

void initialize_data(void){
    int m,n;
    for(n=0;n<8;n++){
	for(m=0;m<64;m++)
	    data_ch[n][m]=0;
    }
}

unsigned int createMask(unsigned int a, unsigned int b){
    unsigned int r=0;
    unsigned int i=0;
    for (i=a; i<=b; i++)
	r |= 1 << i;
    return r;
}

void fprint_data(FILE *fp){
    int m,n;
    
    for(m=0;m<64;m++)
	fprintf(fp,"%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", carrier, asic, m, data_ch[0][m], data_ch[1][m], data_ch[2][m], data_ch[3][m], data_ch[4][m], data_ch[5][m], data_ch[6][m], data_ch[7][m]);
}

void get_eventInfo(FILE *headerFile, unsigned int wordsInPacket,int mm, int k){
    unsigned int r, result;
    fprintf(headerFile,"line %d\n", mm);
    fprintf(headerFile,"k: %d\n", k);
    r = createMask(30,31);
    result = (r & wordsInPacket)>>30;
    carrier = result;
    fprintf(headerFile,"Carrier: 0x%01x\n", result);
    r = createMask(28,29);
    result = (r & wordsInPacket)>>28;
    asic = result;
    fprintf(headerFile,"IRSX: 0x%01x\n", result);
    r = createMask(27,27);
    result = (r & wordsInPacket)>>27;
    fprintf(headerFile,"0: 0x%01x\n", result);
    r = createMask(24,26);
    result = (r & wordsInPacket)>>24;
    fprintf(headerFile,"Channel: 0x%01x\n", result);
    r = createMask(16,23);
    result = (r & wordsInPacket)>>16;
    fprintf(headerFile,"LastWriteAddress: 0x%02x\n", result);
    r = createMask(9,15);
    result = (r & wordsInPacket)>>9;
    fprintf(headerFile,"SCROD ID: 0x%03x\n", result);
    r = createMask(0,8);
    result = (r & wordsInPacket);
    fprintf(headerFile,"Converted Addr: 0x%03x\n", result);
}

main(int argc, char *argv[]){
    if(argc < 2){
	printf("You must enter a binary filename\n");
	goto INVALID_ARGS;
    }

    char headerName[80];
    char dataName[80];
    strcpy(headerName, "XRM_header_");
    strcat(headerName, argv[1]);
    strcat(headerName, ".txt");
    strcpy(dataName, "XRM_data_");
    strcat(dataName, argv[1]);
    strcat(dataName, ".txt");

    FILE *fileName = fopen(argv[1], "r");
    FILE *headerFile = fopen(headerName, "w");
    FILE *dataFile = fopen(dataName, "w");

    fputs("DATA FORMAT\n", headerFile);
    fputs("carrier# | ASIC# | Sample# | CH0 | CH1 | CH2 | CH3 | CH4 | CH5 | CH6 | CH7\n\n", headerFile);

    if(!fileName){
	printf("File doesn't exist\n");
	INVALID_ARGS:
	printf("Usage:\n");
	printf("XRMdataExtractor <binary file>\n");
	return;
    }
    
    unsigned int wordsInPacket, packet_hdr, result, r, num_windows, footer;
    int i = 0;
    int j = 0;
    int k = 0;

    initialize_data();

    printf("_________HEADER__________\n");

    while(!feof(fileName)){
	NEW_EVENT:
	fread(&packet_hdr, sizeof(packet_hdr),1,fileName);
	if(feof(fileName))
	    break;
	wordsInPacket = packet_hdr;
	if (mm < 3){
	    if (mm == 0){
		fprintf(headerFile,"Event size: %d\n", wordsInPacket);
	    }
	    if (mm == 1){
		r = createMask(28,31);
		result = (r & wordsInPacket)>>28;
		fprintf(headerFile,"Trig Pattern: 0x%01x\n", result);
		r = createMask(19,27);
		result = (r & wordsInPacket)>>19;
		num_windows = result+1;
		fprintf(headerFile,"# of windows: 0x%03x\n", result);
		r = createMask(0,18);
		result = r & wordsInPacket;
		fprintf(headerFile,"Timestamp: 0x%05x\n", result);
	    }
	    if (mm == 2){
		get_eventInfo(headerFile,wordsInPacket,mm,k);
	    }
	}
	else{
	    if((j < 8) && (i < 64)){
		r = createMask(0,11);
		result = (r & wordsInPacket);
		data_ch[j][i] = result;
		i++;
		r = createMask(16,27);
		result = (r & wordsInPacket)>>16;
		data_ch[j][i] = result;
		i++;
		    
	    }
	    else{
		if((j==7)){ //on to next event
		    j = 0;
		    i = 0;
		    k = k + 1;
		    fprint_data(dataFile);
		    if(k<4)
			get_eventInfo(headerFile,wordsInPacket,mm,k);
		    else{
			footer = wordsInPacket;
			printf("Footer %08x\n",footer);
			mm = 0;
			k = 0;
			goto NEW_EVENT;
		    }
		}
		else{//on to next channel (same event)
		    i = 0;
		    j++;
		    r = createMask(0,11);
		    result = (r & wordsInPacket);
		    data_ch[j][i] = result;
		    i++;
		    r = createMask(16,27);
		    result = (r & wordsInPacket)>>16;
		    data_ch[j][i] = result;
		    i++;
		}
	    }
	}
	mm++;
    }
    printf("\n");
}

ELOG V3.1.5-3a5f2f0