Skip to content

Commit

Permalink
Merge pull request #122 from slaclab/misc-code-clean-up
Browse files Browse the repository at this point in the history
Misc. Code Clean Up
  • Loading branch information
ruck314 authored Feb 25, 2024
2 parents d5b500d + d88cd67 commit 7573cb5
Show file tree
Hide file tree
Showing 18 changed files with 924 additions and 593 deletions.
28 changes: 22 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Company : SLAC National Accelerator Laboratory
# ----------------------------------------------------------------------------
# Description:
# Example driver makefile
# Makefile for building drivers, applications, and RCE modules.
# This Makefile provides targets for compiling applications (app),
# drivers, and RCE modules for specific architectures and kernel versions.
# ----------------------------------------------------------------------------
# This file is part of the aes_stream_drivers package. It is subject to
# the license terms in the LICENSE.txt file found in the top-level directory
Expand All @@ -13,35 +15,49 @@
# contained in the LICENSE.txt file.
# ----------------------------------------------------------------------------

# Set the path to the Makefile's directory
MAKE_HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

# Default architecture
ARCH ?= arm

# Discover the local kernel versions
LOC_VERS := $(wildcard /lib/modules/*/build)
LOC_VERS := $(patsubst %/,%,$(dir $(LOC_VERS)))
LOC_VERS := $(notdir $(LOC_VERS))

# Define RCE module directories
RCE_DIRS := /afs/slac.stanford.edu/g/cci/volumes/vol1/xilinx/linux-xlnx-v2016.4
RCE_DIRS += /afs/slac.stanford.edu/g/cci/volumes/vol1/xilinx/backup/linux-xlnx-v2016.1.01

# Default target: Display the available build options
all:
@echo "Options: app driver rce"
@echo "Available targets: app driver rce"

# Build applications
app:
@echo "Building applications..."
@make -C $(MAKE_HOME)/rce_stream/app clean
@make -C $(MAKE_HOME)/rce_stream/app
@make -C $(MAKE_HOME)/data_dev/app clean
@make -C $(MAKE_HOME)/data_dev/app

# Build drivers for each discovered kernel version
driver:
@mkdir -p $(MAKE_HOME)/install;
@ $(foreach ver,$(LOC_VERS), \
@echo "Building drivers for all kernel versions..."
@mkdir -p $(MAKE_HOME)/install
@$(foreach ver,$(LOC_VERS), \
mkdir -p $(MAKE_HOME)/install/$(ver); \
make -C $(MAKE_HOME)/data_dev/driver KVER=$(ver) clean; \
make -C $(MAKE_HOME)/data_dev/driver KVER=$(ver); \
scp $(MAKE_HOME)/data_dev/driver/*.ko $(MAKE_HOME)/install/$(ver); \
)

# Build RCE modules for specified directories
rce:
@mkdir -p $(MAKE_HOME)/install;
@ $(foreach d,$(RCE_DIRS), \
@echo "Building RCE modules..."
@mkdir -p $(MAKE_HOME)/install
@$(foreach d,$(RCE_DIRS), \
mkdir -p $(MAKE_HOME)/install/$(shell make -C $(d) -s kernelversion).$(ARCH); \
make -C $(MAKE_HOME)/rce_stream/driver KDIR=$(d) clean; \
make -C $(MAKE_HOME)/rce_stream/driver KDIR=$(d); \
Expand Down
177 changes: 96 additions & 81 deletions common/app_lib/PrbsData.cpp
Original file line number Diff line number Diff line change
@@ -1,160 +1,175 @@
/**
*-----------------------------------------------------------------------------
* Title : PRBS Receive And Transmit Class
* ----------------------------------------------------------------------------
* File : PrbsData.cpp
* Author : Ryan Herbst <[email protected]>
* Created : 08/11/2014
* Last update : 08/11/2014
* Company : SLAC National Accelerator Laboratory
*-----------------------------------------------------------------------------
* Description :
* Class used to generate and receive PRBS test data.
* Description:
* This class is designed for generating and receiving PRBS (Pseudo-Random
* Binary Sequence) test data, primarily used for testing data integrity
* and communication channels.
*-----------------------------------------------------------------------------
* This file is part of the aes_stream_drivers package. It is subject to
* the license terms in the LICENSE.txt file found in the top-level directory
* of this distribution and at:
* https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
* This file is part of the aes_stream_drivers package. It is subject to the
* license terms in the LICENSE.txt file found in the top-level directory of
* this distribution and at:
* https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
* No part of the aes_stream_drivers package, including this file, may be
* copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE.txt file.
*-----------------------------------------------------------------------------
**/
**/

#include "PrbsData.h"
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>

PrbsData::PrbsData (uint32_t width, uint32_t tapCnt, ...) {
// Constructor with specific width and tap counts
PrbsData::PrbsData(uint32_t width, uint32_t tapCnt, ...) {
va_list a_list;
uint32_t x;
uint32_t x;

// Initialize PRBS parameters
_sequence = 0;
_width = width;
_tapCnt = tapCnt;
_width = width;
_tapCnt = tapCnt;

_taps = (uint32_t *)malloc(sizeof(uint32_t)*_tapCnt);
// Allocate memory for tap positions
_taps = (uint32_t *)malloc(sizeof(uint32_t) * _tapCnt);

va_start(a_list,tapCnt);
for(x=0; x < tapCnt; x++) _taps[x] = va_arg(a_list,uint32_t);
// Set tap positions
va_start(a_list, tapCnt);
for (x = 0; x < tapCnt; x++) {
_taps[x] = va_arg(a_list, uint32_t);
}
va_end(a_list);
}

PrbsData::PrbsData () {
// Default constructor
PrbsData::PrbsData() {
// Default PRBS parameters
_sequence = 0;
_width = 32;
_tapCnt = 4;

_taps = (uint32_t *)malloc(sizeof(uint32_t)*_tapCnt);
_width = 32;
_tapCnt = 4;

// Allocate and set default tap positions
_taps = (uint32_t *)malloc(sizeof(uint32_t) * _tapCnt);
_taps[0] = 1;
_taps[1] = 2;
_taps[2] = 6;
_taps[3] = 31;
}

// Destructor
PrbsData::~PrbsData() {
// Free allocated memory for taps
free(_taps);
}

void PrbsData::genData ( const void *data, uint32_t size ) {
uint32_t word;
uint32_t value;
uint32_t * data32;
uint16_t * data16;
// Generate PRBS data
void PrbsData::genData(const void *data, uint32_t size) {
uint32_t word;
uint32_t value;
uint32_t *data32;
uint16_t *data16;

// Cast input data to appropriate type
data32 = (uint32_t *)data;
data16 = (uint16_t *)data;

value = _sequence;

if ( _width == 16 ) {
if ((( size % 2 ) != 0) || size < 6 ) return;
// Handle different data widths
if (_width == 16) {
// Check size constraints for 16-bit width
if ((size % 2) != 0 || size < 6) return;
data16[0] = _sequence & 0xFFFF;
data16[1] = (size - 2) / 2;
}
else if ( _width == 32 ) {
if ((( size % 4 ) != 0) || size < 12 ) return;
} else if (_width == 32) {
// Check size constraints for 32-bit width
if ((size % 4) != 0 || size < 12) return;
data32[0] = _sequence;
data32[1] = (size - 4) / 4;
}
else {
fprintf(stderr,"Bad gen width = %i\n",_width);
} else {
fprintf(stderr, "Bad gen width = %i\n", _width);
return;
}

for (word = 2; word < size/(_width/8); word++) {
// Fill data with PRBS sequence
for (word = 2; word < size / (_width / 8); word++) {
value = flfsr(value);
if ( _width == 16 ) data16[word] = value;
else if ( _width == 32 ) data32[word] = value;
if (_width == 16) data16[word] = value;
else if (_width == 32) data32[word] = value;
}

if ( _width == 16 ) _sequence = data16[0] + 1;
else if ( _width == 32 ) _sequence = data32[0] + 1;
// Update sequence
if (_width == 16) _sequence = data16[0] + 1;
else if (_width == 32) _sequence = data32[0] + 1;
}

bool PrbsData::processData ( const void *data, uint32_t size ) {
uint32_t eventLength;
uint32_t expected;
uint32_t got;
uint32_t word;
uint32_t min;
uint32_t * data32;
uint16_t * data16;

// Process received PRBS data
bool PrbsData::processData(const void *data, uint32_t size) {
uint32_t eventLength;
uint32_t expected;
uint32_t got;
uint32_t word;
uint32_t min;
uint32_t *data32;
uint16_t *data16;

// Cast input data to appropriate type
data32 = (uint32_t *)data;
data16 = (uint16_t *)data;

if ( _width == 16 ) {
expected = data16[0];
// Handle different data widths
if (_width == 16) {
expected = data16[0];
eventLength = (data16[1] * 2) + 2;
min = 6;
}
else if ( _width == 32 ) {
expected = data32[0];
min = 6;
} else if (_width == 32) {
expected = data32[0];
eventLength = (data32[1] * 4) + 4;
min = 12;
}
else {
fprintf(stderr,"Bad process width = %i\n",_width);
return(false);
min = 12;
} else {
fprintf(stderr, "Bad process width = %i\n", _width);
return false;
}

// Verify size constraints
if (size < min || eventLength != size) {
fprintf(stderr,"Bad size. exp=%i, min=%i, got=%i\n",eventLength,min,size);
return(false);
fprintf(stderr, "Bad size. exp=%i, min=%i, got=%i\n", eventLength, min, size);
return false;
}

if ( _sequence != 0 && expected != 0 && _sequence != expected ) {
fprintf(stderr,"Bad Sequence. exp=%i, got=%i\n",_sequence,expected);
// Check sequence continuity
if (_sequence != 0 && expected != 0 && _sequence != expected) {
fprintf(stderr, "Bad Sequence. exp=%i, got=%i\n", _sequence, expected);
_sequence = expected + 1;
return(false);
return false;
}
_sequence = expected + 1;

for (word = 2; word < size/(_width/8); word++) {
// Verify PRBS sequence
for (word = 2; word < size / (_width / 8); word++) {
expected = flfsr(expected);

if ( _width == 16 ) got = data16[word];
else if ( _width == 32 ) got = data32[word];
if (_width == 16) got = data16[word];
else if (_width == 32) got = data32[word];
else got = 0;

if (expected != got) {
fprintf(stderr,"Bad value at index %i. exp=0x%x, got=0x%x\n",word,expected,got);
return(false);
fprintf(stderr, "Bad value at index %i. exp=0x%x, got=0x%x\n", word, expected, got);
return false;
}
}
return(true);
return true;
}

// Linear feedback shift register function
uint32_t PrbsData::flfsr(uint32_t input) {
uint32_t bit = 0;
uint32_t x;

for (x=0; x < _tapCnt; x++) bit = bit ^ (input >> _taps[x]);

bit = bit & 1;
// Compute feedback bit
for (x = 0; x < _tapCnt; x++) bit ^= (input >> _taps[x]) & 1;

//return (input >> 1) | (bit << _width);
return ((input << 1) | bit);
// Shift input and insert feedback bit
return (input << 1) | bit;
}

Loading

0 comments on commit 7573cb5

Please sign in to comment.