This commit is contained in:
altjo87133 2026-01-13 10:15:31 +01:00
parent f893162d89
commit 08dabeda61
2 changed files with 68 additions and 3 deletions

View File

@ -2,10 +2,54 @@
#include "system/hardware_task.h"
#include "system/data_channel.h"
#include "system/float_word.h"
#include <stdio.h>
#include <stdlib.h>
int data_channel_read(uint32_t base, uint32_t * value);
int data_channel_write(uint32_t base, uint32_t value);
float generate_value(uint32_t lfsr)
{
union {
uint32_t u;
float f;
} v;
uint32_t S = (lfsr >> 31) & 0x01u; // Sign
uint32_t M = lfsr & 0x007FFFFFu; // Mantisse
uint32_t E;
uint32_t E_ = (lfsr >> 23) & 0xFFu;
if (E_ & 0x80u) {
// 128 or 129
E = (0x80u) | (E_ & 0x01u);
} else {
// 124..127
E = (0x7Cu) | (E_ & 0x03u);
}
// Zusammensetzen
v.u = (S << 31) | (E << 23) | M;
return v.f;
}
int task_rand_run( void * task ) {
// TODO
rand_config * config = (rand_config *) task;
uint32_t data_channel_base = config->base.sink;
data_channel_clear(data_channel_base);
//srand(time(NULL));
float_word seed = { .value = config->seed};
uint32_t lfsr = seed.word;
for (uint32_t i = 0; i< DATA_CHANNEL_DEPTH; ++i){
float_word res;
res.value = generate_value(lfsr);
data_channel_write(data_channel_base, res.word);
uint32_t fb = ((lfsr >> 31) ^ (lfsr >> 21) ^ (lfsr >> 1) ^ (lfsr >> 0)) & 0x1u;
lfsr = (lfsr << 1) | fb;
}
return 0;
}

View File

@ -1,10 +1,31 @@
#include "system/task_sine.h"
#include "system/sine_config.h"
#include "system/data_channel.h"
#include "system/float_word.h"
#include <math.h>
#include <stdio.h>
#include <limits.h>
//int data_channel_write(uint32_t base, uint32_t value);
int task_sine_run( void * data ) {
// TODO
sine_config * task = (sine_config *) data;
uint32_t data_channel_base = task->base.sink;
data_channel_clear(data_channel_base);
for(uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i){
float_word res;
res.value = (task->amplitude) * sin((2*M_PI*i)/(task->samples_per_periode)+task->phase);
data_channel_write(data_channel_base, res.word);
}
return 0;
}