@@ -1,112 +1,112 | |||
|
1 | 1 | cmake_minimum_required (VERSION 2.6) |
|
2 | 2 | project (fsw) |
|
3 | 3 | |
|
4 | 4 | include(sparc-rtems) |
|
5 | 5 | include(cppcheck) |
|
6 | 6 | |
|
7 | 7 | include_directories("../header" |
|
8 | 8 | "../header/lfr_common_headers" |
|
9 | 9 | "../header/processing" |
|
10 | 10 | "../LFR_basic-parameters" |
|
11 | 11 | "../src") |
|
12 | 12 | |
|
13 | 13 | set(SOURCES wf_handler.c |
|
14 | 14 | tc_handler.c |
|
15 | 15 | fsw_misc.c |
|
16 | 16 | fsw_init.c |
|
17 | 17 | fsw_globals.c |
|
18 | 18 | fsw_spacewire.c |
|
19 | 19 | tc_load_dump_parameters.c |
|
20 | 20 | tm_lfr_tc_exe.c |
|
21 | 21 | tc_acceptance.c |
|
22 | 22 | processing/fsw_processing.c |
|
23 | 23 | processing/avf0_prc0.c |
|
24 | 24 | processing/avf1_prc1.c |
|
25 | 25 | processing/avf2_prc2.c |
|
26 | 26 | lfr_cpu_usage_report.c |
|
27 | 27 | ${LFR_BP_SRC} |
|
28 | 28 | ../header/wf_handler.h |
|
29 | 29 | ../header/tc_handler.h |
|
30 | 30 | ../header/grlib_regs.h |
|
31 | 31 | ../header/fsw_misc.h |
|
32 | 32 | ../header/fsw_init.h |
|
33 | 33 | ../header/fsw_spacewire.h |
|
34 | 34 | ../header/tc_load_dump_parameters.h |
|
35 | 35 | ../header/tm_lfr_tc_exe.h |
|
36 | 36 | ../header/tc_acceptance.h |
|
37 | 37 | ../header/processing/fsw_processing.h |
|
38 | 38 | ../header/processing/avf0_prc0.h |
|
39 | 39 | ../header/processing/avf1_prc1.h |
|
40 | 40 | ../header/processing/avf2_prc2.h |
|
41 | 41 | ../header/fsw_params_wf_handler.h |
|
42 | 42 | ../header/lfr_cpu_usage_report.h |
|
43 | 43 | ../header/lfr_common_headers/ccsds_types.h |
|
44 | 44 | ../header/lfr_common_headers/fsw_params.h |
|
45 | 45 | ../header/lfr_common_headers/fsw_params_nb_bytes.h |
|
46 | 46 | ../header/lfr_common_headers/fsw_params_processing.h |
|
47 | 47 | ../header/lfr_common_headers/tm_byte_positions.h |
|
48 | 48 | ../LFR_basic-parameters/basic_parameters.h |
|
49 | 49 | ../LFR_basic-parameters/basic_parameters_params.h |
|
50 | 50 | ../header/GscMemoryLPP.hpp |
|
51 | 51 | ) |
|
52 | 52 | |
|
53 | 53 | |
|
54 | 54 | option(FSW_verbose "Enable verbose LFR" OFF) |
|
55 | 55 | option(FSW_boot_messages "Enable LFR boot messages" OFF) |
|
56 | 56 | option(FSW_debug_messages "Enable LFR debug messages" OFF) |
|
57 | 57 | option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF) |
|
58 | 58 | option(FSW_stack_report "Enable LFR stack report" OFF) |
|
59 | 59 | option(FSW_vhdl_dev "?" OFF) |
|
60 | 60 | option(FSW_lpp_dpu_destid "Set to debug at LPP" OFF) |
|
61 | 61 | option(FSW_debug_watchdog "Enable debug watchdog" OFF) |
|
62 | 62 | option(FSW_debug_tch "?" OFF) |
|
63 | 63 | |
|
64 | 64 | set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE) |
|
65 | 65 | set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE) |
|
66 | 66 | set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE) |
|
67 |
set(SW_VERSION_N4 "1 |
|
|
67 | set(SW_VERSION_N4 "16" CACHE STRING "Choose N4 FSW Version." FORCE) | |
|
68 | 68 | |
|
69 | 69 | if(FSW_verbose) |
|
70 | 70 | add_definitions(-DPRINT_MESSAGES_ON_CONSOLE) |
|
71 | 71 | endif() |
|
72 | 72 | if(FSW_boot_messages) |
|
73 | 73 | add_definitions(-DBOOT_MESSAGES) |
|
74 | 74 | endif() |
|
75 | 75 | if(FSW_debug_messages) |
|
76 | 76 | add_definitions(-DDEBUG_MESSAGES) |
|
77 | 77 | endif() |
|
78 | 78 | if(FSW_cpu_usage_report) |
|
79 | 79 | add_definitions(-DPRINT_TASK_STATISTICS) |
|
80 | 80 | endif() |
|
81 | 81 | if(FSW_stack_report) |
|
82 | 82 | add_definitions(-DPRINT_STACK_REPORT) |
|
83 | 83 | endif() |
|
84 | 84 | if(FSW_vhdl_dev) |
|
85 | 85 | add_definitions(-DVHDL_DEV) |
|
86 | 86 | endif() |
|
87 | 87 | if(FSW_lpp_dpu_destid) |
|
88 | 88 | add_definitions(-DLPP_DPU_DESTID) |
|
89 | 89 | endif() |
|
90 | 90 | if(FSW_debug_watchdog) |
|
91 | 91 | add_definitions(-DDEBUG_WATCHDOG) |
|
92 | 92 | endif() |
|
93 | 93 | if(FSW_debug_tch) |
|
94 | 94 | add_definitions(-DDEBUG_TCH) |
|
95 | 95 | endif() |
|
96 | 96 | |
|
97 | 97 | add_definitions(-DMSB_FIRST_TCH) |
|
98 | 98 | |
|
99 | 99 | add_definitions(-DSWVERSION=-1-0) |
|
100 | 100 | add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1}) |
|
101 | 101 | add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2}) |
|
102 | 102 | add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3}) |
|
103 | 103 | add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4}) |
|
104 | 104 | |
|
105 | 105 | add_executable(fsw ${SOURCES}) |
|
106 | 106 | |
|
107 | 107 | if(fix-b2bst) |
|
108 | 108 | check_b2bst(fsw ${CMAKE_CURRENT_BINARY_DIR}) |
|
109 | 109 | endif() |
|
110 | 110 | |
|
111 | 111 | add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE) |
|
112 | 112 |
@@ -1,514 +1,512 | |||
|
1 | 1 | /** Functions to send TM packets related to TC parsing and execution. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * A group of functions to send appropriate TM packets after parsing and execution: |
|
7 | 7 | * - TM_LFR_TC_EXE_SUCCESS |
|
8 | 8 | * - TM_LFR_TC_EXE_INCONSISTENT |
|
9 | 9 | * - TM_LFR_TC_EXE_NOT_EXECUTABLE |
|
10 | 10 | * - TM_LFR_TC_EXE_NOT_IMPLEMENTED |
|
11 | 11 | * - TM_LFR_TC_EXE_ERROR |
|
12 | 12 | * - TM_LFR_TC_EXE_CORRUPTED |
|
13 | 13 | * |
|
14 | 14 | */ |
|
15 | 15 | |
|
16 | 16 | #include "tm_lfr_tc_exe.h" |
|
17 | 17 | |
|
18 | 18 | int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
19 | 19 | { |
|
20 | 20 | /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue. |
|
21 | 21 | * |
|
22 | 22 | * @param TC points to the TeleCommand packet that is being processed |
|
23 | 23 | * @param queue_id is the id of the queue which handles TM |
|
24 | 24 | * |
|
25 | 25 | * @return RTEMS directive status code: |
|
26 | 26 | * - RTEMS_SUCCESSFUL - message sent successfully |
|
27 | 27 | * - RTEMS_INVALID_ID - invalid queue id |
|
28 | 28 | * - RTEMS_INVALID_SIZE - invalid message size |
|
29 | 29 | * - RTEMS_INVALID_ADDRESS - buffer is NULL |
|
30 | 30 | * - RTEMS_UNSATISFIED - out of message buffers |
|
31 | 31 | * - RTEMS_TOO_MANY - queue s limit has been reached |
|
32 | 32 | * |
|
33 | 33 | */ |
|
34 | 34 | |
|
35 | 35 | rtems_status_code status; |
|
36 | 36 | Packet_TM_LFR_TC_EXE_SUCCESS_t TM; |
|
37 | 37 | unsigned char messageSize; |
|
38 | 38 | |
|
39 | 39 | TM.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
40 | 40 | TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
41 | 41 | TM.reserved = DEFAULT_RESERVED; |
|
42 | 42 | TM.userApplication = CCSDS_USER_APP; |
|
43 | 43 | // PACKET HEADER |
|
44 | 44 | TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE); |
|
45 | 45 | TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); |
|
46 | 46 | increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); |
|
47 | 47 | TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> SHIFT_1_BYTE); |
|
48 | 48 | TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS ); |
|
49 | 49 | // DATA FIELD HEADER |
|
50 | 50 | TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
51 | 51 | TM.serviceType = TM_TYPE_TC_EXE; |
|
52 | 52 | TM.serviceSubType = TM_SUBTYPE_EXE_OK; |
|
53 | 53 | TM.destinationID = TC->sourceID; |
|
54 | 54 | TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
55 | 55 | TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
56 | 56 | TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
57 | 57 | TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
58 | 58 | TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
59 | 59 | TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
60 | 60 | // |
|
61 | 61 | TM.telecommand_pkt_id[0] = TC->packetID[0]; |
|
62 | 62 | TM.telecommand_pkt_id[1] = TC->packetID[1]; |
|
63 | 63 | TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; |
|
64 | 64 | TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; |
|
65 | 65 | |
|
66 | 66 | messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; |
|
67 | 67 | |
|
68 | 68 | // SEND DATA |
|
69 | 69 | status = rtems_message_queue_send( queue_id, &TM, messageSize); |
|
70 | 70 | if (status != RTEMS_SUCCESSFUL) { |
|
71 | 71 | PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n") |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | 74 | // UPDATE HK FIELDS |
|
75 | 75 | update_last_TC_exe( TC, TM.time ); |
|
76 | 76 | |
|
77 | 77 | return status; |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, |
|
81 | 81 | unsigned char byte_position, unsigned char rcv_value ) |
|
82 | 82 | { |
|
83 | 83 | /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue. |
|
84 | 84 | * |
|
85 | 85 | * @param TC points to the TeleCommand packet that is being processed |
|
86 | 86 | * @param queue_id is the id of the queue which handles TM |
|
87 | 87 | * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent |
|
88 | 88 | * @param rcv_value is the value of the LSB of the parameter that has been detected as inconsistent |
|
89 | 89 | * |
|
90 | 90 | * @return RTEMS directive status code: |
|
91 | 91 | * - RTEMS_SUCCESSFUL - message sent successfully |
|
92 | 92 | * - RTEMS_INVALID_ID - invalid queue id |
|
93 | 93 | * - RTEMS_INVALID_SIZE - invalid message size |
|
94 | 94 | * - RTEMS_INVALID_ADDRESS - buffer is NULL |
|
95 | 95 | * - RTEMS_UNSATISFIED - out of message buffers |
|
96 | 96 | * - RTEMS_TOO_MANY - queue s limit has been reached |
|
97 | 97 | * |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | rtems_status_code status; |
|
101 | 101 | Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM; |
|
102 | 102 | unsigned char messageSize; |
|
103 | 103 | |
|
104 | 104 | TM.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
105 | 105 | TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
106 | 106 | TM.reserved = DEFAULT_RESERVED; |
|
107 | 107 | TM.userApplication = CCSDS_USER_APP; |
|
108 | 108 | // PACKET HEADER |
|
109 | 109 | TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE); |
|
110 | 110 | TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); |
|
111 | 111 | increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); |
|
112 | 112 | TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> SHIFT_1_BYTE); |
|
113 | 113 | TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT ); |
|
114 | 114 | // DATA FIELD HEADER |
|
115 | 115 | TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
116 | 116 | TM.serviceType = TM_TYPE_TC_EXE; |
|
117 | 117 | TM.serviceSubType = TM_SUBTYPE_EXE_NOK; |
|
118 | 118 | TM.destinationID = TC->sourceID; |
|
119 | 119 | TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
120 | 120 | TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
121 | 121 | TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
122 | 122 | TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
123 | 123 | TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
124 | 124 | TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
125 | 125 | // |
|
126 | 126 | TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> SHIFT_1_BYTE); |
|
127 | 127 | TM.tc_failure_code[1] = (char) (WRONG_APP_DATA ); |
|
128 | 128 | TM.telecommand_pkt_id[0] = TC->packetID[0]; |
|
129 | 129 | TM.telecommand_pkt_id[1] = TC->packetID[1]; |
|
130 | 130 | TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; |
|
131 | 131 | TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; |
|
132 | 132 | TM.tc_service = TC->serviceType; // type of the rejected TC |
|
133 | 133 | TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC |
|
134 | 134 | TM.byte_position = byte_position; |
|
135 | 135 | TM.rcv_value = (unsigned char) rcv_value; |
|
136 | 136 | |
|
137 | 137 | messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; |
|
138 | 138 | |
|
139 | 139 | // SEND DATA |
|
140 | 140 | status = rtems_message_queue_send( queue_id, &TM, messageSize); |
|
141 | 141 | if (status != RTEMS_SUCCESSFUL) { |
|
142 | 142 | PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n") |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | // UPDATE HK FIELDS |
|
146 | 146 | update_last_TC_rej( TC, TM.time ); |
|
147 | 147 | |
|
148 | 148 | return status; |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
152 | 152 | { |
|
153 | 153 | /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue. |
|
154 | 154 | * |
|
155 | 155 | * @param TC points to the TeleCommand packet that is being processed |
|
156 | 156 | * @param queue_id is the id of the queue which handles TM |
|
157 | 157 | * |
|
158 | 158 | * @return RTEMS directive status code: |
|
159 | 159 | * - RTEMS_SUCCESSFUL - message sent successfully |
|
160 | 160 | * - RTEMS_INVALID_ID - invalid queue id |
|
161 | 161 | * - RTEMS_INVALID_SIZE - invalid message size |
|
162 | 162 | * - RTEMS_INVALID_ADDRESS - buffer is NULL |
|
163 | 163 | * - RTEMS_UNSATISFIED - out of message buffers |
|
164 | 164 | * - RTEMS_TOO_MANY - queue s limit has been reached |
|
165 | 165 | * |
|
166 | 166 | */ |
|
167 | 167 | |
|
168 | 168 | rtems_status_code status; |
|
169 | 169 | Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM; |
|
170 | 170 | unsigned char messageSize; |
|
171 | 171 | |
|
172 | 172 | TM.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
173 | 173 | TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
174 | 174 | TM.reserved = DEFAULT_RESERVED; |
|
175 | 175 | TM.userApplication = CCSDS_USER_APP; |
|
176 | 176 | // PACKET HEADER |
|
177 | 177 | TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE); |
|
178 | 178 | TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); |
|
179 | 179 | increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); |
|
180 | 180 | TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> SHIFT_1_BYTE); |
|
181 | 181 | TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE ); |
|
182 | 182 | // DATA FIELD HEADER |
|
183 | 183 | TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
184 | 184 | TM.serviceType = TM_TYPE_TC_EXE; |
|
185 | 185 | TM.serviceSubType = TM_SUBTYPE_EXE_NOK; |
|
186 | 186 | TM.destinationID = TC->sourceID; // default destination id |
|
187 | 187 | TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
188 | 188 | TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
189 | 189 | TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
190 | 190 | TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
191 | 191 | TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
192 | 192 | TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
193 | 193 | // |
|
194 | 194 | TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> SHIFT_1_BYTE); |
|
195 | 195 | TM.tc_failure_code[1] = (char) (TC_NOT_EXE ); |
|
196 | 196 | TM.telecommand_pkt_id[0] = TC->packetID[0]; |
|
197 | 197 | TM.telecommand_pkt_id[1] = TC->packetID[1]; |
|
198 | 198 | TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; |
|
199 | 199 | TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; |
|
200 | 200 | TM.tc_service = TC->serviceType; // type of the rejected TC |
|
201 | 201 | TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC |
|
202 | 202 | TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0]; |
|
203 | 203 | TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]; |
|
204 | 204 | |
|
205 | 205 | messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; |
|
206 | 206 | |
|
207 | 207 | // SEND DATA |
|
208 | 208 | status = rtems_message_queue_send( queue_id, &TM, messageSize); |
|
209 | 209 | if (status != RTEMS_SUCCESSFUL) { |
|
210 | 210 | PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n") |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | // UPDATE HK FIELDS |
|
214 | 214 | update_last_TC_rej( TC, TM.time ); |
|
215 | 215 | |
|
216 | 216 | return status; |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ) |
|
220 | 220 | { |
|
221 | 221 | /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue. |
|
222 | 222 | * |
|
223 | 223 | * @param TC points to the TeleCommand packet that is being processed |
|
224 | 224 | * @param queue_id is the id of the queue which handles TM |
|
225 | 225 | * |
|
226 | 226 | * @return RTEMS directive status code: |
|
227 | 227 | * - RTEMS_SUCCESSFUL - message sent successfully |
|
228 | 228 | * - RTEMS_INVALID_ID - invalid queue id |
|
229 | 229 | * - RTEMS_INVALID_SIZE - invalid message size |
|
230 | 230 | * - RTEMS_INVALID_ADDRESS - buffer is NULL |
|
231 | 231 | * - RTEMS_UNSATISFIED - out of message buffers |
|
232 | 232 | * - RTEMS_TOO_MANY - queue s limit has been reached |
|
233 | 233 | * |
|
234 | 234 | */ |
|
235 | 235 | |
|
236 | 236 | rtems_status_code status; |
|
237 | 237 | Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM; |
|
238 | 238 | unsigned char messageSize; |
|
239 | 239 | |
|
240 | 240 | TM.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
241 | 241 | TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
242 | 242 | TM.reserved = DEFAULT_RESERVED; |
|
243 | 243 | TM.userApplication = CCSDS_USER_APP; |
|
244 | 244 | // PACKET HEADER |
|
245 | 245 | TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE); |
|
246 | 246 | TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); |
|
247 | 247 | increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); |
|
248 | 248 | TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> SHIFT_1_BYTE); |
|
249 | 249 | TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED ); |
|
250 | 250 | // DATA FIELD HEADER |
|
251 | 251 | TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
252 | 252 | TM.serviceType = TM_TYPE_TC_EXE; |
|
253 | 253 | TM.serviceSubType = TM_SUBTYPE_EXE_NOK; |
|
254 | 254 | TM.destinationID = TC->sourceID; // default destination id |
|
255 | 255 | TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
256 | 256 | TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
257 | 257 | TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
258 | 258 | TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
259 | 259 | TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
260 | 260 | TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
261 | 261 | // |
|
262 | 262 | TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> SHIFT_1_BYTE); |
|
263 | 263 | TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL ); |
|
264 | 264 | TM.telecommand_pkt_id[0] = TC->packetID[0]; |
|
265 | 265 | TM.telecommand_pkt_id[1] = TC->packetID[1]; |
|
266 | 266 | TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; |
|
267 | 267 | TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; |
|
268 | 268 | TM.tc_service = TC->serviceType; // type of the rejected TC |
|
269 | 269 | TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC |
|
270 | 270 | |
|
271 | 271 | messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; |
|
272 | 272 | |
|
273 | 273 | // SEND DATA |
|
274 | 274 | status = rtems_message_queue_send( queue_id, &TM, messageSize); |
|
275 | 275 | if (status != RTEMS_SUCCESSFUL) { |
|
276 | 276 | PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n") |
|
277 | 277 | } |
|
278 | 278 | |
|
279 | 279 | // UPDATE HK FIELDS |
|
280 | 280 | update_last_TC_rej( TC, TM.time ); |
|
281 | 281 | |
|
282 | 282 | return status; |
|
283 | 283 | } |
|
284 | 284 | |
|
285 | 285 | int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
286 | 286 | { |
|
287 | 287 | /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue. |
|
288 | 288 | * |
|
289 | 289 | * @param TC points to the TeleCommand packet that is being processed |
|
290 | 290 | * @param queue_id is the id of the queue which handles TM |
|
291 | 291 | * |
|
292 | 292 | * @return RTEMS directive status code: |
|
293 | 293 | * - RTEMS_SUCCESSFUL - message sent successfully |
|
294 | 294 | * - RTEMS_INVALID_ID - invalid queue id |
|
295 | 295 | * - RTEMS_INVALID_SIZE - invalid message size |
|
296 | 296 | * - RTEMS_INVALID_ADDRESS - buffer is NULL |
|
297 | 297 | * - RTEMS_UNSATISFIED - out of message buffers |
|
298 | 298 | * - RTEMS_TOO_MANY - queue s limit has been reached |
|
299 | 299 | * |
|
300 | 300 | */ |
|
301 | 301 | |
|
302 | 302 | rtems_status_code status; |
|
303 | 303 | Packet_TM_LFR_TC_EXE_ERROR_t TM; |
|
304 | 304 | unsigned char messageSize; |
|
305 | 305 | |
|
306 | 306 | TM.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
307 | 307 | TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
308 | 308 | TM.reserved = DEFAULT_RESERVED; |
|
309 | 309 | TM.userApplication = CCSDS_USER_APP; |
|
310 | 310 | // PACKET HEADER |
|
311 | 311 | TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE); |
|
312 | 312 | TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); |
|
313 | 313 | increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); |
|
314 | 314 | TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> SHIFT_1_BYTE); |
|
315 | 315 | TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR ); |
|
316 | 316 | // DATA FIELD HEADER |
|
317 | 317 | TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
318 | 318 | TM.serviceType = TM_TYPE_TC_EXE; |
|
319 | 319 | TM.serviceSubType = TM_SUBTYPE_EXE_NOK; |
|
320 | 320 | TM.destinationID = TC->sourceID; // default destination id |
|
321 | 321 | TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
322 | 322 | TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
323 | 323 | TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
324 | 324 | TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
325 | 325 | TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
326 | 326 | TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
327 | 327 | // |
|
328 | 328 | TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> SHIFT_1_BYTE); |
|
329 | 329 | TM.tc_failure_code[1] = (char) (FAIL_DETECTED ); |
|
330 | 330 | TM.telecommand_pkt_id[0] = TC->packetID[0]; |
|
331 | 331 | TM.telecommand_pkt_id[1] = TC->packetID[1]; |
|
332 | 332 | TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; |
|
333 | 333 | TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; |
|
334 | 334 | TM.tc_service = TC->serviceType; // type of the rejected TC |
|
335 | 335 | TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC |
|
336 | 336 | |
|
337 | 337 | messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; |
|
338 | 338 | |
|
339 | 339 | // SEND DATA |
|
340 | 340 | status = rtems_message_queue_send( queue_id, &TM, messageSize); |
|
341 | 341 | if (status != RTEMS_SUCCESSFUL) { |
|
342 | 342 | PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n") |
|
343 | 343 | } |
|
344 | 344 | |
|
345 | 345 | // UPDATE HK FIELDS |
|
346 | 346 | update_last_TC_rej( TC, TM.time ); |
|
347 | 347 | |
|
348 | 348 | return status; |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, |
|
352 | 352 | unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV, |
|
353 | 353 | unsigned char destinationID ) |
|
354 | 354 | { |
|
355 | 355 | /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue. |
|
356 | 356 | * |
|
357 | 357 | * @param TC points to the TeleCommand packet that is being processed |
|
358 | 358 | * @param queue_id is the id of the queue which handles TM |
|
359 | 359 | * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand |
|
360 | 360 | * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data |
|
361 | 361 | * |
|
362 | 362 | * @return RTEMS directive status code: |
|
363 | 363 | * - RTEMS_SUCCESSFUL - message sent successfully |
|
364 | 364 | * - RTEMS_INVALID_ID - invalid queue id |
|
365 | 365 | * - RTEMS_INVALID_SIZE - invalid message size |
|
366 | 366 | * - RTEMS_INVALID_ADDRESS - buffer is NULL |
|
367 | 367 | * - RTEMS_UNSATISFIED - out of message buffers |
|
368 | 368 | * - RTEMS_TOO_MANY - queue s limit has been reached |
|
369 | 369 | * |
|
370 | 370 | */ |
|
371 | 371 | |
|
372 | 372 | rtems_status_code status; |
|
373 | 373 | Packet_TM_LFR_TC_EXE_CORRUPTED_t TM; |
|
374 | 374 | unsigned char messageSize; |
|
375 | 375 | unsigned int packetLength; |
|
376 | 376 | unsigned int estimatedPacketLength; |
|
377 | 377 | unsigned char *packetDataField; |
|
378 | 378 | |
|
379 | 379 | packetLength = (TC->packetLength[0] * CONST_256) + TC->packetLength[1]; // compute the packet length parameter written in the TC |
|
380 | 380 | estimatedPacketLength = (unsigned int) ((currentTC_LEN_RCV[0] * CONST_256) + currentTC_LEN_RCV[1]); |
|
381 | 381 | packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field |
|
382 | 382 | |
|
383 | 383 | TM.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
384 | 384 | TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
385 | 385 | TM.reserved = DEFAULT_RESERVED; |
|
386 | 386 | TM.userApplication = CCSDS_USER_APP; |
|
387 | 387 | // PACKET HEADER |
|
388 | 388 | TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE); |
|
389 | 389 | TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); |
|
390 | 390 | increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); |
|
391 | 391 | TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> SHIFT_1_BYTE); |
|
392 | 392 | TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED ); |
|
393 | 393 | // DATA FIELD HEADER |
|
394 | 394 | TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
395 | 395 | TM.serviceType = TM_TYPE_TC_EXE; |
|
396 | 396 | TM.serviceSubType = TM_SUBTYPE_EXE_NOK; |
|
397 | 397 | TM.destinationID = destinationID; |
|
398 | 398 | TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
399 | 399 | TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
400 | 400 | TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
401 | 401 | TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
402 | 402 | TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
403 | 403 | TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
404 | 404 | // |
|
405 | 405 | TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> SHIFT_1_BYTE); |
|
406 | 406 | TM.tc_failure_code[1] = (unsigned char) (CORRUPTED ); |
|
407 | 407 | TM.telecommand_pkt_id[0] = TC->packetID[0]; |
|
408 | 408 | TM.telecommand_pkt_id[1] = TC->packetID[1]; |
|
409 | 409 | TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; |
|
410 | 410 | TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; |
|
411 | 411 | TM.tc_service = TC->serviceType; // type of the rejected TC |
|
412 | 412 | TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC |
|
413 | 413 | TM.pkt_len_rcv_value[0] = TC->packetLength[0]; |
|
414 | 414 | TM.pkt_len_rcv_value[1] = TC->packetLength[1]; |
|
415 | 415 | TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0]; |
|
416 | 416 | TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1]; |
|
417 | // TM.rcv_crc[0] = packetDataField[ packetLength - 1 ]; | |
|
418 | // TM.rcv_crc[1] = packetDataField[ packetLength ]; | |
|
419 | 417 | TM.rcv_crc[0] = packetDataField[ estimatedPacketLength - 1 ]; |
|
420 | 418 | TM.rcv_crc[1] = packetDataField[ estimatedPacketLength ]; |
|
421 | 419 | TM.computed_crc[0] = computed_CRC[0]; |
|
422 | 420 | TM.computed_crc[1] = computed_CRC[1]; |
|
423 | 421 | |
|
424 | 422 | messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; |
|
425 | 423 | |
|
426 | 424 | // SEND DATA |
|
427 | 425 | status = rtems_message_queue_send( queue_id, &TM, messageSize); |
|
428 | 426 | if (status != RTEMS_SUCCESSFUL) { |
|
429 | 427 | PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n") |
|
430 | 428 | } |
|
431 | 429 | |
|
432 | 430 | // UPDATE HK FIELDS |
|
433 | 431 | update_last_TC_rej( TC, TM.time ); |
|
434 | 432 | |
|
435 | 433 | return status; |
|
436 | 434 | } |
|
437 | 435 | |
|
438 | 436 | void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id ) |
|
439 | 437 | { |
|
440 | 438 | /** This function increment the packet sequence control parameter of a TC, depending on its destination ID. |
|
441 | 439 | * |
|
442 | 440 | * @param packet_sequence_control points to the packet sequence control which will be incremented |
|
443 | 441 | * @param destination_id is the destination ID of the TM, there is one counter by destination ID |
|
444 | 442 | * |
|
445 | 443 | * If the destination ID is not known, a dedicated counter is incremented. |
|
446 | 444 | * |
|
447 | 445 | */ |
|
448 | 446 | |
|
449 | 447 | unsigned short sequence_cnt; |
|
450 | 448 | unsigned short segmentation_grouping_flag; |
|
451 | 449 | unsigned short new_packet_sequence_control; |
|
452 | 450 | unsigned char i; |
|
453 | 451 | |
|
454 | 452 | switch (destination_id) |
|
455 | 453 | { |
|
456 | 454 | case SID_TC_GROUND: |
|
457 | 455 | i = GROUND; |
|
458 | 456 | break; |
|
459 | 457 | case SID_TC_MISSION_TIMELINE: |
|
460 | 458 | i = MISSION_TIMELINE; |
|
461 | 459 | break; |
|
462 | 460 | case SID_TC_TC_SEQUENCES: |
|
463 | 461 | i = TC_SEQUENCES; |
|
464 | 462 | break; |
|
465 | 463 | case SID_TC_RECOVERY_ACTION_CMD: |
|
466 | 464 | i = RECOVERY_ACTION_CMD; |
|
467 | 465 | break; |
|
468 | 466 | case SID_TC_BACKUP_MISSION_TIMELINE: |
|
469 | 467 | i = BACKUP_MISSION_TIMELINE; |
|
470 | 468 | break; |
|
471 | 469 | case SID_TC_DIRECT_CMD: |
|
472 | 470 | i = DIRECT_CMD; |
|
473 | 471 | break; |
|
474 | 472 | case SID_TC_SPARE_GRD_SRC1: |
|
475 | 473 | i = SPARE_GRD_SRC1; |
|
476 | 474 | break; |
|
477 | 475 | case SID_TC_SPARE_GRD_SRC2: |
|
478 | 476 | i = SPARE_GRD_SRC2; |
|
479 | 477 | break; |
|
480 | 478 | case SID_TC_OBCP: |
|
481 | 479 | i = OBCP; |
|
482 | 480 | break; |
|
483 | 481 | case SID_TC_SYSTEM_CONTROL: |
|
484 | 482 | i = SYSTEM_CONTROL; |
|
485 | 483 | break; |
|
486 | 484 | case SID_TC_AOCS: |
|
487 | 485 | i = AOCS; |
|
488 | 486 | break; |
|
489 | 487 | case SID_TC_RPW_INTERNAL: |
|
490 | 488 | i = RPW_INTERNAL; |
|
491 | 489 | break; |
|
492 | 490 | default: |
|
493 | 491 | i = GROUND; |
|
494 | 492 | break; |
|
495 | 493 | } |
|
496 | 494 | |
|
497 | 495 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; |
|
498 | 496 | sequence_cnt = sequenceCounters_TC_EXE[ i ] & SEQ_CNT_MASK; |
|
499 | 497 | |
|
500 | 498 | new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ; |
|
501 | 499 | |
|
502 | 500 | packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE); |
|
503 | 501 | packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); |
|
504 | 502 | |
|
505 | 503 | // increment the sequence counter |
|
506 | 504 | if ( sequenceCounters_TC_EXE[ i ] < SEQ_CNT_MAX ) |
|
507 | 505 | { |
|
508 | 506 | sequenceCounters_TC_EXE[ i ] = sequenceCounters_TC_EXE[ i ] + 1; |
|
509 | 507 | } |
|
510 | 508 | else |
|
511 | 509 | { |
|
512 | 510 | sequenceCounters_TC_EXE[ i ] = 0; |
|
513 | 511 | } |
|
514 | 512 | } |
@@ -1,1344 +1,1342 | |||
|
1 | 1 | /** Functions and tasks related to waveform packet generation. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * A group of functions to handle waveforms, in snapshot or continuous format.\n |
|
7 | 7 | * |
|
8 | 8 | */ |
|
9 | 9 | |
|
10 | 10 | #include "wf_handler.h" |
|
11 | 11 | |
|
12 | 12 | //*************** |
|
13 | 13 | // waveform rings |
|
14 | 14 | // F0 |
|
15 | 15 | ring_node waveform_ring_f0[NB_RING_NODES_F0]= {0}; |
|
16 | 16 | ring_node *current_ring_node_f0 = NULL; |
|
17 | 17 | ring_node *ring_node_to_send_swf_f0 = NULL; |
|
18 | 18 | // F1 |
|
19 | 19 | ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0}; |
|
20 | 20 | ring_node *current_ring_node_f1 = NULL; |
|
21 | 21 | ring_node *ring_node_to_send_swf_f1 = NULL; |
|
22 | 22 | ring_node *ring_node_to_send_cwf_f1 = NULL; |
|
23 | 23 | // F2 |
|
24 | 24 | ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0}; |
|
25 | 25 | ring_node *current_ring_node_f2 = NULL; |
|
26 | 26 | ring_node *ring_node_to_send_swf_f2 = NULL; |
|
27 | 27 | ring_node *ring_node_to_send_cwf_f2 = NULL; |
|
28 | 28 | // F3 |
|
29 | 29 | ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0}; |
|
30 | 30 | ring_node *current_ring_node_f3 = NULL; |
|
31 | 31 | ring_node *ring_node_to_send_cwf_f3 = NULL; |
|
32 | 32 | char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0}; |
|
33 | 33 | |
|
34 | 34 | bool extractSWF1 = false; |
|
35 | 35 | bool extractSWF2 = false; |
|
36 | 36 | bool swf0_ready_flag_f1 = false; |
|
37 | 37 | bool swf0_ready_flag_f2 = false; |
|
38 | 38 | bool swf1_ready = false; |
|
39 | 39 | bool swf2_ready = false; |
|
40 | 40 | |
|
41 | 41 | int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0}; |
|
42 | 42 | int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0}; |
|
43 | 43 | ring_node ring_node_swf1_extracted = {0}; |
|
44 | 44 | ring_node ring_node_swf2_extracted = {0}; |
|
45 | 45 | |
|
46 | 46 | typedef enum resynchro_state_t |
|
47 | 47 | { |
|
48 | 48 | MEASURE, |
|
49 | 49 | CORRECTION |
|
50 | 50 | } resynchro_state; |
|
51 | 51 | |
|
52 | 52 | //********************* |
|
53 | 53 | // Interrupt SubRoutine |
|
54 | 54 | |
|
55 | 55 | ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel) |
|
56 | 56 | { |
|
57 | 57 | ring_node *node; |
|
58 | 58 | |
|
59 | 59 | node = NULL; |
|
60 | 60 | switch ( frequencyChannel ) { |
|
61 | 61 | case CHANNELF1: |
|
62 | 62 | node = ring_node_to_send_cwf_f1; |
|
63 | 63 | break; |
|
64 | 64 | case CHANNELF2: |
|
65 | 65 | node = ring_node_to_send_cwf_f2; |
|
66 | 66 | break; |
|
67 | 67 | case CHANNELF3: |
|
68 | 68 | node = ring_node_to_send_cwf_f3; |
|
69 | 69 | break; |
|
70 | 70 | default: |
|
71 | 71 | break; |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | 74 | return node; |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel) |
|
78 | 78 | { |
|
79 | 79 | ring_node *node; |
|
80 | 80 | |
|
81 | 81 | node = NULL; |
|
82 | 82 | switch ( frequencyChannel ) { |
|
83 | 83 | case CHANNELF0: |
|
84 | 84 | node = ring_node_to_send_swf_f0; |
|
85 | 85 | break; |
|
86 | 86 | case CHANNELF1: |
|
87 | 87 | node = ring_node_to_send_swf_f1; |
|
88 | 88 | break; |
|
89 | 89 | case CHANNELF2: |
|
90 | 90 | node = ring_node_to_send_swf_f2; |
|
91 | 91 | break; |
|
92 | 92 | default: |
|
93 | 93 | break; |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | return node; |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | void reset_extractSWF( void ) |
|
100 | 100 | { |
|
101 | 101 | extractSWF1 = false; |
|
102 | 102 | extractSWF2 = false; |
|
103 | 103 | swf0_ready_flag_f1 = false; |
|
104 | 104 | swf0_ready_flag_f2 = false; |
|
105 | 105 | swf1_ready = false; |
|
106 | 106 | swf2_ready = false; |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | inline void waveforms_isr_f3( void ) |
|
110 | 110 | { |
|
111 | 111 | rtems_status_code spare_status; |
|
112 | 112 | |
|
113 | 113 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet |
|
114 | 114 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
115 | 115 | { // in modes other than STANDBY and BURST, send the CWF_F3 data |
|
116 | 116 | //*** |
|
117 | 117 | // F3 |
|
118 | 118 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits |
|
119 | 119 | ring_node_to_send_cwf_f3 = current_ring_node_f3->previous; |
|
120 | 120 | current_ring_node_f3 = current_ring_node_f3->next; |
|
121 | 121 | if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full |
|
122 | 122 | ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time; |
|
123 | 123 | ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time; |
|
124 | 124 | waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address; |
|
125 | 125 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000] |
|
126 | 126 | } |
|
127 | 127 | else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full |
|
128 | 128 | ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time; |
|
129 | 129 | ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time; |
|
130 | 130 | waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; |
|
131 | 131 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000] |
|
132 | 132 | } |
|
133 | 133 | if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
134 | 134 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); |
|
135 | 135 | } |
|
136 | 136 | } |
|
137 | 137 | } |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | inline void waveforms_isr_burst( void ) |
|
141 | 141 | { |
|
142 | 142 | unsigned char status; |
|
143 | 143 | rtems_status_code spare_status; |
|
144 | 144 | |
|
145 | 145 | status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2 |
|
146 | 146 | |
|
147 | 147 | switch(status) |
|
148 | 148 | { |
|
149 | 149 | case BIT_WFP_BUFFER_0: |
|
150 | 150 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
151 | 151 | ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; |
|
152 | 152 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time; |
|
153 | 153 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time; |
|
154 | 154 | current_ring_node_f2 = current_ring_node_f2->next; |
|
155 | 155 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address; |
|
156 | 156 | if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) { |
|
157 | 157 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); |
|
158 | 158 | } |
|
159 | 159 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000] |
|
160 | 160 | break; |
|
161 | 161 | case BIT_WFP_BUFFER_1: |
|
162 | 162 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
163 | 163 | ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; |
|
164 | 164 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time; |
|
165 | 165 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time; |
|
166 | 166 | current_ring_node_f2 = current_ring_node_f2->next; |
|
167 | 167 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; |
|
168 | 168 | if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) { |
|
169 | 169 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); |
|
170 | 170 | } |
|
171 | 171 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000] |
|
172 | 172 | break; |
|
173 | 173 | default: |
|
174 | 174 | break; |
|
175 | 175 | } |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | inline void waveform_isr_normal_sbm1_sbm2( void ) |
|
179 | 179 | { |
|
180 | 180 | rtems_status_code status; |
|
181 | 181 | |
|
182 | 182 | //*** |
|
183 | 183 | // F0 |
|
184 | 184 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits |
|
185 | 185 | { |
|
186 | 186 | swf0_ready_flag_f1 = true; |
|
187 | 187 | swf0_ready_flag_f2 = true; |
|
188 | 188 | ring_node_to_send_swf_f0 = current_ring_node_f0->previous; |
|
189 | 189 | current_ring_node_f0 = current_ring_node_f0->next; |
|
190 | 190 | if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0) |
|
191 | 191 | { |
|
192 | 192 | |
|
193 | 193 | ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time; |
|
194 | 194 | ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time; |
|
195 | 195 | waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address; |
|
196 | 196 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001] |
|
197 | 197 | } |
|
198 | 198 | else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1) |
|
199 | 199 | { |
|
200 | 200 | ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time; |
|
201 | 201 | ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time; |
|
202 | 202 | waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; |
|
203 | 203 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010] |
|
204 | 204 | } |
|
205 | 205 | // send an event to the WFRM task for resynchro activities |
|
206 | 206 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH ); |
|
207 | 207 | status = rtems_event_send( Task_id[TASKID_CALI], RTEMS_EVENT_CAL_SWEEP_WAKE ); |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | //*** |
|
211 | 211 | // F1 |
|
212 | 212 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F1) != INIT_CHAR ) { // [0000 1100] check the f1 full bits |
|
213 | 213 | // (1) change the receiving buffer for the waveform picker |
|
214 | 214 | ring_node_to_send_cwf_f1 = current_ring_node_f1->previous; |
|
215 | 215 | current_ring_node_f1 = current_ring_node_f1->next; |
|
216 | 216 | if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0) |
|
217 | 217 | { |
|
218 | 218 | ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time; |
|
219 | 219 | ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time; |
|
220 | 220 | waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address; |
|
221 | 221 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0 |
|
222 | 222 | } |
|
223 | 223 | else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1) |
|
224 | 224 | { |
|
225 | 225 | ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time; |
|
226 | 226 | ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time; |
|
227 | 227 | waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; |
|
228 | 228 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0 |
|
229 | 229 | } |
|
230 | 230 | // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed) |
|
231 | 231 | status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 ); |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | //*** |
|
235 | 235 | // F2 |
|
236 | 236 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit |
|
237 | 237 | // (1) change the receiving buffer for the waveform picker |
|
238 | 238 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
239 | 239 | ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2; |
|
240 | 240 | current_ring_node_f2 = current_ring_node_f2->next; |
|
241 | 241 | if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0) |
|
242 | 242 | { |
|
243 | 243 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time; |
|
244 | 244 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time; |
|
245 | 245 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address; |
|
246 | 246 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000] |
|
247 | 247 | } |
|
248 | 248 | else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1) |
|
249 | 249 | { |
|
250 | 250 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time; |
|
251 | 251 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time; |
|
252 | 252 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; |
|
253 | 253 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000] |
|
254 | 254 | } |
|
255 | 255 | // (2) send an event for the waveforms transmission |
|
256 | 256 | status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 ); |
|
257 | 257 | } |
|
258 | 258 | } |
|
259 | 259 | |
|
260 | 260 | rtems_isr waveforms_isr( rtems_vector_number vector ) |
|
261 | 261 | { |
|
262 | 262 | /** This is the interrupt sub routine called by the waveform picker core. |
|
263 | 263 | * |
|
264 | 264 | * This ISR launch different actions depending mainly on two pieces of information: |
|
265 | 265 | * 1. the values read in the registers of the waveform picker. |
|
266 | 266 | * 2. the current LFR mode. |
|
267 | 267 | * |
|
268 | 268 | */ |
|
269 | 269 | |
|
270 | 270 | // STATUS |
|
271 | 271 | // new error error buffer full |
|
272 | 272 | // 15 14 13 12 11 10 9 8 |
|
273 | 273 | // f3 f2 f1 f0 f3 f2 f1 f0 |
|
274 | 274 | // |
|
275 | 275 | // ready buffer |
|
276 | 276 | // 7 6 5 4 3 2 1 0 |
|
277 | 277 | // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0 |
|
278 | 278 | |
|
279 | 279 | rtems_status_code spare_status; |
|
280 | 280 | |
|
281 | 281 | waveforms_isr_f3(); |
|
282 | 282 | |
|
283 | 283 | //************************************************* |
|
284 | 284 | // copy the status bits in the housekeeping packets |
|
285 | 285 | housekeeping_packet.hk_lfr_vhdl_iir_cal = |
|
286 | 286 | (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
287 | 287 | |
|
288 | 288 | if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits |
|
289 | 289 | { |
|
290 | 290 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 ); |
|
291 | 291 | } |
|
292 | 292 | |
|
293 | 293 | switch(lfrCurrentMode) |
|
294 | 294 | { |
|
295 | 295 | //******** |
|
296 | 296 | // STANDBY |
|
297 | 297 | case LFR_MODE_STANDBY: |
|
298 | 298 | break; |
|
299 | 299 | //************************** |
|
300 | 300 | // LFR NORMAL, SBM1 and SBM2 |
|
301 | 301 | case LFR_MODE_NORMAL: |
|
302 | 302 | case LFR_MODE_SBM1: |
|
303 | 303 | case LFR_MODE_SBM2: |
|
304 | 304 | waveform_isr_normal_sbm1_sbm2(); |
|
305 | 305 | break; |
|
306 | 306 | //****** |
|
307 | 307 | // BURST |
|
308 | 308 | case LFR_MODE_BURST: |
|
309 | 309 | waveforms_isr_burst(); |
|
310 | 310 | break; |
|
311 | 311 | //******** |
|
312 | 312 | // DEFAULT |
|
313 | 313 | default: |
|
314 | 314 | break; |
|
315 | 315 | } |
|
316 | 316 | } |
|
317 | 317 | |
|
318 | 318 | //************ |
|
319 | 319 | // RTEMS TASKS |
|
320 | 320 | |
|
321 | 321 | rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP |
|
322 | 322 | { |
|
323 | 323 | /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode. |
|
324 | 324 | * |
|
325 | 325 | * @param unused is the starting argument of the RTEMS task |
|
326 | 326 | * |
|
327 | 327 | * The following data packets are sent by this task: |
|
328 | 328 | * - TM_LFR_SCIENCE_NORMAL_SWF_F0 |
|
329 | 329 | * - TM_LFR_SCIENCE_NORMAL_SWF_F1 |
|
330 | 330 | * - TM_LFR_SCIENCE_NORMAL_SWF_F2 |
|
331 | 331 | * |
|
332 | 332 | */ |
|
333 | 333 | |
|
334 | 334 | rtems_event_set event_out; |
|
335 | 335 | rtems_id queue_id; |
|
336 | 336 | rtems_status_code status; |
|
337 | 337 | ring_node *ring_node_swf1_extracted_ptr; |
|
338 | 338 | ring_node *ring_node_swf2_extracted_ptr; |
|
339 | 339 | |
|
340 | 340 | event_out = EVENT_SETS_NONE_PENDING; |
|
341 | 341 | queue_id = RTEMS_ID_NONE; |
|
342 | 342 | |
|
343 | 343 | ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted; |
|
344 | 344 | ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted; |
|
345 | 345 | |
|
346 | 346 | status = get_message_queue_id_send( &queue_id ); |
|
347 | 347 | if (status != RTEMS_SUCCESSFUL) |
|
348 | 348 | { |
|
349 | 349 | PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status); |
|
350 | 350 | } |
|
351 | 351 | |
|
352 | 352 | BOOT_PRINTF("in WFRM ***\n"); |
|
353 | 353 | |
|
354 | 354 | while(1){ |
|
355 | 355 | // wait for an RTEMS_EVENT |
|
356 | 356 | rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH, |
|
357 | 357 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
358 | 358 | |
|
359 | 359 | if (event_out == RTEMS_EVENT_MODE_NORMAL) |
|
360 | 360 | { |
|
361 | 361 | DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n"); |
|
362 | 362 | ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0; |
|
363 | 363 | ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1; |
|
364 | 364 | ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2; |
|
365 | 365 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) ); |
|
366 | 366 | status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) ); |
|
367 | 367 | status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) ); |
|
368 | 368 | } |
|
369 | 369 | if (event_out == RTEMS_EVENT_SWF_RESYNCH) |
|
370 | 370 | { |
|
371 | 371 | snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
372 | 372 | } |
|
373 | 373 | } |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP |
|
377 | 377 | { |
|
378 | 378 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3. |
|
379 | 379 | * |
|
380 | 380 | * @param unused is the starting argument of the RTEMS task |
|
381 | 381 | * |
|
382 | 382 | * The following data packet is sent by this task: |
|
383 | 383 | * - TM_LFR_SCIENCE_NORMAL_CWF_F3 |
|
384 | 384 | * |
|
385 | 385 | */ |
|
386 | 386 | |
|
387 | 387 | rtems_event_set event_out; |
|
388 | 388 | rtems_id queue_id; |
|
389 | 389 | rtems_status_code status; |
|
390 | 390 | ring_node ring_node_cwf3_light; |
|
391 | 391 | ring_node *ring_node_to_send_cwf; |
|
392 | 392 | |
|
393 | 393 | event_out = EVENT_SETS_NONE_PENDING; |
|
394 | 394 | queue_id = RTEMS_ID_NONE; |
|
395 | 395 | |
|
396 | 396 | status = get_message_queue_id_send( &queue_id ); |
|
397 | 397 | if (status != RTEMS_SUCCESSFUL) |
|
398 | 398 | { |
|
399 | 399 | PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status) |
|
400 | 400 | } |
|
401 | 401 | |
|
402 | 402 | ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; |
|
403 | 403 | |
|
404 | 404 | // init the ring_node_cwf3_light structure |
|
405 | 405 | ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light; |
|
406 | 406 | ring_node_cwf3_light.coarseTime = INIT_CHAR; |
|
407 | 407 | ring_node_cwf3_light.fineTime = INIT_CHAR; |
|
408 | 408 | ring_node_cwf3_light.next = NULL; |
|
409 | 409 | ring_node_cwf3_light.previous = NULL; |
|
410 | 410 | ring_node_cwf3_light.sid = SID_NORM_CWF_F3; |
|
411 | 411 | ring_node_cwf3_light.status = INIT_CHAR; |
|
412 | 412 | |
|
413 | 413 | BOOT_PRINTF("in CWF3 ***\n"); |
|
414 | 414 | |
|
415 | 415 | while(1){ |
|
416 | 416 | // wait for an RTEMS_EVENT |
|
417 | 417 | rtems_event_receive( RTEMS_EVENT_0, |
|
418 | 418 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
419 | 419 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) |
|
420 | 420 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) ) |
|
421 | 421 | { |
|
422 | 422 | ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 ); |
|
423 | 423 | if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3) |
|
424 | 424 | { |
|
425 | 425 | PRINTF("send CWF_LONG_F3\n"); |
|
426 | 426 | ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; |
|
427 | 427 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); |
|
428 | 428 | } |
|
429 | 429 | else |
|
430 | 430 | { |
|
431 | 431 | PRINTF("send CWF_F3 (light)\n"); |
|
432 | 432 | send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id ); |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | } |
|
436 | 436 | else |
|
437 | 437 | { |
|
438 | 438 | PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode) |
|
439 | 439 | } |
|
440 | 440 | } |
|
441 | 441 | } |
|
442 | 442 | |
|
443 | 443 | rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2 |
|
444 | 444 | { |
|
445 | 445 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2. |
|
446 | 446 | * |
|
447 | 447 | * @param unused is the starting argument of the RTEMS task |
|
448 | 448 | * |
|
449 | 449 | * The following data packet is sent by this function: |
|
450 | 450 | * - TM_LFR_SCIENCE_BURST_CWF_F2 |
|
451 | 451 | * - TM_LFR_SCIENCE_SBM2_CWF_F2 |
|
452 | 452 | * |
|
453 | 453 | */ |
|
454 | 454 | |
|
455 | 455 | rtems_event_set event_out; |
|
456 | 456 | rtems_id queue_id; |
|
457 | 457 | rtems_status_code status; |
|
458 | 458 | ring_node *ring_node_to_send; |
|
459 | 459 | unsigned long long int acquisitionTimeF0_asLong; |
|
460 | 460 | |
|
461 | 461 | event_out = EVENT_SETS_NONE_PENDING; |
|
462 | 462 | queue_id = RTEMS_ID_NONE; |
|
463 | 463 | |
|
464 | 464 | acquisitionTimeF0_asLong = INIT_CHAR; |
|
465 | 465 | |
|
466 | 466 | status = get_message_queue_id_send( &queue_id ); |
|
467 | 467 | if (status != RTEMS_SUCCESSFUL) |
|
468 | 468 | { |
|
469 | 469 | PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status) |
|
470 | 470 | } |
|
471 | 471 | |
|
472 | 472 | BOOT_PRINTF("in CWF2 ***\n"); |
|
473 | 473 | |
|
474 | 474 | while(1){ |
|
475 | 475 | // wait for an RTEMS_EVENT// send the snapshot when built |
|
476 | 476 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ); |
|
477 | 477 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST, |
|
478 | 478 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
479 | 479 | ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 ); |
|
480 | 480 | if (event_out == RTEMS_EVENT_MODE_BURST) |
|
481 | 481 | { // data are sent whatever the transition time |
|
482 | 482 | status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) ); |
|
483 | 483 | } |
|
484 | 484 | else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) |
|
485 | 485 | { |
|
486 | 486 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) |
|
487 | 487 | { |
|
488 | 488 | // data are sent depending on the transition time |
|
489 | 489 | if ( time_management_regs->coarse_time >= lastValidEnterModeTime) |
|
490 | 490 | { |
|
491 | 491 | status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) ); |
|
492 | 492 | } |
|
493 | 493 | } |
|
494 | 494 | // launch snapshot extraction if needed |
|
495 | 495 | if (extractSWF2 == true) |
|
496 | 496 | { |
|
497 | 497 | ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2; |
|
498 | 498 | // extract the snapshot |
|
499 | 499 | build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong, |
|
500 | 500 | &ring_node_swf2_extracted, swf2_extracted ); |
|
501 | 501 | extractSWF2 = false; |
|
502 | 502 | swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM |
|
503 | 503 | } |
|
504 | 504 | if (swf0_ready_flag_f2 == true) |
|
505 | 505 | { |
|
506 | 506 | extractSWF2 = true; |
|
507 | 507 | // record the acquition time of the f0 snapshot to use to build the snapshot at f2 |
|
508 | 508 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
509 | 509 | swf0_ready_flag_f2 = false; |
|
510 | 510 | } |
|
511 | 511 | } |
|
512 | 512 | } |
|
513 | 513 | } |
|
514 | 514 | |
|
515 | 515 | rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1 |
|
516 | 516 | { |
|
517 | 517 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1. |
|
518 | 518 | * |
|
519 | 519 | * @param unused is the starting argument of the RTEMS task |
|
520 | 520 | * |
|
521 | 521 | * The following data packet is sent by this function: |
|
522 | 522 | * - TM_LFR_SCIENCE_SBM1_CWF_F1 |
|
523 | 523 | * |
|
524 | 524 | */ |
|
525 | 525 | |
|
526 | 526 | rtems_event_set event_out; |
|
527 | 527 | rtems_id queue_id; |
|
528 | 528 | rtems_status_code status; |
|
529 | 529 | |
|
530 | 530 | ring_node *ring_node_to_send_cwf; |
|
531 | 531 | |
|
532 | 532 | event_out = EVENT_SETS_NONE_PENDING; |
|
533 | 533 | queue_id = RTEMS_ID_NONE; |
|
534 | 534 | |
|
535 | 535 | status = get_message_queue_id_send( &queue_id ); |
|
536 | 536 | if (status != RTEMS_SUCCESSFUL) |
|
537 | 537 | { |
|
538 | 538 | PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status) |
|
539 | 539 | } |
|
540 | 540 | |
|
541 | 541 | BOOT_PRINTF("in CWF1 ***\n"); |
|
542 | 542 | |
|
543 | 543 | while(1){ |
|
544 | 544 | // wait for an RTEMS_EVENT |
|
545 | 545 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, |
|
546 | 546 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
547 | 547 | ring_node_to_send_cwf = getRingNodeToSendCWF( 1 ); |
|
548 | 548 | ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1; |
|
549 | 549 | if (lfrCurrentMode == LFR_MODE_SBM1) |
|
550 | 550 | { |
|
551 | 551 | // data are sent depending on the transition time |
|
552 | 552 | if ( time_management_regs->coarse_time >= lastValidEnterModeTime ) |
|
553 | 553 | { |
|
554 | 554 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); |
|
555 | 555 | } |
|
556 | 556 | } |
|
557 | 557 | // launch snapshot extraction if needed |
|
558 | 558 | if (extractSWF1 == true) |
|
559 | 559 | { |
|
560 | 560 | ring_node_to_send_swf_f1 = ring_node_to_send_cwf; |
|
561 | 561 | // launch the snapshot extraction |
|
562 | 562 | status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 ); |
|
563 | 563 | extractSWF1 = false; |
|
564 | 564 | } |
|
565 | 565 | if (swf0_ready_flag_f1 == true) |
|
566 | 566 | { |
|
567 | 567 | extractSWF1 = true; |
|
568 | 568 | swf0_ready_flag_f1 = false; // this step shall be executed only one time |
|
569 | 569 | } |
|
570 | 570 | if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction |
|
571 | 571 | { |
|
572 | 572 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ); |
|
573 | 573 | swf1_ready = false; |
|
574 | 574 | swf2_ready = false; |
|
575 | 575 | } |
|
576 | 576 | } |
|
577 | 577 | } |
|
578 | 578 | |
|
579 | 579 | rtems_task swbd_task(rtems_task_argument argument) |
|
580 | 580 | { |
|
581 | 581 | /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers. |
|
582 | 582 | * |
|
583 | 583 | * @param unused is the starting argument of the RTEMS task |
|
584 | 584 | * |
|
585 | 585 | */ |
|
586 | 586 | |
|
587 | 587 | rtems_event_set event_out; |
|
588 | 588 | unsigned long long int acquisitionTimeF0_asLong; |
|
589 | 589 | |
|
590 | 590 | event_out = EVENT_SETS_NONE_PENDING; |
|
591 | 591 | acquisitionTimeF0_asLong = INIT_CHAR; |
|
592 | 592 | |
|
593 | 593 | BOOT_PRINTF("in SWBD ***\n") |
|
594 | 594 | |
|
595 | 595 | while(1){ |
|
596 | 596 | // wait for an RTEMS_EVENT |
|
597 | 597 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, |
|
598 | 598 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
599 | 599 | if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) |
|
600 | 600 | { |
|
601 | 601 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
602 | 602 | build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong, |
|
603 | 603 | &ring_node_swf1_extracted, swf1_extracted ); |
|
604 | 604 | swf1_ready = true; // the snapshot has been extracted and is ready to be sent |
|
605 | 605 | } |
|
606 | 606 | else |
|
607 | 607 | { |
|
608 | 608 | PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out) |
|
609 | 609 | } |
|
610 | 610 | } |
|
611 | 611 | } |
|
612 | 612 | |
|
613 | 613 | //****************** |
|
614 | 614 | // general functions |
|
615 | 615 | |
|
616 | 616 | void WFP_init_rings( void ) |
|
617 | 617 | { |
|
618 | 618 | // F0 RING |
|
619 | 619 | init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER ); |
|
620 | 620 | // F1 RING |
|
621 | 621 | init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER ); |
|
622 | 622 | // F2 RING |
|
623 | 623 | init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER ); |
|
624 | 624 | // F3 RING |
|
625 | 625 | init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER ); |
|
626 | 626 | |
|
627 | 627 | ring_node_swf1_extracted.buffer_address = (int) swf1_extracted; |
|
628 | 628 | ring_node_swf2_extracted.buffer_address = (int) swf2_extracted; |
|
629 | 629 | |
|
630 | 630 | DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0) |
|
631 | 631 | DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1) |
|
632 | 632 | DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2) |
|
633 | 633 | DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3) |
|
634 | 634 | DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0) |
|
635 | 635 | DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1) |
|
636 | 636 | DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2) |
|
637 | 637 | DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3) |
|
638 | 638 | |
|
639 | 639 | } |
|
640 | 640 | |
|
641 | 641 | void WFP_reset_current_ring_nodes( void ) |
|
642 | 642 | { |
|
643 | 643 | current_ring_node_f0 = waveform_ring_f0[0].next; |
|
644 | 644 | current_ring_node_f1 = waveform_ring_f1[0].next; |
|
645 | 645 | current_ring_node_f2 = waveform_ring_f2[0].next; |
|
646 | 646 | current_ring_node_f3 = waveform_ring_f3[0].next; |
|
647 | 647 | |
|
648 | 648 | ring_node_to_send_swf_f0 = waveform_ring_f0; |
|
649 | 649 | ring_node_to_send_swf_f1 = waveform_ring_f1; |
|
650 | 650 | ring_node_to_send_swf_f2 = waveform_ring_f2; |
|
651 | 651 | |
|
652 | 652 | ring_node_to_send_cwf_f1 = waveform_ring_f1; |
|
653 | 653 | ring_node_to_send_cwf_f2 = waveform_ring_f2; |
|
654 | 654 | ring_node_to_send_cwf_f3 = waveform_ring_f3; |
|
655 | 655 | } |
|
656 | 656 | |
|
657 | 657 | int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id ) |
|
658 | 658 | { |
|
659 | 659 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. |
|
660 | 660 | * |
|
661 | 661 | * @param waveform points to the buffer containing the data that will be send. |
|
662 | 662 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
663 | 663 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
664 | 664 | * contain information to setup the transmission of the data packets. |
|
665 | 665 | * |
|
666 | 666 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer |
|
667 | 667 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. |
|
668 | 668 | * |
|
669 | 669 | */ |
|
670 | 670 | |
|
671 | 671 | unsigned int i; |
|
672 | 672 | unsigned int j; |
|
673 | 673 | int ret; |
|
674 | 674 | rtems_status_code status; |
|
675 | 675 | |
|
676 | 676 | char *sample; |
|
677 | 677 | int *dataPtr; |
|
678 | 678 | |
|
679 | 679 | ret = LFR_DEFAULT; |
|
680 | 680 | |
|
681 | 681 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
682 | 682 | |
|
683 | 683 | ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime; |
|
684 | 684 | ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime; |
|
685 | 685 | |
|
686 | 686 | //********************** |
|
687 | 687 | // BUILD CWF3_light DATA |
|
688 | 688 | for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++) |
|
689 | 689 | { |
|
690 | 690 | sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ]; |
|
691 | 691 | for (j=0; j < CWF_BLK_SIZE; j++) |
|
692 | 692 | { |
|
693 | 693 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ]; |
|
694 | 694 | } |
|
695 | 695 | } |
|
696 | 696 | |
|
697 | 697 | // SEND PACKET |
|
698 | 698 | status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) ); |
|
699 | 699 | if (status != RTEMS_SUCCESSFUL) { |
|
700 | 700 | ret = LFR_DEFAULT; |
|
701 | 701 | } |
|
702 | 702 | |
|
703 | 703 | return ret; |
|
704 | 704 | } |
|
705 | 705 | |
|
706 | 706 | void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime, |
|
707 | 707 | unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime ) |
|
708 | 708 | { |
|
709 | 709 | unsigned long long int acquisitionTimeAsLong; |
|
710 | 710 | unsigned char localAcquisitionTime[BYTES_PER_TIME]; |
|
711 | 711 | double deltaT; |
|
712 | 712 | |
|
713 | 713 | deltaT = INIT_FLOAT; |
|
714 | 714 | |
|
715 | 715 | localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES ); |
|
716 | 716 | localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES ); |
|
717 | 717 | localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE ); |
|
718 | 718 | localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime ); |
|
719 | 719 | localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE ); |
|
720 | 720 | localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime ); |
|
721 | 721 | |
|
722 | 722 | acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES ) |
|
723 | 723 | + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES ) |
|
724 | 724 | + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES ) |
|
725 | 725 | + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES ) |
|
726 | 726 | + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE ) |
|
727 | 727 | + ( (unsigned long long int) localAcquisitionTime[BYTE_5] ); |
|
728 | 728 | |
|
729 | 729 | switch( sid ) |
|
730 | 730 | { |
|
731 | 731 | case SID_NORM_SWF_F0: |
|
732 | 732 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ; |
|
733 | 733 | break; |
|
734 | 734 | |
|
735 | 735 | case SID_NORM_SWF_F1: |
|
736 | 736 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ; |
|
737 | 737 | break; |
|
738 | 738 | |
|
739 | 739 | case SID_NORM_SWF_F2: |
|
740 | 740 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ; |
|
741 | 741 | break; |
|
742 | 742 | |
|
743 | 743 | case SID_SBM1_CWF_F1: |
|
744 | 744 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ; |
|
745 | 745 | break; |
|
746 | 746 | |
|
747 | 747 | case SID_SBM2_CWF_F2: |
|
748 | 748 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ; |
|
749 | 749 | break; |
|
750 | 750 | |
|
751 | 751 | case SID_BURST_CWF_F2: |
|
752 | 752 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ; |
|
753 | 753 | break; |
|
754 | 754 | |
|
755 | 755 | case SID_NORM_CWF_F3: |
|
756 | 756 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ; |
|
757 | 757 | break; |
|
758 | 758 | |
|
759 | 759 | case SID_NORM_CWF_LONG_F3: |
|
760 | 760 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ; |
|
761 | 761 | break; |
|
762 | 762 | |
|
763 | 763 | default: |
|
764 | 764 | PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid) |
|
765 | 765 | deltaT = 0.; |
|
766 | 766 | break; |
|
767 | 767 | } |
|
768 | 768 | |
|
769 | 769 | acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT; |
|
770 | 770 | // |
|
771 | 771 | acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES); |
|
772 | 772 | acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES); |
|
773 | 773 | acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES); |
|
774 | 774 | acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES); |
|
775 | 775 | acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE ); |
|
776 | 776 | acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong ); |
|
777 | 777 | |
|
778 | 778 | } |
|
779 | 779 | |
|
780 | 780 | void build_snapshot_from_ring( ring_node *ring_node_to_send, |
|
781 | 781 | unsigned char frequencyChannel, |
|
782 | 782 | unsigned long long int acquisitionTimeF0_asLong, |
|
783 | 783 | ring_node *ring_node_swf_extracted, |
|
784 | 784 | int *swf_extracted) |
|
785 | 785 | { |
|
786 | 786 | unsigned int i; |
|
787 | 787 | unsigned int node; |
|
788 | 788 | unsigned long long int centerTime_asLong; |
|
789 | 789 | unsigned long long int acquisitionTime_asLong; |
|
790 | 790 | unsigned long long int bufferAcquisitionTime_asLong; |
|
791 | 791 | unsigned char *ptr1; |
|
792 | 792 | unsigned char *ptr2; |
|
793 | 793 | unsigned char *timeCharPtr; |
|
794 | 794 | unsigned char nb_ring_nodes; |
|
795 | 795 | unsigned long long int frequency_asLong; |
|
796 | 796 | unsigned long long int nbTicksPerSample_asLong; |
|
797 | 797 | unsigned long long int nbSamplesPart1_asLong; |
|
798 | 798 | unsigned long long int sampleOffset_asLong; |
|
799 | 799 | |
|
800 | 800 | unsigned int deltaT_F0; |
|
801 | 801 | unsigned int deltaT_F1; |
|
802 | 802 | unsigned long long int deltaT_F2; |
|
803 | 803 | |
|
804 | 804 | deltaT_F0 = DELTAT_F0; |
|
805 | 805 | deltaT_F1 = DELTAT_F1; |
|
806 | 806 | deltaT_F2 = DELTAT_F2; |
|
807 | 807 | sampleOffset_asLong = INIT_CHAR; |
|
808 | 808 | |
|
809 | 809 | // (1) get the f0 acquisition time => the value is passed in argument |
|
810 | 810 | |
|
811 | 811 | // (2) compute the central reference time |
|
812 | 812 | centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0; |
|
813 | 813 | acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2) |
|
814 | 814 | bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2) |
|
815 | 815 | nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2) |
|
816 | 816 | |
|
817 | 817 | // (3) compute the acquisition time of the current snapshot |
|
818 | 818 | switch(frequencyChannel) |
|
819 | 819 | { |
|
820 | 820 | case CHANNELF1: // 1 is for F1 = 4096 Hz |
|
821 | 821 | acquisitionTime_asLong = centerTime_asLong - deltaT_F1; |
|
822 | 822 | nb_ring_nodes = NB_RING_NODES_F1; |
|
823 | 823 | frequency_asLong = FREQ_F1; |
|
824 | 824 | nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096; |
|
825 | 825 | break; |
|
826 | 826 | case CHANNELF2: // 2 is for F2 = 256 Hz |
|
827 | 827 | acquisitionTime_asLong = centerTime_asLong - deltaT_F2; |
|
828 | 828 | nb_ring_nodes = NB_RING_NODES_F2; |
|
829 | 829 | frequency_asLong = FREQ_F2; |
|
830 | 830 | nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256; |
|
831 | 831 | break; |
|
832 | 832 | default: |
|
833 | 833 | acquisitionTime_asLong = centerTime_asLong; |
|
834 | 834 | nb_ring_nodes = 0; |
|
835 | 835 | frequency_asLong = FREQ_F2; |
|
836 | 836 | nbTicksPerSample_asLong = TICKS_PER_T2; |
|
837 | 837 | break; |
|
838 | 838 | } |
|
839 | 839 | |
|
840 | 840 | //***************************************************************************** |
|
841 | 841 | // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong |
|
842 | 842 | node = 0; |
|
843 | 843 | while ( node < nb_ring_nodes) |
|
844 | 844 | { |
|
845 | //PRINTF1("%d ... ", node); | |
|
846 | 845 | bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime ); |
|
847 | 846 | if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong) |
|
848 | 847 | { |
|
849 | //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong); | |
|
850 | 848 | node = nb_ring_nodes; |
|
851 | 849 | } |
|
852 | 850 | else |
|
853 | 851 | { |
|
854 | 852 | node = node + 1; |
|
855 | 853 | ring_node_to_send = ring_node_to_send->previous; |
|
856 | 854 | } |
|
857 | 855 | } |
|
858 | 856 | |
|
859 | 857 | // (5) compute the number of samples to take in the current buffer |
|
860 | 858 | sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES; |
|
861 | 859 | nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong; |
|
862 | //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong); | |
|
863 | 860 | |
|
864 | 861 | // (6) compute the final acquisition time |
|
865 | 862 | acquisitionTime_asLong = bufferAcquisitionTime_asLong + |
|
866 | 863 | (sampleOffset_asLong * nbTicksPerSample_asLong); |
|
867 | 864 | |
|
868 | 865 | // (7) copy the acquisition time at the beginning of the extrated snapshot |
|
869 | 866 | ptr1 = (unsigned char*) &acquisitionTime_asLong; |
|
870 | 867 | // fine time |
|
871 | 868 | ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime; |
|
872 | 869 | ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ]; |
|
873 | 870 | ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ]; |
|
874 | 871 | // coarse time |
|
875 | 872 | ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime; |
|
876 | 873 | ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ]; |
|
877 | 874 | ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ]; |
|
878 | 875 | ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ]; |
|
879 | 876 | ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ]; |
|
880 | 877 | |
|
881 | 878 | // re set the synchronization bit |
|
882 | 879 | timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime; |
|
883 | 880 | ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000] |
|
884 | 881 | |
|
885 |
if ( (nbSamplesPart1_asLong > |
|
|
882 | if ( (nbSamplesPart1_asLong > NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) ) | |
|
886 | 883 | { |
|
887 | 884 | nbSamplesPart1_asLong = 0; |
|
888 | 885 | } |
|
889 | 886 | // copy the part 1 of the snapshot in the extracted buffer |
|
890 | 887 | for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ ) |
|
891 | 888 | { |
|
892 | 889 | swf_extracted[i] = |
|
893 | 890 | ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ]; |
|
894 | 891 | } |
|
895 | 892 | // copy the part 2 of the snapshot in the extracted buffer |
|
896 | 893 | ring_node_to_send = ring_node_to_send->next; |
|
897 | 894 | for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ ) |
|
898 | 895 | { |
|
899 | 896 | swf_extracted[i] = |
|
900 | 897 | ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ]; |
|
901 | 898 | } |
|
902 | 899 | } |
|
903 | 900 | |
|
904 | 901 | double computeCorrection( unsigned char *timePtr ) |
|
905 | 902 | { |
|
906 | 903 | unsigned long long int acquisitionTime; |
|
907 | 904 | unsigned long long int centerTime; |
|
908 | 905 | unsigned long long int previousTick; |
|
909 | 906 | unsigned long long int nextTick; |
|
910 | 907 | unsigned long long int deltaPreviousTick; |
|
911 | 908 | unsigned long long int deltaNextTick; |
|
912 | 909 | double deltaPrevious_ms; |
|
913 | 910 | double deltaNext_ms; |
|
914 | 911 | double correctionInF2; |
|
915 | 912 | |
|
916 | 913 | correctionInF2 = 0; //set to default value (Don_Initialisation_P2) |
|
917 | 914 | |
|
918 | 915 | // get acquisition time in fine time ticks |
|
919 | 916 | acquisitionTime = get_acquisition_time( timePtr ); |
|
920 | 917 | |
|
921 | 918 | // compute center time |
|
922 | 919 | centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667; |
|
923 | 920 | previousTick = centerTime - (centerTime & INT16_ALL_F); |
|
924 | 921 | nextTick = previousTick + TICKS_PER_S; |
|
925 | 922 | |
|
926 | 923 | deltaPreviousTick = centerTime - previousTick; |
|
927 | 924 | deltaNextTick = nextTick - centerTime; |
|
928 | 925 | |
|
929 | 926 | deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S; |
|
930 | 927 | deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S; |
|
931 | 928 | |
|
932 | 929 | PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms); |
|
933 | 930 | |
|
934 | 931 | // which tick is the closest? |
|
935 | 932 | if (deltaPreviousTick > deltaNextTick) |
|
936 | 933 | { |
|
937 | 934 | // the snapshot center is just before the second => increase delta_snapshot |
|
938 | 935 | correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S ); |
|
939 | 936 | } |
|
940 | 937 | else |
|
941 | 938 | { |
|
942 | 939 | // the snapshot center is just after the second => decrease delta_snapshot |
|
943 | 940 | correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S ); |
|
944 | 941 | } |
|
945 | 942 | |
|
946 | 943 | PRINTF1(" correctionInF2 = %.2f\n", correctionInF2); |
|
947 | 944 | |
|
948 | 945 | return correctionInF2; |
|
949 | 946 | } |
|
950 | 947 | |
|
951 | 948 | void applyCorrection( double correction ) |
|
952 | 949 | { |
|
953 | 950 | int correctionInt; |
|
954 | 951 | |
|
955 | 952 | correctionInt = 0; |
|
956 | 953 | |
|
957 | 954 | if (correction >= 0.) |
|
958 | 955 | { |
|
959 | 956 | if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) ) |
|
960 | 957 | { |
|
961 | 958 | correctionInt = ONE_TICK_CORR; |
|
962 | 959 | } |
|
963 | 960 | else |
|
964 | 961 | { |
|
965 | 962 | correctionInt = CORR_MULT * floor(correction); |
|
966 | 963 | } |
|
967 | 964 | } |
|
968 | 965 | else |
|
969 | 966 | { |
|
970 | 967 | if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) ) |
|
971 | 968 | { |
|
972 | 969 | correctionInt = -ONE_TICK_CORR; |
|
973 | 970 | } |
|
974 | 971 | else |
|
975 | 972 | { |
|
976 | 973 | correctionInt = CORR_MULT * ceil(correction); |
|
977 | 974 | } |
|
978 | 975 | } |
|
979 | 976 | waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt; |
|
980 | 977 | } |
|
981 | 978 | |
|
982 | 979 | void snapshot_resynchronization( unsigned char *timePtr ) |
|
983 | 980 | { |
|
984 | 981 | /** This function compute a correction to apply on delta_snapshot. |
|
985 | 982 | * |
|
986 | 983 | * |
|
987 | 984 | * @param timePtr is a pointer to the acquisition time of the snapshot being considered. |
|
988 | 985 | * |
|
989 | 986 | * @return void |
|
990 | 987 | * |
|
991 | 988 | */ |
|
992 | 989 | |
|
993 | 990 | static double correction = INIT_FLOAT; |
|
994 | 991 | static resynchro_state state = MEASURE; |
|
995 | 992 | static unsigned int nbSnapshots = 0; |
|
996 | 993 | |
|
997 | 994 | int correctionInt; |
|
998 | 995 | |
|
999 | 996 | correctionInt = 0; |
|
1000 | 997 | |
|
1001 | 998 | switch (state) |
|
1002 | 999 | { |
|
1003 | 1000 | |
|
1004 | 1001 | case MEASURE: |
|
1005 | 1002 | // ******** |
|
1006 | 1003 | PRINTF1("MEASURE === %d\n", nbSnapshots); |
|
1007 | 1004 | state = CORRECTION; |
|
1008 | 1005 | correction = computeCorrection( timePtr ); |
|
1009 | 1006 | PRINTF1("MEASURE === correction = %.2f\n", correction ); |
|
1010 | 1007 | applyCorrection( correction ); |
|
1011 | 1008 | PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); |
|
1012 | 1009 | //**** |
|
1013 | 1010 | break; |
|
1014 | 1011 | |
|
1015 | 1012 | case CORRECTION: |
|
1016 | 1013 | //************ |
|
1017 | 1014 | PRINTF1("CORRECTION === %d\n", nbSnapshots); |
|
1018 | 1015 | state = MEASURE; |
|
1019 | 1016 | computeCorrection( timePtr ); |
|
1020 | 1017 | set_wfp_delta_snapshot(); |
|
1021 | 1018 | PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); |
|
1022 | 1019 | //**** |
|
1023 | 1020 | break; |
|
1024 | 1021 | |
|
1025 | 1022 | default: |
|
1026 | 1023 | break; |
|
1027 | 1024 | |
|
1028 | 1025 | } |
|
1029 | 1026 | |
|
1030 | 1027 | nbSnapshots++; |
|
1031 | 1028 | } |
|
1032 | 1029 | |
|
1033 | 1030 | //************** |
|
1034 | 1031 | // wfp registers |
|
1035 | 1032 | void reset_wfp_burst_enable( void ) |
|
1036 | 1033 | { |
|
1037 | 1034 | /** This function resets the waveform picker burst_enable register. |
|
1038 | 1035 | * |
|
1039 | 1036 | * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0. |
|
1040 | 1037 | * |
|
1041 | 1038 | */ |
|
1042 | 1039 | |
|
1043 | 1040 | // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0 |
|
1044 | 1041 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN; |
|
1045 | 1042 | } |
|
1046 | 1043 | |
|
1047 | 1044 | void reset_wfp_status( void ) |
|
1048 | 1045 | { |
|
1049 | 1046 | /** This function resets the waveform picker status register. |
|
1050 | 1047 | * |
|
1051 | 1048 | * All status bits are set to 0 [new_err full_err full]. |
|
1052 | 1049 | * |
|
1053 | 1050 | */ |
|
1054 | 1051 | |
|
1055 | 1052 | waveform_picker_regs->status = INT16_ALL_F; |
|
1056 | 1053 | } |
|
1057 | 1054 | |
|
1058 | 1055 | void reset_wfp_buffer_addresses( void ) |
|
1059 | 1056 | { |
|
1060 | 1057 | // F0 |
|
1061 | 1058 | waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08 |
|
1062 | 1059 | waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c |
|
1063 | 1060 | // F1 |
|
1064 | 1061 | waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10 |
|
1065 | 1062 | waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14 |
|
1066 | 1063 | // F2 |
|
1067 | 1064 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18 |
|
1068 | 1065 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c |
|
1069 | 1066 | // F3 |
|
1070 | 1067 | waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20 |
|
1071 | 1068 | waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24 |
|
1072 | 1069 | } |
|
1073 | 1070 | |
|
1074 | 1071 | void reset_waveform_picker_regs( void ) |
|
1075 | 1072 | { |
|
1076 | 1073 | /** This function resets the waveform picker module registers. |
|
1077 | 1074 | * |
|
1078 | 1075 | * The registers affected by this function are located at the following offset addresses: |
|
1079 | 1076 | * - 0x00 data_shaping |
|
1080 | 1077 | * - 0x04 run_burst_enable |
|
1081 | 1078 | * - 0x08 addr_data_f0 |
|
1082 | 1079 | * - 0x0C addr_data_f1 |
|
1083 | 1080 | * - 0x10 addr_data_f2 |
|
1084 | 1081 | * - 0x14 addr_data_f3 |
|
1085 | 1082 | * - 0x18 status |
|
1086 | 1083 | * - 0x1C delta_snapshot |
|
1087 | 1084 | * - 0x20 delta_f0 |
|
1088 | 1085 | * - 0x24 delta_f0_2 |
|
1089 | 1086 | * - 0x28 delta_f1 (obsolet parameter) |
|
1090 | 1087 | * - 0x2c delta_f2 |
|
1091 | 1088 | * - 0x30 nb_data_by_buffer |
|
1092 | 1089 | * - 0x34 nb_snapshot_param |
|
1093 | 1090 | * - 0x38 start_date |
|
1094 | 1091 | * - 0x3c nb_word_in_buffer |
|
1095 | 1092 | * |
|
1096 | 1093 | */ |
|
1097 | 1094 | |
|
1098 | 1095 | set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW |
|
1099 | 1096 | |
|
1100 | 1097 | reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] |
|
1101 | 1098 | |
|
1102 | 1099 | reset_wfp_buffer_addresses(); |
|
1103 | 1100 | |
|
1104 | 1101 | reset_wfp_status(); // 0x18 |
|
1105 | 1102 | |
|
1106 | 1103 | set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff |
|
1107 | 1104 | |
|
1108 | 1105 | set_wfp_delta_f0_f0_2(); // 0x20, 0x24 |
|
1109 | 1106 | |
|
1110 | 1107 | //the parameter delta_f1 [0x28] is not used anymore |
|
1111 | 1108 | |
|
1112 | 1109 | set_wfp_delta_f2(); // 0x2c |
|
1113 | 1110 | |
|
1114 | 1111 | DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot); |
|
1115 | 1112 | DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0); |
|
1116 | 1113 | DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2); |
|
1117 | 1114 | DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1); |
|
1118 | 1115 | DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2); |
|
1119 | 1116 | // 2688 = 8 * 336 |
|
1120 | 1117 | waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1 |
|
1121 | 1118 | waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples |
|
1122 | 1119 | waveform_picker_regs->start_date = COARSE_TIME_MASK; |
|
1123 | 1120 | // |
|
1124 | 1121 | // coarse time and fine time registers are not initialized, they are volatile |
|
1125 | 1122 | // |
|
1126 | 1123 | waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8 |
|
1127 | 1124 | } |
|
1128 | 1125 | |
|
1129 | 1126 | void set_wfp_data_shaping( void ) |
|
1130 | 1127 | { |
|
1131 | 1128 | /** This function sets the data_shaping register of the waveform picker module. |
|
1132 | 1129 | * |
|
1133 | 1130 | * The value is read from one field of the parameter_dump_packet structure:\n |
|
1134 | 1131 | * bw_sp0_sp1_r0_r1 |
|
1135 | 1132 | * |
|
1136 | 1133 | */ |
|
1137 | 1134 | |
|
1138 | 1135 | unsigned char data_shaping; |
|
1139 | 1136 | |
|
1140 | 1137 | // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register |
|
1141 | 1138 | // waveform picker : [R1 R0 SP1 SP0 BW] |
|
1142 | 1139 | |
|
1143 | 1140 | data_shaping = parameter_dump_packet.sy_lfr_common_parameters; |
|
1144 | 1141 | |
|
1145 | 1142 | waveform_picker_regs->data_shaping = |
|
1146 | 1143 | ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW |
|
1147 | 1144 | + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0 |
|
1148 | 1145 | + ( (data_shaping & BIT_3) >> 1 ) // SP1 |
|
1149 | 1146 | + ( (data_shaping & BIT_2) << 1 ) // R0 |
|
1150 | 1147 | + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1 |
|
1151 | 1148 | + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2 |
|
1152 | 1149 | } |
|
1153 | 1150 | |
|
1154 | 1151 | void set_wfp_burst_enable_register( unsigned char mode ) |
|
1155 | 1152 | { |
|
1156 | 1153 | /** This function sets the waveform picker burst_enable register depending on the mode. |
|
1157 | 1154 | * |
|
1158 | 1155 | * @param mode is the LFR mode to launch. |
|
1159 | 1156 | * |
|
1160 | 1157 | * The burst bits shall be before the enable bits. |
|
1161 | 1158 | * |
|
1162 | 1159 | */ |
|
1163 | 1160 | |
|
1164 | 1161 | // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0 |
|
1165 | 1162 | // the burst bits shall be set first, before the enable bits |
|
1166 | 1163 | switch(mode) { |
|
1167 | 1164 | case LFR_MODE_NORMAL: |
|
1168 | 1165 | case LFR_MODE_SBM1: |
|
1169 | 1166 | case LFR_MODE_SBM2: |
|
1170 | 1167 | waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst |
|
1171 | 1168 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_ALL; // [1111] enable f3 f2 f1 f0 |
|
1172 | 1169 | break; |
|
1173 | 1170 | case LFR_MODE_BURST: |
|
1174 | 1171 | waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled |
|
1175 | 1172 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_BURST; // [1100] enable f3 and f2 |
|
1176 | 1173 | break; |
|
1177 | 1174 | default: |
|
1178 | 1175 | waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled |
|
1179 | 1176 | break; |
|
1180 | 1177 | } |
|
1181 | 1178 | } |
|
1182 | 1179 | |
|
1183 | 1180 | void set_wfp_delta_snapshot( void ) |
|
1184 | 1181 | { |
|
1185 | 1182 | /** This function sets the delta_snapshot register of the waveform picker module. |
|
1186 | 1183 | * |
|
1187 | 1184 | * The value is read from two (unsigned char) of the parameter_dump_packet structure: |
|
1188 | 1185 | * - sy_lfr_n_swf_p[0] |
|
1189 | 1186 | * - sy_lfr_n_swf_p[1] |
|
1190 | 1187 | * |
|
1191 | 1188 | */ |
|
1192 | 1189 | |
|
1193 | 1190 | unsigned int delta_snapshot; |
|
1194 | 1191 | unsigned int delta_snapshot_in_T2; |
|
1195 | 1192 | |
|
1196 | 1193 | delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256) |
|
1197 | 1194 | + parameter_dump_packet.sy_lfr_n_swf_p[1]; |
|
1198 | 1195 | |
|
1199 | 1196 | delta_snapshot_in_T2 = delta_snapshot * FREQ_F2; |
|
1200 | 1197 | waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes |
|
1201 | 1198 | } |
|
1202 | 1199 | |
|
1203 | 1200 | void set_wfp_delta_f0_f0_2( void ) |
|
1204 | 1201 | { |
|
1205 | 1202 | unsigned int delta_snapshot; |
|
1206 | 1203 | unsigned int nb_samples_per_snapshot; |
|
1207 | 1204 | float delta_f0_in_float; |
|
1208 | 1205 | |
|
1209 | 1206 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1210 | 1207 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; |
|
1211 | 1208 | delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2; |
|
1212 | 1209 | |
|
1213 | 1210 | waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float ); |
|
1214 | 1211 | waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2; |
|
1215 | 1212 | } |
|
1216 | 1213 | |
|
1217 | 1214 | void set_wfp_delta_f1( void ) |
|
1218 | 1215 | { |
|
1219 | 1216 | /** Sets the value of the delta_f1 parameter |
|
1220 | 1217 | * |
|
1221 | 1218 | * @param void |
|
1222 | 1219 | * |
|
1223 | 1220 | * @return void |
|
1224 | 1221 | * |
|
1225 | 1222 | * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms. |
|
1226 | 1223 | * |
|
1227 | 1224 | */ |
|
1228 | 1225 | |
|
1229 | 1226 | unsigned int delta_snapshot; |
|
1230 | 1227 | unsigned int nb_samples_per_snapshot; |
|
1231 | 1228 | float delta_f1_in_float; |
|
1232 | 1229 | |
|
1233 | 1230 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1234 | 1231 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; |
|
1235 | 1232 | delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2; |
|
1236 | 1233 | |
|
1237 | 1234 | waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float ); |
|
1238 | 1235 | } |
|
1239 | 1236 | |
|
1240 | 1237 | void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used |
|
1241 | 1238 | { |
|
1242 | 1239 | /** Sets the value of the delta_f2 parameter |
|
1243 | 1240 | * |
|
1244 | 1241 | * @param void |
|
1245 | 1242 | * |
|
1246 | 1243 | * @return void |
|
1247 | 1244 | * |
|
1248 | 1245 | * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2 |
|
1249 | 1246 | * waveforms (see lpp_waveform_snapshot_controler.vhd for details). |
|
1250 | 1247 | * |
|
1251 | 1248 | */ |
|
1252 | 1249 | |
|
1253 | 1250 | unsigned int delta_snapshot; |
|
1254 | 1251 | unsigned int nb_samples_per_snapshot; |
|
1255 | 1252 | |
|
1256 | 1253 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1257 | 1254 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; |
|
1258 | 1255 | |
|
1259 | 1256 | waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1; |
|
1260 | 1257 | } |
|
1261 | 1258 | |
|
1262 | 1259 | //***************** |
|
1263 | 1260 | // local parameters |
|
1264 | 1261 | |
|
1265 | 1262 | void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid ) |
|
1266 | 1263 | { |
|
1267 | 1264 | /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument. |
|
1268 | 1265 | * |
|
1269 | 1266 | * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update. |
|
1270 | 1267 | * @param sid is the source identifier of the packet being updated. |
|
1271 | 1268 | * |
|
1272 | 1269 | * REQ-LFR-SRS-5240 / SSS-CP-FS-590 |
|
1273 | 1270 | * The sequence counters shall wrap around from 2^14 to zero. |
|
1274 | 1271 | * The sequence counter shall start at zero at startup. |
|
1275 | 1272 | * |
|
1276 | 1273 | * REQ-LFR-SRS-5239 / SSS-CP-FS-580 |
|
1277 | 1274 | * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0 |
|
1278 | 1275 | * |
|
1279 | 1276 | */ |
|
1280 | 1277 | |
|
1281 | 1278 | unsigned short *sequence_cnt; |
|
1282 | 1279 | unsigned short segmentation_grouping_flag; |
|
1283 | 1280 | unsigned short new_packet_sequence_control; |
|
1284 | 1281 | rtems_mode initial_mode_set; |
|
1285 | 1282 | rtems_mode current_mode_set; |
|
1286 | 1283 | rtems_status_code status; |
|
1287 | 1284 | |
|
1288 | 1285 | initial_mode_set = RTEMS_DEFAULT_MODES; |
|
1289 | 1286 | current_mode_set = RTEMS_DEFAULT_MODES; |
|
1290 | 1287 | sequence_cnt = NULL; |
|
1291 | 1288 | |
|
1292 | 1289 | //****************************************** |
|
1293 | 1290 | // CHANGE THE MODE OF THE CALLING RTEMS TASK |
|
1294 | 1291 | status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set ); |
|
1295 | 1292 | |
|
1296 | 1293 | if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2) |
|
1297 | 1294 | || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3) |
|
1298 | 1295 | || (sid == SID_BURST_CWF_F2) |
|
1299 | 1296 | || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2) |
|
1300 | 1297 | || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2) |
|
1301 | 1298 | || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2) |
|
1302 | 1299 | || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0) |
|
1303 | 1300 | || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) ) |
|
1304 | 1301 | { |
|
1305 | 1302 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST; |
|
1306 | 1303 | } |
|
1307 | 1304 | else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2) |
|
1308 | 1305 | || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0) |
|
1309 | 1306 | || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0) |
|
1310 | 1307 | || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) ) |
|
1311 | 1308 | { |
|
1312 | 1309 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2; |
|
1313 | 1310 | } |
|
1314 | 1311 | else |
|
1315 | 1312 | { |
|
1316 | 1313 | sequence_cnt = (unsigned short *) NULL; |
|
1317 | 1314 | PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid) |
|
1318 | 1315 | } |
|
1319 | 1316 | |
|
1320 | 1317 | if (sequence_cnt != NULL) |
|
1321 | 1318 | { |
|
1322 | 1319 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; |
|
1323 | 1320 | *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK; |
|
1324 | 1321 | |
|
1325 | 1322 | new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ; |
|
1326 | 1323 | |
|
1327 | 1324 | packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE); |
|
1328 | 1325 | packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); |
|
1329 | 1326 | |
|
1330 | 1327 | // increment the sequence counter |
|
1331 | 1328 | if ( *sequence_cnt < SEQ_CNT_MAX) |
|
1332 | 1329 | { |
|
1333 | 1330 | *sequence_cnt = *sequence_cnt + 1; |
|
1334 | 1331 | } |
|
1335 | 1332 | else |
|
1336 | 1333 | { |
|
1337 | 1334 | *sequence_cnt = 0; |
|
1338 | 1335 | } |
|
1339 | 1336 | } |
|
1340 | 1337 | |
|
1341 | 1338 | //************************************* |
|
1342 | 1339 | // RESTORE THE MODE OF THE CALLING TASK |
|
1343 | 1340 | status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, ¤t_mode_set ); |
|
1344 | 1341 | } |
|
1342 |
General Comments 0
You need to be logged in to leave comments.
Login now