wf_handler.c
1343 lines
| 50.3 KiB
| text/x-c
|
CLexer
/ src / wf_handler.c
|
r40 | /** Functions and tasks related to waveform packet generation. | ||
* | ||||
* @file | ||||
* @author P. LEROY | ||||
* | ||||
* A group of functions to handle waveforms, in snapshot or continuous format.\n | ||||
* | ||||
*/ | ||||
#include "wf_handler.h" | ||||
|
r5 | |||
|
r171 | //*************** | ||
// waveform rings | ||||
// F0 | ||||
|
r321 | ring_node waveform_ring_f0[NB_RING_NODES_F0]= {0}; | ||
ring_node *current_ring_node_f0 = NULL; | ||||
ring_node *ring_node_to_send_swf_f0 = NULL; | ||||
|
r171 | // F1 | ||
|
r321 | ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0}; | ||
ring_node *current_ring_node_f1 = NULL; | ||||
ring_node *ring_node_to_send_swf_f1 = NULL; | ||||
ring_node *ring_node_to_send_cwf_f1 = NULL; | ||||
|
r171 | // F2 | ||
|
r321 | ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0}; | ||
ring_node *current_ring_node_f2 = NULL; | ||||
ring_node *ring_node_to_send_swf_f2 = NULL; | ||||
ring_node *ring_node_to_send_cwf_f2 = NULL; | ||||
|
r171 | // F3 | ||
|
r321 | ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0}; | ||
ring_node *current_ring_node_f3 = NULL; | ||||
ring_node *ring_node_to_send_cwf_f3 = NULL; | ||||
char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0}; | ||||
|
r87 | |||
|
r238 | bool extractSWF1 = false; | ||
bool extractSWF2 = false; | ||||
bool swf0_ready_flag_f1 = false; | ||||
bool swf0_ready_flag_f2 = false; | ||||
bool swf1_ready = false; | ||||
bool swf2_ready = false; | ||||
|
r105 | |||
|
r321 | int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0}; | ||
int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0}; | ||||
ring_node ring_node_swf1_extracted = {0}; | ||||
ring_node ring_node_swf2_extracted = {0}; | ||||
|
r106 | |||
|
r256 | typedef enum resynchro_state_t | ||
{ | ||||
|
r267 | MEASURE, | ||
CORRECTION | ||||
|
r256 | } resynchro_state; | ||
|
r106 | //********************* | ||
// Interrupt SubRoutine | ||||
|
r179 | ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel) | ||
{ | ||||
ring_node *node; | ||||
node = NULL; | ||||
switch ( frequencyChannel ) { | ||||
|
r318 | case CHANNELF1: | ||
|
r179 | node = ring_node_to_send_cwf_f1; | ||
break; | ||||
|
r318 | case CHANNELF2: | ||
|
r179 | node = ring_node_to_send_cwf_f2; | ||
break; | ||||
|
r318 | case CHANNELF3: | ||
|
r179 | node = ring_node_to_send_cwf_f3; | ||
break; | ||||
default: | ||||
break; | ||||
} | ||||
return node; | ||||
} | ||||
ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel) | ||||
{ | ||||
ring_node *node; | ||||
node = NULL; | ||||
switch ( frequencyChannel ) { | ||||
|
r318 | case CHANNELF0: | ||
|
r179 | node = ring_node_to_send_swf_f0; | ||
break; | ||||
|
r318 | case CHANNELF1: | ||
|
r179 | node = ring_node_to_send_swf_f1; | ||
break; | ||||
|
r318 | case CHANNELF2: | ||
|
r179 | node = ring_node_to_send_swf_f2; | ||
break; | ||||
default: | ||||
break; | ||||
} | ||||
return node; | ||||
} | ||||
|
r106 | void reset_extractSWF( void ) | ||
{ | ||||
|
r238 | extractSWF1 = false; | ||
extractSWF2 = false; | ||||
swf0_ready_flag_f1 = false; | ||||
swf0_ready_flag_f2 = false; | ||||
swf1_ready = false; | ||||
swf2_ready = false; | ||||
|
r106 | } | ||
|
r105 | |||
|
r172 | inline void waveforms_isr_f3( void ) | ||
|
r170 | { | ||
rtems_status_code spare_status; | ||||
if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet | ||||
|| (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) | ||||
{ // in modes other than STANDBY and BURST, send the CWF_F3 data | ||||
|
r171 | //*** | ||
// F3 | ||||
|
r318 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits | ||
|
r171 | ring_node_to_send_cwf_f3 = current_ring_node_f3->previous; | ||
current_ring_node_f3 = current_ring_node_f3->next; | ||||
|
r318 | if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full | ||
|
r171 | ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time; | ||
ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time; | ||||
waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address; | ||||
|
r318 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000] | ||
|
r171 | } | ||
|
r318 | else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full | ||
|
r171 | ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time; | ||
ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time; | ||||
waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; | ||||
|
r318 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000] | ||
|
r171 | } | ||
|
r170 | if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | ||
|
r171 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); | ||
|
r170 | } | ||
} | ||||
} | ||||
} | ||||
|
r172 | inline void waveforms_isr_burst( void ) | ||
|
r170 | { | ||
|
r179 | unsigned char status; | ||
|
r170 | rtems_status_code spare_status; | ||
|
r318 | status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2 | ||
|
r179 | |||
switch(status) | ||||
{ | ||||
|
r318 | case BIT_WFP_BUFFER_0: | ||
|
r185 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; | ||
ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; | ||||
|
r179 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time; | ||
ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time; | ||||
|
r185 | current_ring_node_f2 = current_ring_node_f2->next; | ||
|
r179 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address; | ||
|
r170 | if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) { | ||
|
r171 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); | ||
|
r170 | } | ||
|
r318 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000] | ||
|
r179 | break; | ||
|
r318 | case BIT_WFP_BUFFER_1: | ||
|
r185 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; | ||
ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; | ||||
|
r179 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time; | ||
ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time; | ||||
|
r185 | current_ring_node_f2 = current_ring_node_f2->next; | ||
|
r179 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; | ||
if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) { | ||||
spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); | ||||
} | ||||
|
r318 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000] | ||
|
r179 | break; | ||
default: | ||||
break; | ||||
|
r170 | } | ||
} | ||||
|
r238 | inline void waveform_isr_normal_sbm1_sbm2( void ) | ||
|
r170 | { | ||
rtems_status_code status; | ||||
//*** | ||||
|
r238 | // F0 | ||
|
r318 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits | ||
|
r238 | { | ||
swf0_ready_flag_f1 = true; | ||||
swf0_ready_flag_f2 = true; | ||||
ring_node_to_send_swf_f0 = current_ring_node_f0->previous; | ||||
current_ring_node_f0 = current_ring_node_f0->next; | ||||
|
r318 | if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0) | ||
|
r238 | { | ||
ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time; | ||||
ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time; | ||||
waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address; | ||||
|
r318 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001] | ||
|
r238 | } | ||
|
r318 | else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1) | ||
|
r238 | { | ||
ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time; | ||||
ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time; | ||||
waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; | ||||
|
r318 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010] | ||
|
r238 | } | ||
|
r267 | // send an event to the WFRM task for resynchro activities | ||
status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH ); | ||||
|
r238 | } | ||
//*** | ||||
|
r170 | // F1 | ||
|
r324 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F1) != INIT_CHAR ) { // [0000 1100] check the f1 full bits | ||
|
r170 | // (1) change the receiving buffer for the waveform picker | ||
|
r171 | ring_node_to_send_cwf_f1 = current_ring_node_f1->previous; | ||
current_ring_node_f1 = current_ring_node_f1->next; | ||||
|
r318 | if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0) | ||
|
r171 | { | ||
ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time; | ||||
ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time; | ||||
waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address; | ||||
|
r318 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0 | ||
|
r171 | } | ||
|
r318 | else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1) | ||
|
r171 | { | ||
ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time; | ||||
ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time; | ||||
waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; | ||||
|
r318 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0 | ||
|
r171 | } | ||
|
r170 | // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed) | ||
|
r238 | status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 ); | ||
|
r170 | } | ||
//*** | ||||
// F2 | ||||
|
r318 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit | ||
|
r170 | // (1) change the receiving buffer for the waveform picker | ||
|
r181 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; | ||
ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2; | ||||
current_ring_node_f2 = current_ring_node_f2->next; | ||||
|
r318 | if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0) | ||
|
r171 | { | ||
ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time; | ||||
ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time; | ||||
waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address; | ||||
|
r318 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000] | ||
|
r171 | } | ||
|
r318 | else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1) | ||
|
r171 | { | ||
ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time; | ||||
ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time; | ||||
waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; | ||||
|
r318 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000] | ||
|
r171 | } | ||
|
r170 | // (2) send an event for the waveforms transmission | ||
|
r238 | status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 ); | ||
|
r170 | } | ||
} | ||||
|
r21 | rtems_isr waveforms_isr( rtems_vector_number vector ) | ||
{ | ||||
|
r45 | /** This is the interrupt sub routine called by the waveform picker core. | ||
* | ||||
* This ISR launch different actions depending mainly on two pieces of information: | ||||
* 1. the values read in the registers of the waveform picker. | ||||
* 2. the current LFR mode. | ||||
* | ||||
*/ | ||||
|
r21 | |||
|
r170 | // STATUS | ||
// new error error buffer full | ||||
// 15 14 13 12 11 10 9 8 | ||||
// f3 f2 f1 f0 f3 f2 f1 f0 | ||||
// | ||||
// ready buffer | ||||
// 7 6 5 4 3 2 1 0 | ||||
// f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0 | ||||
|
r166 | rtems_status_code spare_status; | ||
|
r95 | |||
|
r170 | waveforms_isr_f3(); | ||
|
r265 | //************************************************* | ||
// copy the status bits in the housekeeping packets | ||||
housekeeping_packet.hk_lfr_vhdl_iir_cal = | ||||
|
r318 | (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE); | ||
|
r265 | |||
|
r318 | if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits | ||
|
r170 | { | ||
|
r171 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 ); | ||
|
r32 | } | ||
|
r33 | switch(lfrCurrentMode) | ||
|
r21 | { | ||
|
r238 | //******** | ||
// STANDBY | ||||
case LFR_MODE_STANDBY: | ||||
|
r33 | break; | ||
|
r246 | //************************** | ||
// LFR NORMAL, SBM1 and SBM2 | ||||
|
r238 | case LFR_MODE_NORMAL: | ||
case LFR_MODE_SBM1: | ||||
case LFR_MODE_SBM2: | ||||
waveform_isr_normal_sbm1_sbm2(); | ||||
|
r95 | break; | ||
|
r246 | //****** | ||
// BURST | ||||
|
r238 | case LFR_MODE_BURST: | ||
|
r170 | waveforms_isr_burst(); | ||
|
r95 | break; | ||
|
r246 | //******** | ||
// DEFAULT | ||||
|
r238 | default: | ||
|
r33 | break; | ||
|
r21 | } | ||
} | ||||
|
r106 | //************ | ||
// RTEMS TASKS | ||||
|
r18 | rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP | ||
{ | ||||
|
r45 | /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode. | ||
* | ||||
* @param unused is the starting argument of the RTEMS task | ||||
* | ||||
* The following data packets are sent by this task: | ||||
* - TM_LFR_SCIENCE_NORMAL_SWF_F0 | ||||
* - TM_LFR_SCIENCE_NORMAL_SWF_F1 | ||||
* - TM_LFR_SCIENCE_NORMAL_SWF_F2 | ||||
* | ||||
*/ | ||||
|
r5 | rtems_event_set event_out; | ||
|
r35 | rtems_id queue_id; | ||
|
r82 | rtems_status_code status; | ||
|
r238 | ring_node *ring_node_swf1_extracted_ptr; | ||
ring_node *ring_node_swf2_extracted_ptr; | ||||
|
r172 | |||
|
r320 | event_out = EVENT_SETS_NONE_PENDING; | ||
queue_id = RTEMS_ID_NONE; | ||||
|
r238 | ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted; | ||
ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted; | ||||
|
r168 | |||
|
r82 | status = get_message_queue_id_send( &queue_id ); | ||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
|
r246 | PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status); | ||
|
r82 | } | ||
|
r35 | |||
|
r246 | BOOT_PRINTF("in WFRM ***\n"); | ||
|
r18 | |||
|
r246 | while(1){ | ||
|
r21 | // wait for an RTEMS_EVENT | ||
|
r267 | rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH, | ||
|
r21 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||
|
r247 | |||
|
r35 | if (event_out == RTEMS_EVENT_MODE_NORMAL) | ||
{ | ||||
|
r246 | DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n"); | ||
ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0; | ||||
|
r238 | ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1; | ||
ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2; | ||||
status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) ); | ||||
status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) ); | ||||
status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) ); | ||||
|
r106 | } | ||
|
r267 | if (event_out == RTEMS_EVENT_SWF_RESYNCH) | ||
{ | ||||
snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); | ||||
} | ||||
|
r5 | } | ||
} | ||||
|
r17 | |||
|
r32 | rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP | ||
{ | ||||
|
r45 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3. | ||
* | ||||
* @param unused is the starting argument of the RTEMS task | ||||
* | ||||
* The following data packet is sent by this task: | ||||
* - TM_LFR_SCIENCE_NORMAL_CWF_F3 | ||||
* | ||||
*/ | ||||
|
r32 | rtems_event_set event_out; | ||
|
r35 | rtems_id queue_id; | ||
|
r82 | rtems_status_code status; | ||
|
r172 | ring_node ring_node_cwf3_light; | ||
|
r205 | ring_node *ring_node_to_send_cwf; | ||
|
r32 | |||
|
r320 | event_out = EVENT_SETS_NONE_PENDING; | ||
queue_id = RTEMS_ID_NONE; | ||||
|
r82 | status = get_message_queue_id_send( &queue_id ); | ||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status) | ||||
} | ||||
|
r35 | |||
|
r172 | ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; | ||
// init the ring_node_cwf3_light structure | ||||
ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light; | ||||
|
r318 | ring_node_cwf3_light.coarseTime = INIT_CHAR; | ||
ring_node_cwf3_light.fineTime = INIT_CHAR; | ||||
|
r172 | ring_node_cwf3_light.next = NULL; | ||
ring_node_cwf3_light.previous = NULL; | ||||
ring_node_cwf3_light.sid = SID_NORM_CWF_F3; | ||||
|
r318 | ring_node_cwf3_light.status = INIT_CHAR; | ||
|
r172 | |||
|
r292 | BOOT_PRINTF("in CWF3 ***\n"); | ||
|
r32 | |||
|
r292 | while(1){ | ||
|
r32 | // wait for an RTEMS_EVENT | ||
|
r33 | rtems_event_receive( RTEMS_EVENT_0, | ||
|
r238 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||
|
r129 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) | ||
|| (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) ) | ||||
|
r98 | { | ||
|
r318 | ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 ); | ||
if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3) | ||||
|
r92 | { | ||
|
r292 | PRINTF("send CWF_LONG_F3\n"); | ||
ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; | ||||
|
r205 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); | ||
|
r92 | } | ||
else | ||||
{ | ||||
|
r292 | PRINTF("send CWF_F3 (light)\n"); | ||
send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id ); | ||||
|
r129 | } | ||
|
r33 | } | ||
|
r92 | else | ||
{ | ||||
|
r129 | PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode) | ||
|
r33 | } | ||
} | ||||
} | ||||
rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2 | ||||
{ | ||||
|
r45 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2. | ||
* | ||||
* @param unused is the starting argument of the RTEMS task | ||||
* | ||||
* The following data packet is sent by this function: | ||||
* - TM_LFR_SCIENCE_BURST_CWF_F2 | ||||
* - TM_LFR_SCIENCE_SBM2_CWF_F2 | ||||
* | ||||
*/ | ||||
|
r33 | rtems_event_set event_out; | ||
|
r35 | rtems_id queue_id; | ||
|
r82 | rtems_status_code status; | ||
|
r179 | ring_node *ring_node_to_send; | ||
|
r181 | unsigned long long int acquisitionTimeF0_asLong; | ||
|
r320 | event_out = EVENT_SETS_NONE_PENDING; | ||
queue_id = RTEMS_ID_NONE; | ||||
|
r318 | acquisitionTimeF0_asLong = INIT_CHAR; | ||
|
r33 | |||
|
r82 | status = get_message_queue_id_send( &queue_id ); | ||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status) | ||||
} | ||||
|
r35 | |||
|
r292 | BOOT_PRINTF("in CWF2 ***\n"); | ||
|
r33 | |||
|
r292 | while(1){ | ||
|
r267 | // wait for an RTEMS_EVENT// send the snapshot when built | ||
status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ); | ||||
|
r238 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST, | ||
RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||||
|
r318 | ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 ); | ||
|
r33 | if (event_out == RTEMS_EVENT_MODE_BURST) | ||
|
r292 | { // data are sent whatever the transition time | ||
|
r179 | status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) ); | ||
|
r33 | } | ||
|
r238 | else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) | ||
|
r33 | { | ||
|
r238 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) | ||
{ | ||||
|
r292 | // data are sent depending on the transition time | ||
if ( time_management_regs->coarse_time >= lastValidEnterModeTime) | ||||
{ | ||||
status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) ); | ||||
} | ||||
|
r238 | } | ||
|
r112 | // launch snapshot extraction if needed | ||
|
r238 | if (extractSWF2 == true) | ||
|
r112 | { | ||
|
r181 | ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2; | ||
|
r112 | // extract the snapshot | ||
|
r318 | build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong, | ||
|
r238 | &ring_node_swf2_extracted, swf2_extracted ); | ||
extractSWF2 = false; | ||||
|
r267 | swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM | ||
|
r112 | } | ||
|
r238 | if (swf0_ready_flag_f2 == true) | ||
|
r112 | { | ||
|
r238 | extractSWF2 = true; | ||
// record the acquition time of the f0 snapshot to use to build the snapshot at f2 | ||||
|
r181 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); | ||
|
r238 | swf0_ready_flag_f2 = false; | ||
|
r112 | } | ||
|
r33 | } | ||
} | ||||
} | ||||
rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1 | ||||
{ | ||||
|
r45 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1. | ||
* | ||||
* @param unused is the starting argument of the RTEMS task | ||||
* | ||||
* The following data packet is sent by this function: | ||||
* - TM_LFR_SCIENCE_SBM1_CWF_F1 | ||||
* | ||||
*/ | ||||
|
r33 | rtems_event_set event_out; | ||
|
r35 | rtems_id queue_id; | ||
|
r82 | rtems_status_code status; | ||
|
r33 | |||
|
r194 | ring_node *ring_node_to_send_cwf; | ||
|
r33 | |||
|
r320 | event_out = EVENT_SETS_NONE_PENDING; | ||
queue_id = RTEMS_ID_NONE; | ||||
|
r82 | status = get_message_queue_id_send( &queue_id ); | ||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status) | ||||
} | ||||
|
r35 | |||
|
r247 | BOOT_PRINTF("in CWF1 ***\n"); | ||
|
r33 | |||
|
r247 | while(1){ | ||
|
r33 | // wait for an RTEMS_EVENT | ||
|
r238 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, | ||
RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||||
|
r179 | ring_node_to_send_cwf = getRingNodeToSendCWF( 1 ); | ||
|
r172 | ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1; | ||
|
r238 | if (lfrCurrentMode == LFR_MODE_SBM1) | ||
|
r227 | { | ||
|
r292 | // data are sent depending on the transition time | ||
if ( time_management_regs->coarse_time >= lastValidEnterModeTime ) | ||||
|
r238 | { | ||
|
r292 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); | ||
|
r238 | } | ||
|
r227 | } | ||
|
r112 | // launch snapshot extraction if needed | ||
|
r238 | if (extractSWF1 == true) | ||
|
r112 | { | ||
|
r179 | ring_node_to_send_swf_f1 = ring_node_to_send_cwf; | ||
|
r112 | // launch the snapshot extraction | ||
|
r238 | status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 ); | ||
extractSWF1 = false; | ||||
|
r112 | } | ||
|
r238 | if (swf0_ready_flag_f1 == true) | ||
|
r112 | { | ||
|
r238 | extractSWF1 = true; | ||
swf0_ready_flag_f1 = false; // this step shall be executed only one time | ||||
|
r112 | } | ||
|
r238 | if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction | ||
|
r112 | { | ||
|
r238 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ); | ||
swf1_ready = false; | ||||
swf2_ready = false; | ||||
|
r112 | } | ||
|
r32 | } | ||
} | ||||
|
r105 | rtems_task swbd_task(rtems_task_argument argument) | ||
{ | ||||
/** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers. | ||||
* | ||||
* @param unused is the starting argument of the RTEMS task | ||||
* | ||||
*/ | ||||
rtems_event_set event_out; | ||||
|
r181 | unsigned long long int acquisitionTimeF0_asLong; | ||
|
r320 | event_out = EVENT_SETS_NONE_PENDING; | ||
|
r318 | acquisitionTimeF0_asLong = INIT_CHAR; | ||
|
r105 | |||
BOOT_PRINTF("in SWBD ***\n") | ||||
|
r238 | while(1){ | ||
|
r105 | // wait for an RTEMS_EVENT | ||
|
r238 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, | ||
RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||||
if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) | ||||
|
r106 | { | ||
|
r181 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); | ||
|
r319 | build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong, | ||
|
r238 | &ring_node_swf1_extracted, swf1_extracted ); | ||
swf1_ready = true; // the snapshot has been extracted and is ready to be sent | ||||
|
r106 | } | ||
else | ||||
{ | ||||
PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out) | ||||
} | ||||
|
r105 | } | ||
} | ||||
|
r17 | //****************** | ||
// general functions | ||||
|
r87 | |||
|
r139 | void WFP_init_rings( void ) | ||
|
r87 | { | ||
|
r92 | // F0 RING | ||
|
r172 | init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER ); | ||
|
r87 | // F1 RING | ||
|
r172 | init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER ); | ||
|
r87 | // F2 RING | ||
|
r172 | init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER ); | ||
|
r131 | // F3 RING | ||
|
r172 | init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER ); | ||
|
r87 | |||
|
r238 | ring_node_swf1_extracted.buffer_address = (int) swf1_extracted; | ||
ring_node_swf2_extracted.buffer_address = (int) swf2_extracted; | ||||
|
r171 | |||
|
r92 | DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0) | ||
|
r238 | DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1) | ||
DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2) | ||||
DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3) | ||||
DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0) | ||||
DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1) | ||||
DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2) | ||||
DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3) | ||||
|
r172 | |||
|
r131 | } | ||
|
r87 | |||
|
r139 | void WFP_reset_current_ring_nodes( void ) | ||
|
r87 | { | ||
|
r179 | current_ring_node_f0 = waveform_ring_f0[0].next; | ||
current_ring_node_f1 = waveform_ring_f1[0].next; | ||||
current_ring_node_f2 = waveform_ring_f2[0].next; | ||||
current_ring_node_f3 = waveform_ring_f3[0].next; | ||||
|
r92 | |||
|
r179 | ring_node_to_send_swf_f0 = waveform_ring_f0; | ||
|
r171 | ring_node_to_send_swf_f1 = waveform_ring_f1; | ||
ring_node_to_send_swf_f2 = waveform_ring_f2; | ||||
|
r131 | |||
|
r179 | ring_node_to_send_cwf_f1 = waveform_ring_f1; | ||
ring_node_to_send_cwf_f2 = waveform_ring_f2; | ||||
|
r171 | ring_node_to_send_cwf_f3 = waveform_ring_f3; | ||
|
r18 | } | ||
|
r172 | int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id ) | ||
|
r38 | { | ||
|
r40 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. | ||
* | ||||
* @param waveform points to the buffer containing the data that will be send. | ||||
* @param headerCWF points to a table of headers that have been prepared for the data transmission. | ||||
* @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures | ||||
* contain information to setup the transmission of the data packets. | ||||
* | ||||
* By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer | ||||
* from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. | ||||
* | ||||
*/ | ||||
|
r38 | unsigned int i; | ||
|
r318 | unsigned int j; | ||
|
r38 | int ret; | ||
rtems_status_code status; | ||||
|
r179 | |||
|
r38 | char *sample; | ||
|
r171 | int *dataPtr; | ||
|
r38 | |||
ret = LFR_DEFAULT; | ||||
|
r171 | dataPtr = (int*) ring_node_to_send->buffer_address; | ||
|
r172 | ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime; | ||
ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime; | ||||
|
r38 | //********************** | ||
// BUILD CWF3_light DATA | ||||
|
r93 | for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++) | ||
|
r38 | { | ||
|
r171 | sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ]; | ||
|
r318 | for (j=0; j < CWF_BLK_SIZE; j++) | ||
{ | ||||
wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ]; | ||||
} | ||||
|
r38 | } | ||
|
r172 | // SEND PACKET | ||
status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) ); | ||||
if (status != RTEMS_SUCCESSFUL) { | ||||
ret = LFR_DEFAULT; | ||||
|
r38 | } | ||
return ret; | ||||
} | ||||
|
r135 | void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime, | ||
unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime ) | ||||
{ | ||||
unsigned long long int acquisitionTimeAsLong; | ||||
|
r318 | unsigned char localAcquisitionTime[BYTES_PER_TIME]; | ||
|
r135 | double deltaT; | ||
|
r318 | deltaT = INIT_FLOAT; | ||
|
r135 | |||
|
r318 | localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES ); | ||
localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES ); | ||||
localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE ); | ||||
localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime ); | ||||
localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE ); | ||||
localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime ); | ||||
|
r135 | |||
|
r318 | acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES ) | ||
+ ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES ) | ||||
+ ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES ) | ||||
+ ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES ) | ||||
+ ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE ) | ||||
+ ( (unsigned long long int) localAcquisitionTime[BYTE_5] ); | ||||
|
r135 | |||
switch( sid ) | ||||
{ | ||||
case SID_NORM_SWF_F0: | ||||
|
r318 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ; | ||
|
r135 | break; | ||
case SID_NORM_SWF_F1: | ||||
|
r318 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ; | ||
|
r135 | break; | ||
case SID_NORM_SWF_F2: | ||||
|
r318 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ; | ||
|
r135 | break; | ||
case SID_SBM1_CWF_F1: | ||||
|
r318 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ; | ||
|
r135 | break; | ||
case SID_SBM2_CWF_F2: | ||||
|
r318 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ; | ||
|
r135 | break; | ||
case SID_BURST_CWF_F2: | ||||
|
r318 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ; | ||
|
r135 | break; | ||
case SID_NORM_CWF_F3: | ||||
|
r318 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ; | ||
|
r135 | break; | ||
case SID_NORM_CWF_LONG_F3: | ||||
|
r318 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ; | ||
|
r135 | break; | ||
default: | ||||
|
r172 | PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid) | ||
|
r238 | deltaT = 0.; | ||
|
r135 | break; | ||
} | ||||
acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT; | ||||
// | ||||
|
r318 | acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES); | ||
acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES); | ||||
acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES); | ||||
acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES); | ||||
acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE ); | ||||
acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong ); | ||||
|
r135 | |||
} | ||||
|
r238 | void build_snapshot_from_ring( ring_node *ring_node_to_send, | ||
unsigned char frequencyChannel, | ||||
unsigned long long int acquisitionTimeF0_asLong, | ||||
ring_node *ring_node_swf_extracted, | ||||
int *swf_extracted) | ||||
|
r105 | { | ||
unsigned int i; | ||||
|
r319 | unsigned int node; | ||
|
r105 | unsigned long long int centerTime_asLong; | ||
|
r106 | unsigned long long int acquisitionTime_asLong; | ||
unsigned long long int bufferAcquisitionTime_asLong; | ||||
|
r105 | unsigned char *ptr1; | ||
unsigned char *ptr2; | ||||
|
r147 | unsigned char *timeCharPtr; | ||
|
r106 | unsigned char nb_ring_nodes; | ||
unsigned long long int frequency_asLong; | ||||
unsigned long long int nbTicksPerSample_asLong; | ||||
unsigned long long int nbSamplesPart1_asLong; | ||||
unsigned long long int sampleOffset_asLong; | ||||
|
r105 | |||
|
r106 | unsigned int deltaT_F0; | ||
unsigned int deltaT_F1; | ||||
unsigned long long int deltaT_F2; | ||||
|
r105 | |||
|
r318 | deltaT_F0 = DELTAT_F0; | ||
deltaT_F1 = DELTAF_F1; | ||||
deltaT_F2 = DELTAF_F2; | ||||
sampleOffset_asLong = INIT_CHAR; | ||||
|
r105 | |||
|
r181 | // (1) get the f0 acquisition time => the value is passed in argument | ||
|
r106 | |||
|
r110 | // (2) compute the central reference time | ||
|
r106 | centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0; | ||
|
r320 | acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2) | ||
bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2) | ||||
nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2) | ||||
|
r105 | |||
|
r110 | // (3) compute the acquisition time of the current snapshot | ||
|
r106 | switch(frequencyChannel) | ||
{ | ||||
|
r318 | case CHANNELF1: // 1 is for F1 = 4096 Hz | ||
|
r106 | acquisitionTime_asLong = centerTime_asLong - deltaT_F1; | ||
nb_ring_nodes = NB_RING_NODES_F1; | ||||
|
r318 | frequency_asLong = FREQ_F1; | ||
nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096; | ||||
|
r106 | break; | ||
|
r318 | case CHANNELF2: // 2 is for F2 = 256 Hz | ||
|
r106 | acquisitionTime_asLong = centerTime_asLong - deltaT_F2; | ||
nb_ring_nodes = NB_RING_NODES_F2; | ||||
|
r318 | frequency_asLong = FREQ_F2; | ||
nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256; | ||||
|
r106 | break; | ||
default: | ||||
acquisitionTime_asLong = centerTime_asLong; | ||||
|
r319 | nb_ring_nodes = 0; | ||
|
r318 | frequency_asLong = FREQ_F2; | ||
nbTicksPerSample_asLong = TICKS_PER_T2; | ||||
|
r106 | break; | ||
} | ||||
|
r105 | |||
|
r319 | //***************************************************************************** | ||
|
r110 | // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong | ||
|
r319 | node = 0; | ||
while ( node < nb_ring_nodes) | ||||
|
r106 | { | ||
|
r319 | //PRINTF1("%d ... ", node); | ||
bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime ); | ||||
|
r106 | if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong) | ||
{ | ||||
|
r246 | //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong); | ||
|
r319 | node = nb_ring_nodes; | ||
|
r106 | } | ||
|
r319 | else | ||
{ | ||||
node = node + 1; | ||||
ring_node_to_send = ring_node_to_send->previous; | ||||
} | ||||
|
r106 | } | ||
|
r105 | |||
|
r110 | // (5) compute the number of samples to take in the current buffer | ||
|
r318 | sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES; | ||
|
r106 | nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong; | ||
|
r246 | //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong); | ||
|
r105 | |||
|
r318 | // (6) compute the final acquisition time | ||
acquisitionTime_asLong = bufferAcquisitionTime_asLong + | ||||
(sampleOffset_asLong * nbTicksPerSample_asLong); | ||||
|
r105 | |||
|
r110 | // (7) copy the acquisition time at the beginning of the extrated snapshot | ||
|
r106 | ptr1 = (unsigned char*) &acquisitionTime_asLong; | ||
|
r171 | // fine time | ||
|
r238 | ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime; | ||
|
r318 | ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ]; | ||
ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ]; | ||||
|
r171 | // coarse time | ||
|
r238 | ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime; | ||
|
r318 | ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ]; | ||
ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ]; | ||||
ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ]; | ||||
ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ]; | ||||
|
r105 | |||
|
r106 | // re set the synchronization bit | ||
|
r171 | timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime; | ||
|
r318 | ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000] | ||
|
r106 | |||
|
r147 | if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) ) | ||
{ | ||||
nbSamplesPart1_asLong = 0; | ||||
} | ||||
|
r106 | // copy the part 1 of the snapshot in the extracted buffer | ||
for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ ) | ||||
{ | ||||
|
r238 | swf_extracted[i] = | ||
|
r171 | ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ]; | ||
|
r106 | } | ||
// copy the part 2 of the snapshot in the extracted buffer | ||||
ring_node_to_send = ring_node_to_send->next; | ||||
for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ ) | ||||
|
r105 | { | ||
|
r238 | swf_extracted[i] = | ||
|
r171 | ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ]; | ||
|
r105 | } | ||
|
r93 | } | ||
|
r38 | |||
|
r257 | double computeCorrection( unsigned char *timePtr ) | ||
|
r135 | { | ||
|
r168 | unsigned long long int acquisitionTime; | ||
unsigned long long int centerTime; | ||||
unsigned long long int previousTick; | ||||
unsigned long long int nextTick; | ||||
unsigned long long int deltaPreviousTick; | ||||
unsigned long long int deltaNextTick; | ||||
|
r246 | double deltaPrevious_ms; | ||
double deltaNext_ms; | ||||
|
r253 | double correctionInF2; | ||
|
r257 | |||
|
r320 | correctionInF2 = 0; //set to default value (Don_Initialisation_P2) | ||
|
r257 | // get acquisition time in fine time ticks | ||
acquisitionTime = get_acquisition_time( timePtr ); | ||||
|
r135 | |||
|
r257 | // compute center time | ||
|
r318 | centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667; | ||
previousTick = centerTime - (centerTime & INT16_ALL_F); | ||||
nextTick = previousTick + TICKS_PER_S; | ||||
|
r168 | |||
|
r257 | deltaPreviousTick = centerTime - previousTick; | ||
deltaNextTick = nextTick - centerTime; | ||||
|
r135 | |||
|
r318 | deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S; | ||
deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S; | ||||
|
r253 | |||
|
r257 | PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms); | ||
|
r253 | |||
|
r257 | // which tick is the closest? | ||
if (deltaPreviousTick > deltaNextTick) | ||||
{ | ||||
// the snapshot center is just before the second => increase delta_snapshot | ||||
|
r318 | correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S ); | ||
|
r257 | } | ||
else | ||||
{ | ||||
// the snapshot center is just after the second => decrease delta_snapshot | ||||
|
r318 | correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S ); | ||
|
r257 | } | ||
|
r168 | |||
|
r257 | PRINTF1(" correctionInF2 = %.2f\n", correctionInF2); | ||
return correctionInF2; | ||||
} | ||||
|
r168 | |||
|
r257 | void applyCorrection( double correction ) | ||
{ | ||||
int correctionInt; | ||||
|
r320 | correctionInt = 0; | ||
|
r272 | if (correction >= 0.) | ||
|
r257 | { | ||
|
r318 | if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) ) | ||
|
r263 | { | ||
|
r318 | correctionInt = ONE_TICK_CORR; | ||
|
r263 | } | ||
else | ||||
{ | ||||
|
r318 | correctionInt = CORR_MULT * floor(correction); | ||
|
r263 | } | ||
|
r168 | } | ||
else | ||||
{ | ||||
|
r318 | if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) ) | ||
|
r263 | { | ||
|
r318 | correctionInt = -ONE_TICK_CORR; | ||
|
r263 | } | ||
else | ||||
{ | ||||
|
r318 | correctionInt = CORR_MULT * ceil(correction); | ||
|
r263 | } | ||
|
r257 | } | ||
waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt; | ||||
} | ||||
void snapshot_resynchronization( unsigned char *timePtr ) | ||||
{ | ||||
|
r268 | /** This function compute a correction to apply on delta_snapshot. | ||
* | ||||
* | ||||
* @param timePtr is a pointer to the acquisition time of the snapshot being considered. | ||||
* | ||||
* @return void | ||||
* | ||||
*/ | ||||
|
r318 | static double correction = INIT_FLOAT; | ||
|
r267 | static resynchro_state state = MEASURE; | ||
|
r271 | static unsigned int nbSnapshots = 0; | ||
|
r257 | |||
int correctionInt; | ||||
correctionInt = 0; | ||||
switch (state) | ||||
{ | ||||
|
r267 | case MEASURE: | ||
|
r257 | // ******** | ||
|
r271 | PRINTF1("MEASURE === %d\n", nbSnapshots); | ||
|
r267 | state = CORRECTION; | ||
|
r263 | correction = computeCorrection( timePtr ); | ||
|
r267 | PRINTF1("MEASURE === correction = %.2f\n", correction ); | ||
|
r257 | applyCorrection( correction ); | ||
|
r267 | PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); | ||
|
r257 | //**** | ||
break; | ||||
|
r267 | case CORRECTION: | ||
|
r257 | //************ | ||
|
r271 | PRINTF1("CORRECTION === %d\n", nbSnapshots); | ||
|
r267 | state = MEASURE; | ||
|
r257 | computeCorrection( timePtr ); | ||
|
r274 | set_wfp_delta_snapshot(); | ||
|
r267 | PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); | ||
|
r257 | //**** | ||
break; | ||||
default: | ||||
break; | ||||
|
r168 | } | ||
|
r271 | |||
nbSnapshots++; | ||||
|
r135 | } | ||
|
r23 | //************** | ||
// wfp registers | ||||
|
r171 | void reset_wfp_burst_enable( void ) | ||
|
r97 | { | ||
/** This function resets the waveform picker burst_enable register. | ||||
* | ||||
* The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0. | ||||
* | ||||
*/ | ||||
|
r171 | // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0 | ||
|
r318 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN; | ||
|
r97 | } | ||
void reset_wfp_status( void ) | ||||
{ | ||||
/** This function resets the waveform picker status register. | ||||
* | ||||
* All status bits are set to 0 [new_err full_err full]. | ||||
* | ||||
*/ | ||||
|
r318 | waveform_picker_regs->status = INT16_ALL_F; | ||
|
r97 | } | ||
|
r171 | void reset_wfp_buffer_addresses( void ) | ||
{ | ||||
// F0 | ||||
|
r179 | waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08 | ||
waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c | ||||
|
r171 | // F1 | ||
|
r179 | waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10 | ||
waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14 | ||||
|
r171 | // F2 | ||
|
r179 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18 | ||
waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c | ||||
|
r171 | // F3 | ||
|
r179 | waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20 | ||
waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24 | ||||
|
r171 | } | ||
void reset_waveform_picker_regs( void ) | ||||
|
r97 | { | ||
/** This function resets the waveform picker module registers. | ||||
* | ||||
* The registers affected by this function are located at the following offset addresses: | ||||
* - 0x00 data_shaping | ||||
* - 0x04 run_burst_enable | ||||
* - 0x08 addr_data_f0 | ||||
* - 0x0C addr_data_f1 | ||||
* - 0x10 addr_data_f2 | ||||
* - 0x14 addr_data_f3 | ||||
* - 0x18 status | ||||
* - 0x1C delta_snapshot | ||||
* - 0x20 delta_f0 | ||||
* - 0x24 delta_f0_2 | ||||
|
r256 | * - 0x28 delta_f1 (obsolet parameter) | ||
|
r97 | * - 0x2c delta_f2 | ||
* - 0x30 nb_data_by_buffer | ||||
* - 0x34 nb_snapshot_param | ||||
* - 0x38 start_date | ||||
* - 0x3c nb_word_in_buffer | ||||
* | ||||
*/ | ||||
|
r110 | set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW | ||
|
r171 | |||
|
r110 | reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] | ||
|
r171 | |||
reset_wfp_buffer_addresses(); | ||||
|
r110 | reset_wfp_status(); // 0x18 | ||
|
r171 | |||
set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff | ||||
|
r97 | set_wfp_delta_f0_f0_2(); // 0x20, 0x24 | ||
|
r171 | |||
|
r256 | //the parameter delta_f1 [0x28] is not used anymore | ||
|
r171 | |||
|
r97 | set_wfp_delta_f2(); // 0x2c | ||
|
r171 | |||
|
r256 | DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot); | ||
DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0); | ||||
DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2); | ||||
DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1); | ||||
DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2); | ||||
// 2688 = 8 * 336 | ||||
|
r318 | waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1 | ||
waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples | ||||
waveform_picker_regs->start_date = COARSE_TIME_MASK; | ||||
|
r171 | // | ||
// coarse time and fine time registers are not initialized, they are volatile | ||||
// | ||||
|
r318 | waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8 | ||
|
r97 | } | ||
void set_wfp_data_shaping( void ) | ||||
|
r23 | { | ||
|
r40 | /** This function sets the data_shaping register of the waveform picker module. | ||
* | ||||
* The value is read from one field of the parameter_dump_packet structure:\n | ||||
* bw_sp0_sp1_r0_r1 | ||||
* | ||||
*/ | ||||
|
r32 | unsigned char data_shaping; | ||
|
r23 | // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register | ||
// waveform picker : [R1 R0 SP1 SP0 BW] | ||||
|
r32 | |||
|
r192 | data_shaping = parameter_dump_packet.sy_lfr_common_parameters; | ||
|
r32 | |||
|
r23 | waveform_picker_regs->data_shaping = | ||
|
r318 | ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW | ||
+ ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0 | ||||
+ ( (data_shaping & BIT_3) >> 1 ) // SP1 | ||||
+ ( (data_shaping & BIT_2) << 1 ) // R0 | ||||
+ ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1 | ||||
+ ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2 | ||||
|
r23 | } | ||
|
r90 | void set_wfp_burst_enable_register( unsigned char mode ) | ||
|
r23 | { | ||
|
r40 | /** This function sets the waveform picker burst_enable register depending on the mode. | ||
* | ||||
* @param mode is the LFR mode to launch. | ||||
* | ||||
* The burst bits shall be before the enable bits. | ||||
* | ||||
*/ | ||||
|
r90 | // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0 | ||
// the burst bits shall be set first, before the enable bits | ||||
switch(mode) { | ||||
|
r238 | case LFR_MODE_NORMAL: | ||
case LFR_MODE_SBM1: | ||||
case LFR_MODE_SBM2: | ||||
|
r318 | waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst | ||
|
r324 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_ALL; // [1111] enable f3 f2 f1 f0 | ||
|
r90 | break; | ||
|
r238 | case LFR_MODE_BURST: | ||
|
r318 | waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled | ||
|
r324 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_BURST; // [1100] enable f3 and f2 | ||
|
r90 | break; | ||
default: | ||||
|
r318 | waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled | ||
|
r90 | break; | ||
} | ||||
} | ||||
|
r97 | |||
void set_wfp_delta_snapshot( void ) | ||||
|
r90 | { | ||
|
r97 | /** This function sets the delta_snapshot register of the waveform picker module. | ||
|
r90 | * | ||
|
r97 | * The value is read from two (unsigned char) of the parameter_dump_packet structure: | ||
* - sy_lfr_n_swf_p[0] | ||||
* - sy_lfr_n_swf_p[1] | ||||
|
r40 | * | ||
*/ | ||||
|
r97 | unsigned int delta_snapshot; | ||
unsigned int delta_snapshot_in_T2; | ||||
|
r33 | |||
|
r318 | delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256) | ||
|
r97 | + parameter_dump_packet.sy_lfr_n_swf_p[1]; | ||
|
r318 | delta_snapshot_in_T2 = delta_snapshot * FREQ_F2; | ||
|
r160 | waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes | ||
|
r95 | } | ||
|
r97 | void set_wfp_delta_f0_f0_2( void ) | ||
|
r95 | { | ||
|
r97 | unsigned int delta_snapshot; | ||
unsigned int nb_samples_per_snapshot; | ||||
float delta_f0_in_float; | ||||
delta_snapshot = waveform_picker_regs->delta_snapshot; | ||||
|
r318 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; | ||
delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2; | ||||
|
r97 | |||
|
r256 | waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float ); | ||
|
r362 | waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2; | ||
|
r90 | } | ||
|
r95 | |||
|
r97 | void set_wfp_delta_f1( void ) | ||
|
r95 | { | ||
|
r256 | /** Sets the value of the delta_f1 parameter | ||
* | ||||
* @param void | ||||
* | ||||
* @return void | ||||
* | ||||
* delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms. | ||||
* | ||||
*/ | ||||
|
r97 | unsigned int delta_snapshot; | ||
unsigned int nb_samples_per_snapshot; | ||||
float delta_f1_in_float; | ||||
delta_snapshot = waveform_picker_regs->delta_snapshot; | ||||
|
r318 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; | ||
delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2; | ||||
|
r97 | |||
waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float ); | ||||
|
r95 | } | ||
|
r256 | void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used | ||
|
r23 | { | ||
|
r256 | /** Sets the value of the delta_f2 parameter | ||
* | ||||
* @param void | ||||
* | ||||
* @return void | ||||
* | ||||
* delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2 | ||||
* waveforms (see lpp_waveform_snapshot_controler.vhd for details). | ||||
* | ||||
*/ | ||||
|
r97 | unsigned int delta_snapshot; | ||
unsigned int nb_samples_per_snapshot; | ||||
|
r40 | |||
|
r97 | delta_snapshot = waveform_picker_regs->delta_snapshot; | ||
|
r318 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; | ||
|
r97 | |||
|
r318 | waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1; | ||
|
r90 | } | ||
|
r32 | |||
//***************** | ||||
// local parameters | ||||
|
r133 | |||
void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid ) | ||||
|
r32 | { | ||
|
r133 | /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument. | ||
|
r40 | * | ||
|
r133 | * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update. | ||
* @param sid is the source identifier of the packet being updated. | ||||
* | ||||
* REQ-LFR-SRS-5240 / SSS-CP-FS-590 | ||||
* The sequence counters shall wrap around from 2^14 to zero. | ||||
* The sequence counter shall start at zero at startup. | ||||
* | ||||
* REQ-LFR-SRS-5239 / SSS-CP-FS-580 | ||||
* All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0 | ||||
|
r40 | * | ||
*/ | ||||
|
r56 | unsigned short *sequence_cnt; | ||
unsigned short segmentation_grouping_flag; | ||||
unsigned short new_packet_sequence_control; | ||||
|
r133 | rtems_mode initial_mode_set; | ||
rtems_mode current_mode_set; | ||||
rtems_status_code status; | ||||
|
r56 | |||
|
r320 | initial_mode_set = RTEMS_DEFAULT_MODES; | ||
current_mode_set = RTEMS_DEFAULT_MODES; | ||||
sequence_cnt = NULL; | ||||
|
r133 | //****************************************** | ||
// CHANGE THE MODE OF THE CALLING RTEMS TASK | ||||
status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set ); | ||||
if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2) | ||||
|| (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3) | ||||
|| (sid == SID_BURST_CWF_F2) | ||||
|| (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2) | ||||
|| (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2) | ||||
|| (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2) | ||||
|| (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0) | ||||
|| (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) ) | ||||
|
r56 | { | ||
|
r128 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST; | ||
|
r56 | } | ||
|
r133 | else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2) | ||
|| (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0) | ||||
|| (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0) | ||||
|| (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) ) | ||||
|
r56 | { | ||
|
r128 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2; | ||
|
r56 | } | ||
else | ||||
{ | ||||
|
r128 | sequence_cnt = (unsigned short *) NULL; | ||
|
r56 | PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid) | ||
} | ||||
|
r84 | if (sequence_cnt != NULL) | ||
{ | ||||
|
r318 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; | ||
*sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK; | ||||
|
r155 | |||
new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ; | ||||
|
r318 | packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE); | ||
|
r155 | packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); | ||
|
r128 | // increment the sequence counter | ||
|
r84 | if ( *sequence_cnt < SEQ_CNT_MAX) | ||
{ | ||||
*sequence_cnt = *sequence_cnt + 1; | ||||
} | ||||
else | ||||
{ | ||||
*sequence_cnt = 0; | ||||
} | ||||
|
r56 | } | ||
|
r133 | |||
|
r228 | //************************************* | ||
// RESTORE THE MODE OF THE CALLING TASK | ||||
|
r133 | status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, ¤t_mode_set ); | ||
|
r56 | } | ||