#include "system/task_rand.h" #include "system/hardware_task.h" #include "system/data_channel.h" #include "system/float_word.h" #include #include int task_rand_run( void * task ) { // Nachfolgende Anweisungen Schreiben 1024 Mal den seed Wert in den FIFO für Rand rand_config * config = ( rand_config * ) task; float_word seed = {.value = config->seed}; uint32_t lfsr = seed.word; uint32_t bit = 0; // Must be 32-bit to allow bit << 31 later in the code for( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; i++ ) { float_word res; uint32_t sign = (lfsr >> 31) & 1; uint32_t exponent; uint32_t mantisse = lfsr & 0x7FFFFF; if((lfsr >> 30) & 1) // MSB exponent { exponent = 128 + ((lfsr >> 23) & 1); // 128 to 129 } else { exponent = 124 + ((lfsr >> 23) & 3); // 124 to 127 } uint32_t ieee754 = (sign << 31) | (exponent << 23) | mantisse; res.value = ieee754; data_channel_write( config->base.sink, ieee754); // fibonacci feedback polynomial: x^31 + x^21 + x^1 + 1 bit = ((lfsr >> 31) ^ (lfsr >> 21) ^ (lfsr >> 1)) & 1; lfsr = (lfsr << 1) | bit; } return 0; }