diff --git a/PULP/adaptive_Rpeak_detection/adaptiveRpeakDetection.c b/PULP/adaptive_Rpeak_detection/adaptiveRpeakDetection.c index 23fb59c..cffa1ef 100755 --- a/PULP/adaptive_Rpeak_detection/adaptiveRpeakDetection.c +++ b/PULP/adaptive_Rpeak_detection/adaptiveRpeakDetection.c @@ -1,368 +1,377 @@ #include "rt/rt_api.h" #include "adaptiveRpeakDetection.h" #include "../defines.h" #include "../profiling/profile.h" #include "../profiling/profile_cl.h" #include "../profiling/defines.h" #include "../data/signal.h" #include "../Morph_filt/morpho_filtering.h" #include "../Morph_filt/defines_globals.h" #include "../error_detection/error_detection.h" #include "../test_double_buffering.h" #define N_WINDOWS (int) (2*((ECG_VECTOR_SIZE-LONG_WINDOW)/DIM)+1)// Counting the worst case scenario when overlap is DIM RT_L2_DATA int16_t ecg_L2buff[(LONG_WINDOW+DIM)*(NLEADS+1)]; RT_L2_DATA rt_perf_t perf[NUM_CORES]; #ifdef MODULE_MF RT_L2_DATA int32_t *argMF[4]; RT_L2_DATA int32_t buffSize_windowMF; #endif #ifdef MODULE_RELEN RT_L2_DATA int32_t *argRelEn[4]; RT_L2_DATA int32_t start_RelEn = 1; RT_L2_DATA int32_t buffSize_windowRelEn; #endif #ifdef MODULE_RPEAK_REWARD RT_L2_DATA int32_t *argRW_Rpeak[3]; RT_L2_DATA int32_t indicesRpeaks[H_B+1]; #endif #ifdef MODULE_ERROR_DETECTION RT_L2_DATA int32_t *argErrDet[5]; RT_L2_DATA int32_t lastRpeak = 0; RT_L2_DATA int32_t lastRR = 0; RT_L2_DATA int32_t error_RWindow = 0; #endif #ifdef MODULE_CLUSTERING RT_L2_DATA int32_t rL2BufferIndex; -RT_L1_DATA int32_t rL1BufferIndex = 0; +RT_L2_DATA int32_t rL1BufferIndex = 0; RT_L1_DATA int16_t ecg_L1buff[DIM*(NLEADS+1)]; +RT_L1_DATA int32_t start_index_w = 0; RT_L1_DATA int32_t end_main_loop; RT_L2_DATA int32_t* argCL[3]; RT_L2_DATA rt_event_sched_t * psched = 0; RT_L2_DATA int32_t done = 0; #endif RT_L2_DATA int32_t overlap; RT_L2_DATA int32_t rWindow; void clearRelEn() { clearAndResetRelEn(); resetPeakDetection(); } // static void cluster_Rpeaks(int32_t *arg[]) // { // rt_team_fork(NUM_CORES, rpeaks, arg); // } static void cluster_test_doublebuff(int32_t *arg[]) { rt_team_fork(NUM_CORES, testDoubleBuff, arg); } extern void end_of_call(void *arg) { done = 1; } static void fCore0_DmaTransfer_Window(void *arg) { rt_dma_copy_t dmaCp; // Copy data block window from L2 to shared L1 memory using the cluster DMA rt_dma_memcpy((unsigned int)&ecg_L2buff[rL2BufferIndex], (unsigned int)&ecg_L1buff[rL1BufferIndex], 2*DIM, RT_DMA_DIR_EXT2LOC, 0, &dmaCp); // Wait for dma to finish rt_dma_wait(&dmaCp); // printf("rL1BufferIndex: %d endL1BufferIndex: %d\n",rL1BufferIndex,rL1BufferIndex+DIM ); - for(int i=rL1BufferIndex; i= ECG_VECTOR_SIZE){ return; } if(rWindow > 0){ offset_window = LONG_WINDOW; } else{ offset_window = 0; } if (rWindow > 0) { for(int32_t i=0; i 0) start_RelEn = 0; argRelEn[0] = (int32_t*) &ecg_L2buff[offset_window + overlap]; argRelEn[1] = (int32_t*) &ecg_L2buff[offset_window + (LONG_WINDOW + DIM)*NLEADS+overlap]; buffSize_windowRelEn = LONG_WINDOW - offset_window + DIM-overlap; #endif relEn_w(argRelEn); #ifdef HWPERF_MODULES profile_stop(perf); #endif #ifdef PRINT_RELEN for(int32_t sample = offset_window + (LONG_WINDOW + DIM)*NLEADS; sample< (LONG_WINDOW + DIM)*(NLEADS+1); sample++) { printf("%d\n", ecg_L2buff[sample]); } #endif #endif #ifdef MODULE_RPEAK_REWARD #ifdef HWPERF_MODULE_RPEAK_REWARD || HWPERF_MODULES profile_start(perf); #endif getPeaks_w(argRW_Rpeak); rpeaks_counter = 0; while(indicesRpeaks[rpeaks_counter]!=0) { rpeaks_counter++; } #ifdef HWPERF_MODULE_RPEAK_REWARD || HWPERF_MODULES profile_stop(perf); #endif #ifdef PRINT_RPEAKS for(int32_t indR=0; indR 0 && error_RWindow == 1){ #endif // ----------------------------Copy current window ecg buffer from L2 to L1 memory if error was 1 ------------------------------ // // Initialize event event = rt_event_get_blocking(NULL); // Run function on Core 0 of the cluster rt_cluster_call(NULL, 0, fCore0_DmaTransfer_Window, NULL, NULL, STACK_SIZE, STACK_SIZE, 1, event); // Wait for event rt_event_wait(event); // ------------------------------------------------------------------------------------------------------------------------------// - argCL[0] = (int32_t*) &ecg_L1buff[rL1BufferIndex]; - argCL[1] = &rL1BufferIndex; + argCL[0] = (int32_t*) ecg_L1buff; //The start index is the one in argCL[1] + argCL[1] = &start_index_w; argCL[2] = &end_main_loop; rt_cluster_call(NULL, CID, cluster_test_doublebuff, argCL, NULL, 2048, 2048, NUM_CORES, rt_event_get(psched, end_of_call, (void *) CID)); while(!done) rt_event_execute(psched, 1); done = 0; #ifdef MODULE_ERROR_DETECTION } #endif #endif #ifdef ONLY_FIRST_WINDOW //Only for debug return; #endif #ifdef OVERLAP_MF overlap = LONG_WINDOW + LONG_WINDOW/2 + 1; #endif #ifdef OVERLAP_RELEN overlap = 0; #endif tot_overlap += overlap; offset_ind = offset_ind + DIM - tot_overlap; #ifdef MODULE_RPEAK_REWARD rpeaks_counter = 0; for(int32_t ix_rp = 0; ix_rp < H_B+1 ; ix_rp++) { indicesRpeaks[ix_rp] = 0; } #endif } #ifdef MODULE_CLUSTERING rt_cluster_mount(UNMOUNT, 0, 0, NULL); #endif } diff --git a/PULP/test_double_buffering.c b/PULP/test_double_buffering.c index a0dcb3a..e3cbb24 100644 --- a/PULP/test_double_buffering.c +++ b/PULP/test_double_buffering.c @@ -1,13 +1,13 @@ #include "test_double_buffering.h" #include "rt/rt_api.h" #include void testDoubleBuff(int32_t* arg[]){ - int16_t* ecg_buff = (int16_t*) arg[0]; + int16_t* ecg_buff = (int16_t*) arg[0]; // pointing at ecg_buff from 0 and then using start_index_w and end_main_loop to use the correct part of the buffer int32_t start_index_w = *(arg[1]); int32_t end_main_loop = *(arg[2]); // printf("start_index_w: %d end_main_loop: %d\n",start_index_w,end_main_loop ); // for(int i=start_index_w; i