|
|
|
|
|
|
|
|
#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> |
|
|
|
|
|
|
|
|
int task_crc_run( void * task ) { |
|
|
|
|
|
|
|
|
|
|
|
// TODO |
|
|
|
|
|
crc_config * config = ( crc_config *) task; |
|
|
|
|
|
|
|
|
|
|
|
uint32_t value = config->start; // Startwert CRC vom gewaehlten Algorithmus (wird erst in der Funktion invertiert) |
|
|
|
|
|
|
|
|
// 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 ) { |
|
|
|
|
|
crc_config * config = (crc_config*) task; |
|
|
|
|
|
uint32_t value = config->start; |
|
|
// 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 ); |
|
|
|
|
|
float_word c; |
|
|
|
|
|
//c.value = 4*a; //Hier mit Werten aus CRC FIFO multiplizieren |
|
|
|
|
|
c.value = 0; |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
data_channel_read(config->base.sources[0], (uint32_t * ) & a.value ); |
|
|
|
|
|
if (i<10) {printf("\n Input %i DATA; %x\ CRC: %x\n", i, a.word, value);} |
|
|
|
|
|
berechne_crc32(a.word, &value); //Startwert jedes Mal, oder mit vorheriger crc starten? |
|
|
|
|
|
if (i<10) {printf("\n CRC Zwischenwert Output(%i): %x\n", i, value);} |
|
|
} |
|
|
} |
|
|
|
|
|
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: |
|
|
|
|
|
|
|
|
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 |