Lösung Praktikum HW/SW

This commit is contained in:
pfeiffjo103624
2026-01-13 10:05:02 +01:00
parent c90753aa23
commit b5e28ecc9d
7 changed files with 527 additions and 87 deletions
+19 -2
View File
@@ -2,9 +2,26 @@
#include "system/data_channel.h"
#include "system/float_word.h"
int task_add_run( void * task ) {
int task_add_run( void * task )
{
// Die Task-Einstellungen liegen als task_base_config vor
task_base_config *config = (task_base_config *) task;
// TODO
for (uint32_t i = 0; i < DATA_CHANNEL_DEPTH; i++) {
float_word a, b, c;
// aus Quelle 0 lesen
data_channel_read(config->sources[0], &a.word);
// aus Quelle 1 lesen
data_channel_read(config->sources[1], &b.word);
// Addition der beiden Float-Werte
c.value = a.value + b.value;
// Ergebnis in den Ziel-Data-Channel schreiben
data_channel_write(config->sink, c.word);
}
return 0;
}
+38 -2
View File
@@ -2,10 +2,46 @@
#include "system/data_channel.h"
#include "system/float_word.h"
int task_crc_run( void * task ) {
#define CRC32_POLY_REVERSED 0xEDB88320u
// TODO
// CRC32-Update über ein komplettes 32-bit Wort (LSB-first)
static inline uint32_t crc32_update_word(uint32_t crc, uint32_t word)
{
for (int i = 0; i < 4; i++)
{
uint8_t b = (word >> (8 * i)) & 0xFF; // LSB first!
crc ^= b;
for (int j = 0; j < 8; j++)
{
if (crc & 1)
crc = (crc >> 1) ^ CRC32_POLY_REVERSED;
else
crc >>= 1;
}
}
return crc;
}
int task_crc_run(void *task)
{
crc_config *config = (crc_config*)task;
// WICHTIG: Startwert invertieren (wie im PDF Seite 14 beschrieben)
uint32_t crc = ~config->start; // = ~0xFFFFFFFF = 0x00000000
for (uint32_t i = 0; i < DATA_CHANNEL_DEPTH; i++)
{
uint32_t word;
data_channel_read(config->base.sources[0], &word);
crc = crc32_update_word(crc, word);
}
// Endwert invertieren (zlib-Standard)
crc = ~crc;
// Ergebnis schreiben
data_channel_write(config->base.sink, crc);
return 0;
}
+27 -2
View File
@@ -1,10 +1,35 @@
#include "system/task_sine.h"
#include "system/data_channel.h"
#include "system/float_word.h"
#include <math.h>
int task_sine_run( void * data ) {
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
// TODO
int task_sine_run(void *data)
{
sine_config *task = (sine_config *) data;
uint32_t data_channel_base = task->base.sink;
data_channel_clear(data_channel_base);
float amplitude = task->amplitude;
float phase_rad = task->phase * (float)M_PI / 180.0f;
float step = 2.0f * (float)M_PI / (float)task->samples_per_periode;
for (uint32_t i = 0; i < DATA_CHANNEL_DEPTH; i++)
{
float angle = phase_rad + i * step;
float y = amplitude * sinf(angle);
float_word res;
res.value = y;
data_channel_write(data_channel_base, res.word);
}
return 0;
}
@@ -37,7 +37,7 @@ sine_config COSINE_CONFIG = {
.sink = DATA_CHANNEL_1_BASE,
.cycle_count = 0 },
.samples_per_periode = 200,
.phase = M_PI / 2.0,
.phase = 90.0,
.amplitude = 2.0 };
uint32_t to_hardware_step_size( uint32_t steps ) {