wf_handler.c
1152 lines
| 45.1 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 | |||
|
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 | ||||
|
r33 | Header_TM_LFR_SCIENCE_CWF_t headerCWF_F1[7]; | ||
Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_BURST[7]; | ||||
|
r34 | Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_SBM2[7]; | ||
|
r33 | Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3[7]; | ||
|
r38 | Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3_light[7]; | ||
|
r33 | |||
unsigned char doubleSendCWF1 = 0; | ||||
unsigned char doubleSendCWF2 = 0; | ||||
|
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 | |||
|
r32 | #ifdef GSA | ||
#else | ||||
|
r33 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) | ||
|| (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) | ||||
|
r32 | { // in modes other than STANDBY and BURST, send the CWF_F3 data | ||
|
r52 | if ((new_waveform_picker_regs->status & 0x08) == 0x08){ // [1000] f3 is full | ||
|
r32 | // (1) change the receiving buffer for the waveform picker | ||
|
r52 | if (new_waveform_picker_regs->addr_data_f3 == (int) wf_cont_f3) { | ||
new_waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3_bis); | ||||
|
r32 | } | ||
else { | ||||
|
r52 | new_waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3); | ||
|
r32 | } | ||
// (2) send an event for the waveforms transmission | ||||
|
r33 | if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | ||
|
r32 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||
} | ||||
|
r52 | new_waveform_picker_regs->status = new_waveform_picker_regs->status & 0xfffff777; // reset f3 bits to 0, [1111 0111 0111 0111] | ||
|
r32 | } | ||
} | ||||
#endif | ||||
|
r33 | switch(lfrCurrentMode) | ||
|
r21 | { | ||
//******** | ||||
// STANDBY | ||||
case(LFR_MODE_STANDBY): | ||||
|
r33 | break; | ||
|
r21 | |||
//****** | ||||
// NORMAL | ||||
case(LFR_MODE_NORMAL): | ||||
#ifdef GSA | ||||
|
r33 | PRINTF("in waveform_isr *** unexpected waveform picker interruption\n") | ||
|
r21 | #else | ||
|
r52 | if ( (new_waveform_picker_regs->run_burst_enable & 0x7) == 0x0 ){ // if no channel is enable | ||
|
r35 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||
} | ||||
else { | ||||
|
r52 | if ( (new_waveform_picker_regs->status & 0x7) == 0x7 ){ // f2 f1 and f0 are full | ||
new_waveform_picker_regs->run_burst_enable = new_waveform_picker_regs->run_burst_enable & 0x08; | ||||
|
r35 | if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) { | ||
rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||||
} | ||||
|
r52 | // new_waveform_picker_regs->status = new_waveform_picker_regs->status & 0x00; | ||
new_waveform_picker_regs->status = new_waveform_picker_regs->status & 0xfffff888; | ||||
new_waveform_picker_regs->run_burst_enable = new_waveform_picker_regs->run_burst_enable | 0x07; // [0111] enable f2 f1 f0 | ||||
|
r21 | } | ||
|
r35 | } | ||
|
r21 | #endif | ||
|
r33 | break; | ||
|
r21 | |||
//****** | ||||
// BURST | ||||
case(LFR_MODE_BURST): | ||||
|
r22 | #ifdef GSA | ||
|
r33 | PRINTF("in waveform_isr *** unexpected waveform picker interruption\n") | ||
|
r22 | #else | ||
|
r52 | if ((new_waveform_picker_regs->status & 0x04) == 0x04){ // [0100] check the f2 full bit | ||
|
r33 | // (1) change the receiving buffer for the waveform picker | ||
|
r52 | if (new_waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2) { | ||
new_waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2_bis); | ||||
|
r33 | } | ||
else { | ||||
|
r52 | new_waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2); | ||
|
r22 | } | ||
|
r33 | // (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 ); | ||||
} | ||||
|
r52 | new_waveform_picker_regs->status = new_waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bits = 0 | ||
|
r33 | } | ||
|
r22 | #endif | ||
|
r33 | break; | ||
|
r21 | |||
|
r23 | //***** | ||
// SBM1 | ||||
case(LFR_MODE_SBM1): | ||||
#ifdef GSA | ||||
|
r33 | PRINTF("in waveform_isr *** unexpected waveform picker interruption\n") | ||
|
r23 | #else | ||
|
r52 | if ((new_waveform_picker_regs->status & 0x02) == 0x02){ // [0010] check the f1 full bit | ||
|
r33 | // (1) change the receiving buffer for the waveform picker | ||
if ( param_local.local_sbm1_nb_cwf_sent == (param_local.local_sbm1_nb_cwf_max-1) ) | ||||
{ | ||||
|
r52 | new_waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1_norm); | ||
|
r33 | } | ||
|
r52 | else if ( new_waveform_picker_regs->addr_data_f1 == (int) wf_snap_f1_norm ) | ||
|
r33 | { | ||
doubleSendCWF1 = 1; | ||||
|
r52 | new_waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1); | ||
|
r33 | } | ||
|
r52 | else if ( new_waveform_picker_regs->addr_data_f1 == (int) wf_snap_f1 ) { | ||
new_waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1_bis); | ||||
|
r23 | } | ||
|
r33 | else { | ||
|
r52 | new_waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1); | ||
|
r33 | } | ||
// (2) send an event for the waveforms transmission | ||||
if (rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 ) != RTEMS_SUCCESSFUL) { | ||||
rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||||
|
r23 | } | ||
|
r52 | new_waveform_picker_regs->status = new_waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1 bit = 0 | ||
|
r33 | } | ||
|
r52 | if ( ( (new_waveform_picker_regs->status & 0x05) == 0x05 ) ) { // [0101] check the f2 and f0 full bit | ||
|
r33 | if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) { | ||
rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||||
} | ||||
|
r52 | new_waveform_picker_regs->status = new_waveform_picker_regs->status & 0xfffffaaa; // [1111 1010 1010 1010] f2 and f0 bits = 0 | ||
|
r33 | reset_local_sbm1_nb_cwf_sent(); | ||
} | ||||
|
r32 | |||
|
r23 | #endif | ||
|
r33 | break; | ||
|
r23 | |||
//***** | ||||
// SBM2 | ||||
case(LFR_MODE_SBM2): | ||||
#ifdef GSA | ||||
|
r33 | PRINTF("in waveform_isr *** unexpected waveform picker interruption\n") | ||
|
r23 | #else | ||
|
r52 | if ((new_waveform_picker_regs->status & 0x04) == 0x04){ // [0100] check the f2 full bit | ||
|
r33 | // (1) change the receiving buffer for the waveform picker | ||
|
r34 | if ( param_local.local_sbm2_nb_cwf_sent == (param_local.local_sbm2_nb_cwf_max-1) ) | ||
{ | ||||
|
r52 | new_waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2_norm); | ||
|
r34 | } | ||
|
r52 | else if ( new_waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2_norm ) { | ||
new_waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2); | ||||
|
r34 | doubleSendCWF2 = 1; | ||
if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2_WFRM ) != RTEMS_SUCCESSFUL) { | ||||
rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||||
} | ||||
reset_local_sbm2_nb_cwf_sent(); | ||||
} | ||||
|
r52 | else if ( new_waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2 ) { | ||
new_waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2_bis); | ||||
|
r33 | } | ||
else { | ||||
|
r52 | new_waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2); | ||
|
r33 | } | ||
// (2) send an event for the waveforms transmission | ||||
if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 ) != RTEMS_SUCCESSFUL) { | ||||
rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||||
|
r23 | } | ||
|
r52 | new_waveform_picker_regs->status = new_waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0 | ||
|
r33 | } | ||
|
r52 | if ( ( (new_waveform_picker_regs->status & 0x03) == 0x03 ) ) { // [0011] f3 f2 f1 f0, f1 and f0 are full | ||
|
r33 | if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ) != RTEMS_SUCCESSFUL) { | ||
rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); | ||||
|
r23 | } | ||
|
r52 | new_waveform_picker_regs->status = new_waveform_picker_regs->status & 0xfffffccc; // [1111 1100 1100 1100] f1, f0 bits = 0 | ||
|
r33 | } | ||
|
r23 | #endif | ||
|
r33 | break; | ||
|
r23 | |||
|
r21 | //******** | ||
// DEFAULT | ||||
default: | ||||
|
r33 | break; | ||
|
r21 | } | ||
} | ||||
|
r18 | rtems_isr waveforms_simulator_isr( rtems_vector_number vector ) | ||
|
r5 | { | ||
|
r45 | /** This is the interrupt sub routine called by the waveform picker simulator. | ||
* | ||||
* This ISR is for debug purpose only. | ||||
* | ||||
*/ | ||||
|
r22 | unsigned char lfrMode; | ||
lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; | ||||
|
r31 | switch(lfrMode) { | ||
case (LFR_MODE_STANDBY): | ||||
break; | ||||
case (LFR_MODE_NORMAL): | ||||
if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) { | ||||
|
r30 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_5 ); | ||
|
r31 | } | ||
break; | ||||
case (LFR_MODE_BURST): | ||||
break; | ||||
case (LFR_MODE_SBM1): | ||||
break; | ||||
case (LFR_MODE_SBM2): | ||||
break; | ||||
|
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; | ||
|
r5 | |||
|
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 ); | ||||
|
r11 | |||
|
r18 | init_waveforms(); | ||
|
r46 | queue_id = get_pkts_queue_id(); | ||
|
r35 | |||
BOOT_PRINTF("in WFRM ***\n") | ||||
|
r18 | |||
while(1){ | ||||
|
r21 | // wait for an RTEMS_EVENT | ||
|
r34 | rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1 | ||
| RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM, | ||||
|
r21 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||
|
r32 | |||
|
r35 | if (event_out == RTEMS_EVENT_MODE_NORMAL) | ||
{ | ||||
send_waveform_SWF(wf_snap_f0, SID_NORM_SWF_F0, headerSWF_F0, queue_id); | ||||
send_waveform_SWF(wf_snap_f1, SID_NORM_SWF_F1, headerSWF_F1, queue_id); | ||||
send_waveform_SWF(wf_snap_f2, SID_NORM_SWF_F2, headerSWF_F2, queue_id); | ||||
|
r33 | #ifdef GSA | ||
|
r52 | new_waveform_picker_regs->status = new_waveform_picker_regs->status & 0xf888; // [1111 1000 1000 1000] f2, f1, f0 bits =0 | ||
|
r31 | #endif | ||
|
r35 | } | ||
else if (event_out == RTEMS_EVENT_MODE_SBM1) | ||||
{ | ||||
send_waveform_SWF(wf_snap_f0, SID_NORM_SWF_F0, headerSWF_F0, queue_id); | ||||
send_waveform_SWF(wf_snap_f1_norm, SID_NORM_SWF_F1, headerSWF_F1, queue_id); | ||||
send_waveform_SWF(wf_snap_f2, SID_NORM_SWF_F2, headerSWF_F2, queue_id); | ||||
|
r31 | #ifdef GSA | ||
|
r52 | new_waveform_picker_regs->status = new_waveform_picker_regs->status & 0xfffffaaa; // [1111 1010 1010 1010] f2, f0 bits = 0 | ||
|
r31 | #endif | ||
|
r35 | } | ||
else if (event_out == RTEMS_EVENT_MODE_SBM2) | ||||
{ | ||||
send_waveform_SWF(wf_snap_f0, SID_NORM_SWF_F0, headerSWF_F0, queue_id); | ||||
send_waveform_SWF(wf_snap_f1, SID_NORM_SWF_F1, headerSWF_F1, queue_id); | ||||
|
r34 | #ifdef GSA | ||
|
r52 | new_waveform_picker_regs->status = new_waveform_picker_regs->status & 0xfffffccc; // [1111 1100 1100 1100] f1, f0 bits = 0 | ||
|
r34 | #endif | ||
|
r35 | } | ||
else if (event_out == RTEMS_EVENT_MODE_SBM2_WFRM) | ||||
{ | ||||
send_waveform_SWF(wf_snap_f2_norm, SID_NORM_SWF_F2, headerSWF_F2, queue_id); | ||||
} | ||||
else | ||||
{ | ||||
PRINTF("in WFRM *** unexpected event") | ||||
} | ||||
|
r34 | |||
|
r32 | |||
|
r33 | #ifdef GSA | ||
// irq processed, reset the related register of the timer unit | ||||
gptimer_regs->timer[TIMER_WF_SIMULATOR].ctrl = gptimer_regs->timer[TIMER_WF_SIMULATOR].ctrl | 0x00000010; | ||||
// clear the interruption | ||||
LEON_Unmask_interrupt( IRQ_WF ); | ||||
#endif | ||||
|
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; | ||
|
r32 | |||
|
r33 | init_header_continuous_wf_table( SID_NORM_CWF_F3, headerCWF_F3 ); | ||
|
r38 | init_header_continuous_wf3_light_table( headerCWF_F3_light ); | ||
|
r32 | |||
|
r35 | queue_id = get_pkts_queue_id(); | ||
BOOT_PRINTF("in CWF3 ***\n") | ||||
|
r32 | |||
while(1){ | ||||
// wait for an RTEMS_EVENT | ||||
|
r33 | rtems_event_receive( RTEMS_EVENT_0, | ||
|
r32 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | ||
PRINTF("send CWF F3 \n") | ||||
|
r33 | #ifdef GSA | ||
#else | ||||
|
r52 | if (new_waveform_picker_regs->addr_data_f3 == (int) wf_cont_f3) { | ||
|
r38 | send_waveform_CWF3_light( wf_cont_f3_bis, headerCWF_F3_light, queue_id ); | ||
|
r33 | } | ||
else { | ||||
|
r38 | send_waveform_CWF3_light( wf_cont_f3, headerCWF_F3_light, queue_id ); | ||
|
r33 | } | ||
#endif | ||||
} | ||||
} | ||||
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; | ||
|
r33 | |||
init_header_continuous_wf_table( SID_BURST_CWF_F2, headerCWF_F2_BURST ); | ||||
|
r34 | init_header_continuous_wf_table( SID_SBM2_CWF_F2, headerCWF_F2_SBM2 ); | ||
|
r33 | |||
|
r35 | queue_id = get_pkts_queue_id(); | ||
BOOT_PRINTF("in CWF2 ***\n") | ||||
|
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); | ||||
|
r37 | |||
|
r33 | if (event_out == RTEMS_EVENT_MODE_BURST) | ||
{ | ||||
// F2 | ||||
#ifdef GSA | ||||
#else | ||||
|
r52 | if (new_waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2) { | ||
|
r37 | send_waveform_CWF( wf_snap_f2_bis, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id ); | ||
|
r33 | } | ||
else { | ||||
|
r35 | send_waveform_CWF( wf_snap_f2, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id ); | ||
|
r33 | } | ||
#endif | ||||
} | ||||
|
r37 | |||
|
r33 | else if (event_out == RTEMS_EVENT_MODE_SBM2) | ||
{ | ||||
#ifdef GSA | ||||
#else | ||||
|
r34 | if (doubleSendCWF2 == 1) | ||
{ | ||||
doubleSendCWF2 = 0; | ||||
|
r35 | send_waveform_CWF( wf_snap_f2_norm, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id ); | ||
|
r34 | } | ||
|
r52 | else if (new_waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2) { | ||
|
r35 | send_waveform_CWF( wf_snap_f2_bis, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id ); | ||
|
r33 | } | ||
else { | ||||
|
r35 | send_waveform_CWF( wf_snap_f2, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id ); | ||
|
r33 | } | ||
|
r34 | param_local.local_sbm2_nb_cwf_sent ++; | ||
|
r33 | #endif | ||
} | ||||
else | ||||
{ | ||||
PRINTF1("in CWF2 *** ERR mode = %d\n", lfrCurrentMode) | ||||
} | ||||
} | ||||
} | ||||
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; | ||
|
r33 | |||
init_header_continuous_wf_table( SID_SBM1_CWF_F1, headerCWF_F1 ); | ||||
|
r35 | queue_id = get_pkts_queue_id(); | ||
BOOT_PRINTF("in CWF1 ***\n") | ||||
|
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); | ||||
if (event_out == RTEMS_EVENT_MODE_SBM1) | ||||
{ | ||||
#ifdef GSA | ||||
#else | ||||
if (doubleSendCWF1 == 1) | ||||
{ | ||||
doubleSendCWF1 = 0; | ||||
|
r35 | send_waveform_CWF( wf_snap_f1_norm, SID_SBM1_CWF_F1, headerCWF_F1, queue_id ); | ||
|
r33 | } | ||
|
r52 | else if (new_waveform_picker_regs->addr_data_f1 == (int) wf_snap_f1) { | ||
|
r35 | send_waveform_CWF( wf_snap_f1_bis, SID_SBM1_CWF_F1, headerCWF_F1, queue_id ); | ||
|
r33 | } | ||
else { | ||||
|
r35 | send_waveform_CWF( wf_snap_f1, SID_SBM1_CWF_F1, headerCWF_F1, queue_id ); | ||
|
r33 | } | ||
param_local.local_sbm1_nb_cwf_sent ++; | ||||
#endif | ||||
} | ||||
else | ||||
{ | ||||
PRINTF1("in CWF1 *** ERR mode = %d\n", lfrCurrentMode) | ||||
} | ||||
|
r32 | } | ||
} | ||||
|
r17 | //****************** | ||
// general functions | ||||
|
r18 | void init_waveforms( void ) | ||
{ | ||||
int i = 0; | ||||
for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++) | ||||
{ | ||||
//*** | ||||
// F0 | ||||
wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x88887777; // | ||||
wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x22221111; // | ||||
wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0x44443333; // | ||||
//*** | ||||
// F1 | ||||
|
r19 | wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x22221111; | ||
wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x44443333; | ||||
|
r18 | wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0xaaaa0000; | ||
//*** | ||||
// F2 | ||||
|
r19 | wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x44443333; | ||
wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x22221111; | ||||
|
r18 | wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0xaaaa0000; | ||
//*** | ||||
// F3 | ||||
//wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 0 ] = val1; | ||||
//wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 1 ] = val2; | ||||
//wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 2 ] = 0xaaaa0000; | ||||
} | ||||
} | ||||
|
r34 | int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF) | ||
|
r18 | { | ||
|
r33 | unsigned char i; | ||
for (i=0; i<7; i++) | ||||
{ | ||||
|
r34 | headerSWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID; | ||
headerSWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID; | ||||
headerSWF[ i ].reserved = DEFAULT_RESERVED; | ||||
headerSWF[ i ].userApplication = CCSDS_USER_APP; | ||||
headerSWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8); | ||||
headerSWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST); | ||||
|
r33 | if (i == 0) | ||
{ | ||||
|
r34 | headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_FIRST; | ||
headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_340 >> 8); | ||||
headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_340 ); | ||||
headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8); | ||||
headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 ); | ||||
|
r33 | } | ||
else if (i == 6) | ||||
{ | ||||
|
r34 | headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_LAST; | ||
headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_8 >> 8); | ||||
headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_8 ); | ||||
headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_8 >> 8); | ||||
headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_8 ); | ||||
|
r33 | } | ||
else | ||||
{ | ||||
|
r34 | headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_CONTINUATION; | ||
headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_340 >> 8); | ||||
headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_340 ); | ||||
headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8); | ||||
headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 ); | ||||
|
r33 | } | ||
|
r34 | headerSWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | ||
headerSWF[ i ].pktCnt = DEFAULT_PKTCNT; // PKT_CNT | ||||
headerSWF[ i ].pktNr = i+1; // PKT_NR | ||||
|
r33 | // DATA FIELD HEADER | ||
|
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; | ||||
|
r33 | // AUXILIARY DATA HEADER | ||
|
r34 | headerSWF[ i ].sid = sid; | ||
headerSWF[ i ].hkBIA = DEFAULT_HKBIA; | ||||
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; | ||||
|
r33 | } | ||
return LFR_SUCCESSFUL; | ||||
|
r23 | } | ||
|
r18 | |||
|
r33 | int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF ) | ||
|
r23 | { | ||
|
r33 | unsigned int i; | ||
for (i=0; i<7; i++) | ||||
{ | ||||
headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID; | ||||
headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID; | ||||
headerCWF[ i ].reserved = DEFAULT_RESERVED; | ||||
headerCWF[ i ].userApplication = CCSDS_USER_APP; | ||||
|
r37 | if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) ) | ||
|
r34 | { | ||
headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_SBM1_SBM2 >> 8); | ||||
headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_SBM1_SBM2); | ||||
} | ||||
else | ||||
{ | ||||
headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8); | ||||
headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST); | ||||
} | ||||
|
r33 | if (i == 0) | ||
{ | ||||
headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_FIRST; | ||||
headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_340 >> 8); | ||||
headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_340 ); | ||||
headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8); | ||||
headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 ); | ||||
} | ||||
else if (i == 6) | ||||
{ | ||||
headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_LAST; | ||||
headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_8 >> 8); | ||||
headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_8 ); | ||||
headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_8 >> 8); | ||||
headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_8 ); | ||||
} | ||||
else | ||||
{ | ||||
headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_CONTINUATION; | ||||
headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_340 >> 8); | ||||
headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_340 ); | ||||
headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8); | ||||
headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 ); | ||||
} | ||||
headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | ||||
// PKT_CNT | ||||
// PKT_NR | ||||
// 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; | ||||
|
r18 | } | ||
|
r38 | int init_header_continuous_wf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF ) | ||
{ | ||||
unsigned int i; | ||||
for (i=0; i<7; i++) | ||||
{ | ||||
headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID; | ||||
headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID; | ||||
headerCWF[ i ].reserved = DEFAULT_RESERVED; | ||||
headerCWF[ i ].userApplication = CCSDS_USER_APP; | ||||
headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8); | ||||
headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST); | ||||
if (i == 0) | ||||
{ | ||||
headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_FIRST; | ||||
headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_340 >> 8); | ||||
headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_340 ); | ||||
headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8); | ||||
headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 ); | ||||
} | ||||
else if (i == 6) | ||||
{ | ||||
headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_LAST; | ||||
headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_8 >> 8); | ||||
headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_8 ); | ||||
headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_8 >> 8); | ||||
headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_8 ); | ||||
} | ||||
else | ||||
{ | ||||
headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_CONTINUATION; | ||||
headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_340 >> 8); | ||||
headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_340 ); | ||||
headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8); | ||||
headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 ); | ||||
} | ||||
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; | ||||
} | ||||
|
r18 | void reset_waveforms( void ) | ||
|
r17 | { | ||
int i = 0; | ||||
for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++) | ||||
{ | ||||
|
r18 | wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET] = 0x10002000; | ||
wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET] = 0x20001000; | ||||
wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET] = 0x40008000; | ||||
//*** | ||||
// F1 | ||||
wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET] = 0x1000f000; | ||||
wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET] = 0xf0001000; | ||||
wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET] = 0x40008000; | ||||
//*** | ||||
// F2 | ||||
wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET] = 0x40008000; | ||||
wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET] = 0x20001000; | ||||
wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET] = 0x10002000; | ||||
//*** | ||||
// F3 | ||||
/*wf_cont_f3[ i* NB_WORDS_SWF_BLK + 0 ] = build_value( i, i ); // v and 1 | ||||
wf_cont_f3[ i* NB_WORDS_SWF_BLK + 1 ] = build_value( i, i ); // e2 and b1 | ||||
wf_cont_f3[ i* NB_WORDS_SWF_BLK + 2 ] = build_value( i, i ); // b2 and b3*/ | ||||
|
r17 | } | ||
} | ||||
|
r35 | int send_waveform_SWF( volatile int *waveform, unsigned int sid, | ||
Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id ) | ||||
|
r18 | { | ||
|
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. | ||||
* | ||||
*/ | ||||
|
r33 | unsigned int i; | ||
int ret; | ||||
|
r18 | rtems_status_code status; | ||
|
r33 | spw_ioctl_pkt_send spw_ioctl_send_SWF; | ||
|
r18 | |||
|
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; | ||||
|
r23 | |||
|
r33 | ret = LFR_DEFAULT; | ||
|
r23 | for (i=0; i<7; i++) // send waveform | ||
{ | ||||
|
r33 | spw_ioctl_send_SWF.data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) ]; | ||
|
r34 | spw_ioctl_send_SWF.hdr = (char*) &headerSWF[ i ]; | ||
|
r23 | // BUILD THE DATA | ||
if (i==6) { | ||||
|
r33 | spw_ioctl_send_SWF.dlen = 8 * NB_BYTES_SWF_BLK; | ||
|
r23 | } | ||
else { | ||||
|
r33 | spw_ioctl_send_SWF.dlen = 340 * NB_BYTES_SWF_BLK; | ||
|
r18 | } | ||
|
r33 | // SET PACKET TIME | ||
|
r46 | headerSWF[ i ].acquisitionTime[0] = (unsigned char) (time_management_regs->coarse_time>>24); | ||
headerSWF[ i ].acquisitionTime[1] = (unsigned char) (time_management_regs->coarse_time>>16); | ||||
headerSWF[ i ].acquisitionTime[2] = (unsigned char) (time_management_regs->coarse_time>>8); | ||||
headerSWF[ i ].acquisitionTime[3] = (unsigned char) (time_management_regs->coarse_time); | ||||
headerSWF[ i ].acquisitionTime[4] = (unsigned char) (time_management_regs->fine_time>>8); | ||||
headerSWF[ i ].acquisitionTime[5] = (unsigned char) (time_management_regs->fine_time); | ||||
|
r34 | headerSWF[ i ].time[0] = (unsigned char) (time_management_regs->coarse_time>>24); | ||
headerSWF[ i ].time[1] = (unsigned char) (time_management_regs->coarse_time>>16); | ||||
headerSWF[ i ].time[2] = (unsigned char) (time_management_regs->coarse_time>>8); | ||||
headerSWF[ i ].time[3] = (unsigned char) (time_management_regs->coarse_time); | ||||
headerSWF[ i ].time[4] = (unsigned char) (time_management_regs->fine_time>>8); | ||||
headerSWF[ i ].time[5] = (unsigned char) (time_management_regs->fine_time); | ||||
|
r33 | // SEND PACKET | ||
|
r37 | status = rtems_message_queue_send( queue_id, &spw_ioctl_send_SWF, ACTION_MSG_SPW_IOCTL_SEND_SIZE); | ||
|
r33 | if (status != RTEMS_SUCCESSFUL) { | ||
|
r34 | printf("%d-%d, ERR %d\n", sid, i, (int) status); | ||
|
r33 | ret = LFR_DEFAULT; | ||
} | ||||
rtems_task_wake_after(TIME_BETWEEN_TWO_SWF_PACKETS); // 300 ms between each packet => 7 * 3 = 21 packets => 6.3 seconds | ||||
|
r23 | } | ||
|
r32 | |||
|
r33 | return ret; | ||
|
r23 | } | ||
|
r35 | int send_waveform_CWF(volatile int *waveform, unsigned int sid, | ||
Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id) | ||||
|
r23 | { | ||
|
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. | ||||
* | ||||
*/ | ||||
|
r33 | unsigned int i; | ||
int ret; | ||||
rtems_status_code status; | ||||
spw_ioctl_pkt_send spw_ioctl_send_CWF; | ||||
|
r23 | |||
|
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; | ||||
|
r23 | |||
|
r33 | for (i=0; i<7; i++) // send waveform | ||
{ | ||||
int coarseTime = 0x00; | ||||
int fineTime = 0x00; | ||||
spw_ioctl_send_CWF.data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) ]; | ||||
spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ]; | ||||
// BUILD THE DATA | ||||
if (i==6) { | ||||
spw_ioctl_send_CWF.dlen = 8 * NB_BYTES_SWF_BLK; | ||||
} | ||||
else { | ||||
spw_ioctl_send_CWF.dlen = 340 * NB_BYTES_SWF_BLK; | ||||
} | ||||
// SET PACKET TIME | ||||
coarseTime = time_management_regs->coarse_time; | ||||
fineTime = time_management_regs->fine_time; | ||||
|
r46 | headerCWF[ i ].acquisitionTime[0] = (unsigned char) (coarseTime>>24); | ||
headerCWF[ i ].acquisitionTime[1] = (unsigned char) (coarseTime>>16); | ||||
headerCWF[ i ].acquisitionTime[2] = (unsigned char) (coarseTime>>8); | ||||
headerCWF[ i ].acquisitionTime[3] = (unsigned char) (coarseTime); | ||||
headerCWF[ i ].acquisitionTime[4] = (unsigned char) (fineTime>>8); | ||||
headerCWF[ i ].acquisitionTime[5] = (unsigned char) (fineTime); | ||||
|
r33 | headerCWF[ i ].time[0] = (unsigned char) (coarseTime>>24); | ||
headerCWF[ i ].time[1] = (unsigned char) (coarseTime>>16); | ||||
headerCWF[ i ].time[2] = (unsigned char) (coarseTime>>8); | ||||
headerCWF[ i ].time[3] = (unsigned char) (coarseTime); | ||||
headerCWF[ i ].time[4] = (unsigned char) (fineTime>>8); | ||||
headerCWF[ i ].time[5] = (unsigned char) (fineTime); | ||||
// SEND PACKET | ||||
|
r34 | if (sid == SID_NORM_CWF_F3) | ||
{ | ||||
|
r35 | status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF)); | ||
|
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); | ||||
|
r33 | } | ||
else | ||||
{ | ||||
|
r36 | status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF)); | ||
|
r34 | if (status != RTEMS_SUCCESSFUL) { | ||
printf("%d-%d, ERR %d\n", sid, i, (int) status); | ||||
ret = LFR_DEFAULT; | ||||
} | ||||
|
r33 | } | ||
} | ||||
|
r23 | |||
|
r33 | return ret; | ||
|
r23 | } | ||
|
r38 | int send_waveform_CWF3_light(volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id) | ||
{ | ||||
|
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; | ||
int ret; | ||||
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 | ||||
for ( i=0; i< 2048; i++) | ||||
{ | ||||
sample = (char*) &waveform[ i * NB_WORDS_SWF_BLK ]; | ||||
wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) ] = sample[ 0 ]; | ||||
wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 ] = sample[ 1 ]; | ||||
wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 ] = sample[ 2 ]; | ||||
wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 ] = sample[ 3 ]; | ||||
wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 ] = sample[ 4 ]; | ||||
wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 ] = sample[ 5 ]; | ||||
} | ||||
//********************* | ||||
// SEND CWF3_light DATA | ||||
for (i=0; i<7; i++) // send waveform | ||||
{ | ||||
int coarseTime = 0x00; | ||||
int fineTime = 0x00; | ||||
spw_ioctl_send_CWF.data = (char*) &wf_cont_f3_light[ (i * 340 * NB_BYTES_CWF3_LIGHT_BLK) ]; | ||||
spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ]; | ||||
// BUILD THE DATA | ||||
if ( i == WFRM_INDEX_OF_LAST_PACKET ) { | ||||
spw_ioctl_send_CWF.dlen = 8 * NB_BYTES_CWF3_LIGHT_BLK; | ||||
} | ||||
else { | ||||
spw_ioctl_send_CWF.dlen = 340 * NB_BYTES_CWF3_LIGHT_BLK; | ||||
} | ||||
// SET PACKET TIME | ||||
coarseTime = time_management_regs->coarse_time; | ||||
fineTime = time_management_regs->fine_time; | ||||
|
r46 | headerCWF[ i ].acquisitionTime[0] = (unsigned char) (coarseTime>>24); | ||
headerCWF[ i ].acquisitionTime[1] = (unsigned char) (coarseTime>>16); | ||||
headerCWF[ i ].acquisitionTime[2] = (unsigned char) (coarseTime>>8); | ||||
headerCWF[ i ].acquisitionTime[3] = (unsigned char) (coarseTime); | ||||
headerCWF[ i ].acquisitionTime[4] = (unsigned char) (fineTime>>8); | ||||
headerCWF[ i ].acquisitionTime[5] = (unsigned char) (fineTime); | ||||
|
r38 | headerCWF[ i ].time[0] = (unsigned char) (coarseTime>>24); | ||
headerCWF[ i ].time[1] = (unsigned char) (coarseTime>>16); | ||||
headerCWF[ i ].time[2] = (unsigned char) (coarseTime>>8); | ||||
headerCWF[ i ].time[3] = (unsigned char) (coarseTime); | ||||
headerCWF[ i ].time[4] = (unsigned char) (fineTime>>8); | ||||
headerCWF[ i ].time[5] = (unsigned char) (fineTime); | ||||
// 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; | ||||
} | ||||
|
r23 | //************** | ||
// wfp registers | ||||
|
r32 | void set_wfp_data_shaping() | ||
|
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 | |||
data_shaping = parameter_dump_packet.bw_sp0_sp1_r0_r1; | ||||
|
r31 | #ifdef GSA | ||
#else | ||||
|
r52 | new_waveform_picker_regs->data_shaping = | ||
|
r23 | ( (data_shaping & 0x10) >> 4 ) // BW | ||
+ ( (data_shaping & 0x08) >> 2 ) // SP0 | ||||
+ ( (data_shaping & 0x04) ) // SP1 | ||||
+ ( (data_shaping & 0x02) << 2 ) // R0 | ||||
+ ( (data_shaping & 0x01) << 4 ); // R1 | ||||
|
r31 | #endif | ||
|
r23 | } | ||
|
r32 | char set_wfp_delta_snapshot() | ||
{ | ||||
|
r40 | /** This function sets the delta_snapshot register of the waveform picker module. | ||
* | ||||
|
r45 | * 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 | * | ||
*/ | ||||
|
r32 | char ret; | ||
unsigned int delta_snapshot; | ||||
|
r38 | unsigned int aux; | ||
aux = 0; | ||||
|
r32 | ret = LFR_DEFAULT; | ||
delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256 | ||||
+ parameter_dump_packet.sy_lfr_n_swf_p[1]; | ||||
#ifdef GSA | ||||
#else | ||||
if ( delta_snapshot < MIN_DELTA_SNAPSHOT ) | ||||
{ | ||||
aux = MIN_DELTA_SNAPSHOT; | ||||
ret = LFR_DEFAULT; | ||||
} | ||||
else | ||||
{ | ||||
aux = delta_snapshot ; | ||||
ret = LFR_SUCCESSFUL; | ||||
} | ||||
|
r52 | new_waveform_picker_regs->delta_snapshot = aux - 1; // max 2 bytes | ||
|
r32 | #endif | ||
return ret; | ||||
} | ||||
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. | ||||
* | ||||
*/ | ||||
|
r31 | #ifdef GSA | ||
#else | ||||
|
r32 | // [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): | ||||
|
r52 | new_waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enable | ||
new_waveform_picker_regs->run_burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0 | ||||
|
r32 | break; | ||
case(LFR_MODE_BURST): | ||||
|
r52 | new_waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled | ||
new_waveform_picker_regs->run_burst_enable = new_waveform_picker_regs->run_burst_enable | 0x04; // [0100] enable f2 | ||||
|
r32 | break; | ||
case(LFR_MODE_SBM1): | ||||
|
r52 | new_waveform_picker_regs->run_burst_enable = 0x20; // [0010 0000] f1 burst enabled | ||
new_waveform_picker_regs->run_burst_enable = new_waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0 | ||||
|
r32 | break; | ||
case(LFR_MODE_SBM2): | ||||
|
r52 | new_waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled | ||
new_waveform_picker_regs->run_burst_enable = new_waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0 | ||||
|
r32 | break; | ||
default: | ||||
|
r52 | new_waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled | ||
|
r32 | break; | ||
} | ||||
|
r31 | #endif | ||
|
r23 | } | ||
void reset_wfp_burst_enable() | ||||
{ | ||||
|
r40 | /** 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. | ||||
* | ||||
*/ | ||||
|
r31 | #ifdef GSA | ||
#else | ||||
|
r52 | new_waveform_picker_regs->run_burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0 | ||
|
r31 | #endif | ||
|
r23 | } | ||
|
r33 | void reset_wfp_status() | ||
{ | ||||
|
r40 | /** This function resets the waveform picker status register. | ||
* | ||||
* All status bits are set to 0 [new_err full_err full]. | ||||
* | ||||
*/ | ||||
|
r33 | #ifdef GSA | ||
#else | ||||
|
r52 | new_waveform_picker_regs->status = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0 | ||
|
r33 | #endif | ||
} | ||||
|
r52 | void reset_new_waveform_picker_regs() | ||
|
r23 | { | ||
|
r52 | new_waveform_picker_regs->data_shaping = 0x01; // 0x00 00 *** R1 R0 SP1 SP0 BW | ||
new_waveform_picker_regs->run_burst_enable = 0x00; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] | ||||
new_waveform_picker_regs->addr_data_f0 = (int) (wf_snap_f0); // 0x08 | ||||
new_waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1); // 0x0c | ||||
new_waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2); // 0x10 | ||||
new_waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3); // 0x14 | ||||
new_waveform_picker_regs->status = 0x00; // 0x18 | ||||
new_waveform_picker_regs->delta_snapshot = 0x12800; // 0x1c | ||||
new_waveform_picker_regs->delta_f0 = 0x3f5; // 0x20 *** 1013 | ||||
new_waveform_picker_regs->delta_f0_2 = 0x7; // 0x24 *** 7 | ||||
new_waveform_picker_regs->delta_f1 = 0x3c0; // 0x28 *** 960 | ||||
new_waveform_picker_regs->delta_f2 = 0x12200; // 0x2c *** 74240 | ||||
new_waveform_picker_regs->nb_data_by_buffer = 0x1802; // 0x30 *** 2048 * 3 + 2 | ||||
new_waveform_picker_regs->snapshot_param = 0x7ff; // 0x34 *** 2048 -1 | ||||
new_waveform_picker_regs->start_date = 0x00; | ||||
|
r51 | } | ||
|
r32 | //***************** | ||
// local parameters | ||||
void set_local_sbm1_nb_cwf_max() | ||||
{ | ||||
|
r40 | /** This function sets the value of the sbm1_nb_cwf_max local parameter. | ||
* | ||||
* The sbm1_nb_cwf_max parameter counts the number of CWF_F1 records that have been sent.\n | ||||
* This parameter is used to send CWF_F1 data as normal data when the SBM1 is active.\n\n | ||||
* (2 snapshots of 2048 points per seconds) * (period of the NORM snashots) - 8 s (duration of the f2 snapshot) | ||||
* | ||||
*/ | ||||
|
r34 | param_local.local_sbm1_nb_cwf_max = 2 * | ||
(parameter_dump_packet.sy_lfr_n_swf_p[0] * 256 | ||||
+ parameter_dump_packet.sy_lfr_n_swf_p[1]) - 8; // 16 CWF1 parts during 1 SWF2 | ||||
|
r32 | } | ||
void set_local_sbm2_nb_cwf_max() | ||||
{ | ||||
|
r40 | /** This function sets the value of the sbm1_nb_cwf_max local parameter. | ||
* | ||||
* The sbm1_nb_cwf_max parameter counts the number of CWF_F1 records that have been sent.\n | ||||
* This parameter is used to send CWF_F2 data as normal data when the SBM2 is active.\n\n | ||||
* (period of the NORM snashots) / (8 seconds per snapshot at f2 = 256 Hz) | ||||
* | ||||
*/ | ||||
|
r34 | param_local.local_sbm2_nb_cwf_max = (parameter_dump_packet.sy_lfr_n_swf_p[0] * 256 | ||
+ parameter_dump_packet.sy_lfr_n_swf_p[1]) / 8; | ||||
|
r32 | } | ||
void set_local_nb_interrupt_f0_MAX() | ||||
{ | ||||
|
r40 | /** This function sets the value of the nb_interrupt_f0_MAX local parameter. | ||
* | ||||
* This parameter is used for the SM validation only.\n | ||||
* The software waits param_local.local_nb_interrupt_f0_MAX interruptions from the spectral matrices | ||||
* module before launching a basic processing. | ||||
* | ||||
*/ | ||||
|
r32 | param_local.local_nb_interrupt_f0_MAX = ( (parameter_dump_packet.sy_lfr_n_asm_p[0]) * 256 | ||
+ parameter_dump_packet.sy_lfr_n_asm_p[1] ) * 100; | ||||
} | ||||
void reset_local_sbm1_nb_cwf_sent() | ||||
{ | ||||
|
r40 | /** This function resets the value of the sbm1_nb_cwf_sent local parameter. | ||
* | ||||
* The sbm1_nb_cwf_sent parameter counts the number of CWF_F1 records that have been sent.\n | ||||
* This parameter is used to send CWF_F1 data as normal data when the SBM1 is active. | ||||
* | ||||
*/ | ||||
|
r32 | param_local.local_sbm1_nb_cwf_sent = 0; | ||
} | ||||
void reset_local_sbm2_nb_cwf_sent() | ||||
{ | ||||
|
r40 | /** This function resets the value of the sbm2_nb_cwf_sent local parameter. | ||
* | ||||
* The sbm2_nb_cwf_sent parameter counts the number of CWF_F2 records that have been sent.\n | ||||
* This parameter is used to send CWF_F2 data as normal data when the SBM2 mode is active. | ||||
* | ||||
*/ | ||||
|
r32 | param_local.local_sbm2_nb_cwf_sent = 0; | ||
} | ||||
|
r45 | |||
rtems_id get_pkts_queue_id( void ) | ||||
{ | ||||
rtems_id queue_id; | ||||
rtems_status_code status; | ||||
|
r50 | rtems_name queue_send_name; | ||
|
r45 | |||
|
r50 | queue_send_name = rtems_build_name( 'Q', '_', 'S', 'D' ); | ||
status = rtems_message_queue_ident( queue_send_name, 0, &queue_id ); | ||||
|
r45 | if (status != RTEMS_SUCCESSFUL) | ||
{ | ||||
PRINTF1("in get_pkts_queue_id *** ERR %d\n", status) | ||||
} | ||||
return queue_id; | ||||
} | ||||