Software fast final
This commit is contained in:
+159
-139
@@ -16,187 +16,207 @@
|
||||
#include "axi_crc_dma.h"
|
||||
#include "gip.h"
|
||||
|
||||
#define DEBUG 1
|
||||
//#define test 0
|
||||
|
||||
#define PACKET_SIZE 3
|
||||
#define NUMBER_PACKETS 8
|
||||
#define PACKET_SIZE 200
|
||||
#define NUMBER_PACKETS 5
|
||||
|
||||
#define DATA_SIZE ((PACKET_SIZE)*(NUMBER_PACKETS))
|
||||
|
||||
// Berechnen einer 32 Bit CRC-Pruefsumme mit allen Parametern
|
||||
uint32_t calcCRC32(
|
||||
uint8_t* inBytes,
|
||||
size_t size,
|
||||
uint32_t polynomial,
|
||||
uint32_t initialValue,
|
||||
uint32_t finalXOR,
|
||||
uint8_t inputReflected,
|
||||
uint8_t outputReflected
|
||||
uint8_t* inBytes,
|
||||
size_t size,
|
||||
uint32_t polynomial,
|
||||
uint32_t initialValue,
|
||||
uint32_t finalXOR,
|
||||
uint8_t inputReflected,
|
||||
uint8_t outputReflected
|
||||
);
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// some established CRC32 Parameter sets. Source: https://reveng.sourceforge.io/crc-catalogue/ (13.02.2025)
|
||||
const CrcParameterSet CRC32_AIXM = {
|
||||
.Polynomial = 0x814141ab,
|
||||
.InitalValue = 0x0,
|
||||
.FinalXOR = 0x0,
|
||||
.InputReflected = false,
|
||||
.OutputReflected = false
|
||||
};
|
||||
// some established CRC32 Parameter sets. Source: https://reveng.sourceforge.io/crc-catalogue/ (13.02.2025)
|
||||
const CrcParameterSet CRC32_AIXM = {
|
||||
.Polynomial = 0x814141ab,
|
||||
.InitalValue = 0x0,
|
||||
.FinalXOR = 0x0,
|
||||
.InputReflected = false,
|
||||
.OutputReflected = false
|
||||
};
|
||||
|
||||
const CrcParameterSet CRC32_ISO_HDLC = {
|
||||
.Polynomial = 0x04c11db7,
|
||||
.InitalValue = 0xFFFFFFFF,
|
||||
.FinalXOR = 0xFFFFFFFF,
|
||||
.InputReflected = true,
|
||||
.OutputReflected = true
|
||||
};
|
||||
const CrcParameterSet CRC32_ISO_HDLC = {
|
||||
.Polynomial = 0x04c11db7,
|
||||
.InitalValue = 0xFFFFFFFF,
|
||||
.FinalXOR = 0xFFFFFFFF,
|
||||
.InputReflected = true,
|
||||
.OutputReflected = true
|
||||
};
|
||||
|
||||
const CrcParameterSet CRC32_ISCSI = {
|
||||
.Polynomial = 0x1edc6f41 ,
|
||||
.InitalValue = 0xFFFFFFFF ,
|
||||
.FinalXOR = 0xFFFFFFFF ,
|
||||
.InputReflected = true,
|
||||
.OutputReflected = true
|
||||
};
|
||||
const CrcParameterSet CRC32_ISCSI = {
|
||||
.Polynomial = 0x1edc6f41 ,
|
||||
.InitalValue = 0xFFFFFFFF ,
|
||||
.FinalXOR = 0xFFFFFFFF ,
|
||||
.InputReflected = true,
|
||||
.OutputReflected = true
|
||||
};
|
||||
|
||||
const CrcParameterSet CRC32_CD_ROM_EDC = {
|
||||
.Polynomial = 0x8001801b,
|
||||
.InitalValue = 0x0,
|
||||
.FinalXOR = 0x0,
|
||||
.InputReflected = false,
|
||||
.OutputReflected = false
|
||||
};
|
||||
const CrcParameterSet CRC32_CD_ROM_EDC = {
|
||||
.Polynomial = 0x8001801b,
|
||||
.InitalValue = 0x0,
|
||||
.FinalXOR = 0x0,
|
||||
.InputReflected = false,
|
||||
.OutputReflected = false
|
||||
};
|
||||
|
||||
// UIO & pointers
|
||||
int fdCRC = open("/dev/uio0", O_RDWR);
|
||||
int fdMem = open("/dev/uio16", O_RDWR);
|
||||
PCRC_DMA_Typedef CRC = (PCRC_DMA_Typedef) mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fdCRC, 0);
|
||||
uint32_t* pMem = (uint32_t*) mmap(NULL, 0x20000000, PROT_READ | PROT_WRITE, MAP_SHARED, fdMem, 0);
|
||||
CrcParameterSet CrcSets[4] = {CRC32_AIXM, CRC32_ISO_HDLC, CRC32_ISCSI, CRC32_CD_ROM_EDC};
|
||||
|
||||
printf("Programm startet\n\n");
|
||||
CrcParameterSet paraSet = CRC32_AIXM;
|
||||
// UIO & pointers
|
||||
int fdCRC = open("/dev/uio0", O_RDWR);
|
||||
int fdMem = open("/dev/uio16", O_RDWR);
|
||||
PCRC_DMA_Typedef CRC = (PCRC_DMA_Typedef) mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fdCRC, 0);
|
||||
uint32_t* pMem = (uint32_t*) mmap(NULL, 0x20000000, PROT_READ | PROT_WRITE, MAP_SHARED, fdMem, 0);
|
||||
|
||||
// Physische Adressen anlegen
|
||||
uint32_t uio16PhysBase = 0x30000000; // UIO16 physical Baseaddress
|
||||
uint32_t* pDataPhy = (uint32_t*) uio16PhysBase;
|
||||
uint32_t* pDataDestPhy = pDataPhy + DATA_SIZE;
|
||||
// Physische Adressen anlegen
|
||||
uint32_t uio16PhysBase = 0x30000000; // UIO16 physical Baseaddress
|
||||
uint32_t* pDataPhy = (uint32_t*) uio16PhysBase;
|
||||
uint32_t* pDataDestPhy = pDataPhy + DATA_SIZE;
|
||||
|
||||
// Mehrdimensionale Arrays deklarieren und mit virtuellen Adressen initialisieren
|
||||
uint32_t (*data)[PACKET_SIZE] = (uint32_t (*)[PACKET_SIZE]) pMem;
|
||||
uint32_t (*DataDest)[PACKET_SIZE+1] = (uint32_t (*)[PACKET_SIZE+1]) (pMem + DATA_SIZE);
|
||||
printf("Programm startet\n\n");
|
||||
|
||||
// Speicher der Ergebnisse der CRC Berechnungen durch Hardware und Software
|
||||
uint32_t crc_sw[NUMBER_PACKETS];
|
||||
uint32_t crc_hw[NUMBER_PACKETS];
|
||||
for (int CrcSetI = 0; CrcSetI < 4; CrcSetI++) {
|
||||
CrcParameterSet paraSet = CrcSets[CrcSetI];
|
||||
|
||||
// Testdaten erzeugen
|
||||
printf("Testdaten erzeugen\n\n");
|
||||
srand(time(NULL));
|
||||
for (int packet = 0; packet < NUMBER_PACKETS; packet++) {
|
||||
for (int word = 0; word < PACKET_SIZE; word++) {
|
||||
data[packet][word] = (uint32_t) rand();
|
||||
}
|
||||
}
|
||||
// Mehrdimensionale Arrays deklarieren und mit virtuellen Adressen initialisieren
|
||||
uint32_t (*data)[PACKET_SIZE] = (uint32_t (*)[PACKET_SIZE]) pMem;
|
||||
uint32_t (*DataDest)[PACKET_SIZE+1] = (uint32_t (*)[PACKET_SIZE+1]) (pMem + DATA_SIZE);
|
||||
|
||||
// axi_crc_dam Komponete parametrieren
|
||||
CRC->Control |= (1<<1); // INT aktivieren
|
||||
CRC->ReadAddress = (uint32_t) pDataPhy;
|
||||
CRC->WriteAddress = (uint32_t) pDataDestPhy;
|
||||
CRC->PacketSize = PACKET_SIZE - 1;
|
||||
CRC->NumberPackets = NUMBER_PACKETS - 1;
|
||||
CRC_DMA_set_parameters(CRC, ¶Set);
|
||||
// Speicher der Ergebnisse der CRC Berechnungen durch Hardware und Software
|
||||
uint32_t crc_sw[NUMBER_PACKETS];
|
||||
uint32_t crc_hw[NUMBER_PACKETS];
|
||||
|
||||
// Interrupt zurücksetzen und aktivieren
|
||||
CRC->InterruptStatus = 0;
|
||||
int reenable = 1;
|
||||
write(fdCRC, (void*) &reenable, 4);
|
||||
// Testdaten erzeugen
|
||||
printf("Testdaten erzeugen\n\n");
|
||||
srand(time(NULL));
|
||||
for (int packet = 0; packet < NUMBER_PACKETS; packet++) {
|
||||
for (int word = 0; word < PACKET_SIZE; word++) {
|
||||
data[packet][word] = (uint32_t) rand();
|
||||
}
|
||||
}
|
||||
|
||||
// CRC Berechnung mit Hardware starten
|
||||
printf("CRC-Berechnung in Hardware starten\n\n");
|
||||
CRC->Control |= (1<<0);
|
||||
// axi_crc_dam Komponete parametrieren
|
||||
CRC->Control |= (1<<1); // INT aktivieren
|
||||
CRC->ReadAddress = (uint32_t) pDataPhy;
|
||||
CRC->WriteAddress = (uint32_t) pDataDestPhy;
|
||||
CRC->PacketSize = PACKET_SIZE - 1;
|
||||
CRC->NumberPackets = NUMBER_PACKETS - 1;
|
||||
CRC_DMA_set_parameters(CRC, ¶Set);
|
||||
|
||||
// CRC Berechnung in Software durchfuehren
|
||||
printf("CRC-Berechnung in Software durchfuehren\n\n");
|
||||
for (int p = 0; p < NUMBER_PACKETS; p++) {
|
||||
crc_sw[p] = calcCRC32((uint8_t*) (&data[p][0]), PACKET_SIZE*4, paraSet.Polynomial, paraSet.InitalValue, paraSet.FinalXOR, paraSet.InputReflected ? 1 : 0, paraSet.OutputReflected ? 1 : 0);
|
||||
printf("Packet %i:\t0x%08x\n", p, crc_sw[p]);
|
||||
}
|
||||
printf("\n");
|
||||
// Interrupt zurücksetzen und aktivieren
|
||||
CRC->InterruptStatus = 0;
|
||||
int reenable = 1;
|
||||
write(fdCRC, (void*) &reenable, 4);
|
||||
|
||||
// Auf INT warten
|
||||
printf("Auf Interrupt warten...\n");
|
||||
int pending;
|
||||
read(fdCRC, (void*) &pending, 4);
|
||||
CRC->InterruptStatus = 0;
|
||||
write(fdCRC, (void*) &reenable, 4);
|
||||
printf("Interrupt erhalten\n");
|
||||
// CRC Berechnung mit Hardware starten
|
||||
printf("CRC-Berechnung in Hardware starten\n\n");
|
||||
CRC->Control |= (1<<0);
|
||||
|
||||
// Hardwareergebnis in Array ablegen
|
||||
for (int p = 0; p < NUMBER_PACKETS; p++) {
|
||||
crc_hw[p] = DataDest[p][PACKET_SIZE];
|
||||
}
|
||||
// CRC Berechnung in Software durchfuehren
|
||||
printf("CRC-Berechnung in Software durchfuehren\n\n");
|
||||
for (int p = 0; p < NUMBER_PACKETS; p++) {
|
||||
crc_sw[p] = calcCRC32((uint8_t*) (&data[p][0]),
|
||||
PACKET_SIZE*4,
|
||||
paraSet.Polynomial,
|
||||
paraSet.InitalValue,
|
||||
paraSet.FinalXOR,
|
||||
paraSet.InputReflected ? 1 : 0,
|
||||
paraSet.OutputReflected ? 1 : 0
|
||||
);
|
||||
|
||||
printf("Packet %i:\t0x%08x\n", p, crc_sw[p]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Auf INT warten
|
||||
printf("Auf Interrupt warten...\n");
|
||||
int pending;
|
||||
read(fdCRC, (void*) &pending, 4);
|
||||
CRC->InterruptStatus = 0;
|
||||
write(fdCRC, (void*) &reenable, 4);
|
||||
printf("Interrupt erhalten\n");
|
||||
|
||||
// Hardwareergebnis in Array ablegen
|
||||
for (int p = 0; p < NUMBER_PACKETS; p++) {
|
||||
crc_hw[p] = DataDest[p][PACKET_SIZE];
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
// data und DataDest komplett ausgeben
|
||||
printf("\ndata\tDataDest:\n");
|
||||
for (int p = 0; p < NUMBER_PACKETS; p++) {
|
||||
for (int w = 0; w < PACKET_SIZE+1; w++) {
|
||||
#ifdef test
|
||||
// data und DataDest komplett ausgeben
|
||||
printf("\ndata\tDataDest:\n");
|
||||
for (int p = 0; p < NUMBER_PACKETS; p++) {
|
||||
for (int w = 0; w < PACKET_SIZE+1; w++) {
|
||||
|
||||
// dataDest ausgeben
|
||||
if (w < PACKET_SIZE) {
|
||||
printf("0x%08x: 0x%08x\t0x%08x: 0x%08x\n", &DataDest[p][w], DataDest[p][w], &data[p][w], data[p][w]);
|
||||
} else {
|
||||
printf("0x%08x: 0x%08x\n", &DataDest[p][w], DataDest[p][w]);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
// dataDest ausgeben
|
||||
if (w < PACKET_SIZE) {
|
||||
printf("0x%08x: 0x%08x\t0x%08x: 0x%08x\n", &DataDest[p][w], DataDest[p][w], &data[p][w], data[p][w]);
|
||||
} else {
|
||||
printf("0x%08x: 0x%08x\n", &DataDest[p][w], DataDest[p][w]);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
#endif
|
||||
|
||||
|
||||
// Daten und Ergebnisse vergleichen
|
||||
printf("Daten Ergebnisse vergleichen\n\n");
|
||||
bool allPaketsOK = true;
|
||||
for (int p = 0; p < NUMBER_PACKETS; p++) {
|
||||
bool dataOK = true;
|
||||
bool crcOK = true;
|
||||
// Daten und Ergebnisse vergleichen
|
||||
unsigned int wrongWords = 0; // Zaehler fuer Anzahl der fehlerhaften Worte im (Ziel-)Speicher
|
||||
printf("Daten Ergebnisse vergleichen\n\n");
|
||||
bool allPaketsOK = true;
|
||||
for (int p = 0; p < NUMBER_PACKETS; p++) {
|
||||
bool dataOK = true;
|
||||
bool crcOK = true;
|
||||
|
||||
printf("Paket %i:\t", p);
|
||||
printf("Paket %i:\t", p);
|
||||
|
||||
for (int w = 0; w < PACKET_SIZE; w++) {
|
||||
// Daten vergleichen
|
||||
if (data[p][w] != DataDest[p][w]) {
|
||||
dataOK = false;
|
||||
printf("Fehler bei Datenwort %i\t", w);
|
||||
}
|
||||
}
|
||||
for (int w = 0; w < PACKET_SIZE; w++) {
|
||||
// Daten vergleichen
|
||||
if (data[p][w] != DataDest[p][w]) {
|
||||
dataOK = false;
|
||||
wrongWords++;
|
||||
printf("Fehler bei Datenwort %i\t", w);
|
||||
}
|
||||
}
|
||||
|
||||
if (dataOK) {printf("Daten OK\t");}
|
||||
if (dataOK) {printf("Daten OK\t");}
|
||||
|
||||
// CRC Ergebnis vergleichen
|
||||
if (crc_hw[p] != crc_sw[p]) {
|
||||
crcOK = false;
|
||||
printf("Fehler bei CRC\t");
|
||||
}
|
||||
// CRC Ergebnis vergleichen
|
||||
if (crc_hw[p] != crc_sw[p]) {
|
||||
crcOK = false;
|
||||
wrongWords++;
|
||||
printf("Fehler bei CRC\t");
|
||||
}
|
||||
|
||||
if (crcOK) {printf("CRC OK\t");}
|
||||
if (crcOK) {printf("CRC OK\t");}
|
||||
|
||||
printf("CRC: 0x%08x\n", crc_hw[p]);
|
||||
printf("CRC: 0x%08x\n", crc_hw[p]);
|
||||
|
||||
if (!(crcOK && dataOK)) {
|
||||
allPaketsOK = false;
|
||||
}
|
||||
}
|
||||
if (!(crcOK && dataOK)) {
|
||||
allPaketsOK = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (allPaketsOK) {printf("Alle Pakete OK\n\n");}
|
||||
if (allPaketsOK) {printf("Alle Pakete OK\n\n");}
|
||||
|
||||
printf("Alle Ergebnisse verglichen\n");
|
||||
printf("Alle Ergebnisse verglichen\n");
|
||||
|
||||
return 0;
|
||||
double percentageWrong = (double) wrongWords / (DATA_SIZE + NUMBER_PACKETS);
|
||||
printf("%f Prozent der geschriebenen Worte sind fehlerhaft!\n", percentageWrong);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t calcCRC32(
|
||||
|
||||
@@ -28,7 +28,7 @@ volatile uint32_t data_dest[(PACKET_SIZE + 1)*PACKET_NUMBER];
|
||||
|
||||
int main()
|
||||
{
|
||||
PCRC_Typedef CRC = (PCRC_Typedef) 0x43c00000;
|
||||
PCRC_DMA_Typedef CRC = (PCRC_DMA_Typedef) 0x43c00000;
|
||||
|
||||
const CrcParameterSet CRC32_AXIM = {
|
||||
.Polynomial = 0x814141ab,
|
||||
|
||||
Reference in New Issue
Block a user