avf2_prc2.c
332 lines
| 11.8 KiB
| text/x-c
|
CLexer
paul
|
r126 | /** Functions related to data processing. | ||
* | ||||
* @file | ||||
* @author P. LEROY | ||||
* | ||||
* These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. | ||||
* | ||||
*/ | ||||
#include "avf2_prc2.h" | ||||
paul
|
r321 | nb_sm_before_bp_asm_f2 nb_sm_before_f2 = {0}; | ||
paul
|
r179 | |||
paul
|
r126 | //*** | ||
// F2 | ||||
paul
|
r321 | ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ] = {0}; | ||
paul
|
r126 | |||
paul
|
r321 | ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ] = {0}; | ||
int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ] = {0}; | ||||
paul
|
r173 | |||
paul
|
r321 | float asm_f2_patched_norm [ TOTAL_SIZE_SM ] = {0}; | ||
float asm_f2_reorganized [ TOTAL_SIZE_SM ] = {0}; | ||||
paul
|
r183 | |||
paul
|
r321 | float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2] = {0}; | ||
paul
|
r126 | |||
paul
|
r321 | float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ] = {0}; // 12 * 32 = 384 | ||
paul
|
r179 | |||
paul
|
r126 | //************ | ||
// RTEMS TASKS | ||||
//*** | ||||
// F2 | ||||
rtems_task avf2_task( rtems_task_argument argument ) | ||||
{ | ||||
rtems_event_set event_out; | ||||
rtems_status_code status; | ||||
rtems_id queue_id_prc2; | ||||
paul
|
r259 | asm_msg msgForPRC; | ||
paul
|
r179 | ring_node *nodeForAveraging; | ||
paul
|
r126 | ring_node_asm *current_ring_node_asm_norm_f2; | ||
unsigned int nb_norm_bp1; | ||||
unsigned int nb_norm_bp2; | ||||
unsigned int nb_norm_asm; | ||||
paul
|
r320 | event_out = EVENT_SETS_NONE_PENDING; | ||
queue_id_prc2 = RTEMS_ID_NONE; | ||||
paul
|
r126 | nb_norm_bp1 = 0; | ||
nb_norm_bp2 = 0; | ||||
nb_norm_asm = 0; | ||||
reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions | ||||
ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 ); | ||||
current_ring_node_asm_norm_f2 = asm_ring_norm_f2; | ||||
BOOT_PRINTF("in AVF2 ***\n") | ||||
status = get_message_queue_id_prc2( &queue_id_prc2 ); | ||||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status) | ||||
} | ||||
while(1){ | ||||
rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 | ||||
paul
|
r150 | //**************************************** | ||
// initialize the mesage for the MATR task | ||||
paul
|
r259 | msgForPRC.norm = current_ring_node_asm_norm_f2; | ||
msgForPRC.burst_sbm = NULL; | ||||
paul
|
r318 | msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task | ||
paul
|
r150 | // | ||
//**************************************** | ||||
paul
|
r318 | nodeForAveraging = getRingNodeForAveraging( CHANNELF2 ); | ||
paul
|
r179 | |||
paul
|
r126 | // compute the average and store it in the averaged_sm_f2 buffer | ||
SM_average_f2( current_ring_node_asm_norm_f2->matrix, | ||||
paul
|
r179 | nodeForAveraging, | ||
nb_norm_bp1, | ||||
paul
|
r259 | &msgForPRC ); | ||
paul
|
r126 | |||
// update nb_average | ||||
nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2; | ||||
nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2; | ||||
nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2; | ||||
if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1) | ||||
{ | ||||
nb_norm_bp1 = 0; | ||||
// set another ring for the ASM storage | ||||
current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next; | ||||
if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) | ||||
|| (lfrCurrentMode == LFR_MODE_SBM2) ) | ||||
{ | ||||
paul
|
r259 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2; | ||
paul
|
r126 | } | ||
} | ||||
if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2) | ||||
{ | ||||
nb_norm_bp2 = 0; | ||||
if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) | ||||
|| (lfrCurrentMode == LFR_MODE_SBM2) ) | ||||
{ | ||||
paul
|
r259 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2; | ||
paul
|
r126 | } | ||
} | ||||
if (nb_norm_asm == nb_sm_before_f2.norm_asm) | ||||
{ | ||||
nb_norm_asm = 0; | ||||
if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) | ||||
|| (lfrCurrentMode == LFR_MODE_SBM2) ) | ||||
{ | ||||
paul
|
r259 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2; | ||
paul
|
r126 | } | ||
} | ||||
//************************* | ||||
paul
|
r259 | // send the message to PRC2 | ||
paul
|
r318 | if (msgForPRC.event != EVENT_SETS_NONE_PENDING) | ||
paul
|
r126 | { | ||
paul
|
r259 | status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2); | ||
paul
|
r126 | } | ||
if (status != RTEMS_SUCCESSFUL) { | ||||
paul
|
r259 | PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status) | ||
paul
|
r126 | } | ||
} | ||||
} | ||||
rtems_task prc2_task( rtems_task_argument argument ) | ||||
{ | ||||
char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer | ||||
size_t size; // size of the incoming TC packet | ||||
asm_msg *incomingMsg; | ||||
// | ||||
rtems_status_code status; | ||||
paul
|
r181 | rtems_id queue_id_send; | ||
paul
|
r126 | rtems_id queue_id_q_p2; | ||
paul
|
r338 | bp_packet __attribute__((aligned(4))) packet_norm_bp1; | ||
bp_packet __attribute__((aligned(4))) packet_norm_bp2; | ||||
paul
|
r173 | ring_node *current_ring_node_to_send_asm_f2; | ||
paul
|
r289 | float nbSMInASMNORM; | ||
paul
|
r126 | |||
unsigned long long int localTime; | ||||
paul
|
r320 | size = 0; | ||
queue_id_send = RTEMS_ID_NONE; | ||||
queue_id_q_p2 = RTEMS_ID_NONE; | ||||
memset( &packet_norm_bp1, 0, sizeof(bp_packet) ); | ||||
memset( &packet_norm_bp2, 0, sizeof(bp_packet) ); | ||||
paul
|
r173 | // init the ring of the averaged spectral matrices which will be transmitted to the DPU | ||
init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM ); | ||||
current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2; | ||||
paul
|
r166 | |||
paul
|
r126 | //************* | ||
// NORM headers | ||||
paul
|
r179 | BP_init_header( &packet_norm_bp1, | ||
paul
|
r126 | APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2, | ||
PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 ); | ||||
paul
|
r179 | BP_init_header( &packet_norm_bp2, | ||
paul
|
r126 | APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2, | ||
PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 ); | ||||
paul
|
r181 | status = get_message_queue_id_send( &queue_id_send ); | ||
paul
|
r126 | if (status != RTEMS_SUCCESSFUL) | ||
{ | ||||
PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status) | ||||
} | ||||
status = get_message_queue_id_prc2( &queue_id_q_p2); | ||||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status) | ||||
} | ||||
BOOT_PRINTF("in PRC2 ***\n") | ||||
while(1){ | ||||
status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************ | ||||
paul
|
r182 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2 | ||
paul
|
r126 | |||
incomingMsg = (asm_msg*) incomingData; | ||||
paul
|
r183 | ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm ); | ||
paul
|
r126 | localTime = getTimeAsUnsignedLongLongInt( ); | ||
paul
|
r289 | nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM; | ||
paul
|
r126 | //***** | ||
//***** | ||||
// NORM | ||||
//***** | ||||
//***** | ||||
paul
|
r289 | // 1) compress the matrix for Basic Parameters calculation | ||
paul
|
r236 | ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2, | ||
paul
|
r289 | nbSMInASMNORM, | ||
paul
|
r182 | NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2, | ||
paul
|
r236 | ASM_F2_INDICE_START, CHANNELF2 ); | ||
paul
|
r182 | // BP1_F2 | ||
paul
|
r126 | if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2) | ||
{ | ||||
paul
|
r182 | // 1) compute the BP1 set | ||
paul
|
r183 | BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data ); | ||
paul
|
r182 | // 2) send the BP1 set | ||
paul
|
r179 | set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM ); | ||
set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM ); | ||||
paul
|
r283 | packet_norm_bp1.pa_bia_status_info = pa_bia_status_info; | ||
paul
|
r192 | packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | ||
paul
|
r181 | BP_send( (char *) &packet_norm_bp1, queue_id_send, | ||
paul
|
r133 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA, | ||
SID_NORM_BP1_F2 ); | ||||
paul
|
r182 | } | ||
// BP2_F2 | ||||
if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2) | ||||
{ | ||||
// 1) compute the BP2 set | ||||
BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data ); | ||||
// 2) send the BP2 set | ||||
set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM ); | ||||
set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM ); | ||||
paul
|
r283 | packet_norm_bp2.pa_bia_status_info = pa_bia_status_info; | ||
paul
|
r192 | packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | ||
paul
|
r182 | BP_send( (char *) &packet_norm_bp2, queue_id_send, | ||
PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA, | ||||
SID_NORM_BP2_F2 ); | ||||
paul
|
r126 | } | ||
if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2) | ||||
{ | ||||
// 1) reorganize the ASM and divide | ||||
paul
|
r183 | ASM_reorganize_and_divide( asm_f2_patched_norm, | ||
paul
|
r196 | (float*) current_ring_node_to_send_asm_f2->buffer_address, | ||
paul
|
r126 | nb_sm_before_f2.norm_bp1 ); | ||
paul
|
r179 | current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM; | ||
current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM; | ||||
paul
|
r173 | current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2; | ||
paul
|
r292 | |||
paul
|
r126 | // 3) send the spectral matrix packets | ||
paul
|
r181 | status = rtems_message_queue_send( queue_id_send, ¤t_ring_node_to_send_asm_f2, sizeof( ring_node* ) ); | ||
paul
|
r292 | |||
paul
|
r173 | // change asm ring node | ||
current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next; | ||||
paul
|
r126 | } | ||
paul
|
r197 | update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max ); | ||
paul
|
r126 | } | ||
} | ||||
//********** | ||||
// FUNCTIONS | ||||
void reset_nb_sm_f2( void ) | ||||
{ | ||||
nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0; | ||||
nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1; | ||||
paul
|
r318 | nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_asm_p[1]; | ||
paul
|
r126 | } | ||
void SM_average_f2( float *averaged_spec_mat_f2, | ||||
paul
|
r179 | ring_node *ring_node, | ||
unsigned int nbAverageNormF2, | ||||
asm_msg *msgForMATR ) | ||||
paul
|
r126 | { | ||
float sum; | ||||
unsigned int i; | ||||
paul
|
r289 | unsigned char keepMatrix; | ||
// test acquisitionTime validity | ||||
paul
|
r318 | keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, CHANNELF2 ); | ||
paul
|
r126 | |||
for(i=0; i<TOTAL_SIZE_SM; i++) | ||||
{ | ||||
sum = ( (int *) (ring_node->buffer_address) ) [ i ]; | ||||
paul
|
r289 | if ( (nbAverageNormF2 == 0) ) // average initialization | ||
paul
|
r126 | { | ||
paul
|
r289 | if (keepMatrix == 1) // keep the matrix and add it to the average | ||
{ | ||||
averaged_spec_mat_f2[ i ] = sum; | ||||
} | ||||
else // drop the matrix and initialize the average | ||||
{ | ||||
paul
|
r318 | averaged_spec_mat_f2[ i ] = INIT_FLOAT; | ||
paul
|
r289 | } | ||
paul
|
r179 | msgForMATR->coarseTimeNORM = ring_node->coarseTime; | ||
msgForMATR->fineTimeNORM = ring_node->fineTime; | ||||
paul
|
r126 | } | ||
else | ||||
{ | ||||
paul
|
r289 | if (keepMatrix == 1) // keep the matrix and add it to the average | ||
{ | ||||
averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum ); | ||||
} | ||||
else | ||||
{ | ||||
// nothing to do, the matrix is not valid | ||||
} | ||||
} | ||||
} | ||||
if (keepMatrix == 1) | ||||
{ | ||||
if ( (nbAverageNormF2 == 0) ) | ||||
{ | ||||
msgForMATR->numberOfSMInASMNORM = 1; | ||||
} | ||||
else | ||||
{ | ||||
msgForMATR->numberOfSMInASMNORM++; | ||||
} | ||||
} | ||||
else | ||||
{ | ||||
if ( (nbAverageNormF2 == 0) ) | ||||
{ | ||||
msgForMATR->numberOfSMInASMNORM = 0; | ||||
} | ||||
else | ||||
{ | ||||
// nothing to do | ||||
paul
|
r126 | } | ||
} | ||||
} | ||||
paul
|
r179 | |||
paul
|
r214 | void init_k_coefficients_prc2( void ) | ||
paul
|
r179 | { | ||
init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2); | ||||
} | ||||