#include #include #include //*********************************************************** // Interrupt Service Routine for spectral matrices processing rtems_isr spectral_matrices_isr( rtems_vector_number vector ) { if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_4 ); } } //************ // RTEMS TASKS rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ { rtems_event_set event_out; unsigned char nb_interrupt_f0 = 0; PRINTF("in SMIQ *** \n") while(1){ rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 nb_interrupt_f0 = nb_interrupt_f0 + 1; if (nb_interrupt_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) ){ if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); } nb_interrupt_f0 = 0; } } } rtems_task spw_bppr_task(rtems_task_argument argument) { rtems_status_code status; rtems_event_set event_out; static int Nb_average_f0 = 0; //static int nb_average_f1 = 0; //static int nb_average_f2 = 0; spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES; spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a; spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b; printf("in BPPR ***\n"); while(true){ // wait for an event to begin with the processing status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); if (status == RTEMS_SUCCESSFUL) { if ((spectral_matrices_regs->ctrl & 0x00000001)==1) { matrix_average(spec_mat_f0_a, averaged_spec_mat_f0); spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; //printf("f0_a\n"); Nb_average_f0++; } if (((spectral_matrices_regs->ctrl>>1) & 0x00000001)==1) { matrix_average(spec_mat_f0_b, compressed_spec_mat_f0); spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffd; //printf("f0_b\n"); Nb_average_f0++; } if (Nb_average_f0 == NB_AVERAGE_NORMAL_f0) { matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0); //printf("f0 compressed\n"); Nb_average_f0 = 0; matrix_reset(averaged_spec_mat_f0); } } } } rtems_task avf0_task(rtems_task_argument argument){ int i; static int nb_average; rtems_event_set event_out; rtems_status_code status; spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES; spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a; spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b; nb_average = 0; PRINTF("in AVFO *** \n") while(1){ rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 for(i=0; ictrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0; if (nb_average == NB_AVERAGE_NORMAL_f0) { nb_average = 0; status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0 if (status != RTEMS_SUCCESSFUL) { printf("iN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status); } } } } rtems_task bpf0_task(rtems_task_argument argument){ rtems_event_set event_out; PRINTF("in BPFO *** \n") while(1){ rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0); BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0); //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n") } } //***************************** // Spectral matrices processing void matrix_average(volatile int *spec_mat, float *averaged_spec_mat) { int i; for(i=0; i abs(sx_im) ) { LFR_BP1[(i*9) + 7] = LFR_BP1[(i*9) + 1] | (0x80); // extract the sector of sx } else { LFR_BP1[(i*9) + 7] = LFR_BP1[(i*9) + 1] & (0x7f); // extract the sector of sx } //====================================================================== // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1) ny = sin(Alpha_M)*NVEC_V1 + cos(Alpha_M)*NVEC_V2; nz = NVEC_V0; bx_bx_star = cos(Alpha_M) * cos(Alpha_M) * compressed_spec_mat[i*30+10] // re S22 + sin(Alpha_M) * sin(Alpha_M) * compressed_spec_mat[i*30+18] // re S33 - 2 * sin(Alpha_M) * cos(Alpha_M) * compressed_spec_mat[i*30+12]; // re S23 nebx_re = ny * (compressed_spec_mat[(i*30) + 14] * K24_ny_re +compressed_spec_mat[(i*30) + 16] * K25_ny_re +compressed_spec_mat[(i*30) + 20] * K34_ny_re +compressed_spec_mat[(i*30) + 22] * K35_ny_re) + nz * (compressed_spec_mat[(i*30) + 14] * K24_nz_re +compressed_spec_mat[(i*30) + 16] * K25_nz_re +compressed_spec_mat[(i*30) + 20] * K34_nz_re +compressed_spec_mat[(i*30) + 22] * K35_nz_re); nebx_im = ny * (compressed_spec_mat[(i*30) + 15]*K24_ny_re +compressed_spec_mat[(i*30) + 17] * K25_ny_re +compressed_spec_mat[(i*30) + 21] * K34_ny_re +compressed_spec_mat[(i*30) + 23] * K35_ny_re) + nz * (compressed_spec_mat[(i*30) + 15] * K24_nz_im +compressed_spec_mat[(i*30) + 17] * K25_nz_im +compressed_spec_mat[(i*30) + 21] * K34_nz_im +compressed_spec_mat[(i*30) + 23] * K35_nz_im); tmp = nebx_re / bx_bx_star; LFR_BP1[(i*9) + 8] = ((unsigned char) (tmp * 128)) & 0x7f; // cf DOC for the compression if ( abs(nebx_re) > abs(nebx_im) ) { LFR_BP1[(i*9) + 8] = LFR_BP1[(i*9) + 8] | (0x80); // extract the sector of nebx } else { LFR_BP1[(i*9) + 8] = LFR_BP1[(i*9) + 8] & (0x7f); // extract the sector of nebx } } } void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){ // BP2 autocorrelation int i; int aux = 0; for(i = 0; i