schmidtsv99309 7dd0ffc130 Fertig
2024-12-18 10:56:27 +01:00

46 lines
944 B
C

#include "system/task_rand.h"
#include "system/hardware_task.h"
#include "system/data_channel.h"
#include "system/float_word.h"
#include <stdio.h>
#include <system.h>
int task_rand_run(void *task) {
rand_config *config = (rand_config *)task;
uint32_t data_channel_base = DATA_CHANNEL_2_BASE;
uint32_t lfsr = config->seed;
for (uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i) {
uint32_t bit = ((lfsr >> 31) ^ (lfsr >> 21) ^ (lfsr >> 1) ^ (lfsr >> 0)) & 1;
lfsr = (lfsr << 1) | bit;
float_word res;
res.word = lfsr;
uint32_t exponent = (lfsr >> 23) & 0xFF;
if (exponent & 0x80) {
exponent = 0x80 | (lfsr & 0x01);
}else {
exponent = 0x7C | (lfsr & 0x03);
}
res.word &= ~(0xFF << 23);
res.word |= (exponent << 23);
data_channel_write(data_channel_base, res.word);
}
return 0;
}