wf_handler.c
1303 lines
| 52.5 KiB
| text/x-c
|
CLexer
/ src / wf_handler.c
paul
|
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" | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
paul
|
r87 | //***************** | ||
// waveform headers | ||||
paul
|
r34 | // SWF | ||
Header_TM_LFR_SCIENCE_SWF_t headerSWF_F0[7]; | ||||
Header_TM_LFR_SCIENCE_SWF_t headerSWF_F1[7]; | ||||
Header_TM_LFR_SCIENCE_SWF_t headerSWF_F2[7]; | ||||
// CWF | ||||
paul
|
r98 | Header_TM_LFR_SCIENCE_CWF_t headerCWF_F1[ NB_PACKETS_PER_GROUP_OF_CWF ]; | ||
Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_BURST[ NB_PACKETS_PER_GROUP_OF_CWF ]; | ||||
Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_SBM2[ NB_PACKETS_PER_GROUP_OF_CWF ]; | ||||
Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3[ NB_PACKETS_PER_GROUP_OF_CWF ]; | ||||
Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3_light[ NB_PACKETS_PER_GROUP_OF_CWF_LIGHT ]; | ||||
paul
|
r33 | |||
paul
|
r87 | //************** | ||
// waveform ring | ||||
paul
|
r92 | ring_node waveform_ring_f0[NB_RING_NODES_F0]; | ||
paul
|
r87 | ring_node waveform_ring_f1[NB_RING_NODES_F1]; | ||
ring_node waveform_ring_f2[NB_RING_NODES_F2]; | ||||
paul
|
r131 | ring_node waveform_ring_f3[NB_RING_NODES_F3]; | ||
paul
|
r92 | ring_node *current_ring_node_f0; | ||
ring_node *ring_node_to_send_swf_f0; | ||||
paul
|
r87 | ring_node *current_ring_node_f1; | ||
ring_node *ring_node_to_send_swf_f1; | ||||
ring_node *ring_node_to_send_cwf_f1; | ||||
ring_node *current_ring_node_f2; | ||||
ring_node *ring_node_to_send_swf_f2; | ||||
ring_node *ring_node_to_send_cwf_f2; | ||||
paul
|
r131 | ring_node *current_ring_node_f3; | ||
ring_node *ring_node_to_send_cwf_f3; | ||||
paul
|
r87 | |||
paul
|
r105 | bool extractSWF = false; | ||
paul
|
r106 | bool swf_f0_ready = false; | ||
bool swf_f1_ready = false; | ||||
bool swf_f2_ready = false; | ||||
paul
|
r105 | |||
paul
|
r106 | int wf_snap_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET ]; | ||
//********************* | ||||
// Interrupt SubRoutine | ||||
void reset_extractSWF( void ) | ||||
{ | ||||
extractSWF = false; | ||||
swf_f0_ready = false; | ||||
swf_f1_ready = false; | ||||
swf_f2_ready = false; | ||||
} | ||||
paul
|
r105 | |||
paul@pc-solar1.lab-lpp.local
|
r21 | rtems_isr waveforms_isr( rtems_vector_number vector ) | ||
{ | ||||
paul
|
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. | ||||
* | ||||
*/ | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | |||
paul
|
r106 | rtems_status_code status; | ||
paul
|
r95 | |||
paul
|
r129 | 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 | ||
paul
|
r33 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) | ||
paul
|
r32 | { // in modes other than STANDBY and BURST, send the CWF_F3 data | ||
paul
|
r33 | if ((waveform_picker_regs->status & 0x08) == 0x08){ // [1000] f3 is full | ||
paul
|
r32 | // (1) change the receiving buffer for the waveform picker | ||
paul
|
r131 | ring_node_to_send_cwf_f3 = current_ring_node_f3; | ||
current_ring_node_f3 = current_ring_node_f3->next; | ||||
waveform_picker_regs->addr_data_f3 = current_ring_node_f3->buffer_address; | ||||
paul
|
r32 | // (2) send an event for the waveforms transmission | ||
paul
|
r33 | if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | ||
paul
|
r32 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||
} | ||||
paul
|
r130 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2); | ||
paul
|
r33 | waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff777; // reset f3 bits to 0, [1111 0111 0111 0111] | ||
paul
|
r32 | } | ||
} | ||||
paul
|
r33 | switch(lfrCurrentMode) | ||
paul@pc-solar1.lab-lpp.local
|
r21 | { | ||
//******** | ||||
// STANDBY | ||||
case(LFR_MODE_STANDBY): | ||||
paul
|
r33 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r21 | |||
//****** | ||||
// NORMAL | ||||
case(LFR_MODE_NORMAL): | ||||
paul
|
r94 | if ( (waveform_picker_regs->status & 0xff8) != 0x00) // [1000] check the error bits | ||
{ | ||||
rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||||
} | ||||
if ( (waveform_picker_regs->status & 0x07) == 0x07) // [0111] check the f2, f1, f0 full bits | ||||
{ | ||||
paul
|
r92 | // change F0 ring node | ||
ring_node_to_send_swf_f0 = current_ring_node_f0; | ||||
current_ring_node_f0 = current_ring_node_f0->next; | ||||
waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address; | ||||
paul
|
r90 | // change F1 ring node | ||
ring_node_to_send_swf_f1 = current_ring_node_f1; | ||||
current_ring_node_f1 = current_ring_node_f1->next; | ||||
waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; | ||||
// change F2 ring node | ||||
ring_node_to_send_swf_f2 = current_ring_node_f2; | ||||
current_ring_node_f2 = current_ring_node_f2->next; | ||||
waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; | ||||
paul
|
r94 | // | ||
paul
|
r118 | if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) | ||
paul
|
r95 | { | ||
paul
|
r118 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||
paul
|
r95 | } | ||
paul
|
r118 | waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff888; // [1000 1000 1000] | ||
paul
|
r95 | } | ||
break; | ||||
//****** | ||||
// BURST | ||||
case(LFR_MODE_BURST): | ||||
if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit | ||||
// (1) change the receiving buffer for the waveform picker | ||||
ring_node_to_send_cwf_f2 = current_ring_node_f2; | ||||
current_ring_node_f2 = current_ring_node_f2->next; | ||||
waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; | ||||
// (2) send an event for the waveforms transmission | ||||
if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) { | ||||
rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||||
} | ||||
waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0 | ||||
} | ||||
break; | ||||
//***** | ||||
// SBM1 | ||||
case(LFR_MODE_SBM1): | ||||
if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit | ||||
// (1) change the receiving buffer for the waveform picker | ||||
ring_node_to_send_cwf_f1 = current_ring_node_f1; | ||||
current_ring_node_f1 = current_ring_node_f1->next; | ||||
waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; | ||||
paul
|
r112 | // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed) | ||
paul
|
r106 | status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 ); | ||
waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1 bits = 0 | ||||
paul
|
r95 | } | ||
if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit | ||||
paul
|
r106 | swf_f0_ready = true; | ||
paul
|
r105 | waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0 | ||
paul
|
r95 | } | ||
paul
|
r105 | if ( (waveform_picker_regs->status & 0x04) == 0x04 ) { // [0100] check the f2 full bit | ||
paul
|
r106 | swf_f2_ready = true; | ||
paul
|
r105 | waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bits = 0 | ||
paul
|
r33 | } | ||
break; | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | |||
//***** | ||||
// SBM2 | ||||
case(LFR_MODE_SBM2): | ||||
paul
|
r87 | if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit | ||
paul
|
r33 | // (1) change the receiving buffer for the waveform picker | ||
paul
|
r87 | ring_node_to_send_cwf_f2 = current_ring_node_f2; | ||
current_ring_node_f2 = current_ring_node_f2->next; | ||||
waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; | ||||
paul
|
r33 | // (2) send an event for the waveforms transmission | ||
paul
|
r106 | status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 ); | ||
waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0 | ||||
paul
|
r33 | } | ||
paul
|
r90 | if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit | ||
paul
|
r106 | swf_f0_ready = true; | ||
waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0 | ||||
paul
|
r90 | } | ||
if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit | ||||
paul
|
r106 | swf_f1_ready = true; | ||
waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1, f0 bits = 0 | ||||
paul
|
r90 | } | ||
paul
|
r33 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r23 | |||
paul@pc-solar1.lab-lpp.local
|
r21 | //******** | ||
// DEFAULT | ||||
default: | ||||
paul
|
r33 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r21 | } | ||
} | ||||
paul
|
r106 | //************ | ||
// RTEMS TASKS | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP | ||
{ | ||||
paul
|
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 | ||||
* | ||||
*/ | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | rtems_event_set event_out; | ||
paul
|
r35 | rtems_id queue_id; | ||
paul
|
r82 | rtems_status_code status; | ||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
paul
|
r34 | init_header_snapshot_wf_table( SID_NORM_SWF_F0, headerSWF_F0 ); | ||
init_header_snapshot_wf_table( SID_NORM_SWF_F1, headerSWF_F1 ); | ||||
init_header_snapshot_wf_table( SID_NORM_SWF_F2, headerSWF_F2 ); | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | |||
paul
|
r82 | status = get_message_queue_id_send( &queue_id ); | ||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status) | ||||
} | ||||
paul
|
r35 | |||
BOOT_PRINTF("in WFRM ***\n") | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | |||
while(1){ | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | // wait for an RTEMS_EVENT | ||
paul
|
r34 | rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1 | ||
paul
|
r105 | | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM, | ||
paul@pc-solar1.lab-lpp.local
|
r21 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||
paul
|
r35 | if (event_out == RTEMS_EVENT_MODE_NORMAL) | ||
{ | ||||
paul
|
r106 | DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_NORMAL\n") | ||
paul
|
r92 | send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id); | ||
paul
|
r87 | send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id); | ||
send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id); | ||||
paul
|
r94 | } | ||
paul
|
r105 | if (event_out == RTEMS_EVENT_MODE_SBM1) | ||
paul
|
r94 | { | ||
paul
|
r106 | DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM1\n") | ||
paul
|
r94 | send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id); | ||
paul
|
r106 | send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F1, headerSWF_F1, queue_id); | ||
paul
|
r94 | send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id); | ||
paul
|
r35 | } | ||
paul
|
r106 | if (event_out == RTEMS_EVENT_MODE_SBM2) | ||
{ | ||||
DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n") | ||||
send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id); | ||||
send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id); | ||||
send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F2, headerSWF_F2, queue_id); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | } | ||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r17 | |||
paul
|
r32 | rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP | ||
{ | ||||
paul
|
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 | ||||
* | ||||
*/ | ||||
paul
|
r32 | rtems_event_set event_out; | ||
paul
|
r35 | rtems_id queue_id; | ||
paul
|
r82 | rtems_status_code status; | ||
paul
|
r32 | |||
paul
|
r92 | init_header_continuous_wf_table( SID_NORM_CWF_LONG_F3, headerCWF_F3 ); | ||
init_header_continuous_cwf3_light_table( headerCWF_F3_light ); | ||||
paul
|
r32 | |||
paul
|
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) | ||||
} | ||||
paul
|
r35 | |||
BOOT_PRINTF("in CWF3 ***\n") | ||||
paul
|
r32 | |||
while(1){ | ||||
// wait for an RTEMS_EVENT | ||||
paul
|
r33 | rtems_event_receive( RTEMS_EVENT_0, | ||
paul
|
r32 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||
paul
|
r129 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) | ||
|| (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) ) | ||||
paul
|
r98 | { | ||
paul
|
r92 | if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01) | ||
{ | ||||
paul
|
r129 | PRINTF("send CWF_LONG_F3\n") | ||
paul
|
r131 | send_waveform_CWF( | ||
(volatile int*) current_ring_node_f3->buffer_address, | ||||
SID_NORM_CWF_LONG_F3, headerCWF_F3, queue_id ); | ||||
paul
|
r92 | } | ||
else | ||||
{ | ||||
paul
|
r129 | PRINTF("send CWF_F3 (light)\n") | ||
paul
|
r131 | send_waveform_CWF3_light( | ||
(volatile int*) current_ring_node_f3->buffer_address, | ||||
headerCWF_F3_light, queue_id ); | ||||
paul
|
r129 | } | ||
paul
|
r33 | } | ||
paul
|
r92 | else | ||
{ | ||||
paul
|
r129 | PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode) | ||
paul
|
r33 | } | ||
} | ||||
} | ||||
rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2 | ||||
{ | ||||
paul
|
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 | ||||
* | ||||
*/ | ||||
paul
|
r33 | rtems_event_set event_out; | ||
paul
|
r35 | rtems_id queue_id; | ||
paul
|
r82 | rtems_status_code status; | ||
paul
|
r33 | |||
init_header_continuous_wf_table( SID_BURST_CWF_F2, headerCWF_F2_BURST ); | ||||
paul
|
r34 | init_header_continuous_wf_table( SID_SBM2_CWF_F2, headerCWF_F2_SBM2 ); | ||
paul
|
r33 | |||
paul
|
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) | ||||
} | ||||
paul
|
r35 | |||
BOOT_PRINTF("in CWF2 ***\n") | ||||
paul
|
r33 | |||
while(1){ | ||||
// wait for an RTEMS_EVENT | ||||
rtems_event_receive( RTEMS_EVENT_MODE_BURST | RTEMS_EVENT_MODE_SBM2, | ||||
RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||||
if (event_out == RTEMS_EVENT_MODE_BURST) | ||||
{ | ||||
paul
|
r91 | send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id ); | ||
paul
|
r33 | } | ||
paul
|
r87 | if (event_out == RTEMS_EVENT_MODE_SBM2) | ||
paul
|
r33 | { | ||
paul
|
r91 | send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id ); | ||
paul
|
r112 | // launch snapshot extraction if needed | ||
if (extractSWF == true) | ||||
{ | ||||
ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2; | ||||
// extract the snapshot | ||||
build_snapshot_from_ring( ring_node_to_send_swf_f2, 2 ); | ||||
// send the snapshot when built | ||||
status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ); | ||||
extractSWF = false; | ||||
} | ||||
if (swf_f0_ready && swf_f1_ready) | ||||
{ | ||||
extractSWF = true; | ||||
swf_f0_ready = false; | ||||
swf_f1_ready = false; | ||||
} | ||||
paul
|
r33 | } | ||
} | ||||
} | ||||
rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1 | ||||
{ | ||||
paul
|
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 | ||||
* | ||||
*/ | ||||
paul
|
r33 | rtems_event_set event_out; | ||
paul
|
r35 | rtems_id queue_id; | ||
paul
|
r82 | rtems_status_code status; | ||
paul
|
r33 | |||
init_header_continuous_wf_table( SID_SBM1_CWF_F1, headerCWF_F1 ); | ||||
paul
|
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) | ||||
} | ||||
paul
|
r35 | |||
BOOT_PRINTF("in CWF1 ***\n") | ||||
paul
|
r33 | |||
while(1){ | ||||
// wait for an RTEMS_EVENT | ||||
rtems_event_receive( RTEMS_EVENT_MODE_SBM1, | ||||
RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||||
paul
|
r91 | send_waveform_CWF( (volatile int*) ring_node_to_send_cwf_f1->buffer_address, SID_SBM1_CWF_F1, headerCWF_F1, queue_id ); | ||
paul
|
r112 | // launch snapshot extraction if needed | ||
if (extractSWF == true) | ||||
{ | ||||
ring_node_to_send_swf_f1 = ring_node_to_send_cwf_f1; | ||||
// launch the snapshot extraction | ||||
status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_SBM1 ); | ||||
extractSWF = false; | ||||
} | ||||
if (swf_f0_ready == true) | ||||
{ | ||||
extractSWF = true; | ||||
swf_f0_ready = false; // this step shall be executed only one time | ||||
} | ||||
if ((swf_f1_ready == true) && (swf_f2_ready == true)) // swf_f1 is ready after the extraction | ||||
{ | ||||
status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM1 ); | ||||
swf_f1_ready = false; | ||||
swf_f2_ready = false; | ||||
} | ||||
paul
|
r32 | } | ||
} | ||||
paul
|
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; | ||||
BOOT_PRINTF("in SWBD ***\n") | ||||
while(1){ | ||||
// wait for an RTEMS_EVENT | ||||
paul
|
r106 | rtems_event_receive( RTEMS_EVENT_MODE_SBM1 | RTEMS_EVENT_MODE_SBM2, | ||
paul
|
r105 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||
paul
|
r106 | if (event_out == RTEMS_EVENT_MODE_SBM1) | ||
{ | ||||
build_snapshot_from_ring( ring_node_to_send_swf_f1, 1 ); | ||||
paul
|
r112 | swf_f1_ready = true; // the snapshot has been extracted and is ready to be sent | ||
paul
|
r106 | } | ||
else | ||||
{ | ||||
PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out) | ||||
} | ||||
paul
|
r105 | } | ||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r17 | //****************** | ||
// general functions | ||||
paul
|
r87 | |||
void init_waveform_rings( void ) | ||||
{ | ||||
paul
|
r92 | // F0 RING | ||
paul
|
r131 | init_waveform_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_snap_f0 ); | ||
paul
|
r87 | // F1 RING | ||
paul
|
r131 | init_waveform_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_snap_f1 ); | ||
paul
|
r87 | // F2 RING | ||
paul
|
r131 | init_waveform_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_snap_f2 ); | ||
// F3 RING | ||||
init_waveform_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_cont_f3 ); | ||||
paul
|
r87 | |||
paul
|
r92 | DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0) | ||
paul
|
r87 | DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1) | ||
DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2) | ||||
paul
|
r131 | DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3) | ||
} | ||||
paul
|
r87 | |||
paul
|
r131 | void init_waveform_ring(ring_node waveform_ring[], unsigned char nbNodes, volatile int wfrm[] ) | ||
{ | ||||
unsigned char i; | ||||
waveform_ring[0].next = (ring_node*) &waveform_ring[ 1 ]; | ||||
waveform_ring[0].previous = (ring_node*) &waveform_ring[ nbNodes - 1 ]; | ||||
waveform_ring[0].buffer_address = (int) &wfrm[0]; | ||||
waveform_ring[nbNodes-1].next = (ring_node*) &waveform_ring[ 0 ]; | ||||
waveform_ring[nbNodes-1].previous = (ring_node*) &waveform_ring[ nbNodes - 2 ]; | ||||
waveform_ring[nbNodes-1].buffer_address = (int) &wfrm[ (nbNodes-1) * WFRM_BUFFER ]; | ||||
for(i=1; i<nbNodes-1; i++) | ||||
{ | ||||
waveform_ring[i].next = (ring_node*) &waveform_ring[ i + 1 ]; | ||||
waveform_ring[i].previous = (ring_node*) &waveform_ring[ i - 1 ]; | ||||
waveform_ring[i].buffer_address = (int) &wfrm[ i * WFRM_BUFFER ]; | ||||
} | ||||
paul
|
r87 | } | ||
void reset_current_ring_nodes( void ) | ||||
{ | ||||
paul
|
r92 | current_ring_node_f0 = waveform_ring_f0; | ||
ring_node_to_send_swf_f0 = waveform_ring_f0; | ||||
paul
|
r87 | current_ring_node_f1 = waveform_ring_f1; | ||
ring_node_to_send_cwf_f1 = waveform_ring_f1; | ||||
ring_node_to_send_swf_f1 = waveform_ring_f1; | ||||
current_ring_node_f2 = waveform_ring_f2; | ||||
ring_node_to_send_cwf_f2 = waveform_ring_f2; | ||||
ring_node_to_send_swf_f2 = waveform_ring_f2; | ||||
paul
|
r131 | |||
current_ring_node_f3 = waveform_ring_f3; | ||||
ring_node_to_send_cwf_f3 = waveform_ring_f3; | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | } | ||
paul
|
r34 | int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF) | ||
paul@pc-solar1.lab-lpp.local
|
r18 | { | ||
paul
|
r33 | unsigned char i; | ||
for (i=0; i<7; i++) | ||||
{ | ||||
paul
|
r34 | headerSWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID; | ||
headerSWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID; | ||||
headerSWF[ i ].reserved = DEFAULT_RESERVED; | ||||
headerSWF[ i ].userApplication = CCSDS_USER_APP; | ||||
paul
|
r116 | headerSWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); | ||
headerSWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | ||||
paul
|
r92 | headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | ||
if (i == 6) | ||||
paul
|
r33 | { | ||
paul
|
r92 | headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8); | ||
headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 ); | ||||
headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_224 >> 8); | ||||
headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_224 ); | ||||
paul
|
r33 | } | ||
else | ||||
{ | ||||
paul
|
r92 | headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8); | ||
headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 ); | ||||
headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_304 >> 8); | ||||
headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_304 ); | ||||
paul
|
r33 | } | ||
paul
|
r34 | headerSWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | ||
headerSWF[ i ].pktCnt = DEFAULT_PKTCNT; // PKT_CNT | ||||
headerSWF[ i ].pktNr = i+1; // PKT_NR | ||||
paul
|
r33 | // DATA FIELD HEADER | ||
paul
|
r34 | headerSWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | ||
headerSWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type | ||||
headerSWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype | ||||
headerSWF[ i ].destinationID = TM_DESTINATION_ID_GROUND; | ||||
paul
|
r33 | // AUXILIARY DATA HEADER | ||
paul
|
r34 | headerSWF[ i ].time[0] = 0x00; | ||
headerSWF[ i ].time[0] = 0x00; | ||||
headerSWF[ i ].time[0] = 0x00; | ||||
headerSWF[ i ].time[0] = 0x00; | ||||
headerSWF[ i ].time[0] = 0x00; | ||||
headerSWF[ i ].time[0] = 0x00; | ||||
paul
|
r56 | headerSWF[ i ].sid = sid; | ||
headerSWF[ i ].hkBIA = DEFAULT_HKBIA; | ||||
paul
|
r33 | } | ||
return LFR_SUCCESSFUL; | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | } | ||
paul@pc-solar1.lab-lpp.local
|
r18 | |||
paul
|
r33 | int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF ) | ||
paul@pc-solar1.lab-lpp.local
|
r23 | { | ||
paul
|
r33 | unsigned int i; | ||
paul
|
r98 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) | ||
paul
|
r33 | { | ||
headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID; | ||||
headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID; | ||||
headerCWF[ i ].reserved = DEFAULT_RESERVED; | ||||
headerCWF[ i ].userApplication = CCSDS_USER_APP; | ||||
paul
|
r37 | if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) ) | ||
paul
|
r34 | { | ||
paul
|
r116 | headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8); | ||
headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2); | ||||
paul
|
r34 | } | ||
else | ||||
{ | ||||
paul
|
r116 | headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); | ||
headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | ||||
paul
|
r34 | } | ||
paul
|
r93 | headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | ||
headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); | ||||
headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); | ||||
headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); | ||||
headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF ); | ||||
paul
|
r33 | headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | ||
// DATA FIELD HEADER | ||||
headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | ||||
headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type | ||||
headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype | ||||
headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND; | ||||
// AUXILIARY DATA HEADER | ||||
headerCWF[ i ].sid = sid; | ||||
headerCWF[ i ].hkBIA = DEFAULT_HKBIA; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
} | ||||
return LFR_SUCCESSFUL; | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | } | ||
paul
|
r92 | int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF ) | ||
paul
|
r38 | { | ||
unsigned int i; | ||||
paul
|
r98 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) | ||
paul
|
r38 | { | ||
headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID; | ||||
headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID; | ||||
headerCWF[ i ].reserved = DEFAULT_RESERVED; | ||||
headerCWF[ i ].userApplication = CCSDS_USER_APP; | ||||
paul
|
r116 | headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); | ||
headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | ||||
paul
|
r93 | |||
headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | ||||
headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8); | ||||
headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 ); | ||||
headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8); | ||||
headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 ); | ||||
paul
|
r38 | headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | ||
// DATA FIELD HEADER | ||||
headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | ||||
headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type | ||||
headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype | ||||
headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND; | ||||
// AUXILIARY DATA HEADER | ||||
headerCWF[ i ].sid = SID_NORM_CWF_F3; | ||||
headerCWF[ i ].hkBIA = DEFAULT_HKBIA; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
headerCWF[ i ].time[0] = 0x00; | ||||
} | ||||
return LFR_SUCCESSFUL; | ||||
} | ||||
paul
|
r35 | int send_waveform_SWF( volatile int *waveform, unsigned int sid, | ||
Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id ) | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | { | ||
paul
|
r40 | /** This function sends SWF CCSDS packets (F2, F1 or F0). | ||
* | ||||
* @param waveform points to the buffer containing the data that will be send. | ||||
* @param sid is the source identifier of the data that will be sent. | ||||
* @param headerSWF 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. | ||||
* | ||||
* One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. | ||||
* | ||||
*/ | ||||
paul
|
r33 | unsigned int i; | ||
int ret; | ||||
paul
|
r93 | unsigned int coarseTime; | ||
unsigned int fineTime; | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | rtems_status_code status; | ||
paul
|
r33 | spw_ioctl_pkt_send spw_ioctl_send_SWF; | ||
paul@pc-solar1.lab-lpp.local
|
r18 | |||
paul
|
r33 | spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header | ||
spw_ioctl_send_SWF.options = 0; | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | |||
paul
|
r33 | ret = LFR_DEFAULT; | ||
paul
|
r98 | coarseTime = waveform[0]; | ||
fineTime = waveform[1]; | ||||
paul
|
r93 | |||
paul@pc-solar1.lab-lpp.local
|
r23 | for (i=0; i<7; i++) // send waveform | ||
{ | ||||
paul
|
r93 | spw_ioctl_send_SWF.data = (char*) &waveform[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) + TIME_OFFSET]; | ||
paul
|
r34 | spw_ioctl_send_SWF.hdr = (char*) &headerSWF[ i ]; | ||
paul@pc-solar1.lab-lpp.local
|
r23 | // BUILD THE DATA | ||
if (i==6) { | ||||
paul
|
r93 | spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK; | ||
paul@pc-solar1.lab-lpp.local
|
r23 | } | ||
else { | ||||
paul
|
r93 | spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK; | ||
paul@pc-solar1.lab-lpp.local
|
r18 | } | ||
paul
|
r56 | // SET PACKET SEQUENCE COUNTER | ||
increment_seq_counter_source_id( headerSWF[ i ].packetSequenceControl, sid ); | ||||
paul
|
r33 | // SET PACKET TIME | ||
paul
|
r98 | compute_acquisition_time( coarseTime, fineTime, sid, i, headerSWF[ i ].acquisitionTime ); | ||
// | ||||
paul
|
r113 | headerSWF[ i ].time[0] = headerSWF[ i ].acquisitionTime[0]; | ||
headerSWF[ i ].time[1] = headerSWF[ i ].acquisitionTime[1]; | ||||
headerSWF[ i ].time[2] = headerSWF[ i ].acquisitionTime[2]; | ||||
headerSWF[ i ].time[3] = headerSWF[ i ].acquisitionTime[3]; | ||||
headerSWF[ i ].time[4] = headerSWF[ i ].acquisitionTime[4]; | ||||
headerSWF[ i ].time[5] = headerSWF[ i ].acquisitionTime[5]; | ||||
paul
|
r33 | // SEND PACKET | ||
paul
|
r37 | status = rtems_message_queue_send( queue_id, &spw_ioctl_send_SWF, ACTION_MSG_SPW_IOCTL_SEND_SIZE); | ||
paul
|
r33 | if (status != RTEMS_SUCCESSFUL) { | ||
paul
|
r34 | printf("%d-%d, ERR %d\n", sid, i, (int) status); | ||
paul
|
r33 | ret = LFR_DEFAULT; | ||
} | ||||
paul
|
r98 | rtems_task_wake_after(TIME_BETWEEN_TWO_SWF_PACKETS); // 300 ms between each packet => 7 * 3 = 21 packets => 6.3 seconds | ||
paul@pc-solar1.lab-lpp.local
|
r23 | } | ||
paul
|
r32 | |||
paul
|
r33 | return ret; | ||
paul@pc-solar1.lab-lpp.local
|
r23 | } | ||
paul
|
r35 | int send_waveform_CWF(volatile int *waveform, unsigned int sid, | ||
Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id) | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | { | ||
paul
|
r40 | /** This function sends CWF CCSDS packets (F2, F1 or F0). | ||
* | ||||
* @param waveform points to the buffer containing the data that will be send. | ||||
* @param sid is the source identifier of the data that will be sent. | ||||
* @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. | ||||
* | ||||
* One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. | ||||
* | ||||
*/ | ||||
paul
|
r33 | unsigned int i; | ||
int ret; | ||||
paul
|
r98 | unsigned int coarseTime; | ||
unsigned int fineTime; | ||||
paul
|
r33 | rtems_status_code status; | ||
spw_ioctl_pkt_send spw_ioctl_send_CWF; | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | |||
paul
|
r33 | spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header | ||
spw_ioctl_send_CWF.options = 0; | ||||
ret = LFR_DEFAULT; | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | |||
paul
|
r98 | coarseTime = waveform[0]; | ||
fineTime = waveform[1]; | ||||
for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform | ||||
paul
|
r33 | { | ||
paul
|
r93 | spw_ioctl_send_CWF.data = (char*) &waveform[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) + TIME_OFFSET]; | ||
paul
|
r33 | spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ]; | ||
// BUILD THE DATA | ||||
paul
|
r93 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK; | ||
paul
|
r56 | // SET PACKET SEQUENCE COUNTER | ||
increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, sid ); | ||||
paul
|
r33 | // SET PACKET TIME | ||
paul
|
r98 | compute_acquisition_time( coarseTime, fineTime, sid, i, headerCWF[ i ].acquisitionTime); | ||
// | ||||
paul
|
r113 | headerCWF[ i ].time[0] = headerCWF[ i ].acquisitionTime[0]; | ||
headerCWF[ i ].time[1] = headerCWF[ i ].acquisitionTime[1]; | ||||
headerCWF[ i ].time[2] = headerCWF[ i ].acquisitionTime[2]; | ||||
headerCWF[ i ].time[3] = headerCWF[ i ].acquisitionTime[3]; | ||||
headerCWF[ i ].time[4] = headerCWF[ i ].acquisitionTime[4]; | ||||
headerCWF[ i ].time[5] = headerCWF[ i ].acquisitionTime[5]; | ||||
paul
|
r33 | // SEND PACKET | ||
paul
|
r92 | if (sid == SID_NORM_CWF_LONG_F3) | ||
paul
|
r34 | { | ||
paul
|
r35 | status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF)); | ||
paul
|
r34 | if (status != RTEMS_SUCCESSFUL) { | ||
printf("%d-%d, ERR %d\n", sid, i, (int) status); | ||||
ret = LFR_DEFAULT; | ||||
} | ||||
rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS); | ||||
paul
|
r33 | } | ||
else | ||||
{ | ||||
paul
|
r36 | status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF)); | ||
paul
|
r34 | if (status != RTEMS_SUCCESSFUL) { | ||
printf("%d-%d, ERR %d\n", sid, i, (int) status); | ||||
ret = LFR_DEFAULT; | ||||
} | ||||
paul
|
r33 | } | ||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | |||
paul
|
r33 | return ret; | ||
paul@pc-solar1.lab-lpp.local
|
r23 | } | ||
paul
|
r38 | int send_waveform_CWF3_light(volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id) | ||
{ | ||||
paul
|
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. | ||||
* | ||||
*/ | ||||
paul
|
r38 | unsigned int i; | ||
int ret; | ||||
paul
|
r98 | unsigned int coarseTime; | ||
unsigned int fineTime; | ||||
paul
|
r38 | rtems_status_code status; | ||
spw_ioctl_pkt_send spw_ioctl_send_CWF; | ||||
char *sample; | ||||
spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header | ||||
spw_ioctl_send_CWF.options = 0; | ||||
ret = LFR_DEFAULT; | ||||
//********************** | ||||
// BUILD CWF3_light DATA | ||||
paul
|
r93 | for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++) | ||
paul
|
r38 | { | ||
paul
|
r92 | sample = (char*) &waveform[ (i * NB_WORDS_SWF_BLK) + TIME_OFFSET ]; | ||
paul
|
r93 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + TIME_OFFSET_IN_BYTES ] = sample[ 0 ]; | ||
wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 + TIME_OFFSET_IN_BYTES ] = sample[ 1 ]; | ||||
wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 + TIME_OFFSET_IN_BYTES ] = sample[ 2 ]; | ||||
wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 + TIME_OFFSET_IN_BYTES ] = sample[ 3 ]; | ||||
wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 + TIME_OFFSET_IN_BYTES ] = sample[ 4 ]; | ||||
paul
|
r98 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 + TIME_OFFSET_IN_BYTES ] = sample[ 5 ]; | ||
paul
|
r38 | } | ||
paul
|
r98 | coarseTime = waveform[0]; | ||
fineTime = waveform[1]; | ||||
paul
|
r38 | //********************* | ||
// SEND CWF3_light DATA | ||||
paul
|
r98 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform | ||
paul
|
r38 | { | ||
paul
|
r93 | spw_ioctl_send_CWF.data = (char*) &wf_cont_f3_light[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) + TIME_OFFSET_IN_BYTES]; | ||
paul
|
r38 | spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ]; | ||
// BUILD THE DATA | ||||
paul
|
r93 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK; | ||
paul
|
r56 | // SET PACKET SEQUENCE COUNTER | ||
increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, SID_NORM_CWF_F3 ); | ||||
paul
|
r38 | // SET PACKET TIME | ||
paul
|
r98 | compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, headerCWF[ i ].acquisitionTime ); | ||
// | ||||
paul
|
r113 | headerCWF[ i ].time[0] = headerCWF[ i ].acquisitionTime[0]; | ||
headerCWF[ i ].time[1] = headerCWF[ i ].acquisitionTime[1]; | ||||
headerCWF[ i ].time[2] = headerCWF[ i ].acquisitionTime[2]; | ||||
headerCWF[ i ].time[3] = headerCWF[ i ].acquisitionTime[3]; | ||||
headerCWF[ i ].time[4] = headerCWF[ i ].acquisitionTime[4]; | ||||
headerCWF[ i ].time[5] = headerCWF[ i ].acquisitionTime[5]; | ||||
paul
|
r38 | // SEND PACKET | ||
status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF)); | ||||
if (status != RTEMS_SUCCESSFUL) { | ||||
printf("%d-%d, ERR %d\n", SID_NORM_CWF_F3, i, (int) status); | ||||
ret = LFR_DEFAULT; | ||||
} | ||||
rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS); | ||||
} | ||||
return ret; | ||||
} | ||||
paul
|
r98 | void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime, | ||
unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime ) | ||||
paul
|
r93 | { | ||
unsigned long long int acquisitionTimeAsLong; | ||||
paul
|
r98 | unsigned char localAcquisitionTime[6]; | ||
paul
|
r105 | double deltaT; | ||
deltaT = 0.; | ||||
paul
|
r93 | |||
paul
|
r98 | localAcquisitionTime[0] = (unsigned char) ( coarseTime >> 8 ); | ||
localAcquisitionTime[1] = (unsigned char) ( coarseTime ); | ||||
localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 24 ); | ||||
localAcquisitionTime[3] = (unsigned char) ( coarseTime >> 16 ); | ||||
localAcquisitionTime[4] = (unsigned char) ( fineTime >> 24 ); | ||||
localAcquisitionTime[5] = (unsigned char) ( fineTime >> 16 ); | ||||
paul
|
r93 | |||
paul
|
r98 | acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 ) | ||
+ ( (unsigned long long int) localAcquisitionTime[1] << 32 ) | ||||
+ ( localAcquisitionTime[2] << 24 ) | ||||
+ ( localAcquisitionTime[3] << 16 ) | ||||
+ ( localAcquisitionTime[4] << 8 ) | ||||
+ ( localAcquisitionTime[5] ); | ||||
paul
|
r93 | |||
switch( sid ) | ||||
{ | ||||
case SID_NORM_SWF_F0: | ||||
paul
|
r98 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ; | ||
break; | ||||
paul
|
r93 | |||
case SID_NORM_SWF_F1: | ||||
paul
|
r98 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ; | ||
break; | ||||
paul
|
r102 | case SID_NORM_SWF_F2: | ||
deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ; | ||||
break; | ||||
paul
|
r98 | case SID_SBM1_CWF_F1: | ||
deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ; | ||||
break; | ||||
paul
|
r93 | |||
paul
|
r102 | case SID_SBM2_CWF_F2: | ||
deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ; | ||||
paul
|
r98 | break; | ||
paul
|
r102 | case SID_BURST_CWF_F2: | ||
paul
|
r98 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ; | ||
break; | ||||
case SID_NORM_CWF_F3: | ||||
deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ; | ||||
break; | ||||
case SID_NORM_CWF_LONG_F3: | ||||
deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ; | ||||
break; | ||||
paul
|
r93 | |||
default: | ||||
paul
|
r102 | PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d", sid) | ||
paul
|
r93 | deltaT = 0.; | ||
break; | ||||
} | ||||
acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT; | ||||
paul
|
r98 | // | ||
acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40); | ||||
acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32); | ||||
acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24); | ||||
acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16); | ||||
acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 ); | ||||
acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong ); | ||||
paul
|
r105 | |||
} | ||||
paul
|
r106 | void build_snapshot_from_ring( ring_node *ring_node_to_send, unsigned char frequencyChannel ) | ||
paul
|
r105 | { | ||
unsigned int i; | ||||
unsigned long long int centerTime_asLong; | ||||
unsigned long long int acquisitionTimeF0_asLong; | ||||
paul
|
r106 | unsigned long long int acquisitionTime_asLong; | ||
unsigned long long int bufferAcquisitionTime_asLong; | ||||
paul
|
r105 | unsigned char *ptr1; | ||
unsigned char *ptr2; | ||||
paul
|
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; | ||||
paul
|
r105 | |||
paul
|
r106 | unsigned int deltaT_F0; | ||
unsigned int deltaT_F1; | ||||
unsigned long long int deltaT_F2; | ||||
paul
|
r105 | |||
paul
|
r106 | deltaT_F0 = 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667; | ||
deltaT_F1 = 16384; // (2048. / 4096. / 2.) * 65536. = 16384; | ||||
deltaT_F2 = 262144; // (2048. / 256. / 2.) * 65536. = 262144; | ||||
sampleOffset_asLong = 0x00; | ||||
paul
|
r105 | |||
paul
|
r110 | // (1) get the f0 acquisition time | ||
paul
|
r106 | build_acquisition_time( &acquisitionTimeF0_asLong, current_ring_node_f0 ); | ||
paul
|
r110 | // (2) compute the central reference time | ||
paul
|
r106 | centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0; | ||
paul
|
r105 | |||
paul
|
r110 | // (3) compute the acquisition time of the current snapshot | ||
paul
|
r106 | switch(frequencyChannel) | ||
{ | ||||
case 1: // 1 is for F1 = 4096 Hz | ||||
acquisitionTime_asLong = centerTime_asLong - deltaT_F1; | ||||
nb_ring_nodes = NB_RING_NODES_F1; | ||||
frequency_asLong = 4096; | ||||
nbTicksPerSample_asLong = 16; // 65536 / 4096; | ||||
break; | ||||
case 2: // 2 is for F2 = 256 Hz | ||||
acquisitionTime_asLong = centerTime_asLong - deltaT_F2; | ||||
nb_ring_nodes = NB_RING_NODES_F2; | ||||
frequency_asLong = 256; | ||||
nbTicksPerSample_asLong = 256; // 65536 / 256; | ||||
break; | ||||
default: | ||||
acquisitionTime_asLong = centerTime_asLong; | ||||
frequency_asLong = 256; | ||||
nbTicksPerSample_asLong = 256; | ||||
break; | ||||
} | ||||
paul
|
r105 | |||
paul
|
r106 | //**************************************************************************** | ||
paul
|
r110 | // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong | ||
paul
|
r106 | for (i=0; i<nb_ring_nodes; i++) | ||
{ | ||||
PRINTF1("%d ... ", i) | ||||
build_acquisition_time( &bufferAcquisitionTime_asLong, ring_node_to_send ); | ||||
if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong) | ||||
{ | ||||
PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong) | ||||
break; | ||||
} | ||||
ring_node_to_send = ring_node_to_send->previous; | ||||
} | ||||
paul
|
r105 | |||
paul
|
r110 | // (5) compute the number of samples to take in the current buffer | ||
paul
|
r106 | sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16; | ||
nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong; | ||||
paul
|
r110 | PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong) | ||
paul
|
r105 | |||
paul
|
r110 | // (6) compute the final acquisition time | ||
paul
|
r106 | acquisitionTime_asLong = bufferAcquisitionTime_asLong + | ||
sampleOffset_asLong * nbTicksPerSample_asLong; | ||||
paul
|
r105 | |||
paul
|
r110 | // (7) copy the acquisition time at the beginning of the extrated snapshot | ||
paul
|
r106 | ptr1 = (unsigned char*) &acquisitionTime_asLong; | ||
ptr2 = (unsigned char*) wf_snap_extracted; | ||||
paul
|
r105 | ptr2[0] = ptr1[ 2 + 2 ]; | ||
ptr2[1] = ptr1[ 3 + 2 ]; | ||||
ptr2[2] = ptr1[ 0 + 2 ]; | ||||
ptr2[3] = ptr1[ 1 + 2 ]; | ||||
ptr2[4] = ptr1[ 4 + 2 ]; | ||||
ptr2[5] = ptr1[ 5 + 2 ]; | ||||
paul
|
r106 | // re set the synchronization bit | ||
// copy the part 1 of the snapshot in the extracted buffer | ||||
for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ ) | ||||
{ | ||||
wf_snap_extracted[i + TIME_OFFSET] = | ||||
((int*) ring_node_to_send->buffer_address)[i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) + TIME_OFFSET]; | ||||
} | ||||
// 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++ ) | ||||
paul
|
r105 | { | ||
paul
|
r106 | wf_snap_extracted[i + TIME_OFFSET] = | ||
((int*) ring_node_to_send->buffer_address)[(i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) + TIME_OFFSET]; | ||||
paul
|
r105 | } | ||
paul
|
r93 | } | ||
paul
|
r38 | |||
paul
|
r106 | void build_acquisition_time( unsigned long long int *acquisitionTimeAslong, ring_node *current_ring_node ) | ||
{ | ||||
unsigned char *acquisitionTimeCharPtr; | ||||
acquisitionTimeCharPtr = (unsigned char*) current_ring_node->buffer_address; | ||||
*acquisitionTimeAslong = 0x00; | ||||
*acquisitionTimeAslong = ( acquisitionTimeCharPtr[0] << 24 ) | ||||
+ ( acquisitionTimeCharPtr[1] << 16 ) | ||||
+ ( (unsigned long long int) (acquisitionTimeCharPtr[2] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit | ||||
+ ( (unsigned long long int) acquisitionTimeCharPtr[3] << 32 ) | ||||
+ ( acquisitionTimeCharPtr[4] << 8 ) | ||||
+ ( acquisitionTimeCharPtr[5] ); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | //************** | ||
// wfp registers | ||||
paul
|
r97 | void reset_wfp_burst_enable(void) | ||
{ | ||||
/** 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. | ||||
* | ||||
*/ | ||||
waveform_picker_regs->run_burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0 | ||||
} | ||||
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]. | ||||
* | ||||
*/ | ||||
waveform_picker_regs->status = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0 | ||||
} | ||||
void reset_waveform_picker_regs(void) | ||||
{ | ||||
/** 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 | ||||
* - 0x28 delta_f1 | ||||
* - 0x2c delta_f2 | ||||
* - 0x30 nb_data_by_buffer | ||||
* - 0x34 nb_snapshot_param | ||||
* - 0x38 start_date | ||||
* - 0x3c nb_word_in_buffer | ||||
* | ||||
*/ | ||||
paul
|
r110 | set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW | ||
reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] | ||||
paul
|
r97 | waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address; // 0x08 | ||
waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; // 0x0c | ||||
waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; // 0x10 | ||||
paul
|
r131 | waveform_picker_regs->addr_data_f3 = current_ring_node_f3->buffer_address; // 0x14 | ||
paul
|
r110 | reset_wfp_status(); // 0x18 | ||
paul
|
r97 | // | ||
set_wfp_delta_snapshot(); // 0x1c | ||||
set_wfp_delta_f0_f0_2(); // 0x20, 0x24 | ||||
set_wfp_delta_f1(); // 0x28 | ||||
set_wfp_delta_f2(); // 0x2c | ||||
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) | ||||
paul
|
r98 | // 2688 = 8 * 336 | ||
waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1 | ||||
waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples | ||||
paul
|
r97 | waveform_picker_regs->start_date = 0x00; // 0x38 | ||
paul
|
r98 | waveform_picker_regs->nb_word_in_buffer = 0x1f82; // 0x3c *** 2688 * 3 + 2 = 8066 | ||
paul
|
r97 | } | ||
void set_wfp_data_shaping( void ) | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | { | ||
paul
|
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 | ||||
* | ||||
*/ | ||||
paul
|
r32 | unsigned char data_shaping; | ||
paul@pc-solar1.lab-lpp.local
|
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] | ||||
paul
|
r32 | |||
data_shaping = parameter_dump_packet.bw_sp0_sp1_r0_r1; | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | waveform_picker_regs->data_shaping = | ||
( (data_shaping & 0x10) >> 4 ) // BW | ||||
+ ( (data_shaping & 0x08) >> 2 ) // SP0 | ||||
+ ( (data_shaping & 0x04) ) // SP1 | ||||
+ ( (data_shaping & 0x02) << 2 ) // R0 | ||||
+ ( (data_shaping & 0x01) << 4 ); // R1 | ||||
} | ||||
paul
|
r90 | void set_wfp_burst_enable_register( unsigned char mode ) | ||
paul@pc-solar1.lab-lpp.local
|
r23 | { | ||
paul
|
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. | ||||
* | ||||
*/ | ||||
paul
|
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) { | ||||
case(LFR_MODE_NORMAL): | ||||
waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enable | ||||
waveform_picker_regs->run_burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0 | ||||
break; | ||||
case(LFR_MODE_BURST): | ||||
waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled | ||||
paul
|
r129 | // waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x04; // [0100] enable f2 | ||
paul
|
r130 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 AND f2 | ||
paul
|
r90 | break; | ||
case(LFR_MODE_SBM1): | ||||
waveform_picker_regs->run_burst_enable = 0x20; // [0010 0000] f1 burst enabled | ||||
waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0 | ||||
break; | ||||
case(LFR_MODE_SBM2): | ||||
waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled | ||||
waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0 | ||||
break; | ||||
default: | ||||
waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled | ||||
break; | ||||
} | ||||
} | ||||
paul
|
r97 | |||
void set_wfp_delta_snapshot( void ) | ||||
paul
|
r90 | { | ||
paul
|
r97 | /** This function sets the delta_snapshot register of the waveform picker module. | ||
paul
|
r90 | * | ||
paul
|
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] | ||||
paul
|
r40 | * | ||
*/ | ||||
paul
|
r97 | unsigned int delta_snapshot; | ||
unsigned int delta_snapshot_in_T2; | ||||
paul
|
r33 | |||
paul
|
r97 | delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256 | ||
+ parameter_dump_packet.sy_lfr_n_swf_p[1]; | ||||
delta_snapshot_in_T2 = delta_snapshot * 256; | ||||
waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2; // max 4 bytes | ||||
paul
|
r95 | } | ||
paul
|
r97 | void set_wfp_delta_f0_f0_2( void ) | ||
paul
|
r95 | { | ||
paul
|
r97 | unsigned int delta_snapshot; | ||
unsigned int nb_samples_per_snapshot; | ||||
float delta_f0_in_float; | ||||
delta_snapshot = waveform_picker_regs->delta_snapshot; | ||||
nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; | ||||
delta_f0_in_float =nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.; | ||||
waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float ); | ||||
waveform_picker_regs->delta_f0_2 = 0x7; // max 7 bits | ||||
paul
|
r90 | } | ||
paul
|
r95 | |||
paul
|
r97 | void set_wfp_delta_f1( void ) | ||
paul
|
r95 | { | ||
paul
|
r97 | unsigned int delta_snapshot; | ||
unsigned int nb_samples_per_snapshot; | ||||
float delta_f1_in_float; | ||||
delta_snapshot = waveform_picker_regs->delta_snapshot; | ||||
nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; | ||||
delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.; | ||||
waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float ); | ||||
paul
|
r95 | } | ||
paul
|
r97 | void set_wfp_delta_f2() | ||
paul@pc-solar1.lab-lpp.local
|
r23 | { | ||
paul
|
r97 | unsigned int delta_snapshot; | ||
unsigned int nb_samples_per_snapshot; | ||||
paul
|
r40 | |||
paul
|
r97 | delta_snapshot = waveform_picker_regs->delta_snapshot; | ||
nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; | ||||
waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2; | ||||
paul
|
r90 | } | ||
paul
|
r32 | |||
//***************** | ||||
// local parameters | ||||
paul
|
r133 | |||
void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid ) | ||||
paul
|
r32 | { | ||
paul
|
r133 | /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument. | ||
paul
|
r40 | * | ||
paul
|
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 | ||||
paul
|
r40 | * | ||
*/ | ||||
paul
|
r56 | unsigned short *sequence_cnt; | ||
unsigned short segmentation_grouping_flag; | ||||
unsigned short new_packet_sequence_control; | ||||
paul
|
r133 | rtems_mode initial_mode_set; | ||
rtems_mode current_mode_set; | ||||
rtems_status_code status; | ||||
paul
|
r56 | |||
paul
|
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) ) | ||||
paul
|
r56 | { | ||
paul
|
r128 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST; | ||
paul
|
r56 | } | ||
paul
|
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) ) | ||||
paul
|
r56 | { | ||
paul
|
r128 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2; | ||
paul
|
r56 | } | ||
else | ||||
{ | ||||
paul
|
r128 | sequence_cnt = (unsigned short *) NULL; | ||
paul
|
r56 | PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid) | ||
} | ||||
paul
|
r84 | if (sequence_cnt != NULL) | ||
{ | ||||
paul
|
r128 | // increment the sequence counter | ||
paul
|
r84 | if ( *sequence_cnt < SEQ_CNT_MAX) | ||
{ | ||||
*sequence_cnt = *sequence_cnt + 1; | ||||
} | ||||
else | ||||
{ | ||||
*sequence_cnt = 0; | ||||
} | ||||
paul
|
r128 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; | ||
*sequence_cnt = (*sequence_cnt) & 0x3fff; | ||||
new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ; | ||||
packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8); | ||||
packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); | ||||
paul
|
r56 | } | ||
paul
|
r133 | |||
//*********************************** | ||||
// RESET THE MODE OF THE CALLING TASK | ||||
status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, ¤t_mode_set ); | ||||
paul
|
r56 | } | ||