crc staengert
This commit is contained in:
@@ -2,10 +2,39 @@
|
||||
#include "system/data_channel.h"
|
||||
#include "system/float_word.h"
|
||||
|
||||
int task_crc_run( void * task ) {
|
||||
#define CRC32_POLY 0xEDB88320
|
||||
#define CRC32_INIT 0xFFFFFFFF
|
||||
#define DATA_CHANNEL_DEPTH 1024
|
||||
|
||||
// TODO
|
||||
static uint32_t crc32_update(uint32_t crc, uint32_t data) {
|
||||
int i;
|
||||
crc ^= data;
|
||||
for (i = 0; i < 32; i++) {
|
||||
if (crc & 1) {
|
||||
crc = (crc >> 1) ^ CRC32_POLY;
|
||||
} else {
|
||||
crc >>= 1;
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
int task_crc_run(void *task) {
|
||||
crc_config *config = (crc_config *)task;
|
||||
uint32_t source_base = config->base.sources[0];
|
||||
uint32_t sink_base = config->base.sink;
|
||||
uint32_t crc = CRC32_INIT;
|
||||
uint32_t value;
|
||||
|
||||
for (uint32_t i = 0; i < DATA_CHANNEL_DEPTH; i++) {
|
||||
data_channel_read(source_base, &value);
|
||||
crc = crc32_update(crc, value);
|
||||
}
|
||||
|
||||
crc ^= 0xFFFFFFFF;
|
||||
|
||||
data_channel_write(sink_base, crc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,26 @@
|
||||
#include "system/data_channel.h"
|
||||
#include "system/float_word.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
int task_sine_run( void * data ) {
|
||||
|
||||
// TODO
|
||||
sine_config *task = (sine_config *)data;
|
||||
uint32_t data_channel_base = task->base.sink;
|
||||
|
||||
uint32_t samples_per_period = task->samples_per_periode;
|
||||
float phase = task->phase;
|
||||
float amplitude = task->amplitude;
|
||||
|
||||
float step = ( 2.0f * (float)M_PI ) / (float)samples_per_period;
|
||||
|
||||
for ( uint32_t i = 0; i < 1024; ++i ) {
|
||||
float_word sample;
|
||||
float angle = phase + (float)i * step;
|
||||
sample.value = amplitude * sinf( angle );
|
||||
data_channel_write( data_channel_base, sample.word );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user