@@ -1,1412 +1,1422 | |||||
1 | /** Functions related to the SpaceWire interface. |
|
1 | /** Functions related to the SpaceWire interface. | |
2 | * |
|
2 | * | |
3 | * @file |
|
3 | * @file | |
4 | * @author P. LEROY |
|
4 | * @author P. LEROY | |
5 | * |
|
5 | * | |
6 | * A group of functions to handle SpaceWire transmissions: |
|
6 | * A group of functions to handle SpaceWire transmissions: | |
7 | * - configuration of the SpaceWire link |
|
7 | * - configuration of the SpaceWire link | |
8 | * - SpaceWire related interruption requests processing |
|
8 | * - SpaceWire related interruption requests processing | |
9 | * - transmission of TeleMetry packets by a dedicated RTEMS task |
|
9 | * - transmission of TeleMetry packets by a dedicated RTEMS task | |
10 | * - reception of TeleCommands by a dedicated RTEMS task |
|
10 | * - reception of TeleCommands by a dedicated RTEMS task | |
11 | * |
|
11 | * | |
12 | */ |
|
12 | */ | |
13 |
|
13 | |||
14 | #include "fsw_spacewire.h" |
|
14 | #include "fsw_spacewire.h" | |
15 |
|
15 | |||
16 | rtems_name semq_name; |
|
16 | rtems_name semq_name; | |
17 | rtems_id semq_id; |
|
17 | rtems_id semq_id; | |
18 |
|
18 | |||
19 | //***************** |
|
19 | //***************** | |
20 | // waveform headers |
|
20 | // waveform headers | |
21 | Header_TM_LFR_SCIENCE_CWF_t headerCWF; |
|
21 | Header_TM_LFR_SCIENCE_CWF_t headerCWF; | |
22 | Header_TM_LFR_SCIENCE_SWF_t headerSWF; |
|
22 | Header_TM_LFR_SCIENCE_SWF_t headerSWF; | |
23 | Header_TM_LFR_SCIENCE_ASM_t headerASM; |
|
23 | Header_TM_LFR_SCIENCE_ASM_t headerASM; | |
24 |
|
24 | |||
25 | unsigned char previousTimecodeCtr = 0; |
|
25 | unsigned char previousTimecodeCtr = 0; | |
26 | unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER); |
|
26 | unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER); | |
27 |
|
27 | |||
28 | //*********** |
|
28 | //*********** | |
29 | // RTEMS TASK |
|
29 | // RTEMS TASK | |
30 | rtems_task spiq_task(rtems_task_argument unused) |
|
30 | rtems_task spiq_task(rtems_task_argument unused) | |
31 | { |
|
31 | { | |
32 | /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. |
|
32 | /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. | |
33 | * |
|
33 | * | |
34 | * @param unused is the starting argument of the RTEMS task |
|
34 | * @param unused is the starting argument of the RTEMS task | |
35 | * |
|
35 | * | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | rtems_event_set event_out; |
|
38 | rtems_event_set event_out; | |
39 | rtems_status_code status; |
|
39 | rtems_status_code status; | |
40 | int linkStatus; |
|
40 | int linkStatus; | |
41 |
|
41 | |||
42 | BOOT_PRINTF("in SPIQ *** \n") |
|
42 | BOOT_PRINTF("in SPIQ *** \n") | |
43 |
|
43 | |||
44 | while(true){ |
|
44 | while(true){ | |
45 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT |
|
45 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT | |
46 | PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") |
|
46 | PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") | |
47 |
|
47 | |||
48 | // [0] SUSPEND RECV AND SEND TASKS |
|
48 | // [0] SUSPEND RECV AND SEND TASKS | |
49 | status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); |
|
49 | status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); | |
50 | if ( status != RTEMS_SUCCESSFUL ) { |
|
50 | if ( status != RTEMS_SUCCESSFUL ) { | |
51 | PRINTF("in SPIQ *** ERR suspending RECV Task\n") |
|
51 | PRINTF("in SPIQ *** ERR suspending RECV Task\n") | |
52 | } |
|
52 | } | |
53 | status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); |
|
53 | status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); | |
54 | if ( status != RTEMS_SUCCESSFUL ) { |
|
54 | if ( status != RTEMS_SUCCESSFUL ) { | |
55 | PRINTF("in SPIQ *** ERR suspending SEND Task\n") |
|
55 | PRINTF("in SPIQ *** ERR suspending SEND Task\n") | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | // [1] CHECK THE LINK |
|
58 | // [1] CHECK THE LINK | |
59 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) |
|
59 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) | |
60 | if ( linkStatus != 5) { |
|
60 | if ( linkStatus != 5) { | |
61 | PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) |
|
61 | PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) | |
62 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms |
|
62 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT |
|
65 | // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT | |
66 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) |
|
66 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) | |
67 | if ( linkStatus != 5 ) // [2.a] not in run state, reset the link |
|
67 | if ( linkStatus != 5 ) // [2.a] not in run state, reset the link | |
68 | { |
|
68 | { | |
69 | spacewire_compute_stats_offsets(); |
|
69 | spacewire_compute_stats_offsets(); | |
70 | status = spacewire_reset_link( ); |
|
70 | status = spacewire_reset_link( ); | |
71 | } |
|
71 | } | |
72 | else // [2.b] in run state, start the link |
|
72 | else // [2.b] in run state, start the link | |
73 | { |
|
73 | { | |
74 | status = spacewire_stop_and_start_link( fdSPW ); // start the link |
|
74 | status = spacewire_stop_and_start_link( fdSPW ); // start the link | |
75 | if ( status != RTEMS_SUCCESSFUL) |
|
75 | if ( status != RTEMS_SUCCESSFUL) | |
76 | { |
|
76 | { | |
77 | PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status) |
|
77 | PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status) | |
78 | } |
|
78 | } | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS |
|
81 | // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS | |
82 | if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully |
|
82 | if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully | |
83 | { |
|
83 | { | |
84 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); |
|
84 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); | |
85 | if ( status != RTEMS_SUCCESSFUL ) { |
|
85 | if ( status != RTEMS_SUCCESSFUL ) { | |
86 | PRINTF("in SPIQ *** ERR resuming SEND Task\n") |
|
86 | PRINTF("in SPIQ *** ERR resuming SEND Task\n") | |
87 | } |
|
87 | } | |
88 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); |
|
88 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); | |
89 | if ( status != RTEMS_SUCCESSFUL ) { |
|
89 | if ( status != RTEMS_SUCCESSFUL ) { | |
90 | PRINTF("in SPIQ *** ERR resuming RECV Task\n") |
|
90 | PRINTF("in SPIQ *** ERR resuming RECV Task\n") | |
91 | } |
|
91 | } | |
92 | } |
|
92 | } | |
93 | else // [3.b] the link is not in run state, go in STANDBY mode |
|
93 | else // [3.b] the link is not in run state, go in STANDBY mode | |
94 | { |
|
94 | { | |
95 | status = enter_mode_standby(); |
|
95 | status = enter_mode_standby(); | |
96 | if ( status != RTEMS_SUCCESSFUL ) { |
|
96 | if ( status != RTEMS_SUCCESSFUL ) { | |
97 | PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) |
|
97 | PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) | |
98 | } |
|
98 | } | |
99 | // wake the WTDG task up to wait for the link recovery |
|
99 | // wake the WTDG task up to wait for the link recovery | |
100 | status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 ); |
|
100 | status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 ); | |
101 | status = rtems_task_suspend( RTEMS_SELF ); |
|
101 | status = rtems_task_suspend( RTEMS_SELF ); | |
102 | } |
|
102 | } | |
103 | } |
|
103 | } | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | rtems_task recv_task( rtems_task_argument unused ) |
|
106 | rtems_task recv_task( rtems_task_argument unused ) | |
107 | { |
|
107 | { | |
108 | /** This RTEMS task is dedicated to the reception of incoming TeleCommands. |
|
108 | /** This RTEMS task is dedicated to the reception of incoming TeleCommands. | |
109 | * |
|
109 | * | |
110 | * @param unused is the starting argument of the RTEMS task |
|
110 | * @param unused is the starting argument of the RTEMS task | |
111 | * |
|
111 | * | |
112 | * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: |
|
112 | * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: | |
113 | * 1. It reads the incoming data. |
|
113 | * 1. It reads the incoming data. | |
114 | * 2. Launches the acceptance procedure. |
|
114 | * 2. Launches the acceptance procedure. | |
115 | * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. |
|
115 | * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. | |
116 | * |
|
116 | * | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | int len; |
|
119 | int len; | |
120 | ccsdsTelecommandPacket_t currentTC; |
|
120 | ccsdsTelecommandPacket_t currentTC; | |
121 | unsigned char computed_CRC[ 2 ]; |
|
121 | unsigned char computed_CRC[ 2 ]; | |
122 | unsigned char currentTC_LEN_RCV[ 2 ]; |
|
122 | unsigned char currentTC_LEN_RCV[ 2 ]; | |
123 | unsigned char destinationID; |
|
123 | unsigned char destinationID; | |
124 | unsigned int estimatedPacketLength; |
|
124 | unsigned int estimatedPacketLength; | |
125 | unsigned int parserCode; |
|
125 | unsigned int parserCode; | |
126 | rtems_status_code status; |
|
126 | rtems_status_code status; | |
127 | rtems_id queue_recv_id; |
|
127 | rtems_id queue_recv_id; | |
128 | rtems_id queue_send_id; |
|
128 | rtems_id queue_send_id; | |
129 |
|
129 | |||
130 | initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes |
|
130 | initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes | |
131 |
|
131 | |||
132 | status = get_message_queue_id_recv( &queue_recv_id ); |
|
132 | status = get_message_queue_id_recv( &queue_recv_id ); | |
133 | if (status != RTEMS_SUCCESSFUL) |
|
133 | if (status != RTEMS_SUCCESSFUL) | |
134 | { |
|
134 | { | |
135 | PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) |
|
135 | PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | status = get_message_queue_id_send( &queue_send_id ); |
|
138 | status = get_message_queue_id_send( &queue_send_id ); | |
139 | if (status != RTEMS_SUCCESSFUL) |
|
139 | if (status != RTEMS_SUCCESSFUL) | |
140 | { |
|
140 | { | |
141 | PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) |
|
141 | PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | BOOT_PRINTF("in RECV *** \n") |
|
144 | BOOT_PRINTF("in RECV *** \n") | |
145 |
|
145 | |||
146 | while(1) |
|
146 | while(1) | |
147 | { |
|
147 | { | |
148 | len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking |
|
148 | len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking | |
149 | if (len == -1){ // error during the read call |
|
149 | if (len == -1){ // error during the read call | |
150 | PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) |
|
150 | PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) | |
151 | } |
|
151 | } | |
152 | else { |
|
152 | else { | |
153 | if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { |
|
153 | if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { | |
154 | PRINTF("in RECV *** packet lenght too short\n") |
|
154 | PRINTF("in RECV *** packet lenght too short\n") | |
155 | } |
|
155 | } | |
156 | else { |
|
156 | else { | |
157 | estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes |
|
157 | estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes | |
158 | currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8); |
|
158 | currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8); | |
159 | currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength ); |
|
159 | currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength ); | |
160 | // CHECK THE TC |
|
160 | // CHECK THE TC | |
161 | parserCode = tc_parser( ¤tTC, estimatedPacketLength, computed_CRC ) ; |
|
161 | parserCode = tc_parser( ¤tTC, estimatedPacketLength, computed_CRC ) ; | |
162 | if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) |
|
162 | if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) | |
163 | || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) |
|
163 | || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) | |
164 | || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) |
|
164 | || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) | |
165 | || (parserCode == WRONG_SRC_ID) ) |
|
165 | || (parserCode == WRONG_SRC_ID) ) | |
166 | { // send TM_LFR_TC_EXE_CORRUPTED |
|
166 | { // send TM_LFR_TC_EXE_CORRUPTED | |
167 | PRINTF1("TC corrupted received, with code: %d\n", parserCode) |
|
167 | PRINTF1("TC corrupted received, with code: %d\n", parserCode) | |
168 | if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
168 | if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) | |
169 | && |
|
169 | && | |
170 | !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
170 | !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) | |
171 | ) |
|
171 | ) | |
172 | { |
|
172 | { | |
173 | if ( parserCode == WRONG_SRC_ID ) |
|
173 | if ( parserCode == WRONG_SRC_ID ) | |
174 | { |
|
174 | { | |
175 | destinationID = SID_TC_GROUND; |
|
175 | destinationID = SID_TC_GROUND; | |
176 | } |
|
176 | } | |
177 | else |
|
177 | else | |
178 | { |
|
178 | { | |
179 | destinationID = currentTC.sourceID; |
|
179 | destinationID = currentTC.sourceID; | |
180 | } |
|
180 | } | |
181 | send_tm_lfr_tc_exe_corrupted( ¤tTC, queue_send_id, |
|
181 | send_tm_lfr_tc_exe_corrupted( ¤tTC, queue_send_id, | |
182 | computed_CRC, currentTC_LEN_RCV, |
|
182 | computed_CRC, currentTC_LEN_RCV, | |
183 | destinationID ); |
|
183 | destinationID ); | |
184 | } |
|
184 | } | |
185 | } |
|
185 | } | |
186 | else |
|
186 | else | |
187 | { // send valid TC to the action launcher |
|
187 | { // send valid TC to the action launcher | |
188 | status = rtems_message_queue_send( queue_recv_id, ¤tTC, |
|
188 | status = rtems_message_queue_send( queue_recv_id, ¤tTC, | |
189 | estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3); |
|
189 | estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3); | |
190 | } |
|
190 | } | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max ); |
|
194 | update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max ); | |
195 |
|
195 | |||
196 | } |
|
196 | } | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | rtems_task send_task( rtems_task_argument argument) |
|
199 | rtems_task send_task( rtems_task_argument argument) | |
200 | { |
|
200 | { | |
201 | /** This RTEMS task is dedicated to the transmission of TeleMetry packets. |
|
201 | /** This RTEMS task is dedicated to the transmission of TeleMetry packets. | |
202 | * |
|
202 | * | |
203 | * @param unused is the starting argument of the RTEMS task |
|
203 | * @param unused is the starting argument of the RTEMS task | |
204 | * |
|
204 | * | |
205 | * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: |
|
205 | * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: | |
206 | * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. |
|
206 | * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. | |
207 | * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After |
|
207 | * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After | |
208 | * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the |
|
208 | * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the | |
209 | * data it contains. |
|
209 | * data it contains. | |
210 | * |
|
210 | * | |
211 | */ |
|
211 | */ | |
212 |
|
212 | |||
213 | rtems_status_code status; // RTEMS status code |
|
213 | rtems_status_code status; // RTEMS status code | |
214 | char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer |
|
214 | char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer | |
215 | ring_node *incomingRingNodePtr; |
|
215 | ring_node *incomingRingNodePtr; | |
216 | int ring_node_address; |
|
216 | int ring_node_address; | |
217 | char *charPtr; |
|
217 | char *charPtr; | |
218 | spw_ioctl_pkt_send *spw_ioctl_send; |
|
218 | spw_ioctl_pkt_send *spw_ioctl_send; | |
219 | size_t size; // size of the incoming TC packet |
|
219 | size_t size; // size of the incoming TC packet | |
220 | rtems_id queue_send_id; |
|
220 | rtems_id queue_send_id; | |
221 | unsigned int sid; |
|
221 | unsigned int sid; | |
222 | unsigned char sidAsUnsignedChar; |
|
222 | unsigned char sidAsUnsignedChar; | |
223 | unsigned char type; |
|
223 | unsigned char type; | |
224 |
|
224 | |||
225 | incomingRingNodePtr = NULL; |
|
225 | incomingRingNodePtr = NULL; | |
226 | ring_node_address = 0; |
|
226 | ring_node_address = 0; | |
227 | charPtr = (char *) &ring_node_address; |
|
227 | charPtr = (char *) &ring_node_address; | |
228 | sid = 0; |
|
228 | sid = 0; | |
229 | sidAsUnsignedChar = 0; |
|
229 | sidAsUnsignedChar = 0; | |
230 |
|
230 | |||
231 | init_header_cwf( &headerCWF ); |
|
231 | init_header_cwf( &headerCWF ); | |
232 | init_header_swf( &headerSWF ); |
|
232 | init_header_swf( &headerSWF ); | |
233 | init_header_asm( &headerASM ); |
|
233 | init_header_asm( &headerASM ); | |
234 |
|
234 | |||
235 | status = get_message_queue_id_send( &queue_send_id ); |
|
235 | status = get_message_queue_id_send( &queue_send_id ); | |
236 | if (status != RTEMS_SUCCESSFUL) |
|
236 | if (status != RTEMS_SUCCESSFUL) | |
237 | { |
|
237 | { | |
238 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) |
|
238 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | BOOT_PRINTF("in SEND *** \n") |
|
241 | BOOT_PRINTF("in SEND *** \n") | |
242 |
|
242 | |||
243 | while(1) |
|
243 | while(1) | |
244 | { |
|
244 | { | |
245 | status = rtems_message_queue_receive( queue_send_id, incomingData, &size, |
|
245 | status = rtems_message_queue_receive( queue_send_id, incomingData, &size, | |
246 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
|
246 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); | |
247 |
|
247 | |||
248 | if (status!=RTEMS_SUCCESSFUL) |
|
248 | if (status!=RTEMS_SUCCESSFUL) | |
249 | { |
|
249 | { | |
250 | PRINTF1("in SEND *** (1) ERR = %d\n", status) |
|
250 | PRINTF1("in SEND *** (1) ERR = %d\n", status) | |
251 | } |
|
251 | } | |
252 | else |
|
252 | else | |
253 | { |
|
253 | { | |
254 | if ( size == sizeof(ring_node*) ) |
|
254 | if ( size == sizeof(ring_node*) ) | |
255 | { |
|
255 | { | |
256 | charPtr[0] = incomingData[0]; |
|
256 | charPtr[0] = incomingData[0]; | |
257 | charPtr[1] = incomingData[1]; |
|
257 | charPtr[1] = incomingData[1]; | |
258 | charPtr[2] = incomingData[2]; |
|
258 | charPtr[2] = incomingData[2]; | |
259 | charPtr[3] = incomingData[3]; |
|
259 | charPtr[3] = incomingData[3]; | |
260 | incomingRingNodePtr = (ring_node*) ring_node_address; |
|
260 | incomingRingNodePtr = (ring_node*) ring_node_address; | |
261 | sid = incomingRingNodePtr->sid; |
|
261 | sid = incomingRingNodePtr->sid; | |
262 | if ( (sid==SID_NORM_CWF_LONG_F3) |
|
262 | if ( (sid==SID_NORM_CWF_LONG_F3) | |
263 | || (sid==SID_BURST_CWF_F2 ) |
|
263 | || (sid==SID_BURST_CWF_F2 ) | |
264 | || (sid==SID_SBM1_CWF_F1 ) |
|
264 | || (sid==SID_SBM1_CWF_F1 ) | |
265 | || (sid==SID_SBM2_CWF_F2 )) |
|
265 | || (sid==SID_SBM2_CWF_F2 )) | |
266 | { |
|
266 | { | |
267 | spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF ); |
|
267 | spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF ); | |
268 | } |
|
268 | } | |
269 | else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) ) |
|
269 | else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) ) | |
270 | { |
|
270 | { | |
271 | spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF ); |
|
271 | spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF ); | |
272 | } |
|
272 | } | |
273 | else if ( (sid==SID_NORM_CWF_F3) ) |
|
273 | else if ( (sid==SID_NORM_CWF_F3) ) | |
274 | { |
|
274 | { | |
275 | spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF ); |
|
275 | spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF ); | |
276 | } |
|
276 | } | |
277 | else if (sid==SID_NORM_ASM_F0) |
|
277 | else if (sid==SID_NORM_ASM_F0) | |
278 | { |
|
278 | { | |
279 | spw_send_asm_f0( incomingRingNodePtr, &headerASM ); |
|
279 | spw_send_asm_f0( incomingRingNodePtr, &headerASM ); | |
280 | } |
|
280 | } | |
281 | else if (sid==SID_NORM_ASM_F1) |
|
281 | else if (sid==SID_NORM_ASM_F1) | |
282 | { |
|
282 | { | |
283 | spw_send_asm_f1( incomingRingNodePtr, &headerASM ); |
|
283 | spw_send_asm_f1( incomingRingNodePtr, &headerASM ); | |
284 | } |
|
284 | } | |
285 | else if (sid==SID_NORM_ASM_F2) |
|
285 | else if (sid==SID_NORM_ASM_F2) | |
286 | { |
|
286 | { | |
287 | spw_send_asm_f2( incomingRingNodePtr, &headerASM ); |
|
287 | spw_send_asm_f2( incomingRingNodePtr, &headerASM ); | |
288 | } |
|
288 | } | |
289 | else if ( sid==TM_CODE_K_DUMP ) |
|
289 | else if ( sid==TM_CODE_K_DUMP ) | |
290 | { |
|
290 | { | |
291 | spw_send_k_dump( incomingRingNodePtr ); |
|
291 | spw_send_k_dump( incomingRingNodePtr ); | |
292 | } |
|
292 | } | |
293 | else |
|
293 | else | |
294 | { |
|
294 | { | |
295 | PRINTF1("unexpected sid = %d\n", sid); |
|
295 | PRINTF1("unexpected sid = %d\n", sid); | |
296 | } |
|
296 | } | |
297 | } |
|
297 | } | |
298 | else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet |
|
298 | else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet | |
299 | { |
|
299 | { | |
300 | sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ]; |
|
300 | sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ]; | |
301 | sid = sidAsUnsignedChar; |
|
301 | sid = sidAsUnsignedChar; | |
302 | type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ]; |
|
302 | type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ]; | |
303 | if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently |
|
303 | if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently | |
304 | // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS |
|
304 | // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS | |
305 | { |
|
305 | { | |
306 | increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid ); |
|
306 | increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid ); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | status = write( fdSPW, incomingData, size ); |
|
309 | status = write( fdSPW, incomingData, size ); | |
310 | if (status == -1){ |
|
310 | if (status == -1){ | |
311 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) |
|
311 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) | |
312 | } |
|
312 | } | |
313 | } |
|
313 | } | |
314 | else // the incoming message is a spw_ioctl_pkt_send structure |
|
314 | else // the incoming message is a spw_ioctl_pkt_send structure | |
315 | { |
|
315 | { | |
316 | spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData; |
|
316 | spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData; | |
317 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); |
|
317 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); | |
318 | if (status == -1){ |
|
318 | if (status == -1){ | |
319 | PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status) |
|
319 | PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status) | |
320 | } |
|
320 | } | |
321 | } |
|
321 | } | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max ); |
|
324 | update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max ); | |
325 |
|
325 | |||
326 | } |
|
326 | } | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | rtems_task wtdg_task( rtems_task_argument argument ) |
|
329 | rtems_task wtdg_task( rtems_task_argument argument ) | |
330 | { |
|
330 | { | |
331 | rtems_event_set event_out; |
|
331 | rtems_event_set event_out; | |
332 | rtems_status_code status; |
|
332 | rtems_status_code status; | |
333 | int linkStatus; |
|
333 | int linkStatus; | |
334 |
|
334 | |||
335 | BOOT_PRINTF("in WTDG ***\n") |
|
335 | BOOT_PRINTF("in WTDG ***\n") | |
336 |
|
336 | |||
337 | while(1) |
|
337 | while(1) | |
338 | { |
|
338 | { | |
339 | // wait for an RTEMS_EVENT |
|
339 | // wait for an RTEMS_EVENT | |
340 | rtems_event_receive( RTEMS_EVENT_0, |
|
340 | rtems_event_receive( RTEMS_EVENT_0, | |
341 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
341 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | |
342 | PRINTF("in WTDG *** wait for the link\n") |
|
342 | PRINTF("in WTDG *** wait for the link\n") | |
343 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status |
|
343 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status | |
344 | while( linkStatus != 5) // wait for the link |
|
344 | while( linkStatus != 5) // wait for the link | |
345 | { |
|
345 | { | |
346 | status = rtems_task_wake_after( 10 ); // monitor the link each 100ms |
|
346 | status = rtems_task_wake_after( 10 ); // monitor the link each 100ms | |
347 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status |
|
347 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | status = spacewire_stop_and_start_link( fdSPW ); |
|
350 | status = spacewire_stop_and_start_link( fdSPW ); | |
351 |
|
351 | |||
352 | if (status != RTEMS_SUCCESSFUL) |
|
352 | if (status != RTEMS_SUCCESSFUL) | |
353 | { |
|
353 | { | |
354 | PRINTF1("in WTDG *** ERR link not started %d\n", status) |
|
354 | PRINTF1("in WTDG *** ERR link not started %d\n", status) | |
355 | } |
|
355 | } | |
356 | else |
|
356 | else | |
357 | { |
|
357 | { | |
358 | PRINTF("in WTDG *** OK link started\n") |
|
358 | PRINTF("in WTDG *** OK link started\n") | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | // restart the SPIQ task |
|
361 | // restart the SPIQ task | |
362 | status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 ); |
|
362 | status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 ); | |
363 | if ( status != RTEMS_SUCCESSFUL ) { |
|
363 | if ( status != RTEMS_SUCCESSFUL ) { | |
364 | PRINTF("in SPIQ *** ERR restarting SPIQ Task\n") |
|
364 | PRINTF("in SPIQ *** ERR restarting SPIQ Task\n") | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | // restart RECV and SEND |
|
367 | // restart RECV and SEND | |
368 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); |
|
368 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); | |
369 | if ( status != RTEMS_SUCCESSFUL ) { |
|
369 | if ( status != RTEMS_SUCCESSFUL ) { | |
370 | PRINTF("in SPIQ *** ERR restarting SEND Task\n") |
|
370 | PRINTF("in SPIQ *** ERR restarting SEND Task\n") | |
371 | } |
|
371 | } | |
372 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); |
|
372 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); | |
373 | if ( status != RTEMS_SUCCESSFUL ) { |
|
373 | if ( status != RTEMS_SUCCESSFUL ) { | |
374 | PRINTF("in SPIQ *** ERR restarting RECV Task\n") |
|
374 | PRINTF("in SPIQ *** ERR restarting RECV Task\n") | |
375 | } |
|
375 | } | |
376 | } |
|
376 | } | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | //**************** |
|
379 | //**************** | |
380 | // OTHER FUNCTIONS |
|
380 | // OTHER FUNCTIONS | |
381 | int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);] |
|
381 | int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);] | |
382 | { |
|
382 | { | |
383 | /** This function opens the SpaceWire link. |
|
383 | /** This function opens the SpaceWire link. | |
384 | * |
|
384 | * | |
385 | * @return a valid file descriptor in case of success, -1 in case of a failure |
|
385 | * @return a valid file descriptor in case of success, -1 in case of a failure | |
386 | * |
|
386 | * | |
387 | */ |
|
387 | */ | |
388 | rtems_status_code status; |
|
388 | rtems_status_code status; | |
389 |
|
389 | |||
390 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware |
|
390 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware | |
391 | if ( fdSPW < 0 ) { |
|
391 | if ( fdSPW < 0 ) { | |
392 | PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno) |
|
392 | PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno) | |
393 | } |
|
393 | } | |
394 | else |
|
394 | else | |
395 | { |
|
395 | { | |
396 | status = RTEMS_SUCCESSFUL; |
|
396 | status = RTEMS_SUCCESSFUL; | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | return status; |
|
399 | return status; | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | int spacewire_start_link( int fd ) |
|
402 | int spacewire_start_link( int fd ) | |
403 | { |
|
403 | { | |
404 | rtems_status_code status; |
|
404 | rtems_status_code status; | |
405 |
|
405 | |||
406 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started |
|
406 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started | |
407 | // -1 default hardcoded driver timeout |
|
407 | // -1 default hardcoded driver timeout | |
408 |
|
408 | |||
409 | return status; |
|
409 | return status; | |
410 | } |
|
410 | } | |
411 |
|
411 | |||
412 | int spacewire_stop_and_start_link( int fd ) |
|
412 | int spacewire_stop_and_start_link( int fd ) | |
413 | { |
|
413 | { | |
414 | rtems_status_code status; |
|
414 | rtems_status_code status; | |
415 |
|
415 | |||
416 | status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0 |
|
416 | status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0 | |
417 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started |
|
417 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started | |
418 | // -1 default hardcoded driver timeout |
|
418 | // -1 default hardcoded driver timeout | |
419 |
|
419 | |||
420 | return status; |
|
420 | return status; | |
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | int spacewire_configure_link( int fd ) |
|
423 | int spacewire_configure_link( int fd ) | |
424 | { |
|
424 | { | |
425 | /** This function configures the SpaceWire link. |
|
425 | /** This function configures the SpaceWire link. | |
426 | * |
|
426 | * | |
427 | * @return GR-RTEMS-DRIVER directive status codes: |
|
427 | * @return GR-RTEMS-DRIVER directive status codes: | |
428 | * - 22 EINVAL - Null pointer or an out of range value was given as the argument. |
|
428 | * - 22 EINVAL - Null pointer or an out of range value was given as the argument. | |
429 | * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode. |
|
429 | * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode. | |
430 | * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used. |
|
430 | * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used. | |
431 | * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up. |
|
431 | * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up. | |
432 | * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers. |
|
432 | * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers. | |
433 | * - 5 EIO - Error when writing to grswp hardware registers. |
|
433 | * - 5 EIO - Error when writing to grswp hardware registers. | |
434 | * - 2 ENOENT - No such file or directory |
|
434 | * - 2 ENOENT - No such file or directory | |
435 | */ |
|
435 | */ | |
436 |
|
436 | |||
437 | rtems_status_code status; |
|
437 | rtems_status_code status; | |
438 |
|
438 | |||
439 | spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force |
|
439 | spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force | |
440 | spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration |
|
440 | spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration | |
441 |
|
441 | |||
442 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception |
|
442 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception | |
443 | if (status!=RTEMS_SUCCESSFUL) { |
|
443 | if (status!=RTEMS_SUCCESSFUL) { | |
444 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") |
|
444 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") | |
445 | } |
|
445 | } | |
446 | // |
|
446 | // | |
447 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a |
|
447 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a | |
448 | if (status!=RTEMS_SUCCESSFUL) { |
|
448 | if (status!=RTEMS_SUCCESSFUL) { | |
449 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs |
|
449 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs | |
450 | } |
|
450 | } | |
451 | // |
|
451 | // | |
452 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts |
|
452 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts | |
453 | if (status!=RTEMS_SUCCESSFUL) { |
|
453 | if (status!=RTEMS_SUCCESSFUL) { | |
454 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") |
|
454 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") | |
455 | } |
|
455 | } | |
456 | // |
|
456 | // | |
457 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit |
|
457 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit | |
458 | if (status!=RTEMS_SUCCESSFUL) { |
|
458 | if (status!=RTEMS_SUCCESSFUL) { | |
459 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") |
|
459 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") | |
460 | } |
|
460 | } | |
461 | // |
|
461 | // | |
462 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks |
|
462 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks | |
463 | if (status!=RTEMS_SUCCESSFUL) { |
|
463 | if (status!=RTEMS_SUCCESSFUL) { | |
464 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n") |
|
464 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n") | |
465 | } |
|
465 | } | |
466 | // |
|
466 | // | |
467 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available |
|
467 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available | |
468 | if (status!=RTEMS_SUCCESSFUL) { |
|
468 | if (status!=RTEMS_SUCCESSFUL) { | |
469 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") |
|
469 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") | |
470 | } |
|
470 | } | |
471 | // |
|
471 | // | |
472 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ] |
|
472 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ] | |
473 | if (status!=RTEMS_SUCCESSFUL) { |
|
473 | if (status!=RTEMS_SUCCESSFUL) { | |
474 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n") |
|
474 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n") | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | return status; |
|
477 | return status; | |
478 | } |
|
478 | } | |
479 |
|
479 | |||
480 | int spacewire_reset_link( void ) |
|
480 | int spacewire_reset_link( void ) | |
481 | { |
|
481 | { | |
482 | /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver. |
|
482 | /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver. | |
483 | * |
|
483 | * | |
484 | * @return RTEMS directive status code: |
|
484 | * @return RTEMS directive status code: | |
485 | * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s. |
|
485 | * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s. | |
486 | * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout. |
|
486 | * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout. | |
487 | * |
|
487 | * | |
488 | */ |
|
488 | */ | |
489 |
|
489 | |||
490 | rtems_status_code status_spw; |
|
490 | rtems_status_code status_spw; | |
491 | rtems_status_code status; |
|
491 | rtems_status_code status; | |
492 | int i; |
|
492 | int i; | |
493 |
|
493 | |||
494 | for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ ) |
|
494 | for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ ) | |
495 | { |
|
495 | { | |
496 | PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i); |
|
496 | PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i); | |
497 |
|
497 | |||
498 | // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM |
|
498 | // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM | |
499 |
|
499 | |||
500 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms |
|
500 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms | |
501 |
|
501 | |||
502 | status_spw = spacewire_stop_and_start_link( fdSPW ); |
|
502 | status_spw = spacewire_stop_and_start_link( fdSPW ); | |
503 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
503 | if ( status_spw != RTEMS_SUCCESSFUL ) | |
504 | { |
|
504 | { | |
505 | PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw) |
|
505 | PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw) | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | if ( status_spw == RTEMS_SUCCESSFUL) |
|
508 | if ( status_spw == RTEMS_SUCCESSFUL) | |
509 | { |
|
509 | { | |
510 | break; |
|
510 | break; | |
511 | } |
|
511 | } | |
512 | } |
|
512 | } | |
513 |
|
513 | |||
514 | return status_spw; |
|
514 | return status_spw; | |
515 | } |
|
515 | } | |
516 |
|
516 | |||
517 | void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force |
|
517 | void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force | |
518 | { |
|
518 | { | |
519 | /** This function sets the [N]o [P]ort force bit of the GRSPW control register. |
|
519 | /** This function sets the [N]o [P]ort force bit of the GRSPW control register. | |
520 | * |
|
520 | * | |
521 | * @param val is the value, 0 or 1, used to set the value of the NP bit. |
|
521 | * @param val is the value, 0 or 1, used to set the value of the NP bit. | |
522 | * @param regAddr is the address of the GRSPW control register. |
|
522 | * @param regAddr is the address of the GRSPW control register. | |
523 | * |
|
523 | * | |
524 | * NP is the bit 20 of the GRSPW control register. |
|
524 | * NP is the bit 20 of the GRSPW control register. | |
525 | * |
|
525 | * | |
526 | */ |
|
526 | */ | |
527 |
|
527 | |||
528 | unsigned int *spwptr = (unsigned int*) regAddr; |
|
528 | unsigned int *spwptr = (unsigned int*) regAddr; | |
529 |
|
529 | |||
530 | if (val == 1) { |
|
530 | if (val == 1) { | |
531 | *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit |
|
531 | *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit | |
532 | } |
|
532 | } | |
533 | if (val== 0) { |
|
533 | if (val== 0) { | |
534 | *spwptr = *spwptr & 0xffdfffff; |
|
534 | *spwptr = *spwptr & 0xffdfffff; | |
535 | } |
|
535 | } | |
536 | } |
|
536 | } | |
537 |
|
537 | |||
538 | void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable |
|
538 | void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable | |
539 | { |
|
539 | { | |
540 | /** This function sets the [R]MAP [E]nable bit of the GRSPW control register. |
|
540 | /** This function sets the [R]MAP [E]nable bit of the GRSPW control register. | |
541 | * |
|
541 | * | |
542 | * @param val is the value, 0 or 1, used to set the value of the RE bit. |
|
542 | * @param val is the value, 0 or 1, used to set the value of the RE bit. | |
543 | * @param regAddr is the address of the GRSPW control register. |
|
543 | * @param regAddr is the address of the GRSPW control register. | |
544 | * |
|
544 | * | |
545 | * RE is the bit 16 of the GRSPW control register. |
|
545 | * RE is the bit 16 of the GRSPW control register. | |
546 | * |
|
546 | * | |
547 | */ |
|
547 | */ | |
548 |
|
548 | |||
549 | unsigned int *spwptr = (unsigned int*) regAddr; |
|
549 | unsigned int *spwptr = (unsigned int*) regAddr; | |
550 |
|
550 | |||
551 | if (val == 1) |
|
551 | if (val == 1) | |
552 | { |
|
552 | { | |
553 | *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit |
|
553 | *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit | |
554 | } |
|
554 | } | |
555 | if (val== 0) |
|
555 | if (val== 0) | |
556 | { |
|
556 | { | |
557 | *spwptr = *spwptr & 0xfffdffff; |
|
557 | *spwptr = *spwptr & 0xfffdffff; | |
558 | } |
|
558 | } | |
559 | } |
|
559 | } | |
560 |
|
560 | |||
561 | void spacewire_compute_stats_offsets( void ) |
|
561 | void spacewire_compute_stats_offsets( void ) | |
562 | { |
|
562 | { | |
563 | /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising. |
|
563 | /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising. | |
564 | * |
|
564 | * | |
565 | * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics |
|
565 | * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics | |
566 | * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it |
|
566 | * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it | |
567 | * during the open systel call). |
|
567 | * during the open systel call). | |
568 | * |
|
568 | * | |
569 | */ |
|
569 | */ | |
570 |
|
570 | |||
571 | spw_stats spacewire_stats_grspw; |
|
571 | spw_stats spacewire_stats_grspw; | |
572 | rtems_status_code status; |
|
572 | rtems_status_code status; | |
573 |
|
573 | |||
574 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw ); |
|
574 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw ); | |
575 |
|
575 | |||
576 | spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received |
|
576 | spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received | |
577 | + spacewire_stats.packets_received; |
|
577 | + spacewire_stats.packets_received; | |
578 | spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent |
|
578 | spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent | |
579 | + spacewire_stats.packets_sent; |
|
579 | + spacewire_stats.packets_sent; | |
580 | spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err |
|
580 | spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err | |
581 | + spacewire_stats.parity_err; |
|
581 | + spacewire_stats.parity_err; | |
582 | spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err |
|
582 | spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err | |
583 | + spacewire_stats.disconnect_err; |
|
583 | + spacewire_stats.disconnect_err; | |
584 | spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err |
|
584 | spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err | |
585 | + spacewire_stats.escape_err; |
|
585 | + spacewire_stats.escape_err; | |
586 | spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err |
|
586 | spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err | |
587 | + spacewire_stats.credit_err; |
|
587 | + spacewire_stats.credit_err; | |
588 | spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err |
|
588 | spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err | |
589 | + spacewire_stats.write_sync_err; |
|
589 | + spacewire_stats.write_sync_err; | |
590 | spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err |
|
590 | spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err | |
591 | + spacewire_stats.rx_rmap_header_crc_err; |
|
591 | + spacewire_stats.rx_rmap_header_crc_err; | |
592 | spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err |
|
592 | spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err | |
593 | + spacewire_stats.rx_rmap_data_crc_err; |
|
593 | + spacewire_stats.rx_rmap_data_crc_err; | |
594 | spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep |
|
594 | spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep | |
595 | + spacewire_stats.early_ep; |
|
595 | + spacewire_stats.early_ep; | |
596 | spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address |
|
596 | spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address | |
597 | + spacewire_stats.invalid_address; |
|
597 | + spacewire_stats.invalid_address; | |
598 | spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err |
|
598 | spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err | |
599 | + spacewire_stats.rx_eep_err; |
|
599 | + spacewire_stats.rx_eep_err; | |
600 | spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated |
|
600 | spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated | |
601 | + spacewire_stats.rx_truncated; |
|
601 | + spacewire_stats.rx_truncated; | |
602 | } |
|
602 | } | |
603 |
|
603 | |||
604 | void spacewire_update_statistics( void ) |
|
604 | void spacewire_update_statistics( void ) | |
605 | { |
|
605 | { | |
606 | rtems_status_code status; |
|
606 | rtems_status_code status; | |
607 | spw_stats spacewire_stats_grspw; |
|
607 | spw_stats spacewire_stats_grspw; | |
608 |
|
608 | |||
609 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw ); |
|
609 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw ); | |
610 |
|
610 | |||
611 | spacewire_stats.packets_received = spacewire_stats_backup.packets_received |
|
611 | spacewire_stats.packets_received = spacewire_stats_backup.packets_received | |
612 | + spacewire_stats_grspw.packets_received; |
|
612 | + spacewire_stats_grspw.packets_received; | |
613 | spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent |
|
613 | spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent | |
614 | + spacewire_stats_grspw.packets_sent; |
|
614 | + spacewire_stats_grspw.packets_sent; | |
615 | spacewire_stats.parity_err = spacewire_stats_backup.parity_err |
|
615 | spacewire_stats.parity_err = spacewire_stats_backup.parity_err | |
616 | + spacewire_stats_grspw.parity_err; |
|
616 | + spacewire_stats_grspw.parity_err; | |
617 | spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err |
|
617 | spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err | |
618 | + spacewire_stats_grspw.disconnect_err; |
|
618 | + spacewire_stats_grspw.disconnect_err; | |
619 | spacewire_stats.escape_err = spacewire_stats_backup.escape_err |
|
619 | spacewire_stats.escape_err = spacewire_stats_backup.escape_err | |
620 | + spacewire_stats_grspw.escape_err; |
|
620 | + spacewire_stats_grspw.escape_err; | |
621 | spacewire_stats.credit_err = spacewire_stats_backup.credit_err |
|
621 | spacewire_stats.credit_err = spacewire_stats_backup.credit_err | |
622 | + spacewire_stats_grspw.credit_err; |
|
622 | + spacewire_stats_grspw.credit_err; | |
623 | spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err |
|
623 | spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err | |
624 | + spacewire_stats_grspw.write_sync_err; |
|
624 | + spacewire_stats_grspw.write_sync_err; | |
625 | spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err |
|
625 | spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err | |
626 | + spacewire_stats_grspw.rx_rmap_header_crc_err; |
|
626 | + spacewire_stats_grspw.rx_rmap_header_crc_err; | |
627 | spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err |
|
627 | spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err | |
628 | + spacewire_stats_grspw.rx_rmap_data_crc_err; |
|
628 | + spacewire_stats_grspw.rx_rmap_data_crc_err; | |
629 | spacewire_stats.early_ep = spacewire_stats_backup.early_ep |
|
629 | spacewire_stats.early_ep = spacewire_stats_backup.early_ep | |
630 | + spacewire_stats_grspw.early_ep; |
|
630 | + spacewire_stats_grspw.early_ep; | |
631 | spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address |
|
631 | spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address | |
632 | + spacewire_stats_grspw.invalid_address; |
|
632 | + spacewire_stats_grspw.invalid_address; | |
633 | spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err |
|
633 | spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err | |
634 | + spacewire_stats_grspw.rx_eep_err; |
|
634 | + spacewire_stats_grspw.rx_eep_err; | |
635 | spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated |
|
635 | spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated | |
636 | + spacewire_stats_grspw.rx_truncated; |
|
636 | + spacewire_stats_grspw.rx_truncated; | |
637 | //spacewire_stats.tx_link_err; |
|
637 | //spacewire_stats.tx_link_err; | |
638 |
|
638 | |||
639 | //**************************** |
|
639 | //**************************** | |
640 | // DPU_SPACEWIRE_IF_STATISTICS |
|
640 | // DPU_SPACEWIRE_IF_STATISTICS | |
641 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8); |
|
641 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8); | |
642 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received); |
|
642 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received); | |
643 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8); |
|
643 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8); | |
644 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent); |
|
644 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent); | |
645 | //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt; |
|
645 | //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt; | |
646 | //housekeeping_packet.hk_lfr_dpu_spw_last_timc; |
|
646 | //housekeeping_packet.hk_lfr_dpu_spw_last_timc; | |
647 |
|
647 | |||
648 | //****************************************** |
|
648 | //****************************************** | |
649 | // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY |
|
649 | // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY | |
650 | housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err; |
|
650 | housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err; | |
651 | housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err; |
|
651 | housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err; | |
652 | housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err; |
|
652 | housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err; | |
653 | housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err; |
|
653 | housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err; | |
654 | housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err; |
|
654 | housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err; | |
655 |
|
655 | |||
656 | //********************************************* |
|
656 | //********************************************* | |
657 | // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY |
|
657 | // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY | |
658 | housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep; |
|
658 | housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep; | |
659 | housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address; |
|
659 | housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address; | |
660 | housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err; |
|
660 | housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err; | |
661 | housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated; |
|
661 | housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated; | |
662 | } |
|
662 | } | |
663 |
|
663 | |||
664 | void increase_unsigned_char_counter( unsigned char *counter ) |
|
664 | void increase_unsigned_char_counter( unsigned char *counter ) | |
665 | { |
|
665 | { | |
666 | // update the number of valid timecodes that have been received |
|
666 | // update the number of valid timecodes that have been received | |
667 | if (*counter == 255) |
|
667 | if (*counter == 255) | |
668 | { |
|
668 | { | |
669 | *counter = 0; |
|
669 | *counter = 0; | |
670 | } |
|
670 | } | |
671 | else |
|
671 | else | |
672 | { |
|
672 | { | |
673 | *counter = *counter + 1; |
|
673 | *counter = *counter + 1; | |
674 | } |
|
674 | } | |
675 | } |
|
675 | } | |
676 |
|
676 | |||
677 | rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data ) |
|
677 | rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data ) | |
678 | { |
|
678 | { | |
679 |
|
679 | |||
680 | unsigned char currentTimecodeCtr; |
|
680 | unsigned char currentTimecodeCtr; | |
681 |
|
681 | |||
682 | currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); |
|
682 | currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); | |
683 |
|
683 | |||
684 | if (currentTimecodeCtr == previousTimecodeCtr) |
|
684 | if (currentTimecodeCtr == previousTimecodeCtr) | |
685 | { |
|
685 | { | |
686 | //************************ |
|
686 | //************************ | |
687 | // HK_LFR_TIMECODE_MISSING |
|
687 | // HK_LFR_TIMECODE_MISSING | |
688 | // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING |
|
688 | // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING | |
689 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing ); |
|
689 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing ); | |
690 | } |
|
690 | } | |
691 | else if (currentTimecodeCtr == (previousTimecodeCtr+1)) |
|
691 | else if (currentTimecodeCtr == (previousTimecodeCtr+1)) | |
692 | { |
|
692 | { | |
693 | // the timecode value has changed and the value is valid, this is unexpected because |
|
693 | // the timecode value has changed and the value is valid, this is unexpected because | |
694 | // the timer should not have fired, the timecode_irq_handler should have been raised |
|
694 | // the timer should not have fired, the timecode_irq_handler should have been raised | |
695 | } |
|
695 | } | |
696 | else |
|
696 | else | |
697 | { |
|
697 | { | |
698 | //************************ |
|
698 | //************************ | |
699 | // HK_LFR_TIMECODE_INVALID |
|
699 | // HK_LFR_TIMECODE_INVALID | |
700 | // the timecode value has changed and the value is not valid, no tickout has been generated |
|
700 | // the timecode value has changed and the value is not valid, no tickout has been generated | |
701 | // this is why the timer has fired |
|
701 | // this is why the timer has fired | |
702 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid ); |
|
702 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid ); | |
703 | } |
|
703 | } | |
704 |
|
704 | |||
705 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 ); |
|
705 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 ); | |
706 | } |
|
706 | } | |
707 |
|
707 | |||
708 | unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr) |
|
708 | unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr) | |
709 | { |
|
709 | { | |
|
710 | /** This function checks the coherency between the incoming timecode and the last valid timecode. | |||
|
711 | * | |||
|
712 | * @param currentTimecodeCtr is the incoming timecode | |||
|
713 | * | |||
|
714 | * @return returned codes:: | |||
|
715 | * - LFR_DEFAULT | |||
|
716 | * - LFR_SUCCESSFUL | |||
|
717 | * | |||
|
718 | */ | |||
|
719 | ||||
710 | static unsigned char firstTickout = 1; |
|
720 | static unsigned char firstTickout = 1; | |
711 | unsigned char ret; |
|
721 | unsigned char ret; | |
712 |
|
722 | |||
713 | ret = LFR_DEFAULT; |
|
723 | ret = LFR_DEFAULT; | |
714 |
|
724 | |||
715 | if (firstTickout == 0) |
|
725 | if (firstTickout == 0) | |
716 | { |
|
726 | { | |
717 | if (currentTimecodeCtr == 0) |
|
727 | if (currentTimecodeCtr == 0) | |
718 | { |
|
728 | { | |
719 | if (previousTimecodeCtr == 63) |
|
729 | if (previousTimecodeCtr == 63) | |
720 | { |
|
730 | { | |
721 | ret = LFR_SUCCESSFUL; |
|
731 | ret = LFR_SUCCESSFUL; | |
722 | } |
|
732 | } | |
723 | else |
|
733 | else | |
724 | { |
|
734 | { | |
725 | ret = LFR_DEFAULT; |
|
735 | ret = LFR_DEFAULT; | |
726 | } |
|
736 | } | |
727 | } |
|
737 | } | |
728 | else |
|
738 | else | |
729 | { |
|
739 | { | |
730 | if (currentTimecodeCtr == (previousTimecodeCtr +1)) |
|
740 | if (currentTimecodeCtr == (previousTimecodeCtr +1)) | |
731 | { |
|
741 | { | |
732 | ret = LFR_SUCCESSFUL; |
|
742 | ret = LFR_SUCCESSFUL; | |
733 | } |
|
743 | } | |
734 | else |
|
744 | else | |
735 | { |
|
745 | { | |
736 | ret = LFR_DEFAULT; |
|
746 | ret = LFR_DEFAULT; | |
737 | } |
|
747 | } | |
738 | } |
|
748 | } | |
739 | } |
|
749 | } | |
740 | else |
|
750 | else | |
741 | { |
|
751 | { | |
742 | firstTickout = 0; |
|
752 | firstTickout = 0; | |
743 | ret = LFR_SUCCESSFUL; |
|
753 | ret = LFR_SUCCESSFUL; | |
744 | } |
|
754 | } | |
745 |
|
755 | |||
746 | return ret; |
|
756 | return ret; | |
747 | } |
|
757 | } | |
748 |
|
758 | |||
749 | unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime) |
|
759 | unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime) | |
750 | { |
|
760 | { | |
751 | unsigned int ret; |
|
761 | unsigned int ret; | |
752 |
|
762 | |||
753 | ret = LFR_DEFAULT; |
|
763 | ret = LFR_DEFAULT; | |
754 |
|
764 | |||
755 | if (timecode == internalTime) |
|
765 | if (timecode == internalTime) | |
756 | { |
|
766 | { | |
757 | ret = LFR_SUCCESSFUL; |
|
767 | ret = LFR_SUCCESSFUL; | |
758 | } |
|
768 | } | |
759 | else |
|
769 | else | |
760 | { |
|
770 | { | |
761 | ret = LFR_DEFAULT; |
|
771 | ret = LFR_DEFAULT; | |
762 | } |
|
772 | } | |
763 |
|
773 | |||
764 | return ret; |
|
774 | return ret; | |
765 | } |
|
775 | } | |
766 |
|
776 | |||
767 | void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) |
|
777 | void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) | |
768 | { |
|
778 | { | |
769 | // a tickout has been emitted, perform actions on the incoming timecode |
|
779 | // a tickout has been emitted, perform actions on the incoming timecode | |
770 |
|
780 | |||
771 | unsigned char incomingTimecode; |
|
781 | unsigned char incomingTimecode; | |
772 | unsigned char updateTime; |
|
782 | unsigned char updateTime; | |
773 | unsigned char internalTime; |
|
783 | unsigned char internalTime; | |
774 | rtems_status_code status; |
|
784 | rtems_status_code status; | |
775 |
|
785 | |||
776 | incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); |
|
786 | incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); | |
777 | updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK; |
|
787 | updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK; | |
778 | internalTime = time_management_regs->coarse_time & TIMECODE_MASK; |
|
788 | internalTime = time_management_regs->coarse_time & TIMECODE_MASK; | |
779 |
|
789 | |||
780 | housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode; |
|
790 | housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode; | |
781 |
|
791 | |||
782 | // update the number of tickout that have been generated |
|
792 | // update the number of tickout that have been generated | |
783 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt ); |
|
793 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt ); | |
784 |
|
794 | |||
785 | //************************** |
|
795 | //************************** | |
786 | // HK_LFR_TIMECODE_ERRONEOUS |
|
796 | // HK_LFR_TIMECODE_ERRONEOUS | |
787 | // MISSING and INVALID are handled by the timecode_timer_routine service routine |
|
797 | // MISSING and INVALID are handled by the timecode_timer_routine service routine | |
788 | if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT) |
|
798 | if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT) | |
789 | { |
|
799 | { | |
790 | // this is unexpected but a tickout could have been raised despite of the timecode being erroneous |
|
800 | // this is unexpected but a tickout could have been raised despite of the timecode being erroneous | |
791 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous ); |
|
801 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous ); | |
792 | } |
|
802 | } | |
793 |
|
803 | |||
794 | //************************ |
|
804 | //************************ | |
795 | // HK_LFR_TIME_TIMECODE_IT |
|
805 | // HK_LFR_TIME_TIMECODE_IT | |
796 | // check the coherency between the SpaceWire timecode and the Internal Time |
|
806 | // check the coherency between the SpaceWire timecode and the Internal Time | |
797 | if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT) |
|
807 | if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT) | |
798 | { |
|
808 | { | |
799 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it ); |
|
809 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it ); | |
800 | } |
|
810 | } | |
801 |
|
811 | |||
802 | //******************** |
|
812 | //******************** | |
803 | // HK_LFR_TIMECODE_CTR |
|
813 | // HK_LFR_TIMECODE_CTR | |
804 | // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370 |
|
814 | // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370 | |
805 | if (incomingTimecode != updateTime) |
|
815 | if (incomingTimecode != updateTime) | |
806 | { |
|
816 | { | |
807 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr ); |
|
817 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr ); | |
808 | } |
|
818 | } | |
809 |
|
819 | |||
810 | // launch the timecode timer to detect missing or invalid timecodes |
|
820 | // launch the timecode timer to detect missing or invalid timecodes | |
811 | previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value |
|
821 | previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value | |
812 | status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL ); |
|
822 | status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL ); | |
813 | } |
|
823 | } | |
814 |
|
824 | |||
815 | void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
825 | void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header ) | |
816 | { |
|
826 | { | |
817 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
827 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; | |
818 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
828 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
819 | header->reserved = DEFAULT_RESERVED; |
|
829 | header->reserved = DEFAULT_RESERVED; | |
820 | header->userApplication = CCSDS_USER_APP; |
|
830 | header->userApplication = CCSDS_USER_APP; | |
821 | header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE; |
|
831 | header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE; | |
822 | header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT; |
|
832 | header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT; | |
823 | header->packetLength[0] = 0x00; |
|
833 | header->packetLength[0] = 0x00; | |
824 | header->packetLength[1] = 0x00; |
|
834 | header->packetLength[1] = 0x00; | |
825 | // DATA FIELD HEADER |
|
835 | // DATA FIELD HEADER | |
826 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
836 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
827 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
837 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type | |
828 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype |
|
838 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype | |
829 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
839 | header->destinationID = TM_DESTINATION_ID_GROUND; | |
830 | header->time[0] = 0x00; |
|
840 | header->time[0] = 0x00; | |
831 | header->time[0] = 0x00; |
|
841 | header->time[0] = 0x00; | |
832 | header->time[0] = 0x00; |
|
842 | header->time[0] = 0x00; | |
833 | header->time[0] = 0x00; |
|
843 | header->time[0] = 0x00; | |
834 | header->time[0] = 0x00; |
|
844 | header->time[0] = 0x00; | |
835 | header->time[0] = 0x00; |
|
845 | header->time[0] = 0x00; | |
836 | // AUXILIARY DATA HEADER |
|
846 | // AUXILIARY DATA HEADER | |
837 | header->sid = 0x00; |
|
847 | header->sid = 0x00; | |
838 | header->hkBIA = DEFAULT_HKBIA; |
|
848 | header->hkBIA = DEFAULT_HKBIA; | |
839 | header->blkNr[0] = 0x00; |
|
849 | header->blkNr[0] = 0x00; | |
840 | header->blkNr[1] = 0x00; |
|
850 | header->blkNr[1] = 0x00; | |
841 | } |
|
851 | } | |
842 |
|
852 | |||
843 | void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header ) |
|
853 | void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header ) | |
844 | { |
|
854 | { | |
845 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
855 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; | |
846 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
856 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
847 | header->reserved = DEFAULT_RESERVED; |
|
857 | header->reserved = DEFAULT_RESERVED; | |
848 | header->userApplication = CCSDS_USER_APP; |
|
858 | header->userApplication = CCSDS_USER_APP; | |
849 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
859 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); | |
850 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
860 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
851 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
861 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
852 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
862 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
853 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); |
|
863 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); | |
854 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); |
|
864 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); | |
855 | // DATA FIELD HEADER |
|
865 | // DATA FIELD HEADER | |
856 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
866 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
857 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
867 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type | |
858 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype |
|
868 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype | |
859 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
869 | header->destinationID = TM_DESTINATION_ID_GROUND; | |
860 | header->time[0] = 0x00; |
|
870 | header->time[0] = 0x00; | |
861 | header->time[0] = 0x00; |
|
871 | header->time[0] = 0x00; | |
862 | header->time[0] = 0x00; |
|
872 | header->time[0] = 0x00; | |
863 | header->time[0] = 0x00; |
|
873 | header->time[0] = 0x00; | |
864 | header->time[0] = 0x00; |
|
874 | header->time[0] = 0x00; | |
865 | header->time[0] = 0x00; |
|
875 | header->time[0] = 0x00; | |
866 | // AUXILIARY DATA HEADER |
|
876 | // AUXILIARY DATA HEADER | |
867 | header->sid = 0x00; |
|
877 | header->sid = 0x00; | |
868 | header->hkBIA = DEFAULT_HKBIA; |
|
878 | header->hkBIA = DEFAULT_HKBIA; | |
869 | header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT |
|
879 | header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT | |
870 | header->pktNr = 0x00; |
|
880 | header->pktNr = 0x00; | |
871 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); |
|
881 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); | |
872 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); |
|
882 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); | |
873 | } |
|
883 | } | |
874 |
|
884 | |||
875 | void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
885 | void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header ) | |
876 | { |
|
886 | { | |
877 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
887 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; | |
878 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
888 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
879 | header->reserved = DEFAULT_RESERVED; |
|
889 | header->reserved = DEFAULT_RESERVED; | |
880 | header->userApplication = CCSDS_USER_APP; |
|
890 | header->userApplication = CCSDS_USER_APP; | |
881 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
891 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); | |
882 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
892 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
883 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
893 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
884 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
894 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
885 | header->packetLength[0] = 0x00; |
|
895 | header->packetLength[0] = 0x00; | |
886 | header->packetLength[1] = 0x00; |
|
896 | header->packetLength[1] = 0x00; | |
887 | // DATA FIELD HEADER |
|
897 | // DATA FIELD HEADER | |
888 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
898 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
889 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
899 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type | |
890 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype |
|
900 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype | |
891 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
901 | header->destinationID = TM_DESTINATION_ID_GROUND; | |
892 | header->time[0] = 0x00; |
|
902 | header->time[0] = 0x00; | |
893 | header->time[0] = 0x00; |
|
903 | header->time[0] = 0x00; | |
894 | header->time[0] = 0x00; |
|
904 | header->time[0] = 0x00; | |
895 | header->time[0] = 0x00; |
|
905 | header->time[0] = 0x00; | |
896 | header->time[0] = 0x00; |
|
906 | header->time[0] = 0x00; | |
897 | header->time[0] = 0x00; |
|
907 | header->time[0] = 0x00; | |
898 | // AUXILIARY DATA HEADER |
|
908 | // AUXILIARY DATA HEADER | |
899 | header->sid = 0x00; |
|
909 | header->sid = 0x00; | |
900 | header->biaStatusInfo = 0x00; |
|
910 | header->biaStatusInfo = 0x00; | |
901 | header->pa_lfr_pkt_cnt_asm = 0x00; |
|
911 | header->pa_lfr_pkt_cnt_asm = 0x00; | |
902 | header->pa_lfr_pkt_nr_asm = 0x00; |
|
912 | header->pa_lfr_pkt_nr_asm = 0x00; | |
903 | header->pa_lfr_asm_blk_nr[0] = 0x00; |
|
913 | header->pa_lfr_asm_blk_nr[0] = 0x00; | |
904 | header->pa_lfr_asm_blk_nr[1] = 0x00; |
|
914 | header->pa_lfr_asm_blk_nr[1] = 0x00; | |
905 | } |
|
915 | } | |
906 |
|
916 | |||
907 | int spw_send_waveform_CWF( ring_node *ring_node_to_send, |
|
917 | int spw_send_waveform_CWF( ring_node *ring_node_to_send, | |
908 | Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
918 | Header_TM_LFR_SCIENCE_CWF_t *header ) | |
909 | { |
|
919 | { | |
910 | /** This function sends CWF CCSDS packets (F2, F1 or F0). |
|
920 | /** This function sends CWF CCSDS packets (F2, F1 or F0). | |
911 | * |
|
921 | * | |
912 | * @param waveform points to the buffer containing the data that will be send. |
|
922 | * @param waveform points to the buffer containing the data that will be send. | |
913 | * @param sid is the source identifier of the data that will be sent. |
|
923 | * @param sid is the source identifier of the data that will be sent. | |
914 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
924 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. | |
915 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
925 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures | |
916 | * contain information to setup the transmission of the data packets. |
|
926 | * contain information to setup the transmission of the data packets. | |
917 | * |
|
927 | * | |
918 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. |
|
928 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. | |
919 | * |
|
929 | * | |
920 | */ |
|
930 | */ | |
921 |
|
931 | |||
922 | unsigned int i; |
|
932 | unsigned int i; | |
923 | int ret; |
|
933 | int ret; | |
924 | unsigned int coarseTime; |
|
934 | unsigned int coarseTime; | |
925 | unsigned int fineTime; |
|
935 | unsigned int fineTime; | |
926 | rtems_status_code status; |
|
936 | rtems_status_code status; | |
927 | spw_ioctl_pkt_send spw_ioctl_send_CWF; |
|
937 | spw_ioctl_pkt_send spw_ioctl_send_CWF; | |
928 | int *dataPtr; |
|
938 | int *dataPtr; | |
929 | unsigned char sid; |
|
939 | unsigned char sid; | |
930 |
|
940 | |||
931 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; |
|
941 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; | |
932 | spw_ioctl_send_CWF.options = 0; |
|
942 | spw_ioctl_send_CWF.options = 0; | |
933 |
|
943 | |||
934 | ret = LFR_DEFAULT; |
|
944 | ret = LFR_DEFAULT; | |
935 | sid = (unsigned char) ring_node_to_send->sid; |
|
945 | sid = (unsigned char) ring_node_to_send->sid; | |
936 |
|
946 | |||
937 | coarseTime = ring_node_to_send->coarseTime; |
|
947 | coarseTime = ring_node_to_send->coarseTime; | |
938 | fineTime = ring_node_to_send->fineTime; |
|
948 | fineTime = ring_node_to_send->fineTime; | |
939 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
949 | dataPtr = (int*) ring_node_to_send->buffer_address; | |
940 |
|
950 | |||
941 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); |
|
951 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); | |
942 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); |
|
952 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); | |
943 | header->hkBIA = pa_bia_status_info; |
|
953 | header->hkBIA = pa_bia_status_info; | |
944 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
954 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
945 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); |
|
955 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); | |
946 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); |
|
956 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); | |
947 |
|
957 | |||
948 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform |
|
958 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform | |
949 | { |
|
959 | { | |
950 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ]; |
|
960 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ]; | |
951 | spw_ioctl_send_CWF.hdr = (char*) header; |
|
961 | spw_ioctl_send_CWF.hdr = (char*) header; | |
952 | // BUILD THE DATA |
|
962 | // BUILD THE DATA | |
953 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK; |
|
963 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK; | |
954 |
|
964 | |||
955 | // SET PACKET SEQUENCE CONTROL |
|
965 | // SET PACKET SEQUENCE CONTROL | |
956 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
966 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
957 |
|
967 | |||
958 | // SET SID |
|
968 | // SET SID | |
959 | header->sid = sid; |
|
969 | header->sid = sid; | |
960 |
|
970 | |||
961 | // SET PACKET TIME |
|
971 | // SET PACKET TIME | |
962 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime); |
|
972 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime); | |
963 | // |
|
973 | // | |
964 | header->time[0] = header->acquisitionTime[0]; |
|
974 | header->time[0] = header->acquisitionTime[0]; | |
965 | header->time[1] = header->acquisitionTime[1]; |
|
975 | header->time[1] = header->acquisitionTime[1]; | |
966 | header->time[2] = header->acquisitionTime[2]; |
|
976 | header->time[2] = header->acquisitionTime[2]; | |
967 | header->time[3] = header->acquisitionTime[3]; |
|
977 | header->time[3] = header->acquisitionTime[3]; | |
968 | header->time[4] = header->acquisitionTime[4]; |
|
978 | header->time[4] = header->acquisitionTime[4]; | |
969 | header->time[5] = header->acquisitionTime[5]; |
|
979 | header->time[5] = header->acquisitionTime[5]; | |
970 |
|
980 | |||
971 | // SET PACKET ID |
|
981 | // SET PACKET ID | |
972 | if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) ) |
|
982 | if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) ) | |
973 | { |
|
983 | { | |
974 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8); |
|
984 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8); | |
975 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2); |
|
985 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2); | |
976 | } |
|
986 | } | |
977 | else |
|
987 | else | |
978 | { |
|
988 | { | |
979 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
989 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); | |
980 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
990 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
981 | } |
|
991 | } | |
982 |
|
992 | |||
983 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); |
|
993 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); | |
984 | if (status != RTEMS_SUCCESSFUL) { |
|
994 | if (status != RTEMS_SUCCESSFUL) { | |
985 | ret = LFR_DEFAULT; |
|
995 | ret = LFR_DEFAULT; | |
986 | } |
|
996 | } | |
987 | } |
|
997 | } | |
988 |
|
998 | |||
989 | return ret; |
|
999 | return ret; | |
990 | } |
|
1000 | } | |
991 |
|
1001 | |||
992 | int spw_send_waveform_SWF( ring_node *ring_node_to_send, |
|
1002 | int spw_send_waveform_SWF( ring_node *ring_node_to_send, | |
993 | Header_TM_LFR_SCIENCE_SWF_t *header ) |
|
1003 | Header_TM_LFR_SCIENCE_SWF_t *header ) | |
994 | { |
|
1004 | { | |
995 | /** This function sends SWF CCSDS packets (F2, F1 or F0). |
|
1005 | /** This function sends SWF CCSDS packets (F2, F1 or F0). | |
996 | * |
|
1006 | * | |
997 | * @param waveform points to the buffer containing the data that will be send. |
|
1007 | * @param waveform points to the buffer containing the data that will be send. | |
998 | * @param sid is the source identifier of the data that will be sent. |
|
1008 | * @param sid is the source identifier of the data that will be sent. | |
999 | * @param headerSWF points to a table of headers that have been prepared for the data transmission. |
|
1009 | * @param headerSWF points to a table of headers that have been prepared for the data transmission. | |
1000 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
1010 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures | |
1001 | * contain information to setup the transmission of the data packets. |
|
1011 | * contain information to setup the transmission of the data packets. | |
1002 | * |
|
1012 | * | |
1003 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. |
|
1013 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. | |
1004 | * |
|
1014 | * | |
1005 | */ |
|
1015 | */ | |
1006 |
|
1016 | |||
1007 | unsigned int i; |
|
1017 | unsigned int i; | |
1008 | int ret; |
|
1018 | int ret; | |
1009 | unsigned int coarseTime; |
|
1019 | unsigned int coarseTime; | |
1010 | unsigned int fineTime; |
|
1020 | unsigned int fineTime; | |
1011 | rtems_status_code status; |
|
1021 | rtems_status_code status; | |
1012 | spw_ioctl_pkt_send spw_ioctl_send_SWF; |
|
1022 | spw_ioctl_pkt_send spw_ioctl_send_SWF; | |
1013 | int *dataPtr; |
|
1023 | int *dataPtr; | |
1014 | unsigned char sid; |
|
1024 | unsigned char sid; | |
1015 |
|
1025 | |||
1016 | spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF; |
|
1026 | spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF; | |
1017 | spw_ioctl_send_SWF.options = 0; |
|
1027 | spw_ioctl_send_SWF.options = 0; | |
1018 |
|
1028 | |||
1019 | ret = LFR_DEFAULT; |
|
1029 | ret = LFR_DEFAULT; | |
1020 |
|
1030 | |||
1021 | coarseTime = ring_node_to_send->coarseTime; |
|
1031 | coarseTime = ring_node_to_send->coarseTime; | |
1022 | fineTime = ring_node_to_send->fineTime; |
|
1032 | fineTime = ring_node_to_send->fineTime; | |
1023 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
1033 | dataPtr = (int*) ring_node_to_send->buffer_address; | |
1024 | sid = ring_node_to_send->sid; |
|
1034 | sid = ring_node_to_send->sid; | |
1025 |
|
1035 | |||
1026 | header->hkBIA = pa_bia_status_info; |
|
1036 | header->hkBIA = pa_bia_status_info; | |
1027 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1037 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1028 |
|
1038 | |||
1029 | for (i=0; i<7; i++) // send waveform |
|
1039 | for (i=0; i<7; i++) // send waveform | |
1030 | { |
|
1040 | { | |
1031 | spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ]; |
|
1041 | spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ]; | |
1032 | spw_ioctl_send_SWF.hdr = (char*) header; |
|
1042 | spw_ioctl_send_SWF.hdr = (char*) header; | |
1033 |
|
1043 | |||
1034 | // SET PACKET SEQUENCE CONTROL |
|
1044 | // SET PACKET SEQUENCE CONTROL | |
1035 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1045 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1036 |
|
1046 | |||
1037 | // SET PACKET LENGTH AND BLKNR |
|
1047 | // SET PACKET LENGTH AND BLKNR | |
1038 | if (i == 6) |
|
1048 | if (i == 6) | |
1039 | { |
|
1049 | { | |
1040 | spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK; |
|
1050 | spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK; | |
1041 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8); |
|
1051 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8); | |
1042 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 ); |
|
1052 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 ); | |
1043 | header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8); |
|
1053 | header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8); | |
1044 | header->blkNr[1] = (unsigned char) (BLK_NR_224 ); |
|
1054 | header->blkNr[1] = (unsigned char) (BLK_NR_224 ); | |
1045 | } |
|
1055 | } | |
1046 | else |
|
1056 | else | |
1047 | { |
|
1057 | { | |
1048 | spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK; |
|
1058 | spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK; | |
1049 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8); |
|
1059 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8); | |
1050 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 ); |
|
1060 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 ); | |
1051 | header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8); |
|
1061 | header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8); | |
1052 | header->blkNr[1] = (unsigned char) (BLK_NR_304 ); |
|
1062 | header->blkNr[1] = (unsigned char) (BLK_NR_304 ); | |
1053 | } |
|
1063 | } | |
1054 |
|
1064 | |||
1055 | // SET PACKET TIME |
|
1065 | // SET PACKET TIME | |
1056 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime ); |
|
1066 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime ); | |
1057 | // |
|
1067 | // | |
1058 | header->time[0] = header->acquisitionTime[0]; |
|
1068 | header->time[0] = header->acquisitionTime[0]; | |
1059 | header->time[1] = header->acquisitionTime[1]; |
|
1069 | header->time[1] = header->acquisitionTime[1]; | |
1060 | header->time[2] = header->acquisitionTime[2]; |
|
1070 | header->time[2] = header->acquisitionTime[2]; | |
1061 | header->time[3] = header->acquisitionTime[3]; |
|
1071 | header->time[3] = header->acquisitionTime[3]; | |
1062 | header->time[4] = header->acquisitionTime[4]; |
|
1072 | header->time[4] = header->acquisitionTime[4]; | |
1063 | header->time[5] = header->acquisitionTime[5]; |
|
1073 | header->time[5] = header->acquisitionTime[5]; | |
1064 |
|
1074 | |||
1065 | // SET SID |
|
1075 | // SET SID | |
1066 | header->sid = sid; |
|
1076 | header->sid = sid; | |
1067 |
|
1077 | |||
1068 | // SET PKTNR |
|
1078 | // SET PKTNR | |
1069 | header->pktNr = i+1; // PKT_NR |
|
1079 | header->pktNr = i+1; // PKT_NR | |
1070 |
|
1080 | |||
1071 | // SEND PACKET |
|
1081 | // SEND PACKET | |
1072 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF ); |
|
1082 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF ); | |
1073 | if (status != RTEMS_SUCCESSFUL) { |
|
1083 | if (status != RTEMS_SUCCESSFUL) { | |
1074 | ret = LFR_DEFAULT; |
|
1084 | ret = LFR_DEFAULT; | |
1075 | } |
|
1085 | } | |
1076 | } |
|
1086 | } | |
1077 |
|
1087 | |||
1078 | return ret; |
|
1088 | return ret; | |
1079 | } |
|
1089 | } | |
1080 |
|
1090 | |||
1081 | int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, |
|
1091 | int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, | |
1082 | Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
1092 | Header_TM_LFR_SCIENCE_CWF_t *header ) | |
1083 | { |
|
1093 | { | |
1084 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. |
|
1094 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. | |
1085 | * |
|
1095 | * | |
1086 | * @param waveform points to the buffer containing the data that will be send. |
|
1096 | * @param waveform points to the buffer containing the data that will be send. | |
1087 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
1097 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. | |
1088 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
1098 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures | |
1089 | * contain information to setup the transmission of the data packets. |
|
1099 | * contain information to setup the transmission of the data packets. | |
1090 | * |
|
1100 | * | |
1091 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer |
|
1101 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer | |
1092 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. |
|
1102 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. | |
1093 | * |
|
1103 | * | |
1094 | */ |
|
1104 | */ | |
1095 |
|
1105 | |||
1096 | unsigned int i; |
|
1106 | unsigned int i; | |
1097 | int ret; |
|
1107 | int ret; | |
1098 | unsigned int coarseTime; |
|
1108 | unsigned int coarseTime; | |
1099 | unsigned int fineTime; |
|
1109 | unsigned int fineTime; | |
1100 | rtems_status_code status; |
|
1110 | rtems_status_code status; | |
1101 | spw_ioctl_pkt_send spw_ioctl_send_CWF; |
|
1111 | spw_ioctl_pkt_send spw_ioctl_send_CWF; | |
1102 | char *dataPtr; |
|
1112 | char *dataPtr; | |
1103 | unsigned char sid; |
|
1113 | unsigned char sid; | |
1104 |
|
1114 | |||
1105 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; |
|
1115 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; | |
1106 | spw_ioctl_send_CWF.options = 0; |
|
1116 | spw_ioctl_send_CWF.options = 0; | |
1107 |
|
1117 | |||
1108 | ret = LFR_DEFAULT; |
|
1118 | ret = LFR_DEFAULT; | |
1109 | sid = ring_node_to_send->sid; |
|
1119 | sid = ring_node_to_send->sid; | |
1110 |
|
1120 | |||
1111 | coarseTime = ring_node_to_send->coarseTime; |
|
1121 | coarseTime = ring_node_to_send->coarseTime; | |
1112 | fineTime = ring_node_to_send->fineTime; |
|
1122 | fineTime = ring_node_to_send->fineTime; | |
1113 | dataPtr = (char*) ring_node_to_send->buffer_address; |
|
1123 | dataPtr = (char*) ring_node_to_send->buffer_address; | |
1114 |
|
1124 | |||
1115 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8); |
|
1125 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8); | |
1116 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 ); |
|
1126 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 ); | |
1117 | header->hkBIA = pa_bia_status_info; |
|
1127 | header->hkBIA = pa_bia_status_info; | |
1118 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1128 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1119 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8); |
|
1129 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8); | |
1120 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 ); |
|
1130 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 ); | |
1121 |
|
1131 | |||
1122 | //********************* |
|
1132 | //********************* | |
1123 | // SEND CWF3_light DATA |
|
1133 | // SEND CWF3_light DATA | |
1124 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform |
|
1134 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform | |
1125 | { |
|
1135 | { | |
1126 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ]; |
|
1136 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ]; | |
1127 | spw_ioctl_send_CWF.hdr = (char*) header; |
|
1137 | spw_ioctl_send_CWF.hdr = (char*) header; | |
1128 | // BUILD THE DATA |
|
1138 | // BUILD THE DATA | |
1129 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK; |
|
1139 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK; | |
1130 |
|
1140 | |||
1131 | // SET PACKET SEQUENCE COUNTER |
|
1141 | // SET PACKET SEQUENCE COUNTER | |
1132 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1142 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1133 |
|
1143 | |||
1134 | // SET SID |
|
1144 | // SET SID | |
1135 | header->sid = sid; |
|
1145 | header->sid = sid; | |
1136 |
|
1146 | |||
1137 | // SET PACKET TIME |
|
1147 | // SET PACKET TIME | |
1138 | compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime ); |
|
1148 | compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime ); | |
1139 | // |
|
1149 | // | |
1140 | header->time[0] = header->acquisitionTime[0]; |
|
1150 | header->time[0] = header->acquisitionTime[0]; | |
1141 | header->time[1] = header->acquisitionTime[1]; |
|
1151 | header->time[1] = header->acquisitionTime[1]; | |
1142 | header->time[2] = header->acquisitionTime[2]; |
|
1152 | header->time[2] = header->acquisitionTime[2]; | |
1143 | header->time[3] = header->acquisitionTime[3]; |
|
1153 | header->time[3] = header->acquisitionTime[3]; | |
1144 | header->time[4] = header->acquisitionTime[4]; |
|
1154 | header->time[4] = header->acquisitionTime[4]; | |
1145 | header->time[5] = header->acquisitionTime[5]; |
|
1155 | header->time[5] = header->acquisitionTime[5]; | |
1146 |
|
1156 | |||
1147 | // SET PACKET ID |
|
1157 | // SET PACKET ID | |
1148 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
1158 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); | |
1149 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
1159 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
1150 |
|
1160 | |||
1151 | // SEND PACKET |
|
1161 | // SEND PACKET | |
1152 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); |
|
1162 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); | |
1153 | if (status != RTEMS_SUCCESSFUL) { |
|
1163 | if (status != RTEMS_SUCCESSFUL) { | |
1154 | ret = LFR_DEFAULT; |
|
1164 | ret = LFR_DEFAULT; | |
1155 | } |
|
1165 | } | |
1156 | } |
|
1166 | } | |
1157 |
|
1167 | |||
1158 | return ret; |
|
1168 | return ret; | |
1159 | } |
|
1169 | } | |
1160 |
|
1170 | |||
1161 | void spw_send_asm_f0( ring_node *ring_node_to_send, |
|
1171 | void spw_send_asm_f0( ring_node *ring_node_to_send, | |
1162 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1172 | Header_TM_LFR_SCIENCE_ASM_t *header ) | |
1163 | { |
|
1173 | { | |
1164 | unsigned int i; |
|
1174 | unsigned int i; | |
1165 | unsigned int length = 0; |
|
1175 | unsigned int length = 0; | |
1166 | rtems_status_code status; |
|
1176 | rtems_status_code status; | |
1167 | unsigned int sid; |
|
1177 | unsigned int sid; | |
1168 | float *spectral_matrix; |
|
1178 | float *spectral_matrix; | |
1169 | int coarseTime; |
|
1179 | int coarseTime; | |
1170 | int fineTime; |
|
1180 | int fineTime; | |
1171 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1181 | spw_ioctl_pkt_send spw_ioctl_send_ASM; | |
1172 |
|
1182 | |||
1173 | sid = ring_node_to_send->sid; |
|
1183 | sid = ring_node_to_send->sid; | |
1174 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1184 | spectral_matrix = (float*) ring_node_to_send->buffer_address; | |
1175 | coarseTime = ring_node_to_send->coarseTime; |
|
1185 | coarseTime = ring_node_to_send->coarseTime; | |
1176 | fineTime = ring_node_to_send->fineTime; |
|
1186 | fineTime = ring_node_to_send->fineTime; | |
1177 |
|
1187 | |||
1178 | header->biaStatusInfo = pa_bia_status_info; |
|
1188 | header->biaStatusInfo = pa_bia_status_info; | |
1179 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1189 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1180 |
|
1190 | |||
1181 | for (i=0; i<3; i++) |
|
1191 | for (i=0; i<3; i++) | |
1182 | { |
|
1192 | { | |
1183 | if ((i==0) || (i==1)) |
|
1193 | if ((i==0) || (i==1)) | |
1184 | { |
|
1194 | { | |
1185 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1; |
|
1195 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1; | |
1186 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1196 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ | |
1187 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) |
|
1197 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) | |
1188 | ]; |
|
1198 | ]; | |
1189 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1; |
|
1199 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1; | |
1190 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1200 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1191 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB |
|
1201 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB | |
1192 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB |
|
1202 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB | |
1193 | } |
|
1203 | } | |
1194 | else |
|
1204 | else | |
1195 | { |
|
1205 | { | |
1196 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2; |
|
1206 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2; | |
1197 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ |
|
1207 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ | |
1198 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) |
|
1208 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) | |
1199 | ]; |
|
1209 | ]; | |
1200 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2; |
|
1210 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2; | |
1201 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1211 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1202 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB |
|
1212 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB | |
1203 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB |
|
1213 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB | |
1204 | } |
|
1214 | } | |
1205 |
|
1215 | |||
1206 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1216 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; | |
1207 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1217 | spw_ioctl_send_ASM.hdr = (char *) header; | |
1208 | spw_ioctl_send_ASM.options = 0; |
|
1218 | spw_ioctl_send_ASM.options = 0; | |
1209 |
|
1219 | |||
1210 | // (2) BUILD THE HEADER |
|
1220 | // (2) BUILD THE HEADER | |
1211 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1221 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1212 | header->packetLength[0] = (unsigned char) (length>>8); |
|
1222 | header->packetLength[0] = (unsigned char) (length>>8); | |
1213 | header->packetLength[1] = (unsigned char) (length); |
|
1223 | header->packetLength[1] = (unsigned char) (length); | |
1214 | header->sid = (unsigned char) sid; // SID |
|
1224 | header->sid = (unsigned char) sid; // SID | |
1215 | header->pa_lfr_pkt_cnt_asm = 3; |
|
1225 | header->pa_lfr_pkt_cnt_asm = 3; | |
1216 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1226 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); | |
1217 |
|
1227 | |||
1218 | // (3) SET PACKET TIME |
|
1228 | // (3) SET PACKET TIME | |
1219 | header->time[0] = (unsigned char) (coarseTime>>24); |
|
1229 | header->time[0] = (unsigned char) (coarseTime>>24); | |
1220 | header->time[1] = (unsigned char) (coarseTime>>16); |
|
1230 | header->time[1] = (unsigned char) (coarseTime>>16); | |
1221 | header->time[2] = (unsigned char) (coarseTime>>8); |
|
1231 | header->time[2] = (unsigned char) (coarseTime>>8); | |
1222 | header->time[3] = (unsigned char) (coarseTime); |
|
1232 | header->time[3] = (unsigned char) (coarseTime); | |
1223 | header->time[4] = (unsigned char) (fineTime>>8); |
|
1233 | header->time[4] = (unsigned char) (fineTime>>8); | |
1224 | header->time[5] = (unsigned char) (fineTime); |
|
1234 | header->time[5] = (unsigned char) (fineTime); | |
1225 | // |
|
1235 | // | |
1226 | header->acquisitionTime[0] = header->time[0]; |
|
1236 | header->acquisitionTime[0] = header->time[0]; | |
1227 | header->acquisitionTime[1] = header->time[1]; |
|
1237 | header->acquisitionTime[1] = header->time[1]; | |
1228 | header->acquisitionTime[2] = header->time[2]; |
|
1238 | header->acquisitionTime[2] = header->time[2]; | |
1229 | header->acquisitionTime[3] = header->time[3]; |
|
1239 | header->acquisitionTime[3] = header->time[3]; | |
1230 | header->acquisitionTime[4] = header->time[4]; |
|
1240 | header->acquisitionTime[4] = header->time[4]; | |
1231 | header->acquisitionTime[5] = header->time[5]; |
|
1241 | header->acquisitionTime[5] = header->time[5]; | |
1232 |
|
1242 | |||
1233 | // (4) SEND PACKET |
|
1243 | // (4) SEND PACKET | |
1234 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1244 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); | |
1235 | if (status != RTEMS_SUCCESSFUL) { |
|
1245 | if (status != RTEMS_SUCCESSFUL) { | |
1236 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1246 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) | |
1237 | } |
|
1247 | } | |
1238 | } |
|
1248 | } | |
1239 | } |
|
1249 | } | |
1240 |
|
1250 | |||
1241 | void spw_send_asm_f1( ring_node *ring_node_to_send, |
|
1251 | void spw_send_asm_f1( ring_node *ring_node_to_send, | |
1242 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1252 | Header_TM_LFR_SCIENCE_ASM_t *header ) | |
1243 | { |
|
1253 | { | |
1244 | unsigned int i; |
|
1254 | unsigned int i; | |
1245 | unsigned int length = 0; |
|
1255 | unsigned int length = 0; | |
1246 | rtems_status_code status; |
|
1256 | rtems_status_code status; | |
1247 | unsigned int sid; |
|
1257 | unsigned int sid; | |
1248 | float *spectral_matrix; |
|
1258 | float *spectral_matrix; | |
1249 | int coarseTime; |
|
1259 | int coarseTime; | |
1250 | int fineTime; |
|
1260 | int fineTime; | |
1251 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1261 | spw_ioctl_pkt_send spw_ioctl_send_ASM; | |
1252 |
|
1262 | |||
1253 | sid = ring_node_to_send->sid; |
|
1263 | sid = ring_node_to_send->sid; | |
1254 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1264 | spectral_matrix = (float*) ring_node_to_send->buffer_address; | |
1255 | coarseTime = ring_node_to_send->coarseTime; |
|
1265 | coarseTime = ring_node_to_send->coarseTime; | |
1256 | fineTime = ring_node_to_send->fineTime; |
|
1266 | fineTime = ring_node_to_send->fineTime; | |
1257 |
|
1267 | |||
1258 | header->biaStatusInfo = pa_bia_status_info; |
|
1268 | header->biaStatusInfo = pa_bia_status_info; | |
1259 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1269 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1260 |
|
1270 | |||
1261 | for (i=0; i<3; i++) |
|
1271 | for (i=0; i<3; i++) | |
1262 | { |
|
1272 | { | |
1263 | if ((i==0) || (i==1)) |
|
1273 | if ((i==0) || (i==1)) | |
1264 | { |
|
1274 | { | |
1265 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1; |
|
1275 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1; | |
1266 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1276 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ | |
1267 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) |
|
1277 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) | |
1268 | ]; |
|
1278 | ]; | |
1269 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1; |
|
1279 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1; | |
1270 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1280 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1271 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB |
|
1281 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB | |
1272 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB |
|
1282 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB | |
1273 | } |
|
1283 | } | |
1274 | else |
|
1284 | else | |
1275 | { |
|
1285 | { | |
1276 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2; |
|
1286 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2; | |
1277 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ |
|
1287 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ | |
1278 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) |
|
1288 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) | |
1279 | ]; |
|
1289 | ]; | |
1280 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2; |
|
1290 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2; | |
1281 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1291 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1282 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB |
|
1292 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB | |
1283 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB |
|
1293 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB | |
1284 | } |
|
1294 | } | |
1285 |
|
1295 | |||
1286 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1296 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; | |
1287 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1297 | spw_ioctl_send_ASM.hdr = (char *) header; | |
1288 | spw_ioctl_send_ASM.options = 0; |
|
1298 | spw_ioctl_send_ASM.options = 0; | |
1289 |
|
1299 | |||
1290 | // (2) BUILD THE HEADER |
|
1300 | // (2) BUILD THE HEADER | |
1291 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1301 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1292 | header->packetLength[0] = (unsigned char) (length>>8); |
|
1302 | header->packetLength[0] = (unsigned char) (length>>8); | |
1293 | header->packetLength[1] = (unsigned char) (length); |
|
1303 | header->packetLength[1] = (unsigned char) (length); | |
1294 | header->sid = (unsigned char) sid; // SID |
|
1304 | header->sid = (unsigned char) sid; // SID | |
1295 | header->pa_lfr_pkt_cnt_asm = 3; |
|
1305 | header->pa_lfr_pkt_cnt_asm = 3; | |
1296 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1306 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); | |
1297 |
|
1307 | |||
1298 | // (3) SET PACKET TIME |
|
1308 | // (3) SET PACKET TIME | |
1299 | header->time[0] = (unsigned char) (coarseTime>>24); |
|
1309 | header->time[0] = (unsigned char) (coarseTime>>24); | |
1300 | header->time[1] = (unsigned char) (coarseTime>>16); |
|
1310 | header->time[1] = (unsigned char) (coarseTime>>16); | |
1301 | header->time[2] = (unsigned char) (coarseTime>>8); |
|
1311 | header->time[2] = (unsigned char) (coarseTime>>8); | |
1302 | header->time[3] = (unsigned char) (coarseTime); |
|
1312 | header->time[3] = (unsigned char) (coarseTime); | |
1303 | header->time[4] = (unsigned char) (fineTime>>8); |
|
1313 | header->time[4] = (unsigned char) (fineTime>>8); | |
1304 | header->time[5] = (unsigned char) (fineTime); |
|
1314 | header->time[5] = (unsigned char) (fineTime); | |
1305 | // |
|
1315 | // | |
1306 | header->acquisitionTime[0] = header->time[0]; |
|
1316 | header->acquisitionTime[0] = header->time[0]; | |
1307 | header->acquisitionTime[1] = header->time[1]; |
|
1317 | header->acquisitionTime[1] = header->time[1]; | |
1308 | header->acquisitionTime[2] = header->time[2]; |
|
1318 | header->acquisitionTime[2] = header->time[2]; | |
1309 | header->acquisitionTime[3] = header->time[3]; |
|
1319 | header->acquisitionTime[3] = header->time[3]; | |
1310 | header->acquisitionTime[4] = header->time[4]; |
|
1320 | header->acquisitionTime[4] = header->time[4]; | |
1311 | header->acquisitionTime[5] = header->time[5]; |
|
1321 | header->acquisitionTime[5] = header->time[5]; | |
1312 |
|
1322 | |||
1313 | // (4) SEND PACKET |
|
1323 | // (4) SEND PACKET | |
1314 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1324 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); | |
1315 | if (status != RTEMS_SUCCESSFUL) { |
|
1325 | if (status != RTEMS_SUCCESSFUL) { | |
1316 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1326 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) | |
1317 | } |
|
1327 | } | |
1318 | } |
|
1328 | } | |
1319 | } |
|
1329 | } | |
1320 |
|
1330 | |||
1321 | void spw_send_asm_f2( ring_node *ring_node_to_send, |
|
1331 | void spw_send_asm_f2( ring_node *ring_node_to_send, | |
1322 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1332 | Header_TM_LFR_SCIENCE_ASM_t *header ) | |
1323 | { |
|
1333 | { | |
1324 | unsigned int i; |
|
1334 | unsigned int i; | |
1325 | unsigned int length = 0; |
|
1335 | unsigned int length = 0; | |
1326 | rtems_status_code status; |
|
1336 | rtems_status_code status; | |
1327 | unsigned int sid; |
|
1337 | unsigned int sid; | |
1328 | float *spectral_matrix; |
|
1338 | float *spectral_matrix; | |
1329 | int coarseTime; |
|
1339 | int coarseTime; | |
1330 | int fineTime; |
|
1340 | int fineTime; | |
1331 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1341 | spw_ioctl_pkt_send spw_ioctl_send_ASM; | |
1332 |
|
1342 | |||
1333 | sid = ring_node_to_send->sid; |
|
1343 | sid = ring_node_to_send->sid; | |
1334 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1344 | spectral_matrix = (float*) ring_node_to_send->buffer_address; | |
1335 | coarseTime = ring_node_to_send->coarseTime; |
|
1345 | coarseTime = ring_node_to_send->coarseTime; | |
1336 | fineTime = ring_node_to_send->fineTime; |
|
1346 | fineTime = ring_node_to_send->fineTime; | |
1337 |
|
1347 | |||
1338 | header->biaStatusInfo = pa_bia_status_info; |
|
1348 | header->biaStatusInfo = pa_bia_status_info; | |
1339 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1349 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1340 |
|
1350 | |||
1341 | for (i=0; i<3; i++) |
|
1351 | for (i=0; i<3; i++) | |
1342 | { |
|
1352 | { | |
1343 |
|
1353 | |||
1344 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT; |
|
1354 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT; | |
1345 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1355 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ | |
1346 | ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) |
|
1356 | ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) | |
1347 | ]; |
|
1357 | ]; | |
1348 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2; |
|
1358 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2; | |
1349 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; |
|
1359 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; | |
1350 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB |
|
1360 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB | |
1351 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB |
|
1361 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB | |
1352 |
|
1362 | |||
1353 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1363 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; | |
1354 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1364 | spw_ioctl_send_ASM.hdr = (char *) header; | |
1355 | spw_ioctl_send_ASM.options = 0; |
|
1365 | spw_ioctl_send_ASM.options = 0; | |
1356 |
|
1366 | |||
1357 | // (2) BUILD THE HEADER |
|
1367 | // (2) BUILD THE HEADER | |
1358 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1368 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1359 | header->packetLength[0] = (unsigned char) (length>>8); |
|
1369 | header->packetLength[0] = (unsigned char) (length>>8); | |
1360 | header->packetLength[1] = (unsigned char) (length); |
|
1370 | header->packetLength[1] = (unsigned char) (length); | |
1361 | header->sid = (unsigned char) sid; // SID |
|
1371 | header->sid = (unsigned char) sid; // SID | |
1362 | header->pa_lfr_pkt_cnt_asm = 3; |
|
1372 | header->pa_lfr_pkt_cnt_asm = 3; | |
1363 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1373 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); | |
1364 |
|
1374 | |||
1365 | // (3) SET PACKET TIME |
|
1375 | // (3) SET PACKET TIME | |
1366 | header->time[0] = (unsigned char) (coarseTime>>24); |
|
1376 | header->time[0] = (unsigned char) (coarseTime>>24); | |
1367 | header->time[1] = (unsigned char) (coarseTime>>16); |
|
1377 | header->time[1] = (unsigned char) (coarseTime>>16); | |
1368 | header->time[2] = (unsigned char) (coarseTime>>8); |
|
1378 | header->time[2] = (unsigned char) (coarseTime>>8); | |
1369 | header->time[3] = (unsigned char) (coarseTime); |
|
1379 | header->time[3] = (unsigned char) (coarseTime); | |
1370 | header->time[4] = (unsigned char) (fineTime>>8); |
|
1380 | header->time[4] = (unsigned char) (fineTime>>8); | |
1371 | header->time[5] = (unsigned char) (fineTime); |
|
1381 | header->time[5] = (unsigned char) (fineTime); | |
1372 | // |
|
1382 | // | |
1373 | header->acquisitionTime[0] = header->time[0]; |
|
1383 | header->acquisitionTime[0] = header->time[0]; | |
1374 | header->acquisitionTime[1] = header->time[1]; |
|
1384 | header->acquisitionTime[1] = header->time[1]; | |
1375 | header->acquisitionTime[2] = header->time[2]; |
|
1385 | header->acquisitionTime[2] = header->time[2]; | |
1376 | header->acquisitionTime[3] = header->time[3]; |
|
1386 | header->acquisitionTime[3] = header->time[3]; | |
1377 | header->acquisitionTime[4] = header->time[4]; |
|
1387 | header->acquisitionTime[4] = header->time[4]; | |
1378 | header->acquisitionTime[5] = header->time[5]; |
|
1388 | header->acquisitionTime[5] = header->time[5]; | |
1379 |
|
1389 | |||
1380 | // (4) SEND PACKET |
|
1390 | // (4) SEND PACKET | |
1381 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1391 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); | |
1382 | if (status != RTEMS_SUCCESSFUL) { |
|
1392 | if (status != RTEMS_SUCCESSFUL) { | |
1383 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1393 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) | |
1384 | } |
|
1394 | } | |
1385 | } |
|
1395 | } | |
1386 | } |
|
1396 | } | |
1387 |
|
1397 | |||
1388 | void spw_send_k_dump( ring_node *ring_node_to_send ) |
|
1398 | void spw_send_k_dump( ring_node *ring_node_to_send ) | |
1389 | { |
|
1399 | { | |
1390 | rtems_status_code status; |
|
1400 | rtems_status_code status; | |
1391 | Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump; |
|
1401 | Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump; | |
1392 | unsigned int packetLength; |
|
1402 | unsigned int packetLength; | |
1393 | unsigned int size; |
|
1403 | unsigned int size; | |
1394 |
|
1404 | |||
1395 | PRINTF("spw_send_k_dump\n") |
|
1405 | PRINTF("spw_send_k_dump\n") | |
1396 |
|
1406 | |||
1397 | kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address; |
|
1407 | kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address; | |
1398 |
|
1408 | |||
1399 | packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1]; |
|
1409 | packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1]; | |
1400 |
|
1410 | |||
1401 | size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; |
|
1411 | size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; | |
1402 |
|
1412 | |||
1403 | PRINTF2("packetLength %d, size %d\n", packetLength, size ) |
|
1413 | PRINTF2("packetLength %d, size %d\n", packetLength, size ) | |
1404 |
|
1414 | |||
1405 | status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size ); |
|
1415 | status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size ); | |
1406 |
|
1416 | |||
1407 | if (status == -1){ |
|
1417 | if (status == -1){ | |
1408 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) |
|
1418 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) | |
1409 | } |
|
1419 | } | |
1410 |
|
1420 | |||
1411 | ring_node_to_send->status = 0x00; |
|
1421 | ring_node_to_send->status = 0x00; | |
1412 | } |
|
1422 | } |
@@ -1,1606 +1,1606 | |||||
1 | /** Functions and tasks related to TeleCommand handling. |
|
1 | /** Functions and tasks related to TeleCommand handling. | |
2 | * |
|
2 | * | |
3 | * @file |
|
3 | * @file | |
4 | * @author P. LEROY |
|
4 | * @author P. LEROY | |
5 | * |
|
5 | * | |
6 | * A group of functions to handle TeleCommands:\n |
|
6 | * A group of functions to handle TeleCommands:\n | |
7 | * action launching\n |
|
7 | * action launching\n | |
8 | * TC parsing\n |
|
8 | * TC parsing\n | |
9 | * ... |
|
9 | * ... | |
10 | * |
|
10 | * | |
11 | */ |
|
11 | */ | |
12 |
|
12 | |||
13 | #include "tc_handler.h" |
|
13 | #include "tc_handler.h" | |
14 | #include "math.h" |
|
14 | #include "math.h" | |
15 |
|
15 | |||
16 | //*********** |
|
16 | //*********** | |
17 | // RTEMS TASK |
|
17 | // RTEMS TASK | |
18 |
|
18 | |||
19 | rtems_task actn_task( rtems_task_argument unused ) |
|
19 | rtems_task actn_task( rtems_task_argument unused ) | |
20 | { |
|
20 | { | |
21 | /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands. |
|
21 | /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands. | |
22 | * |
|
22 | * | |
23 | * @param unused is the starting argument of the RTEMS task |
|
23 | * @param unused is the starting argument of the RTEMS task | |
24 | * |
|
24 | * | |
25 | * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending |
|
25 | * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending | |
26 | * on the incoming TeleCommand. |
|
26 | * on the incoming TeleCommand. | |
27 | * |
|
27 | * | |
28 | */ |
|
28 | */ | |
29 |
|
29 | |||
30 | int result; |
|
30 | int result; | |
31 | rtems_status_code status; // RTEMS status code |
|
31 | rtems_status_code status; // RTEMS status code | |
32 | ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task |
|
32 | ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task | |
33 | size_t size; // size of the incoming TC packet |
|
33 | size_t size; // size of the incoming TC packet | |
34 | unsigned char subtype; // subtype of the current TC packet |
|
34 | unsigned char subtype; // subtype of the current TC packet | |
35 | unsigned char time[6]; |
|
35 | unsigned char time[6]; | |
36 | rtems_id queue_rcv_id; |
|
36 | rtems_id queue_rcv_id; | |
37 | rtems_id queue_snd_id; |
|
37 | rtems_id queue_snd_id; | |
38 |
|
38 | |||
39 | status = get_message_queue_id_recv( &queue_rcv_id ); |
|
39 | status = get_message_queue_id_recv( &queue_rcv_id ); | |
40 | if (status != RTEMS_SUCCESSFUL) |
|
40 | if (status != RTEMS_SUCCESSFUL) | |
41 | { |
|
41 | { | |
42 | PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) |
|
42 | PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | status = get_message_queue_id_send( &queue_snd_id ); |
|
45 | status = get_message_queue_id_send( &queue_snd_id ); | |
46 | if (status != RTEMS_SUCCESSFUL) |
|
46 | if (status != RTEMS_SUCCESSFUL) | |
47 | { |
|
47 | { | |
48 | PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) |
|
48 | PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | result = LFR_SUCCESSFUL; |
|
51 | result = LFR_SUCCESSFUL; | |
52 | subtype = 0; // subtype of the current TC packet |
|
52 | subtype = 0; // subtype of the current TC packet | |
53 |
|
53 | |||
54 | BOOT_PRINTF("in ACTN *** \n") |
|
54 | BOOT_PRINTF("in ACTN *** \n") | |
55 |
|
55 | |||
56 | while(1) |
|
56 | while(1) | |
57 | { |
|
57 | { | |
58 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, |
|
58 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, | |
59 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
|
59 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); | |
60 | getTime( time ); // set time to the current time |
|
60 | getTime( time ); // set time to the current time | |
61 | if (status!=RTEMS_SUCCESSFUL) |
|
61 | if (status!=RTEMS_SUCCESSFUL) | |
62 | { |
|
62 | { | |
63 | PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) |
|
63 | PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) | |
64 | } |
|
64 | } | |
65 | else |
|
65 | else | |
66 | { |
|
66 | { | |
67 | subtype = TC.serviceSubType; |
|
67 | subtype = TC.serviceSubType; | |
68 | switch(subtype) |
|
68 | switch(subtype) | |
69 | { |
|
69 | { | |
70 | case TC_SUBTYPE_RESET: |
|
70 | case TC_SUBTYPE_RESET: | |
71 | result = action_reset( &TC, queue_snd_id, time ); |
|
71 | result = action_reset( &TC, queue_snd_id, time ); | |
72 | close_action( &TC, result, queue_snd_id ); |
|
72 | close_action( &TC, result, queue_snd_id ); | |
73 | break; |
|
73 | break; | |
74 | case TC_SUBTYPE_LOAD_COMM: |
|
74 | case TC_SUBTYPE_LOAD_COMM: | |
75 | result = action_load_common_par( &TC ); |
|
75 | result = action_load_common_par( &TC ); | |
76 | close_action( &TC, result, queue_snd_id ); |
|
76 | close_action( &TC, result, queue_snd_id ); | |
77 | break; |
|
77 | break; | |
78 | case TC_SUBTYPE_LOAD_NORM: |
|
78 | case TC_SUBTYPE_LOAD_NORM: | |
79 | result = action_load_normal_par( &TC, queue_snd_id, time ); |
|
79 | result = action_load_normal_par( &TC, queue_snd_id, time ); | |
80 | close_action( &TC, result, queue_snd_id ); |
|
80 | close_action( &TC, result, queue_snd_id ); | |
81 | break; |
|
81 | break; | |
82 | case TC_SUBTYPE_LOAD_BURST: |
|
82 | case TC_SUBTYPE_LOAD_BURST: | |
83 | result = action_load_burst_par( &TC, queue_snd_id, time ); |
|
83 | result = action_load_burst_par( &TC, queue_snd_id, time ); | |
84 | close_action( &TC, result, queue_snd_id ); |
|
84 | close_action( &TC, result, queue_snd_id ); | |
85 | break; |
|
85 | break; | |
86 | case TC_SUBTYPE_LOAD_SBM1: |
|
86 | case TC_SUBTYPE_LOAD_SBM1: | |
87 | result = action_load_sbm1_par( &TC, queue_snd_id, time ); |
|
87 | result = action_load_sbm1_par( &TC, queue_snd_id, time ); | |
88 | close_action( &TC, result, queue_snd_id ); |
|
88 | close_action( &TC, result, queue_snd_id ); | |
89 | break; |
|
89 | break; | |
90 | case TC_SUBTYPE_LOAD_SBM2: |
|
90 | case TC_SUBTYPE_LOAD_SBM2: | |
91 | result = action_load_sbm2_par( &TC, queue_snd_id, time ); |
|
91 | result = action_load_sbm2_par( &TC, queue_snd_id, time ); | |
92 | close_action( &TC, result, queue_snd_id ); |
|
92 | close_action( &TC, result, queue_snd_id ); | |
93 | break; |
|
93 | break; | |
94 | case TC_SUBTYPE_DUMP: |
|
94 | case TC_SUBTYPE_DUMP: | |
95 | result = action_dump_par( &TC, queue_snd_id ); |
|
95 | result = action_dump_par( &TC, queue_snd_id ); | |
96 | close_action( &TC, result, queue_snd_id ); |
|
96 | close_action( &TC, result, queue_snd_id ); | |
97 | break; |
|
97 | break; | |
98 | case TC_SUBTYPE_ENTER: |
|
98 | case TC_SUBTYPE_ENTER: | |
99 | result = action_enter_mode( &TC, queue_snd_id ); |
|
99 | result = action_enter_mode( &TC, queue_snd_id ); | |
100 | close_action( &TC, result, queue_snd_id ); |
|
100 | close_action( &TC, result, queue_snd_id ); | |
101 | break; |
|
101 | break; | |
102 | case TC_SUBTYPE_UPDT_INFO: |
|
102 | case TC_SUBTYPE_UPDT_INFO: | |
103 | result = action_update_info( &TC, queue_snd_id ); |
|
103 | result = action_update_info( &TC, queue_snd_id ); | |
104 | close_action( &TC, result, queue_snd_id ); |
|
104 | close_action( &TC, result, queue_snd_id ); | |
105 | break; |
|
105 | break; | |
106 | case TC_SUBTYPE_EN_CAL: |
|
106 | case TC_SUBTYPE_EN_CAL: | |
107 | result = action_enable_calibration( &TC, queue_snd_id, time ); |
|
107 | result = action_enable_calibration( &TC, queue_snd_id, time ); | |
108 | close_action( &TC, result, queue_snd_id ); |
|
108 | close_action( &TC, result, queue_snd_id ); | |
109 | break; |
|
109 | break; | |
110 | case TC_SUBTYPE_DIS_CAL: |
|
110 | case TC_SUBTYPE_DIS_CAL: | |
111 | result = action_disable_calibration( &TC, queue_snd_id, time ); |
|
111 | result = action_disable_calibration( &TC, queue_snd_id, time ); | |
112 | close_action( &TC, result, queue_snd_id ); |
|
112 | close_action( &TC, result, queue_snd_id ); | |
113 | break; |
|
113 | break; | |
114 | case TC_SUBTYPE_LOAD_K: |
|
114 | case TC_SUBTYPE_LOAD_K: | |
115 | result = action_load_kcoefficients( &TC, queue_snd_id, time ); |
|
115 | result = action_load_kcoefficients( &TC, queue_snd_id, time ); | |
116 | close_action( &TC, result, queue_snd_id ); |
|
116 | close_action( &TC, result, queue_snd_id ); | |
117 | break; |
|
117 | break; | |
118 | case TC_SUBTYPE_DUMP_K: |
|
118 | case TC_SUBTYPE_DUMP_K: | |
119 | result = action_dump_kcoefficients( &TC, queue_snd_id, time ); |
|
119 | result = action_dump_kcoefficients( &TC, queue_snd_id, time ); | |
120 | close_action( &TC, result, queue_snd_id ); |
|
120 | close_action( &TC, result, queue_snd_id ); | |
121 | break; |
|
121 | break; | |
122 | case TC_SUBTYPE_LOAD_FBINS: |
|
122 | case TC_SUBTYPE_LOAD_FBINS: | |
123 | result = action_load_fbins_mask( &TC, queue_snd_id, time ); |
|
123 | result = action_load_fbins_mask( &TC, queue_snd_id, time ); | |
124 | close_action( &TC, result, queue_snd_id ); |
|
124 | close_action( &TC, result, queue_snd_id ); | |
125 | break; |
|
125 | break; | |
126 | case TC_SUBTYPE_UPDT_TIME: |
|
126 | case TC_SUBTYPE_UPDT_TIME: | |
127 | result = action_update_time( &TC ); |
|
127 | result = action_update_time( &TC ); | |
128 | close_action( &TC, result, queue_snd_id ); |
|
128 | close_action( &TC, result, queue_snd_id ); | |
129 | break; |
|
129 | break; | |
130 | default: |
|
130 | default: | |
131 | break; |
|
131 | break; | |
132 | } |
|
132 | } | |
133 | } |
|
133 | } | |
134 | } |
|
134 | } | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | //*********** |
|
137 | //*********** | |
138 | // TC ACTIONS |
|
138 | // TC ACTIONS | |
139 |
|
139 | |||
140 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
140 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | |
141 | { |
|
141 | { | |
142 | /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received. |
|
142 | /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received. | |
143 | * |
|
143 | * | |
144 | * @param TC points to the TeleCommand packet that is being processed |
|
144 | * @param TC points to the TeleCommand packet that is being processed | |
145 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
145 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
146 | * |
|
146 | * | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | PRINTF("this is the end!!!\n") |
|
149 | PRINTF("this is the end!!!\n") | |
150 | exit(0); |
|
150 | exit(0); | |
151 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); |
|
151 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); | |
152 | return LFR_DEFAULT; |
|
152 | return LFR_DEFAULT; | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
155 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) | |
156 | { |
|
156 | { | |
157 | /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received. |
|
157 | /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received. | |
158 | * |
|
158 | * | |
159 | * @param TC points to the TeleCommand packet that is being processed |
|
159 | * @param TC points to the TeleCommand packet that is being processed | |
160 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
160 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
161 | * |
|
161 | * | |
162 | */ |
|
162 | */ | |
163 |
|
163 | |||
164 | rtems_status_code status; |
|
164 | rtems_status_code status; | |
165 | unsigned char requestedMode; |
|
165 | unsigned char requestedMode; | |
166 | unsigned int *transitionCoarseTime_ptr; |
|
166 | unsigned int *transitionCoarseTime_ptr; | |
167 | unsigned int transitionCoarseTime; |
|
167 | unsigned int transitionCoarseTime; | |
168 | unsigned char * bytePosPtr; |
|
168 | unsigned char * bytePosPtr; | |
169 |
|
169 | |||
170 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
170 | bytePosPtr = (unsigned char *) &TC->packetID; | |
171 |
|
171 | |||
172 | requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ]; |
|
172 | requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ]; | |
173 | transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); |
|
173 | transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); | |
174 | transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff; |
|
174 | transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff; | |
175 |
|
175 | |||
176 | status = check_mode_value( requestedMode ); |
|
176 | status = check_mode_value( requestedMode ); | |
177 |
|
177 | |||
178 | if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent |
|
178 | if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent | |
179 | { |
|
179 | { | |
180 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode ); |
|
180 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode ); | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | else // the mode value is valid, check the transition |
|
183 | else // the mode value is valid, check the transition | |
184 | { |
|
184 | { | |
185 | status = check_mode_transition(requestedMode); |
|
185 | status = check_mode_transition(requestedMode); | |
186 | if (status != LFR_SUCCESSFUL) |
|
186 | if (status != LFR_SUCCESSFUL) | |
187 | { |
|
187 | { | |
188 | PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n") |
|
188 | PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n") | |
189 | send_tm_lfr_tc_exe_not_executable( TC, queue_id ); |
|
189 | send_tm_lfr_tc_exe_not_executable( TC, queue_id ); | |
190 | } |
|
190 | } | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date |
|
193 | if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date | |
194 | { |
|
194 | { | |
195 | status = check_transition_date( transitionCoarseTime ); |
|
195 | status = check_transition_date( transitionCoarseTime ); | |
196 | if (status != LFR_SUCCESSFUL) |
|
196 | if (status != LFR_SUCCESSFUL) | |
197 | { |
|
197 | { | |
198 | PRINTF("ERR *** in action_enter_mode *** check_transition_date\n") |
|
198 | PRINTF("ERR *** in action_enter_mode *** check_transition_date\n") | |
199 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, |
|
199 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, | |
200 | BYTE_POS_CP_LFR_ENTER_MODE_TIME, |
|
200 | BYTE_POS_CP_LFR_ENTER_MODE_TIME, | |
201 | bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] ); |
|
201 | bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] ); | |
202 | } |
|
202 | } | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode |
|
205 | if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode | |
206 | { |
|
206 | { | |
207 | PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode); |
|
207 | PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode); | |
208 |
|
208 | |||
209 | update_last_valid_transition_date( transitionCoarseTime ); |
|
209 | update_last_valid_transition_date( transitionCoarseTime ); | |
210 |
|
210 | |||
211 | switch(requestedMode) |
|
211 | switch(requestedMode) | |
212 | { |
|
212 | { | |
213 | case LFR_MODE_STANDBY: |
|
213 | case LFR_MODE_STANDBY: | |
214 | status = enter_mode_standby(); |
|
214 | status = enter_mode_standby(); | |
215 | break; |
|
215 | break; | |
216 | case LFR_MODE_NORMAL: |
|
216 | case LFR_MODE_NORMAL: | |
217 | status = enter_mode_normal( transitionCoarseTime ); |
|
217 | status = enter_mode_normal( transitionCoarseTime ); | |
218 | break; |
|
218 | break; | |
219 | case LFR_MODE_BURST: |
|
219 | case LFR_MODE_BURST: | |
220 | status = enter_mode_burst( transitionCoarseTime ); |
|
220 | status = enter_mode_burst( transitionCoarseTime ); | |
221 | break; |
|
221 | break; | |
222 | case LFR_MODE_SBM1: |
|
222 | case LFR_MODE_SBM1: | |
223 | status = enter_mode_sbm1( transitionCoarseTime ); |
|
223 | status = enter_mode_sbm1( transitionCoarseTime ); | |
224 | break; |
|
224 | break; | |
225 | case LFR_MODE_SBM2: |
|
225 | case LFR_MODE_SBM2: | |
226 | status = enter_mode_sbm2( transitionCoarseTime ); |
|
226 | status = enter_mode_sbm2( transitionCoarseTime ); | |
227 | break; |
|
227 | break; | |
228 | default: |
|
228 | default: | |
229 | break; |
|
229 | break; | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | return status; |
|
233 | return status; | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) |
|
236 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) | |
237 | { |
|
237 | { | |
238 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. |
|
238 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. | |
239 | * |
|
239 | * | |
240 | * @param TC points to the TeleCommand packet that is being processed |
|
240 | * @param TC points to the TeleCommand packet that is being processed | |
241 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
241 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
242 | * |
|
242 | * | |
243 | * @return LFR directive status code: |
|
243 | * @return LFR directive status code: | |
244 | * - LFR_DEFAULT |
|
244 | * - LFR_DEFAULT | |
245 | * - LFR_SUCCESSFUL |
|
245 | * - LFR_SUCCESSFUL | |
246 | * |
|
246 | * | |
247 | */ |
|
247 | */ | |
248 |
|
248 | |||
249 | unsigned int val; |
|
249 | unsigned int val; | |
250 | int result; |
|
250 | int result; | |
251 | unsigned int status; |
|
251 | unsigned int status; | |
252 | unsigned char mode; |
|
252 | unsigned char mode; | |
253 | unsigned char * bytePosPtr; |
|
253 | unsigned char * bytePosPtr; | |
254 |
|
254 | |||
255 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
255 | bytePosPtr = (unsigned char *) &TC->packetID; | |
256 |
|
256 | |||
257 | // check LFR mode |
|
257 | // check LFR mode | |
258 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1; |
|
258 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1; | |
259 | status = check_update_info_hk_lfr_mode( mode ); |
|
259 | status = check_update_info_hk_lfr_mode( mode ); | |
260 | if (status == LFR_SUCCESSFUL) // check TDS mode |
|
260 | if (status == LFR_SUCCESSFUL) // check TDS mode | |
261 | { |
|
261 | { | |
262 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4; |
|
262 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4; | |
263 | status = check_update_info_hk_tds_mode( mode ); |
|
263 | status = check_update_info_hk_tds_mode( mode ); | |
264 | } |
|
264 | } | |
265 | if (status == LFR_SUCCESSFUL) // check THR mode |
|
265 | if (status == LFR_SUCCESSFUL) // check THR mode | |
266 | { |
|
266 | { | |
267 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f); |
|
267 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f); | |
268 | status = check_update_info_hk_thr_mode( mode ); |
|
268 | status = check_update_info_hk_thr_mode( mode ); | |
269 | } |
|
269 | } | |
270 | if (status == LFR_SUCCESSFUL) // if the parameter check is successful |
|
270 | if (status == LFR_SUCCESSFUL) // if the parameter check is successful | |
271 | { |
|
271 | { | |
272 | val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256 |
|
272 | val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256 | |
273 | + housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; |
|
273 | + housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; | |
274 | val++; |
|
274 | val++; | |
275 | housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8); |
|
275 | housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8); | |
276 | housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); |
|
276 | housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | // pa_bia_status_info |
|
279 | // pa_bia_status_info | |
280 | // => pa_bia_mode_mux_set 3 bits |
|
280 | // => pa_bia_mode_mux_set 3 bits | |
281 | // => pa_bia_mode_hv_enabled 1 bit |
|
281 | // => pa_bia_mode_hv_enabled 1 bit | |
282 | // => pa_bia_mode_bias1_enabled 1 bit |
|
282 | // => pa_bia_mode_bias1_enabled 1 bit | |
283 | // => pa_bia_mode_bias2_enabled 1 bit |
|
283 | // => pa_bia_mode_bias2_enabled 1 bit | |
284 | // => pa_bia_mode_bias3_enabled 1 bit |
|
284 | // => pa_bia_mode_bias3_enabled 1 bit | |
285 | // => pa_bia_on_off (cp_dpu_bias_on_off) |
|
285 | // => pa_bia_on_off (cp_dpu_bias_on_off) | |
286 | pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & 0xfe; // [1111 1110] |
|
286 | pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & 0xfe; // [1111 1110] | |
287 | pa_bia_status_info = pa_bia_status_info |
|
287 | pa_bia_status_info = pa_bia_status_info | |
288 | | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 0x1); |
|
288 | | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 0x1); | |
289 |
|
289 | |||
290 | result = status; |
|
290 | result = status; | |
291 |
|
291 | |||
292 | return result; |
|
292 | return result; | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
295 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | |
296 | { |
|
296 | { | |
297 | /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received. |
|
297 | /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received. | |
298 | * |
|
298 | * | |
299 | * @param TC points to the TeleCommand packet that is being processed |
|
299 | * @param TC points to the TeleCommand packet that is being processed | |
300 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
300 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
301 | * |
|
301 | * | |
302 | */ |
|
302 | */ | |
303 |
|
303 | |||
304 | int result; |
|
304 | int result; | |
305 |
|
305 | |||
306 | result = LFR_DEFAULT; |
|
306 | result = LFR_DEFAULT; | |
307 |
|
307 | |||
308 | setCalibration( true ); |
|
308 | setCalibration( true ); | |
309 |
|
309 | |||
310 | result = LFR_SUCCESSFUL; |
|
310 | result = LFR_SUCCESSFUL; | |
311 |
|
311 | |||
312 | return result; |
|
312 | return result; | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
315 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | |
316 | { |
|
316 | { | |
317 | /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received. |
|
317 | /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received. | |
318 | * |
|
318 | * | |
319 | * @param TC points to the TeleCommand packet that is being processed |
|
319 | * @param TC points to the TeleCommand packet that is being processed | |
320 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
320 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
321 | * |
|
321 | * | |
322 | */ |
|
322 | */ | |
323 |
|
323 | |||
324 | int result; |
|
324 | int result; | |
325 |
|
325 | |||
326 | result = LFR_DEFAULT; |
|
326 | result = LFR_DEFAULT; | |
327 |
|
327 | |||
328 | setCalibration( false ); |
|
328 | setCalibration( false ); | |
329 |
|
329 | |||
330 | result = LFR_SUCCESSFUL; |
|
330 | result = LFR_SUCCESSFUL; | |
331 |
|
331 | |||
332 | return result; |
|
332 | return result; | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | int action_update_time(ccsdsTelecommandPacket_t *TC) |
|
335 | int action_update_time(ccsdsTelecommandPacket_t *TC) | |
336 | { |
|
336 | { | |
337 | /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received. |
|
337 | /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received. | |
338 | * |
|
338 | * | |
339 | * @param TC points to the TeleCommand packet that is being processed |
|
339 | * @param TC points to the TeleCommand packet that is being processed | |
340 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
340 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
341 | * |
|
341 | * | |
342 | * @return LFR_SUCCESSFUL |
|
342 | * @return LFR_SUCCESSFUL | |
343 | * |
|
343 | * | |
344 | */ |
|
344 | */ | |
345 |
|
345 | |||
346 | unsigned int val; |
|
346 | unsigned int val; | |
347 |
|
347 | |||
348 | time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) |
|
348 | time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) | |
349 | + (TC->dataAndCRC[1] << 16) |
|
349 | + (TC->dataAndCRC[1] << 16) | |
350 | + (TC->dataAndCRC[2] << 8) |
|
350 | + (TC->dataAndCRC[2] << 8) | |
351 | + TC->dataAndCRC[3]; |
|
351 | + TC->dataAndCRC[3]; | |
352 |
|
352 | |||
353 | val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256 |
|
353 | val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256 | |
354 | + housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; |
|
354 | + housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; | |
355 | val++; |
|
355 | val++; | |
356 | housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8); |
|
356 | housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8); | |
357 | housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); |
|
357 | housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); | |
358 |
|
358 | |||
359 | return LFR_SUCCESSFUL; |
|
359 | return LFR_SUCCESSFUL; | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | //******************* |
|
362 | //******************* | |
363 | // ENTERING THE MODES |
|
363 | // ENTERING THE MODES | |
364 | int check_mode_value( unsigned char requestedMode ) |
|
364 | int check_mode_value( unsigned char requestedMode ) | |
365 | { |
|
365 | { | |
366 | int status; |
|
366 | int status; | |
367 |
|
367 | |||
368 | if ( (requestedMode != LFR_MODE_STANDBY) |
|
368 | if ( (requestedMode != LFR_MODE_STANDBY) | |
369 | && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) |
|
369 | && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) | |
370 | && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) |
|
370 | && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) | |
371 | { |
|
371 | { | |
372 | status = LFR_DEFAULT; |
|
372 | status = LFR_DEFAULT; | |
373 | } |
|
373 | } | |
374 | else |
|
374 | else | |
375 | { |
|
375 | { | |
376 | status = LFR_SUCCESSFUL; |
|
376 | status = LFR_SUCCESSFUL; | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | return status; |
|
379 | return status; | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | int check_mode_transition( unsigned char requestedMode ) |
|
382 | int check_mode_transition( unsigned char requestedMode ) | |
383 | { |
|
383 | { | |
384 | /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE. |
|
384 | /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE. | |
385 | * |
|
385 | * | |
386 | * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE |
|
386 | * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE | |
387 | * |
|
387 | * | |
388 | * @return LFR directive status codes: |
|
388 | * @return LFR directive status codes: | |
389 | * - LFR_SUCCESSFUL - the transition is authorized |
|
389 | * - LFR_SUCCESSFUL - the transition is authorized | |
390 | * - LFR_DEFAULT - the transition is not authorized |
|
390 | * - LFR_DEFAULT - the transition is not authorized | |
391 | * |
|
391 | * | |
392 | */ |
|
392 | */ | |
393 |
|
393 | |||
394 | int status; |
|
394 | int status; | |
395 |
|
395 | |||
396 | switch (requestedMode) |
|
396 | switch (requestedMode) | |
397 | { |
|
397 | { | |
398 | case LFR_MODE_STANDBY: |
|
398 | case LFR_MODE_STANDBY: | |
399 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { |
|
399 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { | |
400 | status = LFR_DEFAULT; |
|
400 | status = LFR_DEFAULT; | |
401 | } |
|
401 | } | |
402 | else |
|
402 | else | |
403 | { |
|
403 | { | |
404 | status = LFR_SUCCESSFUL; |
|
404 | status = LFR_SUCCESSFUL; | |
405 | } |
|
405 | } | |
406 | break; |
|
406 | break; | |
407 | case LFR_MODE_NORMAL: |
|
407 | case LFR_MODE_NORMAL: | |
408 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { |
|
408 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { | |
409 | status = LFR_DEFAULT; |
|
409 | status = LFR_DEFAULT; | |
410 | } |
|
410 | } | |
411 | else { |
|
411 | else { | |
412 | status = LFR_SUCCESSFUL; |
|
412 | status = LFR_SUCCESSFUL; | |
413 | } |
|
413 | } | |
414 | break; |
|
414 | break; | |
415 | case LFR_MODE_BURST: |
|
415 | case LFR_MODE_BURST: | |
416 | if ( lfrCurrentMode == LFR_MODE_BURST ) { |
|
416 | if ( lfrCurrentMode == LFR_MODE_BURST ) { | |
417 | status = LFR_DEFAULT; |
|
417 | status = LFR_DEFAULT; | |
418 | } |
|
418 | } | |
419 | else { |
|
419 | else { | |
420 | status = LFR_SUCCESSFUL; |
|
420 | status = LFR_SUCCESSFUL; | |
421 | } |
|
421 | } | |
422 | break; |
|
422 | break; | |
423 | case LFR_MODE_SBM1: |
|
423 | case LFR_MODE_SBM1: | |
424 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { |
|
424 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { | |
425 | status = LFR_DEFAULT; |
|
425 | status = LFR_DEFAULT; | |
426 | } |
|
426 | } | |
427 | else { |
|
427 | else { | |
428 | status = LFR_SUCCESSFUL; |
|
428 | status = LFR_SUCCESSFUL; | |
429 | } |
|
429 | } | |
430 | break; |
|
430 | break; | |
431 | case LFR_MODE_SBM2: |
|
431 | case LFR_MODE_SBM2: | |
432 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { |
|
432 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { | |
433 | status = LFR_DEFAULT; |
|
433 | status = LFR_DEFAULT; | |
434 | } |
|
434 | } | |
435 | else { |
|
435 | else { | |
436 | status = LFR_SUCCESSFUL; |
|
436 | status = LFR_SUCCESSFUL; | |
437 | } |
|
437 | } | |
438 | break; |
|
438 | break; | |
439 | default: |
|
439 | default: | |
440 | status = LFR_DEFAULT; |
|
440 | status = LFR_DEFAULT; | |
441 | break; |
|
441 | break; | |
442 | } |
|
442 | } | |
443 |
|
443 | |||
444 | return status; |
|
444 | return status; | |
445 | } |
|
445 | } | |
446 |
|
446 | |||
447 | void update_last_valid_transition_date( unsigned int transitionCoarseTime ) |
|
447 | void update_last_valid_transition_date( unsigned int transitionCoarseTime ) | |
448 | { |
|
448 | { | |
449 | lastValidEnterModeTime = transitionCoarseTime; |
|
449 | lastValidEnterModeTime = transitionCoarseTime; | |
450 | } |
|
450 | } | |
451 |
|
451 | |||
452 | int check_transition_date( unsigned int transitionCoarseTime ) |
|
452 | int check_transition_date( unsigned int transitionCoarseTime ) | |
453 | { |
|
453 | { | |
454 | int status; |
|
454 | int status; | |
455 | unsigned int localCoarseTime; |
|
455 | unsigned int localCoarseTime; | |
456 | unsigned int deltaCoarseTime; |
|
456 | unsigned int deltaCoarseTime; | |
457 |
|
457 | |||
458 | status = LFR_SUCCESSFUL; |
|
458 | status = LFR_SUCCESSFUL; | |
459 |
|
459 | |||
460 | if (transitionCoarseTime == 0) // transition time = 0 means an instant transition |
|
460 | if (transitionCoarseTime == 0) // transition time = 0 means an instant transition | |
461 | { |
|
461 | { | |
462 | status = LFR_SUCCESSFUL; |
|
462 | status = LFR_SUCCESSFUL; | |
463 | } |
|
463 | } | |
464 | else |
|
464 | else | |
465 | { |
|
465 | { | |
466 | localCoarseTime = time_management_regs->coarse_time & 0x7fffffff; |
|
466 | localCoarseTime = time_management_regs->coarse_time & 0x7fffffff; | |
467 |
|
467 | |||
468 | PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime) |
|
468 | PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime) | |
469 |
|
469 | |||
470 | if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322 |
|
470 | if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322 | |
471 | { |
|
471 | { | |
472 | status = LFR_DEFAULT; |
|
472 | status = LFR_DEFAULT; | |
473 | PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n") |
|
473 | PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n") | |
474 | } |
|
474 | } | |
475 |
|
475 | |||
476 | if (status == LFR_SUCCESSFUL) |
|
476 | if (status == LFR_SUCCESSFUL) | |
477 | { |
|
477 | { | |
478 | deltaCoarseTime = transitionCoarseTime - localCoarseTime; |
|
478 | deltaCoarseTime = transitionCoarseTime - localCoarseTime; | |
479 | if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323 |
|
479 | if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323 | |
480 | { |
|
480 | { | |
481 | status = LFR_DEFAULT; |
|
481 | status = LFR_DEFAULT; | |
482 | PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime) |
|
482 | PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime) | |
483 | } |
|
483 | } | |
484 | } |
|
484 | } | |
485 | } |
|
485 | } | |
486 |
|
486 | |||
487 | return status; |
|
487 | return status; | |
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | int restart_asm_activities( unsigned char lfrRequestedMode ) |
|
490 | int restart_asm_activities( unsigned char lfrRequestedMode ) | |
491 | { |
|
491 | { | |
492 | rtems_status_code status; |
|
492 | rtems_status_code status; | |
493 |
|
493 | |||
494 | status = stop_spectral_matrices(); |
|
494 | status = stop_spectral_matrices(); | |
495 |
|
495 | |||
496 | status = restart_asm_tasks( lfrRequestedMode ); |
|
496 | status = restart_asm_tasks( lfrRequestedMode ); | |
497 |
|
497 | |||
498 | launch_spectral_matrix(); |
|
498 | launch_spectral_matrix(); | |
499 |
|
499 | |||
500 | return status; |
|
500 | return status; | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 | int stop_spectral_matrices( void ) |
|
503 | int stop_spectral_matrices( void ) | |
504 | { |
|
504 | { | |
505 | /** This function stops and restarts the current mode average spectral matrices activities. |
|
505 | /** This function stops and restarts the current mode average spectral matrices activities. | |
506 | * |
|
506 | * | |
507 | * @return RTEMS directive status codes: |
|
507 | * @return RTEMS directive status codes: | |
508 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
508 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
509 | * - RTEMS_INVALID_ID - task id invalid |
|
509 | * - RTEMS_INVALID_ID - task id invalid | |
510 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
510 | * - RTEMS_ALREADY_SUSPENDED - task already suspended | |
511 | * |
|
511 | * | |
512 | */ |
|
512 | */ | |
513 |
|
513 | |||
514 | rtems_status_code status; |
|
514 | rtems_status_code status; | |
515 |
|
515 | |||
516 | status = RTEMS_SUCCESSFUL; |
|
516 | status = RTEMS_SUCCESSFUL; | |
517 |
|
517 | |||
518 | // (1) mask interruptions |
|
518 | // (1) mask interruptions | |
519 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
519 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | |
520 |
|
520 | |||
521 | // (2) reset spectral matrices registers |
|
521 | // (2) reset spectral matrices registers | |
522 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices |
|
522 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices | |
523 | reset_sm_status(); |
|
523 | reset_sm_status(); | |
524 |
|
524 | |||
525 | // (3) clear interruptions |
|
525 | // (3) clear interruptions | |
526 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
526 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | |
527 |
|
527 | |||
528 | // suspend several tasks |
|
528 | // suspend several tasks | |
529 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
529 | if (lfrCurrentMode != LFR_MODE_STANDBY) { | |
530 | status = suspend_asm_tasks(); |
|
530 | status = suspend_asm_tasks(); | |
531 | } |
|
531 | } | |
532 |
|
532 | |||
533 | if (status != RTEMS_SUCCESSFUL) |
|
533 | if (status != RTEMS_SUCCESSFUL) | |
534 | { |
|
534 | { | |
535 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
535 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) | |
536 | } |
|
536 | } | |
537 |
|
537 | |||
538 | return status; |
|
538 | return status; | |
539 | } |
|
539 | } | |
540 |
|
540 | |||
541 | int stop_current_mode( void ) |
|
541 | int stop_current_mode( void ) | |
542 | { |
|
542 | { | |
543 | /** This function stops the current mode by masking interrupt lines and suspending science tasks. |
|
543 | /** This function stops the current mode by masking interrupt lines and suspending science tasks. | |
544 | * |
|
544 | * | |
545 | * @return RTEMS directive status codes: |
|
545 | * @return RTEMS directive status codes: | |
546 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
546 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
547 | * - RTEMS_INVALID_ID - task id invalid |
|
547 | * - RTEMS_INVALID_ID - task id invalid | |
548 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
548 | * - RTEMS_ALREADY_SUSPENDED - task already suspended | |
549 | * |
|
549 | * | |
550 | */ |
|
550 | */ | |
551 |
|
551 | |||
552 | rtems_status_code status; |
|
552 | rtems_status_code status; | |
553 |
|
553 | |||
554 | status = RTEMS_SUCCESSFUL; |
|
554 | status = RTEMS_SUCCESSFUL; | |
555 |
|
555 | |||
556 | // (1) mask interruptions |
|
556 | // (1) mask interruptions | |
557 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt |
|
557 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt | |
558 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
558 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | |
559 |
|
559 | |||
560 | // (2) reset waveform picker registers |
|
560 | // (2) reset waveform picker registers | |
561 | reset_wfp_burst_enable(); // reset burst and enable bits |
|
561 | reset_wfp_burst_enable(); // reset burst and enable bits | |
562 | reset_wfp_status(); // reset all the status bits |
|
562 | reset_wfp_status(); // reset all the status bits | |
563 |
|
563 | |||
564 | // (3) reset spectral matrices registers |
|
564 | // (3) reset spectral matrices registers | |
565 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices |
|
565 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices | |
566 | reset_sm_status(); |
|
566 | reset_sm_status(); | |
567 |
|
567 | |||
568 | // reset lfr VHDL module |
|
568 | // reset lfr VHDL module | |
569 | reset_lfr(); |
|
569 | reset_lfr(); | |
570 |
|
570 | |||
571 | reset_extractSWF(); // reset the extractSWF flag to false |
|
571 | reset_extractSWF(); // reset the extractSWF flag to false | |
572 |
|
572 | |||
573 | // (4) clear interruptions |
|
573 | // (4) clear interruptions | |
574 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt |
|
574 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt | |
575 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
575 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | |
576 |
|
576 | |||
577 | // suspend several tasks |
|
577 | // suspend several tasks | |
578 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
578 | if (lfrCurrentMode != LFR_MODE_STANDBY) { | |
579 | status = suspend_science_tasks(); |
|
579 | status = suspend_science_tasks(); | |
580 | } |
|
580 | } | |
581 |
|
581 | |||
582 | if (status != RTEMS_SUCCESSFUL) |
|
582 | if (status != RTEMS_SUCCESSFUL) | |
583 | { |
|
583 | { | |
584 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
584 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) | |
585 | } |
|
585 | } | |
586 |
|
586 | |||
587 | return status; |
|
587 | return status; | |
588 | } |
|
588 | } | |
589 |
|
589 | |||
590 | int enter_mode_standby() |
|
590 | int enter_mode_standby() | |
591 | { |
|
591 | { | |
592 | /** This function is used to put LFR in the STANDBY mode. |
|
592 | /** This function is used to put LFR in the STANDBY mode. | |
593 | * |
|
593 | * | |
594 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
594 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
595 | * |
|
595 | * | |
596 | * @return RTEMS directive status codes: |
|
596 | * @return RTEMS directive status codes: | |
597 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
597 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
598 | * - RTEMS_INVALID_ID - task id invalid |
|
598 | * - RTEMS_INVALID_ID - task id invalid | |
599 | * - RTEMS_INCORRECT_STATE - task never started |
|
599 | * - RTEMS_INCORRECT_STATE - task never started | |
600 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
600 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
601 | * |
|
601 | * | |
602 | * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE |
|
602 | * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE | |
603 | * is immediate. |
|
603 | * is immediate. | |
604 | * |
|
604 | * | |
605 | */ |
|
605 | */ | |
606 |
|
606 | |||
607 | int status; |
|
607 | int status; | |
608 |
|
608 | |||
609 | status = stop_current_mode(); // STOP THE CURRENT MODE |
|
609 | status = stop_current_mode(); // STOP THE CURRENT MODE | |
610 |
|
610 | |||
611 | #ifdef PRINT_TASK_STATISTICS |
|
611 | #ifdef PRINT_TASK_STATISTICS | |
612 | rtems_cpu_usage_report(); |
|
612 | rtems_cpu_usage_report(); | |
613 | #endif |
|
613 | #endif | |
614 |
|
614 | |||
615 | #ifdef PRINT_STACK_REPORT |
|
615 | #ifdef PRINT_STACK_REPORT | |
616 | PRINTF("stack report selected\n") |
|
616 | PRINTF("stack report selected\n") | |
617 | rtems_stack_checker_report_usage(); |
|
617 | rtems_stack_checker_report_usage(); | |
618 | #endif |
|
618 | #endif | |
619 |
|
619 | |||
620 | return status; |
|
620 | return status; | |
621 | } |
|
621 | } | |
622 |
|
622 | |||
623 | int enter_mode_normal( unsigned int transitionCoarseTime ) |
|
623 | int enter_mode_normal( unsigned int transitionCoarseTime ) | |
624 | { |
|
624 | { | |
625 | /** This function is used to start the NORMAL mode. |
|
625 | /** This function is used to start the NORMAL mode. | |
626 | * |
|
626 | * | |
627 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
627 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
628 | * |
|
628 | * | |
629 | * @return RTEMS directive status codes: |
|
629 | * @return RTEMS directive status codes: | |
630 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
630 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
631 | * - RTEMS_INVALID_ID - task id invalid |
|
631 | * - RTEMS_INVALID_ID - task id invalid | |
632 | * - RTEMS_INCORRECT_STATE - task never started |
|
632 | * - RTEMS_INCORRECT_STATE - task never started | |
633 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
633 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
634 | * |
|
634 | * | |
635 | * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2, |
|
635 | * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2, | |
636 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. |
|
636 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. | |
637 | * |
|
637 | * | |
638 | */ |
|
638 | */ | |
639 |
|
639 | |||
640 | int status; |
|
640 | int status; | |
641 |
|
641 | |||
642 | #ifdef PRINT_TASK_STATISTICS |
|
642 | #ifdef PRINT_TASK_STATISTICS | |
643 | rtems_cpu_usage_reset(); |
|
643 | rtems_cpu_usage_reset(); | |
644 | #endif |
|
644 | #endif | |
645 |
|
645 | |||
646 | status = RTEMS_UNSATISFIED; |
|
646 | status = RTEMS_UNSATISFIED; | |
647 |
|
647 | |||
648 | switch( lfrCurrentMode ) |
|
648 | switch( lfrCurrentMode ) | |
649 | { |
|
649 | { | |
650 | case LFR_MODE_STANDBY: |
|
650 | case LFR_MODE_STANDBY: | |
651 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks |
|
651 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks | |
652 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
652 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
653 | { |
|
653 | { | |
654 | launch_spectral_matrix( ); |
|
654 | launch_spectral_matrix( ); | |
655 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); |
|
655 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); | |
656 | } |
|
656 | } | |
657 | break; |
|
657 | break; | |
658 | case LFR_MODE_BURST: |
|
658 | case LFR_MODE_BURST: | |
659 | status = stop_current_mode(); // stop the current mode |
|
659 | status = stop_current_mode(); // stop the current mode | |
660 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks |
|
660 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks | |
661 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
661 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
662 | { |
|
662 | { | |
663 | launch_spectral_matrix( ); |
|
663 | launch_spectral_matrix( ); | |
664 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); |
|
664 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); | |
665 | } |
|
665 | } | |
666 | break; |
|
666 | break; | |
667 | case LFR_MODE_SBM1: |
|
667 | case LFR_MODE_SBM1: | |
668 |
restart_asm_activities( LFR_MODE_NORMAL ); // |
|
668 | restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters | |
669 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
669 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
670 | break; |
|
670 | break; | |
671 | case LFR_MODE_SBM2: |
|
671 | case LFR_MODE_SBM2: | |
672 |
restart_asm_activities( LFR_MODE_NORMAL ); // |
|
672 | restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters | |
673 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
673 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
674 | break; |
|
674 | break; | |
675 | default: |
|
675 | default: | |
676 | break; |
|
676 | break; | |
677 | } |
|
677 | } | |
678 |
|
678 | |||
679 | if (status != RTEMS_SUCCESSFUL) |
|
679 | if (status != RTEMS_SUCCESSFUL) | |
680 | { |
|
680 | { | |
681 | PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status) |
|
681 | PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status) | |
682 | status = RTEMS_UNSATISFIED; |
|
682 | status = RTEMS_UNSATISFIED; | |
683 | } |
|
683 | } | |
684 |
|
684 | |||
685 | return status; |
|
685 | return status; | |
686 | } |
|
686 | } | |
687 |
|
687 | |||
688 | int enter_mode_burst( unsigned int transitionCoarseTime ) |
|
688 | int enter_mode_burst( unsigned int transitionCoarseTime ) | |
689 | { |
|
689 | { | |
690 | /** This function is used to start the BURST mode. |
|
690 | /** This function is used to start the BURST mode. | |
691 | * |
|
691 | * | |
692 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
692 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
693 | * |
|
693 | * | |
694 | * @return RTEMS directive status codes: |
|
694 | * @return RTEMS directive status codes: | |
695 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
695 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
696 | * - RTEMS_INVALID_ID - task id invalid |
|
696 | * - RTEMS_INVALID_ID - task id invalid | |
697 | * - RTEMS_INCORRECT_STATE - task never started |
|
697 | * - RTEMS_INCORRECT_STATE - task never started | |
698 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
698 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
699 | * |
|
699 | * | |
700 | * The way the BURST mode is started does not depend on the LFR current mode. |
|
700 | * The way the BURST mode is started does not depend on the LFR current mode. | |
701 | * |
|
701 | * | |
702 | */ |
|
702 | */ | |
703 |
|
703 | |||
704 |
|
704 | |||
705 | int status; |
|
705 | int status; | |
706 |
|
706 | |||
707 | #ifdef PRINT_TASK_STATISTICS |
|
707 | #ifdef PRINT_TASK_STATISTICS | |
708 | rtems_cpu_usage_reset(); |
|
708 | rtems_cpu_usage_reset(); | |
709 | #endif |
|
709 | #endif | |
710 |
|
710 | |||
711 | status = stop_current_mode(); // stop the current mode |
|
711 | status = stop_current_mode(); // stop the current mode | |
712 | status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks |
|
712 | status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks | |
713 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
713 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
714 | { |
|
714 | { | |
715 | launch_spectral_matrix( ); |
|
715 | launch_spectral_matrix( ); | |
716 | launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime ); |
|
716 | launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime ); | |
717 | } |
|
717 | } | |
718 |
|
718 | |||
719 | if (status != RTEMS_SUCCESSFUL) |
|
719 | if (status != RTEMS_SUCCESSFUL) | |
720 | { |
|
720 | { | |
721 | PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status) |
|
721 | PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status) | |
722 | status = RTEMS_UNSATISFIED; |
|
722 | status = RTEMS_UNSATISFIED; | |
723 | } |
|
723 | } | |
724 |
|
724 | |||
725 | return status; |
|
725 | return status; | |
726 | } |
|
726 | } | |
727 |
|
727 | |||
728 | int enter_mode_sbm1( unsigned int transitionCoarseTime ) |
|
728 | int enter_mode_sbm1( unsigned int transitionCoarseTime ) | |
729 | { |
|
729 | { | |
730 | /** This function is used to start the SBM1 mode. |
|
730 | /** This function is used to start the SBM1 mode. | |
731 | * |
|
731 | * | |
732 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
732 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
733 | * |
|
733 | * | |
734 | * @return RTEMS directive status codes: |
|
734 | * @return RTEMS directive status codes: | |
735 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
735 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
736 | * - RTEMS_INVALID_ID - task id invalid |
|
736 | * - RTEMS_INVALID_ID - task id invalid | |
737 | * - RTEMS_INCORRECT_STATE - task never started |
|
737 | * - RTEMS_INCORRECT_STATE - task never started | |
738 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
738 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
739 | * |
|
739 | * | |
740 | * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2, |
|
740 | * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2, | |
741 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other |
|
741 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other | |
742 | * cases, the acquisition is completely restarted. |
|
742 | * cases, the acquisition is completely restarted. | |
743 | * |
|
743 | * | |
744 | */ |
|
744 | */ | |
745 |
|
745 | |||
746 | int status; |
|
746 | int status; | |
747 |
|
747 | |||
748 | #ifdef PRINT_TASK_STATISTICS |
|
748 | #ifdef PRINT_TASK_STATISTICS | |
749 | rtems_cpu_usage_reset(); |
|
749 | rtems_cpu_usage_reset(); | |
750 | #endif |
|
750 | #endif | |
751 |
|
751 | |||
752 | status = RTEMS_UNSATISFIED; |
|
752 | status = RTEMS_UNSATISFIED; | |
753 |
|
753 | |||
754 | switch( lfrCurrentMode ) |
|
754 | switch( lfrCurrentMode ) | |
755 | { |
|
755 | { | |
756 | case LFR_MODE_STANDBY: |
|
756 | case LFR_MODE_STANDBY: | |
757 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks |
|
757 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks | |
758 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
758 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
759 | { |
|
759 | { | |
760 | launch_spectral_matrix( ); |
|
760 | launch_spectral_matrix( ); | |
761 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); |
|
761 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); | |
762 | } |
|
762 | } | |
763 | break; |
|
763 | break; | |
764 | case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action |
|
764 | case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action | |
765 | restart_asm_activities( LFR_MODE_SBM1 ); |
|
765 | restart_asm_activities( LFR_MODE_SBM1 ); | |
766 | status = LFR_SUCCESSFUL; |
|
766 | status = LFR_SUCCESSFUL; | |
767 | break; |
|
767 | break; | |
768 | case LFR_MODE_BURST: |
|
768 | case LFR_MODE_BURST: | |
769 | status = stop_current_mode(); // stop the current mode |
|
769 | status = stop_current_mode(); // stop the current mode | |
770 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks |
|
770 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks | |
771 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
771 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
772 | { |
|
772 | { | |
773 | launch_spectral_matrix( ); |
|
773 | launch_spectral_matrix( ); | |
774 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); |
|
774 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); | |
775 | } |
|
775 | } | |
776 | break; |
|
776 | break; | |
777 | case LFR_MODE_SBM2: |
|
777 | case LFR_MODE_SBM2: | |
778 | restart_asm_activities( LFR_MODE_SBM1 ); |
|
778 | restart_asm_activities( LFR_MODE_SBM1 ); | |
779 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
779 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
780 | break; |
|
780 | break; | |
781 | default: |
|
781 | default: | |
782 | break; |
|
782 | break; | |
783 | } |
|
783 | } | |
784 |
|
784 | |||
785 | if (status != RTEMS_SUCCESSFUL) |
|
785 | if (status != RTEMS_SUCCESSFUL) | |
786 | { |
|
786 | { | |
787 | PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status) |
|
787 | PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status) | |
788 | status = RTEMS_UNSATISFIED; |
|
788 | status = RTEMS_UNSATISFIED; | |
789 | } |
|
789 | } | |
790 |
|
790 | |||
791 | return status; |
|
791 | return status; | |
792 | } |
|
792 | } | |
793 |
|
793 | |||
794 | int enter_mode_sbm2( unsigned int transitionCoarseTime ) |
|
794 | int enter_mode_sbm2( unsigned int transitionCoarseTime ) | |
795 | { |
|
795 | { | |
796 | /** This function is used to start the SBM2 mode. |
|
796 | /** This function is used to start the SBM2 mode. | |
797 | * |
|
797 | * | |
798 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
798 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
799 | * |
|
799 | * | |
800 | * @return RTEMS directive status codes: |
|
800 | * @return RTEMS directive status codes: | |
801 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
801 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
802 | * - RTEMS_INVALID_ID - task id invalid |
|
802 | * - RTEMS_INVALID_ID - task id invalid | |
803 | * - RTEMS_INCORRECT_STATE - task never started |
|
803 | * - RTEMS_INCORRECT_STATE - task never started | |
804 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
804 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
805 | * |
|
805 | * | |
806 | * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1, |
|
806 | * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1, | |
807 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other |
|
807 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other | |
808 | * cases, the acquisition is completely restarted. |
|
808 | * cases, the acquisition is completely restarted. | |
809 | * |
|
809 | * | |
810 | */ |
|
810 | */ | |
811 |
|
811 | |||
812 | int status; |
|
812 | int status; | |
813 |
|
813 | |||
814 | #ifdef PRINT_TASK_STATISTICS |
|
814 | #ifdef PRINT_TASK_STATISTICS | |
815 | rtems_cpu_usage_reset(); |
|
815 | rtems_cpu_usage_reset(); | |
816 | #endif |
|
816 | #endif | |
817 |
|
817 | |||
818 | status = RTEMS_UNSATISFIED; |
|
818 | status = RTEMS_UNSATISFIED; | |
819 |
|
819 | |||
820 | switch( lfrCurrentMode ) |
|
820 | switch( lfrCurrentMode ) | |
821 | { |
|
821 | { | |
822 | case LFR_MODE_STANDBY: |
|
822 | case LFR_MODE_STANDBY: | |
823 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks |
|
823 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks | |
824 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
824 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
825 | { |
|
825 | { | |
826 | launch_spectral_matrix( ); |
|
826 | launch_spectral_matrix( ); | |
827 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); |
|
827 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); | |
828 | } |
|
828 | } | |
829 | break; |
|
829 | break; | |
830 | case LFR_MODE_NORMAL: |
|
830 | case LFR_MODE_NORMAL: | |
831 | restart_asm_activities( LFR_MODE_SBM2 ); |
|
831 | restart_asm_activities( LFR_MODE_SBM2 ); | |
832 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
832 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
833 | break; |
|
833 | break; | |
834 | case LFR_MODE_BURST: |
|
834 | case LFR_MODE_BURST: | |
835 | status = stop_current_mode(); // stop the current mode |
|
835 | status = stop_current_mode(); // stop the current mode | |
836 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks |
|
836 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks | |
837 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
837 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
838 | { |
|
838 | { | |
839 | launch_spectral_matrix( ); |
|
839 | launch_spectral_matrix( ); | |
840 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); |
|
840 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); | |
841 | } |
|
841 | } | |
842 | break; |
|
842 | break; | |
843 | case LFR_MODE_SBM1: |
|
843 | case LFR_MODE_SBM1: | |
844 | restart_asm_activities( LFR_MODE_SBM2 ); |
|
844 | restart_asm_activities( LFR_MODE_SBM2 ); | |
845 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
845 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
846 | break; |
|
846 | break; | |
847 | default: |
|
847 | default: | |
848 | break; |
|
848 | break; | |
849 | } |
|
849 | } | |
850 |
|
850 | |||
851 | if (status != RTEMS_SUCCESSFUL) |
|
851 | if (status != RTEMS_SUCCESSFUL) | |
852 | { |
|
852 | { | |
853 | PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status) |
|
853 | PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status) | |
854 | status = RTEMS_UNSATISFIED; |
|
854 | status = RTEMS_UNSATISFIED; | |
855 | } |
|
855 | } | |
856 |
|
856 | |||
857 | return status; |
|
857 | return status; | |
858 | } |
|
858 | } | |
859 |
|
859 | |||
860 | int restart_science_tasks( unsigned char lfrRequestedMode ) |
|
860 | int restart_science_tasks( unsigned char lfrRequestedMode ) | |
861 | { |
|
861 | { | |
862 | /** This function is used to restart all science tasks. |
|
862 | /** This function is used to restart all science tasks. | |
863 | * |
|
863 | * | |
864 | * @return RTEMS directive status codes: |
|
864 | * @return RTEMS directive status codes: | |
865 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
865 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
866 | * - RTEMS_INVALID_ID - task id invalid |
|
866 | * - RTEMS_INVALID_ID - task id invalid | |
867 | * - RTEMS_INCORRECT_STATE - task never started |
|
867 | * - RTEMS_INCORRECT_STATE - task never started | |
868 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
868 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
869 | * |
|
869 | * | |
870 | * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1 |
|
870 | * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1 | |
871 | * |
|
871 | * | |
872 | */ |
|
872 | */ | |
873 |
|
873 | |||
874 | rtems_status_code status[10]; |
|
874 | rtems_status_code status[10]; | |
875 | rtems_status_code ret; |
|
875 | rtems_status_code ret; | |
876 |
|
876 | |||
877 | ret = RTEMS_SUCCESSFUL; |
|
877 | ret = RTEMS_SUCCESSFUL; | |
878 |
|
878 | |||
879 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); |
|
879 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); | |
880 | if (status[0] != RTEMS_SUCCESSFUL) |
|
880 | if (status[0] != RTEMS_SUCCESSFUL) | |
881 | { |
|
881 | { | |
882 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0]) |
|
882 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0]) | |
883 | } |
|
883 | } | |
884 |
|
884 | |||
885 | status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); |
|
885 | status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); | |
886 | if (status[1] != RTEMS_SUCCESSFUL) |
|
886 | if (status[1] != RTEMS_SUCCESSFUL) | |
887 | { |
|
887 | { | |
888 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1]) |
|
888 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1]) | |
889 | } |
|
889 | } | |
890 |
|
890 | |||
891 | status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); |
|
891 | status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); | |
892 | if (status[2] != RTEMS_SUCCESSFUL) |
|
892 | if (status[2] != RTEMS_SUCCESSFUL) | |
893 | { |
|
893 | { | |
894 | PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2]) |
|
894 | PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2]) | |
895 | } |
|
895 | } | |
896 |
|
896 | |||
897 | status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); |
|
897 | status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); | |
898 | if (status[3] != RTEMS_SUCCESSFUL) |
|
898 | if (status[3] != RTEMS_SUCCESSFUL) | |
899 | { |
|
899 | { | |
900 | PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3]) |
|
900 | PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3]) | |
901 | } |
|
901 | } | |
902 |
|
902 | |||
903 | status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); |
|
903 | status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); | |
904 | if (status[4] != RTEMS_SUCCESSFUL) |
|
904 | if (status[4] != RTEMS_SUCCESSFUL) | |
905 | { |
|
905 | { | |
906 | PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4]) |
|
906 | PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4]) | |
907 | } |
|
907 | } | |
908 |
|
908 | |||
909 | status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); |
|
909 | status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); | |
910 | if (status[5] != RTEMS_SUCCESSFUL) |
|
910 | if (status[5] != RTEMS_SUCCESSFUL) | |
911 | { |
|
911 | { | |
912 | PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5]) |
|
912 | PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5]) | |
913 | } |
|
913 | } | |
914 |
|
914 | |||
915 | status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); |
|
915 | status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); | |
916 | if (status[6] != RTEMS_SUCCESSFUL) |
|
916 | if (status[6] != RTEMS_SUCCESSFUL) | |
917 | { |
|
917 | { | |
918 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6]) |
|
918 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6]) | |
919 | } |
|
919 | } | |
920 |
|
920 | |||
921 | status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); |
|
921 | status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); | |
922 | if (status[7] != RTEMS_SUCCESSFUL) |
|
922 | if (status[7] != RTEMS_SUCCESSFUL) | |
923 | { |
|
923 | { | |
924 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7]) |
|
924 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7]) | |
925 | } |
|
925 | } | |
926 |
|
926 | |||
927 | status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); |
|
927 | status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); | |
928 | if (status[8] != RTEMS_SUCCESSFUL) |
|
928 | if (status[8] != RTEMS_SUCCESSFUL) | |
929 | { |
|
929 | { | |
930 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8]) |
|
930 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8]) | |
931 | } |
|
931 | } | |
932 |
|
932 | |||
933 | status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); |
|
933 | status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); | |
934 | if (status[9] != RTEMS_SUCCESSFUL) |
|
934 | if (status[9] != RTEMS_SUCCESSFUL) | |
935 | { |
|
935 | { | |
936 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9]) |
|
936 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9]) | |
937 | } |
|
937 | } | |
938 |
|
938 | |||
939 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || |
|
939 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || | |
940 | (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) || |
|
940 | (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) || | |
941 | (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) || |
|
941 | (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) || | |
942 | (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) || |
|
942 | (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) || | |
943 | (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) ) |
|
943 | (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) ) | |
944 | { |
|
944 | { | |
945 | ret = RTEMS_UNSATISFIED; |
|
945 | ret = RTEMS_UNSATISFIED; | |
946 | } |
|
946 | } | |
947 |
|
947 | |||
948 | return ret; |
|
948 | return ret; | |
949 | } |
|
949 | } | |
950 |
|
950 | |||
951 | int restart_asm_tasks( unsigned char lfrRequestedMode ) |
|
951 | int restart_asm_tasks( unsigned char lfrRequestedMode ) | |
952 | { |
|
952 | { | |
953 | /** This function is used to restart average spectral matrices tasks. |
|
953 | /** This function is used to restart average spectral matrices tasks. | |
954 | * |
|
954 | * | |
955 | * @return RTEMS directive status codes: |
|
955 | * @return RTEMS directive status codes: | |
956 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
956 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
957 | * - RTEMS_INVALID_ID - task id invalid |
|
957 | * - RTEMS_INVALID_ID - task id invalid | |
958 | * - RTEMS_INCORRECT_STATE - task never started |
|
958 | * - RTEMS_INCORRECT_STATE - task never started | |
959 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
959 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
960 | * |
|
960 | * | |
961 | * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2 |
|
961 | * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2 | |
962 | * |
|
962 | * | |
963 | */ |
|
963 | */ | |
964 |
|
964 | |||
965 | rtems_status_code status[6]; |
|
965 | rtems_status_code status[6]; | |
966 | rtems_status_code ret; |
|
966 | rtems_status_code ret; | |
967 |
|
967 | |||
968 | ret = RTEMS_SUCCESSFUL; |
|
968 | ret = RTEMS_SUCCESSFUL; | |
969 |
|
969 | |||
970 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); |
|
970 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); | |
971 | if (status[0] != RTEMS_SUCCESSFUL) |
|
971 | if (status[0] != RTEMS_SUCCESSFUL) | |
972 | { |
|
972 | { | |
973 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0]) |
|
973 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0]) | |
974 | } |
|
974 | } | |
975 |
|
975 | |||
976 | status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); |
|
976 | status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); | |
977 | if (status[1] != RTEMS_SUCCESSFUL) |
|
977 | if (status[1] != RTEMS_SUCCESSFUL) | |
978 | { |
|
978 | { | |
979 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1]) |
|
979 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1]) | |
980 | } |
|
980 | } | |
981 |
|
981 | |||
982 | status[2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); |
|
982 | status[2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); | |
983 | if (status[2] != RTEMS_SUCCESSFUL) |
|
983 | if (status[2] != RTEMS_SUCCESSFUL) | |
984 | { |
|
984 | { | |
985 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[2]) |
|
985 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[2]) | |
986 | } |
|
986 | } | |
987 |
|
987 | |||
988 | status[3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); |
|
988 | status[3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); | |
989 | if (status[3] != RTEMS_SUCCESSFUL) |
|
989 | if (status[3] != RTEMS_SUCCESSFUL) | |
990 | { |
|
990 | { | |
991 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[3]) |
|
991 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[3]) | |
992 | } |
|
992 | } | |
993 |
|
993 | |||
994 | status[4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); |
|
994 | status[4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); | |
995 | if (status[4] != RTEMS_SUCCESSFUL) |
|
995 | if (status[4] != RTEMS_SUCCESSFUL) | |
996 | { |
|
996 | { | |
997 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[4]) |
|
997 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[4]) | |
998 | } |
|
998 | } | |
999 |
|
999 | |||
1000 | status[5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); |
|
1000 | status[5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); | |
1001 | if (status[5] != RTEMS_SUCCESSFUL) |
|
1001 | if (status[5] != RTEMS_SUCCESSFUL) | |
1002 | { |
|
1002 | { | |
1003 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[5]) |
|
1003 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[5]) | |
1004 | } |
|
1004 | } | |
1005 |
|
1005 | |||
1006 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || |
|
1006 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || | |
1007 | (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) || |
|
1007 | (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) || | |
1008 | (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ) |
|
1008 | (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ) | |
1009 | { |
|
1009 | { | |
1010 | ret = RTEMS_UNSATISFIED; |
|
1010 | ret = RTEMS_UNSATISFIED; | |
1011 | } |
|
1011 | } | |
1012 |
|
1012 | |||
1013 | return ret; |
|
1013 | return ret; | |
1014 | } |
|
1014 | } | |
1015 |
|
1015 | |||
1016 | int suspend_science_tasks( void ) |
|
1016 | int suspend_science_tasks( void ) | |
1017 | { |
|
1017 | { | |
1018 | /** This function suspends the science tasks. |
|
1018 | /** This function suspends the science tasks. | |
1019 | * |
|
1019 | * | |
1020 | * @return RTEMS directive status codes: |
|
1020 | * @return RTEMS directive status codes: | |
1021 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
1021 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
1022 | * - RTEMS_INVALID_ID - task id invalid |
|
1022 | * - RTEMS_INVALID_ID - task id invalid | |
1023 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
1023 | * - RTEMS_ALREADY_SUSPENDED - task already suspended | |
1024 | * |
|
1024 | * | |
1025 | */ |
|
1025 | */ | |
1026 |
|
1026 | |||
1027 | rtems_status_code status; |
|
1027 | rtems_status_code status; | |
1028 |
|
1028 | |||
1029 | PRINTF("in suspend_science_tasks\n") |
|
1029 | PRINTF("in suspend_science_tasks\n") | |
1030 |
|
1030 | |||
1031 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 |
|
1031 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 | |
1032 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1032 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1033 | { |
|
1033 | { | |
1034 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
1034 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) | |
1035 | } |
|
1035 | } | |
1036 | else |
|
1036 | else | |
1037 | { |
|
1037 | { | |
1038 | status = RTEMS_SUCCESSFUL; |
|
1038 | status = RTEMS_SUCCESSFUL; | |
1039 | } |
|
1039 | } | |
1040 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 |
|
1040 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 | |
1041 | { |
|
1041 | { | |
1042 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); |
|
1042 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); | |
1043 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1043 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1044 | { |
|
1044 | { | |
1045 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) |
|
1045 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) | |
1046 | } |
|
1046 | } | |
1047 | else |
|
1047 | else | |
1048 | { |
|
1048 | { | |
1049 | status = RTEMS_SUCCESSFUL; |
|
1049 | status = RTEMS_SUCCESSFUL; | |
1050 | } |
|
1050 | } | |
1051 | } |
|
1051 | } | |
1052 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 |
|
1052 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 | |
1053 | { |
|
1053 | { | |
1054 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); |
|
1054 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); | |
1055 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1055 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1056 | { |
|
1056 | { | |
1057 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) |
|
1057 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) | |
1058 | } |
|
1058 | } | |
1059 | else |
|
1059 | else | |
1060 | { |
|
1060 | { | |
1061 | status = RTEMS_SUCCESSFUL; |
|
1061 | status = RTEMS_SUCCESSFUL; | |
1062 | } |
|
1062 | } | |
1063 | } |
|
1063 | } | |
1064 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 |
|
1064 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 | |
1065 | { |
|
1065 | { | |
1066 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); |
|
1066 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); | |
1067 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1067 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1068 | { |
|
1068 | { | |
1069 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) |
|
1069 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) | |
1070 | } |
|
1070 | } | |
1071 | else |
|
1071 | else | |
1072 | { |
|
1072 | { | |
1073 | status = RTEMS_SUCCESSFUL; |
|
1073 | status = RTEMS_SUCCESSFUL; | |
1074 | } |
|
1074 | } | |
1075 | } |
|
1075 | } | |
1076 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 |
|
1076 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 | |
1077 | { |
|
1077 | { | |
1078 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); |
|
1078 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); | |
1079 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1079 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1080 | { |
|
1080 | { | |
1081 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) |
|
1081 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) | |
1082 | } |
|
1082 | } | |
1083 | else |
|
1083 | else | |
1084 | { |
|
1084 | { | |
1085 | status = RTEMS_SUCCESSFUL; |
|
1085 | status = RTEMS_SUCCESSFUL; | |
1086 | } |
|
1086 | } | |
1087 | } |
|
1087 | } | |
1088 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 |
|
1088 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 | |
1089 | { |
|
1089 | { | |
1090 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); |
|
1090 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); | |
1091 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1091 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1092 | { |
|
1092 | { | |
1093 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) |
|
1093 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) | |
1094 | } |
|
1094 | } | |
1095 | else |
|
1095 | else | |
1096 | { |
|
1096 | { | |
1097 | status = RTEMS_SUCCESSFUL; |
|
1097 | status = RTEMS_SUCCESSFUL; | |
1098 | } |
|
1098 | } | |
1099 | } |
|
1099 | } | |
1100 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM |
|
1100 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM | |
1101 | { |
|
1101 | { | |
1102 | status = rtems_task_suspend( Task_id[TASKID_WFRM] ); |
|
1102 | status = rtems_task_suspend( Task_id[TASKID_WFRM] ); | |
1103 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1103 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1104 | { |
|
1104 | { | |
1105 | PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) |
|
1105 | PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) | |
1106 | } |
|
1106 | } | |
1107 | else |
|
1107 | else | |
1108 | { |
|
1108 | { | |
1109 | status = RTEMS_SUCCESSFUL; |
|
1109 | status = RTEMS_SUCCESSFUL; | |
1110 | } |
|
1110 | } | |
1111 | } |
|
1111 | } | |
1112 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 |
|
1112 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 | |
1113 | { |
|
1113 | { | |
1114 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); |
|
1114 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); | |
1115 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1115 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1116 | { |
|
1116 | { | |
1117 | PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) |
|
1117 | PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) | |
1118 | } |
|
1118 | } | |
1119 | else |
|
1119 | else | |
1120 | { |
|
1120 | { | |
1121 | status = RTEMS_SUCCESSFUL; |
|
1121 | status = RTEMS_SUCCESSFUL; | |
1122 | } |
|
1122 | } | |
1123 | } |
|
1123 | } | |
1124 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 |
|
1124 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 | |
1125 | { |
|
1125 | { | |
1126 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); |
|
1126 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); | |
1127 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1127 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1128 | { |
|
1128 | { | |
1129 | PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) |
|
1129 | PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) | |
1130 | } |
|
1130 | } | |
1131 | else |
|
1131 | else | |
1132 | { |
|
1132 | { | |
1133 | status = RTEMS_SUCCESSFUL; |
|
1133 | status = RTEMS_SUCCESSFUL; | |
1134 | } |
|
1134 | } | |
1135 | } |
|
1135 | } | |
1136 | if (status == RTEMS_SUCCESSFUL) // suspend CWF1 |
|
1136 | if (status == RTEMS_SUCCESSFUL) // suspend CWF1 | |
1137 | { |
|
1137 | { | |
1138 | status = rtems_task_suspend( Task_id[TASKID_CWF1] ); |
|
1138 | status = rtems_task_suspend( Task_id[TASKID_CWF1] ); | |
1139 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1139 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1140 | { |
|
1140 | { | |
1141 | PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) |
|
1141 | PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) | |
1142 | } |
|
1142 | } | |
1143 | else |
|
1143 | else | |
1144 | { |
|
1144 | { | |
1145 | status = RTEMS_SUCCESSFUL; |
|
1145 | status = RTEMS_SUCCESSFUL; | |
1146 | } |
|
1146 | } | |
1147 | } |
|
1147 | } | |
1148 |
|
1148 | |||
1149 | return status; |
|
1149 | return status; | |
1150 | } |
|
1150 | } | |
1151 |
|
1151 | |||
1152 | int suspend_asm_tasks( void ) |
|
1152 | int suspend_asm_tasks( void ) | |
1153 | { |
|
1153 | { | |
1154 | /** This function suspends the science tasks. |
|
1154 | /** This function suspends the science tasks. | |
1155 | * |
|
1155 | * | |
1156 | * @return RTEMS directive status codes: |
|
1156 | * @return RTEMS directive status codes: | |
1157 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
1157 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
1158 | * - RTEMS_INVALID_ID - task id invalid |
|
1158 | * - RTEMS_INVALID_ID - task id invalid | |
1159 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
1159 | * - RTEMS_ALREADY_SUSPENDED - task already suspended | |
1160 | * |
|
1160 | * | |
1161 | */ |
|
1161 | */ | |
1162 |
|
1162 | |||
1163 | rtems_status_code status; |
|
1163 | rtems_status_code status; | |
1164 |
|
1164 | |||
1165 | PRINTF("in suspend_science_tasks\n") |
|
1165 | PRINTF("in suspend_science_tasks\n") | |
1166 |
|
1166 | |||
1167 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 |
|
1167 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 | |
1168 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1168 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1169 | { |
|
1169 | { | |
1170 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
1170 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) | |
1171 | } |
|
1171 | } | |
1172 | else |
|
1172 | else | |
1173 | { |
|
1173 | { | |
1174 | status = RTEMS_SUCCESSFUL; |
|
1174 | status = RTEMS_SUCCESSFUL; | |
1175 | } |
|
1175 | } | |
1176 |
|
1176 | |||
1177 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 |
|
1177 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 | |
1178 | { |
|
1178 | { | |
1179 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); |
|
1179 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); | |
1180 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1180 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1181 | { |
|
1181 | { | |
1182 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) |
|
1182 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) | |
1183 | } |
|
1183 | } | |
1184 | else |
|
1184 | else | |
1185 | { |
|
1185 | { | |
1186 | status = RTEMS_SUCCESSFUL; |
|
1186 | status = RTEMS_SUCCESSFUL; | |
1187 | } |
|
1187 | } | |
1188 | } |
|
1188 | } | |
1189 |
|
1189 | |||
1190 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 |
|
1190 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 | |
1191 | { |
|
1191 | { | |
1192 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); |
|
1192 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); | |
1193 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1193 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1194 | { |
|
1194 | { | |
1195 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) |
|
1195 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) | |
1196 | } |
|
1196 | } | |
1197 | else |
|
1197 | else | |
1198 | { |
|
1198 | { | |
1199 | status = RTEMS_SUCCESSFUL; |
|
1199 | status = RTEMS_SUCCESSFUL; | |
1200 | } |
|
1200 | } | |
1201 | } |
|
1201 | } | |
1202 |
|
1202 | |||
1203 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 |
|
1203 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 | |
1204 | { |
|
1204 | { | |
1205 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); |
|
1205 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); | |
1206 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1206 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1207 | { |
|
1207 | { | |
1208 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) |
|
1208 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) | |
1209 | } |
|
1209 | } | |
1210 | else |
|
1210 | else | |
1211 | { |
|
1211 | { | |
1212 | status = RTEMS_SUCCESSFUL; |
|
1212 | status = RTEMS_SUCCESSFUL; | |
1213 | } |
|
1213 | } | |
1214 | } |
|
1214 | } | |
1215 |
|
1215 | |||
1216 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 |
|
1216 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 | |
1217 | { |
|
1217 | { | |
1218 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); |
|
1218 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); | |
1219 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1219 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1220 | { |
|
1220 | { | |
1221 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) |
|
1221 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) | |
1222 | } |
|
1222 | } | |
1223 | else |
|
1223 | else | |
1224 | { |
|
1224 | { | |
1225 | status = RTEMS_SUCCESSFUL; |
|
1225 | status = RTEMS_SUCCESSFUL; | |
1226 | } |
|
1226 | } | |
1227 | } |
|
1227 | } | |
1228 |
|
1228 | |||
1229 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 |
|
1229 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 | |
1230 | { |
|
1230 | { | |
1231 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); |
|
1231 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); | |
1232 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1232 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1233 | { |
|
1233 | { | |
1234 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) |
|
1234 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) | |
1235 | } |
|
1235 | } | |
1236 | else |
|
1236 | else | |
1237 | { |
|
1237 | { | |
1238 | status = RTEMS_SUCCESSFUL; |
|
1238 | status = RTEMS_SUCCESSFUL; | |
1239 | } |
|
1239 | } | |
1240 | } |
|
1240 | } | |
1241 |
|
1241 | |||
1242 | return status; |
|
1242 | return status; | |
1243 | } |
|
1243 | } | |
1244 |
|
1244 | |||
1245 | void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) |
|
1245 | void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) | |
1246 | { |
|
1246 | { | |
1247 | WFP_reset_current_ring_nodes(); |
|
1247 | WFP_reset_current_ring_nodes(); | |
1248 |
|
1248 | |||
1249 | reset_waveform_picker_regs(); |
|
1249 | reset_waveform_picker_regs(); | |
1250 |
|
1250 | |||
1251 | set_wfp_burst_enable_register( mode ); |
|
1251 | set_wfp_burst_enable_register( mode ); | |
1252 |
|
1252 | |||
1253 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); |
|
1253 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); | |
1254 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); |
|
1254 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); | |
1255 |
|
1255 | |||
1256 | if (transitionCoarseTime == 0) |
|
1256 | if (transitionCoarseTime == 0) | |
1257 | { |
|
1257 | { | |
1258 | // instant transition means transition on the next valid date |
|
1258 | // instant transition means transition on the next valid date | |
1259 | // this is mandatory to have a good snapshot period a a good correction of the snapshot period |
|
1259 | // this is mandatory to have a good snapshot period a a good correction of the snapshot period | |
1260 | waveform_picker_regs->start_date = time_management_regs->coarse_time + 1; |
|
1260 | waveform_picker_regs->start_date = time_management_regs->coarse_time + 1; | |
1261 | } |
|
1261 | } | |
1262 | else |
|
1262 | else | |
1263 | { |
|
1263 | { | |
1264 | waveform_picker_regs->start_date = transitionCoarseTime; |
|
1264 | waveform_picker_regs->start_date = transitionCoarseTime; | |
1265 | } |
|
1265 | } | |
1266 |
|
1266 | |||
1267 | } |
|
1267 | } | |
1268 |
|
1268 | |||
1269 | void launch_spectral_matrix( void ) |
|
1269 | void launch_spectral_matrix( void ) | |
1270 | { |
|
1270 | { | |
1271 | SM_reset_current_ring_nodes(); |
|
1271 | SM_reset_current_ring_nodes(); | |
1272 |
|
1272 | |||
1273 | reset_spectral_matrix_regs(); |
|
1273 | reset_spectral_matrix_regs(); | |
1274 |
|
1274 | |||
1275 | reset_nb_sm(); |
|
1275 | reset_nb_sm(); | |
1276 |
|
1276 | |||
1277 | set_sm_irq_onNewMatrix( 1 ); |
|
1277 | set_sm_irq_onNewMatrix( 1 ); | |
1278 |
|
1278 | |||
1279 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
1279 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); | |
1280 | LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
1280 | LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); | |
1281 |
|
1281 | |||
1282 | } |
|
1282 | } | |
1283 |
|
1283 | |||
1284 | void set_sm_irq_onNewMatrix( unsigned char value ) |
|
1284 | void set_sm_irq_onNewMatrix( unsigned char value ) | |
1285 | { |
|
1285 | { | |
1286 | if (value == 1) |
|
1286 | if (value == 1) | |
1287 | { |
|
1287 | { | |
1288 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01; |
|
1288 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01; | |
1289 | } |
|
1289 | } | |
1290 | else |
|
1290 | else | |
1291 | { |
|
1291 | { | |
1292 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110 |
|
1292 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110 | |
1293 | } |
|
1293 | } | |
1294 | } |
|
1294 | } | |
1295 |
|
1295 | |||
1296 | void set_sm_irq_onError( unsigned char value ) |
|
1296 | void set_sm_irq_onError( unsigned char value ) | |
1297 | { |
|
1297 | { | |
1298 | if (value == 1) |
|
1298 | if (value == 1) | |
1299 | { |
|
1299 | { | |
1300 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02; |
|
1300 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02; | |
1301 | } |
|
1301 | } | |
1302 | else |
|
1302 | else | |
1303 | { |
|
1303 | { | |
1304 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101 |
|
1304 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101 | |
1305 | } |
|
1305 | } | |
1306 | } |
|
1306 | } | |
1307 |
|
1307 | |||
1308 | //***************************** |
|
1308 | //***************************** | |
1309 | // CONFIGURE CALIBRATION SIGNAL |
|
1309 | // CONFIGURE CALIBRATION SIGNAL | |
1310 | void setCalibrationPrescaler( unsigned int prescaler ) |
|
1310 | void setCalibrationPrescaler( unsigned int prescaler ) | |
1311 | { |
|
1311 | { | |
1312 | // prescaling of the master clock (25 MHz) |
|
1312 | // prescaling of the master clock (25 MHz) | |
1313 | // master clock is divided by 2^prescaler |
|
1313 | // master clock is divided by 2^prescaler | |
1314 | time_management_regs->calPrescaler = prescaler; |
|
1314 | time_management_regs->calPrescaler = prescaler; | |
1315 | } |
|
1315 | } | |
1316 |
|
1316 | |||
1317 | void setCalibrationDivisor( unsigned int divisionFactor ) |
|
1317 | void setCalibrationDivisor( unsigned int divisionFactor ) | |
1318 | { |
|
1318 | { | |
1319 | // division of the prescaled clock by the division factor |
|
1319 | // division of the prescaled clock by the division factor | |
1320 | time_management_regs->calDivisor = divisionFactor; |
|
1320 | time_management_regs->calDivisor = divisionFactor; | |
1321 | } |
|
1321 | } | |
1322 |
|
1322 | |||
1323 | void setCalibrationData( void ){ |
|
1323 | void setCalibrationData( void ){ | |
1324 | unsigned int k; |
|
1324 | unsigned int k; | |
1325 | unsigned short data; |
|
1325 | unsigned short data; | |
1326 | float val; |
|
1326 | float val; | |
1327 | float f0; |
|
1327 | float f0; | |
1328 | float f1; |
|
1328 | float f1; | |
1329 | float fs; |
|
1329 | float fs; | |
1330 | float Ts; |
|
1330 | float Ts; | |
1331 | float scaleFactor; |
|
1331 | float scaleFactor; | |
1332 |
|
1332 | |||
1333 | f0 = 625; |
|
1333 | f0 = 625; | |
1334 | f1 = 10000; |
|
1334 | f1 = 10000; | |
1335 | fs = 160256.410; |
|
1335 | fs = 160256.410; | |
1336 | Ts = 1. / fs; |
|
1336 | Ts = 1. / fs; | |
1337 | scaleFactor = 0.250 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 500 mVpp each, amplitude = 250 mV |
|
1337 | scaleFactor = 0.250 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 500 mVpp each, amplitude = 250 mV | |
1338 |
|
1338 | |||
1339 | time_management_regs->calDataPtr = 0x00; |
|
1339 | time_management_regs->calDataPtr = 0x00; | |
1340 |
|
1340 | |||
1341 | // build the signal for the SCM calibration |
|
1341 | // build the signal for the SCM calibration | |
1342 | for (k=0; k<256; k++) |
|
1342 | for (k=0; k<256; k++) | |
1343 | { |
|
1343 | { | |
1344 | val = sin( 2 * pi * f0 * k * Ts ) |
|
1344 | val = sin( 2 * pi * f0 * k * Ts ) | |
1345 | + sin( 2 * pi * f1 * k * Ts ); |
|
1345 | + sin( 2 * pi * f1 * k * Ts ); | |
1346 | data = (unsigned short) ((val * scaleFactor) + 2048); |
|
1346 | data = (unsigned short) ((val * scaleFactor) + 2048); | |
1347 | time_management_regs->calData = data & 0xfff; |
|
1347 | time_management_regs->calData = data & 0xfff; | |
1348 | } |
|
1348 | } | |
1349 | } |
|
1349 | } | |
1350 |
|
1350 | |||
1351 | void setCalibrationDataInterleaved( void ){ |
|
1351 | void setCalibrationDataInterleaved( void ){ | |
1352 | unsigned int k; |
|
1352 | unsigned int k; | |
1353 | float val; |
|
1353 | float val; | |
1354 | float f0; |
|
1354 | float f0; | |
1355 | float f1; |
|
1355 | float f1; | |
1356 | float fs; |
|
1356 | float fs; | |
1357 | float Ts; |
|
1357 | float Ts; | |
1358 | unsigned short data[384]; |
|
1358 | unsigned short data[384]; | |
1359 | unsigned char *dataPtr; |
|
1359 | unsigned char *dataPtr; | |
1360 |
|
1360 | |||
1361 | f0 = 625; |
|
1361 | f0 = 625; | |
1362 | f1 = 10000; |
|
1362 | f1 = 10000; | |
1363 | fs = 240384.615; |
|
1363 | fs = 240384.615; | |
1364 | Ts = 1. / fs; |
|
1364 | Ts = 1. / fs; | |
1365 |
|
1365 | |||
1366 | time_management_regs->calDataPtr = 0x00; |
|
1366 | time_management_regs->calDataPtr = 0x00; | |
1367 |
|
1367 | |||
1368 | // build the signal for the SCM calibration |
|
1368 | // build the signal for the SCM calibration | |
1369 | for (k=0; k<384; k++) |
|
1369 | for (k=0; k<384; k++) | |
1370 | { |
|
1370 | { | |
1371 | val = sin( 2 * pi * f0 * k * Ts ) |
|
1371 | val = sin( 2 * pi * f0 * k * Ts ) | |
1372 | + sin( 2 * pi * f1 * k * Ts ); |
|
1372 | + sin( 2 * pi * f1 * k * Ts ); | |
1373 | data[k] = (unsigned short) (val * 512 + 2048); |
|
1373 | data[k] = (unsigned short) (val * 512 + 2048); | |
1374 | } |
|
1374 | } | |
1375 |
|
1375 | |||
1376 | // write the signal in interleaved mode |
|
1376 | // write the signal in interleaved mode | |
1377 | for (k=0; k<128; k++) |
|
1377 | for (k=0; k<128; k++) | |
1378 | { |
|
1378 | { | |
1379 | dataPtr = (unsigned char*) &data[k*3 + 2]; |
|
1379 | dataPtr = (unsigned char*) &data[k*3 + 2]; | |
1380 | time_management_regs->calData = (data[k*3] & 0xfff) |
|
1380 | time_management_regs->calData = (data[k*3] & 0xfff) | |
1381 | + ( (dataPtr[0] & 0x3f) << 12); |
|
1381 | + ( (dataPtr[0] & 0x3f) << 12); | |
1382 | time_management_regs->calData = (data[k*3 + 1] & 0xfff) |
|
1382 | time_management_regs->calData = (data[k*3 + 1] & 0xfff) | |
1383 | + ( (dataPtr[1] & 0x3f) << 12); |
|
1383 | + ( (dataPtr[1] & 0x3f) << 12); | |
1384 | } |
|
1384 | } | |
1385 | } |
|
1385 | } | |
1386 |
|
1386 | |||
1387 | void setCalibrationReload( bool state) |
|
1387 | void setCalibrationReload( bool state) | |
1388 | { |
|
1388 | { | |
1389 | if (state == true) |
|
1389 | if (state == true) | |
1390 | { |
|
1390 | { | |
1391 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000] |
|
1391 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000] | |
1392 | } |
|
1392 | } | |
1393 | else |
|
1393 | else | |
1394 | { |
|
1394 | { | |
1395 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111] |
|
1395 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111] | |
1396 | } |
|
1396 | } | |
1397 | } |
|
1397 | } | |
1398 |
|
1398 | |||
1399 | void setCalibrationEnable( bool state ) |
|
1399 | void setCalibrationEnable( bool state ) | |
1400 | { |
|
1400 | { | |
1401 | // this bit drives the multiplexer |
|
1401 | // this bit drives the multiplexer | |
1402 | if (state == true) |
|
1402 | if (state == true) | |
1403 | { |
|
1403 | { | |
1404 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000] |
|
1404 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000] | |
1405 | } |
|
1405 | } | |
1406 | else |
|
1406 | else | |
1407 | { |
|
1407 | { | |
1408 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111] |
|
1408 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111] | |
1409 | } |
|
1409 | } | |
1410 | } |
|
1410 | } | |
1411 |
|
1411 | |||
1412 | void setCalibrationInterleaved( bool state ) |
|
1412 | void setCalibrationInterleaved( bool state ) | |
1413 | { |
|
1413 | { | |
1414 | // this bit drives the multiplexer |
|
1414 | // this bit drives the multiplexer | |
1415 | if (state == true) |
|
1415 | if (state == true) | |
1416 | { |
|
1416 | { | |
1417 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000] |
|
1417 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000] | |
1418 | } |
|
1418 | } | |
1419 | else |
|
1419 | else | |
1420 | { |
|
1420 | { | |
1421 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111] |
|
1421 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111] | |
1422 | } |
|
1422 | } | |
1423 | } |
|
1423 | } | |
1424 |
|
1424 | |||
1425 | void setCalibration( bool state ) |
|
1425 | void setCalibration( bool state ) | |
1426 | { |
|
1426 | { | |
1427 | if (state == true) |
|
1427 | if (state == true) | |
1428 | { |
|
1428 | { | |
1429 | setCalibrationEnable( true ); |
|
1429 | setCalibrationEnable( true ); | |
1430 | setCalibrationReload( false ); |
|
1430 | setCalibrationReload( false ); | |
1431 | set_hk_lfr_calib_enable( true ); |
|
1431 | set_hk_lfr_calib_enable( true ); | |
1432 | } |
|
1432 | } | |
1433 | else |
|
1433 | else | |
1434 | { |
|
1434 | { | |
1435 | setCalibrationEnable( false ); |
|
1435 | setCalibrationEnable( false ); | |
1436 | setCalibrationReload( true ); |
|
1436 | setCalibrationReload( true ); | |
1437 | set_hk_lfr_calib_enable( false ); |
|
1437 | set_hk_lfr_calib_enable( false ); | |
1438 | } |
|
1438 | } | |
1439 | } |
|
1439 | } | |
1440 |
|
1440 | |||
1441 | void configureCalibration( bool interleaved ) |
|
1441 | void configureCalibration( bool interleaved ) | |
1442 | { |
|
1442 | { | |
1443 | setCalibration( false ); |
|
1443 | setCalibration( false ); | |
1444 | if ( interleaved == true ) |
|
1444 | if ( interleaved == true ) | |
1445 | { |
|
1445 | { | |
1446 | setCalibrationInterleaved( true ); |
|
1446 | setCalibrationInterleaved( true ); | |
1447 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1447 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 | |
1448 | setCalibrationDivisor( 26 ); // => 240 384 |
|
1448 | setCalibrationDivisor( 26 ); // => 240 384 | |
1449 | setCalibrationDataInterleaved(); |
|
1449 | setCalibrationDataInterleaved(); | |
1450 | } |
|
1450 | } | |
1451 | else |
|
1451 | else | |
1452 | { |
|
1452 | { | |
1453 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1453 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 | |
1454 | setCalibrationDivisor( 38 ); // => 160 256 (39 - 1) |
|
1454 | setCalibrationDivisor( 38 ); // => 160 256 (39 - 1) | |
1455 | setCalibrationData(); |
|
1455 | setCalibrationData(); | |
1456 | } |
|
1456 | } | |
1457 | } |
|
1457 | } | |
1458 |
|
1458 | |||
1459 | //**************** |
|
1459 | //**************** | |
1460 | // CLOSING ACTIONS |
|
1460 | // CLOSING ACTIONS | |
1461 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1461 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) | |
1462 | { |
|
1462 | { | |
1463 | /** This function is used to update the HK packets statistics after a successful TC execution. |
|
1463 | /** This function is used to update the HK packets statistics after a successful TC execution. | |
1464 | * |
|
1464 | * | |
1465 | * @param TC points to the TC being processed |
|
1465 | * @param TC points to the TC being processed | |
1466 | * @param time is the time used to date the TC execution |
|
1466 | * @param time is the time used to date the TC execution | |
1467 | * |
|
1467 | * | |
1468 | */ |
|
1468 | */ | |
1469 |
|
1469 | |||
1470 | unsigned int val; |
|
1470 | unsigned int val; | |
1471 |
|
1471 | |||
1472 | housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; |
|
1472 | housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; | |
1473 | housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; |
|
1473 | housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; | |
1474 | housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00; |
|
1474 | housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00; | |
1475 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; |
|
1475 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; | |
1476 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00; |
|
1476 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00; | |
1477 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; |
|
1477 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; | |
1478 | housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0]; |
|
1478 | housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0]; | |
1479 | housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1]; |
|
1479 | housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1]; | |
1480 | housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2]; |
|
1480 | housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2]; | |
1481 | housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3]; |
|
1481 | housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3]; | |
1482 | housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4]; |
|
1482 | housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4]; | |
1483 | housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5]; |
|
1483 | housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5]; | |
1484 |
|
1484 | |||
1485 | val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1]; |
|
1485 | val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1]; | |
1486 | val++; |
|
1486 | val++; | |
1487 | housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8); |
|
1487 | housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8); | |
1488 | housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val); |
|
1488 | housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val); | |
1489 | } |
|
1489 | } | |
1490 |
|
1490 | |||
1491 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1491 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) | |
1492 | { |
|
1492 | { | |
1493 | /** This function is used to update the HK packets statistics after a TC rejection. |
|
1493 | /** This function is used to update the HK packets statistics after a TC rejection. | |
1494 | * |
|
1494 | * | |
1495 | * @param TC points to the TC being processed |
|
1495 | * @param TC points to the TC being processed | |
1496 | * @param time is the time used to date the TC rejection |
|
1496 | * @param time is the time used to date the TC rejection | |
1497 | * |
|
1497 | * | |
1498 | */ |
|
1498 | */ | |
1499 |
|
1499 | |||
1500 | unsigned int val; |
|
1500 | unsigned int val; | |
1501 |
|
1501 | |||
1502 | housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; |
|
1502 | housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; | |
1503 | housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; |
|
1503 | housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; | |
1504 | housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00; |
|
1504 | housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00; | |
1505 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; |
|
1505 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; | |
1506 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00; |
|
1506 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00; | |
1507 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; |
|
1507 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; | |
1508 | housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0]; |
|
1508 | housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0]; | |
1509 | housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1]; |
|
1509 | housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1]; | |
1510 | housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2]; |
|
1510 | housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2]; | |
1511 | housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3]; |
|
1511 | housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3]; | |
1512 | housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4]; |
|
1512 | housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4]; | |
1513 | housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5]; |
|
1513 | housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5]; | |
1514 |
|
1514 | |||
1515 | val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1]; |
|
1515 | val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1]; | |
1516 | val++; |
|
1516 | val++; | |
1517 | housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8); |
|
1517 | housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8); | |
1518 | housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val); |
|
1518 | housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val); | |
1519 | } |
|
1519 | } | |
1520 |
|
1520 | |||
1521 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) |
|
1521 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) | |
1522 | { |
|
1522 | { | |
1523 | /** This function is the last step of the TC execution workflow. |
|
1523 | /** This function is the last step of the TC execution workflow. | |
1524 | * |
|
1524 | * | |
1525 | * @param TC points to the TC being processed |
|
1525 | * @param TC points to the TC being processed | |
1526 | * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT) |
|
1526 | * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT) | |
1527 | * @param queue_id is the id of the RTEMS message queue used to send TM packets |
|
1527 | * @param queue_id is the id of the RTEMS message queue used to send TM packets | |
1528 | * @param time is the time used to date the TC execution |
|
1528 | * @param time is the time used to date the TC execution | |
1529 | * |
|
1529 | * | |
1530 | */ |
|
1530 | */ | |
1531 |
|
1531 | |||
1532 | unsigned char requestedMode; |
|
1532 | unsigned char requestedMode; | |
1533 |
|
1533 | |||
1534 | if (result == LFR_SUCCESSFUL) |
|
1534 | if (result == LFR_SUCCESSFUL) | |
1535 | { |
|
1535 | { | |
1536 | if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
1536 | if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) | |
1537 | & |
|
1537 | & | |
1538 | !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
1538 | !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) | |
1539 | ) |
|
1539 | ) | |
1540 | { |
|
1540 | { | |
1541 | send_tm_lfr_tc_exe_success( TC, queue_id ); |
|
1541 | send_tm_lfr_tc_exe_success( TC, queue_id ); | |
1542 | } |
|
1542 | } | |
1543 | if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) ) |
|
1543 | if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) ) | |
1544 | { |
|
1544 | { | |
1545 | //********************************** |
|
1545 | //********************************** | |
1546 | // UPDATE THE LFRMODE LOCAL VARIABLE |
|
1546 | // UPDATE THE LFRMODE LOCAL VARIABLE | |
1547 | requestedMode = TC->dataAndCRC[1]; |
|
1547 | requestedMode = TC->dataAndCRC[1]; | |
1548 | housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d); |
|
1548 | housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d); | |
1549 | updateLFRCurrentMode(); |
|
1549 | updateLFRCurrentMode(); | |
1550 | } |
|
1550 | } | |
1551 | } |
|
1551 | } | |
1552 | else if (result == LFR_EXE_ERROR) |
|
1552 | else if (result == LFR_EXE_ERROR) | |
1553 | { |
|
1553 | { | |
1554 | send_tm_lfr_tc_exe_error( TC, queue_id ); |
|
1554 | send_tm_lfr_tc_exe_error( TC, queue_id ); | |
1555 | } |
|
1555 | } | |
1556 | } |
|
1556 | } | |
1557 |
|
1557 | |||
1558 | //*************************** |
|
1558 | //*************************** | |
1559 | // Interrupt Service Routines |
|
1559 | // Interrupt Service Routines | |
1560 | rtems_isr commutation_isr1( rtems_vector_number vector ) |
|
1560 | rtems_isr commutation_isr1( rtems_vector_number vector ) | |
1561 | { |
|
1561 | { | |
1562 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1562 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | |
1563 | PRINTF("In commutation_isr1 *** Error sending event to DUMB\n") |
|
1563 | PRINTF("In commutation_isr1 *** Error sending event to DUMB\n") | |
1564 | } |
|
1564 | } | |
1565 | } |
|
1565 | } | |
1566 |
|
1566 | |||
1567 | rtems_isr commutation_isr2( rtems_vector_number vector ) |
|
1567 | rtems_isr commutation_isr2( rtems_vector_number vector ) | |
1568 | { |
|
1568 | { | |
1569 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1569 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | |
1570 | PRINTF("In commutation_isr2 *** Error sending event to DUMB\n") |
|
1570 | PRINTF("In commutation_isr2 *** Error sending event to DUMB\n") | |
1571 | } |
|
1571 | } | |
1572 | } |
|
1572 | } | |
1573 |
|
1573 | |||
1574 | //**************** |
|
1574 | //**************** | |
1575 | // OTHER FUNCTIONS |
|
1575 | // OTHER FUNCTIONS | |
1576 | void updateLFRCurrentMode() |
|
1576 | void updateLFRCurrentMode() | |
1577 | { |
|
1577 | { | |
1578 | /** This function updates the value of the global variable lfrCurrentMode. |
|
1578 | /** This function updates the value of the global variable lfrCurrentMode. | |
1579 | * |
|
1579 | * | |
1580 | * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running. |
|
1580 | * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running. | |
1581 | * |
|
1581 | * | |
1582 | */ |
|
1582 | */ | |
1583 | // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure |
|
1583 | // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure | |
1584 | lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; |
|
1584 | lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; | |
1585 | } |
|
1585 | } | |
1586 |
|
1586 | |||
1587 | void set_lfr_soft_reset( unsigned char value ) |
|
1587 | void set_lfr_soft_reset( unsigned char value ) | |
1588 | { |
|
1588 | { | |
1589 | if (value == 1) |
|
1589 | if (value == 1) | |
1590 | { |
|
1590 | { | |
1591 | time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100] |
|
1591 | time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100] | |
1592 | } |
|
1592 | } | |
1593 | else |
|
1593 | else | |
1594 | { |
|
1594 | { | |
1595 | time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011] |
|
1595 | time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011] | |
1596 | } |
|
1596 | } | |
1597 | } |
|
1597 | } | |
1598 |
|
1598 | |||
1599 | void reset_lfr( void ) |
|
1599 | void reset_lfr( void ) | |
1600 | { |
|
1600 | { | |
1601 | set_lfr_soft_reset( 1 ); |
|
1601 | set_lfr_soft_reset( 1 ); | |
1602 |
|
1602 | |||
1603 | set_lfr_soft_reset( 0 ); |
|
1603 | set_lfr_soft_reset( 0 ); | |
1604 |
|
1604 | |||
1605 | set_hk_lfr_sc_potential_flag( true ); |
|
1605 | set_hk_lfr_sc_potential_flag( true ); | |
1606 | } |
|
1606 | } |
General Comments 0
You need to be logged in to leave comments.
Login now