Loesung von add sin cos und rand
This commit is contained in:
@@ -2,10 +2,23 @@
|
||||
#include "system/data_channel.h"
|
||||
#include "system/float_word.h"
|
||||
|
||||
int task_add_run( void * task ) {
|
||||
int task_add_run( void * task )
|
||||
{
|
||||
add_config * config = (add_config * ) task;
|
||||
|
||||
// TODO
|
||||
// Nachfolgende Antworten Lesen den FIFO der ersten und zweiten Datenquelle aus
|
||||
// den jeweils gelesenen Wert mit 4 und speichern das Ergebnis in der Datensenke
|
||||
for (uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i)
|
||||
{
|
||||
float a, b;
|
||||
data_channel_read( config->sources[0], (uint32_t *) & a );
|
||||
data_channel_read( config->sources[1], (uint32_t *) & b );
|
||||
|
||||
float_word c;
|
||||
c.value = a + b;
|
||||
data_channel_write( config->sink, c.word );
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,43 @@
|
||||
#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 ) {
|
||||
|
||||
// TODO
|
||||
// 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};
|
||||
|
||||
return 0;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
#include "system/task_sine.h"
|
||||
#include "system/data_channel.h"
|
||||
#include "system/float_word.h"
|
||||
#include <math.h>
|
||||
|
||||
int task_sine_run( void * data ) {
|
||||
|
||||
// TODO
|
||||
// Nachfolgende Anweisungen Schreiben 1024 Mal den Wert 4 in den FIFO für Sinus
|
||||
sine_config * task = ( sine_config * ) data;
|
||||
uint32_t data_channel_base = task->base.sink;
|
||||
data_channel_clear( data_channel_base );
|
||||
|
||||
return 0;
|
||||
for( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; i++ ) {
|
||||
float_word res;
|
||||
res.value = task->amplitude * sin((2 * M_PI / task->samples_per_periode) * i + task->phase );
|
||||
|
||||
data_channel_write( data_channel_base, res.word );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user