Code gekürzt - kompilliert
This commit is contained in:
102
main.c
102
main.c
@@ -1,10 +1,11 @@
|
||||
// BLOCK LEN 1 und MAX_FIR_COEFFS 64 werden vom Compiler mitgegeben
|
||||
|
||||
//#define SIMULATE
|
||||
|
||||
#ifdef SIMULATE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#define BLOCK_LEN 1 // define block length for processing - currently only 1 is supported
|
||||
|
||||
#include <stdint.h>
|
||||
#include "signalProcessing/include/signal_path.h"
|
||||
|
||||
@@ -15,48 +16,32 @@
|
||||
|
||||
// Shared Memory von ARM und DSP definieren
|
||||
#define INPUT_PORT0_ADD 0x800000 // Feste Adressen für Eingangsdaten im Shared Memory
|
||||
//#define INPUT_PORT1_ADD INPUT_PORT0_ADD + 2 //DMB - warum auskommentiert?
|
||||
#define OUTPUT_PORT_ADD (INPUT_PORT0_ADD + 16) // Feste Adressen für Ausgangsdatensdaten im Shared Memory, 16 Byte von Eingangsadresse Weg (PS: 2* for 2 channels)
|
||||
#define OUTPUT_PORT_ADD (INPUT_PORT0_ADD + 16) // Feste Adressen für Ausgangsdatensdaten im Shared Memory, 16 Byte von Eingangsadresse Weg
|
||||
|
||||
//Chess Compiler spezifisch: Interrupt-Register festlegen um ARM zu kontaktieren nach fertiger Berechnung (PS: Define the interrupt register to notify the ARM of a completed operation)
|
||||
volatile static unsigned char chess_storage(DMIO:CSS_CMD) CssCmdGen;
|
||||
//Chess Compiler spezifisch: Interrupt-Register festlegen um ARM zu kontaktieren nach fertiger Berechnung
|
||||
volatile static unsigned char chess_storage(DMIO:CSS_CMD) css_cmd_flag;
|
||||
|
||||
// Interrupt-Flag, welche von ARM gesetzt wird, wenn eine Berechnung gewünscht ist
|
||||
static volatile int actionRequired;
|
||||
static volatile int action_required;
|
||||
|
||||
// Structs anlegen für die Signalpfade - hier werden Konfigurationen abgelegt(signal_path.h)
|
||||
static SingleSignalPath cSensorSignal;
|
||||
static SingleSignalPath accSensorSignal;
|
||||
static SingleSignalPath corrupted_signal;
|
||||
static SingleSignalPath reference_noise_signal;
|
||||
|
||||
// Umschaltung zwischen sampleweiser und blockweiser Verarbeitung
|
||||
// Sampleweise Verarbeitung: Adresse aus Shared Memory wird direkt verwendet
|
||||
// Blockweise Verarbeitung: Blöcke kopiert und verarbeitet? Offensichtlicch nicht genutzt bisher
|
||||
#if BLOCK_LEN == 1
|
||||
static volatile int16_t chess_storage(DMB:INPUT_PORT0_ADD) intputPort[4]; //TODO: if BLOCK_LEN >1 is used, the data is interleaved: ch0ch1, ch0ch1 .... chess_storage(DMA % alignof(int)) ?
|
||||
//static volatile int16_t chess_storage(DMB:INPUT_PORT1_ADD) intputPort1[BLOCK_LEN];
|
||||
static volatile int16_t chess_storage(DMB:OUTPUT_PORT_ADD) outputPort[4];
|
||||
static volatile int16_t chess_storage(DMB) *inPtr0;
|
||||
static volatile int16_t chess_storage(DMB) *inPtr1;
|
||||
static volatile int16_t chess_storage(DMB) *outPtr;
|
||||
static volatile int16_t chess_storage(DMB) sample;
|
||||
static volatile int16_t chess_storage(DMB) *sample_ptr;
|
||||
#else
|
||||
// Int-Array für Blockverarbeitung im Shared Memory DMA anlegen (Eingabe)
|
||||
static int16_t chess_storage(DMA) intputPort[BLOCK_LEN]; //chess_storage(DMA:INPUT_PORT_ADD) TODO: volatile? chess_storage(DMA % alignof(int))
|
||||
//static int16_t chess_storage(DMA) intputPort1[BLOCK_LEN]; //chess_storage(DMA:INPUT_PORT_ADD)
|
||||
// Int-Array für Blockverarbeitung im Shared Memory DMA anlegen (Ausgabe)
|
||||
static int16_t chess_storage(DMB) outputPort[BLOCK_LEN]; // chess_storage(DMB:OUTPUT_PORT_ADD) TODO: determine output port add
|
||||
#endif
|
||||
static volatile int16_t chess_storage(DMB:INPUT_PORT0_ADD) input_port[4]; //Array mit 4x16 Bit Einträgen auf 2x32 Bit Registern - nur die ersten 2 werden genutzt
|
||||
static volatile int16_t chess_storage(DMB:OUTPUT_PORT_ADD) output_port[4]; //Array mit 4x16 Bit Einträgen auf 2x32 Bit Registern - alle werden genutzt
|
||||
static volatile int16_t chess_storage(DMB) *input_pointer_0;
|
||||
static volatile int16_t chess_storage(DMB) *input_pointer_1;
|
||||
static volatile int16_t chess_storage(DMB) *output_pointer;
|
||||
static volatile int16_t chess_storage(DMB) *sample_pointer;
|
||||
static volatile int16_t chess_storage(DMB) sample; //Speicherplatz für Ergebnis der calc()-Funktion
|
||||
|
||||
//void isr0() ist eine Interrupt Service Routine Funktion, welche als C Funktion deklariert wird
|
||||
// property (isr) ist Chess Compiler spezifisch und kennzeichnet eine Funktion als Interrupt Service Routine
|
||||
//wird Interrupt getriggert, wird actionRequired auf 1 gesetzt - etwas muss dannpassieren
|
||||
//wird Interrupt getriggert, wird action_required auf 1 gesetzt - etwas muss dannpassieren
|
||||
extern "C" void isr0() property (isr) {
|
||||
actionRequired = 1;
|
||||
action_required = 1;
|
||||
}
|
||||
#ifdef __chess__
|
||||
extern "C"
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
// Enum, welcher den Ausgabemodus definiert - wird in calc()-Funktion verwendet
|
||||
@@ -65,11 +50,11 @@ int main(void) {
|
||||
// Alle 0 bis auf b[0] -> einfacher Gain auf 0,75
|
||||
double b0[5]={0.75, 0., 0., 0., 0.};
|
||||
double b1[5]={0.75, 0., 0., 0., 0.};
|
||||
int N_lms_fir_coeffs = MAX_FIR_COEFFS; // 64 Koeffizienten für ANR
|
||||
int coefficients = MAX_FIR_COEFFS; // 64 Koeffizienten für ANR
|
||||
|
||||
// Signale initialisieren, oben angelegte Structs mit Parametern füllen
|
||||
init(
|
||||
&cSensorSignal, &accSensorSignal, //Signal-Structs
|
||||
&corrupted_signal, &reference_noise_signal, //Signal-Structs
|
||||
b0, // Biqquad Koeffizienten C-Sensor
|
||||
b1, // Biqquad Koeffizienten Acc-Sensor
|
||||
2, // Sample Delay C-Sensor
|
||||
@@ -77,20 +62,9 @@ int main(void) {
|
||||
0.9, //Gewichtung C-Sensor
|
||||
0.9, //Gewichtung Acc-Sensor
|
||||
0.01, // Mu
|
||||
N_lms_fir_coeffs // Anzahl Filterkoeffizienten
|
||||
coefficients // Anzahl Filterkoeffizienten
|
||||
);
|
||||
|
||||
// Fixer Filter wenn nicht adaptiv
|
||||
if (mode == OUTPUT_MODE_FIR){
|
||||
for (int i=0; i<N_lms_fir_coeffs; i++){
|
||||
#ifdef LPDSP16
|
||||
ptr_fir_lms_coeffs.ptr_start[i] = ((pow(2, 15)-1) /N_lms_fir_coeffs);
|
||||
#else
|
||||
ptr_fir_lms_coeffs.ptr_start[i] = ((pow(2, 31)-1) /N_lms_fir_coeffs);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//Simulationsmodus mit File I/O
|
||||
#ifdef SIMULATE
|
||||
FILE *fp1 = fopen("./test/testdata/input/chirp_disturber.txt", "r");
|
||||
@@ -103,19 +77,13 @@ int main(void) {
|
||||
for (int i=0; i<BLOCK_LEN; i++){
|
||||
fscanf(fp1, "%d", &d0); //load blocks
|
||||
fscanf(fp2, "%d", &d1);
|
||||
intputPort[i] = (int16_t) d0;
|
||||
intputPort[i+1] = (int16_t) d1;
|
||||
input_port[i] = (int16_t) d0;
|
||||
input_port[i+1] = (int16_t) d1;
|
||||
}
|
||||
calc(
|
||||
&cSensorSignal, &accSensorSignal,
|
||||
//&ptr_fir_lms_delay_line, &ptr_fir_lms_coeffs,
|
||||
mode,
|
||||
&intputPort[0],
|
||||
&intputPort[1],
|
||||
outputPort
|
||||
);
|
||||
&corrupted_signal, &reference_noise_signal, mode, &input_port[0], &input_port[1], output_port);
|
||||
for (int i=0; i<BLOCK_LEN; i++){
|
||||
fprintf(fp3, "%d\n", outputPort[i]);
|
||||
fprintf(fp3, "%d\n", output_port[i]);
|
||||
}
|
||||
}
|
||||
fclose(fp1);
|
||||
@@ -125,20 +93,20 @@ int main(void) {
|
||||
// Hardwaremodus mit Interrupts
|
||||
#else
|
||||
enable_interrupts(); //Interrupts aktivieren
|
||||
outPtr = &outputPort[1]; // Zweite Hälfte des Ausgangspuffers zuerst füllen - warum 1 statt 2?
|
||||
sample_ptr = &sample;
|
||||
output_pointer = &output_port[1]; // Zweite Hälfte des Ausgangspuffers zuerst füllen - warum 1 statt 2? Warum generell nicht 0?
|
||||
sample_pointer = &sample; //Sample-Pointer wird auf Adresse des Sample-Speicherplatzes gesetzt
|
||||
|
||||
//Endlosschleife für Interrupt-gesteuerte Verarbeitung
|
||||
actionRequired = 0;
|
||||
action_required = 0;
|
||||
while (1){
|
||||
CssCmdGen = CSS_CMD_1; // Interrupt Bit setzen um ARM zu signalisieren, dass der DSP abschaltet
|
||||
css_cmd_flag = CSS_CMD_1; // Interrupt Bit setzen um ARM zu signalisieren, dass der DSP schläft
|
||||
core_halt();
|
||||
if (actionRequired == 1) {
|
||||
CssCmdGen = CSS_CMD_0; // Interrupt Bit setzen um ARM zu signalisieren, dass der DSP arbeitet
|
||||
actionRequired = 0;
|
||||
outPtr = cyclic_add(outPtr, 2, outputPort, 4); //Pointer inkrementieren - was passiert hier genau?
|
||||
*outPtr = *sample_ptr;
|
||||
calc(&cSensorSignal, &accSensorSignal, mode, &intputPort[1], &intputPort[0], sample_ptr);
|
||||
if (action_required == 1) {
|
||||
css_cmd_flag = CSS_CMD_0; // Interrupt Bit setzen um ARM zu signalisieren, dass der DSP arbeitet
|
||||
action_required = 0; // Action-Flag setzen, damit Loop nicht automatisch startet
|
||||
output_pointer = cyclic_add(output_pointer, 2, output_port, 4); //Output Buffer um 2 Byte inkrementieren, hat insgesamt 4 Byte - Reset wenn Ende erreicht
|
||||
*output_pointer = *sample_pointer; //Inhalt des Sample-Pointer Ziels (Ergenis der vorherigen Berechnung) in Output-Pointer schreiben
|
||||
calc(&corrupted_signal, &reference_noise_signal, mode, &input_port[1], &input_port[0], sample_pointer); //16 Bit Output Sample aus 2 16 Bit Input Samples berechnen
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user