##// END OF EJS Templates
alignment added to variables initialized by memset...
paul -
r338:f3be7fb04b63 R3++ draft
parent child
Show More
@@ -1,118 +1,119
1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
2 #define TC_LOAD_DUMP_PARAMETERS_H
2 #define TC_LOAD_DUMP_PARAMETERS_H
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <stdio.h>
5 #include <stdio.h>
6
6
7 #include "fsw_params.h"
7 #include "fsw_params.h"
8 #include "wf_handler.h"
8 #include "wf_handler.h"
9 #include "tm_lfr_tc_exe.h"
9 #include "tm_lfr_tc_exe.h"
10 #include "fsw_misc.h"
10 #include "fsw_misc.h"
11 #include "basic_parameters_params.h"
11 #include "basic_parameters_params.h"
12 #include "avf0_prc0.h"
12 #include "avf0_prc0.h"
13
13
14 #define FLOAT_EQUAL_ZERO 0.001
14 #define FLOAT_EQUAL_ZERO 0.001
15 #define NB_BINS_TO_REMOVE 3
15 #define NB_BINS_TO_REMOVE 3
16 #define FI_INTERVAL_COEFF 0.285
16 #define FI_INTERVAL_COEFF 0.285
17 #define BIN_MIN 0
17 #define BIN_MIN 0
18 #define BIN_MAX 127
18 #define BIN_MAX 127
19 #define DELTAF_F0 96.
19 #define DELTAF_F0 96.
20 #define DELTAF_F1 16.
20 #define DELTAF_F1 16.
21 #define DELTAF_F2 1.
21 #define DELTAF_F2 1.
22 #define DELTAF_DIV 2.
22 #define DELTAF_DIV 2.
23
23
24 #define BIT_RW1_F1 0x80
24 #define BIT_RW1_F1 0x80
25 #define BIT_RW1_F2 0x40
25 #define BIT_RW1_F2 0x40
26 #define BIT_RW2_F1 0x20
26 #define BIT_RW2_F1 0x20
27 #define BIT_RW2_F2 0x10
27 #define BIT_RW2_F2 0x10
28 #define BIT_RW3_F1 0x08
28 #define BIT_RW3_F1 0x08
29 #define BIT_RW3_F2 0x04
29 #define BIT_RW3_F2 0x04
30 #define BIT_RW4_F1 0x02
30 #define BIT_RW4_F1 0x02
31 #define BIT_RW4_F2 0x01
31 #define BIT_RW4_F2 0x01
32
32
33 #define WHEEL_1 1
33 #define WHEEL_1 1
34 #define WHEEL_2 2
34 #define WHEEL_2 2
35 #define WHEEL_3 3
35 #define WHEEL_3 3
36 #define WHEEL_4 4
36 #define WHEEL_4 4
37 #define FREQ_1 1
37 #define FREQ_1 1
38 #define FREQ_2 2
38 #define FREQ_2 2
39 #define FREQ_3 3
39 #define FREQ_3 3
40 #define FREQ_4 4
40 #define FREQ_4 4
41 #define FLAG_OFFSET_WHEELS_1_3 8
41 #define FLAG_OFFSET_WHEELS_1_3 8
42 #define FLAG_OFFSET_WHEELS_2_4 4
42 #define FLAG_OFFSET_WHEELS_2_4 4
43
43
44 #define FLAG_NAN 0 // Not A NUMBER
44 #define FLAG_NAN 0 // Not A NUMBER
45 #define FLAG_IAN 1 // Is A Number
45 #define FLAG_IAN 1 // Is A Number
46
46
47 #define SBM_KCOEFF_PER_NORM_KCOEFF 2
47 #define SBM_KCOEFF_PER_NORM_KCOEFF 2
48
48
49 extern unsigned short sequenceCounterParameterDump;
49 extern unsigned short sequenceCounterParameterDump;
50 extern unsigned short sequenceCounters_TM_DUMP[];
50 extern unsigned short sequenceCounters_TM_DUMP[];
51 extern float k_coeff_intercalib_f0_norm[ ];
51 extern float k_coeff_intercalib_f0_norm[ ];
52 extern float k_coeff_intercalib_f0_sbm[ ];
52 extern float k_coeff_intercalib_f0_sbm[ ];
53 extern float k_coeff_intercalib_f1_norm[ ];
53 extern float k_coeff_intercalib_f1_norm[ ];
54 extern float k_coeff_intercalib_f1_sbm[ ];
54 extern float k_coeff_intercalib_f1_sbm[ ];
55 extern float k_coeff_intercalib_f2[ ];
55 extern float k_coeff_intercalib_f2[ ];
56 extern fbins_masks_t fbins_masks;
56 extern fbins_masks_t fbins_masks;
57
57
58 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
58 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
59 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
59 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
60 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
60 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
61 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
61 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
62 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
62 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
63 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
63 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
64 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
64 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
65 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
65 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
66 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
66 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
67 int action_dump_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
67 int action_dump_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
68
68
69 // NORMAL
69 // NORMAL
70 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
70 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
71 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC );
71 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC );
72 int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC );
72 int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC );
73 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC );
73 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC );
74 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC );
74 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC );
75 int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC );
75 int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC );
76 int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC );
76 int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC );
77
77
78 // BURST
78 // BURST
79 int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC );
79 int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC );
80 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC );
80 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC );
81
81
82 // SBM1
82 // SBM1
83 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC );
83 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC );
84 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC );
84 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC );
85
85
86 // SBM2
86 // SBM2
87 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC );
87 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC );
88 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC );
88 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC );
89
89
90 // TC_LFR_UPDATE_INFO
90 // TC_LFR_UPDATE_INFO
91 unsigned int check_update_info_hk_lfr_mode( unsigned char mode );
91 unsigned int check_update_info_hk_lfr_mode( unsigned char mode );
92 unsigned int check_update_info_hk_tds_mode( unsigned char mode );
92 unsigned int check_update_info_hk_tds_mode( unsigned char mode );
93 unsigned int check_update_info_hk_thr_mode( unsigned char mode );
93 unsigned int check_update_info_hk_thr_mode( unsigned char mode );
94 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value );
94 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value );
95 void set_hk_lfr_sc_rw_f_flags( void );
95 void set_hk_lfr_sc_rw_f_flags( void );
96 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC );
96 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC );
97 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float kcoeff );
97 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float kcoeff );
98 void build_sy_lfr_rw_mask( unsigned int channel );
98 void build_sy_lfr_rw_mask( unsigned int channel );
99 void build_sy_lfr_rw_masks();
99 void build_sy_lfr_rw_masks();
100 void merge_fbins_masks( void );
100 void merge_fbins_masks( void );
101
101
102 // FBINS_MASK
102 // FBINS_MASK
103 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC );
103 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC );
104
104
105 // TC_LFR_LOAD_PARS_FILTER_PAR
105 // TC_LFR_LOAD_PARS_FILTER_PAR
106 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
106 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
107
107
108 // KCOEFFICIENTS
108 // KCOEFFICIENTS
109 int set_sy_lfr_kcoeff(ccsdsTelecommandPacket_t *TC , rtems_id queue_id);
109 int set_sy_lfr_kcoeff(ccsdsTelecommandPacket_t *TC , rtems_id queue_id);
110 void copyFloatByChar( unsigned char *destination, unsigned char *source );
110 void copyFloatByChar( unsigned char *destination, unsigned char *source );
111 void copyInt32ByChar( unsigned char *destination, unsigned char *source );
111 void floatToChar( float value, unsigned char* ptr);
112 void floatToChar( float value, unsigned char* ptr);
112
113
113 void init_parameter_dump( void );
114 void init_parameter_dump( void );
114 void init_kcoefficients_dump( void );
115 void init_kcoefficients_dump( void );
115 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr );
116 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr );
116 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id );
117 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id );
117
118
118 #endif // TC_LOAD_DUMP_PARAMETERS_H
119 #endif // TC_LOAD_DUMP_PARAMETERS_H
@@ -1,1633 +1,1633
1 /** Functions related to the SpaceWire interface.
1 /** Functions related to the SpaceWire interface.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle SpaceWire transmissions:
6 * A group of functions to handle SpaceWire transmissions:
7 * - configuration of the SpaceWire link
7 * - configuration of the SpaceWire link
8 * - SpaceWire related interruption requests processing
8 * - SpaceWire related interruption requests processing
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
11 *
11 *
12 */
12 */
13
13
14 #include "fsw_spacewire.h"
14 #include "fsw_spacewire.h"
15
15
16 rtems_name semq_name = 0;
16 rtems_name semq_name = 0;
17 rtems_id semq_id = RTEMS_ID_NONE;
17 rtems_id semq_id = RTEMS_ID_NONE;
18
18
19 //*****************
19 //*****************
20 // waveform headers
20 // waveform headers
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0};
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0};
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF = {0};
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF = {0};
23 Header_TM_LFR_SCIENCE_ASM_t headerASM = {0};
23 Header_TM_LFR_SCIENCE_ASM_t headerASM = {0};
24
24
25 unsigned char previousTimecodeCtr = 0;
25 unsigned char previousTimecodeCtr = 0;
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
27
27
28 //***********
28 //***********
29 // RTEMS TASK
29 // RTEMS TASK
30 rtems_task spiq_task(rtems_task_argument unused)
30 rtems_task spiq_task(rtems_task_argument unused)
31 {
31 {
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
33 *
33 *
34 * @param unused is the starting argument of the RTEMS task
34 * @param unused is the starting argument of the RTEMS task
35 *
35 *
36 */
36 */
37
37
38 rtems_event_set event_out;
38 rtems_event_set event_out;
39 rtems_status_code status;
39 rtems_status_code status;
40 int linkStatus;
40 int linkStatus;
41
41
42 event_out = EVENT_SETS_NONE_PENDING;
42 event_out = EVENT_SETS_NONE_PENDING;
43 linkStatus = 0;
43 linkStatus = 0;
44
44
45 BOOT_PRINTF("in SPIQ *** \n")
45 BOOT_PRINTF("in SPIQ *** \n")
46
46
47 while(true){
47 while(true){
48 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
48 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
49 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
49 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
50
50
51 // [0] SUSPEND RECV AND SEND TASKS
51 // [0] SUSPEND RECV AND SEND TASKS
52 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
52 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
53 if ( status != RTEMS_SUCCESSFUL ) {
53 if ( status != RTEMS_SUCCESSFUL ) {
54 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
54 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
55 }
55 }
56 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
56 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
57 if ( status != RTEMS_SUCCESSFUL ) {
57 if ( status != RTEMS_SUCCESSFUL ) {
58 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
58 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
59 }
59 }
60
60
61 // [1] CHECK THE LINK
61 // [1] CHECK THE LINK
62 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
62 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
63 if ( linkStatus != SPW_LINK_OK) {
63 if ( linkStatus != SPW_LINK_OK) {
64 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
64 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
65 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
65 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
66 }
66 }
67
67
68 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
68 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
69 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
69 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
70 if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link
70 if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link
71 {
71 {
72 spacewire_read_statistics();
72 spacewire_read_statistics();
73 status = spacewire_several_connect_attemps( );
73 status = spacewire_several_connect_attemps( );
74 }
74 }
75 else // [2.b] in run state, start the link
75 else // [2.b] in run state, start the link
76 {
76 {
77 status = spacewire_stop_and_start_link( fdSPW ); // start the link
77 status = spacewire_stop_and_start_link( fdSPW ); // start the link
78 if ( status != RTEMS_SUCCESSFUL)
78 if ( status != RTEMS_SUCCESSFUL)
79 {
79 {
80 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
80 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
81 }
81 }
82 }
82 }
83
83
84 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
84 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
85 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
85 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
86 {
86 {
87 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
87 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
88 if ( status != RTEMS_SUCCESSFUL ) {
88 if ( status != RTEMS_SUCCESSFUL ) {
89 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
89 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
90 }
90 }
91 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
91 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
92 if ( status != RTEMS_SUCCESSFUL ) {
92 if ( status != RTEMS_SUCCESSFUL ) {
93 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
93 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
94 }
94 }
95 }
95 }
96 else // [3.b] the link is not in run state, go in STANDBY mode
96 else // [3.b] the link is not in run state, go in STANDBY mode
97 {
97 {
98 status = enter_mode_standby();
98 status = enter_mode_standby();
99 if ( status != RTEMS_SUCCESSFUL )
99 if ( status != RTEMS_SUCCESSFUL )
100 {
100 {
101 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
101 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
102 }
102 }
103 {
103 {
104 updateLFRCurrentMode( LFR_MODE_STANDBY );
104 updateLFRCurrentMode( LFR_MODE_STANDBY );
105 }
105 }
106 // wake the LINK task up to wait for the link recovery
106 // wake the LINK task up to wait for the link recovery
107 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
107 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
108 status = rtems_task_suspend( RTEMS_SELF );
108 status = rtems_task_suspend( RTEMS_SELF );
109 }
109 }
110 }
110 }
111 }
111 }
112
112
113 rtems_task recv_task( rtems_task_argument unused )
113 rtems_task recv_task( rtems_task_argument unused )
114 {
114 {
115 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
115 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
116 *
116 *
117 * @param unused is the starting argument of the RTEMS task
117 * @param unused is the starting argument of the RTEMS task
118 *
118 *
119 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
119 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
120 * 1. It reads the incoming data.
120 * 1. It reads the incoming data.
121 * 2. Launches the acceptance procedure.
121 * 2. Launches the acceptance procedure.
122 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
122 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
123 *
123 *
124 */
124 */
125
125
126 int len;
126 int len;
127 ccsdsTelecommandPacket_t currentTC;
127 ccsdsTelecommandPacket_t __attribute__((aligned(4))) currentTC;
128 unsigned char computed_CRC[ BYTES_PER_CRC ];
128 unsigned char computed_CRC[ BYTES_PER_CRC ];
129 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
129 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
130 unsigned char destinationID;
130 unsigned char destinationID;
131 unsigned int estimatedPacketLength;
131 unsigned int estimatedPacketLength;
132 unsigned int parserCode;
132 unsigned int parserCode;
133 rtems_status_code status;
133 rtems_status_code status;
134 rtems_id queue_recv_id;
134 rtems_id queue_recv_id;
135 rtems_id queue_send_id;
135 rtems_id queue_send_id;
136
136
137 memset( &currentTC, 0, sizeof(ccsdsTelecommandPacket_t) );
137 memset( &currentTC, 0, sizeof(ccsdsTelecommandPacket_t) );
138 destinationID = 0;
138 destinationID = 0;
139 queue_recv_id = RTEMS_ID_NONE;
139 queue_recv_id = RTEMS_ID_NONE;
140 queue_send_id = RTEMS_ID_NONE;
140 queue_send_id = RTEMS_ID_NONE;
141
141
142 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
142 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
143
143
144 status = get_message_queue_id_recv( &queue_recv_id );
144 status = get_message_queue_id_recv( &queue_recv_id );
145 if (status != RTEMS_SUCCESSFUL)
145 if (status != RTEMS_SUCCESSFUL)
146 {
146 {
147 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
147 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
148 }
148 }
149
149
150 status = get_message_queue_id_send( &queue_send_id );
150 status = get_message_queue_id_send( &queue_send_id );
151 if (status != RTEMS_SUCCESSFUL)
151 if (status != RTEMS_SUCCESSFUL)
152 {
152 {
153 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
153 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
154 }
154 }
155
155
156 BOOT_PRINTF("in RECV *** \n")
156 BOOT_PRINTF("in RECV *** \n")
157
157
158 while(1)
158 while(1)
159 {
159 {
160 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
160 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
161 if (len == -1){ // error during the read call
161 if (len == -1){ // error during the read call
162 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
162 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
163 }
163 }
164 else {
164 else {
165 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
165 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
166 PRINTF("in RECV *** packet lenght too short\n")
166 PRINTF("in RECV *** packet lenght too short\n")
167 }
167 }
168 else {
168 else {
169 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes
169 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes
170 //PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
170 //PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
171 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
171 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
172 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
172 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
173 // CHECK THE TC
173 // CHECK THE TC
174 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
174 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
175 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
175 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
176 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
176 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
177 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
177 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
178 || (parserCode == WRONG_SRC_ID) )
178 || (parserCode == WRONG_SRC_ID) )
179 { // send TM_LFR_TC_EXE_CORRUPTED
179 { // send TM_LFR_TC_EXE_CORRUPTED
180 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
180 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
181 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
181 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
182 &&
182 &&
183 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
183 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
184 )
184 )
185 {
185 {
186 if ( parserCode == WRONG_SRC_ID )
186 if ( parserCode == WRONG_SRC_ID )
187 {
187 {
188 destinationID = SID_TC_GROUND;
188 destinationID = SID_TC_GROUND;
189 }
189 }
190 else
190 else
191 {
191 {
192 destinationID = currentTC.sourceID;
192 destinationID = currentTC.sourceID;
193 }
193 }
194 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
194 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
195 computed_CRC, currentTC_LEN_RCV,
195 computed_CRC, currentTC_LEN_RCV,
196 destinationID );
196 destinationID );
197 }
197 }
198 }
198 }
199 else
199 else
200 { // send valid TC to the action launcher
200 { // send valid TC to the action launcher
201 status = rtems_message_queue_send( queue_recv_id, &currentTC,
201 status = rtems_message_queue_send( queue_recv_id, &currentTC,
202 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
202 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
203 }
203 }
204 }
204 }
205 }
205 }
206
206
207 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
207 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
208
208
209 }
209 }
210 }
210 }
211
211
212 rtems_task send_task( rtems_task_argument argument)
212 rtems_task send_task( rtems_task_argument argument)
213 {
213 {
214 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
214 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
215 *
215 *
216 * @param unused is the starting argument of the RTEMS task
216 * @param unused is the starting argument of the RTEMS task
217 *
217 *
218 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
218 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
219 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
219 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
220 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
220 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
221 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
221 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
222 * data it contains.
222 * data it contains.
223 *
223 *
224 */
224 */
225
225
226 rtems_status_code status; // RTEMS status code
226 rtems_status_code status; // RTEMS status code
227 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
227 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
228 ring_node *incomingRingNodePtr;
228 ring_node *incomingRingNodePtr;
229 int ring_node_address;
229 int ring_node_address;
230 char *charPtr;
230 char *charPtr;
231 spw_ioctl_pkt_send *spw_ioctl_send;
231 spw_ioctl_pkt_send *spw_ioctl_send;
232 size_t size; // size of the incoming TC packet
232 size_t size; // size of the incoming TC packet
233 rtems_id queue_send_id;
233 rtems_id queue_send_id;
234 unsigned int sid;
234 unsigned int sid;
235 unsigned char sidAsUnsignedChar;
235 unsigned char sidAsUnsignedChar;
236 unsigned char type;
236 unsigned char type;
237
237
238 incomingRingNodePtr = NULL;
238 incomingRingNodePtr = NULL;
239 ring_node_address = 0;
239 ring_node_address = 0;
240 charPtr = (char *) &ring_node_address;
240 charPtr = (char *) &ring_node_address;
241 size = 0;
241 size = 0;
242 queue_send_id = RTEMS_ID_NONE;
242 queue_send_id = RTEMS_ID_NONE;
243 sid = 0;
243 sid = 0;
244 sidAsUnsignedChar = 0;
244 sidAsUnsignedChar = 0;
245
245
246 init_header_cwf( &headerCWF );
246 init_header_cwf( &headerCWF );
247 init_header_swf( &headerSWF );
247 init_header_swf( &headerSWF );
248 init_header_asm( &headerASM );
248 init_header_asm( &headerASM );
249
249
250 status = get_message_queue_id_send( &queue_send_id );
250 status = get_message_queue_id_send( &queue_send_id );
251 if (status != RTEMS_SUCCESSFUL)
251 if (status != RTEMS_SUCCESSFUL)
252 {
252 {
253 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
253 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
254 }
254 }
255
255
256 BOOT_PRINTF("in SEND *** \n")
256 BOOT_PRINTF("in SEND *** \n")
257
257
258 while(1)
258 while(1)
259 {
259 {
260 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
260 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
261 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
261 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
262
262
263 if (status!=RTEMS_SUCCESSFUL)
263 if (status!=RTEMS_SUCCESSFUL)
264 {
264 {
265 PRINTF1("in SEND *** (1) ERR = %d\n", status)
265 PRINTF1("in SEND *** (1) ERR = %d\n", status)
266 }
266 }
267 else
267 else
268 {
268 {
269 if ( size == sizeof(ring_node*) )
269 if ( size == sizeof(ring_node*) )
270 {
270 {
271 charPtr[0] = incomingData[0];
271 charPtr[0] = incomingData[0];
272 charPtr[1] = incomingData[1];
272 charPtr[1] = incomingData[1];
273 charPtr[BYTE_2] = incomingData[BYTE_2];
273 charPtr[BYTE_2] = incomingData[BYTE_2];
274 charPtr[BYTE_3] = incomingData[BYTE_3];
274 charPtr[BYTE_3] = incomingData[BYTE_3];
275 incomingRingNodePtr = (ring_node*) ring_node_address;
275 incomingRingNodePtr = (ring_node*) ring_node_address;
276 sid = incomingRingNodePtr->sid;
276 sid = incomingRingNodePtr->sid;
277 if ( (sid==SID_NORM_CWF_LONG_F3)
277 if ( (sid==SID_NORM_CWF_LONG_F3)
278 || (sid==SID_BURST_CWF_F2 )
278 || (sid==SID_BURST_CWF_F2 )
279 || (sid==SID_SBM1_CWF_F1 )
279 || (sid==SID_SBM1_CWF_F1 )
280 || (sid==SID_SBM2_CWF_F2 ))
280 || (sid==SID_SBM2_CWF_F2 ))
281 {
281 {
282 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
282 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
283 }
283 }
284 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
284 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
285 {
285 {
286 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
286 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
287 }
287 }
288 else if ( (sid==SID_NORM_CWF_F3) )
288 else if ( (sid==SID_NORM_CWF_F3) )
289 {
289 {
290 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
290 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
291 }
291 }
292 else if (sid==SID_NORM_ASM_F0)
292 else if (sid==SID_NORM_ASM_F0)
293 {
293 {
294 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
294 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
295 }
295 }
296 else if (sid==SID_NORM_ASM_F1)
296 else if (sid==SID_NORM_ASM_F1)
297 {
297 {
298 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
298 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
299 }
299 }
300 else if (sid==SID_NORM_ASM_F2)
300 else if (sid==SID_NORM_ASM_F2)
301 {
301 {
302 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
302 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
303 }
303 }
304 else if ( sid==TM_CODE_K_DUMP )
304 else if ( sid==TM_CODE_K_DUMP )
305 {
305 {
306 spw_send_k_dump( incomingRingNodePtr );
306 spw_send_k_dump( incomingRingNodePtr );
307 }
307 }
308 else
308 else
309 {
309 {
310 PRINTF1("unexpected sid = %d\n", sid);
310 PRINTF1("unexpected sid = %d\n", sid);
311 }
311 }
312 }
312 }
313 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
313 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
314 {
314 {
315 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
315 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
316 sid = sidAsUnsignedChar;
316 sid = sidAsUnsignedChar;
317 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
317 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
318 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
318 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
319 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
319 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
320 {
320 {
321 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
321 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
322 }
322 }
323
323
324 status = write( fdSPW, incomingData, size );
324 status = write( fdSPW, incomingData, size );
325 if (status == -1){
325 if (status == -1){
326 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
326 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
327 }
327 }
328 }
328 }
329 else // the incoming message is a spw_ioctl_pkt_send structure
329 else // the incoming message is a spw_ioctl_pkt_send structure
330 {
330 {
331 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
331 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
332 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
332 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
333 if (status == -1){
333 if (status == -1){
334 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
334 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
335 }
335 }
336 }
336 }
337 }
337 }
338
338
339 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
339 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
340
340
341 }
341 }
342 }
342 }
343
343
344 rtems_task link_task( rtems_task_argument argument )
344 rtems_task link_task( rtems_task_argument argument )
345 {
345 {
346 rtems_event_set event_out;
346 rtems_event_set event_out;
347 rtems_status_code status;
347 rtems_status_code status;
348 int linkStatus;
348 int linkStatus;
349
349
350 event_out = EVENT_SETS_NONE_PENDING;
350 event_out = EVENT_SETS_NONE_PENDING;
351 linkStatus = 0;
351 linkStatus = 0;
352
352
353 BOOT_PRINTF("in LINK ***\n")
353 BOOT_PRINTF("in LINK ***\n")
354
354
355 while(1)
355 while(1)
356 {
356 {
357 // wait for an RTEMS_EVENT
357 // wait for an RTEMS_EVENT
358 rtems_event_receive( RTEMS_EVENT_0,
358 rtems_event_receive( RTEMS_EVENT_0,
359 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
359 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
360 PRINTF("in LINK *** wait for the link\n")
360 PRINTF("in LINK *** wait for the link\n")
361 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
361 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
362 while( linkStatus != SPW_LINK_OK) // wait for the link
362 while( linkStatus != SPW_LINK_OK) // wait for the link
363 {
363 {
364 status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms
364 status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms
365 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
365 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
366 watchdog_reload();
366 watchdog_reload();
367 }
367 }
368
368
369 spacewire_read_statistics();
369 spacewire_read_statistics();
370 status = spacewire_stop_and_start_link( fdSPW );
370 status = spacewire_stop_and_start_link( fdSPW );
371
371
372 if (status != RTEMS_SUCCESSFUL)
372 if (status != RTEMS_SUCCESSFUL)
373 {
373 {
374 PRINTF1("in LINK *** ERR link not started %d\n", status)
374 PRINTF1("in LINK *** ERR link not started %d\n", status)
375 }
375 }
376 else
376 else
377 {
377 {
378 PRINTF("in LINK *** OK link started\n")
378 PRINTF("in LINK *** OK link started\n")
379 }
379 }
380
380
381 // restart the SPIQ task
381 // restart the SPIQ task
382 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
382 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
383 if ( status != RTEMS_SUCCESSFUL ) {
383 if ( status != RTEMS_SUCCESSFUL ) {
384 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
384 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
385 }
385 }
386
386
387 // restart RECV and SEND
387 // restart RECV and SEND
388 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
388 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
389 if ( status != RTEMS_SUCCESSFUL ) {
389 if ( status != RTEMS_SUCCESSFUL ) {
390 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
390 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
391 }
391 }
392 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
392 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
393 if ( status != RTEMS_SUCCESSFUL ) {
393 if ( status != RTEMS_SUCCESSFUL ) {
394 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
394 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
395 }
395 }
396 }
396 }
397 }
397 }
398
398
399 //****************
399 //****************
400 // OTHER FUNCTIONS
400 // OTHER FUNCTIONS
401 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
401 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
402 {
402 {
403 /** This function opens the SpaceWire link.
403 /** This function opens the SpaceWire link.
404 *
404 *
405 * @return a valid file descriptor in case of success, -1 in case of a failure
405 * @return a valid file descriptor in case of success, -1 in case of a failure
406 *
406 *
407 */
407 */
408 rtems_status_code status;
408 rtems_status_code status;
409
409
410 status = RTEMS_SUCCESSFUL;
410 status = RTEMS_SUCCESSFUL;
411
411
412 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
412 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
413 if ( fdSPW < 0 ) {
413 if ( fdSPW < 0 ) {
414 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
414 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
415 }
415 }
416 else
416 else
417 {
417 {
418 status = RTEMS_SUCCESSFUL;
418 status = RTEMS_SUCCESSFUL;
419 }
419 }
420
420
421 return status;
421 return status;
422 }
422 }
423
423
424 int spacewire_start_link( int fd )
424 int spacewire_start_link( int fd )
425 {
425 {
426 rtems_status_code status;
426 rtems_status_code status;
427
427
428 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
428 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
429 // -1 default hardcoded driver timeout
429 // -1 default hardcoded driver timeout
430
430
431 return status;
431 return status;
432 }
432 }
433
433
434 int spacewire_stop_and_start_link( int fd )
434 int spacewire_stop_and_start_link( int fd )
435 {
435 {
436 rtems_status_code status;
436 rtems_status_code status;
437
437
438 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
438 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
439 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
439 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
440 // -1 default hardcoded driver timeout
440 // -1 default hardcoded driver timeout
441
441
442 return status;
442 return status;
443 }
443 }
444
444
445 int spacewire_configure_link( int fd )
445 int spacewire_configure_link( int fd )
446 {
446 {
447 /** This function configures the SpaceWire link.
447 /** This function configures the SpaceWire link.
448 *
448 *
449 * @return GR-RTEMS-DRIVER directive status codes:
449 * @return GR-RTEMS-DRIVER directive status codes:
450 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
450 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
451 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
451 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
452 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
452 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
453 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
453 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
454 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
454 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
455 * - 5 EIO - Error when writing to grswp hardware registers.
455 * - 5 EIO - Error when writing to grswp hardware registers.
456 * - 2 ENOENT - No such file or directory
456 * - 2 ENOENT - No such file or directory
457 */
457 */
458
458
459 rtems_status_code status;
459 rtems_status_code status;
460
460
461 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
461 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
462 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
462 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
463 spw_ioctl_packetsize packetsize;
463 spw_ioctl_packetsize packetsize;
464
464
465 packetsize.rxsize = SPW_RXSIZE;
465 packetsize.rxsize = SPW_RXSIZE;
466 packetsize.txdsize = SPW_TXDSIZE;
466 packetsize.txdsize = SPW_TXDSIZE;
467 packetsize.txhsize = SPW_TXHSIZE;
467 packetsize.txhsize = SPW_TXHSIZE;
468
468
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
470 if (status!=RTEMS_SUCCESSFUL) {
470 if (status!=RTEMS_SUCCESSFUL) {
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
472 }
472 }
473 //
473 //
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
475 if (status!=RTEMS_SUCCESSFUL) {
475 if (status!=RTEMS_SUCCESSFUL) {
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
477 }
477 }
478 //
478 //
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
480 if (status!=RTEMS_SUCCESSFUL) {
480 if (status!=RTEMS_SUCCESSFUL) {
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
482 }
482 }
483 //
483 //
484 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
484 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
485 if (status!=RTEMS_SUCCESSFUL) {
485 if (status!=RTEMS_SUCCESSFUL) {
486 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
486 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
487 }
487 }
488 //
488 //
489 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
489 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
490 if (status!=RTEMS_SUCCESSFUL) {
490 if (status!=RTEMS_SUCCESSFUL) {
491 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
491 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
492 }
492 }
493 //
493 //
494 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
494 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
495 if (status!=RTEMS_SUCCESSFUL) {
495 if (status!=RTEMS_SUCCESSFUL) {
496 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
496 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
497 }
497 }
498 //
498 //
499 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
499 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
500 if (status!=RTEMS_SUCCESSFUL) {
500 if (status!=RTEMS_SUCCESSFUL) {
501 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
501 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
502 }
502 }
503 //
503 //
504 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
504 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
505 if (status!=RTEMS_SUCCESSFUL) {
505 if (status!=RTEMS_SUCCESSFUL) {
506 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
506 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
507 }
507 }
508
508
509 return status;
509 return status;
510 }
510 }
511
511
512 int spacewire_several_connect_attemps( void )
512 int spacewire_several_connect_attemps( void )
513 {
513 {
514 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
514 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
515 *
515 *
516 * @return RTEMS directive status code:
516 * @return RTEMS directive status code:
517 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
517 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
518 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
518 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
519 *
519 *
520 */
520 */
521
521
522 rtems_status_code status_spw;
522 rtems_status_code status_spw;
523 rtems_status_code status;
523 rtems_status_code status;
524 int i;
524 int i;
525
525
526 status_spw = RTEMS_SUCCESSFUL;
526 status_spw = RTEMS_SUCCESSFUL;
527
527
528 i = 0;
528 i = 0;
529 while (i < SY_LFR_DPU_CONNECT_ATTEMPT)
529 while (i < SY_LFR_DPU_CONNECT_ATTEMPT)
530 {
530 {
531 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
531 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
532
532
533 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
533 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
534
534
535 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
535 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
536
536
537 status_spw = spacewire_stop_and_start_link( fdSPW );
537 status_spw = spacewire_stop_and_start_link( fdSPW );
538
538
539 if ( status_spw != RTEMS_SUCCESSFUL )
539 if ( status_spw != RTEMS_SUCCESSFUL )
540 {
540 {
541 i = i + 1;
541 i = i + 1;
542 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw);
542 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw);
543 }
543 }
544 else
544 else
545 {
545 {
546 i = SY_LFR_DPU_CONNECT_ATTEMPT;
546 i = SY_LFR_DPU_CONNECT_ATTEMPT;
547 }
547 }
548 }
548 }
549
549
550 return status_spw;
550 return status_spw;
551 }
551 }
552
552
553 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
553 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
554 {
554 {
555 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
555 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
556 *
556 *
557 * @param val is the value, 0 or 1, used to set the value of the NP bit.
557 * @param val is the value, 0 or 1, used to set the value of the NP bit.
558 * @param regAddr is the address of the GRSPW control register.
558 * @param regAddr is the address of the GRSPW control register.
559 *
559 *
560 * NP is the bit 20 of the GRSPW control register.
560 * NP is the bit 20 of the GRSPW control register.
561 *
561 *
562 */
562 */
563
563
564 unsigned int *spwptr = (unsigned int*) regAddr;
564 unsigned int *spwptr = (unsigned int*) regAddr;
565
565
566 if (val == 1) {
566 if (val == 1) {
567 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
567 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
568 }
568 }
569 if (val== 0) {
569 if (val== 0) {
570 *spwptr = *spwptr & SPW_BIT_NP_MASK;
570 *spwptr = *spwptr & SPW_BIT_NP_MASK;
571 }
571 }
572 }
572 }
573
573
574 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
574 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
575 {
575 {
576 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
576 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
577 *
577 *
578 * @param val is the value, 0 or 1, used to set the value of the RE bit.
578 * @param val is the value, 0 or 1, used to set the value of the RE bit.
579 * @param regAddr is the address of the GRSPW control register.
579 * @param regAddr is the address of the GRSPW control register.
580 *
580 *
581 * RE is the bit 16 of the GRSPW control register.
581 * RE is the bit 16 of the GRSPW control register.
582 *
582 *
583 */
583 */
584
584
585 unsigned int *spwptr = (unsigned int*) regAddr;
585 unsigned int *spwptr = (unsigned int*) regAddr;
586
586
587 if (val == 1)
587 if (val == 1)
588 {
588 {
589 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
589 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
590 }
590 }
591 if (val== 0)
591 if (val== 0)
592 {
592 {
593 *spwptr = *spwptr & SPW_BIT_RE_MASK;
593 *spwptr = *spwptr & SPW_BIT_RE_MASK;
594 }
594 }
595 }
595 }
596
596
597 void spacewire_read_statistics( void )
597 void spacewire_read_statistics( void )
598 {
598 {
599 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
599 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
600 *
600 *
601 * @param void
601 * @param void
602 *
602 *
603 * @return void
603 * @return void
604 *
604 *
605 * Once they are read, the counters are stored in a global variable used during the building of the
605 * Once they are read, the counters are stored in a global variable used during the building of the
606 * HK packets.
606 * HK packets.
607 *
607 *
608 */
608 */
609
609
610 rtems_status_code status;
610 rtems_status_code status;
611 spw_stats current;
611 spw_stats current;
612
612
613 memset(&current, 0, sizeof(spw_stats));
613 memset(&current, 0, sizeof(spw_stats));
614
614
615 spacewire_get_last_error();
615 spacewire_get_last_error();
616
616
617 // read the current statistics
617 // read the current statistics
618 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
618 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
619
619
620 // clear the counters
620 // clear the counters
621 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
621 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
622
622
623 // typedef struct {
623 // typedef struct {
624 // unsigned int tx_link_err; // NOT IN HK
624 // unsigned int tx_link_err; // NOT IN HK
625 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
625 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
626 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
626 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
627 // unsigned int rx_eep_err;
627 // unsigned int rx_eep_err;
628 // unsigned int rx_truncated;
628 // unsigned int rx_truncated;
629 // unsigned int parity_err;
629 // unsigned int parity_err;
630 // unsigned int escape_err;
630 // unsigned int escape_err;
631 // unsigned int credit_err;
631 // unsigned int credit_err;
632 // unsigned int write_sync_err;
632 // unsigned int write_sync_err;
633 // unsigned int disconnect_err;
633 // unsigned int disconnect_err;
634 // unsigned int early_ep;
634 // unsigned int early_ep;
635 // unsigned int invalid_address;
635 // unsigned int invalid_address;
636 // unsigned int packets_sent;
636 // unsigned int packets_sent;
637 // unsigned int packets_received;
637 // unsigned int packets_received;
638 // } spw_stats;
638 // } spw_stats;
639
639
640 // rx_eep_err
640 // rx_eep_err
641 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
641 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
642 // rx_truncated
642 // rx_truncated
643 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
643 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
644 // parity_err
644 // parity_err
645 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
645 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
646 // escape_err
646 // escape_err
647 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
647 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
648 // credit_err
648 // credit_err
649 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
649 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
650 // write_sync_err
650 // write_sync_err
651 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
651 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
652 // disconnect_err
652 // disconnect_err
653 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
653 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
654 // early_ep
654 // early_ep
655 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
655 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
656 // invalid_address
656 // invalid_address
657 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
657 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
658 // packets_sent
658 // packets_sent
659 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
659 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
660 // packets_received
660 // packets_received
661 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
661 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
662
662
663 }
663 }
664
664
665 void spacewire_get_last_error( void )
665 void spacewire_get_last_error( void )
666 {
666 {
667 static spw_stats previous = {0};
667 static spw_stats previous = {0};
668 spw_stats current;
668 spw_stats current;
669 rtems_status_code status;
669 rtems_status_code status;
670
670
671 unsigned int hk_lfr_last_er_rid;
671 unsigned int hk_lfr_last_er_rid;
672 unsigned char hk_lfr_last_er_code;
672 unsigned char hk_lfr_last_er_code;
673 int coarseTime;
673 int coarseTime;
674 int fineTime;
674 int fineTime;
675 unsigned char update_hk_lfr_last_er;
675 unsigned char update_hk_lfr_last_er;
676
676
677 memset(&current, 0, sizeof(spw_stats));
677 memset(&current, 0, sizeof(spw_stats));
678 hk_lfr_last_er_rid = INIT_CHAR;
678 hk_lfr_last_er_rid = INIT_CHAR;
679 hk_lfr_last_er_code = INIT_CHAR;
679 hk_lfr_last_er_code = INIT_CHAR;
680 update_hk_lfr_last_er = INIT_CHAR;
680 update_hk_lfr_last_er = INIT_CHAR;
681
681
682 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
682 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
683
683
684 // get current time
684 // get current time
685 coarseTime = time_management_regs->coarse_time;
685 coarseTime = time_management_regs->coarse_time;
686 fineTime = time_management_regs->fine_time;
686 fineTime = time_management_regs->fine_time;
687
687
688 // typedef struct {
688 // typedef struct {
689 // unsigned int tx_link_err; // NOT IN HK
689 // unsigned int tx_link_err; // NOT IN HK
690 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
690 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
691 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
691 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
692 // unsigned int rx_eep_err;
692 // unsigned int rx_eep_err;
693 // unsigned int rx_truncated;
693 // unsigned int rx_truncated;
694 // unsigned int parity_err;
694 // unsigned int parity_err;
695 // unsigned int escape_err;
695 // unsigned int escape_err;
696 // unsigned int credit_err;
696 // unsigned int credit_err;
697 // unsigned int write_sync_err;
697 // unsigned int write_sync_err;
698 // unsigned int disconnect_err;
698 // unsigned int disconnect_err;
699 // unsigned int early_ep;
699 // unsigned int early_ep;
700 // unsigned int invalid_address;
700 // unsigned int invalid_address;
701 // unsigned int packets_sent;
701 // unsigned int packets_sent;
702 // unsigned int packets_received;
702 // unsigned int packets_received;
703 // } spw_stats;
703 // } spw_stats;
704
704
705 // tx_link_err *** no code associated to this field
705 // tx_link_err *** no code associated to this field
706 // rx_rmap_header_crc_err *** LE *** in HK
706 // rx_rmap_header_crc_err *** LE *** in HK
707 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
707 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
708 {
708 {
709 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
709 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
710 hk_lfr_last_er_code = CODE_HEADER_CRC;
710 hk_lfr_last_er_code = CODE_HEADER_CRC;
711 update_hk_lfr_last_er = 1;
711 update_hk_lfr_last_er = 1;
712 }
712 }
713 // rx_rmap_data_crc_err *** LE *** NOT IN HK
713 // rx_rmap_data_crc_err *** LE *** NOT IN HK
714 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
714 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
715 {
715 {
716 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
716 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
717 hk_lfr_last_er_code = CODE_DATA_CRC;
717 hk_lfr_last_er_code = CODE_DATA_CRC;
718 update_hk_lfr_last_er = 1;
718 update_hk_lfr_last_er = 1;
719 }
719 }
720 // rx_eep_err
720 // rx_eep_err
721 if (previous.rx_eep_err != current.rx_eep_err)
721 if (previous.rx_eep_err != current.rx_eep_err)
722 {
722 {
723 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
723 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
724 hk_lfr_last_er_code = CODE_EEP;
724 hk_lfr_last_er_code = CODE_EEP;
725 update_hk_lfr_last_er = 1;
725 update_hk_lfr_last_er = 1;
726 }
726 }
727 // rx_truncated
727 // rx_truncated
728 if (previous.rx_truncated != current.rx_truncated)
728 if (previous.rx_truncated != current.rx_truncated)
729 {
729 {
730 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
730 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
731 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
731 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
732 update_hk_lfr_last_er = 1;
732 update_hk_lfr_last_er = 1;
733 }
733 }
734 // parity_err
734 // parity_err
735 if (previous.parity_err != current.parity_err)
735 if (previous.parity_err != current.parity_err)
736 {
736 {
737 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
737 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
738 hk_lfr_last_er_code = CODE_PARITY;
738 hk_lfr_last_er_code = CODE_PARITY;
739 update_hk_lfr_last_er = 1;
739 update_hk_lfr_last_er = 1;
740 }
740 }
741 // escape_err
741 // escape_err
742 if (previous.parity_err != current.parity_err)
742 if (previous.parity_err != current.parity_err)
743 {
743 {
744 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
744 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
745 hk_lfr_last_er_code = CODE_ESCAPE;
745 hk_lfr_last_er_code = CODE_ESCAPE;
746 update_hk_lfr_last_er = 1;
746 update_hk_lfr_last_er = 1;
747 }
747 }
748 // credit_err
748 // credit_err
749 if (previous.credit_err != current.credit_err)
749 if (previous.credit_err != current.credit_err)
750 {
750 {
751 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
751 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
752 hk_lfr_last_er_code = CODE_CREDIT;
752 hk_lfr_last_er_code = CODE_CREDIT;
753 update_hk_lfr_last_er = 1;
753 update_hk_lfr_last_er = 1;
754 }
754 }
755 // write_sync_err
755 // write_sync_err
756 if (previous.write_sync_err != current.write_sync_err)
756 if (previous.write_sync_err != current.write_sync_err)
757 {
757 {
758 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
758 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
759 hk_lfr_last_er_code = CODE_WRITE_SYNC;
759 hk_lfr_last_er_code = CODE_WRITE_SYNC;
760 update_hk_lfr_last_er = 1;
760 update_hk_lfr_last_er = 1;
761 }
761 }
762 // disconnect_err
762 // disconnect_err
763 if (previous.disconnect_err != current.disconnect_err)
763 if (previous.disconnect_err != current.disconnect_err)
764 {
764 {
765 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
765 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
766 hk_lfr_last_er_code = CODE_DISCONNECT;
766 hk_lfr_last_er_code = CODE_DISCONNECT;
767 update_hk_lfr_last_er = 1;
767 update_hk_lfr_last_er = 1;
768 }
768 }
769 // early_ep
769 // early_ep
770 if (previous.early_ep != current.early_ep)
770 if (previous.early_ep != current.early_ep)
771 {
771 {
772 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
772 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
773 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
773 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
774 update_hk_lfr_last_er = 1;
774 update_hk_lfr_last_er = 1;
775 }
775 }
776 // invalid_address
776 // invalid_address
777 if (previous.invalid_address != current.invalid_address)
777 if (previous.invalid_address != current.invalid_address)
778 {
778 {
779 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
779 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
780 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
780 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
781 update_hk_lfr_last_er = 1;
781 update_hk_lfr_last_er = 1;
782 }
782 }
783
783
784 // if a field has changed, update the hk_last_er fields
784 // if a field has changed, update the hk_last_er fields
785 if (update_hk_lfr_last_er == 1)
785 if (update_hk_lfr_last_er == 1)
786 {
786 {
787 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
787 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
788 }
788 }
789
789
790 previous = current;
790 previous = current;
791 }
791 }
792
792
793 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
793 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
794 {
794 {
795 unsigned char *coarseTimePtr;
795 unsigned char *coarseTimePtr;
796 unsigned char *fineTimePtr;
796 unsigned char *fineTimePtr;
797
797
798 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
798 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
799 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
799 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
800
800
801 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
801 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
802 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
802 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
803 housekeeping_packet.hk_lfr_last_er_code = code;
803 housekeeping_packet.hk_lfr_last_er_code = code;
804 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
804 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
805 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
805 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
806 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
806 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
807 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
807 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
808 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
808 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
809 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
809 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
810 }
810 }
811
811
812 void update_hk_with_grspw_stats( void )
812 void update_hk_with_grspw_stats( void )
813 {
813 {
814 //****************************
814 //****************************
815 // DPU_SPACEWIRE_IF_STATISTICS
815 // DPU_SPACEWIRE_IF_STATISTICS
816 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
816 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
817 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
817 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
818 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
818 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
819 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
819 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
820
820
821 //******************************************
821 //******************************************
822 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
822 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
823 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
823 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
824 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
824 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
825 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
825 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
826 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
826 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
827 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
827 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
828
828
829 //*********************************************
829 //*********************************************
830 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
830 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
831 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
831 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
832 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
832 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
833 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
833 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
834 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
834 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
835 }
835 }
836
836
837 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
837 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
838 {
838 {
839 unsigned int *statusRegisterPtr;
839 unsigned int *statusRegisterPtr;
840 unsigned char linkState;
840 unsigned char linkState;
841
841
842 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
842 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
843 linkState =
843 linkState =
844 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
844 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
845
845
846 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
846 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
847
847
848 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
848 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
849 }
849 }
850
850
851 void increase_unsigned_char_counter( unsigned char *counter )
851 void increase_unsigned_char_counter( unsigned char *counter )
852 {
852 {
853 // update the number of valid timecodes that have been received
853 // update the number of valid timecodes that have been received
854 if (*counter == UINT8_MAX)
854 if (*counter == UINT8_MAX)
855 {
855 {
856 *counter = 0;
856 *counter = 0;
857 }
857 }
858 else
858 else
859 {
859 {
860 *counter = *counter + 1;
860 *counter = *counter + 1;
861 }
861 }
862 }
862 }
863
863
864 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
864 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
865 {
865 {
866 /** This function checks the coherency between the incoming timecode and the last valid timecode.
866 /** This function checks the coherency between the incoming timecode and the last valid timecode.
867 *
867 *
868 * @param currentTimecodeCtr is the incoming timecode
868 * @param currentTimecodeCtr is the incoming timecode
869 *
869 *
870 * @return returned codes::
870 * @return returned codes::
871 * - LFR_DEFAULT
871 * - LFR_DEFAULT
872 * - LFR_SUCCESSFUL
872 * - LFR_SUCCESSFUL
873 *
873 *
874 */
874 */
875
875
876 static unsigned char firstTickout = 1;
876 static unsigned char firstTickout = 1;
877 unsigned char ret;
877 unsigned char ret;
878
878
879 ret = LFR_DEFAULT;
879 ret = LFR_DEFAULT;
880
880
881 if (firstTickout == 0)
881 if (firstTickout == 0)
882 {
882 {
883 if (currentTimecodeCtr == 0)
883 if (currentTimecodeCtr == 0)
884 {
884 {
885 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
885 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
886 {
886 {
887 ret = LFR_SUCCESSFUL;
887 ret = LFR_SUCCESSFUL;
888 }
888 }
889 else
889 else
890 {
890 {
891 ret = LFR_DEFAULT;
891 ret = LFR_DEFAULT;
892 }
892 }
893 }
893 }
894 else
894 else
895 {
895 {
896 if (currentTimecodeCtr == (previousTimecodeCtr +1))
896 if (currentTimecodeCtr == (previousTimecodeCtr +1))
897 {
897 {
898 ret = LFR_SUCCESSFUL;
898 ret = LFR_SUCCESSFUL;
899 }
899 }
900 else
900 else
901 {
901 {
902 ret = LFR_DEFAULT;
902 ret = LFR_DEFAULT;
903 }
903 }
904 }
904 }
905 }
905 }
906 else
906 else
907 {
907 {
908 firstTickout = 0;
908 firstTickout = 0;
909 ret = LFR_SUCCESSFUL;
909 ret = LFR_SUCCESSFUL;
910 }
910 }
911
911
912 return ret;
912 return ret;
913 }
913 }
914
914
915 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
915 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
916 {
916 {
917 unsigned int ret;
917 unsigned int ret;
918
918
919 ret = LFR_DEFAULT;
919 ret = LFR_DEFAULT;
920
920
921 if (timecode == internalTime)
921 if (timecode == internalTime)
922 {
922 {
923 ret = LFR_SUCCESSFUL;
923 ret = LFR_SUCCESSFUL;
924 }
924 }
925 else
925 else
926 {
926 {
927 ret = LFR_DEFAULT;
927 ret = LFR_DEFAULT;
928 }
928 }
929
929
930 return ret;
930 return ret;
931 }
931 }
932
932
933 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
933 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
934 {
934 {
935 // a tickout has been emitted, perform actions on the incoming timecode
935 // a tickout has been emitted, perform actions on the incoming timecode
936
936
937 unsigned char incomingTimecode;
937 unsigned char incomingTimecode;
938 unsigned char updateTime;
938 unsigned char updateTime;
939 unsigned char internalTime;
939 unsigned char internalTime;
940 rtems_status_code status;
940 rtems_status_code status;
941
941
942 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
942 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
943 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
943 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
944 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
944 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
945
945
946 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
946 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
947
947
948 // update the number of tickout that have been generated
948 // update the number of tickout that have been generated
949 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
949 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
950
950
951 //**************************
951 //**************************
952 // HK_LFR_TIMECODE_ERRONEOUS
952 // HK_LFR_TIMECODE_ERRONEOUS
953 // MISSING and INVALID are handled by the timecode_timer_routine service routine
953 // MISSING and INVALID are handled by the timecode_timer_routine service routine
954 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
954 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
955 {
955 {
956 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
956 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
957 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
957 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
958 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
958 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
959 }
959 }
960
960
961 //************************
961 //************************
962 // HK_LFR_TIME_TIMECODE_IT
962 // HK_LFR_TIME_TIMECODE_IT
963 // check the coherency between the SpaceWire timecode and the Internal Time
963 // check the coherency between the SpaceWire timecode and the Internal Time
964 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
964 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
965 {
965 {
966 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
966 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
967 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
967 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
968 }
968 }
969
969
970 //********************
970 //********************
971 // HK_LFR_TIMECODE_CTR
971 // HK_LFR_TIMECODE_CTR
972 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
972 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
973 if (oneTcLfrUpdateTimeReceived == 1)
973 if (oneTcLfrUpdateTimeReceived == 1)
974 {
974 {
975 if ( incomingTimecode != updateTime )
975 if ( incomingTimecode != updateTime )
976 {
976 {
977 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
977 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
978 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
978 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
979 }
979 }
980 }
980 }
981
981
982 // launch the timecode timer to detect missing or invalid timecodes
982 // launch the timecode timer to detect missing or invalid timecodes
983 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
983 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
984 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
984 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
985 if (status != RTEMS_SUCCESSFUL)
985 if (status != RTEMS_SUCCESSFUL)
986 {
986 {
987 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
987 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
988 }
988 }
989 }
989 }
990
990
991 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
991 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
992 {
992 {
993 static unsigned char initStep = 1;
993 static unsigned char initStep = 1;
994
994
995 unsigned char currentTimecodeCtr;
995 unsigned char currentTimecodeCtr;
996
996
997 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
997 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
998
998
999 if (initStep == 1)
999 if (initStep == 1)
1000 {
1000 {
1001 if (currentTimecodeCtr == previousTimecodeCtr)
1001 if (currentTimecodeCtr == previousTimecodeCtr)
1002 {
1002 {
1003 //************************
1003 //************************
1004 // HK_LFR_TIMECODE_MISSING
1004 // HK_LFR_TIMECODE_MISSING
1005 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
1005 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
1006 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1006 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1007 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1007 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1008 }
1008 }
1009 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
1009 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
1010 {
1010 {
1011 // the timecode value has changed and the value is valid, this is unexpected because
1011 // the timecode value has changed and the value is valid, this is unexpected because
1012 // the timer should not have fired, the timecode_irq_handler should have been raised
1012 // the timer should not have fired, the timecode_irq_handler should have been raised
1013 }
1013 }
1014 else
1014 else
1015 {
1015 {
1016 //************************
1016 //************************
1017 // HK_LFR_TIMECODE_INVALID
1017 // HK_LFR_TIMECODE_INVALID
1018 // the timecode value has changed and the value is not valid, no tickout has been generated
1018 // the timecode value has changed and the value is not valid, no tickout has been generated
1019 // this is why the timer has fired
1019 // this is why the timer has fired
1020 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
1020 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
1021 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
1021 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
1022 }
1022 }
1023 }
1023 }
1024 else
1024 else
1025 {
1025 {
1026 initStep = 1;
1026 initStep = 1;
1027 //************************
1027 //************************
1028 // HK_LFR_TIMECODE_MISSING
1028 // HK_LFR_TIMECODE_MISSING
1029 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1029 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1030 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1030 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1031 }
1031 }
1032
1032
1033 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1033 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1034 }
1034 }
1035
1035
1036 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1036 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1037 {
1037 {
1038 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1038 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1039 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1039 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1040 header->reserved = DEFAULT_RESERVED;
1040 header->reserved = DEFAULT_RESERVED;
1041 header->userApplication = CCSDS_USER_APP;
1041 header->userApplication = CCSDS_USER_APP;
1042 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1042 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1043 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1043 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1044 header->packetLength[0] = INIT_CHAR;
1044 header->packetLength[0] = INIT_CHAR;
1045 header->packetLength[1] = INIT_CHAR;
1045 header->packetLength[1] = INIT_CHAR;
1046 // DATA FIELD HEADER
1046 // DATA FIELD HEADER
1047 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1047 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1048 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1048 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1049 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1049 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1050 header->destinationID = TM_DESTINATION_ID_GROUND;
1050 header->destinationID = TM_DESTINATION_ID_GROUND;
1051 header->time[BYTE_0] = INIT_CHAR;
1051 header->time[BYTE_0] = INIT_CHAR;
1052 header->time[BYTE_1] = INIT_CHAR;
1052 header->time[BYTE_1] = INIT_CHAR;
1053 header->time[BYTE_2] = INIT_CHAR;
1053 header->time[BYTE_2] = INIT_CHAR;
1054 header->time[BYTE_3] = INIT_CHAR;
1054 header->time[BYTE_3] = INIT_CHAR;
1055 header->time[BYTE_4] = INIT_CHAR;
1055 header->time[BYTE_4] = INIT_CHAR;
1056 header->time[BYTE_5] = INIT_CHAR;
1056 header->time[BYTE_5] = INIT_CHAR;
1057 // AUXILIARY DATA HEADER
1057 // AUXILIARY DATA HEADER
1058 header->sid = INIT_CHAR;
1058 header->sid = INIT_CHAR;
1059 header->pa_bia_status_info = DEFAULT_HKBIA;
1059 header->pa_bia_status_info = DEFAULT_HKBIA;
1060 header->blkNr[0] = INIT_CHAR;
1060 header->blkNr[0] = INIT_CHAR;
1061 header->blkNr[1] = INIT_CHAR;
1061 header->blkNr[1] = INIT_CHAR;
1062 }
1062 }
1063
1063
1064 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1064 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1065 {
1065 {
1066 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1066 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1067 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1067 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1068 header->reserved = DEFAULT_RESERVED;
1068 header->reserved = DEFAULT_RESERVED;
1069 header->userApplication = CCSDS_USER_APP;
1069 header->userApplication = CCSDS_USER_APP;
1070 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1070 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1071 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1071 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1072 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1072 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1073 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1073 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1074 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1074 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1075 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1075 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1076 // DATA FIELD HEADER
1076 // DATA FIELD HEADER
1077 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1077 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1078 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1078 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1079 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1079 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1080 header->destinationID = TM_DESTINATION_ID_GROUND;
1080 header->destinationID = TM_DESTINATION_ID_GROUND;
1081 header->time[BYTE_0] = INIT_CHAR;
1081 header->time[BYTE_0] = INIT_CHAR;
1082 header->time[BYTE_1] = INIT_CHAR;
1082 header->time[BYTE_1] = INIT_CHAR;
1083 header->time[BYTE_2] = INIT_CHAR;
1083 header->time[BYTE_2] = INIT_CHAR;
1084 header->time[BYTE_3] = INIT_CHAR;
1084 header->time[BYTE_3] = INIT_CHAR;
1085 header->time[BYTE_4] = INIT_CHAR;
1085 header->time[BYTE_4] = INIT_CHAR;
1086 header->time[BYTE_5] = INIT_CHAR;
1086 header->time[BYTE_5] = INIT_CHAR;
1087 // AUXILIARY DATA HEADER
1087 // AUXILIARY DATA HEADER
1088 header->sid = INIT_CHAR;
1088 header->sid = INIT_CHAR;
1089 header->pa_bia_status_info = DEFAULT_HKBIA;
1089 header->pa_bia_status_info = DEFAULT_HKBIA;
1090 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1090 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1091 header->pktNr = INIT_CHAR;
1091 header->pktNr = INIT_CHAR;
1092 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1092 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1093 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1093 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1094 }
1094 }
1095
1095
1096 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1096 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1097 {
1097 {
1098 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1098 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1099 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1099 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1100 header->reserved = DEFAULT_RESERVED;
1100 header->reserved = DEFAULT_RESERVED;
1101 header->userApplication = CCSDS_USER_APP;
1101 header->userApplication = CCSDS_USER_APP;
1102 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1102 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1103 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1103 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1104 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1104 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1105 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1105 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1106 header->packetLength[0] = INIT_CHAR;
1106 header->packetLength[0] = INIT_CHAR;
1107 header->packetLength[1] = INIT_CHAR;
1107 header->packetLength[1] = INIT_CHAR;
1108 // DATA FIELD HEADER
1108 // DATA FIELD HEADER
1109 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1109 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1110 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1110 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1111 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1111 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1112 header->destinationID = TM_DESTINATION_ID_GROUND;
1112 header->destinationID = TM_DESTINATION_ID_GROUND;
1113 header->time[BYTE_0] = INIT_CHAR;
1113 header->time[BYTE_0] = INIT_CHAR;
1114 header->time[BYTE_1] = INIT_CHAR;
1114 header->time[BYTE_1] = INIT_CHAR;
1115 header->time[BYTE_2] = INIT_CHAR;
1115 header->time[BYTE_2] = INIT_CHAR;
1116 header->time[BYTE_3] = INIT_CHAR;
1116 header->time[BYTE_3] = INIT_CHAR;
1117 header->time[BYTE_4] = INIT_CHAR;
1117 header->time[BYTE_4] = INIT_CHAR;
1118 header->time[BYTE_5] = INIT_CHAR;
1118 header->time[BYTE_5] = INIT_CHAR;
1119 // AUXILIARY DATA HEADER
1119 // AUXILIARY DATA HEADER
1120 header->sid = INIT_CHAR;
1120 header->sid = INIT_CHAR;
1121 header->pa_bia_status_info = INIT_CHAR;
1121 header->pa_bia_status_info = INIT_CHAR;
1122 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1122 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1123 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1123 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1124 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1124 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1125 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1125 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1126 }
1126 }
1127
1127
1128 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1128 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1129 Header_TM_LFR_SCIENCE_CWF_t *header )
1129 Header_TM_LFR_SCIENCE_CWF_t *header )
1130 {
1130 {
1131 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1131 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1132 *
1132 *
1133 * @param waveform points to the buffer containing the data that will be send.
1133 * @param waveform points to the buffer containing the data that will be send.
1134 * @param sid is the source identifier of the data that will be sent.
1134 * @param sid is the source identifier of the data that will be sent.
1135 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1135 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1136 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1136 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1137 * contain information to setup the transmission of the data packets.
1137 * contain information to setup the transmission of the data packets.
1138 *
1138 *
1139 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1139 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1140 *
1140 *
1141 */
1141 */
1142
1142
1143 unsigned int i;
1143 unsigned int i;
1144 int ret;
1144 int ret;
1145 unsigned int coarseTime;
1145 unsigned int coarseTime;
1146 unsigned int fineTime;
1146 unsigned int fineTime;
1147 rtems_status_code status;
1147 rtems_status_code status;
1148 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1148 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1149 int *dataPtr;
1149 int *dataPtr;
1150 unsigned char sid;
1150 unsigned char sid;
1151
1151
1152 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1152 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1153 spw_ioctl_send_CWF.options = 0;
1153 spw_ioctl_send_CWF.options = 0;
1154
1154
1155 ret = LFR_DEFAULT;
1155 ret = LFR_DEFAULT;
1156 sid = (unsigned char) ring_node_to_send->sid;
1156 sid = (unsigned char) ring_node_to_send->sid;
1157
1157
1158 coarseTime = ring_node_to_send->coarseTime;
1158 coarseTime = ring_node_to_send->coarseTime;
1159 fineTime = ring_node_to_send->fineTime;
1159 fineTime = ring_node_to_send->fineTime;
1160 dataPtr = (int*) ring_node_to_send->buffer_address;
1160 dataPtr = (int*) ring_node_to_send->buffer_address;
1161
1161
1162 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1162 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1163 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1163 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1164 header->pa_bia_status_info = pa_bia_status_info;
1164 header->pa_bia_status_info = pa_bia_status_info;
1165 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1165 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1166 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1166 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1167 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1167 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1168
1168
1169 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1169 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1170 {
1170 {
1171 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1171 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1172 spw_ioctl_send_CWF.hdr = (char*) header;
1172 spw_ioctl_send_CWF.hdr = (char*) header;
1173 // BUILD THE DATA
1173 // BUILD THE DATA
1174 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1174 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1175
1175
1176 // SET PACKET SEQUENCE CONTROL
1176 // SET PACKET SEQUENCE CONTROL
1177 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1177 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1178
1178
1179 // SET SID
1179 // SET SID
1180 header->sid = sid;
1180 header->sid = sid;
1181
1181
1182 // SET PACKET TIME
1182 // SET PACKET TIME
1183 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1183 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1184 //
1184 //
1185 header->time[0] = header->acquisitionTime[0];
1185 header->time[0] = header->acquisitionTime[0];
1186 header->time[1] = header->acquisitionTime[1];
1186 header->time[1] = header->acquisitionTime[1];
1187 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1187 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1188 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1188 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1189 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1189 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1190 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1190 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1191
1191
1192 // SET PACKET ID
1192 // SET PACKET ID
1193 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1193 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1194 {
1194 {
1195 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1195 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1196 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1196 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1197 }
1197 }
1198 else
1198 else
1199 {
1199 {
1200 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1200 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1201 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1201 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1202 }
1202 }
1203
1203
1204 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1204 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1205 if (status != RTEMS_SUCCESSFUL) {
1205 if (status != RTEMS_SUCCESSFUL) {
1206 ret = LFR_DEFAULT;
1206 ret = LFR_DEFAULT;
1207 }
1207 }
1208 }
1208 }
1209
1209
1210 return ret;
1210 return ret;
1211 }
1211 }
1212
1212
1213 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1213 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1214 Header_TM_LFR_SCIENCE_SWF_t *header )
1214 Header_TM_LFR_SCIENCE_SWF_t *header )
1215 {
1215 {
1216 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1216 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1217 *
1217 *
1218 * @param waveform points to the buffer containing the data that will be send.
1218 * @param waveform points to the buffer containing the data that will be send.
1219 * @param sid is the source identifier of the data that will be sent.
1219 * @param sid is the source identifier of the data that will be sent.
1220 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1220 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1221 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1221 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1222 * contain information to setup the transmission of the data packets.
1222 * contain information to setup the transmission of the data packets.
1223 *
1223 *
1224 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1224 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1225 *
1225 *
1226 */
1226 */
1227
1227
1228 unsigned int i;
1228 unsigned int i;
1229 int ret;
1229 int ret;
1230 unsigned int coarseTime;
1230 unsigned int coarseTime;
1231 unsigned int fineTime;
1231 unsigned int fineTime;
1232 rtems_status_code status;
1232 rtems_status_code status;
1233 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1233 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1234 int *dataPtr;
1234 int *dataPtr;
1235 unsigned char sid;
1235 unsigned char sid;
1236
1236
1237 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1237 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1238 spw_ioctl_send_SWF.options = 0;
1238 spw_ioctl_send_SWF.options = 0;
1239
1239
1240 ret = LFR_DEFAULT;
1240 ret = LFR_DEFAULT;
1241
1241
1242 coarseTime = ring_node_to_send->coarseTime;
1242 coarseTime = ring_node_to_send->coarseTime;
1243 fineTime = ring_node_to_send->fineTime;
1243 fineTime = ring_node_to_send->fineTime;
1244 dataPtr = (int*) ring_node_to_send->buffer_address;
1244 dataPtr = (int*) ring_node_to_send->buffer_address;
1245 sid = ring_node_to_send->sid;
1245 sid = ring_node_to_send->sid;
1246
1246
1247 header->pa_bia_status_info = pa_bia_status_info;
1247 header->pa_bia_status_info = pa_bia_status_info;
1248 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1248 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1249
1249
1250 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1250 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1251 {
1251 {
1252 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1252 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1253 spw_ioctl_send_SWF.hdr = (char*) header;
1253 spw_ioctl_send_SWF.hdr = (char*) header;
1254
1254
1255 // SET PACKET SEQUENCE CONTROL
1255 // SET PACKET SEQUENCE CONTROL
1256 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1256 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1257
1257
1258 // SET PACKET LENGTH AND BLKNR
1258 // SET PACKET LENGTH AND BLKNR
1259 if (i == (PKTCNT_SWF-1))
1259 if (i == (PKTCNT_SWF-1))
1260 {
1260 {
1261 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1261 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1262 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1262 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1263 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1263 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1264 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1264 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1265 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1265 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1266 }
1266 }
1267 else
1267 else
1268 {
1268 {
1269 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1269 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1270 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1270 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1271 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1271 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1272 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1272 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1273 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1273 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1274 }
1274 }
1275
1275
1276 // SET PACKET TIME
1276 // SET PACKET TIME
1277 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1277 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1278 //
1278 //
1279 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1279 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1280 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1280 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1281 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1281 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1282 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1282 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1283 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1283 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1284 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1284 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1285
1285
1286 // SET SID
1286 // SET SID
1287 header->sid = sid;
1287 header->sid = sid;
1288
1288
1289 // SET PKTNR
1289 // SET PKTNR
1290 header->pktNr = i+1; // PKT_NR
1290 header->pktNr = i+1; // PKT_NR
1291
1291
1292 // SEND PACKET
1292 // SEND PACKET
1293 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1293 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1294 if (status != RTEMS_SUCCESSFUL) {
1294 if (status != RTEMS_SUCCESSFUL) {
1295 ret = LFR_DEFAULT;
1295 ret = LFR_DEFAULT;
1296 }
1296 }
1297 }
1297 }
1298
1298
1299 return ret;
1299 return ret;
1300 }
1300 }
1301
1301
1302 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1302 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1303 Header_TM_LFR_SCIENCE_CWF_t *header )
1303 Header_TM_LFR_SCIENCE_CWF_t *header )
1304 {
1304 {
1305 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1305 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1306 *
1306 *
1307 * @param waveform points to the buffer containing the data that will be send.
1307 * @param waveform points to the buffer containing the data that will be send.
1308 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1308 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1309 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1309 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1310 * contain information to setup the transmission of the data packets.
1310 * contain information to setup the transmission of the data packets.
1311 *
1311 *
1312 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1312 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1313 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1313 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1314 *
1314 *
1315 */
1315 */
1316
1316
1317 unsigned int i;
1317 unsigned int i;
1318 int ret;
1318 int ret;
1319 unsigned int coarseTime;
1319 unsigned int coarseTime;
1320 unsigned int fineTime;
1320 unsigned int fineTime;
1321 rtems_status_code status;
1321 rtems_status_code status;
1322 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1322 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1323 char *dataPtr;
1323 char *dataPtr;
1324 unsigned char sid;
1324 unsigned char sid;
1325
1325
1326 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1326 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1327 spw_ioctl_send_CWF.options = 0;
1327 spw_ioctl_send_CWF.options = 0;
1328
1328
1329 ret = LFR_DEFAULT;
1329 ret = LFR_DEFAULT;
1330 sid = ring_node_to_send->sid;
1330 sid = ring_node_to_send->sid;
1331
1331
1332 coarseTime = ring_node_to_send->coarseTime;
1332 coarseTime = ring_node_to_send->coarseTime;
1333 fineTime = ring_node_to_send->fineTime;
1333 fineTime = ring_node_to_send->fineTime;
1334 dataPtr = (char*) ring_node_to_send->buffer_address;
1334 dataPtr = (char*) ring_node_to_send->buffer_address;
1335
1335
1336 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1336 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1337 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1337 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1338 header->pa_bia_status_info = pa_bia_status_info;
1338 header->pa_bia_status_info = pa_bia_status_info;
1339 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1339 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1340 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1340 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1341 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1341 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1342
1342
1343 //*********************
1343 //*********************
1344 // SEND CWF3_light DATA
1344 // SEND CWF3_light DATA
1345 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1345 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1346 {
1346 {
1347 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1347 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1348 spw_ioctl_send_CWF.hdr = (char*) header;
1348 spw_ioctl_send_CWF.hdr = (char*) header;
1349 // BUILD THE DATA
1349 // BUILD THE DATA
1350 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1350 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1351
1351
1352 // SET PACKET SEQUENCE COUNTER
1352 // SET PACKET SEQUENCE COUNTER
1353 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1353 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1354
1354
1355 // SET SID
1355 // SET SID
1356 header->sid = sid;
1356 header->sid = sid;
1357
1357
1358 // SET PACKET TIME
1358 // SET PACKET TIME
1359 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1359 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1360 //
1360 //
1361 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1361 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1362 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1362 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1363 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1363 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1364 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1364 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1365 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1365 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1366 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1366 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1367
1367
1368 // SET PACKET ID
1368 // SET PACKET ID
1369 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1369 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1370 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1370 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1371
1371
1372 // SEND PACKET
1372 // SEND PACKET
1373 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1373 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1374 if (status != RTEMS_SUCCESSFUL) {
1374 if (status != RTEMS_SUCCESSFUL) {
1375 ret = LFR_DEFAULT;
1375 ret = LFR_DEFAULT;
1376 }
1376 }
1377 }
1377 }
1378
1378
1379 return ret;
1379 return ret;
1380 }
1380 }
1381
1381
1382 void spw_send_asm_f0( ring_node *ring_node_to_send,
1382 void spw_send_asm_f0( ring_node *ring_node_to_send,
1383 Header_TM_LFR_SCIENCE_ASM_t *header )
1383 Header_TM_LFR_SCIENCE_ASM_t *header )
1384 {
1384 {
1385 unsigned int i;
1385 unsigned int i;
1386 unsigned int length = 0;
1386 unsigned int length = 0;
1387 rtems_status_code status;
1387 rtems_status_code status;
1388 unsigned int sid;
1388 unsigned int sid;
1389 float *spectral_matrix;
1389 float *spectral_matrix;
1390 int coarseTime;
1390 int coarseTime;
1391 int fineTime;
1391 int fineTime;
1392 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1392 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1393
1393
1394 sid = ring_node_to_send->sid;
1394 sid = ring_node_to_send->sid;
1395 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1395 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1396 coarseTime = ring_node_to_send->coarseTime;
1396 coarseTime = ring_node_to_send->coarseTime;
1397 fineTime = ring_node_to_send->fineTime;
1397 fineTime = ring_node_to_send->fineTime;
1398
1398
1399 header->pa_bia_status_info = pa_bia_status_info;
1399 header->pa_bia_status_info = pa_bia_status_info;
1400 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1400 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1401
1401
1402 for (i=0; i<PKTCNT_ASM; i++)
1402 for (i=0; i<PKTCNT_ASM; i++)
1403 {
1403 {
1404 if ((i==0) || (i==1))
1404 if ((i==0) || (i==1))
1405 {
1405 {
1406 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1406 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1407 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1407 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1408 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1408 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1409 ];
1409 ];
1410 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1410 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1411 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1411 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1412 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1412 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1413 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1413 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1414 }
1414 }
1415 else
1415 else
1416 {
1416 {
1417 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1417 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1418 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1418 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1419 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1419 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1420 ];
1420 ];
1421 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1421 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1422 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1422 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1423 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1423 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1424 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1424 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1425 }
1425 }
1426
1426
1427 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1427 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1428 spw_ioctl_send_ASM.hdr = (char *) header;
1428 spw_ioctl_send_ASM.hdr = (char *) header;
1429 spw_ioctl_send_ASM.options = 0;
1429 spw_ioctl_send_ASM.options = 0;
1430
1430
1431 // (2) BUILD THE HEADER
1431 // (2) BUILD THE HEADER
1432 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1432 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1433 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1433 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1434 header->packetLength[1] = (unsigned char) (length);
1434 header->packetLength[1] = (unsigned char) (length);
1435 header->sid = (unsigned char) sid; // SID
1435 header->sid = (unsigned char) sid; // SID
1436 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1436 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1437 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1437 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1438
1438
1439 // (3) SET PACKET TIME
1439 // (3) SET PACKET TIME
1440 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1440 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1441 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1441 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1442 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1442 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1443 header->time[BYTE_3] = (unsigned char) (coarseTime);
1443 header->time[BYTE_3] = (unsigned char) (coarseTime);
1444 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1444 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1445 header->time[BYTE_5] = (unsigned char) (fineTime);
1445 header->time[BYTE_5] = (unsigned char) (fineTime);
1446 //
1446 //
1447 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1447 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1448 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1448 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1449 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1449 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1450 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1450 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1451 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1451 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1452 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1452 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1453
1453
1454 // (4) SEND PACKET
1454 // (4) SEND PACKET
1455 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1455 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1456 if (status != RTEMS_SUCCESSFUL) {
1456 if (status != RTEMS_SUCCESSFUL) {
1457 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1457 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1458 }
1458 }
1459 }
1459 }
1460 }
1460 }
1461
1461
1462 void spw_send_asm_f1( ring_node *ring_node_to_send,
1462 void spw_send_asm_f1( ring_node *ring_node_to_send,
1463 Header_TM_LFR_SCIENCE_ASM_t *header )
1463 Header_TM_LFR_SCIENCE_ASM_t *header )
1464 {
1464 {
1465 unsigned int i;
1465 unsigned int i;
1466 unsigned int length = 0;
1466 unsigned int length = 0;
1467 rtems_status_code status;
1467 rtems_status_code status;
1468 unsigned int sid;
1468 unsigned int sid;
1469 float *spectral_matrix;
1469 float *spectral_matrix;
1470 int coarseTime;
1470 int coarseTime;
1471 int fineTime;
1471 int fineTime;
1472 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1472 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1473
1473
1474 sid = ring_node_to_send->sid;
1474 sid = ring_node_to_send->sid;
1475 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1475 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1476 coarseTime = ring_node_to_send->coarseTime;
1476 coarseTime = ring_node_to_send->coarseTime;
1477 fineTime = ring_node_to_send->fineTime;
1477 fineTime = ring_node_to_send->fineTime;
1478
1478
1479 header->pa_bia_status_info = pa_bia_status_info;
1479 header->pa_bia_status_info = pa_bia_status_info;
1480 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1480 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1481
1481
1482 for (i=0; i<PKTCNT_ASM; i++)
1482 for (i=0; i<PKTCNT_ASM; i++)
1483 {
1483 {
1484 if ((i==0) || (i==1))
1484 if ((i==0) || (i==1))
1485 {
1485 {
1486 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1486 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1487 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1487 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1488 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1488 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1489 ];
1489 ];
1490 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1490 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1491 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1491 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1492 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1492 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1493 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1493 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1494 }
1494 }
1495 else
1495 else
1496 {
1496 {
1497 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1497 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1498 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1498 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1499 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1499 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1500 ];
1500 ];
1501 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1501 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1502 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1502 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1503 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1503 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1504 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1504 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1505 }
1505 }
1506
1506
1507 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1507 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1508 spw_ioctl_send_ASM.hdr = (char *) header;
1508 spw_ioctl_send_ASM.hdr = (char *) header;
1509 spw_ioctl_send_ASM.options = 0;
1509 spw_ioctl_send_ASM.options = 0;
1510
1510
1511 // (2) BUILD THE HEADER
1511 // (2) BUILD THE HEADER
1512 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1512 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1513 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1513 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1514 header->packetLength[1] = (unsigned char) (length);
1514 header->packetLength[1] = (unsigned char) (length);
1515 header->sid = (unsigned char) sid; // SID
1515 header->sid = (unsigned char) sid; // SID
1516 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1516 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1517 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1517 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1518
1518
1519 // (3) SET PACKET TIME
1519 // (3) SET PACKET TIME
1520 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1520 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1521 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1521 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1522 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1522 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1523 header->time[BYTE_3] = (unsigned char) (coarseTime);
1523 header->time[BYTE_3] = (unsigned char) (coarseTime);
1524 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1524 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1525 header->time[BYTE_5] = (unsigned char) (fineTime);
1525 header->time[BYTE_5] = (unsigned char) (fineTime);
1526 //
1526 //
1527 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1527 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1528 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1528 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1529 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1529 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1530 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1530 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1531 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1531 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1532 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1532 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1533
1533
1534 // (4) SEND PACKET
1534 // (4) SEND PACKET
1535 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1535 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1536 if (status != RTEMS_SUCCESSFUL) {
1536 if (status != RTEMS_SUCCESSFUL) {
1537 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1537 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1538 }
1538 }
1539 }
1539 }
1540 }
1540 }
1541
1541
1542 void spw_send_asm_f2( ring_node *ring_node_to_send,
1542 void spw_send_asm_f2( ring_node *ring_node_to_send,
1543 Header_TM_LFR_SCIENCE_ASM_t *header )
1543 Header_TM_LFR_SCIENCE_ASM_t *header )
1544 {
1544 {
1545 unsigned int i;
1545 unsigned int i;
1546 unsigned int length = 0;
1546 unsigned int length = 0;
1547 rtems_status_code status;
1547 rtems_status_code status;
1548 unsigned int sid;
1548 unsigned int sid;
1549 float *spectral_matrix;
1549 float *spectral_matrix;
1550 int coarseTime;
1550 int coarseTime;
1551 int fineTime;
1551 int fineTime;
1552 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1552 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1553
1553
1554 sid = ring_node_to_send->sid;
1554 sid = ring_node_to_send->sid;
1555 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1555 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1556 coarseTime = ring_node_to_send->coarseTime;
1556 coarseTime = ring_node_to_send->coarseTime;
1557 fineTime = ring_node_to_send->fineTime;
1557 fineTime = ring_node_to_send->fineTime;
1558
1558
1559 header->pa_bia_status_info = pa_bia_status_info;
1559 header->pa_bia_status_info = pa_bia_status_info;
1560 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1560 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1561
1561
1562 for (i=0; i<PKTCNT_ASM; i++)
1562 for (i=0; i<PKTCNT_ASM; i++)
1563 {
1563 {
1564
1564
1565 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1565 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1566 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1566 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1567 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1567 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1568 ];
1568 ];
1569 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1569 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1570 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1570 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1571 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1571 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1572 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1572 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1573
1573
1574 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1574 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1575 spw_ioctl_send_ASM.hdr = (char *) header;
1575 spw_ioctl_send_ASM.hdr = (char *) header;
1576 spw_ioctl_send_ASM.options = 0;
1576 spw_ioctl_send_ASM.options = 0;
1577
1577
1578 // (2) BUILD THE HEADER
1578 // (2) BUILD THE HEADER
1579 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1579 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1580 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1580 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1581 header->packetLength[1] = (unsigned char) (length);
1581 header->packetLength[1] = (unsigned char) (length);
1582 header->sid = (unsigned char) sid; // SID
1582 header->sid = (unsigned char) sid; // SID
1583 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1583 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1584 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1584 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1585
1585
1586 // (3) SET PACKET TIME
1586 // (3) SET PACKET TIME
1587 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1587 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1588 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1588 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1589 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1589 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1590 header->time[BYTE_3] = (unsigned char) (coarseTime);
1590 header->time[BYTE_3] = (unsigned char) (coarseTime);
1591 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1591 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1592 header->time[BYTE_5] = (unsigned char) (fineTime);
1592 header->time[BYTE_5] = (unsigned char) (fineTime);
1593 //
1593 //
1594 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1594 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1595 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1595 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1596 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1596 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1597 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1597 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1598 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1598 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1599 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1599 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1600
1600
1601 // (4) SEND PACKET
1601 // (4) SEND PACKET
1602 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1602 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1603 if (status != RTEMS_SUCCESSFUL) {
1603 if (status != RTEMS_SUCCESSFUL) {
1604 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1604 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1605 }
1605 }
1606 }
1606 }
1607 }
1607 }
1608
1608
1609 void spw_send_k_dump( ring_node *ring_node_to_send )
1609 void spw_send_k_dump( ring_node *ring_node_to_send )
1610 {
1610 {
1611 rtems_status_code status;
1611 rtems_status_code status;
1612 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1612 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1613 unsigned int packetLength;
1613 unsigned int packetLength;
1614 unsigned int size;
1614 unsigned int size;
1615
1615
1616 PRINTF("spw_send_k_dump\n")
1616 PRINTF("spw_send_k_dump\n")
1617
1617
1618 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1618 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1619
1619
1620 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1620 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1621
1621
1622 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1622 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1623
1623
1624 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1624 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1625
1625
1626 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1626 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1627
1627
1628 if (status == -1){
1628 if (status == -1){
1629 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1629 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1630 }
1630 }
1631
1631
1632 ring_node_to_send->status = INIT_CHAR;
1632 ring_node_to_send->status = INIT_CHAR;
1633 }
1633 }
@@ -1,423 +1,423
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf0_prc0.h"
10 #include "avf0_prc0.h"
11
11
12 nb_sm_before_bp_asm_f0 nb_sm_before_f0 = {0};
12 nb_sm_before_bp_asm_f0 nb_sm_before_f0 = {0};
13
13
14 //***
14 //***
15 // F0
15 // F0
16 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ] = {0};
16 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ] = {0};
17 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ] = {0};
17 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ] = {0};
18
18
19 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ] = {0};
19 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ] = {0};
20 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ] = {0};
20 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ] = {0};
21
21
22 float asm_f0_patched_norm [ TOTAL_SIZE_SM ] = {0};
22 float asm_f0_patched_norm [ TOTAL_SIZE_SM ] = {0};
23 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
23 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
24 float asm_f0_reorganized [ TOTAL_SIZE_SM ] = {0};
24 float asm_f0_reorganized [ TOTAL_SIZE_SM ] = {0};
25
25
26 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0] = {0};
26 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0] = {0};
27 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ] = {0};
27 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ] = {0};
28
28
29 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 11 * 32 = 352
29 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 11 * 32 = 352
30 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 22 * 32 = 704
30 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 22 * 32 = 704
31
31
32 //************
32 //************
33 // RTEMS TASKS
33 // RTEMS TASKS
34
34
35 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
35 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
36 {
36 {
37 int i;
37 int i;
38
38
39 rtems_event_set event_out;
39 rtems_event_set event_out;
40 rtems_status_code status;
40 rtems_status_code status;
41 rtems_id queue_id_prc0;
41 rtems_id queue_id_prc0;
42 asm_msg msgForPRC;
42 asm_msg msgForPRC;
43 ring_node *nodeForAveraging;
43 ring_node *nodeForAveraging;
44 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
44 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
45 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
45 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
46 ring_node_asm *current_ring_node_asm_norm_f0;
46 ring_node_asm *current_ring_node_asm_norm_f0;
47
47
48 unsigned int nb_norm_bp1;
48 unsigned int nb_norm_bp1;
49 unsigned int nb_norm_bp2;
49 unsigned int nb_norm_bp2;
50 unsigned int nb_norm_asm;
50 unsigned int nb_norm_asm;
51 unsigned int nb_sbm_bp1;
51 unsigned int nb_sbm_bp1;
52 unsigned int nb_sbm_bp2;
52 unsigned int nb_sbm_bp2;
53
53
54 nb_norm_bp1 = 0;
54 nb_norm_bp1 = 0;
55 nb_norm_bp2 = 0;
55 nb_norm_bp2 = 0;
56 nb_norm_asm = 0;
56 nb_norm_asm = 0;
57 nb_sbm_bp1 = 0;
57 nb_sbm_bp1 = 0;
58 nb_sbm_bp2 = 0;
58 nb_sbm_bp2 = 0;
59 event_out = EVENT_SETS_NONE_PENDING;
59 event_out = EVENT_SETS_NONE_PENDING;
60 queue_id_prc0 = RTEMS_ID_NONE;
60 queue_id_prc0 = RTEMS_ID_NONE;
61
61
62 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
62 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
63 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
63 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
64 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
64 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
65 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
65 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
66 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
66 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
67
67
68 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode);
68 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode);
69
69
70 status = get_message_queue_id_prc0( &queue_id_prc0 );
70 status = get_message_queue_id_prc0( &queue_id_prc0 );
71 if (status != RTEMS_SUCCESSFUL)
71 if (status != RTEMS_SUCCESSFUL)
72 {
72 {
73 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
73 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
74 }
74 }
75
75
76 while(1){
76 while(1){
77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
78
78
79 //****************************************
79 //****************************************
80 // initialize the mesage for the MATR task
80 // initialize the mesage for the MATR task
81 msgForPRC.norm = current_ring_node_asm_norm_f0;
81 msgForPRC.norm = current_ring_node_asm_norm_f0;
82 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
82 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
83 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC0 task
83 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC0 task
84 //
84 //
85 //****************************************
85 //****************************************
86
86
87 nodeForAveraging = getRingNodeForAveraging( 0 );
87 nodeForAveraging = getRingNodeForAveraging( 0 );
88
88
89 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
89 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
90 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
90 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
91 {
91 {
92 nodeForAveraging = nodeForAveraging->previous;
92 nodeForAveraging = nodeForAveraging->previous;
93 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
93 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
94 }
94 }
95
95
96 // compute the average and store it in the averaged_sm_f1 buffer
96 // compute the average and store it in the averaged_sm_f1 buffer
97 SM_average( current_ring_node_asm_norm_f0->matrix,
97 SM_average( current_ring_node_asm_norm_f0->matrix,
98 current_ring_node_asm_burst_sbm_f0->matrix,
98 current_ring_node_asm_burst_sbm_f0->matrix,
99 ring_node_tab,
99 ring_node_tab,
100 nb_norm_bp1, nb_sbm_bp1,
100 nb_norm_bp1, nb_sbm_bp1,
101 &msgForPRC, 0 ); // 0 => frequency channel 0
101 &msgForPRC, 0 ); // 0 => frequency channel 0
102
102
103 // update nb_average
103 // update nb_average
104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
109
109
110 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
110 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
111 {
111 {
112 nb_sbm_bp1 = 0;
112 nb_sbm_bp1 = 0;
113 // set another ring for the ASM storage
113 // set another ring for the ASM storage
114 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
114 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
115 if ( lfrCurrentMode == LFR_MODE_BURST )
115 if ( lfrCurrentMode == LFR_MODE_BURST )
116 {
116 {
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
118 }
118 }
119 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
119 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
120 {
120 {
121 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
121 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
122 }
122 }
123 }
123 }
124
124
125 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
125 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
126 {
126 {
127 nb_sbm_bp2 = 0;
127 nb_sbm_bp2 = 0;
128 if ( lfrCurrentMode == LFR_MODE_BURST )
128 if ( lfrCurrentMode == LFR_MODE_BURST )
129 {
129 {
130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
131 }
131 }
132 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
132 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
133 {
133 {
134 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
134 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
135 }
135 }
136 }
136 }
137
137
138 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
138 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
139 {
139 {
140 nb_norm_bp1 = 0;
140 nb_norm_bp1 = 0;
141 // set another ring for the ASM storage
141 // set another ring for the ASM storage
142 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
142 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
145 {
145 {
146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
147 }
147 }
148 }
148 }
149
149
150 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
150 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
151 {
151 {
152 nb_norm_bp2 = 0;
152 nb_norm_bp2 = 0;
153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
155 {
155 {
156 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
156 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
157 }
157 }
158 }
158 }
159
159
160 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
160 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
161 {
161 {
162 nb_norm_asm = 0;
162 nb_norm_asm = 0;
163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
165 {
165 {
166 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
166 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
167 }
167 }
168 }
168 }
169
169
170 //*************************
170 //*************************
171 // send the message to PRC
171 // send the message to PRC
172 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
172 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
173 {
173 {
174 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
174 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
175 }
175 }
176
176
177 if (status != RTEMS_SUCCESSFUL) {
177 if (status != RTEMS_SUCCESSFUL) {
178 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
178 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
179 }
179 }
180 }
180 }
181 }
181 }
182
182
183 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
183 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
184 {
184 {
185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
186 size_t size; // size of the incoming TC packet
186 size_t size; // size of the incoming TC packet
187 asm_msg *incomingMsg;
187 asm_msg *incomingMsg;
188 //
188 //
189 unsigned char sid;
189 unsigned char sid;
190 rtems_status_code status;
190 rtems_status_code status;
191 rtems_id queue_id;
191 rtems_id queue_id;
192 rtems_id queue_id_q_p0;
192 rtems_id queue_id_q_p0;
193 bp_packet_with_spare packet_norm_bp1;
193 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
194 bp_packet packet_norm_bp2;
194 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
195 bp_packet packet_sbm_bp1;
195 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
196 bp_packet packet_sbm_bp2;
196 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
197 ring_node *current_ring_node_to_send_asm_f0;
197 ring_node *current_ring_node_to_send_asm_f0;
198 float nbSMInASMNORM;
198 float nbSMInASMNORM;
199 float nbSMInASMSBM;
199 float nbSMInASMSBM;
200
200
201 size = 0;
201 size = 0;
202 queue_id = RTEMS_ID_NONE;
202 queue_id = RTEMS_ID_NONE;
203 queue_id_q_p0 = RTEMS_ID_NONE;
203 queue_id_q_p0 = RTEMS_ID_NONE;
204 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
204 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
205 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
205 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
206 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
206 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
207 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
207 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
208
208
209 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
209 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
210 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
210 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
211 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
211 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
212
212
213 //*************
213 //*************
214 // NORM headers
214 // NORM headers
215 BP_init_header_with_spare( &packet_norm_bp1,
215 BP_init_header_with_spare( &packet_norm_bp1,
216 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
216 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
217 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
217 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
218 BP_init_header( &packet_norm_bp2,
218 BP_init_header( &packet_norm_bp2,
219 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
219 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
220 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
220 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
221
221
222 //****************************
222 //****************************
223 // BURST SBM1 and SBM2 headers
223 // BURST SBM1 and SBM2 headers
224 if ( lfrRequestedMode == LFR_MODE_BURST )
224 if ( lfrRequestedMode == LFR_MODE_BURST )
225 {
225 {
226 BP_init_header( &packet_sbm_bp1,
226 BP_init_header( &packet_sbm_bp1,
227 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
227 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
228 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
228 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
229 BP_init_header( &packet_sbm_bp2,
229 BP_init_header( &packet_sbm_bp2,
230 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
230 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
231 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
231 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
232 }
232 }
233 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
233 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
234 {
234 {
235 BP_init_header( &packet_sbm_bp1,
235 BP_init_header( &packet_sbm_bp1,
236 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
236 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
237 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
237 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
238 BP_init_header( &packet_sbm_bp2,
238 BP_init_header( &packet_sbm_bp2,
239 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
239 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
240 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
240 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
241 }
241 }
242 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
242 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
243 {
243 {
244 BP_init_header( &packet_sbm_bp1,
244 BP_init_header( &packet_sbm_bp1,
245 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
245 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
246 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
246 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
247 BP_init_header( &packet_sbm_bp2,
247 BP_init_header( &packet_sbm_bp2,
248 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
248 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
249 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
249 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
250 }
250 }
251 else
251 else
252 {
252 {
253 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
253 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
254 }
254 }
255
255
256 status = get_message_queue_id_send( &queue_id );
256 status = get_message_queue_id_send( &queue_id );
257 if (status != RTEMS_SUCCESSFUL)
257 if (status != RTEMS_SUCCESSFUL)
258 {
258 {
259 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
259 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
260 }
260 }
261 status = get_message_queue_id_prc0( &queue_id_q_p0);
261 status = get_message_queue_id_prc0( &queue_id_q_p0);
262 if (status != RTEMS_SUCCESSFUL)
262 if (status != RTEMS_SUCCESSFUL)
263 {
263 {
264 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
264 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
265 }
265 }
266
266
267 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
267 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
268
268
269 while(1){
269 while(1){
270 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
270 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
271 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
271 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
272
272
273 incomingMsg = (asm_msg*) incomingData;
273 incomingMsg = (asm_msg*) incomingData;
274
274
275 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
275 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
276 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
276 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
277
277
278 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
278 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
279 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
279 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
280
280
281 //****************
281 //****************
282 //****************
282 //****************
283 // BURST SBM1 SBM2
283 // BURST SBM1 SBM2
284 //****************
284 //****************
285 //****************
285 //****************
286 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
286 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
287 {
287 {
288 sid = getSID( incomingMsg->event );
288 sid = getSID( incomingMsg->event );
289 // 1) compress the matrix for Basic Parameters calculation
289 // 1) compress the matrix for Basic Parameters calculation
290 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
290 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
291 nbSMInASMSBM,
291 nbSMInASMSBM,
292 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
292 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
293 ASM_F0_INDICE_START, CHANNELF0);
293 ASM_F0_INDICE_START, CHANNELF0);
294 // 2) compute the BP1 set
294 // 2) compute the BP1 set
295 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
295 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
296 // 3) send the BP1 set
296 // 3) send the BP1 set
297 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
297 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
298 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
298 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
299 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
299 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
300 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
300 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
301 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
301 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
302 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
302 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
303 sid);
303 sid);
304 // 4) compute the BP2 set if needed
304 // 4) compute the BP2 set if needed
305 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
305 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
306 {
306 {
307 // 1) compute the BP2 set
307 // 1) compute the BP2 set
308 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
308 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
309 // 2) send the BP2 set
309 // 2) send the BP2 set
310 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
310 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
311 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
311 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
312 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
312 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
313 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
313 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
314 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
314 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
315 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
315 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
316 sid);
316 sid);
317 }
317 }
318 }
318 }
319
319
320 //*****
320 //*****
321 //*****
321 //*****
322 // NORM
322 // NORM
323 //*****
323 //*****
324 //*****
324 //*****
325 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
325 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
326 {
326 {
327 // 1) compress the matrix for Basic Parameters calculation
327 // 1) compress the matrix for Basic Parameters calculation
328 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
328 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
329 nbSMInASMNORM,
329 nbSMInASMNORM,
330 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
330 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
331 ASM_F0_INDICE_START, CHANNELF0 );
331 ASM_F0_INDICE_START, CHANNELF0 );
332 // 2) compute the BP1 set
332 // 2) compute the BP1 set
333 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
333 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
334 // 3) send the BP1 set
334 // 3) send the BP1 set
335 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
335 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
336 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
336 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
337 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
337 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
338 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
338 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
339 BP_send( (char *) &packet_norm_bp1, queue_id,
339 BP_send( (char *) &packet_norm_bp1, queue_id,
340 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
340 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
341 SID_NORM_BP1_F0 );
341 SID_NORM_BP1_F0 );
342 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
342 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
343 {
343 {
344 // 1) compute the BP2 set using the same ASM as the one used for BP1
344 // 1) compute the BP2 set using the same ASM as the one used for BP1
345 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
345 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
346 // 2) send the BP2 set
346 // 2) send the BP2 set
347 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
347 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
348 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
348 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
349 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
349 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
350 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
350 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
351 BP_send( (char *) &packet_norm_bp2, queue_id,
351 BP_send( (char *) &packet_norm_bp2, queue_id,
352 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
352 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
353 SID_NORM_BP2_F0);
353 SID_NORM_BP2_F0);
354 }
354 }
355 }
355 }
356
356
357 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
357 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
358 {
358 {
359 // 1) reorganize the ASM and divide
359 // 1) reorganize the ASM and divide
360 ASM_reorganize_and_divide( asm_f0_patched_norm,
360 ASM_reorganize_and_divide( asm_f0_patched_norm,
361 (float*) current_ring_node_to_send_asm_f0->buffer_address,
361 (float*) current_ring_node_to_send_asm_f0->buffer_address,
362 nbSMInASMNORM );
362 nbSMInASMNORM );
363 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
363 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
364 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
364 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
365 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
365 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
366
366
367 // 3) send the spectral matrix packets
367 // 3) send the spectral matrix packets
368 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
368 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
369
369
370 // change asm ring node
370 // change asm ring node
371 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
371 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
372 }
372 }
373
373
374 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
374 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
375
375
376 }
376 }
377 }
377 }
378
378
379 //**********
379 //**********
380 // FUNCTIONS
380 // FUNCTIONS
381
381
382 void reset_nb_sm_f0( unsigned char lfrMode )
382 void reset_nb_sm_f0( unsigned char lfrMode )
383 {
383 {
384 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F0;
384 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F0;
385 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F0;
385 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F0;
386 nb_sm_before_f0.norm_asm =
386 nb_sm_before_f0.norm_asm =
387 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F0;
387 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F0;
388 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * NB_SM_PER_S1_BP_P0; // 0.25 s per digit
388 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * NB_SM_PER_S1_BP_P0; // 0.25 s per digit
389 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * NB_SM_PER_S_F0;
389 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * NB_SM_PER_S_F0;
390 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F0;
390 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F0;
391 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F0;
391 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F0;
392 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F0;
392 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F0;
393 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F0;
393 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F0;
394
394
395 if (lfrMode == LFR_MODE_SBM1)
395 if (lfrMode == LFR_MODE_SBM1)
396 {
396 {
397 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
397 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
398 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
398 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
399 }
399 }
400 else if (lfrMode == LFR_MODE_SBM2)
400 else if (lfrMode == LFR_MODE_SBM2)
401 {
401 {
402 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
402 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
403 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
403 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
404 }
404 }
405 else if (lfrMode == LFR_MODE_BURST)
405 else if (lfrMode == LFR_MODE_BURST)
406 {
406 {
407 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
407 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
408 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
408 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
409 }
409 }
410 else
410 else
411 {
411 {
412 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
412 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
413 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
413 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
414 }
414 }
415 }
415 }
416
416
417 void init_k_coefficients_prc0( void )
417 void init_k_coefficients_prc0( void )
418 {
418 {
419 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
419 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
420
420
421 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
421 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
422 }
422 }
423
423
@@ -1,407 +1,407
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf1_prc1.h"
10 #include "avf1_prc1.h"
11
11
12 nb_sm_before_bp_asm_f1 nb_sm_before_f1 = {0};
12 nb_sm_before_bp_asm_f1 nb_sm_before_f1 = {0};
13
13
14 //***
14 //***
15 // F1
15 // F1
16 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ] = {0};
16 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ] = {0};
17 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ] = {0};
17 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ] = {0};
18
18
19 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ] = {0};
19 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ] = {0};
20 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ] = {0};
20 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ] = {0};
21
21
22 float asm_f1_patched_norm [ TOTAL_SIZE_SM ] = {0};
22 float asm_f1_patched_norm [ TOTAL_SIZE_SM ] = {0};
23 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
23 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
24 float asm_f1_reorganized [ TOTAL_SIZE_SM ] = {0};
24 float asm_f1_reorganized [ TOTAL_SIZE_SM ] = {0};
25
25
26 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1] = {0};
26 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1] = {0};
27 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ] = {0};
27 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ] = {0};
28
28
29 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 13 * 32 = 416
29 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 13 * 32 = 416
30 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 26 * 32 = 832
30 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 26 * 32 = 832
31
31
32 //************
32 //************
33 // RTEMS TASKS
33 // RTEMS TASKS
34
34
35 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
35 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
36 {
36 {
37 int i;
37 int i;
38
38
39 rtems_event_set event_out;
39 rtems_event_set event_out;
40 rtems_status_code status;
40 rtems_status_code status;
41 rtems_id queue_id_prc1;
41 rtems_id queue_id_prc1;
42 asm_msg msgForPRC;
42 asm_msg msgForPRC;
43 ring_node *nodeForAveraging;
43 ring_node *nodeForAveraging;
44 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
44 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
45 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
45 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
46 ring_node_asm *current_ring_node_asm_norm_f1;
46 ring_node_asm *current_ring_node_asm_norm_f1;
47
47
48 unsigned int nb_norm_bp1;
48 unsigned int nb_norm_bp1;
49 unsigned int nb_norm_bp2;
49 unsigned int nb_norm_bp2;
50 unsigned int nb_norm_asm;
50 unsigned int nb_norm_asm;
51 unsigned int nb_sbm_bp1;
51 unsigned int nb_sbm_bp1;
52 unsigned int nb_sbm_bp2;
52 unsigned int nb_sbm_bp2;
53
53
54 event_out = EVENT_SETS_NONE_PENDING;
54 event_out = EVENT_SETS_NONE_PENDING;
55 queue_id_prc1 = RTEMS_ID_NONE;
55 queue_id_prc1 = RTEMS_ID_NONE;
56
56
57 nb_norm_bp1 = 0;
57 nb_norm_bp1 = 0;
58 nb_norm_bp2 = 0;
58 nb_norm_bp2 = 0;
59 nb_norm_asm = 0;
59 nb_norm_asm = 0;
60 nb_sbm_bp1 = 0;
60 nb_sbm_bp1 = 0;
61 nb_sbm_bp2 = 0;
61 nb_sbm_bp2 = 0;
62
62
63 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
63 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
64 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
64 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
65 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
65 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
66 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
66 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
67 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
67 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
68
68
69 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
69 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
70
70
71 status = get_message_queue_id_prc1( &queue_id_prc1 );
71 status = get_message_queue_id_prc1( &queue_id_prc1 );
72 if (status != RTEMS_SUCCESSFUL)
72 if (status != RTEMS_SUCCESSFUL)
73 {
73 {
74 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
74 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
75 }
75 }
76
76
77 while(1){
77 while(1){
78 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
78 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
79
79
80 //****************************************
80 //****************************************
81 // initialize the mesage for the MATR task
81 // initialize the mesage for the MATR task
82 msgForPRC.norm = current_ring_node_asm_norm_f1;
82 msgForPRC.norm = current_ring_node_asm_norm_f1;
83 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
83 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
84 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC1 task
84 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC1 task
85 //
85 //
86 //****************************************
86 //****************************************
87
87
88 nodeForAveraging = getRingNodeForAveraging( 1 );
88 nodeForAveraging = getRingNodeForAveraging( 1 );
89
89
90 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
90 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
91 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
91 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
92 {
92 {
93 nodeForAveraging = nodeForAveraging->previous;
93 nodeForAveraging = nodeForAveraging->previous;
94 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
94 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
95 }
95 }
96
96
97 // compute the average and store it in the averaged_sm_f1 buffer
97 // compute the average and store it in the averaged_sm_f1 buffer
98 SM_average( current_ring_node_asm_norm_f1->matrix,
98 SM_average( current_ring_node_asm_norm_f1->matrix,
99 current_ring_node_asm_burst_sbm_f1->matrix,
99 current_ring_node_asm_burst_sbm_f1->matrix,
100 ring_node_tab,
100 ring_node_tab,
101 nb_norm_bp1, nb_sbm_bp1,
101 nb_norm_bp1, nb_sbm_bp1,
102 &msgForPRC, 1 ); // 1 => frequency channel 1
102 &msgForPRC, 1 ); // 1 => frequency channel 1
103
103
104 // update nb_average
104 // update nb_average
105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
107 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
107 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
109 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
109 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
110
110
111 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
111 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
112 {
112 {
113 nb_sbm_bp1 = 0;
113 nb_sbm_bp1 = 0;
114 // set another ring for the ASM storage
114 // set another ring for the ASM storage
115 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
115 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
116 if ( lfrCurrentMode == LFR_MODE_BURST )
116 if ( lfrCurrentMode == LFR_MODE_BURST )
117 {
117 {
118 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
118 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
119 }
119 }
120 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
120 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
121 {
121 {
122 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
122 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
123 }
123 }
124 }
124 }
125
125
126 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
126 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
127 {
127 {
128 nb_sbm_bp2 = 0;
128 nb_sbm_bp2 = 0;
129 if ( lfrCurrentMode == LFR_MODE_BURST )
129 if ( lfrCurrentMode == LFR_MODE_BURST )
130 {
130 {
131 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
131 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
132 }
132 }
133 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
133 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
134 {
134 {
135 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
135 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
136 }
136 }
137 }
137 }
138
138
139 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
139 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
140 {
140 {
141 nb_norm_bp1 = 0;
141 nb_norm_bp1 = 0;
142 // set another ring for the ASM storage
142 // set another ring for the ASM storage
143 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
143 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
146 {
146 {
147 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
147 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
148 }
148 }
149 }
149 }
150
150
151 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
151 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
152 {
152 {
153 nb_norm_bp2 = 0;
153 nb_norm_bp2 = 0;
154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
156 {
156 {
157 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
157 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
158 }
158 }
159 }
159 }
160
160
161 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
161 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
162 {
162 {
163 nb_norm_asm = 0;
163 nb_norm_asm = 0;
164 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
164 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
165 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
165 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
166 {
166 {
167 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
167 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
168 }
168 }
169 }
169 }
170
170
171 //*************************
171 //*************************
172 // send the message to PRC
172 // send the message to PRC
173 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
173 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
174 {
174 {
175 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
175 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
176 }
176 }
177
177
178 if (status != RTEMS_SUCCESSFUL) {
178 if (status != RTEMS_SUCCESSFUL) {
179 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
179 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
180 }
180 }
181 }
181 }
182 }
182 }
183
183
184 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
184 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
185 {
185 {
186 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
186 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
187 size_t size; // size of the incoming TC packet
187 size_t size; // size of the incoming TC packet
188 asm_msg *incomingMsg;
188 asm_msg *incomingMsg;
189 //
189 //
190 unsigned char sid;
190 unsigned char sid;
191 rtems_status_code status;
191 rtems_status_code status;
192 rtems_id queue_id_send;
192 rtems_id queue_id_send;
193 rtems_id queue_id_q_p1;
193 rtems_id queue_id_q_p1;
194 bp_packet_with_spare packet_norm_bp1;
194 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
195 bp_packet packet_norm_bp2;
195 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
196 bp_packet packet_sbm_bp1;
196 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
197 bp_packet packet_sbm_bp2;
197 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
198 ring_node *current_ring_node_to_send_asm_f1;
198 ring_node *current_ring_node_to_send_asm_f1;
199 float nbSMInASMNORM;
199 float nbSMInASMNORM;
200 float nbSMInASMSBM;
200 float nbSMInASMSBM;
201
201
202 size = 0;
202 size = 0;
203 queue_id_send = RTEMS_ID_NONE;
203 queue_id_send = RTEMS_ID_NONE;
204 queue_id_q_p1 = RTEMS_ID_NONE;
204 queue_id_q_p1 = RTEMS_ID_NONE;
205 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
205 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
206 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
206 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
207 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
207 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
208 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
208 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
209
209
210 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
210 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
211 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
211 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
212 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
212 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
213
213
214 //*************
214 //*************
215 // NORM headers
215 // NORM headers
216 BP_init_header_with_spare( &packet_norm_bp1,
216 BP_init_header_with_spare( &packet_norm_bp1,
217 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
217 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
218 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
218 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
219 BP_init_header( &packet_norm_bp2,
219 BP_init_header( &packet_norm_bp2,
220 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
220 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
221 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
221 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
222
222
223 //***********************
223 //***********************
224 // BURST and SBM2 headers
224 // BURST and SBM2 headers
225 if ( lfrRequestedMode == LFR_MODE_BURST )
225 if ( lfrRequestedMode == LFR_MODE_BURST )
226 {
226 {
227 BP_init_header( &packet_sbm_bp1,
227 BP_init_header( &packet_sbm_bp1,
228 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
228 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
229 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
229 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
230 BP_init_header( &packet_sbm_bp2,
230 BP_init_header( &packet_sbm_bp2,
231 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
231 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
232 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
232 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
233 }
233 }
234 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
234 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
235 {
235 {
236 BP_init_header( &packet_sbm_bp1,
236 BP_init_header( &packet_sbm_bp1,
237 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
237 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
238 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
238 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
239 BP_init_header( &packet_sbm_bp2,
239 BP_init_header( &packet_sbm_bp2,
240 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
240 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
241 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
241 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
242 }
242 }
243 else
243 else
244 {
244 {
245 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
245 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
246 }
246 }
247
247
248 status = get_message_queue_id_send( &queue_id_send );
248 status = get_message_queue_id_send( &queue_id_send );
249 if (status != RTEMS_SUCCESSFUL)
249 if (status != RTEMS_SUCCESSFUL)
250 {
250 {
251 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
251 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
252 }
252 }
253 status = get_message_queue_id_prc1( &queue_id_q_p1);
253 status = get_message_queue_id_prc1( &queue_id_q_p1);
254 if (status != RTEMS_SUCCESSFUL)
254 if (status != RTEMS_SUCCESSFUL)
255 {
255 {
256 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
256 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
257 }
257 }
258
258
259 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
259 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
260
260
261 while(1){
261 while(1){
262 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
262 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
263 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
263 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
264
264
265 incomingMsg = (asm_msg*) incomingData;
265 incomingMsg = (asm_msg*) incomingData;
266
266
267 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
267 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
268 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
268 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
269
269
270 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
270 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
271 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
271 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
272
272
273 //***********
273 //***********
274 //***********
274 //***********
275 // BURST SBM2
275 // BURST SBM2
276 //***********
276 //***********
277 //***********
277 //***********
278 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
278 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
279 {
279 {
280 sid = getSID( incomingMsg->event );
280 sid = getSID( incomingMsg->event );
281 // 1) compress the matrix for Basic Parameters calculation
281 // 1) compress the matrix for Basic Parameters calculation
282 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
282 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
283 nbSMInASMSBM,
283 nbSMInASMSBM,
284 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
284 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
285 ASM_F1_INDICE_START, CHANNELF1);
285 ASM_F1_INDICE_START, CHANNELF1);
286 // 2) compute the BP1 set
286 // 2) compute the BP1 set
287 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
287 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
288 // 3) send the BP1 set
288 // 3) send the BP1 set
289 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
289 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
290 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
290 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
291 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
291 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
292 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
292 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
293 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
293 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
294 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
294 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
295 sid );
295 sid );
296 // 4) compute the BP2 set if needed
296 // 4) compute the BP2 set if needed
297 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
297 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
298 {
298 {
299 // 1) compute the BP2 set
299 // 1) compute the BP2 set
300 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
300 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
301 // 2) send the BP2 set
301 // 2) send the BP2 set
302 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
302 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
303 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
303 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
304 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
304 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
305 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
305 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
306 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
306 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
307 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
307 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
308 sid );
308 sid );
309 }
309 }
310 }
310 }
311
311
312 //*****
312 //*****
313 //*****
313 //*****
314 // NORM
314 // NORM
315 //*****
315 //*****
316 //*****
316 //*****
317 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
317 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
318 {
318 {
319 // 1) compress the matrix for Basic Parameters calculation
319 // 1) compress the matrix for Basic Parameters calculation
320 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
320 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
321 nbSMInASMNORM,
321 nbSMInASMNORM,
322 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
322 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
323 ASM_F1_INDICE_START, CHANNELF1 );
323 ASM_F1_INDICE_START, CHANNELF1 );
324 // 2) compute the BP1 set
324 // 2) compute the BP1 set
325 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
325 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
326 // 3) send the BP1 set
326 // 3) send the BP1 set
327 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
327 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
328 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
328 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
329 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
329 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
330 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
330 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
331 BP_send( (char *) &packet_norm_bp1, queue_id_send,
331 BP_send( (char *) &packet_norm_bp1, queue_id_send,
332 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
332 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
333 SID_NORM_BP1_F1 );
333 SID_NORM_BP1_F1 );
334 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
334 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
335 {
335 {
336 // 1) compute the BP2 set
336 // 1) compute the BP2 set
337 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
337 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
338 // 2) send the BP2 set
338 // 2) send the BP2 set
339 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
339 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
340 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
340 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
341 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
341 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
342 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
342 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
343 BP_send( (char *) &packet_norm_bp2, queue_id_send,
343 BP_send( (char *) &packet_norm_bp2, queue_id_send,
344 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
344 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
345 SID_NORM_BP2_F1 );
345 SID_NORM_BP2_F1 );
346 }
346 }
347 }
347 }
348
348
349 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
349 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
350 {
350 {
351 // 1) reorganize the ASM and divide
351 // 1) reorganize the ASM and divide
352 ASM_reorganize_and_divide( asm_f1_patched_norm,
352 ASM_reorganize_and_divide( asm_f1_patched_norm,
353 (float*) current_ring_node_to_send_asm_f1->buffer_address,
353 (float*) current_ring_node_to_send_asm_f1->buffer_address,
354 nbSMInASMNORM );
354 nbSMInASMNORM );
355 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
355 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
356 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
356 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
357 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
357 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
358
358
359 // 3) send the spectral matrix packets
359 // 3) send the spectral matrix packets
360 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
360 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
361
361
362 // change asm ring node
362 // change asm ring node
363 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
363 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
364 }
364 }
365
365
366 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
366 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
367
367
368 }
368 }
369 }
369 }
370
370
371 //**********
371 //**********
372 // FUNCTIONS
372 // FUNCTIONS
373
373
374 void reset_nb_sm_f1( unsigned char lfrMode )
374 void reset_nb_sm_f1( unsigned char lfrMode )
375 {
375 {
376 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F1;
376 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F1;
377 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F1;
377 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F1;
378 nb_sm_before_f1.norm_asm =
378 nb_sm_before_f1.norm_asm =
379 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F1;
379 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F1;
380 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F1;
380 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F1;
381 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F1;
381 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F1;
382 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F1;
382 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F1;
383 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F1;
383 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F1;
384
384
385 if (lfrMode == LFR_MODE_SBM2)
385 if (lfrMode == LFR_MODE_SBM2)
386 {
386 {
387 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
387 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
388 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
388 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
389 }
389 }
390 else if (lfrMode == LFR_MODE_BURST)
390 else if (lfrMode == LFR_MODE_BURST)
391 {
391 {
392 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
392 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
393 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
393 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
394 }
394 }
395 else
395 else
396 {
396 {
397 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
397 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
398 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
398 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
399 }
399 }
400 }
400 }
401
401
402 void init_k_coefficients_prc1( void )
402 void init_k_coefficients_prc1( void )
403 {
403 {
404 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
404 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
405
405
406 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
406 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
407 }
407 }
@@ -1,332 +1,332
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf2_prc2.h"
10 #include "avf2_prc2.h"
11
11
12 nb_sm_before_bp_asm_f2 nb_sm_before_f2 = {0};
12 nb_sm_before_bp_asm_f2 nb_sm_before_f2 = {0};
13
13
14 //***
14 //***
15 // F2
15 // F2
16 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ] = {0};
16 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ] = {0};
17
17
18 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ] = {0};
18 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ] = {0};
19 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ] = {0};
19 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ] = {0};
20
20
21 float asm_f2_patched_norm [ TOTAL_SIZE_SM ] = {0};
21 float asm_f2_patched_norm [ TOTAL_SIZE_SM ] = {0};
22 float asm_f2_reorganized [ TOTAL_SIZE_SM ] = {0};
22 float asm_f2_reorganized [ TOTAL_SIZE_SM ] = {0};
23
23
24 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2] = {0};
24 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2] = {0};
25
25
26 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ] = {0}; // 12 * 32 = 384
26 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ] = {0}; // 12 * 32 = 384
27
27
28 //************
28 //************
29 // RTEMS TASKS
29 // RTEMS TASKS
30
30
31 //***
31 //***
32 // F2
32 // F2
33 rtems_task avf2_task( rtems_task_argument argument )
33 rtems_task avf2_task( rtems_task_argument argument )
34 {
34 {
35 rtems_event_set event_out;
35 rtems_event_set event_out;
36 rtems_status_code status;
36 rtems_status_code status;
37 rtems_id queue_id_prc2;
37 rtems_id queue_id_prc2;
38 asm_msg msgForPRC;
38 asm_msg msgForPRC;
39 ring_node *nodeForAveraging;
39 ring_node *nodeForAveraging;
40 ring_node_asm *current_ring_node_asm_norm_f2;
40 ring_node_asm *current_ring_node_asm_norm_f2;
41
41
42 unsigned int nb_norm_bp1;
42 unsigned int nb_norm_bp1;
43 unsigned int nb_norm_bp2;
43 unsigned int nb_norm_bp2;
44 unsigned int nb_norm_asm;
44 unsigned int nb_norm_asm;
45
45
46 event_out = EVENT_SETS_NONE_PENDING;
46 event_out = EVENT_SETS_NONE_PENDING;
47 queue_id_prc2 = RTEMS_ID_NONE;
47 queue_id_prc2 = RTEMS_ID_NONE;
48 nb_norm_bp1 = 0;
48 nb_norm_bp1 = 0;
49 nb_norm_bp2 = 0;
49 nb_norm_bp2 = 0;
50 nb_norm_asm = 0;
50 nb_norm_asm = 0;
51
51
52 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
52 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
53 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
53 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
54 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
54 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
55
55
56 BOOT_PRINTF("in AVF2 ***\n")
56 BOOT_PRINTF("in AVF2 ***\n")
57
57
58 status = get_message_queue_id_prc2( &queue_id_prc2 );
58 status = get_message_queue_id_prc2( &queue_id_prc2 );
59 if (status != RTEMS_SUCCESSFUL)
59 if (status != RTEMS_SUCCESSFUL)
60 {
60 {
61 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
61 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
62 }
62 }
63
63
64 while(1){
64 while(1){
65 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
65 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
66
66
67 //****************************************
67 //****************************************
68 // initialize the mesage for the MATR task
68 // initialize the mesage for the MATR task
69 msgForPRC.norm = current_ring_node_asm_norm_f2;
69 msgForPRC.norm = current_ring_node_asm_norm_f2;
70 msgForPRC.burst_sbm = NULL;
70 msgForPRC.burst_sbm = NULL;
71 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task
71 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task
72 //
72 //
73 //****************************************
73 //****************************************
74
74
75 nodeForAveraging = getRingNodeForAveraging( CHANNELF2 );
75 nodeForAveraging = getRingNodeForAveraging( CHANNELF2 );
76
76
77 // compute the average and store it in the averaged_sm_f2 buffer
77 // compute the average and store it in the averaged_sm_f2 buffer
78 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
78 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
79 nodeForAveraging,
79 nodeForAveraging,
80 nb_norm_bp1,
80 nb_norm_bp1,
81 &msgForPRC );
81 &msgForPRC );
82
82
83 // update nb_average
83 // update nb_average
84 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
84 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
85 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
85 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
86 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
86 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
87
87
88 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
88 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
89 {
89 {
90 nb_norm_bp1 = 0;
90 nb_norm_bp1 = 0;
91 // set another ring for the ASM storage
91 // set another ring for the ASM storage
92 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
92 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
93 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
93 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
94 || (lfrCurrentMode == LFR_MODE_SBM2) )
94 || (lfrCurrentMode == LFR_MODE_SBM2) )
95 {
95 {
96 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
96 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
97 }
97 }
98 }
98 }
99
99
100 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
100 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
101 {
101 {
102 nb_norm_bp2 = 0;
102 nb_norm_bp2 = 0;
103 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
103 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
104 || (lfrCurrentMode == LFR_MODE_SBM2) )
104 || (lfrCurrentMode == LFR_MODE_SBM2) )
105 {
105 {
106 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
106 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
107 }
107 }
108 }
108 }
109
109
110 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
110 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
111 {
111 {
112 nb_norm_asm = 0;
112 nb_norm_asm = 0;
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
114 || (lfrCurrentMode == LFR_MODE_SBM2) )
114 || (lfrCurrentMode == LFR_MODE_SBM2) )
115 {
115 {
116 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
116 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
117 }
117 }
118 }
118 }
119
119
120 //*************************
120 //*************************
121 // send the message to PRC2
121 // send the message to PRC2
122 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
122 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
123 {
123 {
124 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
124 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
125 }
125 }
126
126
127 if (status != RTEMS_SUCCESSFUL) {
127 if (status != RTEMS_SUCCESSFUL) {
128 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
128 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
129 }
129 }
130 }
130 }
131 }
131 }
132
132
133 rtems_task prc2_task( rtems_task_argument argument )
133 rtems_task prc2_task( rtems_task_argument argument )
134 {
134 {
135 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
135 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
136 size_t size; // size of the incoming TC packet
136 size_t size; // size of the incoming TC packet
137 asm_msg *incomingMsg;
137 asm_msg *incomingMsg;
138 //
138 //
139 rtems_status_code status;
139 rtems_status_code status;
140 rtems_id queue_id_send;
140 rtems_id queue_id_send;
141 rtems_id queue_id_q_p2;
141 rtems_id queue_id_q_p2;
142 bp_packet packet_norm_bp1;
142 bp_packet __attribute__((aligned(4))) packet_norm_bp1;
143 bp_packet packet_norm_bp2;
143 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
144 ring_node *current_ring_node_to_send_asm_f2;
144 ring_node *current_ring_node_to_send_asm_f2;
145 float nbSMInASMNORM;
145 float nbSMInASMNORM;
146
146
147 unsigned long long int localTime;
147 unsigned long long int localTime;
148
148
149 size = 0;
149 size = 0;
150 queue_id_send = RTEMS_ID_NONE;
150 queue_id_send = RTEMS_ID_NONE;
151 queue_id_q_p2 = RTEMS_ID_NONE;
151 queue_id_q_p2 = RTEMS_ID_NONE;
152 memset( &packet_norm_bp1, 0, sizeof(bp_packet) );
152 memset( &packet_norm_bp1, 0, sizeof(bp_packet) );
153 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
153 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
154
154
155 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
155 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
156 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
156 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
157 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
157 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
158
158
159 //*************
159 //*************
160 // NORM headers
160 // NORM headers
161 BP_init_header( &packet_norm_bp1,
161 BP_init_header( &packet_norm_bp1,
162 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
162 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
163 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
163 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
164 BP_init_header( &packet_norm_bp2,
164 BP_init_header( &packet_norm_bp2,
165 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
165 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
166 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
166 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
167
167
168 status = get_message_queue_id_send( &queue_id_send );
168 status = get_message_queue_id_send( &queue_id_send );
169 if (status != RTEMS_SUCCESSFUL)
169 if (status != RTEMS_SUCCESSFUL)
170 {
170 {
171 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
171 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
172 }
172 }
173 status = get_message_queue_id_prc2( &queue_id_q_p2);
173 status = get_message_queue_id_prc2( &queue_id_q_p2);
174 if (status != RTEMS_SUCCESSFUL)
174 if (status != RTEMS_SUCCESSFUL)
175 {
175 {
176 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
176 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
177 }
177 }
178
178
179 BOOT_PRINTF("in PRC2 ***\n")
179 BOOT_PRINTF("in PRC2 ***\n")
180
180
181 while(1){
181 while(1){
182 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
182 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
183 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
183 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
184
184
185 incomingMsg = (asm_msg*) incomingData;
185 incomingMsg = (asm_msg*) incomingData;
186
186
187 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
187 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
188
188
189 localTime = getTimeAsUnsignedLongLongInt( );
189 localTime = getTimeAsUnsignedLongLongInt( );
190
190
191 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
191 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
192
192
193 //*****
193 //*****
194 //*****
194 //*****
195 // NORM
195 // NORM
196 //*****
196 //*****
197 //*****
197 //*****
198 // 1) compress the matrix for Basic Parameters calculation
198 // 1) compress the matrix for Basic Parameters calculation
199 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
199 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
200 nbSMInASMNORM,
200 nbSMInASMNORM,
201 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
201 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
202 ASM_F2_INDICE_START, CHANNELF2 );
202 ASM_F2_INDICE_START, CHANNELF2 );
203 // BP1_F2
203 // BP1_F2
204 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
204 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
205 {
205 {
206 // 1) compute the BP1 set
206 // 1) compute the BP1 set
207 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
207 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
208 // 2) send the BP1 set
208 // 2) send the BP1 set
209 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
209 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
210 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
210 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
211 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
211 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
212 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
212 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
213 BP_send( (char *) &packet_norm_bp1, queue_id_send,
213 BP_send( (char *) &packet_norm_bp1, queue_id_send,
214 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
214 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
215 SID_NORM_BP1_F2 );
215 SID_NORM_BP1_F2 );
216 }
216 }
217 // BP2_F2
217 // BP2_F2
218 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
218 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
219 {
219 {
220 // 1) compute the BP2 set
220 // 1) compute the BP2 set
221 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
221 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
222 // 2) send the BP2 set
222 // 2) send the BP2 set
223 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
223 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
224 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
224 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
225 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
225 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
226 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
226 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
227 BP_send( (char *) &packet_norm_bp2, queue_id_send,
227 BP_send( (char *) &packet_norm_bp2, queue_id_send,
228 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
228 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
229 SID_NORM_BP2_F2 );
229 SID_NORM_BP2_F2 );
230 }
230 }
231
231
232 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
232 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
233 {
233 {
234 // 1) reorganize the ASM and divide
234 // 1) reorganize the ASM and divide
235 ASM_reorganize_and_divide( asm_f2_patched_norm,
235 ASM_reorganize_and_divide( asm_f2_patched_norm,
236 (float*) current_ring_node_to_send_asm_f2->buffer_address,
236 (float*) current_ring_node_to_send_asm_f2->buffer_address,
237 nb_sm_before_f2.norm_bp1 );
237 nb_sm_before_f2.norm_bp1 );
238 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
238 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
239 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
239 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
240 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
240 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
241
241
242 // 3) send the spectral matrix packets
242 // 3) send the spectral matrix packets
243 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
243 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
244
244
245 // change asm ring node
245 // change asm ring node
246 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
246 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
247 }
247 }
248
248
249 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
249 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
250
250
251 }
251 }
252 }
252 }
253
253
254 //**********
254 //**********
255 // FUNCTIONS
255 // FUNCTIONS
256
256
257 void reset_nb_sm_f2( void )
257 void reset_nb_sm_f2( void )
258 {
258 {
259 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
259 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
260 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
260 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
261 nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_asm_p[1];
261 nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_asm_p[1];
262 }
262 }
263
263
264 void SM_average_f2( float *averaged_spec_mat_f2,
264 void SM_average_f2( float *averaged_spec_mat_f2,
265 ring_node *ring_node,
265 ring_node *ring_node,
266 unsigned int nbAverageNormF2,
266 unsigned int nbAverageNormF2,
267 asm_msg *msgForMATR )
267 asm_msg *msgForMATR )
268 {
268 {
269 float sum;
269 float sum;
270 unsigned int i;
270 unsigned int i;
271 unsigned char keepMatrix;
271 unsigned char keepMatrix;
272
272
273 // test acquisitionTime validity
273 // test acquisitionTime validity
274 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, CHANNELF2 );
274 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, CHANNELF2 );
275
275
276 for(i=0; i<TOTAL_SIZE_SM; i++)
276 for(i=0; i<TOTAL_SIZE_SM; i++)
277 {
277 {
278 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
278 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
279 if ( (nbAverageNormF2 == 0) ) // average initialization
279 if ( (nbAverageNormF2 == 0) ) // average initialization
280 {
280 {
281 if (keepMatrix == 1) // keep the matrix and add it to the average
281 if (keepMatrix == 1) // keep the matrix and add it to the average
282 {
282 {
283 averaged_spec_mat_f2[ i ] = sum;
283 averaged_spec_mat_f2[ i ] = sum;
284 }
284 }
285 else // drop the matrix and initialize the average
285 else // drop the matrix and initialize the average
286 {
286 {
287 averaged_spec_mat_f2[ i ] = INIT_FLOAT;
287 averaged_spec_mat_f2[ i ] = INIT_FLOAT;
288 }
288 }
289 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
289 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
290 msgForMATR->fineTimeNORM = ring_node->fineTime;
290 msgForMATR->fineTimeNORM = ring_node->fineTime;
291 }
291 }
292 else
292 else
293 {
293 {
294 if (keepMatrix == 1) // keep the matrix and add it to the average
294 if (keepMatrix == 1) // keep the matrix and add it to the average
295 {
295 {
296 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
296 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
297 }
297 }
298 else
298 else
299 {
299 {
300 // nothing to do, the matrix is not valid
300 // nothing to do, the matrix is not valid
301 }
301 }
302 }
302 }
303 }
303 }
304
304
305 if (keepMatrix == 1)
305 if (keepMatrix == 1)
306 {
306 {
307 if ( (nbAverageNormF2 == 0) )
307 if ( (nbAverageNormF2 == 0) )
308 {
308 {
309 msgForMATR->numberOfSMInASMNORM = 1;
309 msgForMATR->numberOfSMInASMNORM = 1;
310 }
310 }
311 else
311 else
312 {
312 {
313 msgForMATR->numberOfSMInASMNORM++;
313 msgForMATR->numberOfSMInASMNORM++;
314 }
314 }
315 }
315 }
316 else
316 else
317 {
317 {
318 if ( (nbAverageNormF2 == 0) )
318 if ( (nbAverageNormF2 == 0) )
319 {
319 {
320 msgForMATR->numberOfSMInASMNORM = 0;
320 msgForMATR->numberOfSMInASMNORM = 0;
321 }
321 }
322 else
322 else
323 {
323 {
324 // nothing to do
324 // nothing to do
325 }
325 }
326 }
326 }
327 }
327 }
328
328
329 void init_k_coefficients_prc2( void )
329 void init_k_coefficients_prc2( void )
330 {
330 {
331 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
331 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
332 }
332 }
@@ -1,1664 +1,1670
1 /** Functions and tasks related to TeleCommand handling.
1 /** Functions and tasks related to TeleCommand handling.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TeleCommands:\n
6 * A group of functions to handle TeleCommands:\n
7 * action launching\n
7 * action launching\n
8 * TC parsing\n
8 * TC parsing\n
9 * ...
9 * ...
10 *
10 *
11 */
11 */
12
12
13 #include "tc_handler.h"
13 #include "tc_handler.h"
14 #include "math.h"
14 #include "math.h"
15
15
16 //***********
16 //***********
17 // RTEMS TASK
17 // RTEMS TASK
18
18
19 rtems_task actn_task( rtems_task_argument unused )
19 rtems_task actn_task( rtems_task_argument unused )
20 {
20 {
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 *
22 *
23 * @param unused is the starting argument of the RTEMS task
23 * @param unused is the starting argument of the RTEMS task
24 *
24 *
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
26 * on the incoming TeleCommand.
26 * on the incoming TeleCommand.
27 *
27 *
28 */
28 */
29
29
30 int result;
30 int result;
31 rtems_status_code status; // RTEMS status code
31 rtems_status_code status; // RTEMS status code
32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 ccsdsTelecommandPacket_t __attribute__((aligned(4))) TC; // TC sent to the ACTN task
33 size_t size; // size of the incoming TC packet
33 size_t size; // size of the incoming TC packet
34 unsigned char subtype; // subtype of the current TC packet
34 unsigned char subtype; // subtype of the current TC packet
35 unsigned char time[BYTES_PER_TIME];
35 unsigned char time[BYTES_PER_TIME];
36 rtems_id queue_rcv_id;
36 rtems_id queue_rcv_id;
37 rtems_id queue_snd_id;
37 rtems_id queue_snd_id;
38
38
39 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
39 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
40 size = 0;
40 size = 0;
41 queue_rcv_id = RTEMS_ID_NONE;
41 queue_rcv_id = RTEMS_ID_NONE;
42 queue_snd_id = RTEMS_ID_NONE;
42 queue_snd_id = RTEMS_ID_NONE;
43
43
44 status = get_message_queue_id_recv( &queue_rcv_id );
44 status = get_message_queue_id_recv( &queue_rcv_id );
45 if (status != RTEMS_SUCCESSFUL)
45 if (status != RTEMS_SUCCESSFUL)
46 {
46 {
47 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
47 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
48 }
48 }
49
49
50 status = get_message_queue_id_send( &queue_snd_id );
50 status = get_message_queue_id_send( &queue_snd_id );
51 if (status != RTEMS_SUCCESSFUL)
51 if (status != RTEMS_SUCCESSFUL)
52 {
52 {
53 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
53 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
54 }
54 }
55
55
56 result = LFR_SUCCESSFUL;
56 result = LFR_SUCCESSFUL;
57 subtype = 0; // subtype of the current TC packet
57 subtype = 0; // subtype of the current TC packet
58
58
59 BOOT_PRINTF("in ACTN *** \n");
59 BOOT_PRINTF("in ACTN *** \n");
60
60
61 while(1)
61 while(1)
62 {
62 {
63 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
63 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
64 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
64 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
65 getTime( time ); // set time to the current time
65 getTime( time ); // set time to the current time
66 if (status!=RTEMS_SUCCESSFUL)
66 if (status!=RTEMS_SUCCESSFUL)
67 {
67 {
68 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
68 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
69 }
69 }
70 else
70 else
71 {
71 {
72 subtype = TC.serviceSubType;
72 subtype = TC.serviceSubType;
73 switch(subtype)
73 switch(subtype)
74 {
74 {
75 case TC_SUBTYPE_RESET:
75 case TC_SUBTYPE_RESET:
76 result = action_reset( &TC, queue_snd_id, time );
76 result = action_reset( &TC, queue_snd_id, time );
77 close_action( &TC, result, queue_snd_id );
77 close_action( &TC, result, queue_snd_id );
78 break;
78 break;
79 case TC_SUBTYPE_LOAD_COMM:
79 case TC_SUBTYPE_LOAD_COMM:
80 result = action_load_common_par( &TC );
80 result = action_load_common_par( &TC );
81 close_action( &TC, result, queue_snd_id );
81 close_action( &TC, result, queue_snd_id );
82 break;
82 break;
83 case TC_SUBTYPE_LOAD_NORM:
83 case TC_SUBTYPE_LOAD_NORM:
84 result = action_load_normal_par( &TC, queue_snd_id, time );
84 result = action_load_normal_par( &TC, queue_snd_id, time );
85 close_action( &TC, result, queue_snd_id );
85 close_action( &TC, result, queue_snd_id );
86 break;
86 break;
87 case TC_SUBTYPE_LOAD_BURST:
87 case TC_SUBTYPE_LOAD_BURST:
88 result = action_load_burst_par( &TC, queue_snd_id, time );
88 result = action_load_burst_par( &TC, queue_snd_id, time );
89 close_action( &TC, result, queue_snd_id );
89 close_action( &TC, result, queue_snd_id );
90 break;
90 break;
91 case TC_SUBTYPE_LOAD_SBM1:
91 case TC_SUBTYPE_LOAD_SBM1:
92 result = action_load_sbm1_par( &TC, queue_snd_id, time );
92 result = action_load_sbm1_par( &TC, queue_snd_id, time );
93 close_action( &TC, result, queue_snd_id );
93 close_action( &TC, result, queue_snd_id );
94 break;
94 break;
95 case TC_SUBTYPE_LOAD_SBM2:
95 case TC_SUBTYPE_LOAD_SBM2:
96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
97 close_action( &TC, result, queue_snd_id );
97 close_action( &TC, result, queue_snd_id );
98 break;
98 break;
99 case TC_SUBTYPE_DUMP:
99 case TC_SUBTYPE_DUMP:
100 result = action_dump_par( &TC, queue_snd_id );
100 result = action_dump_par( &TC, queue_snd_id );
101 close_action( &TC, result, queue_snd_id );
101 close_action( &TC, result, queue_snd_id );
102 break;
102 break;
103 case TC_SUBTYPE_ENTER:
103 case TC_SUBTYPE_ENTER:
104 result = action_enter_mode( &TC, queue_snd_id );
104 result = action_enter_mode( &TC, queue_snd_id );
105 close_action( &TC, result, queue_snd_id );
105 close_action( &TC, result, queue_snd_id );
106 break;
106 break;
107 case TC_SUBTYPE_UPDT_INFO:
107 case TC_SUBTYPE_UPDT_INFO:
108 result = action_update_info( &TC, queue_snd_id );
108 result = action_update_info( &TC, queue_snd_id );
109 close_action( &TC, result, queue_snd_id );
109 close_action( &TC, result, queue_snd_id );
110 break;
110 break;
111 case TC_SUBTYPE_EN_CAL:
111 case TC_SUBTYPE_EN_CAL:
112 result = action_enable_calibration( &TC, queue_snd_id, time );
112 result = action_enable_calibration( &TC, queue_snd_id, time );
113 close_action( &TC, result, queue_snd_id );
113 close_action( &TC, result, queue_snd_id );
114 break;
114 break;
115 case TC_SUBTYPE_DIS_CAL:
115 case TC_SUBTYPE_DIS_CAL:
116 result = action_disable_calibration( &TC, queue_snd_id, time );
116 result = action_disable_calibration( &TC, queue_snd_id, time );
117 close_action( &TC, result, queue_snd_id );
117 close_action( &TC, result, queue_snd_id );
118 break;
118 break;
119 case TC_SUBTYPE_LOAD_K:
119 case TC_SUBTYPE_LOAD_K:
120 result = action_load_kcoefficients( &TC, queue_snd_id, time );
120 result = action_load_kcoefficients( &TC, queue_snd_id, time );
121 close_action( &TC, result, queue_snd_id );
121 close_action( &TC, result, queue_snd_id );
122 break;
122 break;
123 case TC_SUBTYPE_DUMP_K:
123 case TC_SUBTYPE_DUMP_K:
124 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
124 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
125 close_action( &TC, result, queue_snd_id );
125 close_action( &TC, result, queue_snd_id );
126 break;
126 break;
127 case TC_SUBTYPE_LOAD_FBINS:
127 case TC_SUBTYPE_LOAD_FBINS:
128 result = action_load_fbins_mask( &TC, queue_snd_id, time );
128 result = action_load_fbins_mask( &TC, queue_snd_id, time );
129 close_action( &TC, result, queue_snd_id );
129 close_action( &TC, result, queue_snd_id );
130 break;
130 break;
131 case TC_SUBTYPE_LOAD_FILTER_PAR:
131 case TC_SUBTYPE_LOAD_FILTER_PAR:
132 result = action_load_filter_par( &TC, queue_snd_id, time );
132 result = action_load_filter_par( &TC, queue_snd_id, time );
133 close_action( &TC, result, queue_snd_id );
133 close_action( &TC, result, queue_snd_id );
134 break;
134 break;
135 case TC_SUBTYPE_UPDT_TIME:
135 case TC_SUBTYPE_UPDT_TIME:
136 result = action_update_time( &TC );
136 result = action_update_time( &TC );
137 close_action( &TC, result, queue_snd_id );
137 close_action( &TC, result, queue_snd_id );
138 break;
138 break;
139 default:
139 default:
140 break;
140 break;
141 }
141 }
142 }
142 }
143 }
143 }
144 }
144 }
145
145
146 //***********
146 //***********
147 // TC ACTIONS
147 // TC ACTIONS
148
148
149 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
149 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
150 {
150 {
151 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
151 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
152 *
152 *
153 * @param TC points to the TeleCommand packet that is being processed
153 * @param TC points to the TeleCommand packet that is being processed
154 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
154 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
155 *
155 *
156 */
156 */
157
157
158 PRINTF("this is the end!!!\n");
158 PRINTF("this is the end!!!\n");
159 exit(0);
159 exit(0);
160
160
161 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
161 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
162
162
163 return LFR_DEFAULT;
163 return LFR_DEFAULT;
164 }
164 }
165
165
166 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
166 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
167 {
167 {
168 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
168 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
169 *
169 *
170 * @param TC points to the TeleCommand packet that is being processed
170 * @param TC points to the TeleCommand packet that is being processed
171 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
171 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
172 *
172 *
173 */
173 */
174
174
175 rtems_status_code status;
175 rtems_status_code status;
176 unsigned char requestedMode;
176 unsigned char requestedMode;
177 unsigned int *transitionCoarseTime_ptr;
177 unsigned int *transitionCoarseTime_ptr;
178 unsigned int transitionCoarseTime;
178 unsigned int transitionCoarseTime;
179 unsigned char * bytePosPtr;
179 unsigned char * bytePosPtr;
180
180
181 printf("(0)\n");
181 bytePosPtr = (unsigned char *) &TC->packetID;
182 bytePosPtr = (unsigned char *) &TC->packetID;
182
183 printf("(1)\n");
183 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
184 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
184 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
185 printf("(2)\n");
185 transitionCoarseTime = (*transitionCoarseTime_ptr) & COARSE_TIME_MASK;
186 copyInt32ByChar( &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
186
187 printf("(3)\n");
188 transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK;
189 printf("(4)\n");
187 status = check_mode_value( requestedMode );
190 status = check_mode_value( requestedMode );
191 printf("(5)\n");
188
192
189 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
193 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
190 {
194 {
191 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
195 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
192 }
196 }
193
197
194 else // the mode value is valid, check the transition
198 else // the mode value is valid, check the transition
195 {
199 {
196 status = check_mode_transition(requestedMode);
200 status = check_mode_transition(requestedMode);
197 if (status != LFR_SUCCESSFUL)
201 if (status != LFR_SUCCESSFUL)
198 {
202 {
199 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
203 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
200 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
204 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
201 }
205 }
202 }
206 }
203
207
204 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
208 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
205 {
209 {
206 status = check_transition_date( transitionCoarseTime );
210 status = check_transition_date( transitionCoarseTime );
207 if (status != LFR_SUCCESSFUL)
211 if (status != LFR_SUCCESSFUL)
208 {
212 {
209 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
213 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
210 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
214 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
211 }
215 }
212 }
216 }
213
217
214 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
218 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
215 {
219 {
216 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
220 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
217
221
218 switch(requestedMode)
222 switch(requestedMode)
219 {
223 {
220 case LFR_MODE_STANDBY:
224 case LFR_MODE_STANDBY:
221 status = enter_mode_standby();
225 status = enter_mode_standby();
222 break;
226 break;
223 case LFR_MODE_NORMAL:
227 case LFR_MODE_NORMAL:
224 status = enter_mode_normal( transitionCoarseTime );
228 status = enter_mode_normal( transitionCoarseTime );
225 break;
229 break;
226 case LFR_MODE_BURST:
230 case LFR_MODE_BURST:
227 status = enter_mode_burst( transitionCoarseTime );
231 status = enter_mode_burst( transitionCoarseTime );
228 break;
232 break;
229 case LFR_MODE_SBM1:
233 case LFR_MODE_SBM1:
230 status = enter_mode_sbm1( transitionCoarseTime );
234 status = enter_mode_sbm1( transitionCoarseTime );
231 break;
235 break;
232 case LFR_MODE_SBM2:
236 case LFR_MODE_SBM2:
233 status = enter_mode_sbm2( transitionCoarseTime );
237 status = enter_mode_sbm2( transitionCoarseTime );
234 break;
238 break;
235 default:
239 default:
236 break;
240 break;
237 }
241 }
238
242
239 if (status != RTEMS_SUCCESSFUL)
243 if (status != RTEMS_SUCCESSFUL)
240 {
244 {
241 status = LFR_EXE_ERROR;
245 status = LFR_EXE_ERROR;
242 }
246 }
243 }
247 }
244
248
245 return status;
249 return status;
246 }
250 }
247
251
248 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
252 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
249 {
253 {
250 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
254 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
251 *
255 *
252 * @param TC points to the TeleCommand packet that is being processed
256 * @param TC points to the TeleCommand packet that is being processed
253 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
257 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
254 *
258 *
255 * @return LFR directive status code:
259 * @return LFR directive status code:
256 * - LFR_DEFAULT
260 * - LFR_DEFAULT
257 * - LFR_SUCCESSFUL
261 * - LFR_SUCCESSFUL
258 *
262 *
259 */
263 */
260
264
261 unsigned int val;
265 unsigned int val;
262 int result;
266 int result;
263 unsigned int status;
267 unsigned int status;
264 unsigned char mode;
268 unsigned char mode;
265 unsigned char * bytePosPtr;
269 unsigned char * bytePosPtr;
266
270
267 bytePosPtr = (unsigned char *) &TC->packetID;
271 bytePosPtr = (unsigned char *) &TC->packetID;
268
272
269 // check LFR mode
273 // check LFR mode
270 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
274 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
271 status = check_update_info_hk_lfr_mode( mode );
275 status = check_update_info_hk_lfr_mode( mode );
272 if (status == LFR_SUCCESSFUL) // check TDS mode
276 if (status == LFR_SUCCESSFUL) // check TDS mode
273 {
277 {
274 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
278 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
275 status = check_update_info_hk_tds_mode( mode );
279 status = check_update_info_hk_tds_mode( mode );
276 }
280 }
277 if (status == LFR_SUCCESSFUL) // check THR mode
281 if (status == LFR_SUCCESSFUL) // check THR mode
278 {
282 {
279 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
283 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
280 status = check_update_info_hk_thr_mode( mode );
284 status = check_update_info_hk_thr_mode( mode );
281 }
285 }
282 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
286 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
283 {
287 {
284 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
288 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
285 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
289 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
286 val++;
290 val++;
287 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
291 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
288 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
292 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
289 }
293 }
290
294
291 // pa_bia_status_info
295 // pa_bia_status_info
292 // => pa_bia_mode_mux_set 3 bits
296 // => pa_bia_mode_mux_set 3 bits
293 // => pa_bia_mode_hv_enabled 1 bit
297 // => pa_bia_mode_hv_enabled 1 bit
294 // => pa_bia_mode_bias1_enabled 1 bit
298 // => pa_bia_mode_bias1_enabled 1 bit
295 // => pa_bia_mode_bias2_enabled 1 bit
299 // => pa_bia_mode_bias2_enabled 1 bit
296 // => pa_bia_mode_bias3_enabled 1 bit
300 // => pa_bia_mode_bias3_enabled 1 bit
297 // => pa_bia_on_off (cp_dpu_bias_on_off)
301 // => pa_bia_on_off (cp_dpu_bias_on_off)
298 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
302 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
299 pa_bia_status_info = pa_bia_status_info
303 pa_bia_status_info = pa_bia_status_info
300 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
304 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
301
305
302 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
306 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
303
307
304 //cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ];
308 //cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ];
305 getReactionWheelsFrequencies( TC );
309 getReactionWheelsFrequencies( TC );
306 set_hk_lfr_sc_rw_f_flags();
310 set_hk_lfr_sc_rw_f_flags();
307 build_sy_lfr_rw_masks();
311 build_sy_lfr_rw_masks();
308
312
309 // once the masks are built, they have to be merged with the fbins_mask
313 // once the masks are built, they have to be merged with the fbins_mask
310 merge_fbins_masks();
314 merge_fbins_masks();
311
315
312 result = status;
316 result = status;
313
317
314 return result;
318 return result;
315 }
319 }
316
320
317 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
321 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
318 {
322 {
319 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
323 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
320 *
324 *
321 * @param TC points to the TeleCommand packet that is being processed
325 * @param TC points to the TeleCommand packet that is being processed
322 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
326 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
323 *
327 *
324 */
328 */
325
329
326 int result;
330 int result;
327
331
328 result = LFR_DEFAULT;
332 result = LFR_DEFAULT;
329
333
330 setCalibration( true );
334 setCalibration( true );
331
335
332 result = LFR_SUCCESSFUL;
336 result = LFR_SUCCESSFUL;
333
337
334 return result;
338 return result;
335 }
339 }
336
340
337 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
341 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
338 {
342 {
339 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
343 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
340 *
344 *
341 * @param TC points to the TeleCommand packet that is being processed
345 * @param TC points to the TeleCommand packet that is being processed
342 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
346 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
343 *
347 *
344 */
348 */
345
349
346 int result;
350 int result;
347
351
348 result = LFR_DEFAULT;
352 result = LFR_DEFAULT;
349
353
350 setCalibration( false );
354 setCalibration( false );
351
355
352 result = LFR_SUCCESSFUL;
356 result = LFR_SUCCESSFUL;
353
357
354 return result;
358 return result;
355 }
359 }
356
360
357 int action_update_time(ccsdsTelecommandPacket_t *TC)
361 int action_update_time(ccsdsTelecommandPacket_t *TC)
358 {
362 {
359 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
363 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
360 *
364 *
361 * @param TC points to the TeleCommand packet that is being processed
365 * @param TC points to the TeleCommand packet that is being processed
362 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
366 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
363 *
367 *
364 * @return LFR_SUCCESSFUL
368 * @return LFR_SUCCESSFUL
365 *
369 *
366 */
370 */
367
371
368 unsigned int val;
372 unsigned int val;
369
373
370 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
374 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
371 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
375 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
372 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
376 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
373 + TC->dataAndCRC[BYTE_3];
377 + TC->dataAndCRC[BYTE_3];
374
378
375 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
379 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
376 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
380 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
377 val++;
381 val++;
378 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
382 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
379 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
383 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
380
384
381 oneTcLfrUpdateTimeReceived = 1;
385 oneTcLfrUpdateTimeReceived = 1;
382
386
383 return LFR_SUCCESSFUL;
387 return LFR_SUCCESSFUL;
384 }
388 }
385
389
386 //*******************
390 //*******************
387 // ENTERING THE MODES
391 // ENTERING THE MODES
388 int check_mode_value( unsigned char requestedMode )
392 int check_mode_value( unsigned char requestedMode )
389 {
393 {
390 int status;
394 int status;
391
395
392 status = LFR_DEFAULT;
396 status = LFR_DEFAULT;
393
397
394 if ( (requestedMode != LFR_MODE_STANDBY)
398 if ( (requestedMode != LFR_MODE_STANDBY)
395 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
399 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
396 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
400 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
397 {
401 {
398 status = LFR_DEFAULT;
402 status = LFR_DEFAULT;
399 }
403 }
400 else
404 else
401 {
405 {
402 status = LFR_SUCCESSFUL;
406 status = LFR_SUCCESSFUL;
403 }
407 }
404
408
405 return status;
409 return status;
406 }
410 }
407
411
408 int check_mode_transition( unsigned char requestedMode )
412 int check_mode_transition( unsigned char requestedMode )
409 {
413 {
410 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
414 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
411 *
415 *
412 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
416 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
413 *
417 *
414 * @return LFR directive status codes:
418 * @return LFR directive status codes:
415 * - LFR_SUCCESSFUL - the transition is authorized
419 * - LFR_SUCCESSFUL - the transition is authorized
416 * - LFR_DEFAULT - the transition is not authorized
420 * - LFR_DEFAULT - the transition is not authorized
417 *
421 *
418 */
422 */
419
423
420 int status;
424 int status;
421
425
422 switch (requestedMode)
426 switch (requestedMode)
423 {
427 {
424 case LFR_MODE_STANDBY:
428 case LFR_MODE_STANDBY:
425 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
429 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
426 status = LFR_DEFAULT;
430 status = LFR_DEFAULT;
427 }
431 }
428 else
432 else
429 {
433 {
430 status = LFR_SUCCESSFUL;
434 status = LFR_SUCCESSFUL;
431 }
435 }
432 break;
436 break;
433 case LFR_MODE_NORMAL:
437 case LFR_MODE_NORMAL:
434 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
438 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
435 status = LFR_DEFAULT;
439 status = LFR_DEFAULT;
436 }
440 }
437 else {
441 else {
438 status = LFR_SUCCESSFUL;
442 status = LFR_SUCCESSFUL;
439 }
443 }
440 break;
444 break;
441 case LFR_MODE_BURST:
445 case LFR_MODE_BURST:
442 if ( lfrCurrentMode == LFR_MODE_BURST ) {
446 if ( lfrCurrentMode == LFR_MODE_BURST ) {
443 status = LFR_DEFAULT;
447 status = LFR_DEFAULT;
444 }
448 }
445 else {
449 else {
446 status = LFR_SUCCESSFUL;
450 status = LFR_SUCCESSFUL;
447 }
451 }
448 break;
452 break;
449 case LFR_MODE_SBM1:
453 case LFR_MODE_SBM1:
450 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
454 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
451 status = LFR_DEFAULT;
455 status = LFR_DEFAULT;
452 }
456 }
453 else {
457 else {
454 status = LFR_SUCCESSFUL;
458 status = LFR_SUCCESSFUL;
455 }
459 }
456 break;
460 break;
457 case LFR_MODE_SBM2:
461 case LFR_MODE_SBM2:
458 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
462 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
459 status = LFR_DEFAULT;
463 status = LFR_DEFAULT;
460 }
464 }
461 else {
465 else {
462 status = LFR_SUCCESSFUL;
466 status = LFR_SUCCESSFUL;
463 }
467 }
464 break;
468 break;
465 default:
469 default:
466 status = LFR_DEFAULT;
470 status = LFR_DEFAULT;
467 break;
471 break;
468 }
472 }
469
473
470 return status;
474 return status;
471 }
475 }
472
476
473 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
477 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
474 {
478 {
475 if (transitionCoarseTime == 0)
479 if (transitionCoarseTime == 0)
476 {
480 {
477 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
481 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
478 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
482 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
479 }
483 }
480 else
484 else
481 {
485 {
482 lastValidEnterModeTime = transitionCoarseTime;
486 lastValidEnterModeTime = transitionCoarseTime;
483 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
487 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
484 }
488 }
485 }
489 }
486
490
487 int check_transition_date( unsigned int transitionCoarseTime )
491 int check_transition_date( unsigned int transitionCoarseTime )
488 {
492 {
489 int status;
493 int status;
490 unsigned int localCoarseTime;
494 unsigned int localCoarseTime;
491 unsigned int deltaCoarseTime;
495 unsigned int deltaCoarseTime;
492
496
493 status = LFR_SUCCESSFUL;
497 status = LFR_SUCCESSFUL;
494
498
495 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
499 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
496 {
500 {
497 status = LFR_SUCCESSFUL;
501 status = LFR_SUCCESSFUL;
498 }
502 }
499 else
503 else
500 {
504 {
501 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
505 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
502
506
503 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
507 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
504
508
505 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
509 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
506 {
510 {
507 status = LFR_DEFAULT;
511 status = LFR_DEFAULT;
508 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
512 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
509 }
513 }
510
514
511 if (status == LFR_SUCCESSFUL)
515 if (status == LFR_SUCCESSFUL)
512 {
516 {
513 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
517 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
514 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
518 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
515 {
519 {
516 status = LFR_DEFAULT;
520 status = LFR_DEFAULT;
517 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
521 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
518 }
522 }
519 }
523 }
520 }
524 }
521
525
522 return status;
526 return status;
523 }
527 }
524
528
525 int restart_asm_activities( unsigned char lfrRequestedMode )
529 int restart_asm_activities( unsigned char lfrRequestedMode )
526 {
530 {
527 rtems_status_code status;
531 rtems_status_code status;
528
532
529 status = stop_spectral_matrices();
533 status = stop_spectral_matrices();
530
534
531 thisIsAnASMRestart = 1;
535 thisIsAnASMRestart = 1;
532
536
533 status = restart_asm_tasks( lfrRequestedMode );
537 status = restart_asm_tasks( lfrRequestedMode );
534
538
535 launch_spectral_matrix();
539 launch_spectral_matrix();
536
540
537 return status;
541 return status;
538 }
542 }
539
543
540 int stop_spectral_matrices( void )
544 int stop_spectral_matrices( void )
541 {
545 {
542 /** This function stops and restarts the current mode average spectral matrices activities.
546 /** This function stops and restarts the current mode average spectral matrices activities.
543 *
547 *
544 * @return RTEMS directive status codes:
548 * @return RTEMS directive status codes:
545 * - RTEMS_SUCCESSFUL - task restarted successfully
549 * - RTEMS_SUCCESSFUL - task restarted successfully
546 * - RTEMS_INVALID_ID - task id invalid
550 * - RTEMS_INVALID_ID - task id invalid
547 * - RTEMS_ALREADY_SUSPENDED - task already suspended
551 * - RTEMS_ALREADY_SUSPENDED - task already suspended
548 *
552 *
549 */
553 */
550
554
551 rtems_status_code status;
555 rtems_status_code status;
552
556
553 status = RTEMS_SUCCESSFUL;
557 status = RTEMS_SUCCESSFUL;
554
558
555 // (1) mask interruptions
559 // (1) mask interruptions
556 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
560 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
557
561
558 // (2) reset spectral matrices registers
562 // (2) reset spectral matrices registers
559 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
563 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
560 reset_sm_status();
564 reset_sm_status();
561
565
562 // (3) clear interruptions
566 // (3) clear interruptions
563 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
567 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
564
568
565 // suspend several tasks
569 // suspend several tasks
566 if (lfrCurrentMode != LFR_MODE_STANDBY) {
570 if (lfrCurrentMode != LFR_MODE_STANDBY) {
567 status = suspend_asm_tasks();
571 status = suspend_asm_tasks();
568 }
572 }
569
573
570 if (status != RTEMS_SUCCESSFUL)
574 if (status != RTEMS_SUCCESSFUL)
571 {
575 {
572 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
576 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
573 }
577 }
574
578
575 return status;
579 return status;
576 }
580 }
577
581
578 int stop_current_mode( void )
582 int stop_current_mode( void )
579 {
583 {
580 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
584 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
581 *
585 *
582 * @return RTEMS directive status codes:
586 * @return RTEMS directive status codes:
583 * - RTEMS_SUCCESSFUL - task restarted successfully
587 * - RTEMS_SUCCESSFUL - task restarted successfully
584 * - RTEMS_INVALID_ID - task id invalid
588 * - RTEMS_INVALID_ID - task id invalid
585 * - RTEMS_ALREADY_SUSPENDED - task already suspended
589 * - RTEMS_ALREADY_SUSPENDED - task already suspended
586 *
590 *
587 */
591 */
588
592
589 rtems_status_code status;
593 rtems_status_code status;
590
594
591 status = RTEMS_SUCCESSFUL;
595 status = RTEMS_SUCCESSFUL;
592
596
593 // (1) mask interruptions
597 // (1) mask interruptions
594 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
598 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
595 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
599 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
596
600
597 // (2) reset waveform picker registers
601 // (2) reset waveform picker registers
598 reset_wfp_burst_enable(); // reset burst and enable bits
602 reset_wfp_burst_enable(); // reset burst and enable bits
599 reset_wfp_status(); // reset all the status bits
603 reset_wfp_status(); // reset all the status bits
600
604
601 // (3) reset spectral matrices registers
605 // (3) reset spectral matrices registers
602 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
606 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
603 reset_sm_status();
607 reset_sm_status();
604
608
605 // reset lfr VHDL module
609 // reset lfr VHDL module
606 reset_lfr();
610 reset_lfr();
607
611
608 reset_extractSWF(); // reset the extractSWF flag to false
612 reset_extractSWF(); // reset the extractSWF flag to false
609
613
610 // (4) clear interruptions
614 // (4) clear interruptions
611 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
615 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
612 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
616 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
613
617
614 // suspend several tasks
618 // suspend several tasks
615 if (lfrCurrentMode != LFR_MODE_STANDBY) {
619 if (lfrCurrentMode != LFR_MODE_STANDBY) {
616 status = suspend_science_tasks();
620 status = suspend_science_tasks();
617 }
621 }
618
622
619 if (status != RTEMS_SUCCESSFUL)
623 if (status != RTEMS_SUCCESSFUL)
620 {
624 {
621 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
625 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
622 }
626 }
623
627
624 return status;
628 return status;
625 }
629 }
626
630
627 int enter_mode_standby( void )
631 int enter_mode_standby( void )
628 {
632 {
629 /** This function is used to put LFR in the STANDBY mode.
633 /** This function is used to put LFR in the STANDBY mode.
630 *
634 *
631 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
635 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
632 *
636 *
633 * @return RTEMS directive status codes:
637 * @return RTEMS directive status codes:
634 * - RTEMS_SUCCESSFUL - task restarted successfully
638 * - RTEMS_SUCCESSFUL - task restarted successfully
635 * - RTEMS_INVALID_ID - task id invalid
639 * - RTEMS_INVALID_ID - task id invalid
636 * - RTEMS_INCORRECT_STATE - task never started
640 * - RTEMS_INCORRECT_STATE - task never started
637 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
641 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
638 *
642 *
639 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
643 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
640 * is immediate.
644 * is immediate.
641 *
645 *
642 */
646 */
643
647
644 int status;
648 int status;
645
649
646 status = stop_current_mode(); // STOP THE CURRENT MODE
650 status = stop_current_mode(); // STOP THE CURRENT MODE
647
651
648 #ifdef PRINT_TASK_STATISTICS
652 #ifdef PRINT_TASK_STATISTICS
649 rtems_cpu_usage_report();
653 rtems_cpu_usage_report();
650 #endif
654 #endif
651
655
652 #ifdef PRINT_STACK_REPORT
656 #ifdef PRINT_STACK_REPORT
653 PRINTF("stack report selected\n")
657 PRINTF("stack report selected\n")
654 rtems_stack_checker_report_usage();
658 rtems_stack_checker_report_usage();
655 #endif
659 #endif
656
660
657 return status;
661 return status;
658 }
662 }
659
663
660 int enter_mode_normal( unsigned int transitionCoarseTime )
664 int enter_mode_normal( unsigned int transitionCoarseTime )
661 {
665 {
662 /** This function is used to start the NORMAL mode.
666 /** This function is used to start the NORMAL mode.
663 *
667 *
664 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
668 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
665 *
669 *
666 * @return RTEMS directive status codes:
670 * @return RTEMS directive status codes:
667 * - RTEMS_SUCCESSFUL - task restarted successfully
671 * - RTEMS_SUCCESSFUL - task restarted successfully
668 * - RTEMS_INVALID_ID - task id invalid
672 * - RTEMS_INVALID_ID - task id invalid
669 * - RTEMS_INCORRECT_STATE - task never started
673 * - RTEMS_INCORRECT_STATE - task never started
670 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
674 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
671 *
675 *
672 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
676 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
673 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
677 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
674 *
678 *
675 */
679 */
676
680
677 int status;
681 int status;
678
682
679 #ifdef PRINT_TASK_STATISTICS
683 #ifdef PRINT_TASK_STATISTICS
680 rtems_cpu_usage_reset();
684 rtems_cpu_usage_reset();
681 #endif
685 #endif
682
686
683 status = RTEMS_UNSATISFIED;
687 status = RTEMS_UNSATISFIED;
684
688
689 printf("hop\n");
690
685 switch( lfrCurrentMode )
691 switch( lfrCurrentMode )
686 {
692 {
687 case LFR_MODE_STANDBY:
693 case LFR_MODE_STANDBY:
688 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
694 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
689 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
695 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
690 {
696 {
691 launch_spectral_matrix( );
697 launch_spectral_matrix( );
692 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
698 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
693 }
699 }
694 break;
700 break;
695 case LFR_MODE_BURST:
701 case LFR_MODE_BURST:
696 status = stop_current_mode(); // stop the current mode
702 status = stop_current_mode(); // stop the current mode
697 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
703 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
698 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
704 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
699 {
705 {
700 launch_spectral_matrix( );
706 launch_spectral_matrix( );
701 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
707 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
702 }
708 }
703 break;
709 break;
704 case LFR_MODE_SBM1:
710 case LFR_MODE_SBM1:
705 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
711 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
706 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
712 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
707 update_last_valid_transition_date( transitionCoarseTime );
713 update_last_valid_transition_date( transitionCoarseTime );
708 break;
714 break;
709 case LFR_MODE_SBM2:
715 case LFR_MODE_SBM2:
710 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
716 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
711 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
717 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
712 update_last_valid_transition_date( transitionCoarseTime );
718 update_last_valid_transition_date( transitionCoarseTime );
713 break;
719 break;
714 default:
720 default:
715 break;
721 break;
716 }
722 }
717
723
718 if (status != RTEMS_SUCCESSFUL)
724 if (status != RTEMS_SUCCESSFUL)
719 {
725 {
720 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
726 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
721 status = RTEMS_UNSATISFIED;
727 status = RTEMS_UNSATISFIED;
722 }
728 }
723
729
724 return status;
730 return status;
725 }
731 }
726
732
727 int enter_mode_burst( unsigned int transitionCoarseTime )
733 int enter_mode_burst( unsigned int transitionCoarseTime )
728 {
734 {
729 /** This function is used to start the BURST mode.
735 /** This function is used to start the BURST mode.
730 *
736 *
731 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
737 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
732 *
738 *
733 * @return RTEMS directive status codes:
739 * @return RTEMS directive status codes:
734 * - RTEMS_SUCCESSFUL - task restarted successfully
740 * - RTEMS_SUCCESSFUL - task restarted successfully
735 * - RTEMS_INVALID_ID - task id invalid
741 * - RTEMS_INVALID_ID - task id invalid
736 * - RTEMS_INCORRECT_STATE - task never started
742 * - RTEMS_INCORRECT_STATE - task never started
737 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
743 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
738 *
744 *
739 * The way the BURST mode is started does not depend on the LFR current mode.
745 * The way the BURST mode is started does not depend on the LFR current mode.
740 *
746 *
741 */
747 */
742
748
743
749
744 int status;
750 int status;
745
751
746 #ifdef PRINT_TASK_STATISTICS
752 #ifdef PRINT_TASK_STATISTICS
747 rtems_cpu_usage_reset();
753 rtems_cpu_usage_reset();
748 #endif
754 #endif
749
755
750 status = stop_current_mode(); // stop the current mode
756 status = stop_current_mode(); // stop the current mode
751 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
757 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
752 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
758 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
753 {
759 {
754 launch_spectral_matrix( );
760 launch_spectral_matrix( );
755 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
761 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
756 }
762 }
757
763
758 if (status != RTEMS_SUCCESSFUL)
764 if (status != RTEMS_SUCCESSFUL)
759 {
765 {
760 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
766 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
761 status = RTEMS_UNSATISFIED;
767 status = RTEMS_UNSATISFIED;
762 }
768 }
763
769
764 return status;
770 return status;
765 }
771 }
766
772
767 int enter_mode_sbm1( unsigned int transitionCoarseTime )
773 int enter_mode_sbm1( unsigned int transitionCoarseTime )
768 {
774 {
769 /** This function is used to start the SBM1 mode.
775 /** This function is used to start the SBM1 mode.
770 *
776 *
771 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
777 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
772 *
778 *
773 * @return RTEMS directive status codes:
779 * @return RTEMS directive status codes:
774 * - RTEMS_SUCCESSFUL - task restarted successfully
780 * - RTEMS_SUCCESSFUL - task restarted successfully
775 * - RTEMS_INVALID_ID - task id invalid
781 * - RTEMS_INVALID_ID - task id invalid
776 * - RTEMS_INCORRECT_STATE - task never started
782 * - RTEMS_INCORRECT_STATE - task never started
777 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
783 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
778 *
784 *
779 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
785 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
780 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
786 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
781 * cases, the acquisition is completely restarted.
787 * cases, the acquisition is completely restarted.
782 *
788 *
783 */
789 */
784
790
785 int status;
791 int status;
786
792
787 #ifdef PRINT_TASK_STATISTICS
793 #ifdef PRINT_TASK_STATISTICS
788 rtems_cpu_usage_reset();
794 rtems_cpu_usage_reset();
789 #endif
795 #endif
790
796
791 status = RTEMS_UNSATISFIED;
797 status = RTEMS_UNSATISFIED;
792
798
793 switch( lfrCurrentMode )
799 switch( lfrCurrentMode )
794 {
800 {
795 case LFR_MODE_STANDBY:
801 case LFR_MODE_STANDBY:
796 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
802 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
797 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
803 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
798 {
804 {
799 launch_spectral_matrix( );
805 launch_spectral_matrix( );
800 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
806 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
801 }
807 }
802 break;
808 break;
803 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
809 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
804 status = restart_asm_activities( LFR_MODE_SBM1 );
810 status = restart_asm_activities( LFR_MODE_SBM1 );
805 status = LFR_SUCCESSFUL;
811 status = LFR_SUCCESSFUL;
806 update_last_valid_transition_date( transitionCoarseTime );
812 update_last_valid_transition_date( transitionCoarseTime );
807 break;
813 break;
808 case LFR_MODE_BURST:
814 case LFR_MODE_BURST:
809 status = stop_current_mode(); // stop the current mode
815 status = stop_current_mode(); // stop the current mode
810 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
816 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
811 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
817 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
812 {
818 {
813 launch_spectral_matrix( );
819 launch_spectral_matrix( );
814 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
820 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
815 }
821 }
816 break;
822 break;
817 case LFR_MODE_SBM2:
823 case LFR_MODE_SBM2:
818 status = restart_asm_activities( LFR_MODE_SBM1 );
824 status = restart_asm_activities( LFR_MODE_SBM1 );
819 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
825 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
820 update_last_valid_transition_date( transitionCoarseTime );
826 update_last_valid_transition_date( transitionCoarseTime );
821 break;
827 break;
822 default:
828 default:
823 break;
829 break;
824 }
830 }
825
831
826 if (status != RTEMS_SUCCESSFUL)
832 if (status != RTEMS_SUCCESSFUL)
827 {
833 {
828 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
834 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
829 status = RTEMS_UNSATISFIED;
835 status = RTEMS_UNSATISFIED;
830 }
836 }
831
837
832 return status;
838 return status;
833 }
839 }
834
840
835 int enter_mode_sbm2( unsigned int transitionCoarseTime )
841 int enter_mode_sbm2( unsigned int transitionCoarseTime )
836 {
842 {
837 /** This function is used to start the SBM2 mode.
843 /** This function is used to start the SBM2 mode.
838 *
844 *
839 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
845 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
840 *
846 *
841 * @return RTEMS directive status codes:
847 * @return RTEMS directive status codes:
842 * - RTEMS_SUCCESSFUL - task restarted successfully
848 * - RTEMS_SUCCESSFUL - task restarted successfully
843 * - RTEMS_INVALID_ID - task id invalid
849 * - RTEMS_INVALID_ID - task id invalid
844 * - RTEMS_INCORRECT_STATE - task never started
850 * - RTEMS_INCORRECT_STATE - task never started
845 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
851 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
846 *
852 *
847 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
853 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
848 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
854 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
849 * cases, the acquisition is completely restarted.
855 * cases, the acquisition is completely restarted.
850 *
856 *
851 */
857 */
852
858
853 int status;
859 int status;
854
860
855 #ifdef PRINT_TASK_STATISTICS
861 #ifdef PRINT_TASK_STATISTICS
856 rtems_cpu_usage_reset();
862 rtems_cpu_usage_reset();
857 #endif
863 #endif
858
864
859 status = RTEMS_UNSATISFIED;
865 status = RTEMS_UNSATISFIED;
860
866
861 switch( lfrCurrentMode )
867 switch( lfrCurrentMode )
862 {
868 {
863 case LFR_MODE_STANDBY:
869 case LFR_MODE_STANDBY:
864 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
870 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
865 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
871 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
866 {
872 {
867 launch_spectral_matrix( );
873 launch_spectral_matrix( );
868 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
874 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
869 }
875 }
870 break;
876 break;
871 case LFR_MODE_NORMAL:
877 case LFR_MODE_NORMAL:
872 status = restart_asm_activities( LFR_MODE_SBM2 );
878 status = restart_asm_activities( LFR_MODE_SBM2 );
873 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
879 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
874 update_last_valid_transition_date( transitionCoarseTime );
880 update_last_valid_transition_date( transitionCoarseTime );
875 break;
881 break;
876 case LFR_MODE_BURST:
882 case LFR_MODE_BURST:
877 status = stop_current_mode(); // stop the current mode
883 status = stop_current_mode(); // stop the current mode
878 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
884 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
879 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
885 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
880 {
886 {
881 launch_spectral_matrix( );
887 launch_spectral_matrix( );
882 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
888 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
883 }
889 }
884 break;
890 break;
885 case LFR_MODE_SBM1:
891 case LFR_MODE_SBM1:
886 status = restart_asm_activities( LFR_MODE_SBM2 );
892 status = restart_asm_activities( LFR_MODE_SBM2 );
887 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
893 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
888 update_last_valid_transition_date( transitionCoarseTime );
894 update_last_valid_transition_date( transitionCoarseTime );
889 break;
895 break;
890 default:
896 default:
891 break;
897 break;
892 }
898 }
893
899
894 if (status != RTEMS_SUCCESSFUL)
900 if (status != RTEMS_SUCCESSFUL)
895 {
901 {
896 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
902 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
897 status = RTEMS_UNSATISFIED;
903 status = RTEMS_UNSATISFIED;
898 }
904 }
899
905
900 return status;
906 return status;
901 }
907 }
902
908
903 int restart_science_tasks( unsigned char lfrRequestedMode )
909 int restart_science_tasks( unsigned char lfrRequestedMode )
904 {
910 {
905 /** This function is used to restart all science tasks.
911 /** This function is used to restart all science tasks.
906 *
912 *
907 * @return RTEMS directive status codes:
913 * @return RTEMS directive status codes:
908 * - RTEMS_SUCCESSFUL - task restarted successfully
914 * - RTEMS_SUCCESSFUL - task restarted successfully
909 * - RTEMS_INVALID_ID - task id invalid
915 * - RTEMS_INVALID_ID - task id invalid
910 * - RTEMS_INCORRECT_STATE - task never started
916 * - RTEMS_INCORRECT_STATE - task never started
911 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
917 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
912 *
918 *
913 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
919 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
914 *
920 *
915 */
921 */
916
922
917 rtems_status_code status[NB_SCIENCE_TASKS];
923 rtems_status_code status[NB_SCIENCE_TASKS];
918 rtems_status_code ret;
924 rtems_status_code ret;
919
925
920 ret = RTEMS_SUCCESSFUL;
926 ret = RTEMS_SUCCESSFUL;
921
927
922 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
928 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
923 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
929 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
924 {
930 {
925 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
931 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
926 }
932 }
927
933
928 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
934 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
929 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
935 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
930 {
936 {
931 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
937 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
932 }
938 }
933
939
934 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
940 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
935 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
941 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
936 {
942 {
937 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
943 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
938 }
944 }
939
945
940 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
946 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
941 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
947 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
942 {
948 {
943 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
949 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
944 }
950 }
945
951
946 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
952 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
947 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
953 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
948 {
954 {
949 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
955 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
950 }
956 }
951
957
952 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
958 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
953 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
959 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
954 {
960 {
955 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
961 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
956 }
962 }
957
963
958 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
964 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
959 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
965 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
960 {
966 {
961 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
967 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
962 }
968 }
963
969
964 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
970 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
965 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
971 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
966 {
972 {
967 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
973 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
968 }
974 }
969
975
970 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
976 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
971 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
977 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
972 {
978 {
973 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
979 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
974 }
980 }
975
981
976 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
982 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
977 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
983 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
978 {
984 {
979 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
985 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
980 }
986 }
981
987
982 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
988 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
983 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
989 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
984 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
990 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
985 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
991 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
986 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
992 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
987 {
993 {
988 ret = RTEMS_UNSATISFIED;
994 ret = RTEMS_UNSATISFIED;
989 }
995 }
990
996
991 return ret;
997 return ret;
992 }
998 }
993
999
994 int restart_asm_tasks( unsigned char lfrRequestedMode )
1000 int restart_asm_tasks( unsigned char lfrRequestedMode )
995 {
1001 {
996 /** This function is used to restart average spectral matrices tasks.
1002 /** This function is used to restart average spectral matrices tasks.
997 *
1003 *
998 * @return RTEMS directive status codes:
1004 * @return RTEMS directive status codes:
999 * - RTEMS_SUCCESSFUL - task restarted successfully
1005 * - RTEMS_SUCCESSFUL - task restarted successfully
1000 * - RTEMS_INVALID_ID - task id invalid
1006 * - RTEMS_INVALID_ID - task id invalid
1001 * - RTEMS_INCORRECT_STATE - task never started
1007 * - RTEMS_INCORRECT_STATE - task never started
1002 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
1008 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
1003 *
1009 *
1004 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
1010 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
1005 *
1011 *
1006 */
1012 */
1007
1013
1008 rtems_status_code status[NB_ASM_TASKS];
1014 rtems_status_code status[NB_ASM_TASKS];
1009 rtems_status_code ret;
1015 rtems_status_code ret;
1010
1016
1011 ret = RTEMS_SUCCESSFUL;
1017 ret = RTEMS_SUCCESSFUL;
1012
1018
1013 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1019 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1014 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1020 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1015 {
1021 {
1016 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1022 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1017 }
1023 }
1018
1024
1019 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1025 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1020 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1026 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1021 {
1027 {
1022 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1028 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1023 }
1029 }
1024
1030
1025 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1031 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1026 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1032 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1027 {
1033 {
1028 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1034 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1029 }
1035 }
1030
1036
1031 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1037 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1032 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1038 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1033 {
1039 {
1034 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1040 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1035 }
1041 }
1036
1042
1037 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1043 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1038 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1044 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1039 {
1045 {
1040 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1046 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1041 }
1047 }
1042
1048
1043 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1049 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1044 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1050 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1045 {
1051 {
1046 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1052 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1047 }
1053 }
1048
1054
1049 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1055 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1050 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1056 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1051 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1057 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1052 {
1058 {
1053 ret = RTEMS_UNSATISFIED;
1059 ret = RTEMS_UNSATISFIED;
1054 }
1060 }
1055
1061
1056 return ret;
1062 return ret;
1057 }
1063 }
1058
1064
1059 int suspend_science_tasks( void )
1065 int suspend_science_tasks( void )
1060 {
1066 {
1061 /** This function suspends the science tasks.
1067 /** This function suspends the science tasks.
1062 *
1068 *
1063 * @return RTEMS directive status codes:
1069 * @return RTEMS directive status codes:
1064 * - RTEMS_SUCCESSFUL - task restarted successfully
1070 * - RTEMS_SUCCESSFUL - task restarted successfully
1065 * - RTEMS_INVALID_ID - task id invalid
1071 * - RTEMS_INVALID_ID - task id invalid
1066 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1072 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1067 *
1073 *
1068 */
1074 */
1069
1075
1070 rtems_status_code status;
1076 rtems_status_code status;
1071
1077
1072 PRINTF("in suspend_science_tasks\n")
1078 PRINTF("in suspend_science_tasks\n")
1073
1079
1074 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1080 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1075 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1081 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1076 {
1082 {
1077 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1083 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1078 }
1084 }
1079 else
1085 else
1080 {
1086 {
1081 status = RTEMS_SUCCESSFUL;
1087 status = RTEMS_SUCCESSFUL;
1082 }
1088 }
1083 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1089 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1084 {
1090 {
1085 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1091 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1086 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1092 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1087 {
1093 {
1088 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1094 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1089 }
1095 }
1090 else
1096 else
1091 {
1097 {
1092 status = RTEMS_SUCCESSFUL;
1098 status = RTEMS_SUCCESSFUL;
1093 }
1099 }
1094 }
1100 }
1095 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1101 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1096 {
1102 {
1097 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1103 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1098 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1104 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1099 {
1105 {
1100 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1106 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1101 }
1107 }
1102 else
1108 else
1103 {
1109 {
1104 status = RTEMS_SUCCESSFUL;
1110 status = RTEMS_SUCCESSFUL;
1105 }
1111 }
1106 }
1112 }
1107 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1113 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1108 {
1114 {
1109 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1115 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1110 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1116 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1111 {
1117 {
1112 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1118 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1113 }
1119 }
1114 else
1120 else
1115 {
1121 {
1116 status = RTEMS_SUCCESSFUL;
1122 status = RTEMS_SUCCESSFUL;
1117 }
1123 }
1118 }
1124 }
1119 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1125 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1120 {
1126 {
1121 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1127 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1122 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1128 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1123 {
1129 {
1124 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1130 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1125 }
1131 }
1126 else
1132 else
1127 {
1133 {
1128 status = RTEMS_SUCCESSFUL;
1134 status = RTEMS_SUCCESSFUL;
1129 }
1135 }
1130 }
1136 }
1131 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1137 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1132 {
1138 {
1133 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1139 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1134 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1140 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1135 {
1141 {
1136 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1142 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1137 }
1143 }
1138 else
1144 else
1139 {
1145 {
1140 status = RTEMS_SUCCESSFUL;
1146 status = RTEMS_SUCCESSFUL;
1141 }
1147 }
1142 }
1148 }
1143 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1149 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1144 {
1150 {
1145 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1151 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1146 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1152 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1147 {
1153 {
1148 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1154 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1149 }
1155 }
1150 else
1156 else
1151 {
1157 {
1152 status = RTEMS_SUCCESSFUL;
1158 status = RTEMS_SUCCESSFUL;
1153 }
1159 }
1154 }
1160 }
1155 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1161 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1156 {
1162 {
1157 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1163 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1158 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1164 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1159 {
1165 {
1160 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1166 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1161 }
1167 }
1162 else
1168 else
1163 {
1169 {
1164 status = RTEMS_SUCCESSFUL;
1170 status = RTEMS_SUCCESSFUL;
1165 }
1171 }
1166 }
1172 }
1167 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1173 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1168 {
1174 {
1169 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1175 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1170 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1176 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1171 {
1177 {
1172 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1178 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1173 }
1179 }
1174 else
1180 else
1175 {
1181 {
1176 status = RTEMS_SUCCESSFUL;
1182 status = RTEMS_SUCCESSFUL;
1177 }
1183 }
1178 }
1184 }
1179 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1185 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1180 {
1186 {
1181 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1187 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1182 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1188 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1183 {
1189 {
1184 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1190 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1185 }
1191 }
1186 else
1192 else
1187 {
1193 {
1188 status = RTEMS_SUCCESSFUL;
1194 status = RTEMS_SUCCESSFUL;
1189 }
1195 }
1190 }
1196 }
1191
1197
1192 return status;
1198 return status;
1193 }
1199 }
1194
1200
1195 int suspend_asm_tasks( void )
1201 int suspend_asm_tasks( void )
1196 {
1202 {
1197 /** This function suspends the science tasks.
1203 /** This function suspends the science tasks.
1198 *
1204 *
1199 * @return RTEMS directive status codes:
1205 * @return RTEMS directive status codes:
1200 * - RTEMS_SUCCESSFUL - task restarted successfully
1206 * - RTEMS_SUCCESSFUL - task restarted successfully
1201 * - RTEMS_INVALID_ID - task id invalid
1207 * - RTEMS_INVALID_ID - task id invalid
1202 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1208 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1203 *
1209 *
1204 */
1210 */
1205
1211
1206 rtems_status_code status;
1212 rtems_status_code status;
1207
1213
1208 PRINTF("in suspend_science_tasks\n")
1214 PRINTF("in suspend_science_tasks\n")
1209
1215
1210 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1216 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1211 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1217 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1212 {
1218 {
1213 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1219 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1214 }
1220 }
1215 else
1221 else
1216 {
1222 {
1217 status = RTEMS_SUCCESSFUL;
1223 status = RTEMS_SUCCESSFUL;
1218 }
1224 }
1219
1225
1220 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1226 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1221 {
1227 {
1222 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1228 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1223 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1229 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1224 {
1230 {
1225 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1231 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1226 }
1232 }
1227 else
1233 else
1228 {
1234 {
1229 status = RTEMS_SUCCESSFUL;
1235 status = RTEMS_SUCCESSFUL;
1230 }
1236 }
1231 }
1237 }
1232
1238
1233 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1239 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1234 {
1240 {
1235 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1241 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1236 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1242 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1237 {
1243 {
1238 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1244 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1239 }
1245 }
1240 else
1246 else
1241 {
1247 {
1242 status = RTEMS_SUCCESSFUL;
1248 status = RTEMS_SUCCESSFUL;
1243 }
1249 }
1244 }
1250 }
1245
1251
1246 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1252 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1247 {
1253 {
1248 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1254 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1249 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1255 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1250 {
1256 {
1251 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1257 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1252 }
1258 }
1253 else
1259 else
1254 {
1260 {
1255 status = RTEMS_SUCCESSFUL;
1261 status = RTEMS_SUCCESSFUL;
1256 }
1262 }
1257 }
1263 }
1258
1264
1259 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1265 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1260 {
1266 {
1261 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1267 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1262 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1268 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1263 {
1269 {
1264 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1270 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1265 }
1271 }
1266 else
1272 else
1267 {
1273 {
1268 status = RTEMS_SUCCESSFUL;
1274 status = RTEMS_SUCCESSFUL;
1269 }
1275 }
1270 }
1276 }
1271
1277
1272 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1278 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1273 {
1279 {
1274 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1280 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1275 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1281 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1276 {
1282 {
1277 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1283 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1278 }
1284 }
1279 else
1285 else
1280 {
1286 {
1281 status = RTEMS_SUCCESSFUL;
1287 status = RTEMS_SUCCESSFUL;
1282 }
1288 }
1283 }
1289 }
1284
1290
1285 return status;
1291 return status;
1286 }
1292 }
1287
1293
1288 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1294 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1289 {
1295 {
1290
1296
1291 WFP_reset_current_ring_nodes();
1297 WFP_reset_current_ring_nodes();
1292
1298
1293 reset_waveform_picker_regs();
1299 reset_waveform_picker_regs();
1294
1300
1295 set_wfp_burst_enable_register( mode );
1301 set_wfp_burst_enable_register( mode );
1296
1302
1297 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1303 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1298 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1304 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1299
1305
1300 if (transitionCoarseTime == 0)
1306 if (transitionCoarseTime == 0)
1301 {
1307 {
1302 // instant transition means transition on the next valid date
1308 // instant transition means transition on the next valid date
1303 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1309 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1304 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1310 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1305 }
1311 }
1306 else
1312 else
1307 {
1313 {
1308 waveform_picker_regs->start_date = transitionCoarseTime;
1314 waveform_picker_regs->start_date = transitionCoarseTime;
1309 }
1315 }
1310
1316
1311 update_last_valid_transition_date(waveform_picker_regs->start_date);
1317 update_last_valid_transition_date(waveform_picker_regs->start_date);
1312
1318
1313 }
1319 }
1314
1320
1315 void launch_spectral_matrix( void )
1321 void launch_spectral_matrix( void )
1316 {
1322 {
1317 SM_reset_current_ring_nodes();
1323 SM_reset_current_ring_nodes();
1318
1324
1319 reset_spectral_matrix_regs();
1325 reset_spectral_matrix_regs();
1320
1326
1321 reset_nb_sm();
1327 reset_nb_sm();
1322
1328
1323 set_sm_irq_onNewMatrix( 1 );
1329 set_sm_irq_onNewMatrix( 1 );
1324
1330
1325 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1331 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1326 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1332 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1327
1333
1328 }
1334 }
1329
1335
1330 void set_sm_irq_onNewMatrix( unsigned char value )
1336 void set_sm_irq_onNewMatrix( unsigned char value )
1331 {
1337 {
1332 if (value == 1)
1338 if (value == 1)
1333 {
1339 {
1334 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1340 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1335 }
1341 }
1336 else
1342 else
1337 {
1343 {
1338 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1344 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1339 }
1345 }
1340 }
1346 }
1341
1347
1342 void set_sm_irq_onError( unsigned char value )
1348 void set_sm_irq_onError( unsigned char value )
1343 {
1349 {
1344 if (value == 1)
1350 if (value == 1)
1345 {
1351 {
1346 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1352 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1347 }
1353 }
1348 else
1354 else
1349 {
1355 {
1350 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1356 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1351 }
1357 }
1352 }
1358 }
1353
1359
1354 //*****************************
1360 //*****************************
1355 // CONFIGURE CALIBRATION SIGNAL
1361 // CONFIGURE CALIBRATION SIGNAL
1356 void setCalibrationPrescaler( unsigned int prescaler )
1362 void setCalibrationPrescaler( unsigned int prescaler )
1357 {
1363 {
1358 // prescaling of the master clock (25 MHz)
1364 // prescaling of the master clock (25 MHz)
1359 // master clock is divided by 2^prescaler
1365 // master clock is divided by 2^prescaler
1360 time_management_regs->calPrescaler = prescaler;
1366 time_management_regs->calPrescaler = prescaler;
1361 }
1367 }
1362
1368
1363 void setCalibrationDivisor( unsigned int divisionFactor )
1369 void setCalibrationDivisor( unsigned int divisionFactor )
1364 {
1370 {
1365 // division of the prescaled clock by the division factor
1371 // division of the prescaled clock by the division factor
1366 time_management_regs->calDivisor = divisionFactor;
1372 time_management_regs->calDivisor = divisionFactor;
1367 }
1373 }
1368
1374
1369 void setCalibrationData( void )
1375 void setCalibrationData( void )
1370 {
1376 {
1371 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1377 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1372 *
1378 *
1373 * @param void
1379 * @param void
1374 *
1380 *
1375 * @return void
1381 * @return void
1376 *
1382 *
1377 */
1383 */
1378
1384
1379 unsigned int k;
1385 unsigned int k;
1380 unsigned short data;
1386 unsigned short data;
1381 float val;
1387 float val;
1382 float Ts;
1388 float Ts;
1383
1389
1384 time_management_regs->calDataPtr = INIT_CHAR;
1390 time_management_regs->calDataPtr = INIT_CHAR;
1385
1391
1386 Ts = 1 / CAL_FS;
1392 Ts = 1 / CAL_FS;
1387
1393
1388 // build the signal for the SCM calibration
1394 // build the signal for the SCM calibration
1389 for (k = 0; k < CAL_NB_PTS; k++)
1395 for (k = 0; k < CAL_NB_PTS; k++)
1390 {
1396 {
1391 val = sin( 2 * pi * CAL_F0 * k * Ts )
1397 val = sin( 2 * pi * CAL_F0 * k * Ts )
1392 + sin( 2 * pi * CAL_F1 * k * Ts );
1398 + sin( 2 * pi * CAL_F1 * k * Ts );
1393 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1399 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1394 time_management_regs->calData = data & CAL_DATA_MASK;
1400 time_management_regs->calData = data & CAL_DATA_MASK;
1395 }
1401 }
1396 }
1402 }
1397
1403
1398 void setCalibrationDataInterleaved( void )
1404 void setCalibrationDataInterleaved( void )
1399 {
1405 {
1400 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1406 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1401 *
1407 *
1402 * @param void
1408 * @param void
1403 *
1409 *
1404 * @return void
1410 * @return void
1405 *
1411 *
1406 * In interleaved mode, one can store more values than in normal mode.
1412 * In interleaved mode, one can store more values than in normal mode.
1407 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1413 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1408 * T store 3 values, one need two write operations.
1414 * T store 3 values, one need two write operations.
1409 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1415 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1410 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1416 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1411 *
1417 *
1412 */
1418 */
1413
1419
1414 unsigned int k;
1420 unsigned int k;
1415 float val;
1421 float val;
1416 float Ts;
1422 float Ts;
1417 unsigned short data[CAL_NB_PTS_INTER];
1423 unsigned short data[CAL_NB_PTS_INTER];
1418 unsigned char *dataPtr;
1424 unsigned char *dataPtr;
1419
1425
1420 Ts = 1 / CAL_FS_INTER;
1426 Ts = 1 / CAL_FS_INTER;
1421
1427
1422 time_management_regs->calDataPtr = INIT_CHAR;
1428 time_management_regs->calDataPtr = INIT_CHAR;
1423
1429
1424 // build the signal for the SCM calibration
1430 // build the signal for the SCM calibration
1425 for (k=0; k<CAL_NB_PTS_INTER; k++)
1431 for (k=0; k<CAL_NB_PTS_INTER; k++)
1426 {
1432 {
1427 val = sin( 2 * pi * CAL_F0 * k * Ts )
1433 val = sin( 2 * pi * CAL_F0 * k * Ts )
1428 + sin( 2 * pi * CAL_F1 * k * Ts );
1434 + sin( 2 * pi * CAL_F1 * k * Ts );
1429 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1435 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1430 }
1436 }
1431
1437
1432 // write the signal in interleaved mode
1438 // write the signal in interleaved mode
1433 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1439 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1434 {
1440 {
1435 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1441 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1436 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1442 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1437 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1443 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1438 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1444 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1439 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1445 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1440 }
1446 }
1441 }
1447 }
1442
1448
1443 void setCalibrationReload( bool state)
1449 void setCalibrationReload( bool state)
1444 {
1450 {
1445 if (state == true)
1451 if (state == true)
1446 {
1452 {
1447 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1453 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1448 }
1454 }
1449 else
1455 else
1450 {
1456 {
1451 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1457 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1452 }
1458 }
1453 }
1459 }
1454
1460
1455 void setCalibrationEnable( bool state )
1461 void setCalibrationEnable( bool state )
1456 {
1462 {
1457 // this bit drives the multiplexer
1463 // this bit drives the multiplexer
1458 if (state == true)
1464 if (state == true)
1459 {
1465 {
1460 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1466 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1461 }
1467 }
1462 else
1468 else
1463 {
1469 {
1464 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1470 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1465 }
1471 }
1466 }
1472 }
1467
1473
1468 void setCalibrationInterleaved( bool state )
1474 void setCalibrationInterleaved( bool state )
1469 {
1475 {
1470 // this bit drives the multiplexer
1476 // this bit drives the multiplexer
1471 if (state == true)
1477 if (state == true)
1472 {
1478 {
1473 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1479 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1474 }
1480 }
1475 else
1481 else
1476 {
1482 {
1477 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1483 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1478 }
1484 }
1479 }
1485 }
1480
1486
1481 void setCalibration( bool state )
1487 void setCalibration( bool state )
1482 {
1488 {
1483 if (state == true)
1489 if (state == true)
1484 {
1490 {
1485 setCalibrationEnable( true );
1491 setCalibrationEnable( true );
1486 setCalibrationReload( false );
1492 setCalibrationReload( false );
1487 set_hk_lfr_calib_enable( true );
1493 set_hk_lfr_calib_enable( true );
1488 }
1494 }
1489 else
1495 else
1490 {
1496 {
1491 setCalibrationEnable( false );
1497 setCalibrationEnable( false );
1492 setCalibrationReload( true );
1498 setCalibrationReload( true );
1493 set_hk_lfr_calib_enable( false );
1499 set_hk_lfr_calib_enable( false );
1494 }
1500 }
1495 }
1501 }
1496
1502
1497 void configureCalibration( bool interleaved )
1503 void configureCalibration( bool interleaved )
1498 {
1504 {
1499 setCalibration( false );
1505 setCalibration( false );
1500 if ( interleaved == true )
1506 if ( interleaved == true )
1501 {
1507 {
1502 setCalibrationInterleaved( true );
1508 setCalibrationInterleaved( true );
1503 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1509 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1504 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1510 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1505 setCalibrationDataInterleaved();
1511 setCalibrationDataInterleaved();
1506 }
1512 }
1507 else
1513 else
1508 {
1514 {
1509 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1515 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1510 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1516 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1511 setCalibrationData();
1517 setCalibrationData();
1512 }
1518 }
1513 }
1519 }
1514
1520
1515 //****************
1521 //****************
1516 // CLOSING ACTIONS
1522 // CLOSING ACTIONS
1517 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1523 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1518 {
1524 {
1519 /** This function is used to update the HK packets statistics after a successful TC execution.
1525 /** This function is used to update the HK packets statistics after a successful TC execution.
1520 *
1526 *
1521 * @param TC points to the TC being processed
1527 * @param TC points to the TC being processed
1522 * @param time is the time used to date the TC execution
1528 * @param time is the time used to date the TC execution
1523 *
1529 *
1524 */
1530 */
1525
1531
1526 unsigned int val;
1532 unsigned int val;
1527
1533
1528 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1534 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1529 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1535 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1530 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1536 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1531 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1537 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1532 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1538 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1533 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1539 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1534 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1540 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1535 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1541 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1536 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1542 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1537 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1543 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1538 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1544 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1539 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1545 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1540
1546
1541 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1547 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1542 val++;
1548 val++;
1543 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1549 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1544 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1550 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1545 }
1551 }
1546
1552
1547 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1553 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1548 {
1554 {
1549 /** This function is used to update the HK packets statistics after a TC rejection.
1555 /** This function is used to update the HK packets statistics after a TC rejection.
1550 *
1556 *
1551 * @param TC points to the TC being processed
1557 * @param TC points to the TC being processed
1552 * @param time is the time used to date the TC rejection
1558 * @param time is the time used to date the TC rejection
1553 *
1559 *
1554 */
1560 */
1555
1561
1556 unsigned int val;
1562 unsigned int val;
1557
1563
1558 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1564 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1559 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1565 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1560 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1566 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1561 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1567 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1562 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1568 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1563 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1569 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1564 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1570 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1565 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1571 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1566 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1572 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1567 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1573 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1568 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1574 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1569 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1575 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1570
1576
1571 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1577 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1572 val++;
1578 val++;
1573 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1579 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1574 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1580 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1575 }
1581 }
1576
1582
1577 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1583 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1578 {
1584 {
1579 /** This function is the last step of the TC execution workflow.
1585 /** This function is the last step of the TC execution workflow.
1580 *
1586 *
1581 * @param TC points to the TC being processed
1587 * @param TC points to the TC being processed
1582 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1588 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1583 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1589 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1584 * @param time is the time used to date the TC execution
1590 * @param time is the time used to date the TC execution
1585 *
1591 *
1586 */
1592 */
1587
1593
1588 unsigned char requestedMode;
1594 unsigned char requestedMode;
1589
1595
1590 if (result == LFR_SUCCESSFUL)
1596 if (result == LFR_SUCCESSFUL)
1591 {
1597 {
1592 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1598 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1593 &
1599 &
1594 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1600 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1595 )
1601 )
1596 {
1602 {
1597 send_tm_lfr_tc_exe_success( TC, queue_id );
1603 send_tm_lfr_tc_exe_success( TC, queue_id );
1598 }
1604 }
1599 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1605 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1600 {
1606 {
1601 //**********************************
1607 //**********************************
1602 // UPDATE THE LFRMODE LOCAL VARIABLE
1608 // UPDATE THE LFRMODE LOCAL VARIABLE
1603 requestedMode = TC->dataAndCRC[1];
1609 requestedMode = TC->dataAndCRC[1];
1604 updateLFRCurrentMode( requestedMode );
1610 updateLFRCurrentMode( requestedMode );
1605 }
1611 }
1606 }
1612 }
1607 else if (result == LFR_EXE_ERROR)
1613 else if (result == LFR_EXE_ERROR)
1608 {
1614 {
1609 send_tm_lfr_tc_exe_error( TC, queue_id );
1615 send_tm_lfr_tc_exe_error( TC, queue_id );
1610 }
1616 }
1611 }
1617 }
1612
1618
1613 //***************************
1619 //***************************
1614 // Interrupt Service Routines
1620 // Interrupt Service Routines
1615 rtems_isr commutation_isr1( rtems_vector_number vector )
1621 rtems_isr commutation_isr1( rtems_vector_number vector )
1616 {
1622 {
1617 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1623 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1618 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1624 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1619 }
1625 }
1620 }
1626 }
1621
1627
1622 rtems_isr commutation_isr2( rtems_vector_number vector )
1628 rtems_isr commutation_isr2( rtems_vector_number vector )
1623 {
1629 {
1624 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1630 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1625 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1631 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1626 }
1632 }
1627 }
1633 }
1628
1634
1629 //****************
1635 //****************
1630 // OTHER FUNCTIONS
1636 // OTHER FUNCTIONS
1631 void updateLFRCurrentMode( unsigned char requestedMode )
1637 void updateLFRCurrentMode( unsigned char requestedMode )
1632 {
1638 {
1633 /** This function updates the value of the global variable lfrCurrentMode.
1639 /** This function updates the value of the global variable lfrCurrentMode.
1634 *
1640 *
1635 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1641 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1636 *
1642 *
1637 */
1643 */
1638
1644
1639 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1645 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1640 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1646 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1641 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1647 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1642 lfrCurrentMode = requestedMode;
1648 lfrCurrentMode = requestedMode;
1643 }
1649 }
1644
1650
1645 void set_lfr_soft_reset( unsigned char value )
1651 void set_lfr_soft_reset( unsigned char value )
1646 {
1652 {
1647 if (value == 1)
1653 if (value == 1)
1648 {
1654 {
1649 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1655 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1650 }
1656 }
1651 else
1657 else
1652 {
1658 {
1653 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1659 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1654 }
1660 }
1655 }
1661 }
1656
1662
1657 void reset_lfr( void )
1663 void reset_lfr( void )
1658 {
1664 {
1659 set_lfr_soft_reset( 1 );
1665 set_lfr_soft_reset( 1 );
1660
1666
1661 set_lfr_soft_reset( 0 );
1667 set_lfr_soft_reset( 0 );
1662
1668
1663 set_hk_lfr_sc_potential_flag( true );
1669 set_hk_lfr_sc_potential_flag( true );
1664 }
1670 }
@@ -1,1780 +1,1788
1 /** Functions to load and dump parameters in the LFR registers.
1 /** Functions to load and dump parameters in the LFR registers.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TC related to parameter loading and dumping.\n
6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 * TC_LFR_LOAD_COMMON_PAR\n
7 * TC_LFR_LOAD_COMMON_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
12 *
12 *
13 */
13 */
14
14
15 #include "tc_load_dump_parameters.h"
15 #include "tc_load_dump_parameters.h"
16
16
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1 = {0};
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1 = {0};
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2 = {0};
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2 = {0};
19 ring_node kcoefficient_node_1 = {0};
19 ring_node kcoefficient_node_1 = {0};
20 ring_node kcoefficient_node_2 = {0};
20 ring_node kcoefficient_node_2 = {0};
21
21
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 {
23 {
24 /** This function updates the LFR registers with the incoming common parameters.
24 /** This function updates the LFR registers with the incoming common parameters.
25 *
25 *
26 * @param TC points to the TeleCommand packet that is being processed
26 * @param TC points to the TeleCommand packet that is being processed
27 *
27 *
28 *
28 *
29 */
29 */
30
30
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 set_wfp_data_shaping( );
33 set_wfp_data_shaping( );
34 return LFR_SUCCESSFUL;
34 return LFR_SUCCESSFUL;
35 }
35 }
36
36
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 {
38 {
39 /** This function updates the LFR registers with the incoming normal parameters.
39 /** This function updates the LFR registers with the incoming normal parameters.
40 *
40 *
41 * @param TC points to the TeleCommand packet that is being processed
41 * @param TC points to the TeleCommand packet that is being processed
42 * @param queue_id is the id of the queue which handles TM related to this execution step
42 * @param queue_id is the id of the queue which handles TM related to this execution step
43 *
43 *
44 */
44 */
45
45
46 int result;
46 int result;
47 int flag;
47 int flag;
48 rtems_status_code status;
48 rtems_status_code status;
49
49
50 flag = LFR_SUCCESSFUL;
50 flag = LFR_SUCCESSFUL;
51
51
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 flag = LFR_DEFAULT;
55 flag = LFR_DEFAULT;
56 }
56 }
57
57
58 // CHECK THE PARAMETERS SET CONSISTENCY
58 // CHECK THE PARAMETERS SET CONSISTENCY
59 if (flag == LFR_SUCCESSFUL)
59 if (flag == LFR_SUCCESSFUL)
60 {
60 {
61 flag = check_normal_par_consistency( TC, queue_id );
61 flag = check_normal_par_consistency( TC, queue_id );
62 }
62 }
63
63
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 if (flag == LFR_SUCCESSFUL)
65 if (flag == LFR_SUCCESSFUL)
66 {
66 {
67 result = set_sy_lfr_n_swf_l( TC );
67 result = set_sy_lfr_n_swf_l( TC );
68 result = set_sy_lfr_n_swf_p( TC );
68 result = set_sy_lfr_n_swf_p( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
71 result = set_sy_lfr_n_asm_p( TC );
71 result = set_sy_lfr_n_asm_p( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
73 }
73 }
74
74
75 return flag;
75 return flag;
76 }
76 }
77
77
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 {
79 {
80 /** This function updates the LFR registers with the incoming burst parameters.
80 /** This function updates the LFR registers with the incoming burst parameters.
81 *
81 *
82 * @param TC points to the TeleCommand packet that is being processed
82 * @param TC points to the TeleCommand packet that is being processed
83 * @param queue_id is the id of the queue which handles TM related to this execution step
83 * @param queue_id is the id of the queue which handles TM related to this execution step
84 *
84 *
85 */
85 */
86
86
87 int flag;
87 int flag;
88 rtems_status_code status;
88 rtems_status_code status;
89 unsigned char sy_lfr_b_bp_p0;
89 unsigned char sy_lfr_b_bp_p0;
90 unsigned char sy_lfr_b_bp_p1;
90 unsigned char sy_lfr_b_bp_p1;
91 float aux;
91 float aux;
92
92
93 flag = LFR_SUCCESSFUL;
93 flag = LFR_SUCCESSFUL;
94
94
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 flag = LFR_DEFAULT;
97 flag = LFR_DEFAULT;
98 }
98 }
99
99
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102
102
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
104 if (flag == LFR_SUCCESSFUL)
104 if (flag == LFR_SUCCESSFUL)
105 {
105 {
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 {
107 {
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
109 flag = WRONG_APP_DATA;
109 flag = WRONG_APP_DATA;
110 }
110 }
111 }
111 }
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
113 if (flag == LFR_SUCCESSFUL)
113 if (flag == LFR_SUCCESSFUL)
114 {
114 {
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 {
116 {
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
118 flag = WRONG_APP_DATA;
118 flag = WRONG_APP_DATA;
119 }
119 }
120 }
120 }
121 //****************************************************************
121 //****************************************************************
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 if (flag == LFR_SUCCESSFUL)
123 if (flag == LFR_SUCCESSFUL)
124 {
124 {
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
128 if (aux > FLOAT_EQUAL_ZERO)
128 if (aux > FLOAT_EQUAL_ZERO)
129 {
129 {
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
131 flag = LFR_DEFAULT;
131 flag = LFR_DEFAULT;
132 }
132 }
133 }
133 }
134
134
135 // SET THE PARAMETERS
135 // SET THE PARAMETERS
136 if (flag == LFR_SUCCESSFUL)
136 if (flag == LFR_SUCCESSFUL)
137 {
137 {
138 flag = set_sy_lfr_b_bp_p0( TC );
138 flag = set_sy_lfr_b_bp_p0( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
140 }
140 }
141
141
142 return flag;
142 return flag;
143 }
143 }
144
144
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 {
146 {
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 *
148 *
149 * @param TC points to the TeleCommand packet that is being processed
149 * @param TC points to the TeleCommand packet that is being processed
150 * @param queue_id is the id of the queue which handles TM related to this execution step
150 * @param queue_id is the id of the queue which handles TM related to this execution step
151 *
151 *
152 */
152 */
153
153
154 int flag;
154 int flag;
155 rtems_status_code status;
155 rtems_status_code status;
156 unsigned char sy_lfr_s1_bp_p0;
156 unsigned char sy_lfr_s1_bp_p0;
157 unsigned char sy_lfr_s1_bp_p1;
157 unsigned char sy_lfr_s1_bp_p1;
158 float aux;
158 float aux;
159
159
160 flag = LFR_SUCCESSFUL;
160 flag = LFR_SUCCESSFUL;
161
161
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 flag = LFR_DEFAULT;
164 flag = LFR_DEFAULT;
165 }
165 }
166
166
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169
169
170 // sy_lfr_s1_bp_p0
170 // sy_lfr_s1_bp_p0
171 if (flag == LFR_SUCCESSFUL)
171 if (flag == LFR_SUCCESSFUL)
172 {
172 {
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 {
174 {
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
176 flag = WRONG_APP_DATA;
176 flag = WRONG_APP_DATA;
177 }
177 }
178 }
178 }
179 // sy_lfr_s1_bp_p1
179 // sy_lfr_s1_bp_p1
180 if (flag == LFR_SUCCESSFUL)
180 if (flag == LFR_SUCCESSFUL)
181 {
181 {
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 {
183 {
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
185 flag = WRONG_APP_DATA;
185 flag = WRONG_APP_DATA;
186 }
186 }
187 }
187 }
188 //******************************************************************
188 //******************************************************************
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 if (flag == LFR_SUCCESSFUL)
190 if (flag == LFR_SUCCESSFUL)
191 {
191 {
192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
193 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
193 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
194 if (aux > FLOAT_EQUAL_ZERO)
194 if (aux > FLOAT_EQUAL_ZERO)
195 {
195 {
196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
197 flag = LFR_DEFAULT;
197 flag = LFR_DEFAULT;
198 }
198 }
199 }
199 }
200
200
201 // SET THE PARAMETERS
201 // SET THE PARAMETERS
202 if (flag == LFR_SUCCESSFUL)
202 if (flag == LFR_SUCCESSFUL)
203 {
203 {
204 flag = set_sy_lfr_s1_bp_p0( TC );
204 flag = set_sy_lfr_s1_bp_p0( TC );
205 flag = set_sy_lfr_s1_bp_p1( TC );
205 flag = set_sy_lfr_s1_bp_p1( TC );
206 }
206 }
207
207
208 return flag;
208 return flag;
209 }
209 }
210
210
211 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
211 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
212 {
212 {
213 /** This function updates the LFR registers with the incoming sbm2 parameters.
213 /** This function updates the LFR registers with the incoming sbm2 parameters.
214 *
214 *
215 * @param TC points to the TeleCommand packet that is being processed
215 * @param TC points to the TeleCommand packet that is being processed
216 * @param queue_id is the id of the queue which handles TM related to this execution step
216 * @param queue_id is the id of the queue which handles TM related to this execution step
217 *
217 *
218 */
218 */
219
219
220 int flag;
220 int flag;
221 rtems_status_code status;
221 rtems_status_code status;
222 unsigned char sy_lfr_s2_bp_p0;
222 unsigned char sy_lfr_s2_bp_p0;
223 unsigned char sy_lfr_s2_bp_p1;
223 unsigned char sy_lfr_s2_bp_p1;
224 float aux;
224 float aux;
225
225
226 flag = LFR_SUCCESSFUL;
226 flag = LFR_SUCCESSFUL;
227
227
228 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
228 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
229 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
229 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
230 flag = LFR_DEFAULT;
230 flag = LFR_DEFAULT;
231 }
231 }
232
232
233 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
233 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
234 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
234 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
235
235
236 // sy_lfr_s2_bp_p0
236 // sy_lfr_s2_bp_p0
237 if (flag == LFR_SUCCESSFUL)
237 if (flag == LFR_SUCCESSFUL)
238 {
238 {
239 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
239 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
240 {
240 {
241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
242 flag = WRONG_APP_DATA;
242 flag = WRONG_APP_DATA;
243 }
243 }
244 }
244 }
245 // sy_lfr_s2_bp_p1
245 // sy_lfr_s2_bp_p1
246 if (flag == LFR_SUCCESSFUL)
246 if (flag == LFR_SUCCESSFUL)
247 {
247 {
248 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
248 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
249 {
249 {
250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
251 flag = WRONG_APP_DATA;
251 flag = WRONG_APP_DATA;
252 }
252 }
253 }
253 }
254 //******************************************************************
254 //******************************************************************
255 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
255 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
256 if (flag == LFR_SUCCESSFUL)
256 if (flag == LFR_SUCCESSFUL)
257 {
257 {
258 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
258 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
259 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
259 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
260 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
260 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
261 if (aux > FLOAT_EQUAL_ZERO)
261 if (aux > FLOAT_EQUAL_ZERO)
262 {
262 {
263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
264 flag = LFR_DEFAULT;
264 flag = LFR_DEFAULT;
265 }
265 }
266 }
266 }
267
267
268 // SET THE PARAMETERS
268 // SET THE PARAMETERS
269 if (flag == LFR_SUCCESSFUL)
269 if (flag == LFR_SUCCESSFUL)
270 {
270 {
271 flag = set_sy_lfr_s2_bp_p0( TC );
271 flag = set_sy_lfr_s2_bp_p0( TC );
272 flag = set_sy_lfr_s2_bp_p1( TC );
272 flag = set_sy_lfr_s2_bp_p1( TC );
273 }
273 }
274
274
275 return flag;
275 return flag;
276 }
276 }
277
277
278 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
278 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
279 {
279 {
280 /** This function updates the LFR registers with the incoming sbm2 parameters.
280 /** This function updates the LFR registers with the incoming sbm2 parameters.
281 *
281 *
282 * @param TC points to the TeleCommand packet that is being processed
282 * @param TC points to the TeleCommand packet that is being processed
283 * @param queue_id is the id of the queue which handles TM related to this execution step
283 * @param queue_id is the id of the queue which handles TM related to this execution step
284 *
284 *
285 */
285 */
286
286
287 int flag;
287 int flag;
288
288
289 flag = LFR_DEFAULT;
289 flag = LFR_DEFAULT;
290
290
291 flag = set_sy_lfr_kcoeff( TC, queue_id );
291 flag = set_sy_lfr_kcoeff( TC, queue_id );
292
292
293 return flag;
293 return flag;
294 }
294 }
295
295
296 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
297 {
297 {
298 /** This function updates the LFR registers with the incoming sbm2 parameters.
298 /** This function updates the LFR registers with the incoming sbm2 parameters.
299 *
299 *
300 * @param TC points to the TeleCommand packet that is being processed
300 * @param TC points to the TeleCommand packet that is being processed
301 * @param queue_id is the id of the queue which handles TM related to this execution step
301 * @param queue_id is the id of the queue which handles TM related to this execution step
302 *
302 *
303 */
303 */
304
304
305 int flag;
305 int flag;
306
306
307 flag = LFR_DEFAULT;
307 flag = LFR_DEFAULT;
308
308
309 flag = set_sy_lfr_fbins( TC );
309 flag = set_sy_lfr_fbins( TC );
310
310
311 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
311 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
312 merge_fbins_masks();
312 merge_fbins_masks();
313
313
314 return flag;
314 return flag;
315 }
315 }
316
316
317 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
317 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
318 {
318 {
319 /** This function updates the LFR registers with the incoming sbm2 parameters.
319 /** This function updates the LFR registers with the incoming sbm2 parameters.
320 *
320 *
321 * @param TC points to the TeleCommand packet that is being processed
321 * @param TC points to the TeleCommand packet that is being processed
322 * @param queue_id is the id of the queue which handles TM related to this execution step
322 * @param queue_id is the id of the queue which handles TM related to this execution step
323 *
323 *
324 */
324 */
325
325
326 int flag;
326 int flag;
327 unsigned char k;
327 unsigned char k;
328
328
329 flag = LFR_DEFAULT;
329 flag = LFR_DEFAULT;
330 k = INIT_CHAR;
330 k = INIT_CHAR;
331
331
332 flag = check_sy_lfr_filter_parameters( TC, queue_id );
332 flag = check_sy_lfr_filter_parameters( TC, queue_id );
333
333
334 if (flag == LFR_SUCCESSFUL)
334 if (flag == LFR_SUCCESSFUL)
335 {
335 {
336 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
336 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
337 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
337 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
340 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
340 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
341 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
341 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
342 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
342 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
345 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
345 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
346 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
346 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
349 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
349 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
350 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
350 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
351
351
352 //****************************
352 //****************************
353 // store PAS filter parameters
353 // store PAS filter parameters
354 // sy_lfr_pas_filter_enabled
354 // sy_lfr_pas_filter_enabled
355 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
355 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
356 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
356 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
357 // sy_lfr_pas_filter_modulus
357 // sy_lfr_pas_filter_modulus
358 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
358 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
359 // sy_lfr_pas_filter_tbad
359 // sy_lfr_pas_filter_tbad
360 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
360 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
361 parameter_dump_packet.sy_lfr_pas_filter_tbad );
361 parameter_dump_packet.sy_lfr_pas_filter_tbad );
362 // sy_lfr_pas_filter_offset
362 // sy_lfr_pas_filter_offset
363 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
363 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
364 // sy_lfr_pas_filter_shift
364 // sy_lfr_pas_filter_shift
365 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
365 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
366 parameter_dump_packet.sy_lfr_pas_filter_shift );
366 parameter_dump_packet.sy_lfr_pas_filter_shift );
367
367
368 //****************************************************
368 //****************************************************
369 // store the parameter sy_lfr_sc_rw_delta_f as a float
369 // store the parameter sy_lfr_sc_rw_delta_f as a float
370 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
370 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
371 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
371 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
372
372
373 // copy rw.._k.. from the incoming TC to the local parameter_dump_packet
373 // copy rw.._k.. from the incoming TC to the local parameter_dump_packet
374 for (k = 0; k < NB_RW_K_COEFFS * NB_BYTES_PER_RW_K_COEFF; k++)
374 for (k = 0; k < NB_RW_K_COEFFS * NB_BYTES_PER_RW_K_COEFF; k++)
375 {
375 {
376 parameter_dump_packet.sy_lfr_rw1_k1[k] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_RW1_K1 + k ];
376 parameter_dump_packet.sy_lfr_rw1_k1[k] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_RW1_K1 + k ];
377 }
377 }
378
378
379 //***********************************************
379 //***********************************************
380 // store the parameter sy_lfr_rw.._k.. as a float
380 // store the parameter sy_lfr_rw.._k.. as a float
381 // rw1_k
381 // rw1_k
382 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k1, parameter_dump_packet.sy_lfr_rw1_k1 );
382 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k1, parameter_dump_packet.sy_lfr_rw1_k1 );
383 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k2, parameter_dump_packet.sy_lfr_rw1_k2 );
383 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k2, parameter_dump_packet.sy_lfr_rw1_k2 );
384 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k3, parameter_dump_packet.sy_lfr_rw1_k3 );
384 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k3, parameter_dump_packet.sy_lfr_rw1_k3 );
385 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k4, parameter_dump_packet.sy_lfr_rw1_k4 );
385 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k4, parameter_dump_packet.sy_lfr_rw1_k4 );
386 // rw2_k
386 // rw2_k
387 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k1, parameter_dump_packet.sy_lfr_rw2_k1 );
387 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k1, parameter_dump_packet.sy_lfr_rw2_k1 );
388 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k2, parameter_dump_packet.sy_lfr_rw2_k2 );
388 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k2, parameter_dump_packet.sy_lfr_rw2_k2 );
389 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k3, parameter_dump_packet.sy_lfr_rw2_k3 );
389 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k3, parameter_dump_packet.sy_lfr_rw2_k3 );
390 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k4, parameter_dump_packet.sy_lfr_rw2_k4 );
390 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k4, parameter_dump_packet.sy_lfr_rw2_k4 );
391 // rw3_k
391 // rw3_k
392 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k1, parameter_dump_packet.sy_lfr_rw3_k1 );
392 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k1, parameter_dump_packet.sy_lfr_rw3_k1 );
393 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k2, parameter_dump_packet.sy_lfr_rw3_k2 );
393 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k2, parameter_dump_packet.sy_lfr_rw3_k2 );
394 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k3, parameter_dump_packet.sy_lfr_rw3_k3 );
394 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k3, parameter_dump_packet.sy_lfr_rw3_k3 );
395 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k4, parameter_dump_packet.sy_lfr_rw3_k4 );
395 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k4, parameter_dump_packet.sy_lfr_rw3_k4 );
396 // rw4_k
396 // rw4_k
397 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k1, parameter_dump_packet.sy_lfr_rw4_k1 );
397 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k1, parameter_dump_packet.sy_lfr_rw4_k1 );
398 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k2, parameter_dump_packet.sy_lfr_rw4_k2 );
398 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k2, parameter_dump_packet.sy_lfr_rw4_k2 );
399 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k3, parameter_dump_packet.sy_lfr_rw4_k3 );
399 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k3, parameter_dump_packet.sy_lfr_rw4_k3 );
400 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k4, parameter_dump_packet.sy_lfr_rw4_k4 );
400 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k4, parameter_dump_packet.sy_lfr_rw4_k4 );
401
401
402 }
402 }
403
403
404 return flag;
404 return flag;
405 }
405 }
406
406
407 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
407 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
408 {
408 {
409 /** This function updates the LFR registers with the incoming sbm2 parameters.
409 /** This function updates the LFR registers with the incoming sbm2 parameters.
410 *
410 *
411 * @param TC points to the TeleCommand packet that is being processed
411 * @param TC points to the TeleCommand packet that is being processed
412 * @param queue_id is the id of the queue which handles TM related to this execution step
412 * @param queue_id is the id of the queue which handles TM related to this execution step
413 *
413 *
414 */
414 */
415
415
416 unsigned int address;
416 unsigned int address;
417 rtems_status_code status;
417 rtems_status_code status;
418 unsigned int freq;
418 unsigned int freq;
419 unsigned int bin;
419 unsigned int bin;
420 unsigned int coeff;
420 unsigned int coeff;
421 unsigned char *kCoeffPtr;
421 unsigned char *kCoeffPtr;
422 unsigned char *kCoeffDumpPtr;
422 unsigned char *kCoeffDumpPtr;
423
423
424 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
424 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
425 // F0 => 11 bins
425 // F0 => 11 bins
426 // F1 => 13 bins
426 // F1 => 13 bins
427 // F2 => 12 bins
427 // F2 => 12 bins
428 // 36 bins to dump in two packets (30 bins max per packet)
428 // 36 bins to dump in two packets (30 bins max per packet)
429
429
430 //*********
430 //*********
431 // PACKET 1
431 // PACKET 1
432 // 11 F0 bins, 13 F1 bins and 6 F2 bins
432 // 11 F0 bins, 13 F1 bins and 6 F2 bins
433 kcoefficients_dump_1.destinationID = TC->sourceID;
433 kcoefficients_dump_1.destinationID = TC->sourceID;
434 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
434 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
435 for( freq = 0;
435 for( freq = 0;
436 freq < NB_BINS_COMPRESSED_SM_F0;
436 freq < NB_BINS_COMPRESSED_SM_F0;
437 freq++ )
437 freq++ )
438 {
438 {
439 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
439 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
440 bin = freq;
440 bin = freq;
441 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
441 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
442 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
442 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
443 {
443 {
444 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
444 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
445 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
445 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
446 ]; // 2 for the kcoeff_frequency
446 ]; // 2 for the kcoeff_frequency
447 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
447 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
448 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
448 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
449 }
449 }
450 }
450 }
451 for( freq = NB_BINS_COMPRESSED_SM_F0;
451 for( freq = NB_BINS_COMPRESSED_SM_F0;
452 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
452 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
453 freq++ )
453 freq++ )
454 {
454 {
455 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
455 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
456 bin = freq - NB_BINS_COMPRESSED_SM_F0;
456 bin = freq - NB_BINS_COMPRESSED_SM_F0;
457 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
457 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
458 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
458 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
459 {
459 {
460 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
460 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
461 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
461 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
462 ]; // 2 for the kcoeff_frequency
462 ]; // 2 for the kcoeff_frequency
463 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
463 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
464 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
464 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
465 }
465 }
466 }
466 }
467 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
467 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
468 freq < KCOEFF_BLK_NR_PKT1 ;
468 freq < KCOEFF_BLK_NR_PKT1 ;
469 freq++ )
469 freq++ )
470 {
470 {
471 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
471 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
472 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
472 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
473 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
473 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
474 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
474 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
475 {
475 {
476 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
476 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
477 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
477 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
478 ]; // 2 for the kcoeff_frequency
478 ]; // 2 for the kcoeff_frequency
479 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
479 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
480 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
480 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
481 }
481 }
482 }
482 }
483 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
483 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
484 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
484 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
485 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
485 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
486 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
486 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
487 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
487 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
488 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
488 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
489 // SEND DATA
489 // SEND DATA
490 kcoefficient_node_1.status = 1;
490 kcoefficient_node_1.status = 1;
491 address = (unsigned int) &kcoefficient_node_1;
491 address = (unsigned int) &kcoefficient_node_1;
492 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
492 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
493 if (status != RTEMS_SUCCESSFUL) {
493 if (status != RTEMS_SUCCESSFUL) {
494 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
494 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
495 }
495 }
496
496
497 //********
497 //********
498 // PACKET 2
498 // PACKET 2
499 // 6 F2 bins
499 // 6 F2 bins
500 kcoefficients_dump_2.destinationID = TC->sourceID;
500 kcoefficients_dump_2.destinationID = TC->sourceID;
501 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
501 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
502 for( freq = 0;
502 for( freq = 0;
503 freq < KCOEFF_BLK_NR_PKT2;
503 freq < KCOEFF_BLK_NR_PKT2;
504 freq++ )
504 freq++ )
505 {
505 {
506 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
506 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
507 bin = freq + KCOEFF_BLK_NR_PKT2;
507 bin = freq + KCOEFF_BLK_NR_PKT2;
508 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
508 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
509 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
509 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
510 {
510 {
511 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
511 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
512 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
512 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
513 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
513 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
514 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
514 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
515 }
515 }
516 }
516 }
517 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
517 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
518 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
518 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
519 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
519 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
520 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
520 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
521 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
521 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
522 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
522 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
523 // SEND DATA
523 // SEND DATA
524 kcoefficient_node_2.status = 1;
524 kcoefficient_node_2.status = 1;
525 address = (unsigned int) &kcoefficient_node_2;
525 address = (unsigned int) &kcoefficient_node_2;
526 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
526 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
527 if (status != RTEMS_SUCCESSFUL) {
527 if (status != RTEMS_SUCCESSFUL) {
528 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
528 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
529 }
529 }
530
530
531 return status;
531 return status;
532 }
532 }
533
533
534 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
534 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
535 {
535 {
536 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
536 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
537 *
537 *
538 * @param queue_id is the id of the queue which handles TM related to this execution step.
538 * @param queue_id is the id of the queue which handles TM related to this execution step.
539 *
539 *
540 * @return RTEMS directive status codes:
540 * @return RTEMS directive status codes:
541 * - RTEMS_SUCCESSFUL - message sent successfully
541 * - RTEMS_SUCCESSFUL - message sent successfully
542 * - RTEMS_INVALID_ID - invalid queue id
542 * - RTEMS_INVALID_ID - invalid queue id
543 * - RTEMS_INVALID_SIZE - invalid message size
543 * - RTEMS_INVALID_SIZE - invalid message size
544 * - RTEMS_INVALID_ADDRESS - buffer is NULL
544 * - RTEMS_INVALID_ADDRESS - buffer is NULL
545 * - RTEMS_UNSATISFIED - out of message buffers
545 * - RTEMS_UNSATISFIED - out of message buffers
546 * - RTEMS_TOO_MANY - queue s limit has been reached
546 * - RTEMS_TOO_MANY - queue s limit has been reached
547 *
547 *
548 */
548 */
549
549
550 int status;
550 int status;
551
551
552 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
552 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
553 parameter_dump_packet.destinationID = TC->sourceID;
553 parameter_dump_packet.destinationID = TC->sourceID;
554
554
555 // UPDATE TIME
555 // UPDATE TIME
556 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
556 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
557 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
557 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
558 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
558 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
559 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
559 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
560 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
560 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
561 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
561 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
562 // SEND DATA
562 // SEND DATA
563 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
563 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
564 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
564 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
565 if (status != RTEMS_SUCCESSFUL) {
565 if (status != RTEMS_SUCCESSFUL) {
566 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
566 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
567 }
567 }
568
568
569 return status;
569 return status;
570 }
570 }
571
571
572 //***********************
572 //***********************
573 // NORMAL MODE PARAMETERS
573 // NORMAL MODE PARAMETERS
574
574
575 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
575 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
576 {
576 {
577 unsigned char msb;
577 unsigned char msb;
578 unsigned char lsb;
578 unsigned char lsb;
579 int flag;
579 int flag;
580 float aux;
580 float aux;
581 rtems_status_code status;
581 rtems_status_code status;
582
582
583 unsigned int sy_lfr_n_swf_l;
583 unsigned int sy_lfr_n_swf_l;
584 unsigned int sy_lfr_n_swf_p;
584 unsigned int sy_lfr_n_swf_p;
585 unsigned int sy_lfr_n_asm_p;
585 unsigned int sy_lfr_n_asm_p;
586 unsigned char sy_lfr_n_bp_p0;
586 unsigned char sy_lfr_n_bp_p0;
587 unsigned char sy_lfr_n_bp_p1;
587 unsigned char sy_lfr_n_bp_p1;
588 unsigned char sy_lfr_n_cwf_long_f3;
588 unsigned char sy_lfr_n_cwf_long_f3;
589
589
590 flag = LFR_SUCCESSFUL;
590 flag = LFR_SUCCESSFUL;
591
591
592 //***************
592 //***************
593 // get parameters
593 // get parameters
594 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
594 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
595 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
595 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
596 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
596 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
597
597
598 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
598 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
599 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
599 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
600 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
600 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
601
601
602 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
602 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
603 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
603 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
604 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
604 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
605
605
606 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
606 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
607
607
608 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
608 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
609
609
610 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
610 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
611
611
612 //******************
612 //******************
613 // check consistency
613 // check consistency
614 // sy_lfr_n_swf_l
614 // sy_lfr_n_swf_l
615 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
615 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
616 {
616 {
617 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
617 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
618 flag = WRONG_APP_DATA;
618 flag = WRONG_APP_DATA;
619 }
619 }
620 // sy_lfr_n_swf_p
620 // sy_lfr_n_swf_p
621 if (flag == LFR_SUCCESSFUL)
621 if (flag == LFR_SUCCESSFUL)
622 {
622 {
623 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
623 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
624 {
624 {
625 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
625 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
626 flag = WRONG_APP_DATA;
626 flag = WRONG_APP_DATA;
627 }
627 }
628 }
628 }
629 // sy_lfr_n_bp_p0
629 // sy_lfr_n_bp_p0
630 if (flag == LFR_SUCCESSFUL)
630 if (flag == LFR_SUCCESSFUL)
631 {
631 {
632 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
632 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
633 {
633 {
634 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
634 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
635 flag = WRONG_APP_DATA;
635 flag = WRONG_APP_DATA;
636 }
636 }
637 }
637 }
638 // sy_lfr_n_asm_p
638 // sy_lfr_n_asm_p
639 if (flag == LFR_SUCCESSFUL)
639 if (flag == LFR_SUCCESSFUL)
640 {
640 {
641 if (sy_lfr_n_asm_p == 0)
641 if (sy_lfr_n_asm_p == 0)
642 {
642 {
643 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
643 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
644 flag = WRONG_APP_DATA;
644 flag = WRONG_APP_DATA;
645 }
645 }
646 }
646 }
647 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
647 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
648 if (flag == LFR_SUCCESSFUL)
648 if (flag == LFR_SUCCESSFUL)
649 {
649 {
650 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
650 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
651 if (aux > FLOAT_EQUAL_ZERO)
651 if (aux > FLOAT_EQUAL_ZERO)
652 {
652 {
653 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
653 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
654 flag = WRONG_APP_DATA;
654 flag = WRONG_APP_DATA;
655 }
655 }
656 }
656 }
657 // sy_lfr_n_bp_p1
657 // sy_lfr_n_bp_p1
658 if (flag == LFR_SUCCESSFUL)
658 if (flag == LFR_SUCCESSFUL)
659 {
659 {
660 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
660 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
661 {
661 {
662 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
662 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
663 flag = WRONG_APP_DATA;
663 flag = WRONG_APP_DATA;
664 }
664 }
665 }
665 }
666 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
666 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
667 if (flag == LFR_SUCCESSFUL)
667 if (flag == LFR_SUCCESSFUL)
668 {
668 {
669 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
669 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
670 if (aux > FLOAT_EQUAL_ZERO)
670 if (aux > FLOAT_EQUAL_ZERO)
671 {
671 {
672 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
672 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
673 flag = LFR_DEFAULT;
673 flag = LFR_DEFAULT;
674 }
674 }
675 }
675 }
676 // sy_lfr_n_cwf_long_f3
676 // sy_lfr_n_cwf_long_f3
677
677
678 return flag;
678 return flag;
679 }
679 }
680
680
681 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
681 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
682 {
682 {
683 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
683 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
684 *
684 *
685 * @param TC points to the TeleCommand packet that is being processed
685 * @param TC points to the TeleCommand packet that is being processed
686 * @param queue_id is the id of the queue which handles TM related to this execution step
686 * @param queue_id is the id of the queue which handles TM related to this execution step
687 *
687 *
688 */
688 */
689
689
690 int result;
690 int result;
691
691
692 result = LFR_SUCCESSFUL;
692 result = LFR_SUCCESSFUL;
693
693
694 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
694 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
695 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
695 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
696
696
697 return result;
697 return result;
698 }
698 }
699
699
700 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
700 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
701 {
701 {
702 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
702 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
703 *
703 *
704 * @param TC points to the TeleCommand packet that is being processed
704 * @param TC points to the TeleCommand packet that is being processed
705 * @param queue_id is the id of the queue which handles TM related to this execution step
705 * @param queue_id is the id of the queue which handles TM related to this execution step
706 *
706 *
707 */
707 */
708
708
709 int result;
709 int result;
710
710
711 result = LFR_SUCCESSFUL;
711 result = LFR_SUCCESSFUL;
712
712
713 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
713 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
714 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
714 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
715
715
716 return result;
716 return result;
717 }
717 }
718
718
719 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
719 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
720 {
720 {
721 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
721 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
722 *
722 *
723 * @param TC points to the TeleCommand packet that is being processed
723 * @param TC points to the TeleCommand packet that is being processed
724 * @param queue_id is the id of the queue which handles TM related to this execution step
724 * @param queue_id is the id of the queue which handles TM related to this execution step
725 *
725 *
726 */
726 */
727
727
728 int result;
728 int result;
729
729
730 result = LFR_SUCCESSFUL;
730 result = LFR_SUCCESSFUL;
731
731
732 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
732 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
733 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
733 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
734
734
735 return result;
735 return result;
736 }
736 }
737
737
738 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
738 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
739 {
739 {
740 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
740 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
741 *
741 *
742 * @param TC points to the TeleCommand packet that is being processed
742 * @param TC points to the TeleCommand packet that is being processed
743 * @param queue_id is the id of the queue which handles TM related to this execution step
743 * @param queue_id is the id of the queue which handles TM related to this execution step
744 *
744 *
745 */
745 */
746
746
747 int status;
747 int status;
748
748
749 status = LFR_SUCCESSFUL;
749 status = LFR_SUCCESSFUL;
750
750
751 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
751 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
752
752
753 return status;
753 return status;
754 }
754 }
755
755
756 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
756 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
757 {
757 {
758 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
758 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
759 *
759 *
760 * @param TC points to the TeleCommand packet that is being processed
760 * @param TC points to the TeleCommand packet that is being processed
761 * @param queue_id is the id of the queue which handles TM related to this execution step
761 * @param queue_id is the id of the queue which handles TM related to this execution step
762 *
762 *
763 */
763 */
764
764
765 int status;
765 int status;
766
766
767 status = LFR_SUCCESSFUL;
767 status = LFR_SUCCESSFUL;
768
768
769 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
769 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
770
770
771 return status;
771 return status;
772 }
772 }
773
773
774 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
774 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
775 {
775 {
776 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
776 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
777 *
777 *
778 * @param TC points to the TeleCommand packet that is being processed
778 * @param TC points to the TeleCommand packet that is being processed
779 * @param queue_id is the id of the queue which handles TM related to this execution step
779 * @param queue_id is the id of the queue which handles TM related to this execution step
780 *
780 *
781 */
781 */
782
782
783 int status;
783 int status;
784
784
785 status = LFR_SUCCESSFUL;
785 status = LFR_SUCCESSFUL;
786
786
787 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
787 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
788
788
789 return status;
789 return status;
790 }
790 }
791
791
792 //**********************
792 //**********************
793 // BURST MODE PARAMETERS
793 // BURST MODE PARAMETERS
794 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
794 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
795 {
795 {
796 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
796 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
797 *
797 *
798 * @param TC points to the TeleCommand packet that is being processed
798 * @param TC points to the TeleCommand packet that is being processed
799 * @param queue_id is the id of the queue which handles TM related to this execution step
799 * @param queue_id is the id of the queue which handles TM related to this execution step
800 *
800 *
801 */
801 */
802
802
803 int status;
803 int status;
804
804
805 status = LFR_SUCCESSFUL;
805 status = LFR_SUCCESSFUL;
806
806
807 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
807 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
808
808
809 return status;
809 return status;
810 }
810 }
811
811
812 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
812 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
813 {
813 {
814 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
814 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
815 *
815 *
816 * @param TC points to the TeleCommand packet that is being processed
816 * @param TC points to the TeleCommand packet that is being processed
817 * @param queue_id is the id of the queue which handles TM related to this execution step
817 * @param queue_id is the id of the queue which handles TM related to this execution step
818 *
818 *
819 */
819 */
820
820
821 int status;
821 int status;
822
822
823 status = LFR_SUCCESSFUL;
823 status = LFR_SUCCESSFUL;
824
824
825 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
825 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
826
826
827 return status;
827 return status;
828 }
828 }
829
829
830 //*********************
830 //*********************
831 // SBM1 MODE PARAMETERS
831 // SBM1 MODE PARAMETERS
832 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
832 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
833 {
833 {
834 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
834 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
835 *
835 *
836 * @param TC points to the TeleCommand packet that is being processed
836 * @param TC points to the TeleCommand packet that is being processed
837 * @param queue_id is the id of the queue which handles TM related to this execution step
837 * @param queue_id is the id of the queue which handles TM related to this execution step
838 *
838 *
839 */
839 */
840
840
841 int status;
841 int status;
842
842
843 status = LFR_SUCCESSFUL;
843 status = LFR_SUCCESSFUL;
844
844
845 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
845 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
846
846
847 return status;
847 return status;
848 }
848 }
849
849
850 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
850 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
851 {
851 {
852 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
852 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
853 *
853 *
854 * @param TC points to the TeleCommand packet that is being processed
854 * @param TC points to the TeleCommand packet that is being processed
855 * @param queue_id is the id of the queue which handles TM related to this execution step
855 * @param queue_id is the id of the queue which handles TM related to this execution step
856 *
856 *
857 */
857 */
858
858
859 int status;
859 int status;
860
860
861 status = LFR_SUCCESSFUL;
861 status = LFR_SUCCESSFUL;
862
862
863 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
863 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
864
864
865 return status;
865 return status;
866 }
866 }
867
867
868 //*********************
868 //*********************
869 // SBM2 MODE PARAMETERS
869 // SBM2 MODE PARAMETERS
870 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
870 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
871 {
871 {
872 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
872 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
873 *
873 *
874 * @param TC points to the TeleCommand packet that is being processed
874 * @param TC points to the TeleCommand packet that is being processed
875 * @param queue_id is the id of the queue which handles TM related to this execution step
875 * @param queue_id is the id of the queue which handles TM related to this execution step
876 *
876 *
877 */
877 */
878
878
879 int status;
879 int status;
880
880
881 status = LFR_SUCCESSFUL;
881 status = LFR_SUCCESSFUL;
882
882
883 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
883 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
884
884
885 return status;
885 return status;
886 }
886 }
887
887
888 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
888 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
889 {
889 {
890 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
890 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
891 *
891 *
892 * @param TC points to the TeleCommand packet that is being processed
892 * @param TC points to the TeleCommand packet that is being processed
893 * @param queue_id is the id of the queue which handles TM related to this execution step
893 * @param queue_id is the id of the queue which handles TM related to this execution step
894 *
894 *
895 */
895 */
896
896
897 int status;
897 int status;
898
898
899 status = LFR_SUCCESSFUL;
899 status = LFR_SUCCESSFUL;
900
900
901 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
901 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
902
902
903 return status;
903 return status;
904 }
904 }
905
905
906 //*******************
906 //*******************
907 // TC_LFR_UPDATE_INFO
907 // TC_LFR_UPDATE_INFO
908 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
908 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
909 {
909 {
910 unsigned int status;
910 unsigned int status;
911
911
912 status = LFR_DEFAULT;
912 status = LFR_DEFAULT;
913
913
914 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
914 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
915 || (mode == LFR_MODE_BURST)
915 || (mode == LFR_MODE_BURST)
916 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
916 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
917 {
917 {
918 status = LFR_SUCCESSFUL;
918 status = LFR_SUCCESSFUL;
919 }
919 }
920 else
920 else
921 {
921 {
922 status = LFR_DEFAULT;
922 status = LFR_DEFAULT;
923 }
923 }
924
924
925 return status;
925 return status;
926 }
926 }
927
927
928 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
928 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
929 {
929 {
930 unsigned int status;
930 unsigned int status;
931
931
932 status = LFR_DEFAULT;
932 status = LFR_DEFAULT;
933
933
934 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
934 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
935 || (mode == TDS_MODE_BURST)
935 || (mode == TDS_MODE_BURST)
936 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
936 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
937 || (mode == TDS_MODE_LFM))
937 || (mode == TDS_MODE_LFM))
938 {
938 {
939 status = LFR_SUCCESSFUL;
939 status = LFR_SUCCESSFUL;
940 }
940 }
941 else
941 else
942 {
942 {
943 status = LFR_DEFAULT;
943 status = LFR_DEFAULT;
944 }
944 }
945
945
946 return status;
946 return status;
947 }
947 }
948
948
949 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
949 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
950 {
950 {
951 unsigned int status;
951 unsigned int status;
952
952
953 status = LFR_DEFAULT;
953 status = LFR_DEFAULT;
954
954
955 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
955 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
956 || (mode == THR_MODE_BURST))
956 || (mode == THR_MODE_BURST))
957 {
957 {
958 status = LFR_SUCCESSFUL;
958 status = LFR_SUCCESSFUL;
959 }
959 }
960 else
960 else
961 {
961 {
962 status = LFR_DEFAULT;
962 status = LFR_DEFAULT;
963 }
963 }
964
964
965 return status;
965 return status;
966 }
966 }
967
967
968 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value )
968 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value )
969 {
969 {
970 unsigned char flag;
970 unsigned char flag;
971 unsigned char flagPosInByte;
971 unsigned char flagPosInByte;
972 unsigned char newFlag;
972 unsigned char newFlag;
973 unsigned char flagMask;
973 unsigned char flagMask;
974
974
975 // if the frequency value is not a number, the flag is set to 0 and the frequency RWx_Fy is not filtered
975 // if the frequency value is not a number, the flag is set to 0 and the frequency RWx_Fy is not filtered
976 if (isnan(value))
976 if (isnan(value))
977 {
977 {
978 flag = FLAG_NAN;
978 flag = FLAG_NAN;
979 }
979 }
980 else
980 else
981 {
981 {
982 flag = FLAG_IAN;
982 flag = FLAG_IAN;
983 }
983 }
984
984
985 switch(wheel)
985 switch(wheel)
986 {
986 {
987 case WHEEL_1:
987 case WHEEL_1:
988 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
988 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
989 flagMask = ~(1 << flagPosInByte);
989 flagMask = ~(1 << flagPosInByte);
990 newFlag = flag << flagPosInByte;
990 newFlag = flag << flagPosInByte;
991 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
991 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
992 break;
992 break;
993 case WHEEL_2:
993 case WHEEL_2:
994 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
994 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
995 flagMask = ~(1 << flagPosInByte);
995 flagMask = ~(1 << flagPosInByte);
996 newFlag = flag << flagPosInByte;
996 newFlag = flag << flagPosInByte;
997 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
997 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
998 break;
998 break;
999 case WHEEL_3:
999 case WHEEL_3:
1000 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1000 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1001 flagMask = ~(1 << flagPosInByte);
1001 flagMask = ~(1 << flagPosInByte);
1002 newFlag = flag << flagPosInByte;
1002 newFlag = flag << flagPosInByte;
1003 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1003 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1004 break;
1004 break;
1005 case WHEEL_4:
1005 case WHEEL_4:
1006 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1006 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1007 flagMask = ~(1 << flagPosInByte);
1007 flagMask = ~(1 << flagPosInByte);
1008 newFlag = flag << flagPosInByte;
1008 newFlag = flag << flagPosInByte;
1009 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1009 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1010 break;
1010 break;
1011 default:
1011 default:
1012 break;
1012 break;
1013 }
1013 }
1014 }
1014 }
1015
1015
1016 void set_hk_lfr_sc_rw_f_flags( void )
1016 void set_hk_lfr_sc_rw_f_flags( void )
1017 {
1017 {
1018 // RW1
1018 // RW1
1019 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_1, rw_f.cp_rpw_sc_rw1_f1 );
1019 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_1, rw_f.cp_rpw_sc_rw1_f1 );
1020 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_2, rw_f.cp_rpw_sc_rw1_f2 );
1020 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_2, rw_f.cp_rpw_sc_rw1_f2 );
1021 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_3, rw_f.cp_rpw_sc_rw1_f3 );
1021 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_3, rw_f.cp_rpw_sc_rw1_f3 );
1022 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_4, rw_f.cp_rpw_sc_rw1_f4 );
1022 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_4, rw_f.cp_rpw_sc_rw1_f4 );
1023
1023
1024 // RW2
1024 // RW2
1025 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_1, rw_f.cp_rpw_sc_rw2_f1 );
1025 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_1, rw_f.cp_rpw_sc_rw2_f1 );
1026 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_2, rw_f.cp_rpw_sc_rw2_f2 );
1026 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_2, rw_f.cp_rpw_sc_rw2_f2 );
1027 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_3, rw_f.cp_rpw_sc_rw2_f3 );
1027 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_3, rw_f.cp_rpw_sc_rw2_f3 );
1028 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_4, rw_f.cp_rpw_sc_rw2_f4 );
1028 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_4, rw_f.cp_rpw_sc_rw2_f4 );
1029
1029
1030 // RW3
1030 // RW3
1031 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_1, rw_f.cp_rpw_sc_rw3_f1 );
1031 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_1, rw_f.cp_rpw_sc_rw3_f1 );
1032 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_2, rw_f.cp_rpw_sc_rw3_f2 );
1032 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_2, rw_f.cp_rpw_sc_rw3_f2 );
1033 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_3, rw_f.cp_rpw_sc_rw3_f3 );
1033 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_3, rw_f.cp_rpw_sc_rw3_f3 );
1034 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_4, rw_f.cp_rpw_sc_rw3_f4 );
1034 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_4, rw_f.cp_rpw_sc_rw3_f4 );
1035
1035
1036 // RW4
1036 // RW4
1037 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_1, rw_f.cp_rpw_sc_rw4_f1 );
1037 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_1, rw_f.cp_rpw_sc_rw4_f1 );
1038 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_2, rw_f.cp_rpw_sc_rw4_f2 );
1038 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_2, rw_f.cp_rpw_sc_rw4_f2 );
1039 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_3, rw_f.cp_rpw_sc_rw4_f3 );
1039 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_3, rw_f.cp_rpw_sc_rw4_f3 );
1040 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_4, rw_f.cp_rpw_sc_rw4_f4 );
1040 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_4, rw_f.cp_rpw_sc_rw4_f4 );
1041 }
1041 }
1042
1042
1043 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
1043 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
1044 {
1044 {
1045 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
1045 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
1046 *
1046 *
1047 * @param TC points to the TeleCommand packet that is being processed
1047 * @param TC points to the TeleCommand packet that is being processed
1048 *
1048 *
1049 */
1049 */
1050
1050
1051 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
1051 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
1052
1052
1053 bytePosPtr = (unsigned char *) &TC->packetID;
1053 bytePosPtr = (unsigned char *) &TC->packetID;
1054
1054
1055 // rw1_f
1055 // rw1_f
1056 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
1056 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
1057 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
1057 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
1058 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3 ] );
1058 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3 ] );
1059 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4 ] );
1059 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4 ] );
1060
1060
1061 // rw2_f
1061 // rw2_f
1062 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
1062 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
1063 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
1063 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
1064 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3 ] );
1064 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3 ] );
1065 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4 ] );
1065 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4 ] );
1066
1066
1067 // rw3_f
1067 // rw3_f
1068 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
1068 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
1069 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
1069 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
1070 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3 ] );
1070 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3 ] );
1071 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4 ] );
1071 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4 ] );
1072
1072
1073 // rw4_f
1073 // rw4_f
1074 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
1074 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
1075 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
1075 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
1076 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3 ] );
1076 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3 ] );
1077 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4 ] );
1077 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4 ] );
1078
1078
1079 // test each reaction wheel frequency value. NaN means that the frequency is not filtered
1079 // test each reaction wheel frequency value. NaN means that the frequency is not filtered
1080
1080
1081 }
1081 }
1082
1082
1083 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float kcoeff )
1083 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float kcoeff )
1084 {
1084 {
1085 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
1085 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
1086 *
1086 *
1087 * @param fbins_mask
1087 * @param fbins_mask
1088 * @param rw_f is the reaction wheel frequency to filter
1088 * @param rw_f is the reaction wheel frequency to filter
1089 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
1089 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
1090 * @param flag [true] filtering enabled [false] filtering disabled
1090 * @param flag [true] filtering enabled [false] filtering disabled
1091 *
1091 *
1092 * @return void
1092 * @return void
1093 *
1093 *
1094 */
1094 */
1095
1095
1096 float f_RW_min;
1096 float f_RW_min;
1097 float f_RW_MAX;
1097 float f_RW_MAX;
1098 float fi_min;
1098 float fi_min;
1099 float fi_MAX;
1099 float fi_MAX;
1100 float fi;
1100 float fi;
1101 float deltaBelow;
1101 float deltaBelow;
1102 float deltaAbove;
1102 float deltaAbove;
1103 int binBelow;
1103 int binBelow;
1104 int binAbove;
1104 int binAbove;
1105 int closestBin;
1105 int closestBin;
1106 unsigned int whichByte;
1106 unsigned int whichByte;
1107 int selectedByte;
1107 int selectedByte;
1108 int bin;
1108 int bin;
1109 int binToRemove[NB_BINS_TO_REMOVE];
1109 int binToRemove[NB_BINS_TO_REMOVE];
1110 int i;
1110 int i;
1111
1111
1112 closestBin = 0;
1112 closestBin = 0;
1113 whichByte = 0;
1113 whichByte = 0;
1114 bin = 0;
1114 bin = 0;
1115
1115
1116 for (i = 0; i < NB_BINS_TO_REMOVE; i++)
1116 for (i = 0; i < NB_BINS_TO_REMOVE; i++)
1117 {
1117 {
1118 binToRemove[i] = -1;
1118 binToRemove[i] = -1;
1119 }
1119 }
1120
1120
1121 if (!isnan(rw_f))
1121 if (!isnan(rw_f))
1122 {
1122 {
1123
1123
1124 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
1124 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
1125 f_RW_min = rw_f - ( (filterPar.sy_lfr_sc_rw_delta_f * kcoeff) / DELTAF_DIV);
1125 f_RW_min = rw_f - ( (filterPar.sy_lfr_sc_rw_delta_f * kcoeff) / DELTAF_DIV);
1126 f_RW_MAX = rw_f + ( (filterPar.sy_lfr_sc_rw_delta_f * kcoeff) / DELTAF_DIV);
1126 f_RW_MAX = rw_f + ( (filterPar.sy_lfr_sc_rw_delta_f * kcoeff) / DELTAF_DIV);
1127
1127
1128 // compute the index of the frequency bin immediately below rw_f
1128 // compute the index of the frequency bin immediately below rw_f
1129 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1129 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1130 deltaBelow = rw_f - binBelow * deltaFreq;
1130 deltaBelow = rw_f - binBelow * deltaFreq;
1131
1131
1132 // compute the index of the frequency bin immediately above rw_f
1132 // compute the index of the frequency bin immediately above rw_f
1133 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1133 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1134 deltaAbove = binAbove * deltaFreq - rw_f;
1134 deltaAbove = binAbove * deltaFreq - rw_f;
1135
1135
1136 // search the closest bin
1136 // search the closest bin
1137 if (deltaAbove > deltaBelow)
1137 if (deltaAbove > deltaBelow)
1138 {
1138 {
1139 closestBin = binBelow;
1139 closestBin = binBelow;
1140 }
1140 }
1141 else
1141 else
1142 {
1142 {
1143 closestBin = binAbove;
1143 closestBin = binAbove;
1144 }
1144 }
1145
1145
1146 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1146 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1147 fi = closestBin * deltaFreq;
1147 fi = closestBin * deltaFreq;
1148 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1148 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1149 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1149 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1150
1150
1151 //**************************************************************************************
1151 //**************************************************************************************
1152 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1152 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1153 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1153 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1154 //**************************************************************************************
1154 //**************************************************************************************
1155
1155
1156 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1156 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1157 // => remove f_(i), f_(i-1) and f_(i+1)
1157 // => remove f_(i), f_(i-1) and f_(i+1)
1158 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
1158 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
1159 {
1159 {
1160 binToRemove[0] = (closestBin - 1) - 1;
1160 binToRemove[0] = (closestBin - 1) - 1;
1161 binToRemove[1] = (closestBin) - 1;
1161 binToRemove[1] = (closestBin) - 1;
1162 binToRemove[2] = (closestBin + 1) - 1;
1162 binToRemove[2] = (closestBin + 1) - 1;
1163 }
1163 }
1164 // 2. ELSE
1164 // 2. ELSE
1165 // => remove the two f_(i) which are around f_RW
1165 // => remove the two f_(i) which are around f_RW
1166 else
1166 else
1167 {
1167 {
1168 binToRemove[0] = (binBelow) - 1;
1168 binToRemove[0] = (binBelow) - 1;
1169 binToRemove[1] = (binAbove) - 1;
1169 binToRemove[1] = (binAbove) - 1;
1170 binToRemove[2] = (-1);
1170 binToRemove[2] = (-1);
1171 }
1171 }
1172
1172
1173 for (i = 0; i < NB_BINS_TO_REMOVE; i++)
1173 for (i = 0; i < NB_BINS_TO_REMOVE; i++)
1174 {
1174 {
1175 bin = binToRemove[i];
1175 bin = binToRemove[i];
1176 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1176 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1177 {
1177 {
1178
1178
1179 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1179 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1180 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1180 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1181 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1181 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1182 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1182 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1183 }
1183 }
1184 }
1184 }
1185 }
1185 }
1186 }
1186 }
1187
1187
1188 void build_sy_lfr_rw_mask( unsigned int channel )
1188 void build_sy_lfr_rw_mask( unsigned int channel )
1189 {
1189 {
1190 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1190 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1191 unsigned char *maskPtr;
1191 unsigned char *maskPtr;
1192 double deltaF;
1192 double deltaF;
1193 unsigned k;
1193 unsigned k;
1194
1194
1195 maskPtr = NULL;
1195 maskPtr = NULL;
1196 deltaF = DELTAF_F2;
1196 deltaF = DELTAF_F2;
1197
1197
1198 switch (channel)
1198 switch (channel)
1199 {
1199 {
1200 case CHANNELF0:
1200 case CHANNELF0:
1201 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1201 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1202 deltaF = DELTAF_F0;
1202 deltaF = DELTAF_F0;
1203 break;
1203 break;
1204 case CHANNELF1:
1204 case CHANNELF1:
1205 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1205 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1206 deltaF = DELTAF_F1;
1206 deltaF = DELTAF_F1;
1207 break;
1207 break;
1208 case CHANNELF2:
1208 case CHANNELF2:
1209 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1209 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1210 deltaF = DELTAF_F2;
1210 deltaF = DELTAF_F2;
1211 break;
1211 break;
1212 default:
1212 default:
1213 break;
1213 break;
1214 }
1214 }
1215
1215
1216 for (k = 0; k < BYTES_PER_MASK; k++)
1216 for (k = 0; k < BYTES_PER_MASK; k++)
1217 {
1217 {
1218 local_rw_fbins_mask[k] = INT8_ALL_F;
1218 local_rw_fbins_mask[k] = INT8_ALL_F;
1219 }
1219 }
1220
1220
1221 // RW1
1221 // RW1
1222 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, filterPar.sy_lfr_rw1_k1 );
1222 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, filterPar.sy_lfr_rw1_k1 );
1223 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, filterPar.sy_lfr_rw1_k2 );
1223 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, filterPar.sy_lfr_rw1_k2 );
1224 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f3, deltaF, filterPar.sy_lfr_rw1_k3 );
1224 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f3, deltaF, filterPar.sy_lfr_rw1_k3 );
1225 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f4, deltaF, filterPar.sy_lfr_rw1_k4 );
1225 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f4, deltaF, filterPar.sy_lfr_rw1_k4 );
1226
1226
1227 // RW2
1227 // RW2
1228 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, filterPar.sy_lfr_rw2_k1 );
1228 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, filterPar.sy_lfr_rw2_k1 );
1229 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, filterPar.sy_lfr_rw2_k2 );
1229 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, filterPar.sy_lfr_rw2_k2 );
1230 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f3, deltaF, filterPar.sy_lfr_rw2_k3 );
1230 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f3, deltaF, filterPar.sy_lfr_rw2_k3 );
1231 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f4, deltaF, filterPar.sy_lfr_rw2_k4 );
1231 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f4, deltaF, filterPar.sy_lfr_rw2_k4 );
1232
1232
1233 // RW3
1233 // RW3
1234 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, filterPar.sy_lfr_rw3_k1 );
1234 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, filterPar.sy_lfr_rw3_k1 );
1235 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, filterPar.sy_lfr_rw3_k2 );
1235 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, filterPar.sy_lfr_rw3_k2 );
1236 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f3, deltaF, filterPar.sy_lfr_rw3_k3 );
1236 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f3, deltaF, filterPar.sy_lfr_rw3_k3 );
1237 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f4, deltaF, filterPar.sy_lfr_rw3_k4 );
1237 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f4, deltaF, filterPar.sy_lfr_rw3_k4 );
1238
1238
1239 // RW4
1239 // RW4
1240 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, filterPar.sy_lfr_rw4_k1 );
1240 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, filterPar.sy_lfr_rw4_k1 );
1241 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, filterPar.sy_lfr_rw4_k2 );
1241 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, filterPar.sy_lfr_rw4_k2 );
1242 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f3, deltaF, filterPar.sy_lfr_rw4_k3 );
1242 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f3, deltaF, filterPar.sy_lfr_rw4_k3 );
1243 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f4, deltaF, filterPar.sy_lfr_rw4_k4 );
1243 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f4, deltaF, filterPar.sy_lfr_rw4_k4 );
1244
1244
1245 // update the value of the fbins related to reaction wheels frequency filtering
1245 // update the value of the fbins related to reaction wheels frequency filtering
1246 if (maskPtr != NULL)
1246 if (maskPtr != NULL)
1247 {
1247 {
1248 for (k = 0; k < BYTES_PER_MASK; k++)
1248 for (k = 0; k < BYTES_PER_MASK; k++)
1249 {
1249 {
1250 maskPtr[k] = local_rw_fbins_mask[k];
1250 maskPtr[k] = local_rw_fbins_mask[k];
1251 }
1251 }
1252 }
1252 }
1253 }
1253 }
1254
1254
1255 void build_sy_lfr_rw_masks( void )
1255 void build_sy_lfr_rw_masks( void )
1256 {
1256 {
1257 build_sy_lfr_rw_mask( CHANNELF0 );
1257 build_sy_lfr_rw_mask( CHANNELF0 );
1258 build_sy_lfr_rw_mask( CHANNELF1 );
1258 build_sy_lfr_rw_mask( CHANNELF1 );
1259 build_sy_lfr_rw_mask( CHANNELF2 );
1259 build_sy_lfr_rw_mask( CHANNELF2 );
1260 }
1260 }
1261
1261
1262 void merge_fbins_masks( void )
1262 void merge_fbins_masks( void )
1263 {
1263 {
1264 unsigned char k;
1264 unsigned char k;
1265
1265
1266 unsigned char *fbins_f0;
1266 unsigned char *fbins_f0;
1267 unsigned char *fbins_f1;
1267 unsigned char *fbins_f1;
1268 unsigned char *fbins_f2;
1268 unsigned char *fbins_f2;
1269 unsigned char *rw_mask_f0;
1269 unsigned char *rw_mask_f0;
1270 unsigned char *rw_mask_f1;
1270 unsigned char *rw_mask_f1;
1271 unsigned char *rw_mask_f2;
1271 unsigned char *rw_mask_f2;
1272
1272
1273 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1273 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1274 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1274 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1275 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1275 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1276 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1276 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1277 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1277 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1278 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1278 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1279
1279
1280 for( k=0; k < BYTES_PER_MASK; k++ )
1280 for( k=0; k < BYTES_PER_MASK; k++ )
1281 {
1281 {
1282 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1282 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1283 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1283 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1284 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1284 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1285 }
1285 }
1286 }
1286 }
1287
1287
1288 //***********
1288 //***********
1289 // FBINS MASK
1289 // FBINS MASK
1290
1290
1291 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1291 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1292 {
1292 {
1293 int status;
1293 int status;
1294 unsigned int k;
1294 unsigned int k;
1295 unsigned char *fbins_mask_dump;
1295 unsigned char *fbins_mask_dump;
1296 unsigned char *fbins_mask_TC;
1296 unsigned char *fbins_mask_TC;
1297
1297
1298 status = LFR_SUCCESSFUL;
1298 status = LFR_SUCCESSFUL;
1299
1299
1300 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1300 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1301 fbins_mask_TC = TC->dataAndCRC;
1301 fbins_mask_TC = TC->dataAndCRC;
1302
1302
1303 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1303 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1304 {
1304 {
1305 fbins_mask_dump[k] = fbins_mask_TC[k];
1305 fbins_mask_dump[k] = fbins_mask_TC[k];
1306 }
1306 }
1307
1307
1308 return status;
1308 return status;
1309 }
1309 }
1310
1310
1311 //***************************
1311 //***************************
1312 // TC_LFR_LOAD_PAS_FILTER_PAR
1312 // TC_LFR_LOAD_PAS_FILTER_PAR
1313
1313
1314 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1314 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1315 {
1315 {
1316 int flag;
1316 int flag;
1317 rtems_status_code status;
1317 rtems_status_code status;
1318
1318
1319 unsigned char sy_lfr_pas_filter_enabled;
1319 unsigned char sy_lfr_pas_filter_enabled;
1320 unsigned char sy_lfr_pas_filter_modulus;
1320 unsigned char sy_lfr_pas_filter_modulus;
1321 float sy_lfr_pas_filter_tbad;
1321 float sy_lfr_pas_filter_tbad;
1322 unsigned char sy_lfr_pas_filter_offset;
1322 unsigned char sy_lfr_pas_filter_offset;
1323 float sy_lfr_pas_filter_shift;
1323 float sy_lfr_pas_filter_shift;
1324 float sy_lfr_sc_rw_delta_f;
1324 float sy_lfr_sc_rw_delta_f;
1325 char *parPtr;
1325 char *parPtr;
1326
1326
1327 flag = LFR_SUCCESSFUL;
1327 flag = LFR_SUCCESSFUL;
1328 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1328 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1329 sy_lfr_pas_filter_shift = INIT_FLOAT;
1329 sy_lfr_pas_filter_shift = INIT_FLOAT;
1330 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1330 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1331 parPtr = NULL;
1331 parPtr = NULL;
1332
1332
1333 //***************
1333 //***************
1334 // get parameters
1334 // get parameters
1335 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1335 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1336 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1336 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1337 copyFloatByChar(
1337 copyFloatByChar(
1338 (unsigned char*) &sy_lfr_pas_filter_tbad,
1338 (unsigned char*) &sy_lfr_pas_filter_tbad,
1339 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1339 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1340 );
1340 );
1341 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1341 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1342 copyFloatByChar(
1342 copyFloatByChar(
1343 (unsigned char*) &sy_lfr_pas_filter_shift,
1343 (unsigned char*) &sy_lfr_pas_filter_shift,
1344 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1344 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1345 );
1345 );
1346 copyFloatByChar(
1346 copyFloatByChar(
1347 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1347 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1348 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1348 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1349 );
1349 );
1350
1350
1351 //******************
1351 //******************
1352 // CHECK CONSISTENCY
1352 // CHECK CONSISTENCY
1353
1353
1354 //**************************
1354 //**************************
1355 // sy_lfr_pas_filter_enabled
1355 // sy_lfr_pas_filter_enabled
1356 // nothing to check, value is 0 or 1
1356 // nothing to check, value is 0 or 1
1357
1357
1358 //**************************
1358 //**************************
1359 // sy_lfr_pas_filter_modulus
1359 // sy_lfr_pas_filter_modulus
1360 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1360 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1361 {
1361 {
1362 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1362 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1363 flag = WRONG_APP_DATA;
1363 flag = WRONG_APP_DATA;
1364 }
1364 }
1365
1365
1366 //***********************
1366 //***********************
1367 // sy_lfr_pas_filter_tbad
1367 // sy_lfr_pas_filter_tbad
1368 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1368 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1369 {
1369 {
1370 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1370 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1371 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1371 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1372 flag = WRONG_APP_DATA;
1372 flag = WRONG_APP_DATA;
1373 }
1373 }
1374
1374
1375 //*************************
1375 //*************************
1376 // sy_lfr_pas_filter_offset
1376 // sy_lfr_pas_filter_offset
1377 if (flag == LFR_SUCCESSFUL)
1377 if (flag == LFR_SUCCESSFUL)
1378 {
1378 {
1379 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1379 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1380 {
1380 {
1381 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1381 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1382 flag = WRONG_APP_DATA;
1382 flag = WRONG_APP_DATA;
1383 }
1383 }
1384 }
1384 }
1385
1385
1386 //************************
1386 //************************
1387 // sy_lfr_pas_filter_shift
1387 // sy_lfr_pas_filter_shift
1388 if (flag == LFR_SUCCESSFUL)
1388 if (flag == LFR_SUCCESSFUL)
1389 {
1389 {
1390 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1390 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1391 {
1391 {
1392 parPtr = (char*) &sy_lfr_pas_filter_shift;
1392 parPtr = (char*) &sy_lfr_pas_filter_shift;
1393 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1393 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1394 flag = WRONG_APP_DATA;
1394 flag = WRONG_APP_DATA;
1395 }
1395 }
1396 }
1396 }
1397
1397
1398 //*************************************
1398 //*************************************
1399 // check global coherency of the values
1399 // check global coherency of the values
1400 if (flag == LFR_SUCCESSFUL)
1400 if (flag == LFR_SUCCESSFUL)
1401 {
1401 {
1402 if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus )
1402 if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus )
1403 {
1403 {
1404 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1404 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1405 flag = WRONG_APP_DATA;
1405 flag = WRONG_APP_DATA;
1406 }
1406 }
1407 }
1407 }
1408
1408
1409 //*********************
1409 //*********************
1410 // sy_lfr_sc_rw_delta_f
1410 // sy_lfr_sc_rw_delta_f
1411 // nothing to check, no default value in the ICD
1411 // nothing to check, no default value in the ICD
1412
1412
1413 return flag;
1413 return flag;
1414 }
1414 }
1415
1415
1416 //**************
1416 //**************
1417 // KCOEFFICIENTS
1417 // KCOEFFICIENTS
1418 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1418 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1419 {
1419 {
1420 unsigned int kcoeff;
1420 unsigned int kcoeff;
1421 unsigned short sy_lfr_kcoeff_frequency;
1421 unsigned short sy_lfr_kcoeff_frequency;
1422 unsigned short bin;
1422 unsigned short bin;
1423 unsigned short *freqPtr;
1423 unsigned short *freqPtr;
1424 float *kcoeffPtr_norm;
1424 float *kcoeffPtr_norm;
1425 float *kcoeffPtr_sbm;
1425 float *kcoeffPtr_sbm;
1426 int status;
1426 int status;
1427 unsigned char *kcoeffLoadPtr;
1427 unsigned char *kcoeffLoadPtr;
1428 unsigned char *kcoeffNormPtr;
1428 unsigned char *kcoeffNormPtr;
1429 unsigned char *kcoeffSbmPtr_a;
1429 unsigned char *kcoeffSbmPtr_a;
1430 unsigned char *kcoeffSbmPtr_b;
1430 unsigned char *kcoeffSbmPtr_b;
1431
1431
1432 status = LFR_SUCCESSFUL;
1432 status = LFR_SUCCESSFUL;
1433
1433
1434 kcoeffPtr_norm = NULL;
1434 kcoeffPtr_norm = NULL;
1435 kcoeffPtr_sbm = NULL;
1435 kcoeffPtr_sbm = NULL;
1436 bin = 0;
1436 bin = 0;
1437
1437
1438 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1438 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1439 sy_lfr_kcoeff_frequency = *freqPtr;
1439 sy_lfr_kcoeff_frequency = *freqPtr;
1440
1440
1441 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1441 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1442 {
1442 {
1443 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1443 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1444 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1,
1444 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1,
1445 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1445 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1446 status = LFR_DEFAULT;
1446 status = LFR_DEFAULT;
1447 }
1447 }
1448 else
1448 else
1449 {
1449 {
1450 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1450 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1451 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1451 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1452 {
1452 {
1453 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1453 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1454 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1454 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1455 bin = sy_lfr_kcoeff_frequency;
1455 bin = sy_lfr_kcoeff_frequency;
1456 }
1456 }
1457 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1457 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1458 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1458 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1459 {
1459 {
1460 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1460 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1461 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1461 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1462 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1462 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1463 }
1463 }
1464 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1464 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1465 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1465 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1466 {
1466 {
1467 kcoeffPtr_norm = k_coeff_intercalib_f2;
1467 kcoeffPtr_norm = k_coeff_intercalib_f2;
1468 kcoeffPtr_sbm = NULL;
1468 kcoeffPtr_sbm = NULL;
1469 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1469 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1470 }
1470 }
1471 }
1471 }
1472
1472
1473 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1473 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1474 {
1474 {
1475 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1475 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1476 {
1476 {
1477 // destination
1477 // destination
1478 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1478 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1479 // source
1479 // source
1480 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1480 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1481 // copy source to destination
1481 // copy source to destination
1482 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1482 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1483 }
1483 }
1484 }
1484 }
1485
1485
1486 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1486 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1487 {
1487 {
1488 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1488 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1489 {
1489 {
1490 // destination
1490 // destination
1491 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1491 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1492 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1492 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1493 // source
1493 // source
1494 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1494 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1495 // copy source to destination
1495 // copy source to destination
1496 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1496 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1497 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1497 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1498 }
1498 }
1499 }
1499 }
1500
1500
1501 // print_k_coeff();
1501 // print_k_coeff();
1502
1502
1503 return status;
1503 return status;
1504 }
1504 }
1505
1505
1506 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1506 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1507 {
1507 {
1508 destination[BYTE_0] = source[BYTE_0];
1508 destination[BYTE_0] = source[BYTE_0];
1509 destination[BYTE_1] = source[BYTE_1];
1509 destination[BYTE_1] = source[BYTE_1];
1510 destination[BYTE_2] = source[BYTE_2];
1510 destination[BYTE_2] = source[BYTE_2];
1511 destination[BYTE_3] = source[BYTE_3];
1511 destination[BYTE_3] = source[BYTE_3];
1512 }
1512 }
1513
1513
1514 void copyInt32ByChar( unsigned char *destination, unsigned char *source )
1515 {
1516 destination[BYTE_0] = source[BYTE_0];
1517 destination[BYTE_1] = source[BYTE_1];
1518 destination[BYTE_2] = source[BYTE_2];
1519 destination[BYTE_3] = source[BYTE_3];
1520 }
1521
1514 void floatToChar( float value, unsigned char* ptr)
1522 void floatToChar( float value, unsigned char* ptr)
1515 {
1523 {
1516 unsigned char* valuePtr;
1524 unsigned char* valuePtr;
1517
1525
1518 valuePtr = (unsigned char*) &value;
1526 valuePtr = (unsigned char*) &value;
1519 ptr[BYTE_0] = valuePtr[BYTE_0];
1527 ptr[BYTE_0] = valuePtr[BYTE_0];
1520 ptr[BYTE_1] = valuePtr[BYTE_1];
1528 ptr[BYTE_1] = valuePtr[BYTE_1];
1521 ptr[BYTE_2] = valuePtr[BYTE_2];
1529 ptr[BYTE_2] = valuePtr[BYTE_2];
1522 ptr[BYTE_3] = valuePtr[BYTE_3];
1530 ptr[BYTE_3] = valuePtr[BYTE_3];
1523 }
1531 }
1524
1532
1525 //**********
1533 //**********
1526 // init dump
1534 // init dump
1527
1535
1528 void init_parameter_dump( void )
1536 void init_parameter_dump( void )
1529 {
1537 {
1530 /** This function initialize the parameter_dump_packet global variable with default values.
1538 /** This function initialize the parameter_dump_packet global variable with default values.
1531 *
1539 *
1532 */
1540 */
1533
1541
1534 unsigned int k;
1542 unsigned int k;
1535
1543
1536 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1544 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1537 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1545 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1538 parameter_dump_packet.reserved = CCSDS_RESERVED;
1546 parameter_dump_packet.reserved = CCSDS_RESERVED;
1539 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1547 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1540 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1548 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1541 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1549 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1542 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1550 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1543 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1551 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1544 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1552 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1545 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1553 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1546 // DATA FIELD HEADER
1554 // DATA FIELD HEADER
1547 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1555 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1548 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1556 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1549 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1557 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1550 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1558 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1551 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1559 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1552 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1560 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1553 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1561 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1554 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1562 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1555 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1563 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1556 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1564 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1557 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1565 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1558
1566
1559 //******************
1567 //******************
1560 // COMMON PARAMETERS
1568 // COMMON PARAMETERS
1561 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1569 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1562 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1570 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1563
1571
1564 //******************
1572 //******************
1565 // NORMAL PARAMETERS
1573 // NORMAL PARAMETERS
1566 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1574 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1567 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1575 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1568 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1576 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1569 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1577 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1570 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1578 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1571 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1579 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1572 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1580 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1573 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1581 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1574 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1582 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1575
1583
1576 //*****************
1584 //*****************
1577 // BURST PARAMETERS
1585 // BURST PARAMETERS
1578 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1586 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1579 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1587 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1580
1588
1581 //****************
1589 //****************
1582 // SBM1 PARAMETERS
1590 // SBM1 PARAMETERS
1583 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1591 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1584 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1592 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1585
1593
1586 //****************
1594 //****************
1587 // SBM2 PARAMETERS
1595 // SBM2 PARAMETERS
1588 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1596 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1589 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1597 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1590
1598
1591 //************
1599 //************
1592 // FBINS MASKS
1600 // FBINS MASKS
1593 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1601 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1594 {
1602 {
1595 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F;
1603 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F;
1596 }
1604 }
1597
1605
1598 // PAS FILTER PARAMETERS
1606 // PAS FILTER PARAMETERS
1599 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1607 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1600 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1608 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1601 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1609 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1602 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1610 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1603 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1611 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1604 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1612 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1605 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1613 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1606
1614
1607 // RW1_K
1615 // RW1_K
1608 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw1_k1);
1616 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw1_k1);
1609 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw1_k2);
1617 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw1_k2);
1610 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw1_k3);
1618 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw1_k3);
1611 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw1_k4);
1619 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw1_k4);
1612 // RW2_K
1620 // RW2_K
1613 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw2_k1);
1621 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw2_k1);
1614 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw2_k2);
1622 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw2_k2);
1615 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw2_k3);
1623 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw2_k3);
1616 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw2_k4);
1624 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw2_k4);
1617 // RW3_K
1625 // RW3_K
1618 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw3_k1);
1626 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw3_k1);
1619 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw3_k2);
1627 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw3_k2);
1620 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw3_k3);
1628 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw3_k3);
1621 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw3_k4);
1629 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw3_k4);
1622 // RW4_K
1630 // RW4_K
1623 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw4_k1);
1631 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw4_k1);
1624 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw4_k2);
1632 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw4_k2);
1625 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw4_k3);
1633 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw4_k3);
1626 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw4_k4);
1634 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw4_k4);
1627
1635
1628 // LFR_RW_MASK
1636 // LFR_RW_MASK
1629 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1637 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1630 {
1638 {
1631 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F;
1639 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F;
1632 }
1640 }
1633
1641
1634 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1642 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1635 merge_fbins_masks();
1643 merge_fbins_masks();
1636 }
1644 }
1637
1645
1638 void init_kcoefficients_dump( void )
1646 void init_kcoefficients_dump( void )
1639 {
1647 {
1640 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1648 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1641 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1649 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1642
1650
1643 kcoefficient_node_1.previous = NULL;
1651 kcoefficient_node_1.previous = NULL;
1644 kcoefficient_node_1.next = NULL;
1652 kcoefficient_node_1.next = NULL;
1645 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1653 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1646 kcoefficient_node_1.coarseTime = INIT_CHAR;
1654 kcoefficient_node_1.coarseTime = INIT_CHAR;
1647 kcoefficient_node_1.fineTime = INIT_CHAR;
1655 kcoefficient_node_1.fineTime = INIT_CHAR;
1648 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1656 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1649 kcoefficient_node_1.status = INIT_CHAR;
1657 kcoefficient_node_1.status = INIT_CHAR;
1650
1658
1651 kcoefficient_node_2.previous = NULL;
1659 kcoefficient_node_2.previous = NULL;
1652 kcoefficient_node_2.next = NULL;
1660 kcoefficient_node_2.next = NULL;
1653 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1661 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1654 kcoefficient_node_2.coarseTime = INIT_CHAR;
1662 kcoefficient_node_2.coarseTime = INIT_CHAR;
1655 kcoefficient_node_2.fineTime = INIT_CHAR;
1663 kcoefficient_node_2.fineTime = INIT_CHAR;
1656 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1664 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1657 kcoefficient_node_2.status = INIT_CHAR;
1665 kcoefficient_node_2.status = INIT_CHAR;
1658 }
1666 }
1659
1667
1660 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1668 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1661 {
1669 {
1662 unsigned int k;
1670 unsigned int k;
1663 unsigned int packetLength;
1671 unsigned int packetLength;
1664
1672
1665 packetLength =
1673 packetLength =
1666 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1674 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1667
1675
1668 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1676 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1669 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1677 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1670 kcoefficients_dump->reserved = CCSDS_RESERVED;
1678 kcoefficients_dump->reserved = CCSDS_RESERVED;
1671 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1679 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1672 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1680 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1673 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1681 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1674 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1682 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1675 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1683 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1676 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1684 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1677 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1685 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1678 // DATA FIELD HEADER
1686 // DATA FIELD HEADER
1679 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1687 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1680 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1688 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1681 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1689 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1682 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1690 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1683 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1691 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1684 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1692 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1685 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1693 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1686 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1694 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1687 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1695 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1688 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1696 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1689 kcoefficients_dump->sid = SID_K_DUMP;
1697 kcoefficients_dump->sid = SID_K_DUMP;
1690
1698
1691 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1699 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1692 kcoefficients_dump->pkt_nr = PKTNR_1;
1700 kcoefficients_dump->pkt_nr = PKTNR_1;
1693 kcoefficients_dump->blk_nr = blk_nr;
1701 kcoefficients_dump->blk_nr = blk_nr;
1694
1702
1695 //******************
1703 //******************
1696 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1704 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1697 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1705 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1698 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1706 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1699 {
1707 {
1700 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1708 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1701 }
1709 }
1702 }
1710 }
1703
1711
1704 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1712 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1705 {
1713 {
1706 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1714 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1707 *
1715 *
1708 * @param packet_sequence_control points to the packet sequence control which will be incremented
1716 * @param packet_sequence_control points to the packet sequence control which will be incremented
1709 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1717 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1710 *
1718 *
1711 * If the destination ID is not known, a dedicated counter is incremented.
1719 * If the destination ID is not known, a dedicated counter is incremented.
1712 *
1720 *
1713 */
1721 */
1714
1722
1715 unsigned short sequence_cnt;
1723 unsigned short sequence_cnt;
1716 unsigned short segmentation_grouping_flag;
1724 unsigned short segmentation_grouping_flag;
1717 unsigned short new_packet_sequence_control;
1725 unsigned short new_packet_sequence_control;
1718 unsigned char i;
1726 unsigned char i;
1719
1727
1720 switch (destination_id)
1728 switch (destination_id)
1721 {
1729 {
1722 case SID_TC_GROUND:
1730 case SID_TC_GROUND:
1723 i = GROUND;
1731 i = GROUND;
1724 break;
1732 break;
1725 case SID_TC_MISSION_TIMELINE:
1733 case SID_TC_MISSION_TIMELINE:
1726 i = MISSION_TIMELINE;
1734 i = MISSION_TIMELINE;
1727 break;
1735 break;
1728 case SID_TC_TC_SEQUENCES:
1736 case SID_TC_TC_SEQUENCES:
1729 i = TC_SEQUENCES;
1737 i = TC_SEQUENCES;
1730 break;
1738 break;
1731 case SID_TC_RECOVERY_ACTION_CMD:
1739 case SID_TC_RECOVERY_ACTION_CMD:
1732 i = RECOVERY_ACTION_CMD;
1740 i = RECOVERY_ACTION_CMD;
1733 break;
1741 break;
1734 case SID_TC_BACKUP_MISSION_TIMELINE:
1742 case SID_TC_BACKUP_MISSION_TIMELINE:
1735 i = BACKUP_MISSION_TIMELINE;
1743 i = BACKUP_MISSION_TIMELINE;
1736 break;
1744 break;
1737 case SID_TC_DIRECT_CMD:
1745 case SID_TC_DIRECT_CMD:
1738 i = DIRECT_CMD;
1746 i = DIRECT_CMD;
1739 break;
1747 break;
1740 case SID_TC_SPARE_GRD_SRC1:
1748 case SID_TC_SPARE_GRD_SRC1:
1741 i = SPARE_GRD_SRC1;
1749 i = SPARE_GRD_SRC1;
1742 break;
1750 break;
1743 case SID_TC_SPARE_GRD_SRC2:
1751 case SID_TC_SPARE_GRD_SRC2:
1744 i = SPARE_GRD_SRC2;
1752 i = SPARE_GRD_SRC2;
1745 break;
1753 break;
1746 case SID_TC_OBCP:
1754 case SID_TC_OBCP:
1747 i = OBCP;
1755 i = OBCP;
1748 break;
1756 break;
1749 case SID_TC_SYSTEM_CONTROL:
1757 case SID_TC_SYSTEM_CONTROL:
1750 i = SYSTEM_CONTROL;
1758 i = SYSTEM_CONTROL;
1751 break;
1759 break;
1752 case SID_TC_AOCS:
1760 case SID_TC_AOCS:
1753 i = AOCS;
1761 i = AOCS;
1754 break;
1762 break;
1755 case SID_TC_RPW_INTERNAL:
1763 case SID_TC_RPW_INTERNAL:
1756 i = RPW_INTERNAL;
1764 i = RPW_INTERNAL;
1757 break;
1765 break;
1758 default:
1766 default:
1759 i = GROUND;
1767 i = GROUND;
1760 break;
1768 break;
1761 }
1769 }
1762
1770
1763 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1771 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1764 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
1772 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
1765
1773
1766 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1774 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1767
1775
1768 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1776 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1769 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1777 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1770
1778
1771 // increment the sequence counter
1779 // increment the sequence counter
1772 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1780 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1773 {
1781 {
1774 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1782 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1775 }
1783 }
1776 else
1784 else
1777 {
1785 {
1778 sequenceCounters_TM_DUMP[ i ] = 0;
1786 sequenceCounters_TM_DUMP[ i ] = 0;
1779 }
1787 }
1780 }
1788 }
General Comments 0
You need to be logged in to leave comments. Login now