Erstcommit
This commit is contained in:
154
main.c
Normal file
154
main.c
Normal file
@@ -0,0 +1,154 @@
|
||||
//#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"
|
||||
|
||||
// Register und Bitmasken für Interrupts zwischen ARM und LPDSP Prozessor
|
||||
#define CSS_CMD 0xC00004
|
||||
#define CSS_CMD_0 (1<<0)
|
||||
#define CSS_CMD_1 (1<<1)
|
||||
|
||||
// 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)
|
||||
|
||||
//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;
|
||||
|
||||
// Interrupt-Flag, welche von ARM gesetzt wird, wenn eine Berechnung gewünscht ist
|
||||
static volatile int actionRequired;
|
||||
|
||||
// Structs anlegen für die Signalpfade - hier werden Konfigurationen abgelegt(signal_path.h)
|
||||
static SingleSignalPath cSensorSignal;
|
||||
static SingleSignalPath accSensorSignal;
|
||||
|
||||
// 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
|
||||
|
||||
//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
|
||||
extern "C" void isr0() property (isr) {
|
||||
actionRequired = 1;
|
||||
}
|
||||
|
||||
#ifdef __chess__
|
||||
extern "C"
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
// Enum, welcher den Ausgabemodus definiert - wird in calc()-Funktion verwendet
|
||||
static OutputMode mode = OUTPUT_MODE_FIR_LMS;
|
||||
|
||||
// Initialize the signal path
|
||||
// Initialize the csensor signal subpath
|
||||
// Instanciate the signal path state structs
|
||||
|
||||
// Deactivate preemphasis filter by initializing with coefficients {1., 0., 0., 0., 0.}
|
||||
// biquad filter coefficients - off
|
||||
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; // always test with max coeffs
|
||||
|
||||
//init-Funktion aufrufen
|
||||
init(
|
||||
&cSensorSignal, &accSensorSignal,
|
||||
//&ptr_fir_lms_delay_line, &ptr_fir_lms_coeffs,
|
||||
b0,
|
||||
b1,
|
||||
2, // sample delayS
|
||||
2,
|
||||
0.9, // weight
|
||||
0.9,
|
||||
0.01, // lms learning rate
|
||||
N_lms_fir_coeffs // Numer of lms fir coefficients
|
||||
);
|
||||
|
||||
if (mode == OUTPUT_MODE_FIR){ //FIR filter mit fixen coeffizienten wenn nicht adaptiv
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SIMULATE // use the simulator with file I/O
|
||||
FILE *fp1 = fopen("./test/testdata/input/chirp_disturber.txt", "r");
|
||||
FILE *fp2 = fopen("./test/testdata/input/disturber.txt", "r");
|
||||
FILE *fp3 = fopen("./test/testdata/output/out_simulated.txt", "w");
|
||||
|
||||
int d0, d1;
|
||||
|
||||
while (!(feof(fp1) || feof(fp2))){
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
calc(
|
||||
&cSensorSignal, &accSensorSignal,
|
||||
//&ptr_fir_lms_delay_line, &ptr_fir_lms_coeffs,
|
||||
mode,
|
||||
&intputPort[0],
|
||||
&intputPort[1],
|
||||
outputPort
|
||||
);
|
||||
|
||||
for (int i=0; i<BLOCK_LEN; i++){
|
||||
fprintf(fp3, "%d\n", outputPort[i]);
|
||||
}
|
||||
}
|
||||
fclose(fp1);
|
||||
fclose(fp2);
|
||||
fclose(fp3);
|
||||
|
||||
#else // how its done in hw
|
||||
// enable the interrupts
|
||||
enable_interrupts();
|
||||
outPtr = &outputPort[1]; // start with second half of buffer
|
||||
sample_ptr = &sample;
|
||||
|
||||
/*Signalprocessing, called by an interrupt*/
|
||||
actionRequired = 0;
|
||||
while (1){
|
||||
CssCmdGen = CSS_CMD_1; // indicate going to sleep to the cm3
|
||||
core_halt();
|
||||
if (actionRequired == 1) {
|
||||
CssCmdGen = CSS_CMD_0; // indicate wakeup to the cm3
|
||||
actionRequired = 0;
|
||||
|
||||
outPtr = cyclic_add(outPtr, 2, outputPort, 4);
|
||||
*outPtr = *sample_ptr;
|
||||
calc(&cSensorSignal, &accSensorSignal, mode, &intputPort[1], &intputPort[0], sample_ptr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user