diff --git a/software/signal_processing/crc.c b/software/signal_processing/crc.c index e214b9e..0b5ffc7 100644 --- a/software/signal_processing/crc.c +++ b/software/signal_processing/crc.c @@ -5,7 +5,66 @@ 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) + + // Nachfolgende Antworten Lesen den FIFO der ersten Datenquelle aus und multiplizieren + // den jeweils gelesenen Wert mit 4 und speichern das Ergebnis in der Datensenke + for (uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i) { + 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)) ^ CRC32POLY; + } else { + c.word = (c.word * 2 + ((a.word & (1<>j)); + } + } + +/* + for (uint32_t j = 0; j < 4; j++) { + if (a.word & (1<<31)) { + c.word = (c.word * 2 + ((a.word & (0xff<>j*8)) ^ CRC32POLY; + } else { + c.word = (c.word * 2 + ((a.word & (0xff<>j*8)); + } + } +*/ + data_channel_write( config->base.sink, c.word ); + printf("a= %08x c= %08x\n", a.word, c.word); + } return 0; } +/* +crc := 0000… (Startwert) +für alle Bits b im Datenstrom: + wenn das am weitesten links stehende Bit von crc 1 ist: + crc := (crc * 2 + b) xor CRC-Polynom + sonst: + crc := crc * 2 + b +crc enthält das Ergebnis. +*/ +/* +const uint8_t bitstream[] = { 1,0,0,0,1,1,0,0 }; +const int bitcount = 8; +uint32_t crc32 = 0; // Schieberegister + +int main () +{ + for (int i = 0; i < bitcount; i++) + { + if ( ((crc32 >> 31) & 1) != bitstream[i]) + crc32 = (crc32 << 1) ^ CRC32POLY; + else + crc32 = (crc32 << 1); + } + printf ("0x%08X\n", crc32); +} +*/ diff --git a/software/signal_processing/system/task_crc.h b/software/signal_processing/system/task_crc.h index 60301bd..4b45dd3 100644 --- a/software/signal_processing/system/task_crc.h +++ b/software/signal_processing/system/task_crc.h @@ -9,7 +9,8 @@ extern "C" { extern crc_config CRC_CONFIG; -#define CRC32POLY 0xEDB88320 /* CRC-32 Polynom (Invers)*/ +//#define CRC32POLY 0xEDB88320 /* CRC-32 Polynom (Invers)*/ +#define CRC32POLY 0x04C11DB7 int task_crc_run( void * task ); diff --git a/tests/software/task_crc/test_task_crc b/tests/software/task_crc/test_task_crc new file mode 100755 index 0000000..9c4c5c5 Binary files /dev/null and b/tests/software/task_crc/test_task_crc differ