SuperKEKB XRM system  Not logged in ELOG logo
Message ID: 1     Entry time: Tue Apr 19 19:09:25 2016
Author: James Bynes 
Type: Instructions 
Subject: Obtaining data from XRM development boardstack 
Here are the instructions to obtain data from XRM boardstack. This has currently been tested with 1 carrier board, but little modifications will allow multiple boards. Currently the data
taken is raw data, a pedestal extractor is currently under works.
The current firmware and software branch can be accessible from the svn repo at: https://www.phys.hawaii.edu/repos/belle2/itop/electronics/branches/XRM
**note** The firmware and software bundle can also be temporarily downloaded from Google Drive: https://drive.google.com/file/d/0B7Z8jduXUZ-LbFdUTFdEMkctUnc/view?usp=sharing
**note** Software bundle does not include XRM parser, please download from this ELOG.
**note** The following instructions are written using the directory for the test setup at IDLAB. Please modify the upcoming directories to match your system.

If any questions, please email James (bynes@hawaii.edu) or Luca (lucam@hawaii.edu)

Preliminary Step (setting up the network):

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
Next, we setup the test workstation (at IDLAB) using a static IP address, this machine ran Scientific Linux (red hat variant)
From red hat linux this can be done like so...
Menu System >> Administration >> Network
Statically set IP address:
Address 192.168.10.200
Subnet mask 255.255.255.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.

Step 1 (program FPGA):
First need to source Xilinx settings, if your .bashrc doesn’t already do so.
Directory: /opt/Xilinx/Vivado/2014.4/
Change to c shell, type ‘csh’ in terminal
Source settings64.csh
Directory: /home/idlab/svn-02-18-2016/gigE
Upload bitfiles to FPGAs on chain ‘xmd -tcl program-bit-and-elf-and-go.xmd.tcl’

Step 2 (run GUI):
Directory: /home/idlab/svn-02-18-2016/gigE/software/gigE/
Source setup_env_template.csh
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

Step 3 (configuration):
Next, the configuration script will need to be ran
Directory: /home/idlab/svn-02-18-2016/gigE/software/gigE/pnnl
Run configuration script: './configure_boardstack.csh'
...
In the GUI, will also need to manually configure some settings.
From the Configuration tab, change the following fields to the parameters:
trigMask -> 0xe
featureExtractionMode -> Passthrough
After these two parameters are changed, hit the “Write Configuration” button on the bottom.

Step 4 (pull data):
This current script will take data from carrier 0 (includes all 4 ASICs).
Directory: /home/idlab/svn-02-18-2016/gigE/software/gigE/pnnl/
Run current test script: ‘./runtest.csh’
The binary file will be outputted to data/test_c0_1.bin

Step 5 (parse data):
XRMdataExtractor.c will convert binary data pulled from previous step and output to a readable format. It is attached to this elog
Use: ./XRMdataExtractor <binary_file>
Output files: XRM_header_from_binary_file.txt, XRM_data_from_binary_file.txt
The header file shows format of data file which is as follows:
carrier# | ASIC# | Sample# | CH0 | CH1 | CH2 | CH3 | CH4 | CH5 | CH6 | CH7

Upcoming additions:
XRMpedExtractor
XRMdataVisualizer
Attachment 1: XRMdataExtractor.c  4 kB  | 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