##// END OF EJS Templates
3.1.0.3...
paul -
r296:fb16b781e584 R3_plus draft
parent child
Show More
@@ -1,125 +1,125
1 TEMPLATE = app
1 TEMPLATE = app
2 # CONFIG += console v8 sim
2 # CONFIG += console v8 sim
3 # CONFIG options =
3 # CONFIG options =
4 # verbose
4 # verbose
5 # boot_messages
5 # boot_messages
6 # debug_messages
6 # debug_messages
7 # cpu_usage_report
7 # cpu_usage_report
8 # stack_report
8 # stack_report
9 # vhdl_dev
9 # vhdl_dev
10 # debug_tch
10 # debug_tch
11 # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\
11 # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\
12 # debug_watchdog
12 # debug_watchdog
13 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
13 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
14 CONFIG -= qt
14 CONFIG -= qt
15
15
16 include(./sparc.pri)
16 include(./sparc.pri)
17
17
18 INCLUDEPATH += /opt/rtems-4.10/sparc-rtems/leon3/lib/include
18 INCLUDEPATH += /opt/rtems-4.10/sparc-rtems/leon3/lib/include
19
19
20 # flight software version
20 # flight software version
21 SWVERSION=-1-0
21 SWVERSION=-1-0
22 DEFINES += SW_VERSION_N1=3 # major
22 DEFINES += SW_VERSION_N1=3 # major
23 DEFINES += SW_VERSION_N2=1 # minor
23 DEFINES += SW_VERSION_N2=1 # minor
24 DEFINES += SW_VERSION_N3=0 # patch
24 DEFINES += SW_VERSION_N3=0 # patch
25 DEFINES += SW_VERSION_N4=2 # internal
25 DEFINES += SW_VERSION_N4=3 # internal
26
26
27 # <GCOV>
27 # <GCOV>
28 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
28 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
29 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
29 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
30 # </GCOV>
30 # </GCOV>
31
31
32 # <CHANGE BEFORE FLIGHT>
32 # <CHANGE BEFORE FLIGHT>
33 contains( CONFIG, lpp_dpu_destid ) {
33 contains( CONFIG, lpp_dpu_destid ) {
34 DEFINES += LPP_DPU_DESTID
34 DEFINES += LPP_DPU_DESTID
35 }
35 }
36 # </CHANGE BEFORE FLIGHT>
36 # </CHANGE BEFORE FLIGHT>
37
37
38 contains( CONFIG, debug_tch ) {
38 contains( CONFIG, debug_tch ) {
39 DEFINES += DEBUG_TCH
39 DEFINES += DEBUG_TCH
40 }
40 }
41 DEFINES += MSB_FIRST_TCH
41 DEFINES += MSB_FIRST_TCH
42
42
43 contains( CONFIG, vhdl_dev ) {
43 contains( CONFIG, vhdl_dev ) {
44 DEFINES += VHDL_DEV
44 DEFINES += VHDL_DEV
45 }
45 }
46
46
47 contains( CONFIG, verbose ) {
47 contains( CONFIG, verbose ) {
48 DEFINES += PRINT_MESSAGES_ON_CONSOLE
48 DEFINES += PRINT_MESSAGES_ON_CONSOLE
49 }
49 }
50
50
51 contains( CONFIG, debug_messages ) {
51 contains( CONFIG, debug_messages ) {
52 DEFINES += DEBUG_MESSAGES
52 DEFINES += DEBUG_MESSAGES
53 }
53 }
54
54
55 contains( CONFIG, cpu_usage_report ) {
55 contains( CONFIG, cpu_usage_report ) {
56 DEFINES += PRINT_TASK_STATISTICS
56 DEFINES += PRINT_TASK_STATISTICS
57 }
57 }
58
58
59 contains( CONFIG, stack_report ) {
59 contains( CONFIG, stack_report ) {
60 DEFINES += PRINT_STACK_REPORT
60 DEFINES += PRINT_STACK_REPORT
61 }
61 }
62
62
63 contains( CONFIG, boot_messages ) {
63 contains( CONFIG, boot_messages ) {
64 DEFINES += BOOT_MESSAGES
64 DEFINES += BOOT_MESSAGES
65 }
65 }
66
66
67 contains( CONFIG, debug_watchdog ) {
67 contains( CONFIG, debug_watchdog ) {
68 DEFINES += DEBUG_WATCHDOG
68 DEFINES += DEBUG_WATCHDOG
69 }
69 }
70
70
71 #doxygen.target = doxygen
71 #doxygen.target = doxygen
72 #doxygen.commands = doxygen ../doc/Doxyfile
72 #doxygen.commands = doxygen ../doc/Doxyfile
73 #QMAKE_EXTRA_TARGETS += doxygen
73 #QMAKE_EXTRA_TARGETS += doxygen
74
74
75 TARGET = fsw
75 TARGET = fsw
76
76
77 INCLUDEPATH += \
77 INCLUDEPATH += \
78 $${PWD}/../src \
78 $${PWD}/../src \
79 $${PWD}/../header \
79 $${PWD}/../header \
80 $${PWD}/../header/lfr_common_headers \
80 $${PWD}/../header/lfr_common_headers \
81 $${PWD}/../header/processing \
81 $${PWD}/../header/processing \
82 $${PWD}/../LFR_basic-parameters
82 $${PWD}/../LFR_basic-parameters
83
83
84 SOURCES += \
84 SOURCES += \
85 ../src/wf_handler.c \
85 ../src/wf_handler.c \
86 ../src/tc_handler.c \
86 ../src/tc_handler.c \
87 ../src/fsw_misc.c \
87 ../src/fsw_misc.c \
88 ../src/fsw_init.c \
88 ../src/fsw_init.c \
89 ../src/fsw_globals.c \
89 ../src/fsw_globals.c \
90 ../src/fsw_spacewire.c \
90 ../src/fsw_spacewire.c \
91 ../src/tc_load_dump_parameters.c \
91 ../src/tc_load_dump_parameters.c \
92 ../src/tm_lfr_tc_exe.c \
92 ../src/tm_lfr_tc_exe.c \
93 ../src/tc_acceptance.c \
93 ../src/tc_acceptance.c \
94 ../src/processing/fsw_processing.c \
94 ../src/processing/fsw_processing.c \
95 ../src/processing/avf0_prc0.c \
95 ../src/processing/avf0_prc0.c \
96 ../src/processing/avf1_prc1.c \
96 ../src/processing/avf1_prc1.c \
97 ../src/processing/avf2_prc2.c \
97 ../src/processing/avf2_prc2.c \
98 ../src/lfr_cpu_usage_report.c \
98 ../src/lfr_cpu_usage_report.c \
99 ../LFR_basic-parameters/basic_parameters.c
99 ../LFR_basic-parameters/basic_parameters.c
100
100
101 HEADERS += \
101 HEADERS += \
102 ../header/wf_handler.h \
102 ../header/wf_handler.h \
103 ../header/tc_handler.h \
103 ../header/tc_handler.h \
104 ../header/grlib_regs.h \
104 ../header/grlib_regs.h \
105 ../header/fsw_misc.h \
105 ../header/fsw_misc.h \
106 ../header/fsw_init.h \
106 ../header/fsw_init.h \
107 ../header/fsw_spacewire.h \
107 ../header/fsw_spacewire.h \
108 ../header/tc_load_dump_parameters.h \
108 ../header/tc_load_dump_parameters.h \
109 ../header/tm_lfr_tc_exe.h \
109 ../header/tm_lfr_tc_exe.h \
110 ../header/tc_acceptance.h \
110 ../header/tc_acceptance.h \
111 ../header/processing/fsw_processing.h \
111 ../header/processing/fsw_processing.h \
112 ../header/processing/avf0_prc0.h \
112 ../header/processing/avf0_prc0.h \
113 ../header/processing/avf1_prc1.h \
113 ../header/processing/avf1_prc1.h \
114 ../header/processing/avf2_prc2.h \
114 ../header/processing/avf2_prc2.h \
115 ../header/fsw_params_wf_handler.h \
115 ../header/fsw_params_wf_handler.h \
116 ../header/lfr_cpu_usage_report.h \
116 ../header/lfr_cpu_usage_report.h \
117 ../header/lfr_common_headers/ccsds_types.h \
117 ../header/lfr_common_headers/ccsds_types.h \
118 ../header/lfr_common_headers/fsw_params.h \
118 ../header/lfr_common_headers/fsw_params.h \
119 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
119 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
120 ../header/lfr_common_headers/fsw_params_processing.h \
120 ../header/lfr_common_headers/fsw_params_processing.h \
121 ../header/lfr_common_headers/tm_byte_positions.h \
121 ../header/lfr_common_headers/tm_byte_positions.h \
122 ../LFR_basic-parameters/basic_parameters.h \
122 ../LFR_basic-parameters/basic_parameters.h \
123 ../LFR_basic-parameters/basic_parameters_params.h \
123 ../LFR_basic-parameters/basic_parameters_params.h \
124 ../header/GscMemoryLPP.hpp
124 ../header/GscMemoryLPP.hpp
125
125
@@ -1,1599 +1,1599
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;
16 rtems_name semq_name;
17 rtems_id semq_id;
17 rtems_id semq_id;
18
18
19 //*****************
19 //*****************
20 // waveform headers
20 // waveform headers
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
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 BOOT_PRINTF("in SPIQ *** \n")
42 BOOT_PRINTF("in SPIQ *** \n")
43
43
44 while(true){
44 while(true){
45 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
45 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
46 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
46 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
47
47
48 // [0] SUSPEND RECV AND SEND TASKS
48 // [0] SUSPEND RECV AND SEND TASKS
49 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
49 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
50 if ( status != RTEMS_SUCCESSFUL ) {
50 if ( status != RTEMS_SUCCESSFUL ) {
51 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
51 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
52 }
52 }
53 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
53 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
54 if ( status != RTEMS_SUCCESSFUL ) {
54 if ( status != RTEMS_SUCCESSFUL ) {
55 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
55 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
56 }
56 }
57
57
58 // [1] CHECK THE LINK
58 // [1] CHECK THE LINK
59 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
59 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
60 if ( linkStatus != 5) {
60 if ( linkStatus != 5) {
61 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
61 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
62 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
62 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
63 }
63 }
64
64
65 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
65 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
66 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
66 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
67 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
67 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
68 {
68 {
69 spacewire_read_statistics();
69 spacewire_read_statistics();
70 status = spacewire_several_connect_attemps( );
70 status = spacewire_several_connect_attemps( );
71 }
71 }
72 else // [2.b] in run state, start the link
72 else // [2.b] in run state, start the link
73 {
73 {
74 status = spacewire_stop_and_start_link( fdSPW ); // start the link
74 status = spacewire_stop_and_start_link( fdSPW ); // start the link
75 if ( status != RTEMS_SUCCESSFUL)
75 if ( status != RTEMS_SUCCESSFUL)
76 {
76 {
77 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
77 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
78 }
78 }
79 }
79 }
80
80
81 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
81 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
82 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
82 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
83 {
83 {
84 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
84 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
85 if ( status != RTEMS_SUCCESSFUL ) {
85 if ( status != RTEMS_SUCCESSFUL ) {
86 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
86 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
87 }
87 }
88 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
88 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
89 if ( status != RTEMS_SUCCESSFUL ) {
89 if ( status != RTEMS_SUCCESSFUL ) {
90 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
90 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
91 }
91 }
92 }
92 }
93 else // [3.b] the link is not in run state, go in STANDBY mode
93 else // [3.b] the link is not in run state, go in STANDBY mode
94 {
94 {
95 status = enter_mode_standby();
95 status = enter_mode_standby();
96 if ( status != RTEMS_SUCCESSFUL )
96 if ( status != RTEMS_SUCCESSFUL )
97 {
97 {
98 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
98 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
99 }
99 }
100 {
100 {
101 updateLFRCurrentMode( LFR_MODE_STANDBY );
101 updateLFRCurrentMode( LFR_MODE_STANDBY );
102 }
102 }
103 // wake the LINK task up to wait for the link recovery
103 // wake the LINK task up to wait for the link recovery
104 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
104 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
105 status = rtems_task_suspend( RTEMS_SELF );
105 status = rtems_task_suspend( RTEMS_SELF );
106 }
106 }
107 }
107 }
108 }
108 }
109
109
110 rtems_task recv_task( rtems_task_argument unused )
110 rtems_task recv_task( rtems_task_argument unused )
111 {
111 {
112 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
112 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
113 *
113 *
114 * @param unused is the starting argument of the RTEMS task
114 * @param unused is the starting argument of the RTEMS task
115 *
115 *
116 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
116 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
117 * 1. It reads the incoming data.
117 * 1. It reads the incoming data.
118 * 2. Launches the acceptance procedure.
118 * 2. Launches the acceptance procedure.
119 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
119 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
120 *
120 *
121 */
121 */
122
122
123 int len;
123 int len;
124 ccsdsTelecommandPacket_t currentTC;
124 ccsdsTelecommandPacket_t currentTC;
125 unsigned char computed_CRC[ 2 ];
125 unsigned char computed_CRC[ 2 ];
126 unsigned char currentTC_LEN_RCV[ 2 ];
126 unsigned char currentTC_LEN_RCV[ 2 ];
127 unsigned char destinationID;
127 unsigned char destinationID;
128 unsigned int estimatedPacketLength;
128 unsigned int estimatedPacketLength;
129 unsigned int parserCode;
129 unsigned int parserCode;
130 rtems_status_code status;
130 rtems_status_code status;
131 rtems_id queue_recv_id;
131 rtems_id queue_recv_id;
132 rtems_id queue_send_id;
132 rtems_id queue_send_id;
133
133
134 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
134 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
135
135
136 status = get_message_queue_id_recv( &queue_recv_id );
136 status = get_message_queue_id_recv( &queue_recv_id );
137 if (status != RTEMS_SUCCESSFUL)
137 if (status != RTEMS_SUCCESSFUL)
138 {
138 {
139 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
139 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
140 }
140 }
141
141
142 status = get_message_queue_id_send( &queue_send_id );
142 status = get_message_queue_id_send( &queue_send_id );
143 if (status != RTEMS_SUCCESSFUL)
143 if (status != RTEMS_SUCCESSFUL)
144 {
144 {
145 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
145 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
146 }
146 }
147
147
148 BOOT_PRINTF("in RECV *** \n")
148 BOOT_PRINTF("in RECV *** \n")
149
149
150 while(1)
150 while(1)
151 {
151 {
152 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
152 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
153 if (len == -1){ // error during the read call
153 if (len == -1){ // error during the read call
154 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
154 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
155 }
155 }
156 else {
156 else {
157 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
157 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
158 PRINTF("in RECV *** packet lenght too short\n")
158 PRINTF("in RECV *** packet lenght too short\n")
159 }
159 }
160 else {
160 else {
161 PRINTF1("incoming TC with len: %d\n", len);
161 // PRINTF1("incoming TC with len: %d\n", len);
162 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
162 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
163 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
163 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
164 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
164 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
165 // CHECK THE TC
165 // CHECK THE TC
166 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
166 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
167 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
167 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
168 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
168 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
169 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
169 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
170 || (parserCode == WRONG_SRC_ID) )
170 || (parserCode == WRONG_SRC_ID) )
171 { // send TM_LFR_TC_EXE_CORRUPTED
171 { // send TM_LFR_TC_EXE_CORRUPTED
172 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
172 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
173 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
173 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
174 &&
174 &&
175 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
175 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
176 )
176 )
177 {
177 {
178 if ( parserCode == WRONG_SRC_ID )
178 if ( parserCode == WRONG_SRC_ID )
179 {
179 {
180 destinationID = SID_TC_GROUND;
180 destinationID = SID_TC_GROUND;
181 }
181 }
182 else
182 else
183 {
183 {
184 destinationID = currentTC.sourceID;
184 destinationID = currentTC.sourceID;
185 }
185 }
186 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
186 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
187 computed_CRC, currentTC_LEN_RCV,
187 computed_CRC, currentTC_LEN_RCV,
188 destinationID );
188 destinationID );
189 }
189 }
190 }
190 }
191 else
191 else
192 { // send valid TC to the action launcher
192 { // send valid TC to the action launcher
193 status = rtems_message_queue_send( queue_recv_id, &currentTC,
193 status = rtems_message_queue_send( queue_recv_id, &currentTC,
194 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
194 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
195 }
195 }
196 }
196 }
197 }
197 }
198
198
199 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
199 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
200
200
201 }
201 }
202 }
202 }
203
203
204 rtems_task send_task( rtems_task_argument argument)
204 rtems_task send_task( rtems_task_argument argument)
205 {
205 {
206 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
206 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
207 *
207 *
208 * @param unused is the starting argument of the RTEMS task
208 * @param unused is the starting argument of the RTEMS task
209 *
209 *
210 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
210 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
211 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
211 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
212 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
212 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
213 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
213 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
214 * data it contains.
214 * data it contains.
215 *
215 *
216 */
216 */
217
217
218 rtems_status_code status; // RTEMS status code
218 rtems_status_code status; // RTEMS status code
219 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
219 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
220 ring_node *incomingRingNodePtr;
220 ring_node *incomingRingNodePtr;
221 int ring_node_address;
221 int ring_node_address;
222 char *charPtr;
222 char *charPtr;
223 spw_ioctl_pkt_send *spw_ioctl_send;
223 spw_ioctl_pkt_send *spw_ioctl_send;
224 size_t size; // size of the incoming TC packet
224 size_t size; // size of the incoming TC packet
225 rtems_id queue_send_id;
225 rtems_id queue_send_id;
226 unsigned int sid;
226 unsigned int sid;
227 unsigned char sidAsUnsignedChar;
227 unsigned char sidAsUnsignedChar;
228 unsigned char type;
228 unsigned char type;
229
229
230 incomingRingNodePtr = NULL;
230 incomingRingNodePtr = NULL;
231 ring_node_address = 0;
231 ring_node_address = 0;
232 charPtr = (char *) &ring_node_address;
232 charPtr = (char *) &ring_node_address;
233 sid = 0;
233 sid = 0;
234 sidAsUnsignedChar = 0;
234 sidAsUnsignedChar = 0;
235
235
236 init_header_cwf( &headerCWF );
236 init_header_cwf( &headerCWF );
237 init_header_swf( &headerSWF );
237 init_header_swf( &headerSWF );
238 init_header_asm( &headerASM );
238 init_header_asm( &headerASM );
239
239
240 status = get_message_queue_id_send( &queue_send_id );
240 status = get_message_queue_id_send( &queue_send_id );
241 if (status != RTEMS_SUCCESSFUL)
241 if (status != RTEMS_SUCCESSFUL)
242 {
242 {
243 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
243 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
244 }
244 }
245
245
246 BOOT_PRINTF("in SEND *** \n")
246 BOOT_PRINTF("in SEND *** \n")
247
247
248 while(1)
248 while(1)
249 {
249 {
250 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
250 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
251 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
251 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
252
252
253 if (status!=RTEMS_SUCCESSFUL)
253 if (status!=RTEMS_SUCCESSFUL)
254 {
254 {
255 PRINTF1("in SEND *** (1) ERR = %d\n", status)
255 PRINTF1("in SEND *** (1) ERR = %d\n", status)
256 }
256 }
257 else
257 else
258 {
258 {
259 if ( size == sizeof(ring_node*) )
259 if ( size == sizeof(ring_node*) )
260 {
260 {
261 charPtr[0] = incomingData[0];
261 charPtr[0] = incomingData[0];
262 charPtr[1] = incomingData[1];
262 charPtr[1] = incomingData[1];
263 charPtr[2] = incomingData[2];
263 charPtr[2] = incomingData[2];
264 charPtr[3] = incomingData[3];
264 charPtr[3] = incomingData[3];
265 incomingRingNodePtr = (ring_node*) ring_node_address;
265 incomingRingNodePtr = (ring_node*) ring_node_address;
266 sid = incomingRingNodePtr->sid;
266 sid = incomingRingNodePtr->sid;
267 if ( (sid==SID_NORM_CWF_LONG_F3)
267 if ( (sid==SID_NORM_CWF_LONG_F3)
268 || (sid==SID_BURST_CWF_F2 )
268 || (sid==SID_BURST_CWF_F2 )
269 || (sid==SID_SBM1_CWF_F1 )
269 || (sid==SID_SBM1_CWF_F1 )
270 || (sid==SID_SBM2_CWF_F2 ))
270 || (sid==SID_SBM2_CWF_F2 ))
271 {
271 {
272 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
272 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
273 }
273 }
274 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
274 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
275 {
275 {
276 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
276 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
277 }
277 }
278 else if ( (sid==SID_NORM_CWF_F3) )
278 else if ( (sid==SID_NORM_CWF_F3) )
279 {
279 {
280 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
280 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
281 }
281 }
282 else if (sid==SID_NORM_ASM_F0)
282 else if (sid==SID_NORM_ASM_F0)
283 {
283 {
284 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
284 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
285 }
285 }
286 else if (sid==SID_NORM_ASM_F1)
286 else if (sid==SID_NORM_ASM_F1)
287 {
287 {
288 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
288 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
289 }
289 }
290 else if (sid==SID_NORM_ASM_F2)
290 else if (sid==SID_NORM_ASM_F2)
291 {
291 {
292 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
292 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
293 }
293 }
294 else if ( sid==TM_CODE_K_DUMP )
294 else if ( sid==TM_CODE_K_DUMP )
295 {
295 {
296 spw_send_k_dump( incomingRingNodePtr );
296 spw_send_k_dump( incomingRingNodePtr );
297 }
297 }
298 else
298 else
299 {
299 {
300 PRINTF1("unexpected sid = %d\n", sid);
300 PRINTF1("unexpected sid = %d\n", sid);
301 }
301 }
302 }
302 }
303 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
303 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
304 {
304 {
305 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
305 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
306 sid = sidAsUnsignedChar;
306 sid = sidAsUnsignedChar;
307 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
307 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
308 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
308 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
309 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
309 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
310 {
310 {
311 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
311 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
312 }
312 }
313
313
314 status = write( fdSPW, incomingData, size );
314 status = write( fdSPW, incomingData, size );
315 if (status == -1){
315 if (status == -1){
316 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
316 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
317 }
317 }
318 }
318 }
319 else // the incoming message is a spw_ioctl_pkt_send structure
319 else // the incoming message is a spw_ioctl_pkt_send structure
320 {
320 {
321 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
321 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
322 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
322 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
323 if (status == -1){
323 if (status == -1){
324 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
324 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
325 }
325 }
326 }
326 }
327 }
327 }
328
328
329 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
329 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
330
330
331 }
331 }
332 }
332 }
333
333
334 rtems_task link_task( rtems_task_argument argument )
334 rtems_task link_task( rtems_task_argument argument )
335 {
335 {
336 rtems_event_set event_out;
336 rtems_event_set event_out;
337 rtems_status_code status;
337 rtems_status_code status;
338 int linkStatus;
338 int linkStatus;
339
339
340 BOOT_PRINTF("in LINK ***\n")
340 BOOT_PRINTF("in LINK ***\n")
341
341
342 while(1)
342 while(1)
343 {
343 {
344 // wait for an RTEMS_EVENT
344 // wait for an RTEMS_EVENT
345 rtems_event_receive( RTEMS_EVENT_0,
345 rtems_event_receive( RTEMS_EVENT_0,
346 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
346 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
347 PRINTF("in LINK *** wait for the link\n")
347 PRINTF("in LINK *** wait for the link\n")
348 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
348 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
349 while( linkStatus != 5) // wait for the link
349 while( linkStatus != 5) // wait for the link
350 {
350 {
351 status = rtems_task_wake_after( 10 ); // monitor the link each 100ms
351 status = rtems_task_wake_after( 10 ); // monitor the link each 100ms
352 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
352 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
353 watchdog_reload();
353 watchdog_reload();
354 }
354 }
355
355
356 spacewire_read_statistics();
356 spacewire_read_statistics();
357 status = spacewire_stop_and_start_link( fdSPW );
357 status = spacewire_stop_and_start_link( fdSPW );
358
358
359 if (status != RTEMS_SUCCESSFUL)
359 if (status != RTEMS_SUCCESSFUL)
360 {
360 {
361 PRINTF1("in LINK *** ERR link not started %d\n", status)
361 PRINTF1("in LINK *** ERR link not started %d\n", status)
362 }
362 }
363 else
363 else
364 {
364 {
365 PRINTF("in LINK *** OK link started\n")
365 PRINTF("in LINK *** OK link started\n")
366 }
366 }
367
367
368 // restart the SPIQ task
368 // restart the SPIQ task
369 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
369 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
370 if ( status != RTEMS_SUCCESSFUL ) {
370 if ( status != RTEMS_SUCCESSFUL ) {
371 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
371 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
372 }
372 }
373
373
374 // restart RECV and SEND
374 // restart RECV and SEND
375 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
375 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
376 if ( status != RTEMS_SUCCESSFUL ) {
376 if ( status != RTEMS_SUCCESSFUL ) {
377 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
377 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
378 }
378 }
379 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
379 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
380 if ( status != RTEMS_SUCCESSFUL ) {
380 if ( status != RTEMS_SUCCESSFUL ) {
381 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
381 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
382 }
382 }
383 }
383 }
384 }
384 }
385
385
386 //****************
386 //****************
387 // OTHER FUNCTIONS
387 // OTHER FUNCTIONS
388 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
388 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
389 {
389 {
390 /** This function opens the SpaceWire link.
390 /** This function opens the SpaceWire link.
391 *
391 *
392 * @return a valid file descriptor in case of success, -1 in case of a failure
392 * @return a valid file descriptor in case of success, -1 in case of a failure
393 *
393 *
394 */
394 */
395 rtems_status_code status;
395 rtems_status_code status;
396
396
397 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
397 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
398 if ( fdSPW < 0 ) {
398 if ( fdSPW < 0 ) {
399 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
399 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
400 }
400 }
401 else
401 else
402 {
402 {
403 status = RTEMS_SUCCESSFUL;
403 status = RTEMS_SUCCESSFUL;
404 }
404 }
405
405
406 return status;
406 return status;
407 }
407 }
408
408
409 int spacewire_start_link( int fd )
409 int spacewire_start_link( int fd )
410 {
410 {
411 rtems_status_code status;
411 rtems_status_code status;
412
412
413 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
413 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
414 // -1 default hardcoded driver timeout
414 // -1 default hardcoded driver timeout
415
415
416 return status;
416 return status;
417 }
417 }
418
418
419 int spacewire_stop_and_start_link( int fd )
419 int spacewire_stop_and_start_link( int fd )
420 {
420 {
421 rtems_status_code status;
421 rtems_status_code status;
422
422
423 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
423 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
424 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
424 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
425 // -1 default hardcoded driver timeout
425 // -1 default hardcoded driver timeout
426
426
427 return status;
427 return status;
428 }
428 }
429
429
430 int spacewire_configure_link( int fd )
430 int spacewire_configure_link( int fd )
431 {
431 {
432 /** This function configures the SpaceWire link.
432 /** This function configures the SpaceWire link.
433 *
433 *
434 * @return GR-RTEMS-DRIVER directive status codes:
434 * @return GR-RTEMS-DRIVER directive status codes:
435 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
435 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
436 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
436 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
437 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
437 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
438 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
438 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
439 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
439 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
440 * - 5 EIO - Error when writing to grswp hardware registers.
440 * - 5 EIO - Error when writing to grswp hardware registers.
441 * - 2 ENOENT - No such file or directory
441 * - 2 ENOENT - No such file or directory
442 */
442 */
443
443
444 rtems_status_code status;
444 rtems_status_code status;
445
445
446 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
446 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
447 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
447 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
448
448
449 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
449 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
450 if (status!=RTEMS_SUCCESSFUL) {
450 if (status!=RTEMS_SUCCESSFUL) {
451 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
451 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
452 }
452 }
453 //
453 //
454 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
454 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
455 if (status!=RTEMS_SUCCESSFUL) {
455 if (status!=RTEMS_SUCCESSFUL) {
456 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
456 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
457 }
457 }
458 //
458 //
459 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
459 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
460 if (status!=RTEMS_SUCCESSFUL) {
460 if (status!=RTEMS_SUCCESSFUL) {
461 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
461 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
462 }
462 }
463 //
463 //
464 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
464 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
465 if (status!=RTEMS_SUCCESSFUL) {
465 if (status!=RTEMS_SUCCESSFUL) {
466 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
466 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
467 }
467 }
468 //
468 //
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
470 if (status!=RTEMS_SUCCESSFUL) {
470 if (status!=RTEMS_SUCCESSFUL) {
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
472 }
472 }
473 //
473 //
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
475 if (status!=RTEMS_SUCCESSFUL) {
475 if (status!=RTEMS_SUCCESSFUL) {
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
477 }
477 }
478 //
478 //
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
480 if (status!=RTEMS_SUCCESSFUL) {
480 if (status!=RTEMS_SUCCESSFUL) {
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
482 }
482 }
483
483
484 return status;
484 return status;
485 }
485 }
486
486
487 int spacewire_several_connect_attemps( void )
487 int spacewire_several_connect_attemps( void )
488 {
488 {
489 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
489 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
490 *
490 *
491 * @return RTEMS directive status code:
491 * @return RTEMS directive status code:
492 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
492 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
493 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
493 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
494 *
494 *
495 */
495 */
496
496
497 rtems_status_code status_spw;
497 rtems_status_code status_spw;
498 rtems_status_code status;
498 rtems_status_code status;
499 int i;
499 int i;
500
500
501 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
501 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
502 {
502 {
503 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
503 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
504
504
505 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
505 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
506
506
507 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
507 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
508
508
509 status_spw = spacewire_stop_and_start_link( fdSPW );
509 status_spw = spacewire_stop_and_start_link( fdSPW );
510
510
511 if ( status_spw != RTEMS_SUCCESSFUL )
511 if ( status_spw != RTEMS_SUCCESSFUL )
512 {
512 {
513 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
513 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
514 }
514 }
515
515
516 if ( status_spw == RTEMS_SUCCESSFUL)
516 if ( status_spw == RTEMS_SUCCESSFUL)
517 {
517 {
518 break;
518 break;
519 }
519 }
520 }
520 }
521
521
522 return status_spw;
522 return status_spw;
523 }
523 }
524
524
525 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
525 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
526 {
526 {
527 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
527 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
528 *
528 *
529 * @param val is the value, 0 or 1, used to set the value of the NP bit.
529 * @param val is the value, 0 or 1, used to set the value of the NP bit.
530 * @param regAddr is the address of the GRSPW control register.
530 * @param regAddr is the address of the GRSPW control register.
531 *
531 *
532 * NP is the bit 20 of the GRSPW control register.
532 * NP is the bit 20 of the GRSPW control register.
533 *
533 *
534 */
534 */
535
535
536 unsigned int *spwptr = (unsigned int*) regAddr;
536 unsigned int *spwptr = (unsigned int*) regAddr;
537
537
538 if (val == 1) {
538 if (val == 1) {
539 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
539 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
540 }
540 }
541 if (val== 0) {
541 if (val== 0) {
542 *spwptr = *spwptr & 0xffdfffff;
542 *spwptr = *spwptr & 0xffdfffff;
543 }
543 }
544 }
544 }
545
545
546 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
546 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
547 {
547 {
548 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
548 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
549 *
549 *
550 * @param val is the value, 0 or 1, used to set the value of the RE bit.
550 * @param val is the value, 0 or 1, used to set the value of the RE bit.
551 * @param regAddr is the address of the GRSPW control register.
551 * @param regAddr is the address of the GRSPW control register.
552 *
552 *
553 * RE is the bit 16 of the GRSPW control register.
553 * RE is the bit 16 of the GRSPW control register.
554 *
554 *
555 */
555 */
556
556
557 unsigned int *spwptr = (unsigned int*) regAddr;
557 unsigned int *spwptr = (unsigned int*) regAddr;
558
558
559 if (val == 1)
559 if (val == 1)
560 {
560 {
561 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
561 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
562 }
562 }
563 if (val== 0)
563 if (val== 0)
564 {
564 {
565 *spwptr = *spwptr & 0xfffdffff;
565 *spwptr = *spwptr & 0xfffdffff;
566 }
566 }
567 }
567 }
568
568
569 void spacewire_read_statistics( void )
569 void spacewire_read_statistics( void )
570 {
570 {
571 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
571 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
572 *
572 *
573 * @param void
573 * @param void
574 *
574 *
575 * @return void
575 * @return void
576 *
576 *
577 * Once they are read, the counters are stored in a global variable used during the building of the
577 * Once they are read, the counters are stored in a global variable used during the building of the
578 * HK packets.
578 * HK packets.
579 *
579 *
580 */
580 */
581
581
582 rtems_status_code status;
582 rtems_status_code status;
583 spw_stats current;
583 spw_stats current;
584
584
585 spacewire_get_last_error();
585 spacewire_get_last_error();
586
586
587 // read the current statistics
587 // read the current statistics
588 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
588 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
589
589
590 // clear the counters
590 // clear the counters
591 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
591 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
592
592
593 // typedef struct {
593 // typedef struct {
594 // unsigned int tx_link_err; // NOT IN HK
594 // unsigned int tx_link_err; // NOT IN HK
595 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
595 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
596 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
596 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
597 // unsigned int rx_eep_err;
597 // unsigned int rx_eep_err;
598 // unsigned int rx_truncated;
598 // unsigned int rx_truncated;
599 // unsigned int parity_err;
599 // unsigned int parity_err;
600 // unsigned int escape_err;
600 // unsigned int escape_err;
601 // unsigned int credit_err;
601 // unsigned int credit_err;
602 // unsigned int write_sync_err;
602 // unsigned int write_sync_err;
603 // unsigned int disconnect_err;
603 // unsigned int disconnect_err;
604 // unsigned int early_ep;
604 // unsigned int early_ep;
605 // unsigned int invalid_address;
605 // unsigned int invalid_address;
606 // unsigned int packets_sent;
606 // unsigned int packets_sent;
607 // unsigned int packets_received;
607 // unsigned int packets_received;
608 // } spw_stats;
608 // } spw_stats;
609
609
610 // rx_eep_err
610 // rx_eep_err
611 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
611 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
612 // rx_truncated
612 // rx_truncated
613 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
613 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
614 // parity_err
614 // parity_err
615 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
615 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
616 // escape_err
616 // escape_err
617 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
617 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
618 // credit_err
618 // credit_err
619 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
619 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
620 // write_sync_err
620 // write_sync_err
621 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
621 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
622 // disconnect_err
622 // disconnect_err
623 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
623 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
624 // early_ep
624 // early_ep
625 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
625 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
626 // invalid_address
626 // invalid_address
627 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
627 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
628 // packets_sent
628 // packets_sent
629 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
629 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
630 // packets_received
630 // packets_received
631 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
631 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
632
632
633 }
633 }
634
634
635 void spacewire_get_last_error( void )
635 void spacewire_get_last_error( void )
636 {
636 {
637 static spw_stats previous;
637 static spw_stats previous;
638 spw_stats current;
638 spw_stats current;
639 rtems_status_code status;
639 rtems_status_code status;
640
640
641 unsigned int hk_lfr_last_er_rid;
641 unsigned int hk_lfr_last_er_rid;
642 unsigned char hk_lfr_last_er_code;
642 unsigned char hk_lfr_last_er_code;
643 int coarseTime;
643 int coarseTime;
644 int fineTime;
644 int fineTime;
645 unsigned char update_hk_lfr_last_er;
645 unsigned char update_hk_lfr_last_er;
646
646
647 update_hk_lfr_last_er = 0;
647 update_hk_lfr_last_er = 0;
648
648
649 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
649 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
650
650
651 // get current time
651 // get current time
652 coarseTime = time_management_regs->coarse_time;
652 coarseTime = time_management_regs->coarse_time;
653 fineTime = time_management_regs->fine_time;
653 fineTime = time_management_regs->fine_time;
654
654
655 // typedef struct {
655 // typedef struct {
656 // unsigned int tx_link_err; // NOT IN HK
656 // unsigned int tx_link_err; // NOT IN HK
657 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
657 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
658 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
658 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
659 // unsigned int rx_eep_err;
659 // unsigned int rx_eep_err;
660 // unsigned int rx_truncated;
660 // unsigned int rx_truncated;
661 // unsigned int parity_err;
661 // unsigned int parity_err;
662 // unsigned int escape_err;
662 // unsigned int escape_err;
663 // unsigned int credit_err;
663 // unsigned int credit_err;
664 // unsigned int write_sync_err;
664 // unsigned int write_sync_err;
665 // unsigned int disconnect_err;
665 // unsigned int disconnect_err;
666 // unsigned int early_ep;
666 // unsigned int early_ep;
667 // unsigned int invalid_address;
667 // unsigned int invalid_address;
668 // unsigned int packets_sent;
668 // unsigned int packets_sent;
669 // unsigned int packets_received;
669 // unsigned int packets_received;
670 // } spw_stats;
670 // } spw_stats;
671
671
672 // tx_link_err *** no code associated to this field
672 // tx_link_err *** no code associated to this field
673 // rx_rmap_header_crc_err *** LE *** in HK
673 // rx_rmap_header_crc_err *** LE *** in HK
674 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
674 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
675 {
675 {
676 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
676 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
677 hk_lfr_last_er_code = CODE_HEADER_CRC;
677 hk_lfr_last_er_code = CODE_HEADER_CRC;
678 update_hk_lfr_last_er = 1;
678 update_hk_lfr_last_er = 1;
679 }
679 }
680 // rx_rmap_data_crc_err *** LE *** NOT IN HK
680 // rx_rmap_data_crc_err *** LE *** NOT IN HK
681 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
681 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
682 {
682 {
683 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
683 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
684 hk_lfr_last_er_code = CODE_DATA_CRC;
684 hk_lfr_last_er_code = CODE_DATA_CRC;
685 update_hk_lfr_last_er = 1;
685 update_hk_lfr_last_er = 1;
686 }
686 }
687 // rx_eep_err
687 // rx_eep_err
688 if (previous.rx_eep_err != current.rx_eep_err)
688 if (previous.rx_eep_err != current.rx_eep_err)
689 {
689 {
690 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
690 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
691 hk_lfr_last_er_code = CODE_EEP;
691 hk_lfr_last_er_code = CODE_EEP;
692 update_hk_lfr_last_er = 1;
692 update_hk_lfr_last_er = 1;
693 }
693 }
694 // rx_truncated
694 // rx_truncated
695 if (previous.rx_truncated != current.rx_truncated)
695 if (previous.rx_truncated != current.rx_truncated)
696 {
696 {
697 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
697 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
698 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
698 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
699 update_hk_lfr_last_er = 1;
699 update_hk_lfr_last_er = 1;
700 }
700 }
701 // parity_err
701 // parity_err
702 if (previous.parity_err != current.parity_err)
702 if (previous.parity_err != current.parity_err)
703 {
703 {
704 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
704 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
705 hk_lfr_last_er_code = CODE_PARITY;
705 hk_lfr_last_er_code = CODE_PARITY;
706 update_hk_lfr_last_er = 1;
706 update_hk_lfr_last_er = 1;
707 }
707 }
708 // escape_err
708 // escape_err
709 if (previous.parity_err != current.parity_err)
709 if (previous.parity_err != current.parity_err)
710 {
710 {
711 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
711 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
712 hk_lfr_last_er_code = CODE_ESCAPE;
712 hk_lfr_last_er_code = CODE_ESCAPE;
713 update_hk_lfr_last_er = 1;
713 update_hk_lfr_last_er = 1;
714 }
714 }
715 // credit_err
715 // credit_err
716 if (previous.credit_err != current.credit_err)
716 if (previous.credit_err != current.credit_err)
717 {
717 {
718 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
718 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
719 hk_lfr_last_er_code = CODE_CREDIT;
719 hk_lfr_last_er_code = CODE_CREDIT;
720 update_hk_lfr_last_er = 1;
720 update_hk_lfr_last_er = 1;
721 }
721 }
722 // write_sync_err
722 // write_sync_err
723 if (previous.write_sync_err != current.write_sync_err)
723 if (previous.write_sync_err != current.write_sync_err)
724 {
724 {
725 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
725 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
726 hk_lfr_last_er_code = CODE_WRITE_SYNC;
726 hk_lfr_last_er_code = CODE_WRITE_SYNC;
727 update_hk_lfr_last_er = 1;
727 update_hk_lfr_last_er = 1;
728 }
728 }
729 // disconnect_err
729 // disconnect_err
730 if (previous.disconnect_err != current.disconnect_err)
730 if (previous.disconnect_err != current.disconnect_err)
731 {
731 {
732 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
732 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
733 hk_lfr_last_er_code = CODE_DISCONNECT;
733 hk_lfr_last_er_code = CODE_DISCONNECT;
734 update_hk_lfr_last_er = 1;
734 update_hk_lfr_last_er = 1;
735 }
735 }
736 // early_ep
736 // early_ep
737 if (previous.early_ep != current.early_ep)
737 if (previous.early_ep != current.early_ep)
738 {
738 {
739 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
739 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
740 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
740 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
741 update_hk_lfr_last_er = 1;
741 update_hk_lfr_last_er = 1;
742 }
742 }
743 // invalid_address
743 // invalid_address
744 if (previous.invalid_address != current.invalid_address)
744 if (previous.invalid_address != current.invalid_address)
745 {
745 {
746 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
746 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
747 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
747 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
748 update_hk_lfr_last_er = 1;
748 update_hk_lfr_last_er = 1;
749 }
749 }
750
750
751 // if a field has changed, update the hk_last_er fields
751 // if a field has changed, update the hk_last_er fields
752 if (update_hk_lfr_last_er == 1)
752 if (update_hk_lfr_last_er == 1)
753 {
753 {
754 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
754 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
755 }
755 }
756
756
757 previous = current;
757 previous = current;
758 }
758 }
759
759
760 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
760 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
761 {
761 {
762 unsigned char *coarseTimePtr;
762 unsigned char *coarseTimePtr;
763 unsigned char *fineTimePtr;
763 unsigned char *fineTimePtr;
764
764
765 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
765 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
766 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
766 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
767
767
768 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & 0xff00) >> 8 );
768 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & 0xff00) >> 8 );
769 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & 0x00ff);
769 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & 0x00ff);
770 housekeeping_packet.hk_lfr_last_er_code = code;
770 housekeeping_packet.hk_lfr_last_er_code = code;
771 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
771 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
772 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
772 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
773 housekeeping_packet.hk_lfr_last_er_time[2] = coarseTimePtr[2];
773 housekeeping_packet.hk_lfr_last_er_time[2] = coarseTimePtr[2];
774 housekeeping_packet.hk_lfr_last_er_time[3] = coarseTimePtr[3];
774 housekeeping_packet.hk_lfr_last_er_time[3] = coarseTimePtr[3];
775 housekeeping_packet.hk_lfr_last_er_time[4] = fineTimePtr[2];
775 housekeeping_packet.hk_lfr_last_er_time[4] = fineTimePtr[2];
776 housekeeping_packet.hk_lfr_last_er_time[5] = fineTimePtr[3];
776 housekeeping_packet.hk_lfr_last_er_time[5] = fineTimePtr[3];
777 }
777 }
778
778
779 void update_hk_with_grspw_stats( void )
779 void update_hk_with_grspw_stats( void )
780 {
780 {
781 //****************************
781 //****************************
782 // DPU_SPACEWIRE_IF_STATISTICS
782 // DPU_SPACEWIRE_IF_STATISTICS
783 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> 8);
783 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> 8);
784 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
784 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
785 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> 8);
785 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> 8);
786 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
786 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
787
787
788 //******************************************
788 //******************************************
789 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
789 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
790 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
790 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
791 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
791 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
792 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
792 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
793 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
793 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
794 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
794 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
795
795
796 //*********************************************
796 //*********************************************
797 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
797 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
798 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
798 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
799 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
799 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
800 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
800 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
801 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
801 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
802 }
802 }
803
803
804 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
804 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
805 {
805 {
806 unsigned int *statusRegisterPtr;
806 unsigned int *statusRegisterPtr;
807 unsigned char linkState;
807 unsigned char linkState;
808
808
809 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
809 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
810 linkState = (unsigned char) ( ( (*statusRegisterPtr) >> 21) & 0x07); // [0000 0111]
810 linkState = (unsigned char) ( ( (*statusRegisterPtr) >> 21) & 0x07); // [0000 0111]
811
811
812 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & 0xf8; // [1111 1000] set link state to 0
812 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & 0xf8; // [1111 1000] set link state to 0
813
813
814 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
814 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
815 }
815 }
816
816
817 void increase_unsigned_char_counter( unsigned char *counter )
817 void increase_unsigned_char_counter( unsigned char *counter )
818 {
818 {
819 // update the number of valid timecodes that have been received
819 // update the number of valid timecodes that have been received
820 if (*counter == 255)
820 if (*counter == 255)
821 {
821 {
822 *counter = 0;
822 *counter = 0;
823 }
823 }
824 else
824 else
825 {
825 {
826 *counter = *counter + 1;
826 *counter = *counter + 1;
827 }
827 }
828 }
828 }
829
829
830 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
830 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
831 {
831 {
832 /** This function checks the coherency between the incoming timecode and the last valid timecode.
832 /** This function checks the coherency between the incoming timecode and the last valid timecode.
833 *
833 *
834 * @param currentTimecodeCtr is the incoming timecode
834 * @param currentTimecodeCtr is the incoming timecode
835 *
835 *
836 * @return returned codes::
836 * @return returned codes::
837 * - LFR_DEFAULT
837 * - LFR_DEFAULT
838 * - LFR_SUCCESSFUL
838 * - LFR_SUCCESSFUL
839 *
839 *
840 */
840 */
841
841
842 static unsigned char firstTickout = 1;
842 static unsigned char firstTickout = 1;
843 unsigned char ret;
843 unsigned char ret;
844
844
845 ret = LFR_DEFAULT;
845 ret = LFR_DEFAULT;
846
846
847 if (firstTickout == 0)
847 if (firstTickout == 0)
848 {
848 {
849 if (currentTimecodeCtr == 0)
849 if (currentTimecodeCtr == 0)
850 {
850 {
851 if (previousTimecodeCtr == 63)
851 if (previousTimecodeCtr == 63)
852 {
852 {
853 ret = LFR_SUCCESSFUL;
853 ret = LFR_SUCCESSFUL;
854 }
854 }
855 else
855 else
856 {
856 {
857 ret = LFR_DEFAULT;
857 ret = LFR_DEFAULT;
858 }
858 }
859 }
859 }
860 else
860 else
861 {
861 {
862 if (currentTimecodeCtr == (previousTimecodeCtr +1))
862 if (currentTimecodeCtr == (previousTimecodeCtr +1))
863 {
863 {
864 ret = LFR_SUCCESSFUL;
864 ret = LFR_SUCCESSFUL;
865 }
865 }
866 else
866 else
867 {
867 {
868 ret = LFR_DEFAULT;
868 ret = LFR_DEFAULT;
869 }
869 }
870 }
870 }
871 }
871 }
872 else
872 else
873 {
873 {
874 firstTickout = 0;
874 firstTickout = 0;
875 ret = LFR_SUCCESSFUL;
875 ret = LFR_SUCCESSFUL;
876 }
876 }
877
877
878 return ret;
878 return ret;
879 }
879 }
880
880
881 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
881 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
882 {
882 {
883 unsigned int ret;
883 unsigned int ret;
884
884
885 ret = LFR_DEFAULT;
885 ret = LFR_DEFAULT;
886
886
887 if (timecode == internalTime)
887 if (timecode == internalTime)
888 {
888 {
889 ret = LFR_SUCCESSFUL;
889 ret = LFR_SUCCESSFUL;
890 }
890 }
891 else
891 else
892 {
892 {
893 ret = LFR_DEFAULT;
893 ret = LFR_DEFAULT;
894 }
894 }
895
895
896 return ret;
896 return ret;
897 }
897 }
898
898
899 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
899 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
900 {
900 {
901 // a tickout has been emitted, perform actions on the incoming timecode
901 // a tickout has been emitted, perform actions on the incoming timecode
902
902
903 unsigned char incomingTimecode;
903 unsigned char incomingTimecode;
904 unsigned char updateTime;
904 unsigned char updateTime;
905 unsigned char internalTime;
905 unsigned char internalTime;
906 rtems_status_code status;
906 rtems_status_code status;
907
907
908 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
908 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
909 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
909 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
910 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
910 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
911
911
912 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
912 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
913
913
914 // update the number of tickout that have been generated
914 // update the number of tickout that have been generated
915 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
915 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
916
916
917 //**************************
917 //**************************
918 // HK_LFR_TIMECODE_ERRONEOUS
918 // HK_LFR_TIMECODE_ERRONEOUS
919 // MISSING and INVALID are handled by the timecode_timer_routine service routine
919 // MISSING and INVALID are handled by the timecode_timer_routine service routine
920 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
920 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
921 {
921 {
922 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
922 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
923 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
923 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
924 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
924 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
925 }
925 }
926
926
927 //************************
927 //************************
928 // HK_LFR_TIME_TIMECODE_IT
928 // HK_LFR_TIME_TIMECODE_IT
929 // check the coherency between the SpaceWire timecode and the Internal Time
929 // check the coherency between the SpaceWire timecode and the Internal Time
930 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
930 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
931 {
931 {
932 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
932 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
933 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
933 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
934 }
934 }
935
935
936 //********************
936 //********************
937 // HK_LFR_TIMECODE_CTR
937 // HK_LFR_TIMECODE_CTR
938 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
938 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
939 if (oneTcLfrUpdateTimeReceived == 1)
939 if (oneTcLfrUpdateTimeReceived == 1)
940 {
940 {
941 if ( incomingTimecode != updateTime )
941 if ( incomingTimecode != updateTime )
942 {
942 {
943 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
943 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
944 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
944 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
945 }
945 }
946 }
946 }
947
947
948 // launch the timecode timer to detect missing or invalid timecodes
948 // launch the timecode timer to detect missing or invalid timecodes
949 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
949 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
950 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
950 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
951 if (status != RTEMS_SUCCESSFUL)
951 if (status != RTEMS_SUCCESSFUL)
952 {
952 {
953 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
953 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
954 }
954 }
955 }
955 }
956
956
957 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
957 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
958 {
958 {
959 static unsigned char initStep = 1;
959 static unsigned char initStep = 1;
960
960
961 unsigned char currentTimecodeCtr;
961 unsigned char currentTimecodeCtr;
962
962
963 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
963 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
964
964
965 if (initStep == 1)
965 if (initStep == 1)
966 {
966 {
967 if (currentTimecodeCtr == previousTimecodeCtr)
967 if (currentTimecodeCtr == previousTimecodeCtr)
968 {
968 {
969 //************************
969 //************************
970 // HK_LFR_TIMECODE_MISSING
970 // HK_LFR_TIMECODE_MISSING
971 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
971 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
972 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
972 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
973 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
973 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
974 }
974 }
975 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
975 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
976 {
976 {
977 // the timecode value has changed and the value is valid, this is unexpected because
977 // the timecode value has changed and the value is valid, this is unexpected because
978 // the timer should not have fired, the timecode_irq_handler should have been raised
978 // the timer should not have fired, the timecode_irq_handler should have been raised
979 }
979 }
980 else
980 else
981 {
981 {
982 //************************
982 //************************
983 // HK_LFR_TIMECODE_INVALID
983 // HK_LFR_TIMECODE_INVALID
984 // the timecode value has changed and the value is not valid, no tickout has been generated
984 // the timecode value has changed and the value is not valid, no tickout has been generated
985 // this is why the timer has fired
985 // this is why the timer has fired
986 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
986 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
987 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
987 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
988 }
988 }
989 }
989 }
990 else
990 else
991 {
991 {
992 initStep = 1;
992 initStep = 1;
993 //************************
993 //************************
994 // HK_LFR_TIMECODE_MISSING
994 // HK_LFR_TIMECODE_MISSING
995 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
995 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
996 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
996 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
997 }
997 }
998
998
999 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
999 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1000 }
1000 }
1001
1001
1002 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1002 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1003 {
1003 {
1004 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1004 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1005 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1005 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1006 header->reserved = DEFAULT_RESERVED;
1006 header->reserved = DEFAULT_RESERVED;
1007 header->userApplication = CCSDS_USER_APP;
1007 header->userApplication = CCSDS_USER_APP;
1008 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1008 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1009 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1009 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1010 header->packetLength[0] = 0x00;
1010 header->packetLength[0] = 0x00;
1011 header->packetLength[1] = 0x00;
1011 header->packetLength[1] = 0x00;
1012 // DATA FIELD HEADER
1012 // DATA FIELD HEADER
1013 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1013 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1014 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1014 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1015 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1015 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1016 header->destinationID = TM_DESTINATION_ID_GROUND;
1016 header->destinationID = TM_DESTINATION_ID_GROUND;
1017 header->time[0] = 0x00;
1017 header->time[0] = 0x00;
1018 header->time[0] = 0x00;
1018 header->time[0] = 0x00;
1019 header->time[0] = 0x00;
1019 header->time[0] = 0x00;
1020 header->time[0] = 0x00;
1020 header->time[0] = 0x00;
1021 header->time[0] = 0x00;
1021 header->time[0] = 0x00;
1022 header->time[0] = 0x00;
1022 header->time[0] = 0x00;
1023 // AUXILIARY DATA HEADER
1023 // AUXILIARY DATA HEADER
1024 header->sid = 0x00;
1024 header->sid = 0x00;
1025 header->pa_bia_status_info = DEFAULT_HKBIA;
1025 header->pa_bia_status_info = DEFAULT_HKBIA;
1026 header->blkNr[0] = 0x00;
1026 header->blkNr[0] = 0x00;
1027 header->blkNr[1] = 0x00;
1027 header->blkNr[1] = 0x00;
1028 }
1028 }
1029
1029
1030 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1030 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1031 {
1031 {
1032 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1032 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1033 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1033 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1034 header->reserved = DEFAULT_RESERVED;
1034 header->reserved = DEFAULT_RESERVED;
1035 header->userApplication = CCSDS_USER_APP;
1035 header->userApplication = CCSDS_USER_APP;
1036 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1036 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1037 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1037 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1038 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1038 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1039 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1039 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1040 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1040 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1041 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1041 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1042 // DATA FIELD HEADER
1042 // DATA FIELD HEADER
1043 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1043 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1044 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1044 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1045 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1045 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1046 header->destinationID = TM_DESTINATION_ID_GROUND;
1046 header->destinationID = TM_DESTINATION_ID_GROUND;
1047 header->time[0] = 0x00;
1047 header->time[0] = 0x00;
1048 header->time[0] = 0x00;
1048 header->time[0] = 0x00;
1049 header->time[0] = 0x00;
1049 header->time[0] = 0x00;
1050 header->time[0] = 0x00;
1050 header->time[0] = 0x00;
1051 header->time[0] = 0x00;
1051 header->time[0] = 0x00;
1052 header->time[0] = 0x00;
1052 header->time[0] = 0x00;
1053 // AUXILIARY DATA HEADER
1053 // AUXILIARY DATA HEADER
1054 header->sid = 0x00;
1054 header->sid = 0x00;
1055 header->pa_bia_status_info = DEFAULT_HKBIA;
1055 header->pa_bia_status_info = DEFAULT_HKBIA;
1056 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
1056 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
1057 header->pktNr = 0x00;
1057 header->pktNr = 0x00;
1058 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1058 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1059 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1059 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1060 }
1060 }
1061
1061
1062 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1062 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1063 {
1063 {
1064 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1064 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1065 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1065 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1066 header->reserved = DEFAULT_RESERVED;
1066 header->reserved = DEFAULT_RESERVED;
1067 header->userApplication = CCSDS_USER_APP;
1067 header->userApplication = CCSDS_USER_APP;
1068 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1068 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1069 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1069 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1070 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1070 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1071 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1071 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1072 header->packetLength[0] = 0x00;
1072 header->packetLength[0] = 0x00;
1073 header->packetLength[1] = 0x00;
1073 header->packetLength[1] = 0x00;
1074 // DATA FIELD HEADER
1074 // DATA FIELD HEADER
1075 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1075 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1076 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1076 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1077 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1077 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1078 header->destinationID = TM_DESTINATION_ID_GROUND;
1078 header->destinationID = TM_DESTINATION_ID_GROUND;
1079 header->time[0] = 0x00;
1079 header->time[0] = 0x00;
1080 header->time[0] = 0x00;
1080 header->time[0] = 0x00;
1081 header->time[0] = 0x00;
1081 header->time[0] = 0x00;
1082 header->time[0] = 0x00;
1082 header->time[0] = 0x00;
1083 header->time[0] = 0x00;
1083 header->time[0] = 0x00;
1084 header->time[0] = 0x00;
1084 header->time[0] = 0x00;
1085 // AUXILIARY DATA HEADER
1085 // AUXILIARY DATA HEADER
1086 header->sid = 0x00;
1086 header->sid = 0x00;
1087 header->pa_bia_status_info = 0x00;
1087 header->pa_bia_status_info = 0x00;
1088 header->pa_lfr_pkt_cnt_asm = 0x00;
1088 header->pa_lfr_pkt_cnt_asm = 0x00;
1089 header->pa_lfr_pkt_nr_asm = 0x00;
1089 header->pa_lfr_pkt_nr_asm = 0x00;
1090 header->pa_lfr_asm_blk_nr[0] = 0x00;
1090 header->pa_lfr_asm_blk_nr[0] = 0x00;
1091 header->pa_lfr_asm_blk_nr[1] = 0x00;
1091 header->pa_lfr_asm_blk_nr[1] = 0x00;
1092 }
1092 }
1093
1093
1094 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1094 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1095 Header_TM_LFR_SCIENCE_CWF_t *header )
1095 Header_TM_LFR_SCIENCE_CWF_t *header )
1096 {
1096 {
1097 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1097 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1098 *
1098 *
1099 * @param waveform points to the buffer containing the data that will be send.
1099 * @param waveform points to the buffer containing the data that will be send.
1100 * @param sid is the source identifier of the data that will be sent.
1100 * @param sid is the source identifier of the data that will be sent.
1101 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1101 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1102 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1102 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1103 * contain information to setup the transmission of the data packets.
1103 * contain information to setup the transmission of the data packets.
1104 *
1104 *
1105 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1105 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1106 *
1106 *
1107 */
1107 */
1108
1108
1109 unsigned int i;
1109 unsigned int i;
1110 int ret;
1110 int ret;
1111 unsigned int coarseTime;
1111 unsigned int coarseTime;
1112 unsigned int fineTime;
1112 unsigned int fineTime;
1113 rtems_status_code status;
1113 rtems_status_code status;
1114 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1114 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1115 int *dataPtr;
1115 int *dataPtr;
1116 unsigned char sid;
1116 unsigned char sid;
1117
1117
1118 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1118 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1119 spw_ioctl_send_CWF.options = 0;
1119 spw_ioctl_send_CWF.options = 0;
1120
1120
1121 ret = LFR_DEFAULT;
1121 ret = LFR_DEFAULT;
1122 sid = (unsigned char) ring_node_to_send->sid;
1122 sid = (unsigned char) ring_node_to_send->sid;
1123
1123
1124 coarseTime = ring_node_to_send->coarseTime;
1124 coarseTime = ring_node_to_send->coarseTime;
1125 fineTime = ring_node_to_send->fineTime;
1125 fineTime = ring_node_to_send->fineTime;
1126 dataPtr = (int*) ring_node_to_send->buffer_address;
1126 dataPtr = (int*) ring_node_to_send->buffer_address;
1127
1127
1128 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1128 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1129 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1129 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1130 header->pa_bia_status_info = pa_bia_status_info;
1130 header->pa_bia_status_info = pa_bia_status_info;
1131 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1131 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1132 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1132 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1133 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1133 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1134
1134
1135 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1135 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1136 {
1136 {
1137 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1137 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1138 spw_ioctl_send_CWF.hdr = (char*) header;
1138 spw_ioctl_send_CWF.hdr = (char*) header;
1139 // BUILD THE DATA
1139 // BUILD THE DATA
1140 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1140 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1141
1141
1142 // SET PACKET SEQUENCE CONTROL
1142 // SET PACKET SEQUENCE CONTROL
1143 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1143 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1144
1144
1145 // SET SID
1145 // SET SID
1146 header->sid = sid;
1146 header->sid = sid;
1147
1147
1148 // SET PACKET TIME
1148 // SET PACKET TIME
1149 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1149 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1150 //
1150 //
1151 header->time[0] = header->acquisitionTime[0];
1151 header->time[0] = header->acquisitionTime[0];
1152 header->time[1] = header->acquisitionTime[1];
1152 header->time[1] = header->acquisitionTime[1];
1153 header->time[2] = header->acquisitionTime[2];
1153 header->time[2] = header->acquisitionTime[2];
1154 header->time[3] = header->acquisitionTime[3];
1154 header->time[3] = header->acquisitionTime[3];
1155 header->time[4] = header->acquisitionTime[4];
1155 header->time[4] = header->acquisitionTime[4];
1156 header->time[5] = header->acquisitionTime[5];
1156 header->time[5] = header->acquisitionTime[5];
1157
1157
1158 // SET PACKET ID
1158 // SET PACKET ID
1159 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1159 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1160 {
1160 {
1161 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
1161 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
1162 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1162 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1163 }
1163 }
1164 else
1164 else
1165 {
1165 {
1166 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1166 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1167 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1167 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1168 }
1168 }
1169
1169
1170 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1170 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1171 if (status != RTEMS_SUCCESSFUL) {
1171 if (status != RTEMS_SUCCESSFUL) {
1172 ret = LFR_DEFAULT;
1172 ret = LFR_DEFAULT;
1173 }
1173 }
1174 }
1174 }
1175
1175
1176 return ret;
1176 return ret;
1177 }
1177 }
1178
1178
1179 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1179 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1180 Header_TM_LFR_SCIENCE_SWF_t *header )
1180 Header_TM_LFR_SCIENCE_SWF_t *header )
1181 {
1181 {
1182 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1182 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1183 *
1183 *
1184 * @param waveform points to the buffer containing the data that will be send.
1184 * @param waveform points to the buffer containing the data that will be send.
1185 * @param sid is the source identifier of the data that will be sent.
1185 * @param sid is the source identifier of the data that will be sent.
1186 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1186 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1187 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1187 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1188 * contain information to setup the transmission of the data packets.
1188 * contain information to setup the transmission of the data packets.
1189 *
1189 *
1190 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1190 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1191 *
1191 *
1192 */
1192 */
1193
1193
1194 unsigned int i;
1194 unsigned int i;
1195 int ret;
1195 int ret;
1196 unsigned int coarseTime;
1196 unsigned int coarseTime;
1197 unsigned int fineTime;
1197 unsigned int fineTime;
1198 rtems_status_code status;
1198 rtems_status_code status;
1199 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1199 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1200 int *dataPtr;
1200 int *dataPtr;
1201 unsigned char sid;
1201 unsigned char sid;
1202
1202
1203 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1203 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1204 spw_ioctl_send_SWF.options = 0;
1204 spw_ioctl_send_SWF.options = 0;
1205
1205
1206 ret = LFR_DEFAULT;
1206 ret = LFR_DEFAULT;
1207
1207
1208 coarseTime = ring_node_to_send->coarseTime;
1208 coarseTime = ring_node_to_send->coarseTime;
1209 fineTime = ring_node_to_send->fineTime;
1209 fineTime = ring_node_to_send->fineTime;
1210 dataPtr = (int*) ring_node_to_send->buffer_address;
1210 dataPtr = (int*) ring_node_to_send->buffer_address;
1211 sid = ring_node_to_send->sid;
1211 sid = ring_node_to_send->sid;
1212
1212
1213 header->pa_bia_status_info = pa_bia_status_info;
1213 header->pa_bia_status_info = pa_bia_status_info;
1214 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1214 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1215
1215
1216 for (i=0; i<7; i++) // send waveform
1216 for (i=0; i<7; i++) // send waveform
1217 {
1217 {
1218 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1218 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1219 spw_ioctl_send_SWF.hdr = (char*) header;
1219 spw_ioctl_send_SWF.hdr = (char*) header;
1220
1220
1221 // SET PACKET SEQUENCE CONTROL
1221 // SET PACKET SEQUENCE CONTROL
1222 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1222 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1223
1223
1224 // SET PACKET LENGTH AND BLKNR
1224 // SET PACKET LENGTH AND BLKNR
1225 if (i == 6)
1225 if (i == 6)
1226 {
1226 {
1227 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1227 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1228 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
1228 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
1229 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1229 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1230 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
1230 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
1231 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1231 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1232 }
1232 }
1233 else
1233 else
1234 {
1234 {
1235 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1235 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1236 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
1236 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
1237 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1237 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1238 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
1238 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
1239 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1239 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1240 }
1240 }
1241
1241
1242 // SET PACKET TIME
1242 // SET PACKET TIME
1243 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1243 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1244 //
1244 //
1245 header->time[0] = header->acquisitionTime[0];
1245 header->time[0] = header->acquisitionTime[0];
1246 header->time[1] = header->acquisitionTime[1];
1246 header->time[1] = header->acquisitionTime[1];
1247 header->time[2] = header->acquisitionTime[2];
1247 header->time[2] = header->acquisitionTime[2];
1248 header->time[3] = header->acquisitionTime[3];
1248 header->time[3] = header->acquisitionTime[3];
1249 header->time[4] = header->acquisitionTime[4];
1249 header->time[4] = header->acquisitionTime[4];
1250 header->time[5] = header->acquisitionTime[5];
1250 header->time[5] = header->acquisitionTime[5];
1251
1251
1252 // SET SID
1252 // SET SID
1253 header->sid = sid;
1253 header->sid = sid;
1254
1254
1255 // SET PKTNR
1255 // SET PKTNR
1256 header->pktNr = i+1; // PKT_NR
1256 header->pktNr = i+1; // PKT_NR
1257
1257
1258 // SEND PACKET
1258 // SEND PACKET
1259 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1259 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1260 if (status != RTEMS_SUCCESSFUL) {
1260 if (status != RTEMS_SUCCESSFUL) {
1261 ret = LFR_DEFAULT;
1261 ret = LFR_DEFAULT;
1262 }
1262 }
1263 }
1263 }
1264
1264
1265 return ret;
1265 return ret;
1266 }
1266 }
1267
1267
1268 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1268 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1269 Header_TM_LFR_SCIENCE_CWF_t *header )
1269 Header_TM_LFR_SCIENCE_CWF_t *header )
1270 {
1270 {
1271 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1271 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1272 *
1272 *
1273 * @param waveform points to the buffer containing the data that will be send.
1273 * @param waveform points to the buffer containing the data that will be send.
1274 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1274 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1275 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1275 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1276 * contain information to setup the transmission of the data packets.
1276 * contain information to setup the transmission of the data packets.
1277 *
1277 *
1278 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1278 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1279 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1279 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1280 *
1280 *
1281 */
1281 */
1282
1282
1283 unsigned int i;
1283 unsigned int i;
1284 int ret;
1284 int ret;
1285 unsigned int coarseTime;
1285 unsigned int coarseTime;
1286 unsigned int fineTime;
1286 unsigned int fineTime;
1287 rtems_status_code status;
1287 rtems_status_code status;
1288 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1288 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1289 char *dataPtr;
1289 char *dataPtr;
1290 unsigned char sid;
1290 unsigned char sid;
1291
1291
1292 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1292 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1293 spw_ioctl_send_CWF.options = 0;
1293 spw_ioctl_send_CWF.options = 0;
1294
1294
1295 ret = LFR_DEFAULT;
1295 ret = LFR_DEFAULT;
1296 sid = ring_node_to_send->sid;
1296 sid = ring_node_to_send->sid;
1297
1297
1298 coarseTime = ring_node_to_send->coarseTime;
1298 coarseTime = ring_node_to_send->coarseTime;
1299 fineTime = ring_node_to_send->fineTime;
1299 fineTime = ring_node_to_send->fineTime;
1300 dataPtr = (char*) ring_node_to_send->buffer_address;
1300 dataPtr = (char*) ring_node_to_send->buffer_address;
1301
1301
1302 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
1302 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
1303 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1303 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1304 header->pa_bia_status_info = pa_bia_status_info;
1304 header->pa_bia_status_info = pa_bia_status_info;
1305 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1305 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1306 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
1306 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
1307 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1307 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1308
1308
1309 //*********************
1309 //*********************
1310 // SEND CWF3_light DATA
1310 // SEND CWF3_light DATA
1311 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1311 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1312 {
1312 {
1313 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1313 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1314 spw_ioctl_send_CWF.hdr = (char*) header;
1314 spw_ioctl_send_CWF.hdr = (char*) header;
1315 // BUILD THE DATA
1315 // BUILD THE DATA
1316 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1316 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1317
1317
1318 // SET PACKET SEQUENCE COUNTER
1318 // SET PACKET SEQUENCE COUNTER
1319 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1319 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1320
1320
1321 // SET SID
1321 // SET SID
1322 header->sid = sid;
1322 header->sid = sid;
1323
1323
1324 // SET PACKET TIME
1324 // SET PACKET TIME
1325 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1325 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1326 //
1326 //
1327 header->time[0] = header->acquisitionTime[0];
1327 header->time[0] = header->acquisitionTime[0];
1328 header->time[1] = header->acquisitionTime[1];
1328 header->time[1] = header->acquisitionTime[1];
1329 header->time[2] = header->acquisitionTime[2];
1329 header->time[2] = header->acquisitionTime[2];
1330 header->time[3] = header->acquisitionTime[3];
1330 header->time[3] = header->acquisitionTime[3];
1331 header->time[4] = header->acquisitionTime[4];
1331 header->time[4] = header->acquisitionTime[4];
1332 header->time[5] = header->acquisitionTime[5];
1332 header->time[5] = header->acquisitionTime[5];
1333
1333
1334 // SET PACKET ID
1334 // SET PACKET ID
1335 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1335 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1336 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1336 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1337
1337
1338 // SEND PACKET
1338 // SEND PACKET
1339 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1339 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1340 if (status != RTEMS_SUCCESSFUL) {
1340 if (status != RTEMS_SUCCESSFUL) {
1341 ret = LFR_DEFAULT;
1341 ret = LFR_DEFAULT;
1342 }
1342 }
1343 }
1343 }
1344
1344
1345 return ret;
1345 return ret;
1346 }
1346 }
1347
1347
1348 void spw_send_asm_f0( ring_node *ring_node_to_send,
1348 void spw_send_asm_f0( ring_node *ring_node_to_send,
1349 Header_TM_LFR_SCIENCE_ASM_t *header )
1349 Header_TM_LFR_SCIENCE_ASM_t *header )
1350 {
1350 {
1351 unsigned int i;
1351 unsigned int i;
1352 unsigned int length = 0;
1352 unsigned int length = 0;
1353 rtems_status_code status;
1353 rtems_status_code status;
1354 unsigned int sid;
1354 unsigned int sid;
1355 float *spectral_matrix;
1355 float *spectral_matrix;
1356 int coarseTime;
1356 int coarseTime;
1357 int fineTime;
1357 int fineTime;
1358 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1358 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1359
1359
1360 sid = ring_node_to_send->sid;
1360 sid = ring_node_to_send->sid;
1361 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1361 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1362 coarseTime = ring_node_to_send->coarseTime;
1362 coarseTime = ring_node_to_send->coarseTime;
1363 fineTime = ring_node_to_send->fineTime;
1363 fineTime = ring_node_to_send->fineTime;
1364
1364
1365 header->pa_bia_status_info = pa_bia_status_info;
1365 header->pa_bia_status_info = pa_bia_status_info;
1366 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1366 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1367
1367
1368 for (i=0; i<3; i++)
1368 for (i=0; i<3; i++)
1369 {
1369 {
1370 if ((i==0) || (i==1))
1370 if ((i==0) || (i==1))
1371 {
1371 {
1372 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1372 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1373 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1373 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1374 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1374 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1375 ];
1375 ];
1376 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1376 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1377 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1377 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1378 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB
1378 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB
1379 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1379 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1380 }
1380 }
1381 else
1381 else
1382 {
1382 {
1383 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1383 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1384 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1384 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1385 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1385 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1386 ];
1386 ];
1387 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1387 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1388 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1388 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1389 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB
1389 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB
1390 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1390 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1391 }
1391 }
1392
1392
1393 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1393 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1394 spw_ioctl_send_ASM.hdr = (char *) header;
1394 spw_ioctl_send_ASM.hdr = (char *) header;
1395 spw_ioctl_send_ASM.options = 0;
1395 spw_ioctl_send_ASM.options = 0;
1396
1396
1397 // (2) BUILD THE HEADER
1397 // (2) BUILD THE HEADER
1398 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1398 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1399 header->packetLength[0] = (unsigned char) (length>>8);
1399 header->packetLength[0] = (unsigned char) (length>>8);
1400 header->packetLength[1] = (unsigned char) (length);
1400 header->packetLength[1] = (unsigned char) (length);
1401 header->sid = (unsigned char) sid; // SID
1401 header->sid = (unsigned char) sid; // SID
1402 header->pa_lfr_pkt_cnt_asm = 3;
1402 header->pa_lfr_pkt_cnt_asm = 3;
1403 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1403 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1404
1404
1405 // (3) SET PACKET TIME
1405 // (3) SET PACKET TIME
1406 header->time[0] = (unsigned char) (coarseTime>>24);
1406 header->time[0] = (unsigned char) (coarseTime>>24);
1407 header->time[1] = (unsigned char) (coarseTime>>16);
1407 header->time[1] = (unsigned char) (coarseTime>>16);
1408 header->time[2] = (unsigned char) (coarseTime>>8);
1408 header->time[2] = (unsigned char) (coarseTime>>8);
1409 header->time[3] = (unsigned char) (coarseTime);
1409 header->time[3] = (unsigned char) (coarseTime);
1410 header->time[4] = (unsigned char) (fineTime>>8);
1410 header->time[4] = (unsigned char) (fineTime>>8);
1411 header->time[5] = (unsigned char) (fineTime);
1411 header->time[5] = (unsigned char) (fineTime);
1412 //
1412 //
1413 header->acquisitionTime[0] = header->time[0];
1413 header->acquisitionTime[0] = header->time[0];
1414 header->acquisitionTime[1] = header->time[1];
1414 header->acquisitionTime[1] = header->time[1];
1415 header->acquisitionTime[2] = header->time[2];
1415 header->acquisitionTime[2] = header->time[2];
1416 header->acquisitionTime[3] = header->time[3];
1416 header->acquisitionTime[3] = header->time[3];
1417 header->acquisitionTime[4] = header->time[4];
1417 header->acquisitionTime[4] = header->time[4];
1418 header->acquisitionTime[5] = header->time[5];
1418 header->acquisitionTime[5] = header->time[5];
1419
1419
1420 // (4) SEND PACKET
1420 // (4) SEND PACKET
1421 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1421 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1422 if (status != RTEMS_SUCCESSFUL) {
1422 if (status != RTEMS_SUCCESSFUL) {
1423 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1423 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1424 }
1424 }
1425 }
1425 }
1426 }
1426 }
1427
1427
1428 void spw_send_asm_f1( ring_node *ring_node_to_send,
1428 void spw_send_asm_f1( ring_node *ring_node_to_send,
1429 Header_TM_LFR_SCIENCE_ASM_t *header )
1429 Header_TM_LFR_SCIENCE_ASM_t *header )
1430 {
1430 {
1431 unsigned int i;
1431 unsigned int i;
1432 unsigned int length = 0;
1432 unsigned int length = 0;
1433 rtems_status_code status;
1433 rtems_status_code status;
1434 unsigned int sid;
1434 unsigned int sid;
1435 float *spectral_matrix;
1435 float *spectral_matrix;
1436 int coarseTime;
1436 int coarseTime;
1437 int fineTime;
1437 int fineTime;
1438 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1438 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1439
1439
1440 sid = ring_node_to_send->sid;
1440 sid = ring_node_to_send->sid;
1441 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1441 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1442 coarseTime = ring_node_to_send->coarseTime;
1442 coarseTime = ring_node_to_send->coarseTime;
1443 fineTime = ring_node_to_send->fineTime;
1443 fineTime = ring_node_to_send->fineTime;
1444
1444
1445 header->pa_bia_status_info = pa_bia_status_info;
1445 header->pa_bia_status_info = pa_bia_status_info;
1446 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1446 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1447
1447
1448 for (i=0; i<3; i++)
1448 for (i=0; i<3; i++)
1449 {
1449 {
1450 if ((i==0) || (i==1))
1450 if ((i==0) || (i==1))
1451 {
1451 {
1452 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1452 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1453 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1453 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1454 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1454 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1455 ];
1455 ];
1456 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1456 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1457 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1457 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1458 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB
1458 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB
1459 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1459 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1460 }
1460 }
1461 else
1461 else
1462 {
1462 {
1463 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1463 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1464 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1464 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1465 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1465 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1466 ];
1466 ];
1467 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1467 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1468 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1468 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1469 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB
1469 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB
1470 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1470 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1471 }
1471 }
1472
1472
1473 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1473 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1474 spw_ioctl_send_ASM.hdr = (char *) header;
1474 spw_ioctl_send_ASM.hdr = (char *) header;
1475 spw_ioctl_send_ASM.options = 0;
1475 spw_ioctl_send_ASM.options = 0;
1476
1476
1477 // (2) BUILD THE HEADER
1477 // (2) BUILD THE HEADER
1478 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1478 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1479 header->packetLength[0] = (unsigned char) (length>>8);
1479 header->packetLength[0] = (unsigned char) (length>>8);
1480 header->packetLength[1] = (unsigned char) (length);
1480 header->packetLength[1] = (unsigned char) (length);
1481 header->sid = (unsigned char) sid; // SID
1481 header->sid = (unsigned char) sid; // SID
1482 header->pa_lfr_pkt_cnt_asm = 3;
1482 header->pa_lfr_pkt_cnt_asm = 3;
1483 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1483 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1484
1484
1485 // (3) SET PACKET TIME
1485 // (3) SET PACKET TIME
1486 header->time[0] = (unsigned char) (coarseTime>>24);
1486 header->time[0] = (unsigned char) (coarseTime>>24);
1487 header->time[1] = (unsigned char) (coarseTime>>16);
1487 header->time[1] = (unsigned char) (coarseTime>>16);
1488 header->time[2] = (unsigned char) (coarseTime>>8);
1488 header->time[2] = (unsigned char) (coarseTime>>8);
1489 header->time[3] = (unsigned char) (coarseTime);
1489 header->time[3] = (unsigned char) (coarseTime);
1490 header->time[4] = (unsigned char) (fineTime>>8);
1490 header->time[4] = (unsigned char) (fineTime>>8);
1491 header->time[5] = (unsigned char) (fineTime);
1491 header->time[5] = (unsigned char) (fineTime);
1492 //
1492 //
1493 header->acquisitionTime[0] = header->time[0];
1493 header->acquisitionTime[0] = header->time[0];
1494 header->acquisitionTime[1] = header->time[1];
1494 header->acquisitionTime[1] = header->time[1];
1495 header->acquisitionTime[2] = header->time[2];
1495 header->acquisitionTime[2] = header->time[2];
1496 header->acquisitionTime[3] = header->time[3];
1496 header->acquisitionTime[3] = header->time[3];
1497 header->acquisitionTime[4] = header->time[4];
1497 header->acquisitionTime[4] = header->time[4];
1498 header->acquisitionTime[5] = header->time[5];
1498 header->acquisitionTime[5] = header->time[5];
1499
1499
1500 // (4) SEND PACKET
1500 // (4) SEND PACKET
1501 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1501 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1502 if (status != RTEMS_SUCCESSFUL) {
1502 if (status != RTEMS_SUCCESSFUL) {
1503 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1503 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1504 }
1504 }
1505 }
1505 }
1506 }
1506 }
1507
1507
1508 void spw_send_asm_f2( ring_node *ring_node_to_send,
1508 void spw_send_asm_f2( ring_node *ring_node_to_send,
1509 Header_TM_LFR_SCIENCE_ASM_t *header )
1509 Header_TM_LFR_SCIENCE_ASM_t *header )
1510 {
1510 {
1511 unsigned int i;
1511 unsigned int i;
1512 unsigned int length = 0;
1512 unsigned int length = 0;
1513 rtems_status_code status;
1513 rtems_status_code status;
1514 unsigned int sid;
1514 unsigned int sid;
1515 float *spectral_matrix;
1515 float *spectral_matrix;
1516 int coarseTime;
1516 int coarseTime;
1517 int fineTime;
1517 int fineTime;
1518 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1518 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1519
1519
1520 sid = ring_node_to_send->sid;
1520 sid = ring_node_to_send->sid;
1521 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1521 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1522 coarseTime = ring_node_to_send->coarseTime;
1522 coarseTime = ring_node_to_send->coarseTime;
1523 fineTime = ring_node_to_send->fineTime;
1523 fineTime = ring_node_to_send->fineTime;
1524
1524
1525 header->pa_bia_status_info = pa_bia_status_info;
1525 header->pa_bia_status_info = pa_bia_status_info;
1526 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1526 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1527
1527
1528 for (i=0; i<3; i++)
1528 for (i=0; i<3; i++)
1529 {
1529 {
1530
1530
1531 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1531 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1532 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1532 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1533 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1533 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1534 ];
1534 ];
1535 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1535 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1536 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1536 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1537 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
1537 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
1538 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1538 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1539
1539
1540 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1540 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1541 spw_ioctl_send_ASM.hdr = (char *) header;
1541 spw_ioctl_send_ASM.hdr = (char *) header;
1542 spw_ioctl_send_ASM.options = 0;
1542 spw_ioctl_send_ASM.options = 0;
1543
1543
1544 // (2) BUILD THE HEADER
1544 // (2) BUILD THE HEADER
1545 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1545 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1546 header->packetLength[0] = (unsigned char) (length>>8);
1546 header->packetLength[0] = (unsigned char) (length>>8);
1547 header->packetLength[1] = (unsigned char) (length);
1547 header->packetLength[1] = (unsigned char) (length);
1548 header->sid = (unsigned char) sid; // SID
1548 header->sid = (unsigned char) sid; // SID
1549 header->pa_lfr_pkt_cnt_asm = 3;
1549 header->pa_lfr_pkt_cnt_asm = 3;
1550 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1550 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1551
1551
1552 // (3) SET PACKET TIME
1552 // (3) SET PACKET TIME
1553 header->time[0] = (unsigned char) (coarseTime>>24);
1553 header->time[0] = (unsigned char) (coarseTime>>24);
1554 header->time[1] = (unsigned char) (coarseTime>>16);
1554 header->time[1] = (unsigned char) (coarseTime>>16);
1555 header->time[2] = (unsigned char) (coarseTime>>8);
1555 header->time[2] = (unsigned char) (coarseTime>>8);
1556 header->time[3] = (unsigned char) (coarseTime);
1556 header->time[3] = (unsigned char) (coarseTime);
1557 header->time[4] = (unsigned char) (fineTime>>8);
1557 header->time[4] = (unsigned char) (fineTime>>8);
1558 header->time[5] = (unsigned char) (fineTime);
1558 header->time[5] = (unsigned char) (fineTime);
1559 //
1559 //
1560 header->acquisitionTime[0] = header->time[0];
1560 header->acquisitionTime[0] = header->time[0];
1561 header->acquisitionTime[1] = header->time[1];
1561 header->acquisitionTime[1] = header->time[1];
1562 header->acquisitionTime[2] = header->time[2];
1562 header->acquisitionTime[2] = header->time[2];
1563 header->acquisitionTime[3] = header->time[3];
1563 header->acquisitionTime[3] = header->time[3];
1564 header->acquisitionTime[4] = header->time[4];
1564 header->acquisitionTime[4] = header->time[4];
1565 header->acquisitionTime[5] = header->time[5];
1565 header->acquisitionTime[5] = header->time[5];
1566
1566
1567 // (4) SEND PACKET
1567 // (4) SEND PACKET
1568 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1568 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1569 if (status != RTEMS_SUCCESSFUL) {
1569 if (status != RTEMS_SUCCESSFUL) {
1570 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1570 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1571 }
1571 }
1572 }
1572 }
1573 }
1573 }
1574
1574
1575 void spw_send_k_dump( ring_node *ring_node_to_send )
1575 void spw_send_k_dump( ring_node *ring_node_to_send )
1576 {
1576 {
1577 rtems_status_code status;
1577 rtems_status_code status;
1578 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1578 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1579 unsigned int packetLength;
1579 unsigned int packetLength;
1580 unsigned int size;
1580 unsigned int size;
1581
1581
1582 PRINTF("spw_send_k_dump\n")
1582 PRINTF("spw_send_k_dump\n")
1583
1583
1584 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1584 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1585
1585
1586 packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1];
1586 packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1];
1587
1587
1588 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1588 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1589
1589
1590 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1590 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1591
1591
1592 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1592 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1593
1593
1594 if (status == -1){
1594 if (status == -1){
1595 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1595 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1596 }
1596 }
1597
1597
1598 ring_node_to_send->status = 0x00;
1598 ring_node_to_send->status = 0x00;
1599 }
1599 }
@@ -1,1567 +1,1642
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;
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1;
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
19 ring_node kcoefficient_node_1;
19 ring_node kcoefficient_node_1;
20 ring_node kcoefficient_node_2;
20 ring_node kcoefficient_node_2;
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+10, sy_lfr_b_bp_p0 );
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, 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+10, sy_lfr_b_bp_p1 );
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1+10, 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+10, sy_lfr_b_bp_p0 );
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, 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+10, sy_lfr_s1_bp_p0 );
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, 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+10, sy_lfr_s1_bp_p1 );
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1+10, 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*0.25) ) - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25));
192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25) ) - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25));
193 if (aux > FLOAT_EQUAL_ZERO)
193 if (aux > FLOAT_EQUAL_ZERO)
194 {
194 {
195 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
195 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
196 flag = LFR_DEFAULT;
196 flag = LFR_DEFAULT;
197 }
197 }
198 }
198 }
199
199
200 // SET THE PARAMETERS
200 // SET THE PARAMETERS
201 if (flag == LFR_SUCCESSFUL)
201 if (flag == LFR_SUCCESSFUL)
202 {
202 {
203 flag = set_sy_lfr_s1_bp_p0( TC );
203 flag = set_sy_lfr_s1_bp_p0( TC );
204 flag = set_sy_lfr_s1_bp_p1( TC );
204 flag = set_sy_lfr_s1_bp_p1( TC );
205 }
205 }
206
206
207 return flag;
207 return flag;
208 }
208 }
209
209
210 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
210 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
211 {
211 {
212 /** This function updates the LFR registers with the incoming sbm2 parameters.
212 /** This function updates the LFR registers with the incoming sbm2 parameters.
213 *
213 *
214 * @param TC points to the TeleCommand packet that is being processed
214 * @param TC points to the TeleCommand packet that is being processed
215 * @param queue_id is the id of the queue which handles TM related to this execution step
215 * @param queue_id is the id of the queue which handles TM related to this execution step
216 *
216 *
217 */
217 */
218
218
219 int flag;
219 int flag;
220 rtems_status_code status;
220 rtems_status_code status;
221 unsigned char sy_lfr_s2_bp_p0;
221 unsigned char sy_lfr_s2_bp_p0;
222 unsigned char sy_lfr_s2_bp_p1;
222 unsigned char sy_lfr_s2_bp_p1;
223 float aux;
223 float aux;
224
224
225 flag = LFR_SUCCESSFUL;
225 flag = LFR_SUCCESSFUL;
226
226
227 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
227 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
228 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
228 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
229 flag = LFR_DEFAULT;
229 flag = LFR_DEFAULT;
230 }
230 }
231
231
232 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
232 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
233 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
233 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
234
234
235 // sy_lfr_s2_bp_p0
235 // sy_lfr_s2_bp_p0
236 if (flag == LFR_SUCCESSFUL)
236 if (flag == LFR_SUCCESSFUL)
237 {
237 {
238 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
238 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
239 {
239 {
240 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
240 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
241 flag = WRONG_APP_DATA;
241 flag = WRONG_APP_DATA;
242 }
242 }
243 }
243 }
244 // sy_lfr_s2_bp_p1
244 // sy_lfr_s2_bp_p1
245 if (flag == LFR_SUCCESSFUL)
245 if (flag == LFR_SUCCESSFUL)
246 {
246 {
247 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
247 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
248 {
248 {
249 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 );
249 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 );
250 flag = WRONG_APP_DATA;
250 flag = WRONG_APP_DATA;
251 }
251 }
252 }
252 }
253 //******************************************************************
253 //******************************************************************
254 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
254 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
255 if (flag == LFR_SUCCESSFUL)
255 if (flag == LFR_SUCCESSFUL)
256 {
256 {
257 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
257 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
258 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
258 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
259 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
259 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
260 if (aux > FLOAT_EQUAL_ZERO)
260 if (aux > FLOAT_EQUAL_ZERO)
261 {
261 {
262 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
262 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
263 flag = LFR_DEFAULT;
263 flag = LFR_DEFAULT;
264 }
264 }
265 }
265 }
266
266
267 // SET THE PARAMETERS
267 // SET THE PARAMETERS
268 if (flag == LFR_SUCCESSFUL)
268 if (flag == LFR_SUCCESSFUL)
269 {
269 {
270 flag = set_sy_lfr_s2_bp_p0( TC );
270 flag = set_sy_lfr_s2_bp_p0( TC );
271 flag = set_sy_lfr_s2_bp_p1( TC );
271 flag = set_sy_lfr_s2_bp_p1( TC );
272 }
272 }
273
273
274 return flag;
274 return flag;
275 }
275 }
276
276
277 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
277 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
278 {
278 {
279 /** This function updates the LFR registers with the incoming sbm2 parameters.
279 /** This function updates the LFR registers with the incoming sbm2 parameters.
280 *
280 *
281 * @param TC points to the TeleCommand packet that is being processed
281 * @param TC points to the TeleCommand packet that is being processed
282 * @param queue_id is the id of the queue which handles TM related to this execution step
282 * @param queue_id is the id of the queue which handles TM related to this execution step
283 *
283 *
284 */
284 */
285
285
286 int flag;
286 int flag;
287
287
288 flag = LFR_DEFAULT;
288 flag = LFR_DEFAULT;
289
289
290 flag = set_sy_lfr_kcoeff( TC, queue_id );
290 flag = set_sy_lfr_kcoeff( TC, queue_id );
291
291
292 return flag;
292 return flag;
293 }
293 }
294
294
295 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
295 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 {
296 {
297 /** This function updates the LFR registers with the incoming sbm2 parameters.
297 /** This function updates the LFR registers with the incoming sbm2 parameters.
298 *
298 *
299 * @param TC points to the TeleCommand packet that is being processed
299 * @param TC points to the TeleCommand packet that is being processed
300 * @param queue_id is the id of the queue which handles TM related to this execution step
300 * @param queue_id is the id of the queue which handles TM related to this execution step
301 *
301 *
302 */
302 */
303
303
304 int flag;
304 int flag;
305
305
306 flag = LFR_DEFAULT;
306 flag = LFR_DEFAULT;
307
307
308 flag = set_sy_lfr_fbins( TC );
308 flag = set_sy_lfr_fbins( TC );
309
309
310 return flag;
310 return flag;
311 }
311 }
312
312
313 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
313 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
314 {
314 {
315 /** This function updates the LFR registers with the incoming sbm2 parameters.
315 /** This function updates the LFR registers with the incoming sbm2 parameters.
316 *
316 *
317 * @param TC points to the TeleCommand packet that is being processed
317 * @param TC points to the TeleCommand packet that is being processed
318 * @param queue_id is the id of the queue which handles TM related to this execution step
318 * @param queue_id is the id of the queue which handles TM related to this execution step
319 *
319 *
320 */
320 */
321
321
322 int flag;
322 int flag;
323
323
324 flag = LFR_DEFAULT;
324 flag = LFR_DEFAULT;
325
325
326 flag = check_sy_lfr_filter_parameters( TC, queue_id );
326 flag = check_sy_lfr_filter_parameters( TC, queue_id );
327
327
328 if (flag == LFR_SUCCESSFUL)
328 if (flag == LFR_SUCCESSFUL)
329 {
329 {
330 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
330 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
331 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
331 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
332 parameter_dump_packet.sy_lfr_pas_filter_tbad[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 0 ];
332 parameter_dump_packet.sy_lfr_pas_filter_tbad[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 0 ];
333 parameter_dump_packet.sy_lfr_pas_filter_tbad[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 1 ];
333 parameter_dump_packet.sy_lfr_pas_filter_tbad[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 1 ];
334 parameter_dump_packet.sy_lfr_pas_filter_tbad[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 2 ];
334 parameter_dump_packet.sy_lfr_pas_filter_tbad[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 2 ];
335 parameter_dump_packet.sy_lfr_pas_filter_tbad[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 3 ];
335 parameter_dump_packet.sy_lfr_pas_filter_tbad[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 3 ];
336 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
336 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
337 parameter_dump_packet.sy_lfr_pas_filter_shift[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 0 ];
337 parameter_dump_packet.sy_lfr_pas_filter_shift[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 0 ];
338 parameter_dump_packet.sy_lfr_pas_filter_shift[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 1 ];
338 parameter_dump_packet.sy_lfr_pas_filter_shift[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 1 ];
339 parameter_dump_packet.sy_lfr_pas_filter_shift[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 2 ];
339 parameter_dump_packet.sy_lfr_pas_filter_shift[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 2 ];
340 parameter_dump_packet.sy_lfr_pas_filter_shift[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 3 ];
340 parameter_dump_packet.sy_lfr_pas_filter_shift[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 3 ];
341 parameter_dump_packet.sy_lfr_sc_rw_delta_f[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 0 ];
341 parameter_dump_packet.sy_lfr_sc_rw_delta_f[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 0 ];
342 parameter_dump_packet.sy_lfr_sc_rw_delta_f[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 1 ];
342 parameter_dump_packet.sy_lfr_sc_rw_delta_f[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 1 ];
343 parameter_dump_packet.sy_lfr_sc_rw_delta_f[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 2 ];
343 parameter_dump_packet.sy_lfr_sc_rw_delta_f[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 2 ];
344 parameter_dump_packet.sy_lfr_sc_rw_delta_f[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 3 ];
344 parameter_dump_packet.sy_lfr_sc_rw_delta_f[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 3 ];
345
345
346 //****************************
346 //****************************
347 // store PAS filter parameters
347 // store PAS filter parameters
348 // sy_lfr_pas_filter_enabled
348 // sy_lfr_pas_filter_enabled
349 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
349 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
350 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & 0x01 );
350 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & 0x01 );
351 // sy_lfr_pas_filter_modulus
351 // sy_lfr_pas_filter_modulus
352 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
352 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
353 // sy_lfr_pas_filter_tbad
353 // sy_lfr_pas_filter_tbad
354 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
354 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
355 parameter_dump_packet.sy_lfr_pas_filter_tbad );
355 parameter_dump_packet.sy_lfr_pas_filter_tbad );
356 // sy_lfr_pas_filter_offset
356 // sy_lfr_pas_filter_offset
357 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
357 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
358 // sy_lfr_pas_filter_shift
358 // sy_lfr_pas_filter_shift
359 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
359 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
360 parameter_dump_packet.sy_lfr_pas_filter_shift );
360 parameter_dump_packet.sy_lfr_pas_filter_shift );
361
361
362 //****************************************************
362 //****************************************************
363 // store the parameter sy_lfr_sc_rw_delta_f as a float
363 // store the parameter sy_lfr_sc_rw_delta_f as a float
364 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
364 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
365 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
365 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
366 }
366 }
367
367
368 return flag;
368 return flag;
369 }
369 }
370
370
371 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
371 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
372 {
372 {
373 /** This function updates the LFR registers with the incoming sbm2 parameters.
373 /** This function updates the LFR registers with the incoming sbm2 parameters.
374 *
374 *
375 * @param TC points to the TeleCommand packet that is being processed
375 * @param TC points to the TeleCommand packet that is being processed
376 * @param queue_id is the id of the queue which handles TM related to this execution step
376 * @param queue_id is the id of the queue which handles TM related to this execution step
377 *
377 *
378 */
378 */
379
379
380 unsigned int address;
380 unsigned int address;
381 rtems_status_code status;
381 rtems_status_code status;
382 unsigned int freq;
382 unsigned int freq;
383 unsigned int bin;
383 unsigned int bin;
384 unsigned int coeff;
384 unsigned int coeff;
385 unsigned char *kCoeffPtr;
385 unsigned char *kCoeffPtr;
386 unsigned char *kCoeffDumpPtr;
386 unsigned char *kCoeffDumpPtr;
387
387
388 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
388 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
389 // F0 => 11 bins
389 // F0 => 11 bins
390 // F1 => 13 bins
390 // F1 => 13 bins
391 // F2 => 12 bins
391 // F2 => 12 bins
392 // 36 bins to dump in two packets (30 bins max per packet)
392 // 36 bins to dump in two packets (30 bins max per packet)
393
393
394 //*********
394 //*********
395 // PACKET 1
395 // PACKET 1
396 // 11 F0 bins, 13 F1 bins and 6 F2 bins
396 // 11 F0 bins, 13 F1 bins and 6 F2 bins
397 kcoefficients_dump_1.destinationID = TC->sourceID;
397 kcoefficients_dump_1.destinationID = TC->sourceID;
398 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
398 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
399 for( freq=0;
399 for( freq=0;
400 freq<NB_BINS_COMPRESSED_SM_F0;
400 freq<NB_BINS_COMPRESSED_SM_F0;
401 freq++ )
401 freq++ )
402 {
402 {
403 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1] = freq;
403 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1] = freq;
404 bin = freq;
404 bin = freq;
405 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
405 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
406 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
406 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
407 {
407 {
408 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
408 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
409 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
409 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
410 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
410 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
411 }
411 }
412 }
412 }
413 for( freq=NB_BINS_COMPRESSED_SM_F0;
413 for( freq=NB_BINS_COMPRESSED_SM_F0;
414 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
414 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
415 freq++ )
415 freq++ )
416 {
416 {
417 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
417 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
418 bin = freq - NB_BINS_COMPRESSED_SM_F0;
418 bin = freq - NB_BINS_COMPRESSED_SM_F0;
419 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
419 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
420 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
420 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
421 {
421 {
422 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
422 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
423 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
423 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
424 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
424 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
425 }
425 }
426 }
426 }
427 for( freq=(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
427 for( freq=(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
428 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1+6);
428 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1+6);
429 freq++ )
429 freq++ )
430 {
430 {
431 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
431 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
432 bin = freq - (NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
432 bin = freq - (NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
433 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
433 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
434 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
434 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
435 {
435 {
436 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
436 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
437 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
437 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
438 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
438 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
439 }
439 }
440 }
440 }
441 kcoefficients_dump_1.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
441 kcoefficients_dump_1.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
442 kcoefficients_dump_1.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
442 kcoefficients_dump_1.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
443 kcoefficients_dump_1.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
443 kcoefficients_dump_1.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
444 kcoefficients_dump_1.time[3] = (unsigned char) (time_management_regs->coarse_time);
444 kcoefficients_dump_1.time[3] = (unsigned char) (time_management_regs->coarse_time);
445 kcoefficients_dump_1.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
445 kcoefficients_dump_1.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
446 kcoefficients_dump_1.time[5] = (unsigned char) (time_management_regs->fine_time);
446 kcoefficients_dump_1.time[5] = (unsigned char) (time_management_regs->fine_time);
447 // SEND DATA
447 // SEND DATA
448 kcoefficient_node_1.status = 1;
448 kcoefficient_node_1.status = 1;
449 address = (unsigned int) &kcoefficient_node_1;
449 address = (unsigned int) &kcoefficient_node_1;
450 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
450 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
451 if (status != RTEMS_SUCCESSFUL) {
451 if (status != RTEMS_SUCCESSFUL) {
452 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
452 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
453 }
453 }
454
454
455 //********
455 //********
456 // PACKET 2
456 // PACKET 2
457 // 6 F2 bins
457 // 6 F2 bins
458 kcoefficients_dump_2.destinationID = TC->sourceID;
458 kcoefficients_dump_2.destinationID = TC->sourceID;
459 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
459 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
460 for( freq=0; freq<6; freq++ )
460 for( freq=0; freq<6; freq++ )
461 {
461 {
462 kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + 6 + freq;
462 kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + 6 + freq;
463 bin = freq + 6;
463 bin = freq + 6;
464 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
464 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
465 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
465 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
466 {
466 {
467 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
467 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
468 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
468 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
469 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
469 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
470 }
470 }
471 }
471 }
472 kcoefficients_dump_2.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
472 kcoefficients_dump_2.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
473 kcoefficients_dump_2.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
473 kcoefficients_dump_2.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
474 kcoefficients_dump_2.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
474 kcoefficients_dump_2.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
475 kcoefficients_dump_2.time[3] = (unsigned char) (time_management_regs->coarse_time);
475 kcoefficients_dump_2.time[3] = (unsigned char) (time_management_regs->coarse_time);
476 kcoefficients_dump_2.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
476 kcoefficients_dump_2.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
477 kcoefficients_dump_2.time[5] = (unsigned char) (time_management_regs->fine_time);
477 kcoefficients_dump_2.time[5] = (unsigned char) (time_management_regs->fine_time);
478 // SEND DATA
478 // SEND DATA
479 kcoefficient_node_2.status = 1;
479 kcoefficient_node_2.status = 1;
480 address = (unsigned int) &kcoefficient_node_2;
480 address = (unsigned int) &kcoefficient_node_2;
481 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
481 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
482 if (status != RTEMS_SUCCESSFUL) {
482 if (status != RTEMS_SUCCESSFUL) {
483 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
483 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
484 }
484 }
485
485
486 return status;
486 return status;
487 }
487 }
488
488
489 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
489 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
490 {
490 {
491 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
491 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
492 *
492 *
493 * @param queue_id is the id of the queue which handles TM related to this execution step.
493 * @param queue_id is the id of the queue which handles TM related to this execution step.
494 *
494 *
495 * @return RTEMS directive status codes:
495 * @return RTEMS directive status codes:
496 * - RTEMS_SUCCESSFUL - message sent successfully
496 * - RTEMS_SUCCESSFUL - message sent successfully
497 * - RTEMS_INVALID_ID - invalid queue id
497 * - RTEMS_INVALID_ID - invalid queue id
498 * - RTEMS_INVALID_SIZE - invalid message size
498 * - RTEMS_INVALID_SIZE - invalid message size
499 * - RTEMS_INVALID_ADDRESS - buffer is NULL
499 * - RTEMS_INVALID_ADDRESS - buffer is NULL
500 * - RTEMS_UNSATISFIED - out of message buffers
500 * - RTEMS_UNSATISFIED - out of message buffers
501 * - RTEMS_TOO_MANY - queue s limit has been reached
501 * - RTEMS_TOO_MANY - queue s limit has been reached
502 *
502 *
503 */
503 */
504
504
505 int status;
505 int status;
506
506
507 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
507 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
508 parameter_dump_packet.destinationID = TC->sourceID;
508 parameter_dump_packet.destinationID = TC->sourceID;
509
509
510 // UPDATE TIME
510 // UPDATE TIME
511 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
511 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
512 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
512 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
513 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
513 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
514 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
514 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
515 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
515 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
516 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
516 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
517 // SEND DATA
517 // SEND DATA
518 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
518 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
519 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
519 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
520 if (status != RTEMS_SUCCESSFUL) {
520 if (status != RTEMS_SUCCESSFUL) {
521 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
521 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
522 }
522 }
523
523
524 return status;
524 return status;
525 }
525 }
526
526
527 //***********************
527 //***********************
528 // NORMAL MODE PARAMETERS
528 // NORMAL MODE PARAMETERS
529
529
530 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
530 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
531 {
531 {
532 unsigned char msb;
532 unsigned char msb;
533 unsigned char lsb;
533 unsigned char lsb;
534 int flag;
534 int flag;
535 float aux;
535 float aux;
536 rtems_status_code status;
536 rtems_status_code status;
537
537
538 unsigned int sy_lfr_n_swf_l;
538 unsigned int sy_lfr_n_swf_l;
539 unsigned int sy_lfr_n_swf_p;
539 unsigned int sy_lfr_n_swf_p;
540 unsigned int sy_lfr_n_asm_p;
540 unsigned int sy_lfr_n_asm_p;
541 unsigned char sy_lfr_n_bp_p0;
541 unsigned char sy_lfr_n_bp_p0;
542 unsigned char sy_lfr_n_bp_p1;
542 unsigned char sy_lfr_n_bp_p1;
543 unsigned char sy_lfr_n_cwf_long_f3;
543 unsigned char sy_lfr_n_cwf_long_f3;
544
544
545 flag = LFR_SUCCESSFUL;
545 flag = LFR_SUCCESSFUL;
546
546
547 //***************
547 //***************
548 // get parameters
548 // get parameters
549 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
549 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
550 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
550 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
551 sy_lfr_n_swf_l = msb * 256 + lsb;
551 sy_lfr_n_swf_l = msb * 256 + lsb;
552
552
553 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
553 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
554 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
554 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
555 sy_lfr_n_swf_p = msb * 256 + lsb;
555 sy_lfr_n_swf_p = msb * 256 + lsb;
556
556
557 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
557 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
558 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
558 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
559 sy_lfr_n_asm_p = msb * 256 + lsb;
559 sy_lfr_n_asm_p = msb * 256 + lsb;
560
560
561 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
561 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
562
562
563 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
563 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
564
564
565 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
565 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
566
566
567 //******************
567 //******************
568 // check consistency
568 // check consistency
569 // sy_lfr_n_swf_l
569 // sy_lfr_n_swf_l
570 if (sy_lfr_n_swf_l != 2048)
570 if (sy_lfr_n_swf_l != 2048)
571 {
571 {
572 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l );
572 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l );
573 flag = WRONG_APP_DATA;
573 flag = WRONG_APP_DATA;
574 }
574 }
575 // sy_lfr_n_swf_p
575 // sy_lfr_n_swf_p
576 if (flag == LFR_SUCCESSFUL)
576 if (flag == LFR_SUCCESSFUL)
577 {
577 {
578 if ( sy_lfr_n_swf_p < 22 )
578 if ( sy_lfr_n_swf_p < 22 )
579 {
579 {
580 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p );
580 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p );
581 flag = WRONG_APP_DATA;
581 flag = WRONG_APP_DATA;
582 }
582 }
583 }
583 }
584 // sy_lfr_n_bp_p0
584 // sy_lfr_n_bp_p0
585 if (flag == LFR_SUCCESSFUL)
585 if (flag == LFR_SUCCESSFUL)
586 {
586 {
587 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
587 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
588 {
588 {
589 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 );
589 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 );
590 flag = WRONG_APP_DATA;
590 flag = WRONG_APP_DATA;
591 }
591 }
592 }
592 }
593 // sy_lfr_n_asm_p
593 // sy_lfr_n_asm_p
594 if (flag == LFR_SUCCESSFUL)
594 if (flag == LFR_SUCCESSFUL)
595 {
595 {
596 if (sy_lfr_n_asm_p == 0)
596 if (sy_lfr_n_asm_p == 0)
597 {
597 {
598 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
598 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
599 flag = WRONG_APP_DATA;
599 flag = WRONG_APP_DATA;
600 }
600 }
601 }
601 }
602 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
602 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
603 if (flag == LFR_SUCCESSFUL)
603 if (flag == LFR_SUCCESSFUL)
604 {
604 {
605 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
605 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
606 if (aux > FLOAT_EQUAL_ZERO)
606 if (aux > FLOAT_EQUAL_ZERO)
607 {
607 {
608 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
608 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
609 flag = WRONG_APP_DATA;
609 flag = WRONG_APP_DATA;
610 }
610 }
611 }
611 }
612 // sy_lfr_n_bp_p1
612 // sy_lfr_n_bp_p1
613 if (flag == LFR_SUCCESSFUL)
613 if (flag == LFR_SUCCESSFUL)
614 {
614 {
615 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
615 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
616 {
616 {
617 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
617 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
618 flag = WRONG_APP_DATA;
618 flag = WRONG_APP_DATA;
619 }
619 }
620 }
620 }
621 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
621 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
622 if (flag == LFR_SUCCESSFUL)
622 if (flag == LFR_SUCCESSFUL)
623 {
623 {
624 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
624 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
625 if (aux > FLOAT_EQUAL_ZERO)
625 if (aux > FLOAT_EQUAL_ZERO)
626 {
626 {
627 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
627 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
628 flag = LFR_DEFAULT;
628 flag = LFR_DEFAULT;
629 }
629 }
630 }
630 }
631 // sy_lfr_n_cwf_long_f3
631 // sy_lfr_n_cwf_long_f3
632
632
633 return flag;
633 return flag;
634 }
634 }
635
635
636 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
636 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
637 {
637 {
638 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
638 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
639 *
639 *
640 * @param TC points to the TeleCommand packet that is being processed
640 * @param TC points to the TeleCommand packet that is being processed
641 * @param queue_id is the id of the queue which handles TM related to this execution step
641 * @param queue_id is the id of the queue which handles TM related to this execution step
642 *
642 *
643 */
643 */
644
644
645 int result;
645 int result;
646
646
647 result = LFR_SUCCESSFUL;
647 result = LFR_SUCCESSFUL;
648
648
649 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
649 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
650 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
650 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
651
651
652 return result;
652 return result;
653 }
653 }
654
654
655 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
655 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
656 {
656 {
657 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
657 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
658 *
658 *
659 * @param TC points to the TeleCommand packet that is being processed
659 * @param TC points to the TeleCommand packet that is being processed
660 * @param queue_id is the id of the queue which handles TM related to this execution step
660 * @param queue_id is the id of the queue which handles TM related to this execution step
661 *
661 *
662 */
662 */
663
663
664 int result;
664 int result;
665
665
666 result = LFR_SUCCESSFUL;
666 result = LFR_SUCCESSFUL;
667
667
668 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
668 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
669 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
669 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
670
670
671 return result;
671 return result;
672 }
672 }
673
673
674 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
674 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
675 {
675 {
676 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
676 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
677 *
677 *
678 * @param TC points to the TeleCommand packet that is being processed
678 * @param TC points to the TeleCommand packet that is being processed
679 * @param queue_id is the id of the queue which handles TM related to this execution step
679 * @param queue_id is the id of the queue which handles TM related to this execution step
680 *
680 *
681 */
681 */
682
682
683 int result;
683 int result;
684
684
685 result = LFR_SUCCESSFUL;
685 result = LFR_SUCCESSFUL;
686
686
687 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
687 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
688 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
688 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
689
689
690 return result;
690 return result;
691 }
691 }
692
692
693 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
693 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
694 {
694 {
695 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
695 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
696 *
696 *
697 * @param TC points to the TeleCommand packet that is being processed
697 * @param TC points to the TeleCommand packet that is being processed
698 * @param queue_id is the id of the queue which handles TM related to this execution step
698 * @param queue_id is the id of the queue which handles TM related to this execution step
699 *
699 *
700 */
700 */
701
701
702 int status;
702 int status;
703
703
704 status = LFR_SUCCESSFUL;
704 status = LFR_SUCCESSFUL;
705
705
706 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
706 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
707
707
708 return status;
708 return status;
709 }
709 }
710
710
711 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
711 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
712 {
712 {
713 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
713 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
714 *
714 *
715 * @param TC points to the TeleCommand packet that is being processed
715 * @param TC points to the TeleCommand packet that is being processed
716 * @param queue_id is the id of the queue which handles TM related to this execution step
716 * @param queue_id is the id of the queue which handles TM related to this execution step
717 *
717 *
718 */
718 */
719
719
720 int status;
720 int status;
721
721
722 status = LFR_SUCCESSFUL;
722 status = LFR_SUCCESSFUL;
723
723
724 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
724 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
725
725
726 return status;
726 return status;
727 }
727 }
728
728
729 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
729 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
730 {
730 {
731 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
731 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
732 *
732 *
733 * @param TC points to the TeleCommand packet that is being processed
733 * @param TC points to the TeleCommand packet that is being processed
734 * @param queue_id is the id of the queue which handles TM related to this execution step
734 * @param queue_id is the id of the queue which handles TM related to this execution step
735 *
735 *
736 */
736 */
737
737
738 int status;
738 int status;
739
739
740 status = LFR_SUCCESSFUL;
740 status = LFR_SUCCESSFUL;
741
741
742 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
742 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
743
743
744 return status;
744 return status;
745 }
745 }
746
746
747 //**********************
747 //**********************
748 // BURST MODE PARAMETERS
748 // BURST MODE PARAMETERS
749 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
749 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
750 {
750 {
751 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
751 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
752 *
752 *
753 * @param TC points to the TeleCommand packet that is being processed
753 * @param TC points to the TeleCommand packet that is being processed
754 * @param queue_id is the id of the queue which handles TM related to this execution step
754 * @param queue_id is the id of the queue which handles TM related to this execution step
755 *
755 *
756 */
756 */
757
757
758 int status;
758 int status;
759
759
760 status = LFR_SUCCESSFUL;
760 status = LFR_SUCCESSFUL;
761
761
762 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
762 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
763
763
764 return status;
764 return status;
765 }
765 }
766
766
767 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
767 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
768 {
768 {
769 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
769 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
770 *
770 *
771 * @param TC points to the TeleCommand packet that is being processed
771 * @param TC points to the TeleCommand packet that is being processed
772 * @param queue_id is the id of the queue which handles TM related to this execution step
772 * @param queue_id is the id of the queue which handles TM related to this execution step
773 *
773 *
774 */
774 */
775
775
776 int status;
776 int status;
777
777
778 status = LFR_SUCCESSFUL;
778 status = LFR_SUCCESSFUL;
779
779
780 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
780 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
781
781
782 return status;
782 return status;
783 }
783 }
784
784
785 //*********************
785 //*********************
786 // SBM1 MODE PARAMETERS
786 // SBM1 MODE PARAMETERS
787 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
787 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
788 {
788 {
789 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
789 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
790 *
790 *
791 * @param TC points to the TeleCommand packet that is being processed
791 * @param TC points to the TeleCommand packet that is being processed
792 * @param queue_id is the id of the queue which handles TM related to this execution step
792 * @param queue_id is the id of the queue which handles TM related to this execution step
793 *
793 *
794 */
794 */
795
795
796 int status;
796 int status;
797
797
798 status = LFR_SUCCESSFUL;
798 status = LFR_SUCCESSFUL;
799
799
800 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
800 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
801
801
802 return status;
802 return status;
803 }
803 }
804
804
805 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
805 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
806 {
806 {
807 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
807 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
808 *
808 *
809 * @param TC points to the TeleCommand packet that is being processed
809 * @param TC points to the TeleCommand packet that is being processed
810 * @param queue_id is the id of the queue which handles TM related to this execution step
810 * @param queue_id is the id of the queue which handles TM related to this execution step
811 *
811 *
812 */
812 */
813
813
814 int status;
814 int status;
815
815
816 status = LFR_SUCCESSFUL;
816 status = LFR_SUCCESSFUL;
817
817
818 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
818 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
819
819
820 return status;
820 return status;
821 }
821 }
822
822
823 //*********************
823 //*********************
824 // SBM2 MODE PARAMETERS
824 // SBM2 MODE PARAMETERS
825 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
825 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
826 {
826 {
827 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
827 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
828 *
828 *
829 * @param TC points to the TeleCommand packet that is being processed
829 * @param TC points to the TeleCommand packet that is being processed
830 * @param queue_id is the id of the queue which handles TM related to this execution step
830 * @param queue_id is the id of the queue which handles TM related to this execution step
831 *
831 *
832 */
832 */
833
833
834 int status;
834 int status;
835
835
836 status = LFR_SUCCESSFUL;
836 status = LFR_SUCCESSFUL;
837
837
838 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
838 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
839
839
840 return status;
840 return status;
841 }
841 }
842
842
843 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
843 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
844 {
844 {
845 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
845 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
846 *
846 *
847 * @param TC points to the TeleCommand packet that is being processed
847 * @param TC points to the TeleCommand packet that is being processed
848 * @param queue_id is the id of the queue which handles TM related to this execution step
848 * @param queue_id is the id of the queue which handles TM related to this execution step
849 *
849 *
850 */
850 */
851
851
852 int status;
852 int status;
853
853
854 status = LFR_SUCCESSFUL;
854 status = LFR_SUCCESSFUL;
855
855
856 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
856 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
857
857
858 return status;
858 return status;
859 }
859 }
860
860
861 //*******************
861 //*******************
862 // TC_LFR_UPDATE_INFO
862 // TC_LFR_UPDATE_INFO
863 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
863 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
864 {
864 {
865 unsigned int status;
865 unsigned int status;
866
866
867 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
867 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
868 || (mode == LFR_MODE_BURST)
868 || (mode == LFR_MODE_BURST)
869 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
869 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
870 {
870 {
871 status = LFR_SUCCESSFUL;
871 status = LFR_SUCCESSFUL;
872 }
872 }
873 else
873 else
874 {
874 {
875 status = LFR_DEFAULT;
875 status = LFR_DEFAULT;
876 }
876 }
877
877
878 return status;
878 return status;
879 }
879 }
880
880
881 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
881 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
882 {
882 {
883 unsigned int status;
883 unsigned int status;
884
884
885 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
885 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
886 || (mode == TDS_MODE_BURST)
886 || (mode == TDS_MODE_BURST)
887 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
887 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
888 || (mode == TDS_MODE_LFM))
888 || (mode == TDS_MODE_LFM))
889 {
889 {
890 status = LFR_SUCCESSFUL;
890 status = LFR_SUCCESSFUL;
891 }
891 }
892 else
892 else
893 {
893 {
894 status = LFR_DEFAULT;
894 status = LFR_DEFAULT;
895 }
895 }
896
896
897 return status;
897 return status;
898 }
898 }
899
899
900 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
900 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
901 {
901 {
902 unsigned int status;
902 unsigned int status;
903
903
904 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
904 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
905 || (mode == THR_MODE_BURST))
905 || (mode == THR_MODE_BURST))
906 {
906 {
907 status = LFR_SUCCESSFUL;
907 status = LFR_SUCCESSFUL;
908 }
908 }
909 else
909 else
910 {
910 {
911 status = LFR_DEFAULT;
911 status = LFR_DEFAULT;
912 }
912 }
913
913
914 return status;
914 return status;
915 }
915 }
916
916
917 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
917 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
918 {
918 {
919 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
919 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
920 *
920 *
921 * @param TC points to the TeleCommand packet that is being processed
921 * @param TC points to the TeleCommand packet that is being processed
922 *
922 *
923 */
923 */
924
924
925 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
925 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
926
926
927 bytePosPtr = (unsigned char *) &TC->packetID;
927 bytePosPtr = (unsigned char *) &TC->packetID;
928
928
929 // cp_rpw_sc_rw1_f1
929 // cp_rpw_sc_rw1_f1
930 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
930 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
931 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
931 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
932
932
933 // cp_rpw_sc_rw1_f2
933 // cp_rpw_sc_rw1_f2
934 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
934 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
935 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
935 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
936
936
937 // cp_rpw_sc_rw2_f1
937 // cp_rpw_sc_rw2_f1
938 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
938 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
939 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
939 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
940
940
941 // cp_rpw_sc_rw2_f2
941 // cp_rpw_sc_rw2_f2
942 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
942 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
943 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
943 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
944
944
945 // cp_rpw_sc_rw3_f1
945 // cp_rpw_sc_rw3_f1
946 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
946 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
947 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
947 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
948
948
949 // cp_rpw_sc_rw3_f2
949 // cp_rpw_sc_rw3_f2
950 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
950 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
951 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
951 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
952
952
953 // cp_rpw_sc_rw4_f1
953 // cp_rpw_sc_rw4_f1
954 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
954 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
955 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
955 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
956
956
957 // cp_rpw_sc_rw4_f2
957 // cp_rpw_sc_rw4_f2
958 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
958 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
959 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
959 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
960 }
960 }
961
961
962 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
962 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
963 {
963 {
964 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
964 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
965 *
965 *
966 * @param fbins_mask
966 * @param fbins_mask
967 * @param rw_f is the reaction wheel frequency to filter
967 * @param rw_f is the reaction wheel frequency to filter
968 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
968 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
969 * @param flag [true] filtering enabled [false] filtering disabled
969 * @param flag [true] filtering enabled [false] filtering disabled
970 *
970 *
971 * @return void
971 * @return void
972 *
972 *
973 */
973 */
974
974
975 float fmin;
975 float f_RW_min;
976 float fMAX;
976 float f_RW_MAX;
977 float fi_min;
978 float fi_MAX;
979 float fi;
980 float deltaBelow;
981 float deltaAbove;
977 int binBelow;
982 int binBelow;
978 int binAbove;
983 int binAbove;
984 int closestBin;
979 unsigned int whichByte;
985 unsigned int whichByte;
980 unsigned char selectedByte;
986 int selectedByte;
981 int bin;
987 int bin;
988 int binToRemove[3];
989 int k;
982
990
983 whichByte = 0;
991 whichByte = 0;
984 bin = 0;
992 bin = 0;
985
993
994 binToRemove[0] = -1;
995 binToRemove[1] = -1;
996 binToRemove[2] = -1;
997
986 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
998 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
987 fmin = rw_f - filterPar.sy_lfr_sc_rw_delta_f / 2.;
999 f_RW_min = rw_f - filterPar.sy_lfr_sc_rw_delta_f / 2.;
988 fMAX = rw_f + filterPar.sy_lfr_sc_rw_delta_f / 2.;
1000 f_RW_MAX = rw_f + filterPar.sy_lfr_sc_rw_delta_f / 2.;
1001
1002 // compute the index of the frequency bin immediately below rw_f
1003 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1004 deltaBelow = rw_f - binBelow * deltaFreq;
1005
1006 // compute the index of the frequency bin immediately above rw_f
1007 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1008 deltaAbove = binAbove * deltaFreq - rw_f;
989
1009
990 // compute the index of the frequency bin immediately below fmin
1010 // search the closest bin
991 binBelow = (int) ( floor( ((double) fmin) / ((double) deltaFreq)) );
1011 if (deltaAbove > deltaBelow)
1012 {
1013 closestBin = binBelow;
1014 }
1015 else
1016 {
1017 closestBin = binAbove;
1018 }
1019
1020 // compute the fi interval [fi - Delta_f * 0.285, fi + Delta_f * 0.285]
1021 fi = closestBin * deltaFreq;
992
1022
993 // compute the index of the frequency bin immediately above fMAX
1023 fi_min = fi - (deltaFreq * 0.285);
994 binAbove = (int) ( floor( ((double) fMAX) / ((double) deltaFreq)) );
1024 if ( fi_min < 0 )
1025 {
1026 fi_min = 0;
1027 }
1028 else if ( fi_min > (deltaFreq*127) )
1029 {
1030 fi_min = -1;
1031 }
1032
1033 fi_MAX = fi + (deltaFreq * 0.285);
1034 if ( fi_MAX > (deltaFreq*127) )
1035 {
1036 fi_MAX = -1;
1037 }
995
1038
996 for (bin = binBelow; bin <= binAbove; bin++)
1039 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1040 // => remove f_(i), f_(i-1) and f_(i+1)
1041 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
997 {
1042 {
998 if ( (bin >= 0) && (bin<=127) )
1043 binToRemove[0] = closestBin - 1;
1044 binToRemove[1] = closestBin;
1045 binToRemove[2] = closestBin + 1;
1046 }
1047 // 2. ELSE
1048 // => remove the two f_(i) which are around f_RW
1049 else
1050 {
1051 binToRemove[0] = binBelow;
1052 binToRemove[1] = binAbove;
1053 binToRemove[2] = -1;
1054 }
1055
1056 for (k = 0; k <= 3; k++)
1057 {
1058 bin = binToRemove[k];
1059 if ( (bin >= 0) && (bin <= 127) )
999 {
1060 {
1000 if (flag == 1)
1061 if (flag == 1)
1001 {
1062 {
1002 whichByte = bin >> 3; // division by 8
1063 whichByte = (bin >> 3); // division by 8
1003 selectedByte = (unsigned char) ( 1 << (bin - (whichByte * 8)) );
1064 selectedByte = ( 1 << (bin - (whichByte * 8)) );
1004 fbins_mask[whichByte] = fbins_mask[whichByte] & (~selectedByte);
1065
1066 printf("whichByte = %d, bin = %d, selectedByte = %x (%x)\n", whichByte, bin, selectedByte, ~selectedByte);
1067
1068 fbins_mask[15 - whichByte] = fbins_mask[15 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1005 }
1069 }
1006 }
1070 }
1007 }
1071 }
1072
1073 if (flag == 1)
1074 {
1075 printf("fi = %f, fi_min = %f, fi_MAX = %f\n", fi, fi_min, fi_MAX);
1076 printf("deltaFreq = %d, flag = %d, rw_f = %f, f_RW_min = %f, f_RW_MAX = %f\n", deltaFreq, flag, rw_f, f_RW_min, f_RW_MAX);
1077 printf("%x %x %x %x ** %x %x %x %x ** %x %x %x %x ** %x %x %x %x\n\n", fbins_mask[0], fbins_mask[1], fbins_mask[2], fbins_mask[3],
1078 fbins_mask[4], fbins_mask[5], fbins_mask[6], fbins_mask[7],
1079 fbins_mask[8], fbins_mask[9], fbins_mask[10], fbins_mask[11],
1080 fbins_mask[12], fbins_mask[13], fbins_mask[14], fbins_mask[15]);
1081 }
1082
1008 }
1083 }
1009
1084
1010 void build_sy_lfr_rw_mask( unsigned int channel )
1085 void build_sy_lfr_rw_mask( unsigned int channel )
1011 {
1086 {
1012 unsigned char local_rw_fbins_mask[16];
1087 unsigned char local_rw_fbins_mask[16];
1013 unsigned char *maskPtr;
1088 unsigned char *maskPtr;
1014 double deltaF;
1089 double deltaF;
1015 unsigned k;
1090 unsigned k;
1016
1091
1017 k = 0;
1092 k = 0;
1018
1093
1019 maskPtr = NULL;
1094 maskPtr = NULL;
1020 deltaF = 1.;
1095 deltaF = 1.;
1021
1096
1022 switch (channel)
1097 switch (channel)
1023 {
1098 {
1024 case 0:
1099 case 0:
1025 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1100 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1026 deltaF = 96.;
1101 deltaF = 96.;
1027 break;
1102 break;
1028 case 1:
1103 case 1:
1029 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1104 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1030 deltaF = 16.;
1105 deltaF = 16.;
1031 break;
1106 break;
1032 case 2:
1107 case 2:
1033 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1108 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1034 deltaF = 1.;
1109 deltaF = 1.;
1035 break;
1110 break;
1036 default:
1111 default:
1037 break;
1112 break;
1038 }
1113 }
1039
1114
1040 for (k = 0; k < 16; k++)
1115 for (k = 0; k < 16; k++)
1041 {
1116 {
1042 local_rw_fbins_mask[k] = 0xff;
1117 local_rw_fbins_mask[k] = 0xff;
1043 }
1118 }
1044
1119
1045 // RW1 F1
1120 // RW1 F1
1046 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x80) >> 7 ); // [1000 0000]
1121 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x80) >> 7 ); // [1000 0000]
1047
1122
1048 // RW1 F2
1123 // RW1 F2
1049 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x40) >> 6 ); // [0100 0000]
1124 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x40) >> 6 ); // [0100 0000]
1050
1125
1051 // RW2 F1
1126 // RW2 F1
1052 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x20) >> 5 ); // [0010 0000]
1127 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x20) >> 5 ); // [0010 0000]
1053
1128
1054 // RW2 F2
1129 // RW2 F2
1055 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x10) >> 4 ); // [0001 0000]
1130 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x10) >> 4 ); // [0001 0000]
1056
1131
1057 // RW3 F1
1132 // RW3 F1
1058 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x08) >> 3 ); // [0000 1000]
1133 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x08) >> 3 ); // [0000 1000]
1059
1134
1060 // RW3 F2
1135 // RW3 F2
1061 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x04) >> 2 ); // [0000 0100]
1136 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x04) >> 2 ); // [0000 0100]
1062
1137
1063 // RW4 F1
1138 // RW4 F1
1064 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x02) >> 1 ); // [0000 0010]
1139 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x02) >> 1 ); // [0000 0010]
1065
1140
1066 // RW4 F2
1141 // RW4 F2
1067 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x01) ); // [0000 0001]
1142 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x01) ); // [0000 0001]
1068
1143
1069 // update the value of the fbins related to reaction wheels frequency filtering
1144 // update the value of the fbins related to reaction wheels frequency filtering
1070 if (maskPtr != NULL)
1145 if (maskPtr != NULL)
1071 {
1146 {
1072 for (k = 0; k < 16; k++)
1147 for (k = 0; k < 16; k++)
1073 {
1148 {
1074 maskPtr[k] = local_rw_fbins_mask[k];
1149 maskPtr[k] = local_rw_fbins_mask[k];
1075 }
1150 }
1076 }
1151 }
1077 }
1152 }
1078
1153
1079 void build_sy_lfr_rw_masks( void )
1154 void build_sy_lfr_rw_masks( void )
1080 {
1155 {
1081 build_sy_lfr_rw_mask( 0 );
1156 build_sy_lfr_rw_mask( 0 );
1082 build_sy_lfr_rw_mask( 1 );
1157 build_sy_lfr_rw_mask( 1 );
1083 build_sy_lfr_rw_mask( 2 );
1158 build_sy_lfr_rw_mask( 2 );
1084
1159
1085 merge_fbins_masks();
1160 merge_fbins_masks();
1086 }
1161 }
1087
1162
1088 void merge_fbins_masks( void )
1163 void merge_fbins_masks( void )
1089 {
1164 {
1090 unsigned char k;
1165 unsigned char k;
1091
1166
1092 unsigned char *fbins_f0;
1167 unsigned char *fbins_f0;
1093 unsigned char *fbins_f1;
1168 unsigned char *fbins_f1;
1094 unsigned char *fbins_f2;
1169 unsigned char *fbins_f2;
1095 unsigned char *rw_mask_f0;
1170 unsigned char *rw_mask_f0;
1096 unsigned char *rw_mask_f1;
1171 unsigned char *rw_mask_f1;
1097 unsigned char *rw_mask_f2;
1172 unsigned char *rw_mask_f2;
1098
1173
1099 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1174 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1100 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1175 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1101 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1176 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1102 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1177 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1103 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1178 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1104 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1179 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1105
1180
1106 for( k=0; k < 16; k++ )
1181 for( k=0; k < 16; k++ )
1107 {
1182 {
1108 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1183 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1109 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1184 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1110 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1185 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1111 }
1186 }
1112 }
1187 }
1113
1188
1114 //***********
1189 //***********
1115 // FBINS MASK
1190 // FBINS MASK
1116
1191
1117 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1192 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1118 {
1193 {
1119 int status;
1194 int status;
1120 unsigned int k;
1195 unsigned int k;
1121 unsigned char *fbins_mask_dump;
1196 unsigned char *fbins_mask_dump;
1122 unsigned char *fbins_mask_TC;
1197 unsigned char *fbins_mask_TC;
1123
1198
1124 status = LFR_SUCCESSFUL;
1199 status = LFR_SUCCESSFUL;
1125
1200
1126 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1201 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1127 fbins_mask_TC = TC->dataAndCRC;
1202 fbins_mask_TC = TC->dataAndCRC;
1128
1203
1129 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1204 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1130 {
1205 {
1131 fbins_mask_dump[k] = fbins_mask_TC[k];
1206 fbins_mask_dump[k] = fbins_mask_TC[k];
1132 }
1207 }
1133
1208
1134 return status;
1209 return status;
1135 }
1210 }
1136
1211
1137 //***************************
1212 //***************************
1138 // TC_LFR_LOAD_PAS_FILTER_PAR
1213 // TC_LFR_LOAD_PAS_FILTER_PAR
1139
1214
1140 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1215 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1141 {
1216 {
1142 int flag;
1217 int flag;
1143 rtems_status_code status;
1218 rtems_status_code status;
1144
1219
1145 unsigned char sy_lfr_pas_filter_enabled;
1220 unsigned char sy_lfr_pas_filter_enabled;
1146 unsigned char sy_lfr_pas_filter_modulus;
1221 unsigned char sy_lfr_pas_filter_modulus;
1147 float sy_lfr_pas_filter_tbad;
1222 float sy_lfr_pas_filter_tbad;
1148 unsigned char sy_lfr_pas_filter_offset;
1223 unsigned char sy_lfr_pas_filter_offset;
1149 float sy_lfr_pas_filter_shift;
1224 float sy_lfr_pas_filter_shift;
1150 float sy_lfr_sc_rw_delta_f;
1225 float sy_lfr_sc_rw_delta_f;
1151 char *parPtr;
1226 char *parPtr;
1152
1227
1153 flag = LFR_SUCCESSFUL;
1228 flag = LFR_SUCCESSFUL;
1154 sy_lfr_pas_filter_tbad = 0.0;
1229 sy_lfr_pas_filter_tbad = 0.0;
1155 sy_lfr_pas_filter_shift = 0.0;
1230 sy_lfr_pas_filter_shift = 0.0;
1156 sy_lfr_sc_rw_delta_f = 0.0;
1231 sy_lfr_sc_rw_delta_f = 0.0;
1157 parPtr = NULL;
1232 parPtr = NULL;
1158
1233
1159 //***************
1234 //***************
1160 // get parameters
1235 // get parameters
1161 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & 0x01; // [0000 0001]
1236 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & 0x01; // [0000 0001]
1162 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1237 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1163 copyFloatByChar(
1238 copyFloatByChar(
1164 (unsigned char*) &sy_lfr_pas_filter_tbad,
1239 (unsigned char*) &sy_lfr_pas_filter_tbad,
1165 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1240 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1166 );
1241 );
1167 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1242 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1168 copyFloatByChar(
1243 copyFloatByChar(
1169 (unsigned char*) &sy_lfr_pas_filter_shift,
1244 (unsigned char*) &sy_lfr_pas_filter_shift,
1170 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1245 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1171 );
1246 );
1172 copyFloatByChar(
1247 copyFloatByChar(
1173 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1248 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1174 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1249 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1175 );
1250 );
1176
1251
1177 //******************
1252 //******************
1178 // CHECK CONSISTENCY
1253 // CHECK CONSISTENCY
1179
1254
1180 //**************************
1255 //**************************
1181 // sy_lfr_pas_filter_enabled
1256 // sy_lfr_pas_filter_enabled
1182 // nothing to check, value is 0 or 1
1257 // nothing to check, value is 0 or 1
1183
1258
1184 //**************************
1259 //**************************
1185 // sy_lfr_pas_filter_modulus
1260 // sy_lfr_pas_filter_modulus
1186 if ( (sy_lfr_pas_filter_modulus < 4) || (sy_lfr_pas_filter_modulus > 8) )
1261 if ( (sy_lfr_pas_filter_modulus < 4) || (sy_lfr_pas_filter_modulus > 8) )
1187 {
1262 {
1188 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS+10, sy_lfr_pas_filter_modulus );
1263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS+10, sy_lfr_pas_filter_modulus );
1189 flag = WRONG_APP_DATA;
1264 flag = WRONG_APP_DATA;
1190 }
1265 }
1191
1266
1192 //***********************
1267 //***********************
1193 // sy_lfr_pas_filter_tbad
1268 // sy_lfr_pas_filter_tbad
1194 if ( (sy_lfr_pas_filter_tbad < 0.0) || (sy_lfr_pas_filter_tbad > 4.0) )
1269 if ( (sy_lfr_pas_filter_tbad < 0.0) || (sy_lfr_pas_filter_tbad > 4.0) )
1195 {
1270 {
1196 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1271 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1197 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD+10, parPtr[3] );
1272 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD+10, parPtr[3] );
1198 flag = WRONG_APP_DATA;
1273 flag = WRONG_APP_DATA;
1199 }
1274 }
1200
1275
1201 //*************************
1276 //*************************
1202 // sy_lfr_pas_filter_offset
1277 // sy_lfr_pas_filter_offset
1203 if (flag == LFR_SUCCESSFUL)
1278 if (flag == LFR_SUCCESSFUL)
1204 {
1279 {
1205 if ( (sy_lfr_pas_filter_offset < 0) || (sy_lfr_pas_filter_offset > 7) )
1280 if ( (sy_lfr_pas_filter_offset < 0) || (sy_lfr_pas_filter_offset > 7) )
1206 {
1281 {
1207 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET+10, sy_lfr_pas_filter_offset );
1282 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET+10, sy_lfr_pas_filter_offset );
1208 flag = WRONG_APP_DATA;
1283 flag = WRONG_APP_DATA;
1209 }
1284 }
1210 }
1285 }
1211
1286
1212 //************************
1287 //************************
1213 // sy_lfr_pas_filter_shift
1288 // sy_lfr_pas_filter_shift
1214 if ( (sy_lfr_pas_filter_shift < 0.0) || (sy_lfr_pas_filter_shift > 1.0) )
1289 if ( (sy_lfr_pas_filter_shift < 0.0) || (sy_lfr_pas_filter_shift > 1.0) )
1215 {
1290 {
1216 parPtr = (char*) &sy_lfr_pas_filter_shift;
1291 parPtr = (char*) &sy_lfr_pas_filter_shift;
1217 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT+10, parPtr[3] );
1292 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT+10, parPtr[3] );
1218 flag = WRONG_APP_DATA;
1293 flag = WRONG_APP_DATA;
1219 }
1294 }
1220
1295
1221 //*********************
1296 //*********************
1222 // sy_lfr_sc_rw_delta_f
1297 // sy_lfr_sc_rw_delta_f
1223 // nothing to check, no default value in the ICD
1298 // nothing to check, no default value in the ICD
1224
1299
1225 return flag;
1300 return flag;
1226 }
1301 }
1227
1302
1228 //**************
1303 //**************
1229 // KCOEFFICIENTS
1304 // KCOEFFICIENTS
1230 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1305 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1231 {
1306 {
1232 unsigned int kcoeff;
1307 unsigned int kcoeff;
1233 unsigned short sy_lfr_kcoeff_frequency;
1308 unsigned short sy_lfr_kcoeff_frequency;
1234 unsigned short bin;
1309 unsigned short bin;
1235 unsigned short *freqPtr;
1310 unsigned short *freqPtr;
1236 float *kcoeffPtr_norm;
1311 float *kcoeffPtr_norm;
1237 float *kcoeffPtr_sbm;
1312 float *kcoeffPtr_sbm;
1238 int status;
1313 int status;
1239 unsigned char *kcoeffLoadPtr;
1314 unsigned char *kcoeffLoadPtr;
1240 unsigned char *kcoeffNormPtr;
1315 unsigned char *kcoeffNormPtr;
1241 unsigned char *kcoeffSbmPtr_a;
1316 unsigned char *kcoeffSbmPtr_a;
1242 unsigned char *kcoeffSbmPtr_b;
1317 unsigned char *kcoeffSbmPtr_b;
1243
1318
1244 status = LFR_SUCCESSFUL;
1319 status = LFR_SUCCESSFUL;
1245
1320
1246 kcoeffPtr_norm = NULL;
1321 kcoeffPtr_norm = NULL;
1247 kcoeffPtr_sbm = NULL;
1322 kcoeffPtr_sbm = NULL;
1248 bin = 0;
1323 bin = 0;
1249
1324
1250 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1325 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1251 sy_lfr_kcoeff_frequency = *freqPtr;
1326 sy_lfr_kcoeff_frequency = *freqPtr;
1252
1327
1253 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1328 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1254 {
1329 {
1255 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1330 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1256 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 10 + 1,
1331 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 10 + 1,
1257 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1332 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1258 status = LFR_DEFAULT;
1333 status = LFR_DEFAULT;
1259 }
1334 }
1260 else
1335 else
1261 {
1336 {
1262 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1337 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1263 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1338 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1264 {
1339 {
1265 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1340 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1266 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1341 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1267 bin = sy_lfr_kcoeff_frequency;
1342 bin = sy_lfr_kcoeff_frequency;
1268 }
1343 }
1269 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1344 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1270 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1345 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1271 {
1346 {
1272 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1347 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1273 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1348 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1274 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1349 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1275 }
1350 }
1276 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1351 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1277 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1352 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1278 {
1353 {
1279 kcoeffPtr_norm = k_coeff_intercalib_f2;
1354 kcoeffPtr_norm = k_coeff_intercalib_f2;
1280 kcoeffPtr_sbm = NULL;
1355 kcoeffPtr_sbm = NULL;
1281 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1356 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1282 }
1357 }
1283 }
1358 }
1284
1359
1285 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1360 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1286 {
1361 {
1287 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1362 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1288 {
1363 {
1289 // destination
1364 // destination
1290 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1365 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1291 // source
1366 // source
1292 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1367 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1293 // copy source to destination
1368 // copy source to destination
1294 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1369 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1295 }
1370 }
1296 }
1371 }
1297
1372
1298 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1373 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1299 {
1374 {
1300 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1375 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1301 {
1376 {
1302 // destination
1377 // destination
1303 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 ];
1378 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 ];
1304 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 + 1 ];
1379 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 + 1 ];
1305 // source
1380 // source
1306 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1381 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1307 // copy source to destination
1382 // copy source to destination
1308 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1383 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1309 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1384 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1310 }
1385 }
1311 }
1386 }
1312
1387
1313 // print_k_coeff();
1388 // print_k_coeff();
1314
1389
1315 return status;
1390 return status;
1316 }
1391 }
1317
1392
1318 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1393 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1319 {
1394 {
1320 destination[0] = source[0];
1395 destination[0] = source[0];
1321 destination[1] = source[1];
1396 destination[1] = source[1];
1322 destination[2] = source[2];
1397 destination[2] = source[2];
1323 destination[3] = source[3];
1398 destination[3] = source[3];
1324 }
1399 }
1325
1400
1326 void floatToChar( float value, unsigned char* ptr)
1401 void floatToChar( float value, unsigned char* ptr)
1327 {
1402 {
1328 unsigned char* valuePtr;
1403 unsigned char* valuePtr;
1329
1404
1330 valuePtr = (unsigned char*) &value;
1405 valuePtr = (unsigned char*) &value;
1331 ptr[0] = valuePtr[0];
1406 ptr[0] = valuePtr[0];
1332 ptr[1] = valuePtr[0];
1407 ptr[1] = valuePtr[0];
1333 ptr[2] = valuePtr[0];
1408 ptr[2] = valuePtr[0];
1334 ptr[3] = valuePtr[0];
1409 ptr[3] = valuePtr[0];
1335 }
1410 }
1336
1411
1337 //**********
1412 //**********
1338 // init dump
1413 // init dump
1339
1414
1340 void init_parameter_dump( void )
1415 void init_parameter_dump( void )
1341 {
1416 {
1342 /** This function initialize the parameter_dump_packet global variable with default values.
1417 /** This function initialize the parameter_dump_packet global variable with default values.
1343 *
1418 *
1344 */
1419 */
1345
1420
1346 unsigned int k;
1421 unsigned int k;
1347
1422
1348 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1423 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1349 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1424 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1350 parameter_dump_packet.reserved = CCSDS_RESERVED;
1425 parameter_dump_packet.reserved = CCSDS_RESERVED;
1351 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1426 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1352 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);
1427 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);
1353 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1428 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1354 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1429 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1355 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1430 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1356 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
1431 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
1357 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1432 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1358 // DATA FIELD HEADER
1433 // DATA FIELD HEADER
1359 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1434 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1360 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1435 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1361 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1436 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1362 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1437 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1363 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
1438 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
1364 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
1439 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
1365 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
1440 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
1366 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
1441 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
1367 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
1442 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
1368 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
1443 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
1369 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1444 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1370
1445
1371 //******************
1446 //******************
1372 // COMMON PARAMETERS
1447 // COMMON PARAMETERS
1373 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1448 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1374 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1449 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1375
1450
1376 //******************
1451 //******************
1377 // NORMAL PARAMETERS
1452 // NORMAL PARAMETERS
1378 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8);
1453 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8);
1379 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1454 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1380 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8);
1455 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8);
1381 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1456 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1382 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8);
1457 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8);
1383 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1458 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1384 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1459 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1385 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1460 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1386 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1461 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1387
1462
1388 //*****************
1463 //*****************
1389 // BURST PARAMETERS
1464 // BURST PARAMETERS
1390 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1465 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1391 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1466 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1392
1467
1393 //****************
1468 //****************
1394 // SBM1 PARAMETERS
1469 // SBM1 PARAMETERS
1395 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
1470 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
1396 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1471 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1397
1472
1398 //****************
1473 //****************
1399 // SBM2 PARAMETERS
1474 // SBM2 PARAMETERS
1400 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1475 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1401 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1476 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1402
1477
1403 //************
1478 //************
1404 // FBINS MASKS
1479 // FBINS MASKS
1405 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1480 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1406 {
1481 {
1407 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = 0xff;
1482 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = 0xff;
1408 }
1483 }
1409
1484
1410 // PAS FILTER PARAMETERS
1485 // PAS FILTER PARAMETERS
1411 parameter_dump_packet.pa_rpw_spare8_2 = 0x00;
1486 parameter_dump_packet.pa_rpw_spare8_2 = 0x00;
1412 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = 0x00;
1487 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = 0x00;
1413 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1488 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1414 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1489 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1415 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1490 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1416 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1491 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1417 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1492 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1418
1493
1419 // LFR_RW_MASK
1494 // LFR_RW_MASK
1420 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1495 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1421 {
1496 {
1422 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = 0xff;
1497 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = 0xff;
1423 }
1498 }
1424 }
1499 }
1425
1500
1426 void init_kcoefficients_dump( void )
1501 void init_kcoefficients_dump( void )
1427 {
1502 {
1428 init_kcoefficients_dump_packet( &kcoefficients_dump_1, 1, 30 );
1503 init_kcoefficients_dump_packet( &kcoefficients_dump_1, 1, 30 );
1429 init_kcoefficients_dump_packet( &kcoefficients_dump_2, 2, 6 );
1504 init_kcoefficients_dump_packet( &kcoefficients_dump_2, 2, 6 );
1430
1505
1431 kcoefficient_node_1.previous = NULL;
1506 kcoefficient_node_1.previous = NULL;
1432 kcoefficient_node_1.next = NULL;
1507 kcoefficient_node_1.next = NULL;
1433 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1508 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1434 kcoefficient_node_1.coarseTime = 0x00;
1509 kcoefficient_node_1.coarseTime = 0x00;
1435 kcoefficient_node_1.fineTime = 0x00;
1510 kcoefficient_node_1.fineTime = 0x00;
1436 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1511 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1437 kcoefficient_node_1.status = 0x00;
1512 kcoefficient_node_1.status = 0x00;
1438
1513
1439 kcoefficient_node_2.previous = NULL;
1514 kcoefficient_node_2.previous = NULL;
1440 kcoefficient_node_2.next = NULL;
1515 kcoefficient_node_2.next = NULL;
1441 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1516 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1442 kcoefficient_node_2.coarseTime = 0x00;
1517 kcoefficient_node_2.coarseTime = 0x00;
1443 kcoefficient_node_2.fineTime = 0x00;
1518 kcoefficient_node_2.fineTime = 0x00;
1444 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1519 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1445 kcoefficient_node_2.status = 0x00;
1520 kcoefficient_node_2.status = 0x00;
1446 }
1521 }
1447
1522
1448 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1523 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1449 {
1524 {
1450 unsigned int k;
1525 unsigned int k;
1451 unsigned int packetLength;
1526 unsigned int packetLength;
1452
1527
1453 packetLength = blk_nr * 130 + 20 - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1528 packetLength = blk_nr * 130 + 20 - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1454
1529
1455 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1530 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1456 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1531 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1457 kcoefficients_dump->reserved = CCSDS_RESERVED;
1532 kcoefficients_dump->reserved = CCSDS_RESERVED;
1458 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1533 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1459 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);;
1534 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);;
1460 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;;
1535 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;;
1461 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1536 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1462 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1537 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1463 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> 8);
1538 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> 8);
1464 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1539 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1465 // DATA FIELD HEADER
1540 // DATA FIELD HEADER
1466 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1541 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1467 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1542 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1468 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1543 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1469 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1544 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1470 kcoefficients_dump->time[0] = 0x00;
1545 kcoefficients_dump->time[0] = 0x00;
1471 kcoefficients_dump->time[1] = 0x00;
1546 kcoefficients_dump->time[1] = 0x00;
1472 kcoefficients_dump->time[2] = 0x00;
1547 kcoefficients_dump->time[2] = 0x00;
1473 kcoefficients_dump->time[3] = 0x00;
1548 kcoefficients_dump->time[3] = 0x00;
1474 kcoefficients_dump->time[4] = 0x00;
1549 kcoefficients_dump->time[4] = 0x00;
1475 kcoefficients_dump->time[5] = 0x00;
1550 kcoefficients_dump->time[5] = 0x00;
1476 kcoefficients_dump->sid = SID_K_DUMP;
1551 kcoefficients_dump->sid = SID_K_DUMP;
1477
1552
1478 kcoefficients_dump->pkt_cnt = 2;
1553 kcoefficients_dump->pkt_cnt = 2;
1479 kcoefficients_dump->pkt_nr = pkt_nr;
1554 kcoefficients_dump->pkt_nr = pkt_nr;
1480 kcoefficients_dump->blk_nr = blk_nr;
1555 kcoefficients_dump->blk_nr = blk_nr;
1481
1556
1482 //******************
1557 //******************
1483 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1558 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1484 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1559 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1485 for (k=0; k<3900; k++)
1560 for (k=0; k<3900; k++)
1486 {
1561 {
1487 kcoefficients_dump->kcoeff_blks[k] = 0x00;
1562 kcoefficients_dump->kcoeff_blks[k] = 0x00;
1488 }
1563 }
1489 }
1564 }
1490
1565
1491 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1566 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1492 {
1567 {
1493 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1568 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1494 *
1569 *
1495 * @param packet_sequence_control points to the packet sequence control which will be incremented
1570 * @param packet_sequence_control points to the packet sequence control which will be incremented
1496 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1571 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1497 *
1572 *
1498 * If the destination ID is not known, a dedicated counter is incremented.
1573 * If the destination ID is not known, a dedicated counter is incremented.
1499 *
1574 *
1500 */
1575 */
1501
1576
1502 unsigned short sequence_cnt;
1577 unsigned short sequence_cnt;
1503 unsigned short segmentation_grouping_flag;
1578 unsigned short segmentation_grouping_flag;
1504 unsigned short new_packet_sequence_control;
1579 unsigned short new_packet_sequence_control;
1505 unsigned char i;
1580 unsigned char i;
1506
1581
1507 switch (destination_id)
1582 switch (destination_id)
1508 {
1583 {
1509 case SID_TC_GROUND:
1584 case SID_TC_GROUND:
1510 i = GROUND;
1585 i = GROUND;
1511 break;
1586 break;
1512 case SID_TC_MISSION_TIMELINE:
1587 case SID_TC_MISSION_TIMELINE:
1513 i = MISSION_TIMELINE;
1588 i = MISSION_TIMELINE;
1514 break;
1589 break;
1515 case SID_TC_TC_SEQUENCES:
1590 case SID_TC_TC_SEQUENCES:
1516 i = TC_SEQUENCES;
1591 i = TC_SEQUENCES;
1517 break;
1592 break;
1518 case SID_TC_RECOVERY_ACTION_CMD:
1593 case SID_TC_RECOVERY_ACTION_CMD:
1519 i = RECOVERY_ACTION_CMD;
1594 i = RECOVERY_ACTION_CMD;
1520 break;
1595 break;
1521 case SID_TC_BACKUP_MISSION_TIMELINE:
1596 case SID_TC_BACKUP_MISSION_TIMELINE:
1522 i = BACKUP_MISSION_TIMELINE;
1597 i = BACKUP_MISSION_TIMELINE;
1523 break;
1598 break;
1524 case SID_TC_DIRECT_CMD:
1599 case SID_TC_DIRECT_CMD:
1525 i = DIRECT_CMD;
1600 i = DIRECT_CMD;
1526 break;
1601 break;
1527 case SID_TC_SPARE_GRD_SRC1:
1602 case SID_TC_SPARE_GRD_SRC1:
1528 i = SPARE_GRD_SRC1;
1603 i = SPARE_GRD_SRC1;
1529 break;
1604 break;
1530 case SID_TC_SPARE_GRD_SRC2:
1605 case SID_TC_SPARE_GRD_SRC2:
1531 i = SPARE_GRD_SRC2;
1606 i = SPARE_GRD_SRC2;
1532 break;
1607 break;
1533 case SID_TC_OBCP:
1608 case SID_TC_OBCP:
1534 i = OBCP;
1609 i = OBCP;
1535 break;
1610 break;
1536 case SID_TC_SYSTEM_CONTROL:
1611 case SID_TC_SYSTEM_CONTROL:
1537 i = SYSTEM_CONTROL;
1612 i = SYSTEM_CONTROL;
1538 break;
1613 break;
1539 case SID_TC_AOCS:
1614 case SID_TC_AOCS:
1540 i = AOCS;
1615 i = AOCS;
1541 break;
1616 break;
1542 case SID_TC_RPW_INTERNAL:
1617 case SID_TC_RPW_INTERNAL:
1543 i = RPW_INTERNAL;
1618 i = RPW_INTERNAL;
1544 break;
1619 break;
1545 default:
1620 default:
1546 i = GROUND;
1621 i = GROUND;
1547 break;
1622 break;
1548 }
1623 }
1549
1624
1550 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1625 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1551 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & 0x3fff;
1626 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & 0x3fff;
1552
1627
1553 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1628 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1554
1629
1555 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1630 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1556 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1631 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1557
1632
1558 // increment the sequence counter
1633 // increment the sequence counter
1559 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1634 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1560 {
1635 {
1561 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1636 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1562 }
1637 }
1563 else
1638 else
1564 {
1639 {
1565 sequenceCounters_TM_DUMP[ i ] = 0;
1640 sequenceCounters_TM_DUMP[ i ] = 0;
1566 }
1641 }
1567 }
1642 }
General Comments 0
You need to be logged in to leave comments. Login now