Versuch 3 CRC, Software fertig
This commit is contained in:
parent
45db9f89e2
commit
118d08219e
@ -1,47 +1,87 @@
|
|||||||
#include "system/task_crc.h"
|
#include "system/task_crc.h"
|
||||||
#include "system/data_channel.h"
|
#include "system/data_channel.h"
|
||||||
#include "system/float_word.h"
|
#include "system/float_word.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
// Funktion zur Berechnung des CRC32
|
||||||
|
void berechne_crc32(uint32_t data, uint32_t * crc);
|
||||||
|
void crc32( uint32_t data, uint32_t* crc );
|
||||||
|
|
||||||
int task_crc_run( void * task ) {
|
int task_crc_run( void * task ) {
|
||||||
|
crc_config * config = (crc_config*) task;
|
||||||
// TODO
|
uint32_t value = config->start;
|
||||||
crc_config * config = ( crc_config *) task;
|
|
||||||
|
|
||||||
uint32_t value = config->start; // Startwert CRC vom gewaehlten Algorithmus (wird erst in der Funktion invertiert)
|
|
||||||
|
|
||||||
// Nachfolgende Antworten Lesen den FIFO der ersten Datenquelle aus und multiplizieren
|
// Nachfolgende Antworten Lesen den FIFO der ersten Datenquelle aus und multiplizieren
|
||||||
// den jeweils gelesenen Wert mit 4 und speichern das Ergebnis in der Datensenke
|
// den jeweils gelesenen Wert mit 4 und speichern das Ergebnis in der Datensenke
|
||||||
for (uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i) {
|
for (uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i) {
|
||||||
float_word a;
|
float_word a;
|
||||||
data_channel_read(config->base.sources[0], (uint32_t * ) & a.word );
|
data_channel_read(config->base.sources[0], (uint32_t * ) & a.value );
|
||||||
float_word c;
|
if (i<10) {printf("\n Input %i DATA; %x\ CRC: %x\n", i, a.word, value);}
|
||||||
//c.value = 4*a; //Hier mit Werten aus CRC FIFO multiplizieren
|
berechne_crc32(a.word, &value); //Startwert jedes Mal, oder mit vorheriger crc starten?
|
||||||
c.value = 0;
|
if (i<10) {printf("\n CRC Zwischenwert Output(%i): %x\n", i, value);}
|
||||||
|
|
||||||
for (uint32_t j = 0; j < 32; j++) {
|
|
||||||
if (a.word & (1<<31)) {
|
|
||||||
c.word = (c.word * 2 + ((a.word & (1<<j))>>j)) ^ CRC32POLY;
|
|
||||||
} else {
|
|
||||||
c.word = (c.word * 2 + ((a.word & (1<<j))>>j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
for (uint32_t j = 0; j < 4; j++) {
|
|
||||||
if (a.word & (1<<31)) {
|
|
||||||
c.word = (c.word * 2 + ((a.word & (0xff<<j*8))>>j*8)) ^ CRC32POLY;
|
|
||||||
} else {
|
|
||||||
c.word = (c.word * 2 + ((a.word & (0xff<<j*8))>>j*8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
data_channel_write( config->base.sink, c.word );
|
|
||||||
printf("a= %08x c= %08x\n", a.word, c.word);
|
|
||||||
}
|
}
|
||||||
|
printf("CRC Wert: %x\n", value);
|
||||||
|
data_channel_write( config->base.sink, value);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// Funktion zur Berechnung des CRC32
|
||||||
|
void crc32( uint32_t data, uint32_t* crc ) {
|
||||||
|
uint32_t byte_array[4];
|
||||||
|
uint32_t reg32 = ~*crc;
|
||||||
|
|
||||||
|
byte_array[3] = (uint32_t) (data>>24) & 0x000000FF;
|
||||||
|
byte_array[2] = (uint32_t) (data>>16) & 0x000000FF;
|
||||||
|
byte_array[1] = (uint32_t) (data>>8) & 0x000000FF;
|
||||||
|
byte_array[0] = (uint32_t) (data) & 0x000000FF;
|
||||||
|
|
||||||
|
for ( uint32_t i = 0; i < 4; ++i ) {
|
||||||
|
for ( uint8_t j = 0; j < 8; ++j ) {
|
||||||
|
|
||||||
|
if ((reg32&1) != (byte_array[i]&1)) { // != hat Prio 7, & hat Prio 8!
|
||||||
|
reg32 = (reg32>>1)^CRC32POLY;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reg32 >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte_array[i] >>= 1;
|
||||||
|
}
|
||||||
|
*crc= reg32 ^ 0xffffffff; //inverses Ergebnis, MSB zuerst
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void berechne_crc32(uint32_t data, uint32_t * crc) {
|
||||||
|
uint32_t bytes[4]; //Reihenfolge richtig?
|
||||||
|
uint32_t reg32 = ~*crc;
|
||||||
|
|
||||||
|
bytes[0] = (uint32_t) (data) & 0x000000FF;
|
||||||
|
bytes[1] = (uint32_t) (data >>8) & 0x000000FF;
|
||||||
|
bytes[2] = (uint32_t) (data >>16) & 0x000000FF;
|
||||||
|
bytes[3] = (uint32_t) (data >>24) & 0x000000FF; //aufffüllen
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < 4; i++) {
|
||||||
|
//von rechts nch links
|
||||||
|
for (uint8_t j = 0; j <8; j++) {
|
||||||
|
|
||||||
|
// Prüfen, ob das am weitesten rechts stehende Bit von crc 1 ist
|
||||||
|
if ((reg32 & 1) != (bytes[i] & 1)) { //Wieso crc & 1?
|
||||||
|
reg32 = (reg32 >> 1)^CRC32POLY; // XOR mit dem Polynom
|
||||||
|
} else {
|
||||||
|
reg32 >>= 1;
|
||||||
|
}
|
||||||
|
bytes[i]>>=1;
|
||||||
|
}
|
||||||
|
*crc = reg32 ^0xFFFFFFFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
crc := 0000… (Startwert)
|
crc := 0000… (Startwert)
|
||||||
für alle Bits b im Datenstrom:
|
für alle Bits b im Datenstrom:
|
||||||
@ -52,6 +92,15 @@ für alle Bits b im Datenstrom:
|
|||||||
crc enthält das Ergebnis.
|
crc enthält das Ergebnis.
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
|
for (uint32_t j = 0; j < 32; j++) {
|
||||||
|
if (a.word & (1<<31)) {
|
||||||
|
c.word = (c.word * 2 + ((a.word & (1<<j))>>j)) ^ CRC32POLY;
|
||||||
|
} else {
|
||||||
|
c.word = (c.word * 2 + ((a.word & (1<<j))>>j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
const uint8_t bitstream[] = { 1,0,0,0,1,1,0,0 };
|
const uint8_t bitstream[] = { 1,0,0,0,1,1,0,0 };
|
||||||
const int bitcount = 8;
|
const int bitcount = 8;
|
||||||
uint32_t crc32 = 0; // Schieberegister
|
uint32_t crc32 = 0; // Schieberegister
|
||||||
|
@ -9,8 +9,8 @@ extern "C" {
|
|||||||
|
|
||||||
extern crc_config CRC_CONFIG;
|
extern crc_config CRC_CONFIG;
|
||||||
|
|
||||||
//#define CRC32POLY 0xEDB88320 /* CRC-32 Polynom (Invers)*/
|
#define CRC32POLY 0xEDB88320 /* CRC-32 Polynom (Invers)*/
|
||||||
#define CRC32POLY 0x04C11DB7
|
//#define CRC32POLY 0x04C11DB7
|
||||||
|
|
||||||
int task_crc_run( void * task );
|
int task_crc_run( void * task );
|
||||||
|
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user