This commit is contained in:
leitnerti80244
2024-01-09 08:49:42 +01:00
parent 0d1b73e3e0
commit 73c4f491fd
6 changed files with 318 additions and 32 deletions
+64 -1
View File
@@ -2,9 +2,72 @@
#include "system/data_channel.h"
#include "system/float_word.h"
#include <math.h>
#include <stdio.h>
typedef struct {
float value;
} Result;
void generateSinusCurve(float samples_per_period, float phase, float amplitude, Result res[]) {
float delta_phase = 2.0 * M_PI / samples_per_period;
float current_phase = phase;
for (int i = 0; i < DATA_CHANNEL_DEPTH; ++i) {
res[i].value = amplitude * sinf(current_phase);
current_phase += delta_phase;
}
}
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 );
float_word res;
//float samples_per_period = 32.0;
float samples_per_period = task ->samples_per_periode;
float phase = task-> phase;
float amplitude = task -> amplitude;
Result results[DATA_CHANNEL_DEPTH];
generateSinusCurve(samples_per_period, phase, amplitude, results);
for (int i = 0; i < DATA_CHANNEL_DEPTH; ++i) {
//printf("Wert %d: %f\n", i, results[i].value);
res.value = results[i].value;
data_channel_write( data_channel_base, res.word);
}
return 0;
}
@@ -24,7 +24,7 @@ sine_config SINE_CONFIG = {
.sink = DATA_CHANNEL_0_BASE,
.cycle_count = 0 },
.samples_per_periode = 32,
.phase = 0.0,
.phase = 0,
.amplitude = 4.0 };
sine_config COSINE_CONFIG = {