Komischer Fehler: IP kann nicht in Speicher schreiben
This commit is contained in:
+110
-35
@@ -13,46 +13,90 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "axi_crc_dma.h"
|
||||
#include "gip.h"
|
||||
|
||||
|
||||
#define PACKET_SIZE 50
|
||||
#define NUMBER_PACKETS 10
|
||||
#define PACKET_SIZE 3
|
||||
#define NUMBER_PACKETS 2
|
||||
|
||||
|
||||
uint32_t calcCRC32(uint8_t* inBytes, size_t size, uint32_t polynomial, uint32_t initialValue);
|
||||
// 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
|
||||
);
|
||||
|
||||
// UIO & pointers
|
||||
int fdCRC = open("/dev/uio0", O_RDWR);
|
||||
int fdMMVS = open("/dev/uio1", O_RDWR);
|
||||
int fdMem = open("/dev/uio16", O_RDWR);
|
||||
PCRC_Typedef CRC = (PCRC_Typedef)mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fdCRC, 0);
|
||||
PGIP_AXI_2D_MM2VS mmvs = (PGIP_AXI_2D_MM2VS)mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fdMMVS, 0);
|
||||
uint8_t* pMem = (uint8_t*)mmap(NULL, 0x20000000, PROT_READ | PROT_WRITE, MAP_SHARED, fdMem, 0);
|
||||
|
||||
// Speicherbereiche fuer Daten anlegen
|
||||
static uint32_t data[NUMBER_PACKETS][PACKET_SIZE];
|
||||
static uint32_t data_CRC[NUMBER_PACKETS][PACKET_SIZE+1];
|
||||
//volatile static uint32_t data[NUMBER_PACKETS][PACKET_SIZE];
|
||||
//volatile static uint32_t data_CRC[NUMBER_PACKETS][PACKET_SIZE+1];
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
printf("Start Program\n");
|
||||
|
||||
int fdCRC = open("/dev/uio0", O_RDWR);
|
||||
PCRC_Typedef CRC = (PCRC_Typedef)mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fdCRC, 0);
|
||||
uint32_t* data = (uint32_t*) pMem;
|
||||
uint32_t* data_CRC = data + (NUMBER_PACKETS*PACKET_SIZE);
|
||||
|
||||
uint32_t polynomial = 0x4C11DB7;
|
||||
uint32_t InitialValue = 0;
|
||||
|
||||
// AXI_CRC_DMA Hardwarekomponente initialisieren
|
||||
CRC->Control |= (1<<1); // INT deaktivieren
|
||||
CRC->Polynomial = polynomial;
|
||||
CRC->InitialValue = InitialValue;
|
||||
CRC->NumberPackets = NUMBER_PACKETS - 1;
|
||||
CRC->PacketSize = PACKET_SIZE - 1;
|
||||
CRC->ReadAddress = (uint32_t) data;
|
||||
CRC->WriteAddress = (uint32_t) data_CRC;
|
||||
printf("pMem: %x\ndata: %x\ndata_CRC: %x\n\n", pMem, data, data_CRC);
|
||||
|
||||
// Testdaten erzeugen
|
||||
printf("Testdaten erzeugen\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();
|
||||
*(data+packet+word) = (uint32_t) rand();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t polynomial = 0x4C11DB7;
|
||||
uint32_t InitialValue = 0;
|
||||
|
||||
// MM2VS Komponeten parametrieren und starten
|
||||
mmvs->VS2MM_Control &= ~1; // VS2MM: Run-Bit loeschen
|
||||
mmvs->MM2VS_Control &= ~1; // MM2VS: Run-Bit loeschen
|
||||
usleep(500000); // 500 ms warten. Falls das MMVS-IP noch aktiv war, kann es so noch ausstehende Speicherzugriffe beenden
|
||||
|
||||
mmvs->InterruptEnable = 0; // INTs deaktivieren
|
||||
mmvs->InterruptStatus = 0;
|
||||
mmvs->MM2VS_StartAddress = (uint32_t) data;
|
||||
mmvs->MM2VS_HorizontalBytes = 24;
|
||||
mmvs->MM2VS_Stride = 24;
|
||||
mmvs->MM2VS_LineNumber = 0;
|
||||
|
||||
mmvs->VS2MM_StartAddress = (uint32_t) data_CRC;
|
||||
mmvs->VS2MM_HorizontalBytes = 24;
|
||||
mmvs->VS2MM_Stride = 24;
|
||||
mmvs->VS2MM_LineNumber = 0;
|
||||
|
||||
mmvs->MM2VS_Control |= (1<<0);
|
||||
mmvs->VS2MM_Control |= (1<<0);
|
||||
|
||||
|
||||
// AXI_CRC_DMA Hardwarekomponente initialisieren
|
||||
CRC->Control |= (1<<1); // INT aktivieren
|
||||
CRC->Polynomial = polynomial;
|
||||
CRC->InitialValue = InitialValue;
|
||||
CRC->NumberPackets = NUMBER_PACKETS - 1;
|
||||
CRC->PacketSize = PACKET_SIZE - 1;
|
||||
CRC->ReadAddress = (uint32_t) data;
|
||||
CRC->WriteAddress = (uint32_t) data_CRC;
|
||||
CRC->FinalXOR = 0;
|
||||
CRC->InOutReflected = 0;
|
||||
|
||||
// CRC Berechnung mit Hardware durchfuehren
|
||||
printf("Berechnung in Hardware starten\n");
|
||||
CRC->Control |= (1<<0);
|
||||
@@ -61,7 +105,7 @@ int main(int argc, char** argv)
|
||||
printf("Berechnung in Software durchfuehren\n");
|
||||
uint32_t CRCs[NUMBER_PACKETS];
|
||||
for (int i = 0; i < NUMBER_PACKETS; i++) {
|
||||
CRCs[i] = calcCRC32((uint8_t*) data[i], PACKET_SIZE*4, polynomial, InitialValue);
|
||||
CRCs[i] = calcCRC32((uint8_t*) data[i], PACKET_SIZE*4, polynomial, InitialValue, 0, 0, 0);
|
||||
}
|
||||
|
||||
// Auf INT warten
|
||||
@@ -75,36 +119,67 @@ int main(int argc, char** argv)
|
||||
|
||||
// Ergebnisse vergleichen
|
||||
printf("Ergebnisse vergleichen\n");
|
||||
for (int i = NUMBER_PACKETS; i < NUMBER_PACKETS; i++) {
|
||||
if (CRCs[i] != data_CRC[i][PACKET_SIZE]) {
|
||||
for (int i = 0; i < NUMBER_PACKETS; i++) {
|
||||
if (CRCs[i] != *(data_CRC+i+PACKET_SIZE)) {
|
||||
printf("Fehler\n");
|
||||
}
|
||||
}
|
||||
printf("Alle Ergebnisse verglichen\n");
|
||||
|
||||
// MMVS anhalten
|
||||
mmvs->VS2MM_Control &= ~1; // VS2MM: Run-Bit loeschen
|
||||
mmvs->MM2VS_Control &= ~1; // MM2VS: Run-Bit loeschen
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t calcCRC32(uint8_t* inBytes, size_t size, uint32_t polynomial, uint32_t initialValue)
|
||||
{
|
||||
uint32_t calcCRC32(
|
||||
uint8_t* inBytes,
|
||||
size_t size,
|
||||
uint32_t polynomial,
|
||||
uint32_t initialValue,
|
||||
uint32_t finalXOR,
|
||||
uint8_t inputReflected,
|
||||
uint8_t outputReflected
|
||||
) {
|
||||
uint32_t crc = initialValue;
|
||||
uint8_t byte;
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
for (int bit = 7; bit >= 0; bit--) {
|
||||
// get next bit
|
||||
uint8_t inBit = (inBytes[i] & (1<<bit)) ? 1 : 0;
|
||||
byte = inBytes[i];
|
||||
|
||||
// check if MSB is set
|
||||
uint32_t MSB_high = crc & 0x80000000;
|
||||
if (inputReflected != 0) {
|
||||
uint8_t reflected = 0;
|
||||
|
||||
// input Bit reinschieben
|
||||
crc <<= 1;
|
||||
crc ^= inBit;
|
||||
for (int b = 0; b < 8; b++) {
|
||||
if ((byte & (1<<b)) != 0) {
|
||||
reflected |= (uint8_t) (1<<(7-b));
|
||||
}
|
||||
}
|
||||
byte = reflected;
|
||||
}
|
||||
|
||||
if (MSB_high) {
|
||||
crc ^= polynomial;
|
||||
crc ^= (uint32_t) (byte << 24);
|
||||
|
||||
for (int bit = 0; bit < 8; bit++) {
|
||||
if ((crc & (uint32_t)(1<<31)) != 0) {
|
||||
crc = (uint32_t) (crc << 1) ^ polynomial;
|
||||
} else {
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
|
||||
if (outputReflected != 0) {
|
||||
uint32_t reflected = 0;
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if ((crc & (uint32_t) (1<<i)) != 0) {
|
||||
reflected |= (uint32_t) (1<<(31-i));
|
||||
}
|
||||
}
|
||||
crc = reflected;
|
||||
}
|
||||
|
||||
return crc ^ finalXOR;
|
||||
}
|
||||
|
||||
@@ -42,11 +42,11 @@ int main()
|
||||
{
|
||||
// Testweise Pruefsumme berechnen und ausgeben
|
||||
char msg[] = "Hello World!";
|
||||
uint32_t crc = calcCRC32((uint8_t*) msg, strlen(msg), 0xF4ACFB13, 0xFFFFFFFF, 0xFFFFFFFF, 1, 1);
|
||||
uint32_t crc = calcCRC32((uint8_t*) msg, strlen(msg), 0xF4ACFB13, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0);
|
||||
printf("CRC32 of '%s': 0x%08x\n\n", msg, crc);
|
||||
|
||||
char msg2[] = "ABCDEFGHIJKL";
|
||||
crc = calcCRC32((uint8_t*) msg2, strlen(msg2), 0xF4ACFB13, 0xFFFFFFFF, 0xFFFFFFFF, 1, 1);
|
||||
crc = calcCRC32((uint8_t*) msg2, strlen(msg2), 0xF4ACFB13, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0);
|
||||
printf("CRC32 of '%s': 0x%08x\n\n", msg2, crc);
|
||||
|
||||
uint8_t data[128];
|
||||
|
||||
Reference in New Issue
Block a user