axi_crc_dma als eigenes Blockschaltbild
This commit is contained in:
@@ -1,59 +1,177 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "axi_crc_dma.h"
|
||||
#include "gip.h"
|
||||
|
||||
|
||||
// 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
|
||||
);
|
||||
|
||||
|
||||
static char msg[] = "Hello World!ABCDEFGHIJKL";
|
||||
volatile static uint8_t dest[32];
|
||||
volatile static uint8_t dest2[32];
|
||||
|
||||
static uint32_t crc_sw[10];
|
||||
static uint32_t crc_hw[10];
|
||||
|
||||
volatile static uint8_t data[128];
|
||||
volatile static uint8_t data_dest[200];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
volatile uint32_t Control; // [0] Run, [1] INT Enable
|
||||
volatile uint32_t InterruptStatus; // [0] INT Status
|
||||
volatile uint32_t ReadAddress; // [31:0] Read Address of Data
|
||||
volatile uint32_t WriteAddress; // [31:0] Write Address of Data
|
||||
volatile uint32_t PacketSize; // [15:0] Size of Packets in 32 Bit words
|
||||
volatile uint32_t NumberPackets; // [15:0] Number of Packets
|
||||
volatile uint32_t Polynomial; // [31:0] Polynomial for CRC Calculation
|
||||
volatile uint32_t InitialValue; // [31:0] Intial Value of CRC Calculation
|
||||
} CRC_Typedef;
|
||||
|
||||
static char msg[] = "Hello World!";
|
||||
|
||||
int main()
|
||||
{
|
||||
CRC_Typedef* CRC = (CRC_Typedef*) 0x43c00000;
|
||||
PCRC_Typedef CRC = (PCRC_Typedef) 0x43c00000;
|
||||
PGIP_AXI_2D_MM2VS MM2VS = (PGIP_AXI_2D_MM2VS) 0x43C10000;
|
||||
|
||||
printf("Hello\n");
|
||||
CrcParameterSet custom = {
|
||||
.Polynomial = 0xF4ACFB13,
|
||||
.InitalValue = 0xFFFFFFFF,
|
||||
.FinalXOR = 0xFFFFFFFF,
|
||||
.InputReflected = false,
|
||||
.OutputReflected = false
|
||||
};
|
||||
|
||||
uint8_t dest[13];
|
||||
for (int i = 0; i < 128; i++) data[i] = 0;
|
||||
for (uint32_t i = 0; i < 32; i++) {
|
||||
data[4*i] = i;
|
||||
}
|
||||
|
||||
// Schreib- und Leseadresse setzen
|
||||
// MM2VS Komponeten parametrieren und starten
|
||||
MM2VS->MM2VS_Control &= ~(1<<0);
|
||||
MM2VS->VS2MM_Control &= ~(1<<0);
|
||||
|
||||
MM2VS->InterruptEnable = 0; // INTs deaktivieren
|
||||
MM2VS->MM2VS_StartAddress = (uint32_t) msg;
|
||||
MM2VS->MM2VS_HorizontalBytes = 24;
|
||||
MM2VS->MM2VS_Stride = 24;
|
||||
MM2VS->MM2VS_LineNumber = 0;
|
||||
|
||||
MM2VS->VS2MM_StartAddress = (uint32_t) dest;
|
||||
MM2VS->VS2MM_HorizontalBytes = 24;
|
||||
MM2VS->VS2MM_Stride = 24;
|
||||
MM2VS->VS2MM_LineNumber = 0;
|
||||
|
||||
MM2VS->MM2VS_Control |= (1<<0);
|
||||
MM2VS->VS2MM_Control |= (1<<0);
|
||||
|
||||
// axi_crc_dam Komponete parametrieren
|
||||
CRC->ReadAddress = (uint32_t) msg;
|
||||
CRC->WriteAddress = (uint32_t) dest;
|
||||
|
||||
// Packetgroesse und -anzahl setzen
|
||||
CRC->WriteAddress = (uint32_t) data_dest;
|
||||
CRC->PacketSize = 2;
|
||||
CRC->NumberPackets = 0;
|
||||
CRC->NumberPackets = 1;
|
||||
CRC->Polynomial = custom.Polynomial;
|
||||
CRC->InitialValue = custom.InitalValue;
|
||||
CRC->FinalXOR = custom.FinalXOR;
|
||||
if (custom.InputReflected) {CRC->InOutReflected |= (1<<0);}
|
||||
else {CRC->InOutReflected &= ~(1<<0);}
|
||||
if (custom.OutputReflected) {CRC->InOutReflected |= (1<<1);}
|
||||
else {CRC->InOutReflected &= ~(1<<1);}
|
||||
|
||||
// Generatorpolynom und Initialwert setzen
|
||||
CRC->Polynomial = 0x814141AB;
|
||||
CRC->InitialValue = 0xFFFFFFFF;
|
||||
|
||||
//
|
||||
|
||||
// Interrupt aktivieren
|
||||
CRC->Control |= (1<<1);
|
||||
// CRC->Control |= (1<<1);
|
||||
|
||||
// IP starten
|
||||
CRC->Control |= (1<<0);
|
||||
CRC->Control = 1;
|
||||
|
||||
while (1) {
|
||||
// Status abfragen
|
||||
if ((CRC->Control & (1<<0)) == 0) {
|
||||
|
||||
// Interrupt zuruecksetzen
|
||||
CRC->InterruptStatus = 0;
|
||||
|
||||
// Erneut starten
|
||||
CRC->Control |= (1<<0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
dest2[i] = dest[i];
|
||||
}
|
||||
|
||||
// Interrupt zuruecksetzen
|
||||
CRC->InterruptStatus = 0;
|
||||
|
||||
custom.InputReflected = true;
|
||||
custom.OutputReflected = true;
|
||||
|
||||
if (custom.InputReflected) {CRC->InOutReflected |= (1<<0);}
|
||||
else {CRC->InOutReflected &= ~(1<<0);}
|
||||
if (custom.OutputReflected) {CRC->InOutReflected |= (1<<1);}
|
||||
else {CRC->InOutReflected &= ~(1<<1);}
|
||||
|
||||
// Erneut starten
|
||||
CRC->Control |= (1<<0);
|
||||
CRC->Control |= (1<<0);
|
||||
|
||||
// Hardwareergebnis und Softwareergebnisse ablegen
|
||||
uint32_t packets = CRC->NumberPackets + 1;
|
||||
uint32_t size = CRC->PacketSize + 1;
|
||||
for (int i = 0; i < packets; i++) {
|
||||
crc_sw[i] = calcCRC32((uint8_t*) CRC->ReadAddress+i*size, size*4, custom.Polynomial, custom.InitalValue, custom.FinalXOR, custom.InputReflected ? 1 : 0, custom.OutputReflected ? 1 : 0);
|
||||
crc_hw[i] = ((uint32_t*)CRC->WriteAddress)[size + i*(size)];
|
||||
}
|
||||
|
||||
CRC->Polynomial = 0x0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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++) {
|
||||
byte = inBytes[i];
|
||||
|
||||
if (inputReflected != 0) {
|
||||
uint8_t reflected = 0;
|
||||
|
||||
for (int b = 0; b < 8; b++) {
|
||||
if ((byte & (1<<b)) != 0) {
|
||||
reflected |= (uint8_t) (1<<(7-b));
|
||||
}
|
||||
}
|
||||
byte = reflected;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user